summaryrefslogtreecommitdiff
path: root/utils/themeeditor/skinhighlighter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'utils/themeeditor/skinhighlighter.cpp')
-rw-r--r--utils/themeeditor/skinhighlighter.cpp132
1 files changed, 132 insertions, 0 deletions
diff --git a/utils/themeeditor/skinhighlighter.cpp b/utils/themeeditor/skinhighlighter.cpp
new file mode 100644
index 0000000000..4b8de9a804
--- /dev/null
+++ b/utils/themeeditor/skinhighlighter.cpp
@@ -0,0 +1,132 @@
1#include "skinhighlighter.h"
2
3SkinHighlighter::SkinHighlighter(QColor comment, QColor tag, QColor conditional,
4 QColor escaped, QTextDocument* doc)
5 :QSyntaxHighlighter(doc),
6 escaped(escaped), tag(tag),
7 conditional(conditional), comment(comment)
8{
9
10}
11
12SkinHighlighter::~SkinHighlighter()
13{
14
15}
16
17void SkinHighlighter::highlightBlock(const QString& text)
18{
19 for(int i = 0; i < text.length(); i++)
20 {
21 QChar c = text[i];
22
23 /* Checking for delimiters */
24 if(c == ARGLISTOPENSYM
25 || c == ARGLISTCLOSESYM
26 || c == ARGLISTSEPERATESYM)
27 setFormat(i, 1, tag);
28
29 if(c == ENUMLISTOPENSYM
30 || c == ENUMLISTCLOSESYM
31 || c == ENUMLISTSEPERATESYM)
32 setFormat(i, 1, conditional);
33
34 /* Checking for comments */
35 if(c == COMMENTSYM)
36 {
37 setFormat(i, text.length() - i, comment);
38 return;
39 }
40
41 if(c == TAGSYM)
42 {
43 if(text.length() - i < 2)
44 return;
45
46 if(find_escape_character(text[i + 1].toAscii()))
47 {
48 /* Checking for escaped characters */
49
50 setFormat(i, 2, escaped);
51 i++;
52 }
53 else if(text[i + 1] != CONDITIONSYM)
54 {
55 /* Checking for normal tags */
56
57 char lookup[3];
58 struct tag_info* found = 0;
59
60 /* First checking for a two-character tag name */
61 lookup[2] = '\0';
62
63 if(text.length() - i >= 3)
64 {
65 lookup[0] = text[i + 1].toAscii();
66 lookup[1] = text[i + 2].toAscii();
67
68 found = find_tag(lookup);
69 }
70
71 if(found)
72 {
73 setFormat(i, 3, tag);
74 i += 2;
75 }
76 else
77 {
78 lookup[1] = '\0';
79 lookup[0] = text[i + 1].toAscii();
80 found = find_tag(lookup);
81
82 if(found)
83 {
84 setFormat(i, 2, tag);
85 i++;
86 }
87 }
88
89 }
90 else if(text[i + 1] == CONDITIONSYM)
91 {
92 /* Checking for conditional tags */
93
94 if(text.length() - i < 3)
95 return;
96
97 char lookup[3];
98 struct tag_info* found = 0;
99
100 lookup[2] = '\0';
101
102 if(text.length() - i >= 4)
103 {
104 lookup[0] = text[i + 2].toAscii();
105 lookup[1] = text[i + 3].toAscii();
106
107 found = find_tag(lookup);
108 }
109
110 if(found)
111 {
112 setFormat(i, 4, conditional);
113 i += 3;
114 }
115 else
116 {
117 lookup[1] = '\0';
118 lookup[0] = text[i + 2].toAscii();
119
120 found = find_tag(lookup);
121
122 if(found)
123 {
124 setFormat(i, 3, conditional);
125 i += 2;
126 }
127 }
128
129 }
130 }
131 }
132}