16 : QSyntaxHighlighter(parent)
19 <<
"foreach" <<
"bool" <<
"int" <<
"void" <<
"double" 20 <<
"float" <<
"char" <<
"delete" <<
"class" <<
"const" 21 <<
"virtual" <<
"mutable" <<
"this" <<
"struct" <<
"union" 22 <<
"throw" <<
"for" <<
"if" <<
"else" <<
"false" 23 <<
"namespace" <<
"switch" <<
"case" <<
"public" <<
"private" 24 <<
"protected" <<
"new" <<
"return" <<
"using" <<
"true" 25 <<
"->" <<
">>" <<
"<<" <<
">" <<
"<" 26 <<
"(" <<
")" <<
"{" <<
"}" <<
"[" 27 <<
"]" <<
"+" <<
"-" <<
"*" <<
"/" 28 <<
"=" <<
"!" <<
"." <<
"," <<
";" 29 <<
":" <<
"&" <<
"emit" <<
"connect" <<
"SIGNAL" 30 <<
"|" <<
"SLOT" <<
"slots" <<
"signals";
36 int nState = previousBlockState();
38 for (
int i = 0; i < str.length(); ++i) {
40 if (str.mid(i, 2) ==
"*/") {
42 setFormat(nStart, i - nStart + 2, Qt::darkGray);
47 if (str.mid(i, 1) ==
"\"" || str.mid(i, 1) ==
"\'") {
48 if (str.mid(i - 1, 2) !=
"\\\"" 49 && str.mid(i - 1, 2) !=
"\\\'" 52 setFormat(nStart, i - nStart + 1, Qt::cyan);
57 if (str.mid(i, 2) ==
"//") {
58 setFormat(i, str.length() - i, Qt::darkGray);
61 else if (str.mid(i, 1) ==
"#") {
62 setFormat(i, str.length() - i, Qt::green);
65 else if (str.at(i).isNumber()) {
66 setFormat(i, 1, Qt::cyan);
68 else if (str.mid(i, 2) ==
"/*") {
72 else if (str.mid(i, 1) ==
"\"" || str.mid(i, 1) ==
"\'") {
78 if (!strKeyword.isEmpty()) {
79 setFormat(i, strKeyword.length(), Qt::white);
80 i += strKeyword.length() - 1;
86 setFormat(nStart, str.length() - nStart, Qt::darkGray);
89 setFormat(nStart, str.length() - nStart, Qt::cyan);
92 setCurrentBlockState(nState);
100 foreach (QString strKeyword, m_lstKeywords) {
101 if (str.mid(nPos, strKeyword.length()) == strKeyword) {
102 strTemp = strKeyword;
QString getKeyword(int i, const QString &str) const
SyntaxHighlighter(QTextDocument *parent=0)
virtual void highlightBlock(const QString &)