1 // This module implements the QsciLexerXML class.
2 //
3 // Copyright (c) 2021 Riverbank Computing Limited <info@riverbankcomputing.com>
4 //
5 // This file is part of QScintilla.
6 //
7 // This file may be used under the terms of the GNU General Public License
8 // version 3.0 as published by the Free Software Foundation and appearing in
9 // the file LICENSE included in the packaging of this file. Please review the
10 // following information to ensure the GNU General Public License version 3.0
11 // requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 //
13 // If you do not wish to use this file under the terms of the GPL version 3.0
14 // then you may purchase a commercial license. For more information contact
15 // info@riverbankcomputing.com.
16 //
17 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
18 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19
20
21 #include "Qsci/qscilexerxml.h"
22
23 #include <qcolor.h>
24 #include <qfont.h>
25 #include <qsettings.h>
26
27
28 // The ctor.
QsciLexerXML(QObject * parent)29 QsciLexerXML::QsciLexerXML(QObject *parent)
30 : QsciLexerHTML(parent), scripts(true)
31 {
32 }
33
34
35 // The dtor.
~QsciLexerXML()36 QsciLexerXML::~QsciLexerXML()
37 {
38 }
39
40
41 // Returns the language name.
language() const42 const char *QsciLexerXML::language() const
43 {
44 return "XML";
45 }
46
47
48 // Returns the lexer name.
lexer() const49 const char *QsciLexerXML::lexer() const
50 {
51 return "xml";
52 }
53
54
55 // Returns the foreground colour of the text for a style.
defaultColor(int style) const56 QColor QsciLexerXML::defaultColor(int style) const
57 {
58 switch (style)
59 {
60 case Default:
61 return QColor(0x00,0x00,0x00);
62
63 case Tag:
64 case UnknownTag:
65 case XMLTagEnd:
66 case SGMLDefault:
67 case SGMLCommand:
68 return QColor(0x00,0x00,0x80);
69
70 case Attribute:
71 case UnknownAttribute:
72 return QColor(0x00,0x80,0x80);
73
74 case HTMLNumber:
75 return QColor(0x00,0x7f,0x7f);
76
77 case HTMLDoubleQuotedString:
78 case HTMLSingleQuotedString:
79 return QColor(0x7f,0x00,0x7f);
80
81 case OtherInTag:
82 case Entity:
83 case XMLStart:
84 case XMLEnd:
85 return QColor(0x80,0x00,0x80);
86
87 case HTMLComment:
88 case SGMLComment:
89 return QColor(0x80,0x80,0x00);
90
91 case CDATA:
92 case PHPStart:
93 case SGMLDoubleQuotedString:
94 case SGMLError:
95 return QColor(0x80,0x00,0x00);
96
97 case HTMLValue:
98 return QColor(0x60,0x80,0x60);
99
100 case SGMLParameter:
101 return QColor(0x00,0x66,0x00);
102
103 case SGMLSingleQuotedString:
104 return QColor(0x99,0x33,0x00);
105
106 case SGMLSpecial:
107 return QColor(0x33,0x66,0xff);
108
109 case SGMLEntity:
110 return QColor(0x33,0x33,0x33);
111
112 case SGMLBlockDefault:
113 return QColor(0x00,0x00,0x66);
114 }
115
116 return QsciLexerHTML::defaultColor(style);
117 }
118
119
120 // Returns the end-of-line fill for a style.
defaultEolFill(int style) const121 bool QsciLexerXML::defaultEolFill(int style) const
122 {
123 if (style == CDATA)
124 return true;
125
126 return QsciLexerHTML::defaultEolFill(style);
127 }
128
129
130 // Returns the font of the text for a style.
defaultFont(int style) const131 QFont QsciLexerXML::defaultFont(int style) const
132 {
133 QFont f;
134
135 switch (style)
136 {
137 case Default:
138 case Entity:
139 case CDATA:
140 #if defined(Q_OS_WIN)
141 f = QFont("Times New Roman",11);
142 #elif defined(Q_OS_MAC)
143 f = QFont("Times New Roman", 12);
144 #else
145 f = QFont("Bitstream Charter",10);
146 #endif
147 break;
148
149 case XMLStart:
150 case XMLEnd:
151 case SGMLCommand:
152 f = QsciLexer::defaultFont(style);
153 f.setBold(true);
154 break;
155
156 default:
157 f = QsciLexerHTML::defaultFont(style);
158 }
159
160 return f;
161 }
162
163
164 // Returns the set of keywords.
keywords(int set) const165 const char *QsciLexerXML::keywords(int set) const
166 {
167 if (set == 6)
168 return QsciLexerHTML::keywords(set);
169
170 return 0;
171 }
172
173
174 // Returns the background colour of the text for a style.
defaultPaper(int style) const175 QColor QsciLexerXML::defaultPaper(int style) const
176 {
177 switch (style)
178 {
179 case CDATA:
180 return QColor(0xff,0xf0,0xf0);
181
182 case SGMLDefault:
183 case SGMLCommand:
184 case SGMLParameter:
185 case SGMLDoubleQuotedString:
186 case SGMLSingleQuotedString:
187 case SGMLSpecial:
188 case SGMLEntity:
189 case SGMLComment:
190 return QColor(0xef,0xef,0xff);
191
192 case SGMLError:
193 return QColor(0xff,0x66,0x66);
194
195 case SGMLBlockDefault:
196 return QColor(0xcc,0xcc,0xe0);
197 }
198
199 return QsciLexerHTML::defaultPaper(style);
200 }
201
202
203 // Refresh all properties.
refreshProperties()204 void QsciLexerXML::refreshProperties()
205 {
206 setScriptsProp();
207 }
208
209
210 // Read properties from the settings.
readProperties(QSettings & qs,const QString & prefix)211 bool QsciLexerXML::readProperties(QSettings &qs, const QString &prefix)
212 {
213 int rc = QsciLexerHTML::readProperties(qs, prefix);
214
215 scripts = qs.value(prefix + "scriptsstyled", true).toBool();
216
217 return rc;
218 }
219
220
221 // Write properties to the settings.
writeProperties(QSettings & qs,const QString & prefix) const222 bool QsciLexerXML::writeProperties(QSettings &qs, const QString &prefix) const
223 {
224 int rc = QsciLexerHTML::writeProperties(qs, prefix);
225
226 qs.setValue(prefix + "scriptsstyled", scripts);
227
228 return rc;
229 }
230
231
232 // Return true if scripts are styled.
scriptsStyled() const233 bool QsciLexerXML::scriptsStyled() const
234 {
235 return scripts;
236 }
237
238
239 // Set if scripts are styled.
setScriptsStyled(bool styled)240 void QsciLexerXML::setScriptsStyled(bool styled)
241 {
242 scripts = styled;
243
244 setScriptsProp();
245 }
246
247
248 // Set the "lexer.xml.allow.scripts" property.
setScriptsProp()249 void QsciLexerXML::setScriptsProp()
250 {
251 emit propertyChanged("lexer.xml.allow.scripts",(scripts ? "1" : "0"));
252 }
253