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