-
Notifications
You must be signed in to change notification settings - Fork 0
/
highlighter.h
48 lines (31 loc) · 874 Bytes
/
highlighter.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
#ifndef HIGHLIGHTER_H
#define HIGHLIGHTER_H
#include <QObject>
#include <QSyntaxHighlighter>
#include <QRegularExpression>
class Highlighter : public QSyntaxHighlighter
{
public:
explicit Highlighter(QTextDocument *parent = nullptr, QString font_family = "Consolas", int font_size = 13);
protected:
virtual void highlightBlock(const QString &text);
private:
void addNormalTextRule();
void addNumberRule();
void addStringRule();
void addCommentRule();
void addMultiLineCommentRule(const QString &text);
void addKeyWordRule();
void addClassNameRule();
void addFuntionRule();
private:
struct HighlightRule // 高亮规则
{
QRegularExpression pattern;
QTextCharFormat format;
};
QVector<HighlightRule> highlightRules;
QString fontFamily;
int fontSize;
};
#endif // HIGHLIGHTER_H