-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocument.h
121 lines (85 loc) · 2.35 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
#ifndef DOCUMENT_H
#define DOCUMENT_H
#include <QVector>
#include <QString>
#include <QRegularExpression>
#include <QPlainTextEdit>
#include <QCompleter>
#include <QSyntaxHighlighter>
#include <QTextCharFormat>
#include <QObject>
#include "theme.h"
#include "project.h"
class LineNumberArea;
class Highlighter;
class Document : public QPlainTextEdit {
Q_OBJECT
public:
//
Document(Project *project_, Theme theme_, QWidget *parent = nullptr);
Project *project;
Theme theme;
QString filepath;
QSet<QString> labels;// to jump around for labels
void lineNumberAreaPaintEvent(QPaintEvent *event);
void setCompleter(QCompleter *c);
int lineNumberAreaWidth();
QCompleter *completer() const;
protected:
void resizeEvent(QResizeEvent *event) override;
private slots:
void updateLineNumberAreaWidth();
void highlightCurrentLine();
void updateLineNumberArea(const QRect &, int);
void insertCompletion(const QString &completion);
private:
QWidget *lineNumberArea;
QCompleter *completer_;
};
class LineNumberArea : public QWidget {
public:
LineNumberArea(Document *editor) : QWidget(editor) {
document = editor;
}
QSize sizeHint() const override {
return QSize(document->lineNumberAreaWidth(), 0);
}
protected:
void paintEvent(QPaintEvent *event) override {
document->lineNumberAreaPaintEvent(event);
}
private:
Document *document;
};
class Highlighter : public QSyntaxHighlighter {
Q_OBJECT
public:
Highlighter(Document *parent = 0);
protected:
void highlightBlock(const QString &text) override;
private:
struct HighlightingRule
{
QRegularExpression pattern;
QTextCharFormat format;
};
QVector<HighlightingRule> highlightingRules;
QRegularExpression commentStartExpression;
QRegularExpression commentEndExpression;
QTextCharFormat keywordFormat;
QTextCharFormat scriptLabelFormat; // functionColor
QTextCharFormat singleLineCommentFormat;
QTextCharFormat multiLineCommentFormat;
QTextCharFormat quotationFormat; // quotedStringColor
QTextCharFormat functionFormat;
QTextCharFormat numberFormat;
QTextCharFormat hexadecimalFormat;
};
/*
class TabWidget : public QTabWidget {
//
public:
TabWidget(QWidget *parent = 0) : QTabWidget(parent) {}
};
*/
#endif // DOCUMENT_H