forked from psemiletov/tea-qt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
document.h
435 lines (289 loc) · 9.9 KB
/
document.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
/***************************************************************************
* 2007-2018 by Peter Semiletov <[email protected]> *
* *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
**************************************************************************/
/*
Copyright (C) 2006-2008 Trolltech ASA. All rights reserved.
*/
/*
Diego Iastrubni <[email protected]> //some GPL'ed code from new-editor-diego-3, found on qtcentre forum
*/
/*
code from qwriter:
* Copyright (C) 2009 by Gancov Kostya *
*/
#ifndef DOCUMENT_H
#define DOCUMENT_H
#include "logmemo.h"
#include "tio.h"
#include "todo.h"
#include <QPoint>
#include <QStatusBar>
#include <QMainWindow>
#include <QTabWidget>
#include <QPlainTextEdit>
#include <QSyntaxHighlighter>
//#include <QDebug>
#if QT_VERSION >= 0x050000
#include <QRegularExpression>
#endif
#include "qgamecontroller.h"
class LineNumberArea;
class document_holder;
class CDocument;
class CTEAEdit: public QPlainTextEdit
{
Q_OBJECT
public:
QString indent_val;
QList <QTextEdit::ExtraSelection> extraSelections;
QTextEdit::ExtraSelection brace_selection;
//rect selection
QPoint rect_sel_start;
QPoint rect_sel_end;
CDocument *doc;
QColor currentLineColor;
QColor brackets_color;
QColor margin_color;
QColor linenums_bg;
QColor text_color;
QColor sel_text_color;
QColor sel_back_color;
QWidget *lineNumberArea;
bool highlightCurrentLine;
bool hl_brackets;
bool draw_margin;
bool draw_linenums;
bool use_hl_wrap;
bool wrap;
bool auto_indent;
bool spaces_instead_of_tabs;
int tab_sp_width; //in spaces
int brace_width; //in pixels
int margin_pos; //in chars
int margin_x; //in pixels
CTEAEdit (QWidget *parent = 0);
void setCurrentLineColor (const QColor &newColor);
void set_brackets_color (const QColor &newColor);
void set_show_linenums (bool enable);
void set_show_margin (bool enable);
void set_margin_pos (int mp);
void set_hl_cur_line (bool enable);
void set_hl_brackets (bool enable);
void indent();
void un_indent();
void calc_auto_indent();
void setup_brace_width();
void text_replace (const QString &s);
void rect_sel_reset();
void rect_sel_replace (const QString &s, bool insert = false);
//void rect_sel_insert (const QString &s);
void update_ext_selections();
void update_rect_sel();
QString get_rect_sel();
void rect_sel_cut (bool just_del = false);
void braceHighlight();
void lineNumberAreaPaintEvent(QPaintEvent *event);
int lineNumberAreaWidth();
Q_INVOKABLE bool has_rect_selection();
protected:
bool canInsertFromMimeData (const QMimeData *source);
void insertFromMimeData (const QMimeData *source);
QMimeData* createMimeDataFromSelection();
void paintEvent(QPaintEvent *event);
void keyPressEvent (QKeyEvent *event);
void resizeEvent(QResizeEvent *event);
/*
bool event(QEvent *ev) {
if (ev->type() == QEvent::KeyboardLayoutChange) {
qDebug() << "kb layout changed";
} else {
return QWidget::event(ev);
}
}
*/
public slots:
void updateLineNumberAreaWidth (int newBlockCount);
void cb_cursorPositionChanged();
void updateLineNumberArea (const QRect &, int);
void slot_selectionChanged();
void handleQGameControllerAxisEvent(QGameControllerAxisEvent *event);
void handleQGameControllerButtonEvent(QGameControllerButtonEvent *event);
// void copy();
};
class CSyntaxHighlighter: public QSyntaxHighlighter
{
public:
CSyntaxHighlighter (QTextDocument *parent = 0, CDocument *doc = 0, const QString &fname = "none");
CDocument *document;
bool casecare;
bool wrap;
int xml_format;
QString exts;
QString langs;
QString cm_mult;
QString cm_single;
QTextCharFormat singleLineCommentFormat;
QTextCharFormat multiLineCommentFormat;
};
class CSyntaxHighlighterQRegExp: public CSyntaxHighlighter
{
Q_OBJECT
protected:
void highlightBlock (const QString &text);
public:
struct HighlightingRule
{
QRegExp pattern;
QTextCharFormat format;
};
QRegExp commentStartExpression;
QRegExp commentEndExpression;
Qt::CaseSensitivity cs;
CSyntaxHighlighterQRegExp (QTextDocument *parent = 0, CDocument *doc = 0, const QString &fname = "none");
QVector <HighlightingRule> highlightingRules;
void load_from_xml (const QString &fname);
};
#if QT_VERSION >= 0x050000
class CSyntaxHighlighterQRegularExpression: public CSyntaxHighlighter
{
Q_OBJECT
protected:
void highlightBlock (const QString &text);
public:
struct HighlightingRule
{
QRegularExpression pattern;
QTextCharFormat format;
};
QRegularExpression commentStartExpression;
QRegularExpression commentEndExpression;
QRegularExpression::PatternOptions pattern_opts;
CSyntaxHighlighterQRegularExpression (QTextDocument *parent = 0, CDocument *doc = 0, const QString &fname = "none");
QVector <HighlightingRule> highlightingRules;
QTextCharFormat singleLineCommentFormat;
QTextCharFormat multiLineCommentFormat;
void load_from_xml (const QString &fname);
};
#endif
class CDocument: public QObject
{
Q_OBJECT
public:
bool cursor_xy_visible;
QHash <QString, QString> fnameswoexts;
QString eol;
document_holder *holder;
CSyntaxHighlighter *highlighter;
CTEAEdit *textEdit;
QStringList labels;
QString markup_mode;
QString file_name;
QString text_to_search;
QString charset;
QWidget *tab_page;
int position;
CDocument (QObject *parent = 0);
~CDocument();
Q_INVOKABLE QString get_selected_text() const;
Q_INVOKABLE void set_selected_text (const QString &value);
void create_new();
Q_INVOKABLE void set_tab_caption (const QString &fileName);
Q_INVOKABLE bool save_with_name (const QString &fileName, const QString &codec);
Q_INVOKABLE bool save_with_name_plain (const QString &fileName);
Q_INVOKABLE void goto_pos (int pos);
Q_INVOKABLE QString get_filename_at_cursor();
Q_INVOKABLE QStringList get_words();
Q_INVOKABLE void set_hl (bool mode_auto = true, const QString &theext = "txt");
Q_INVOKABLE bool open_file (const QString &fileName, const QString &codec);
Q_INVOKABLE void insert_image (const QString &full_path);
Q_INVOKABLE void set_markup_mode();
Q_INVOKABLE void reload (const QString &enc);
Q_INVOKABLE int get_tab_idx();
Q_INVOKABLE QString get_triplex();
Q_INVOKABLE void update_status();
Q_INVOKABLE void update_title (bool fullname = true);
Q_INVOKABLE void update_labels();
};
class document_holder: public QObject
{
Q_OBJECT
public:
CTioHandler tio_handler;
QString fname_current_session;
// QHash <QString, QString> palette;
QHash <QString, QString> hls;
QLabel *l_status_bar;
QString dir_config;
QString fname_crapbook;
CTodo todo;
QString markup_mode;
QStatusBar *status_bar;
CLogMemo *log;
QList <CDocument*> list;
QMainWindow *parent_wnd;
QTabWidget *tab_widget;
QMenu *recent_menu;
QStringList recent_files;
QString recent_list_fname;
QGameController *gameController;
QTimer *timer;
document_holder();
~document_holder();
Q_INVOKABLE CDocument* create_new();
Q_INVOKABLE CDocument* open_file (const QString &fileName, const QString &codec);
Q_INVOKABLE CDocument* open_file_triplex (const QString &triplex);
Q_INVOKABLE CDocument* get_document_by_fname (const QString &fileName);
void reload_recent_list();
Q_INVOKABLE void save_to_session (const QString &fileName);
Q_INVOKABLE void load_from_session (const QString &fileName);
//QHash <QString, QString> load_eclipse_theme_xml (const QString &fname);
//void load_palette (const QString &fileName);
void close_by_idx (int i);
Q_INVOKABLE void close_current();
Q_INVOKABLE void apply_settings();
Q_INVOKABLE void apply_settings_single (CDocument *d);
void add_to_recent (CDocument *d);
void update_recent_menu();
void update_current_files_menu();
Q_INVOKABLE CDocument* get_current();
public slots:
void open_recent();
void open_current();
void handleQGameControllerAxisEvent(QGameControllerAxisEvent *event);
void handleQGameControllerButtonEvent(QGameControllerButtonEvent *event);
};
class CLineNumberArea: public QWidget
{
public:
CTEAEdit *codeEditor;
CLineNumberArea (CTEAEdit *editor = 0): QWidget (editor)
{
codeEditor = editor;
}
QSize sizeHint() const {
return QSize(codeEditor->lineNumberAreaWidth(), 0);
}
protected:
void paintEvent (QPaintEvent *event)
{
codeEditor->lineNumberAreaPaintEvent (event);
}
};
#endif