6 : QSyntaxHighlighter(parent)
12 QStringList keywordPatterns;
13 keywordPatterns <<
"\\break\\b" <<
"\\bcase\\b" <<
"\\bcatch\\b"
14 <<
"\\bcontinue\\b" <<
"\\bdefault\\b" <<
"\\bdelete\\b"
15 <<
"\\bdo\\b" <<
"\\belse\\b" <<
"\\bfinally\\b"
16 <<
"\\bfor\\b" <<
"\\bfunction\\b" <<
"\\bif\\b"
17 <<
"\\bin\\b" <<
"\\binstanceof\\b" <<
"\\bnew\\b"
18 <<
"\\breturn\\b" <<
"\\bswitch\\b" <<
"\\bthis\\b"
19 <<
"\\bthrow\\b" <<
"\\btry\\b" <<
"\\btypeof\\b"
20 <<
"\\bvar\\b" <<
"\\btypedef\\b" <<
"\\btypename\\b"
21 <<
"\\bunion\\b" <<
"\\bvoid\\b" <<
"\\bwhile\\b"
23 <<
"\\babstract\\b" <<
"\\benum\\b" <<
"\\bint\\b" <<
"\\bshort\\b"
24 <<
"\\bboolean\\b" <<
"\\bexport\\b" <<
"\\binterface\\b" <<
"\\bstatic\\b"
25 <<
"\\bbyte\\b" <<
"\\bextends\\b" <<
"\\blong\\b" <<
"\\bsuper\\b"
26 <<
"\\bchar\\b" <<
"\\bfinal\\b" <<
"\\bnative\\b" <<
"\\bsynchronized\\b"
27 <<
"\\bclass\\b" <<
"\\bfloat\\b" <<
"\\bpackage\\b" <<
"\\bthrows\\b"
28 <<
"\\bconst\\b" <<
"\\bgoto\\b" <<
"\\bprivate\\b" <<
"\\btransient\\b"
29 <<
"\\bdebugger\\b" <<
"\\bimplements\\b" <<
"\\bprotected\\b" <<
"\\bvolatile\\b"
30 <<
"\\bdouble\\b" <<
"\\bimport\\b" <<
"\\bpublic\\b";
32 foreach (QString pattern, keywordPatterns) {
33 rule.
pattern = QRegExp(pattern);
40 rule.
pattern = QRegExp(
"\\bQ[A-Za-z]+\\b");
45 rule.
pattern = QRegExp(
"//[^\n]*");
52 rule.
pattern = QRegExp(
"\".*\"");
58 rule.
pattern = QRegExp(
"\\b[A-Za-z0-9_]+(?=\\()");
69 QRegExp expression(rule.
pattern);
70 int index = text.indexOf(expression);
72 int length = expression.matchedLength();
73 setFormat(index, length, rule.
format);
74 index = text.indexOf(expression, index + length);
77 setCurrentBlockState(0);
80 if (previousBlockState() != 1)
83 while (startIndex >= 0) {
87 setCurrentBlockState(1);
88 commentLength = text.length() - startIndex;
90 commentLength = endIndex - startIndex
95 startIndex + commentLength);
QRegExp commentStartExpression
QVector< HighlightingRule > highlightingRules
void highlightBlock(const QString &text)
QxrdHighlighter(QTextDocument *parent=0)
QTextCharFormat singleLineCommentFormat
QTextCharFormat multiLineCommentFormat
QRegExp commentEndExpression
QTextCharFormat keywordFormat
QTextCharFormat classFormat
QTextCharFormat quotationFormat
QTextCharFormat functionFormat