Index: utils/wpseditor/gui/src/qsyntaxer.cpp =================================================================== --- utils/wpseditor/gui/src/qsyntaxer.cpp (revision 0) +++ utils/wpseditor/gui/src/qsyntaxer.cpp (revision 0) @@ -0,0 +1,46 @@ +#include "qsyntaxer.h" +// +QSyntaxer::QSyntaxer(QTextDocument *parent) + : QSyntaxHighlighter(parent) { + HighlightingRule rule; + + operatorFormat.setForeground(Qt::darkBlue); + operatorFormat.setFontWeight(QFont::Bold); + rule.pattern = QRegExp("%[^\\| \n<\\?%]{1,2}"); + rule.format = operatorFormat; + highlightingRules.append(rule); + + questionFormat.setForeground(Qt::darkMagenta); + rule.pattern = QRegExp("%[\\?]{1}[^<]{1,2}"); + rule.format = questionFormat; + highlightingRules.append(rule); + + question2Format.setForeground(Qt::red); + rule.pattern = QRegExp("(<|>)"); + rule.format = question2Format; + highlightingRules.append(rule); + + limiterFormat.setForeground(Qt::darkRed); + rule.pattern = QRegExp("\\|"); + rule.format = limiterFormat; + highlightingRules.append(rule); + + commentFormat.setForeground(Qt::darkGreen); + commentFormat.setFontItalic(true); + operatorFormat.setFontWeight(QFont::Normal); + rule.pattern = QRegExp("#[^\n]*"); + rule.format = commentFormat; + highlightingRules.append(rule); +} +// +void QSyntaxer::highlightBlock(const QString &text) { + foreach (HighlightingRule rule, highlightingRules) { + QRegExp expression(rule.pattern); + int index = text.indexOf(expression); + while (index >= 0) { + int length = expression.matchedLength(); + setFormat(index, length, rule.format); + index = text.indexOf(expression, index + length); + } + } +} Index: utils/wpseditor/gui/src/qsyntaxer.h =================================================================== --- utils/wpseditor/gui/src/qsyntaxer.h (revision 0) +++ utils/wpseditor/gui/src/qsyntaxer.h (revision 0) @@ -0,0 +1,26 @@ +#ifndef QSYNTAXER_H +#define QSYNTAXER_H +// +#include +#include +// +class QSyntaxer : public QSyntaxHighlighter { + Q_OBJECT + QTextCharFormat commentFormat; + QTextCharFormat operatorFormat; + QTextCharFormat questionFormat; + QTextCharFormat question2Format; + QTextCharFormat limiterFormat; + struct HighlightingRule { + QRegExp pattern; + QTextCharFormat format; + }; + QVector highlightingRules; +public: + QSyntaxer(QTextDocument *parent = 0); + +protected: + void highlightBlock(const QString &text); + +}; +#endif