Theme Editor: Fixed some resource alias issues, implemented device configuration...
[kugel-rb.git] / utils / themeeditor / gui / skinhighlighter.cpp
blob25a479f81577e0826e1b4ed7a9178155e9e4d63c
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2010 Robert Bieber
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include "skinhighlighter.h"
24 #include <QSettings>
26 SkinHighlighter::SkinHighlighter(QTextDocument* doc)
27 :QSyntaxHighlighter(doc)
29 loadSettings();
32 SkinHighlighter::~SkinHighlighter()
37 void SkinHighlighter::highlightBlock(const QString& text)
39 for(int i = 0; i < text.length(); i++)
41 QChar c = text[i];
43 /* Checking for delimiters */
44 if(c == ARGLISTOPENSYM
45 || c == ARGLISTCLOSESYM
46 || c == ARGLISTSEPERATESYM)
47 setFormat(i, 1, tag);
49 if(c == ENUMLISTOPENSYM
50 || c == ENUMLISTCLOSESYM
51 || c == ENUMLISTSEPERATESYM)
52 setFormat(i, 1, conditional);
54 /* Checking for comments */
55 if(c == COMMENTSYM)
57 setFormat(i, text.length() - i, comment);
58 return;
61 if(c == TAGSYM)
63 if(text.length() - i < 2)
64 return;
66 if(find_escape_character(text[i + 1].toAscii()))
68 /* Checking for escaped characters */
70 setFormat(i, 2, escaped);
71 i++;
73 else if(text[i + 1] != CONDITIONSYM)
75 /* Checking for normal tags */
77 char lookup[3];
78 struct tag_info* found = 0;
80 /* First checking for a two-character tag name */
81 lookup[2] = '\0';
83 if(text.length() - i >= 3)
85 lookup[0] = text[i + 1].toAscii();
86 lookup[1] = text[i + 2].toAscii();
88 found = find_tag(lookup);
91 if(found)
93 setFormat(i, 3, tag);
94 i += 2;
96 else
98 lookup[1] = '\0';
99 lookup[0] = text[i + 1].toAscii();
100 found = find_tag(lookup);
102 if(found)
104 setFormat(i, 2, tag);
105 i++;
110 else if(text[i + 1] == CONDITIONSYM)
112 /* Checking for conditional tags */
114 if(text.length() - i < 3)
115 return;
117 char lookup[3];
118 struct tag_info* found = 0;
120 lookup[2] = '\0';
122 if(text.length() - i >= 4)
124 lookup[0] = text[i + 2].toAscii();
125 lookup[1] = text[i + 3].toAscii();
127 found = find_tag(lookup);
130 if(found)
132 setFormat(i, 4, conditional);
133 i += 3;
135 else
137 lookup[1] = '\0';
138 lookup[0] = text[i + 2].toAscii();
140 found = find_tag(lookup);
142 if(found)
144 setFormat(i, 3, conditional);
145 i += 2;
154 void SkinHighlighter::loadSettings()
156 QSettings settings;
158 settings.beginGroup("SkinHighlighter");
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>();
169 settings.endGroup();
171 rehighlight();