ide: Splitters in Qtf designer

git-svn-id: svn://ultimatepp.org/upp/trunk@6092 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2013-05-25 11:18:53 +00:00
parent 1afabb1c98
commit 49fe5af649
2 changed files with 141 additions and 128 deletions

View file

@ -1,121 +1,136 @@
#include "ide.h"
INITBLOCK {
RegisterGlobalConfig("QTF-designer");
RegisterGlobalConfig("QTF-designer-editor");
}
class QtfDlg : public WithQtfLayout<TopWindow> {
typedef QtfDlg CLASSNAME;
void Text();
void Clear();
void Copy();
void Editor();
public:
void Serialize(Stream& s);
QtfDlg();
};
void QtfDlg::Text()
{
qtf <<= ~text;
}
void QtfDlg::Clear()
{
text.Clear();
Text();
}
void QtfDlg::Copy()
{
WriteClipboardText(~text);
Break();
}
struct QtfDlgEditor : TopWindow {
RichEditWithToolBar editor;
void Serialize(Stream& s);
QtfDlgEditor();
};
void QtfDlgEditor::Serialize(Stream& s)
{
SerializePlacement(s);
}
QtfDlgEditor::QtfDlgEditor()
{
Add(editor.SizePos());
Rect r = GetWorkArea();
SetRect(0, 0, r.GetWidth() - 100, r.GetHeight() - 100);
}
void QtfDlg::Editor()
{
QtfDlgEditor dlg;
LoadFromGlobal(dlg, "QTF-designer-editor");
dlg.editor.SetQTF((String)~text);
dlg.Run();
if(PromptYesNo("Use the text?")) {
text <<= AsQTF(dlg.editor.Get(),
CHARSET_UTF8, QTF_BODY|QTF_NOSTYLES|QTF_NOCHARSET|QTF_NOLANG);
Text();
}
StoreToGlobal(dlg, "QTF-designer-editor");
}
QtfDlg::QtfDlg()
{
CtrlLayout(*this, "QTF designer");
text <<= THISBACK(Text);
qtf.SetFrame(ViewFrame());
qtf.Background(SColorPaper);
Sizeable().Zoomable();
Rect r = GetWorkArea();
SetRect(0, 0, r.GetWidth() - 100, r.GetHeight() - 200);
String path = AppendFileName(AppendFileName(PackageDirectory("RichText"), "srcdoc.tpp"), "QTF$en-us.tpp");
if(FileExists(path))
help.SetQTF(ReadTopic(LoadFile(path)).text);
else
help <<= "[= &&&QTF documentation not found";
clear <<= THISBACK(Clear);
copy <<= THISBACK(Copy);
editor <<= THISBACK(Editor);
}
void QtfDlg::Serialize(Stream& s)
{
int version = 0;
s / version;
s % text;
SerializePlacement(s);
Text();
}
void Ide::Qtf()
{
QtfDlg dlg;
LoadFromGlobal(dlg, "QTF-designer");
int l,h;
bool sel=editor.GetSelection(l,h);
if(qtfsel && sel){
dlg.text<<=(~editor).ToString().Mid(l,h-l);
dlg.copy.SetLabel("Apply and close");
dlg.Run();
editor.Remove(l,h-l);
editor.Insert(l,(~dlg.text).ToString());
}
else{
dlg.copy.SetLabel("Copy and close");
dlg.Run();
}
StoreToGlobal(dlg, "QTF-designer");
}
#include "ide.h"
INITBLOCK {
RegisterGlobalConfig("QTF-designer");
RegisterGlobalConfig("QTF-designer-editor");
}
class QtfDlg : public TopWindow {
typedef QtfDlg CLASSNAME;
void Text();
void Clear();
void Copy();
void Editor();
public:
Splitter leftSplit, mainSplit;
WithQtfLayout<ParentCtrl> qtfText;
RichTextCtrl qtf;
RichTextView help;
void Serialize(Stream& s);
QtfDlg();
};
void QtfDlg::Text()
{
qtf <<= ~qtfText.text;
}
void QtfDlg::Clear()
{
qtfText.text.Clear();
Text();
}
void QtfDlg::Copy()
{
WriteClipboardText(~qtfText.text);
Break();
}
struct QtfDlgEditor : TopWindow {
RichEditWithToolBar editor;
void Serialize(Stream& s);
QtfDlgEditor();
};
void QtfDlgEditor::Serialize(Stream& s)
{
SerializePlacement(s);
}
QtfDlgEditor::QtfDlgEditor()
{
Add(editor.SizePos());
Rect r = GetWorkArea();
SetRect(0, 0, r.GetWidth() - 100, r.GetHeight() - 100);
}
void QtfDlg::Editor()
{
QtfDlgEditor dlg;
LoadFromGlobal(dlg, "QTF-designer-editor");
dlg.editor.SetQTF((String)~qtfText.text);
dlg.Run();
if(PromptYesNo("Use the text?")) {
qtfText.text <<= AsQTF(dlg.editor.Get(),
CHARSET_UTF8, QTF_BODY|QTF_NOSTYLES|QTF_NOCHARSET|QTF_NOLANG);
Text();
}
StoreToGlobal(dlg, "QTF-designer-editor");
}
QtfDlg::QtfDlg()
{
Title("QTF designer");
CtrlLayout(qtfText);
qtfText.text <<= THISBACK(Text);
qtf.SetFrame(ViewFrame());
qtf.Background(SColorPaper);
Sizeable().Zoomable();
Rect r = GetWorkArea();
SetRect(0, 0, r.GetWidth() - 100, r.GetHeight() - 200);
SetMinSize(Size(min(640, r.GetWidth() - 100), min(480, r.GetHeight() - 200)));
String path = AppendFileName(AppendFileName(PackageDirectory("RichText"), "srcdoc.tpp"), "QTF$en-us.tpp");
if(FileExists(path))
help.SetQTF(ReadTopic(LoadFile(path)).text);
else
help <<= "[= &&&QTF documentation not found";
qtfText.clear <<= THISBACK(Clear);
qtfText.copy <<= THISBACK(Copy);
qtfText.editor <<= THISBACK(Editor);
leftSplit.Vert(qtfText, qtf).SetPos(4000);
mainSplit.Horz(leftSplit, help).SetPos(3500);
Add(mainSplit.HSizePosZ(4, 4).VSizePosZ(4, 4));
}
void QtfDlg::Serialize(Stream& s)
{
int version = 1;
s / version;
s % qtfText.text;
SerializePlacement(s);
if(version >= 1) {
leftSplit.Serialize(s);
mainSplit.Serialize(s);
}
Text();
}
void Ide::Qtf()
{
QtfDlg dlg;
LoadFromGlobal(dlg, "QTF-designer");
int l,h;
bool sel=editor.GetSelection(l,h);
if(qtfsel && sel){
dlg.qtfText.text<<=(~editor).ToString().Mid(l,h-l);
dlg.qtfText.copy.SetLabel("Apply and close");
dlg.Run();
editor.Remove(l,h-l);
editor.Insert(l,(~dlg.qtfText.text).ToString());
}
else{
dlg.qtfText.copy.SetLabel("Copy and close");
dlg.Run();
}
StoreToGlobal(dlg, "QTF-designer");
}

