-
Notifications
You must be signed in to change notification settings - Fork 0
/
myhighlighter.cpp
33 lines (28 loc) · 1.13 KB
/
myhighlighter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "myhighlighter.h"
myHighlighter :: myHighlighter(QTextDocument *parent)
:QSyntaxHighlighter(parent){}
void myHighlighter::highlightBlock(const QString &text){
QTextCharFormat myClassFormat;
myClassFormat.setFontWeight(QFont::Bold);
myClassFormat.setForeground(Qt::red);
QRegExp startExpression("{{");
QRegExp endExpression("}}");
setCurrentBlockState(0);
int startIndex = 0;
if (previousBlockState() != 1)
startIndex = text.indexOf(startExpression);
while (startIndex >= 0) {
int endIndex = text.indexOf(endExpression, startIndex);
int commentLength;
if (endIndex == -1) {
setCurrentBlockState(1);
commentLength = text.length() - startIndex;
} else {
commentLength = endIndex - startIndex
+ endExpression.matchedLength();
}
setFormat(startIndex, commentLength, myClassFormat);
startIndex = text.indexOf(startExpression,
startIndex + commentLength);
}
}