-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
highlighter.cpp
34 lines (32 loc) · 822 Bytes
/
highlighter.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
34
#include "highlighter.h"
#include "settings.h"
Highlighter::Highlighter(QTextDocument *parent)
: QSyntaxHighlighter(parent)
{
}
void Highlighter::highlightBlock(const QString &text)
{
if(settings.getNoteHighlight())
{
foreach (const HighlightRule &rule, settings.getHighlightRules())
{
if(!rule.enabled)
continue;
if(rule.regexp.isEmpty())
continue;
QRegExp expression(rule.regexp);
if(!expression.isValid())
continue;
QTextCharFormat format;
format.setForeground(rule.color);
int index = expression.indexIn(text);
while (index >= 0)
{
int length = expression.matchedLength();
setFormat(index, length, format);
index = expression.indexIn(text, index+length);
}
}
}
setCurrentBlockState(0);
}