46 QTextCharFormat format;
50 format = QTextCharFormat();
51 format.setForeground(QColor(
"darkviolet"));
52 format.setFontWeight(QFont::Bold);
54 this->applyFormat(text, format, pattern);
57 format = QTextCharFormat();
58 format.setForeground(QColor(
"green"));
59 format.setFontItalic(
true);
61 applyFormat(text, format, pattern);
64 format = QTextCharFormat();
65 format.setForeground(QColor(
"blue"));
66 pattern =
"\"[^\"]*\"";
67 applyFormat(text, format, pattern);
70 void SyntaxHighlighter::highlightTimestamp(
const QString &text)
72 QTextCharFormat format;
76 QString stampPattern =
"^\\[?[0-9]{2}:[0-9]{2}:[0-9]{2}( :[0-9]{3})?\\]?";
78 QString headingPattern = stampPattern+
"\\s\\w*\\s--\\s";
79 headingPattern = headingPattern+
"|------->.*";
82 format.setFontWeight(QFont::Bold);
83 format.setForeground(Qt::black);
84 applyFormat(text, format, headingPattern);
87 format.setFontWeight(QFont::Bold);
88 format.setForeground(Qt::darkMagenta);
89 applyFormat(text, format, stampPattern);
92 void SyntaxHighlighter::applyFormat(
const QString &text,
const QTextCharFormat& format,
const QString pattern)
94 QRegExp expression(pattern);
95 int index = text.indexOf(expression);
98 int length = expression.matchedLength();
100 setFormat(index, length, format);
101 index = text.indexOf(expression, index + length);
SyntaxHighlighter(QTextDocument *parent)
RealScalar length() const
virtual void highlightBlock(const QString &text)