summaryrefslogtreecommitdiff
path: root/utils/wpseditor/gui/src/qsyntaxer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'utils/wpseditor/gui/src/qsyntaxer.cpp')
-rw-r--r--utils/wpseditor/gui/src/qsyntaxer.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/utils/wpseditor/gui/src/qsyntaxer.cpp b/utils/wpseditor/gui/src/qsyntaxer.cpp
new file mode 100644
index 0000000000..412ca38148
--- /dev/null
+++ b/utils/wpseditor/gui/src/qsyntaxer.cpp
@@ -0,0 +1,44 @@
1#include <QTextCharFormat>
2
3#include "qsyntaxer.h"
4
5QSyntaxer::QSyntaxer(QTextDocument *parent)
6 : QSyntaxHighlighter(parent) {
7 HighlightingRule rule;
8
9 hrules["operator"].pattern = QRegExp("%[^\\| \n<\\?%]{1,2}");
10 hrules["operator"].format.setFontWeight(QFont::Bold);
11 hrules["operator"].format.setForeground(Qt::darkBlue);
12
13
14 hrules["question"].pattern = QRegExp("%[\\?]{1}[^<]{1,2}");
15 hrules["question"].format.setForeground(Qt::darkMagenta);
16
17 hrules["question2"].pattern = QRegExp("(<|>)");
18 hrules["question2"].format.setForeground(Qt::red);
19
20
21 hrules["limiter"].pattern = QRegExp("\\|");
22 hrules["limiter"].format.setForeground(Qt::darkRed);
23
24 hrules["comment"].pattern = QRegExp("#[^\n]*");
25 hrules["comment"].format.setForeground(Qt::darkGreen);
26 hrules["comment"].format.setFontItalic(true);
27}
28//
29void QSyntaxer::highlightBlock(const QString &text) {
30 QTextCharFormat wholeText;
31 wholeText.setFont(QFont("arial",11,QFont::Normal));
32 setFormat(0,text.length(),wholeText);
33
34 foreach (HighlightingRule rule, hrules) {
35 QRegExp expression(rule.pattern);
36 int index = text.indexOf(expression);
37 while (index >= 0) {
38 int length = expression.matchedLength();
39 setFormat(index, length, rule.format);
40 index = text.indexOf(expression, index + length);
41 }
42 }
43
44}