-
Notifications
You must be signed in to change notification settings - Fork 0
/
qcodetextedit.h
126 lines (102 loc) · 3.01 KB
/
qcodetextedit.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
#ifndef QCODETEXTEDIT_H
#define QCODETEXTEDIT_H
#include <QPlainTextEdit>
#include <QSyntaxHighlighter>
class CPPSyntaxHighlighter : public QSyntaxHighlighter
{
Q_OBJECT
public:
CPPSyntaxHighlighter(QTextDocument* Parent = 0);
protected:
void highlightBlock(const QString& text);
private:
struct HighlightingRule
{
QRegExp Pattern;
QTextCharFormat Format;
};
QVector<HighlightingRule> Rules;
QRegExp CommentStartExpression;
QRegExp CommentEndExpression;
QTextCharFormat KeywordFormat;
QTextCharFormat ClassFormat;
QTextCharFormat SingleLineCommentFormat;
QTextCharFormat MultiLineCommentFormat;
QTextCharFormat QuotationFormat;
QTextCharFormat FunctionFormat;
};
class LLVMSyntaxHighlighter : public QSyntaxHighlighter
{
Q_OBJECT
public:
LLVMSyntaxHighlighter(QTextDocument* Parent = 0);
protected:
void highlightBlock(const QString& text);
private:
struct HighlightingRule
{
QRegExp Pattern;
QTextCharFormat Format;
};
QVector<HighlightingRule> Rules;
QRegExp CommentStartExpression;
QRegExp CommentEndExpression;
QTextCharFormat KeywordFormat;
QTextCharFormat ClassFormat;
QTextCharFormat SingleLineCommentFormat;
QTextCharFormat MultiLineCommentFormat;
QTextCharFormat QuotationFormat;
QTextCharFormat FunctionFormat;
};
class QCodeTextEdit : public QPlainTextEdit
{
Q_OBJECT
public:
explicit QCodeTextEdit(QWidget* parent = nullptr);
void LineNumberAreaPaintEvent(QPaintEvent* event);
int LineNumberAreaWidth() const;
inline QColor setTextColor(const QColor& color)
{
QPalette p = palette();
QColor old = p.color(QPalette::Text);
p.setColor(QPalette::Text,color);
setPalette(p);
return old;
}
inline QColor setTextBackgroundColor(const QColor& color)
{
QPalette p = palette();
QColor old = p.color(QPalette::Background);
p.setColor(QPalette::Text,color);
setPalette(p);
return old;
}
protected:
void resizeEvent(QResizeEvent *event);
private slots:
void UpdateLineNumberAreaWidth(int NewBlockCount);
void HighlightCurrentLine();
void UpdateLineNumberArea(const QRect&, int);
private:
QWidget* LineNumberArea;
};
class QLineNumberArea : public QWidget
{
public:
QLineNumberArea(QCodeTextEdit* editor) : QWidget(editor)
{
Editor = editor;
}
QSize sizeHint() const
{
return QSize(Editor->LineNumberAreaWidth(),0);
}
protected:
void paintEvent(QPaintEvent* event)
{
Editor->LineNumberAreaPaintEvent(event);
}
private:
QCodeTextEdit* Editor;
};
#endif // QCODETEXTEDIT_H