-
Notifications
You must be signed in to change notification settings - Fork 2
/
highlighter.h
58 lines (51 loc) · 1.6 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
#ifndef HIGHLIGHTER_H
#define HIGHLIGHTER_H
#include <QSyntaxHighlighter>
#include "texteditor.h"
class Highlighter : public QSyntaxHighlighter
{
Q_OBJECT
public:
typedef struct tagKeywordRule
{
QRegExp pattern;
QTextCharFormat format;
} KeywordRule;
typedef struct tagBlockwordRule
{
int index;
int depth;
QRegExp beginPattern;
QRegExp endPattern;
QTextCharFormat format;
} BlockwordRule;
explicit Highlighter(QTextDocument *parent = 0);
void rehighlight();
void updateHighlightFormats(const QList<QVariant> &formats);
void updateFindFormats(const QList<QVariant> &formats);
void updateKeywords(const QList<QVariant> &words);
void updateBlockwords(const QList<QVariant> &words);
void updateFindwords(const TextEditor::KeywordData words[]);
QVector<int> findwordMatchLines(int index) const;
inline int findwordCount(int index) const
{
return findwordsCount[index];
}
protected:
void highlightBlock(const QString &text);
public:
static QRegExp convertText(QString text, const TextEditor::KeywordOption &option);
static QTextCharFormat convertFormat(const TextEditor::TextFormat &format);
private:
QList<QVariant> highlightFormats;
QList<QVariant> findFormats;
QList<QVariant> keywords;
QList<QVariant> blockwords;
TextEditor::KeywordData findwords[10];
QVector<KeywordRule> keywordRules;
QVector<BlockwordRule> blockwordRules;
QVector<KeywordRule> findRules;
int findwordsCount[10];
QVector<int> findwordsLine[10];
};
#endif // HIGHLIGHTER_H