25 QTextCharFormat format;
29 format = QTextCharFormat();
30 format.setForeground(QColor(
"darkviolet"));
31 format.setFontWeight(QFont::Bold);
33 this->applyFormat(text, format, pattern);
36 format = QTextCharFormat();
37 format.setForeground(QColor(
"green"));
38 format.setFontItalic(
true);
40 applyFormat(text, format, pattern);
43 format = QTextCharFormat();
44 format.setForeground(QColor(
"blue"));
45 pattern =
"\"[^\"]*\"";
46 applyFormat(text, format, pattern);
49 void SyntaxHighlighter::highlightTimestamp(
const QString &text)
51 QTextCharFormat format;
55 QString stampPattern =
"^\\[?[0-9]{2}:[0-9]{2}:[0-9]{2}( :[0-9]{3})?\\]?";
57 QString headingPattern = stampPattern+
"\\s\\w*\\s--\\s";
58 headingPattern = headingPattern+
"|------->.*";
61 format.setFontWeight(QFont::Bold);
62 format.setForeground(Qt::black);
63 applyFormat(text, format, headingPattern);
66 format.setFontWeight(QFont::Bold);
67 format.setForeground(Qt::darkMagenta);
68 applyFormat(text, format, stampPattern);
71 void SyntaxHighlighter::applyFormat(
const QString &text,
const QTextCharFormat& format,
const QString pattern)
73 QRegExp expression(pattern);
74 int index = text.indexOf(expression);
77 int length = expression.matchedLength();
79 setFormat(index,
length, format);
80 index = text.indexOf(expression, index +
length);