summaryrefslogtreecommitdiff
path: root/utils/themeeditor/gui/skinhighlighter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'utils/themeeditor/gui/skinhighlighter.cpp')
-rw-r--r--utils/themeeditor/gui/skinhighlighter.cpp172
1 files changed, 172 insertions, 0 deletions
diff --git a/utils/themeeditor/gui/skinhighlighter.cpp b/utils/themeeditor/gui/skinhighlighter.cpp
new file mode 100644
index 0000000000..25a479f815
--- /dev/null
+++ b/utils/themeeditor/gui/skinhighlighter.cpp
@@ -0,0 +1,172 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 Robert Bieber
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "skinhighlighter.h"
23
24#include <QSettings>
25
26SkinHighlighter::SkinHighlighter(QTextDocument* doc)
27 :QSyntaxHighlighter(doc)
28{
29 loadSettings();
30}
31
32SkinHighlighter::~SkinHighlighter()
33{
34
35}
36
37void SkinHighlighter::highlightBlock(const QString& text)
38{
39 for(int i = 0; i < text.length(); i++)
40 {
41 QChar c = text[i];
42
43 /* Checking for delimiters */
44 if(c == ARGLISTOPENSYM
45 || c == ARGLISTCLOSESYM
46 || c == ARGLISTSEPERATESYM)
47 setFormat(i, 1, tag);
48
49 if(c == ENUMLISTOPENSYM
50 || c == ENUMLISTCLOSESYM
51 || c == ENUMLISTSEPERATESYM)
52 setFormat(i, 1, conditional);
53
54 /* Checking for comments */
55 if(c == COMMENTSYM)
56 {
57 setFormat(i, text.length() - i, comment);
58 return;
59 }
60
61 if(c == TAGSYM)
62 {
63 if(text.length() - i < 2)
64 return;
65
66 if(find_escape_character(text[i + 1].toAscii()))
67 {
68 /* Checking for escaped characters */
69
70 setFormat(i, 2, escaped);
71 i++;
72 }
73 else if(text[i + 1] != CONDITIONSYM)
74 {
75 /* Checking for normal tags */
76
77 char lookup[3];
78 struct tag_info* found = 0;
79
80 /* First checking for a two-character tag name */
81 lookup[2] = '\0';
82
83 if(text.length() - i >= 3)
84 {
85 lookup[0] = text[i + 1].toAscii();
86 lookup[1] = text[i + 2].toAscii();
87
88 found = find_tag(lookup);
89 }
90
91 if(found)
92 {
93 setFormat(i, 3, tag);
94 i += 2;
95 }
96 else
97 {
98 lookup[1] = '\0';
99 lookup[0] = text[i + 1].toAscii();
100 found = find_tag(lookup);
101
102 if(found)
103 {
104 setFormat(i, 2, tag);
105 i++;
106 }
107 }
108
109 }
110 else if(text[i + 1] == CONDITIONSYM)
111 {
112 /* Checking for conditional tags */
113
114 if(text.length() - i < 3)
115 return;
116
117 char lookup[3];
118 struct tag_info* found = 0;
119
120 lookup[2] = '\0';
121
122 if(text.length() - i >= 4)
123 {
124 lookup[0] = text[i + 2].toAscii();
125 lookup[1] = text[i + 3].toAscii();
126
127 found = find_tag(lookup);
128 }
129
130 if(found)
131 {
132 setFormat(i, 4, conditional);
133 i += 3;
134 }
135 else
136 {
137 lookup[1] = '\0';
138 lookup[0] = text[i + 2].toAscii();
139
140 found = find_tag(lookup);
141
142 if(found)
143 {
144 setFormat(i, 3, conditional);
145 i += 2;
146 }
147 }
148
149 }
150 }
151 }
152}
153
154void SkinHighlighter::loadSettings()
155{
156 QSettings settings;
157
158 settings.beginGroup("SkinHighlighter");
159
160 /* Loading the highlighting colors */
161 tag = settings.value("tagColor", QColor(180,0,0)).value<QColor>();
162 conditional = settings.value("conditionalColor",
163 QColor(0, 0, 180)).value<QColor>();
164 escaped = settings.value("escapedColor",
165 QColor(120,120,120)).value<QColor>();
166 comment = settings.value("commentColor",
167 QColor(0, 180, 0)).value<QColor>();
168
169 settings.endGroup();
170
171 rehighlight();
172}