-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhighlighter.h
76 lines (72 loc) · 2.93 KB
/
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
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
#ifndef HIGHLIGHTER_H
#define HIGHLIGHTER_H
#include<QSyntaxHighlighter>
#include<QRegularExpression>
class HighLighter:public QSyntaxHighlighter{
Q_OBJECT
public:
HighLighter(QTextDocument* parent=nullptr):QSyntaxHighlighter(parent){}
virtual void addKeywords(QStringList keywords);
virtual void setClassPattern(QRegularExpression classPattern);
virtual void setFunctionPattern(QRegularExpression functionPattern);
virtual void setQuotePattern(QRegularExpression quotePattern);
virtual void setInlineCommentPattern(QRegularExpression inlineCommentPattern);
virtual void setBlockCommentStartPattern(QRegularExpression blockCommentStart);
virtual void setBlockCommentEndPattern(QRegularExpression blockCommentEnd);
virtual void setDividePattern(QRegularExpression dividePattern);
virtual void addRule(QRegularExpression pattern,QTextCharFormat format);
virtual void setDeletePattern(QRegularExpression deletePattern);
virtual void setUnderlinePattern(QRegularExpression underlinePattern);
virtual void setFootnotePattern(QRegularExpression footnotePattern);
virtual void setBlockPattern(QRegularExpression blockPattern);
virtual void setCodePattern(QRegularExpression codePattern);
virtual void setLinkPattern(QRegularExpression linkPattern);
protected:
virtual void highlightBlock(const QString &text) override;
virtual void highlightMultilineComments(const QString &text);
virtual void setKeywordFormat();
virtual void setClassFormat();
virtual void setFunctionFormat();
virtual void setQuoteFormat();
virtual void setInlineCommentFormat();
virtual void setBlockCommentFormat();
virtual void setDivideFormat();
virtual void setDeleteFormat();
virtual void setUnderlineFormat();
virtual void setFootnoteFormat();
virtual void setBlockFormat();
virtual void setCodeFormat();
virtual void setLinkFormat();
private:
struct HighlightingRule{
QRegularExpression pattern;
QTextCharFormat format;
};
QVector<HighlightingRule> rules;
QRegularExpression blockCommentStart;
QRegularExpression blockCommentEnd;
QTextCharFormat keywordFormat;
QTextCharFormat classFormat;
QTextCharFormat inlineCommentFormat;
QTextCharFormat blockCommentFormat;
QTextCharFormat quoteFormat;
QTextCharFormat functionFormat;
QTextCharFormat divideFormat;
QTextCharFormat deleteFormat;
QTextCharFormat underlineFormat;
QTextCharFormat footnoteFormat;
QTextCharFormat blockFormat;
QTextCharFormat codeFormat;
QTextCharFormat linkFormat;
};
enum BlockState{
NotInComment,
InComment
};
HighLighter *cHighlighter(QTextDocument* doc);
HighLighter *cppHighlighter(QTextDocument *doc);
HighLighter *javaHighlighter(QTextDocument *doc);
HighLighter *pythonHighlighter(QTextDocument *doc);
HighLighter *markdownHighlighter(QTextDocument *doc);
HighLighter *testLighter(QTextDocument *doc);
#endif // HIGHLIGHTER_H