Qtf.cpp

Zbigniew Rebacz, 11/13/2013 12:36 PM

Download (2.97 KB)

 
1
#include "ide.h"
2

    
3
INITBLOCK {
4
        RegisterGlobalConfig("QTF-designer");
5
        RegisterGlobalConfig("QTF-designer-editor");
6
}
7

    
8
class QtfDlg : public TopWindow {
9
        typedef QtfDlg CLASSNAME;
10

    
11
        void Text();
12
        void Clear();
13
        void Copy();
14
        void Editor();
15

    
16
public:
17
        Splitter leftSplit, mainSplit;
18
        WithQtfLayout<ParentCtrl> qtfText;
19
        RichTextCtrl qtf;
20
        RichTextView help;
21

    
22
        void Serialize(Stream& s);
23

    
24
        QtfDlg();
25
};
26

    
27
void QtfDlg::Text()
28
{
29
        qtf <<= ~qtfText.text;
30
}
31

    
32
void QtfDlg::Clear()
33
{
34
        qtfText.text.Clear();
35
        Text();
36
}
37

    
38
void QtfDlg::Copy()
39
{
40
        WriteClipboardText(~qtfText.text);
41
        Break();
42
}
43

    
44
struct QtfDlgEditor : TopWindow {
45
        RichEditWithToolBar editor;
46

    
47
        void Serialize(Stream& s);        
48
        
49
        QtfDlgEditor();
50
};
51

    
52
void QtfDlgEditor::Serialize(Stream& s)
53
{
54
        SerializePlacement(s);
55
}
56

    
57
QtfDlgEditor::QtfDlgEditor()
58
{
59
    Add(editor.SizePos());
60
    Rect r = GetWorkArea();
61
    Sizeable().Zoomable();
62
    SetRect(0, 0, r.GetWidth() - 100, r.GetHeight() - 100);
63
    SetMinSize(Size(min(640, r.GetWidth() - 100), min(480, r.GetHeight() - 100)));
64
    Title("Editor");
65
}
66

    
67
void QtfDlg::Editor()
68
{
69
        QtfDlgEditor dlg;
70
        LoadFromGlobal(dlg, "QTF-designer-editor");
71
        dlg.editor.SetQTF((String)~qtfText.text);
72
        dlg.Run();
73
        if(PromptYesNo("Use the text?")) {
74
                qtfText.text <<= AsQTF(dlg.editor.Get(),
75
                               CHARSET_UTF8, QTF_BODY|QTF_NOSTYLES|QTF_NOCHARSET|QTF_NOLANG);
76
                Text();
77
        }
78
        StoreToGlobal(dlg, "QTF-designer-editor");
79
}
80

    
81
QtfDlg::QtfDlg()
82
{
83
        Title("QTF designer");
84
        CtrlLayout(qtfText);
85
        qtfText.text <<= THISBACK(Text);
86
        qtf.SetFrame(ViewFrame());
87
        qtf.Background(SColorPaper);
88
        Sizeable().Zoomable();
89
        Rect r = GetWorkArea();
90
        SetRect(0, 0, r.GetWidth() - 100, r.GetHeight() - 200);
91
        SetMinSize(Size(min(640, r.GetWidth() - 100), min(480, r.GetHeight() - 200)));
92

    
93
        help.Margins(Rect(12, 0, 12, 0));
94
        String path = AppendFileName(AppendFileName(PackageDirectory("RichText"), "srcdoc.tpp"), "QTF$en-us.tpp");
95
        if(FileExists(path))
96
                help.SetQTF(ReadTopic(LoadFile(path)).text);
97
        else
98
                help <<= "[= &&&QTF documentation not found";
99

    
100
        qtfText.clear <<= THISBACK(Clear);
101
        qtfText.copy <<= THISBACK(Copy);
102
        qtfText.editor <<= THISBACK(Editor);
103

    
104
        leftSplit.Vert(qtfText, qtf).SetPos(4000);
105
        mainSplit.Horz(leftSplit, help).SetPos(3500);
106
        Add(mainSplit.HSizePosZ(4, 4).VSizePosZ(4, 4));
107
}
108

    
109
void QtfDlg::Serialize(Stream& s)
110
{
111
        int version = 1;
112
        s / version;
113
        s % qtfText.text;
114
        SerializePlacement(s);
115
        if(version >= 1) {
116
                leftSplit.Serialize(s);
117
                mainSplit.Serialize(s);
118
        }
119
        Text();
120
}
121

    
122
void Ide::Qtf()
123
{
124
        QtfDlg dlg;
125
        LoadFromGlobal(dlg, "QTF-designer");
126
        int l,h;
127
        bool sel=editor.GetSelection(l,h);
128
        if(qtfsel && sel){
129
                dlg.qtfText.text<<=(~editor).ToString().Mid(l,h-l);
130
                dlg.qtfText.copy.SetLabel("Apply and close");
131
                dlg.Run();
132
                editor.Remove(l,h-l);
133
                editor.Insert(l,(~dlg.qtfText.text).ToString());
134
        }
135
        else{
136
                dlg.qtfText.copy.SetLabel("Copy and close");
137
                dlg.Run();
138
        }
139
        StoreToGlobal(dlg, "QTF-designer");
140
}