-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhighlighter.h
45 lines (41 loc) · 1.03 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
#ifndef HIGHLIGHTER_H
#define HIGHLIGHTER_H
#include "editor.h"
#include <QSyntaxHighlighter>
#include <QTextDocument>
#include <QTextEdit>
#include <QString>
#include <QVector>
#include <QTextFormat>
#include <QFont>
#include <QColor>
class Editor;
class Highlighter : public QSyntaxHighlighter
{
private:
// Q_OBJECT macro
Q_OBJECT
// Highlightingrule Struct
struct HighlightingRule
{
QRegExp word,start,end;
QTextCharFormat format;
};
// Vector of highlightingrules
QVector<HighlightingRule> multiRules;
QVector<HighlightingRule> singleRules;
// Pointer to editor
Editor * editor;
// Helper method
void findFormatHelper(QString& data,HighlightingRule& rule,int i);
protected:
void highlightBlock(const QString &text);
public:
// Constructor
Highlighter(Editor * editor, QTextDocument *parent = 0);
// Methods
void loadSyntax(QString filename);
void selectSyntax();
QString translate(QString str);
};
#endif // HIGHLIGHTER_H