-
Notifications
You must be signed in to change notification settings - Fork 0
/
zplhighlighter.cpp
36 lines (31 loc) · 1.29 KB
/
zplhighlighter.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
35
36
#include "zplhighlighter.h"
ZPLHighlighter::ZPLHighlighter(QTextDocument *parent) : QSyntaxHighlighter(parent)
{
HighlightingRule rule;
fdfs_format.setFontWeight(QFont::Bold);
fdfs_format.setForeground(Qt::red);
rule.pattern = QRegularExpression(QStringLiteral("\\^FD.*\\^FS"));
rule.format = fdfs_format;
highlightingRules.append(rule);
command_format.setFontWeight(QFont::Normal);
command_format.setForeground(Qt::darkGreen);
rule.pattern = QRegularExpression(QStringLiteral("\\^.."));
rule.format = command_format;
highlightingRules.append(rule);
command_format.setFontWeight(QFont::Bold);
command_format.setForeground(Qt::blue);
rule.pattern = QRegularExpression(QStringLiteral("\\>[\\d;:=<]"));
rule.format = command_format;
highlightingRules.append(rule);
}
void ZPLHighlighter::highlightBlock(const QString &text)
{
for (const HighlightingRule &rule : qAsConst(highlightingRules)) {
QRegularExpressionMatchIterator matchIterator = rule.pattern.globalMatch(text);
while (matchIterator.hasNext()) {
QRegularExpressionMatch match = matchIterator.next();
setFormat(match.capturedStart(), match.capturedLength(), rule.format);
}
}
setCurrentBlockState(0);
}