-
Notifications
You must be signed in to change notification settings - Fork 15
/
MsdHighlighter.cpp
79 lines (70 loc) · 3.25 KB
/
MsdHighlighter.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/****************************************************************************
** Deling Final Fantasy VIII Field Editor
** Copyright (C) 2009-2012 Arzel Jérôme <[email protected]>
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#include "MsdHighlighter.h"
MsdHighlighter::MsdHighlighter(QTextDocument *parent) :
QSyntaxHighlighter(parent)
{
HighlightingRule rule;
rule.pattern = QRegExp("\\{x([\\da-fA-F]{2}){1,2}\\}");
rule.color = Qt::darkRed;
highlightingRules.append(rule);
QStringList names;
names << "\\{Squall\\}" << "\\{Zell\\}" << "\\{Irvine\\}" << "\\{Quistis\\}" << "\\{Rinoa\\}"
<< "\\{Selphie\\}" << "\\{Seifer\\}" << "\\{Edea\\}" << "\\{Laguna\\}" << "\\{Kiros\\}"
<< "\\{Ward\\}" << "\\{Angelo\\}" << "\\{Griever\\}" << "\\{Boko\\}"
<< "\\{Galbadia\\}" << "\\{Esthar\\}" << "\\{Balamb\\}" << "\\{Dollet\\}"
<< "\\{Timber\\}" << "\\{Trabia\\}" << "\\{Centra\\}" << "\\{Horizon\\}";
foreach(const QString &name, names) {
rule.pattern = QRegExp(name);
rule.color = Qt::darkGreen;
highlightingRules.append(rule);
}
QStringList syst;
syst << "\\{Darkgrey\\}" << "\\{Grey\\}" << "\\{Yellow\\}" << "\\{Red\\}"
<< "\\{Green\\}" << "\\{Blue\\}" << "\\{Purple\\}" << "\\{White\\}"
<< "\\{DarkgreyBlink\\}" << "\\{GreyBlink\\}" << "\\{YellowBlink\\}"
<< "\\{RedBlink\\}" << "\\{GreenBlink\\}" << "\\{BlueBlink\\}"
<< "\\{PurpleBlink\\}" << "\\{WhiteBlink\\}" << "\\{Wait\\d\\d\\d\\}"
<< "\\{Var[0b]?[0-7]\\}" << "^\\{NewPage\\}$" << "\\{jp\\d\\d\\d\\}";
foreach(const QString &s, syst) {
rule.pattern = QRegExp(s, Qt::CaseInsensitive);
rule.color = Qt::darkBlue;
highlightingRules.append(rule);
}
QStringList doublet;
doublet << "\\{in\\}" << "\\{e \\}" << "\\{ne\\}" << "\\{to\\}" << "\\{re\\}" << "\\{HP\\}" << "\\{l \\}" << "\\{ll\\}" <<
"\\{GF\\}" << "\\{nt\\}" << "\\{il\\}" << "\\{o \\}" << "\\{ef\\}" << "\\{on\\}" << "\\{ w\\}" << "\\{ r\\}" <<
"\\{wi\\}" << "\\{fi\\}" << "\\{EC\\}" << "\\{s \\}" << "\\{ar\\}" << "\\{FE\\}" << "\\{ S\\}" << "\\{ag\\}";
foreach(const QString &d, doublet) {
rule.pattern = QRegExp(d);
rule.color = Qt::darkBlue;
highlightingRules.append(rule);
}
}
void MsdHighlighter::highlightBlock(const QString &text)
{
foreach(const HighlightingRule &rule, highlightingRules) {
QRegExp expression(rule.pattern);
int index = expression.indexIn(text);
while(index >= 0) {
int length = expression.matchedLength();
setFormat(index, length, rule.color);
index = expression.indexIn(text, index + length);
}
}
}