View file

@ -627,12 +627,10 @@ LAYOUT(ImportLayout, 400, 92)
ITEM(Button, cancel, SetLabel(t_("Cancel")).LeftPosZ(328, 64).TopPosZ(60, 24))
END_LAYOUT
LAYOUT(QtfLayout, 964, 584)
ITEM(DocEdit, text, LeftPosZ(4, 348).TopPosZ(28, 204))
ITEM(RichTextCtrl, qtf, LeftPosZ(4, 348).VSizePosZ(236, 8))
ITEM(RichTextView, help, HSizePosZ(356, 4).VSizePosZ(4, 8))
ITEM(Button, editor, SetLabel(t_("Editor")).LeftPosZ(296, 56).TopPosZ(4, 20))
ITEM(Button, clear, SetLabel(t_("Clear")).LeftPosZ(232, 56).TopPosZ(4, 20))
ITEM(Button, copy, SetLabel(t_("Copy and close")).LeftPosZ(128, 100).TopPosZ(4, 20))
LAYOUT(QtfLayout, 356, 236)
ITEM(DocEdit, text, HSizePosZ(0, 0).VSizePosZ(24, 0))
ITEM(Button, editor, SetLabel(t_("Editor")).RightPosZ(0, 56).TopPosZ(0, 20))
ITEM(Button, clear, SetLabel(t_("Clear")).RightPosZ(60, 56).TopPosZ(0, 20))
ITEM(Button, copy, SetLabel(t_("Copy and close")).RightPosZ(120, 100).TopPosZ(0, 20))
END_LAYOUT