1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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"
26 SkinHighlighter::SkinHighlighter(QTextDocument
* doc
)
27 :QSyntaxHighlighter(doc
)
32 SkinHighlighter::~SkinHighlighter()
37 void SkinHighlighter::highlightBlock(const QString
& text
)
39 for(int i
= 0; i
< text
.length(); i
++)
43 /* Checking for delimiters */
44 if(c
== ARGLISTOPENSYM
45 || c
== ARGLISTCLOSESYM
46 || c
== ARGLISTSEPERATESYM
)
49 if(c
== ENUMLISTOPENSYM
50 || c
== ENUMLISTCLOSESYM
51 || c
== ENUMLISTSEPERATESYM
)
52 setFormat(i
, 1, conditional
);
54 /* Checking for comments */
57 setFormat(i
, text
.length() - i
, comment
);
63 if(text
.length() - i
< 2)
66 if(find_escape_character(text
[i
+ 1].toAscii()))
68 /* Checking for escaped characters */
70 setFormat(i
, 2, escaped
);
73 else if(text
[i
+ 1] != CONDITIONSYM
)
75 /* Checking for normal tags */
78 struct tag_info
* found
= 0;
80 /* First checking for a two-character tag name */
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
);
99 lookup
[0] = text
[i
+ 1].toAscii();
100 found
= find_tag(lookup
);
104 setFormat(i
, 2, tag
);
110 else if(text
[i
+ 1] == CONDITIONSYM
)
112 /* Checking for conditional tags */
114 if(text
.length() - i
< 3)
118 struct tag_info
* found
= 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
);
132 setFormat(i
, 4, conditional
);
138 lookup
[0] = text
[i
+ 2].toAscii();
140 found
= find_tag(lookup
);
144 setFormat(i
, 3, conditional
);
154 void SkinHighlighter::loadSettings()
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
>();