NCL Composer  0.1.5
 All Classes Functions Variables Pages
QsciLexerNCL.cpp
1 /*
2  * Copyright 2011 TeleMidia/PUC-Rio.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library. If not, see
16  * <http://www.gnu.org/licenses/>.
17  */
18 #include "QsciLexerNCL.h"
19 
20 #include <QColor>
21 #include <QFont>
22 #include <QSettings>
23 
24 #include <QDebug>
25 
26 // The ctor.
28  : QsciLexerHTML(parent),
29  scripts(true)
30 {
31 }
32 
33 // The dtor.
35 {
36 }
37 
38 // Returns the language name.
39 const char *QsciLexerNCL::language() const
40 {
41  return "NCL";
42 }
43 
44 
45 // Returns the lexer name.
46 const char *QsciLexerNCL::lexer() const
47 {
48  return "ncl";
49 }
50 
51 
52 // Returns the foreground colour of the text for a style.
53 QColor QsciLexerNCL::defaultColor(int style) const
54 {
55 // return QColor(0xff, 0xff, 0xff);
56 
57  switch (style)
58  {
59  case Default:
60  return QColor(0x00, 0x00, 0x00);
61 
62  case Tag:
63  case UnknownTag:
64  case XMLTagEnd:
65  case SGMLDefault:
66  case SGMLCommand:
67  return QColor(0x00, 0x00, 0x80);
68 
69  case Attribute:
70  case UnknownAttribute:
71  return QColor(0x00, 0x00, 0x80);
72 
73  case HTMLNumber:
74  return QColor(0x00, 0x7f, 0x7f);
75 
76  case HTMLDoubleQuotedString:
77  case HTMLSingleQuotedString:
78  return QColor(0x99, 0x33, 0x00);
79 
80  case OtherInTag:
81  case Entity:
82  case XMLStart:
83  case XMLEnd:
84  return QColor(0x80, 0x00, 0x80);
85 
86  case HTMLComment:
87  case SGMLComment:
88  return QColor(0x00, 0x7f, 0x7f);
89 
90  case CDATA:
91  case PHPStart:
92  case SGMLDoubleQuotedString:
93  case SGMLError:
94  return QColor(0x80,0x00,0x00);
95 
96  case HTMLValue:
97  return QColor(0x00,0xFF,0x00);
98 
99  case SGMLParameter:
100  return QColor(0x00,0x66,0x00);
101 
102  case SGMLSingleQuotedString:
103  return QColor(0x99,0x33,0x00);
104 
105  case SGMLSpecial:
106  return QColor(0x33,0x66,0xff);
107 
108  case SGMLEntity:
109  return QColor(0x00,0x00,0x33);
110 
111  case SGMLBlockDefault:
112  return QColor(0x00,0x00,0x66);
113  }
114 
115  return QsciLexerHTML::defaultColor(style);
116 }
117 
118 
119 // Returns the end-of-line fill for a style.
120 bool QsciLexerNCL::defaultEolFill(int style) const
121 {
122  if (style == CDATA)
123  return true;
124 
125  return QsciLexerHTML::defaultEolFill(style);
126 }
127 
128 
129 // Returns the font of the text for a style.
130 QFont QsciLexerNCL::defaultFont(int style) const
131 {
132  QFont f;
133 
134  switch (style)
135  {
136  case Default:
137  case Entity:
138  case CDATA:
139 #if defined(Q_OS_WIN)
140  f = QFont("Times New Roman", 10);
141 #else
142  f = QFont("Bitstream Charter", 9);
143 #endif
144  break;
145 
146  case XMLStart:
147  case XMLEnd:
148  case SGMLCommand:
149  f = QsciLexerHTML::defaultFont(style);
150  f.setBold(true);
151  break;
152 
153  default:
154  f = QsciLexerHTML::defaultFont(style);
155  }
156 
157  f.setPointSize(8);
158 
159  return f;
160 }
161 
162 
163 // Returns the set of keywords.
164 const char *QsciLexerNCL::keywords(int set) const
165 {
166  if (set == 6)
167  return QsciLexerHTML::keywords(set);
168 
169  return 0;
170 }
171 
172 
173 // Returns the background colour of the text for a style.
174 QColor QsciLexerNCL::defaultPaper(int style) const
175 {
176 // return QColor(0x88,0x88,0x88);
177 
178  switch (style)
179  {
180  case CDATA:
181  return QColor(0xff,0xff,0xff);
182 
183  case SGMLDefault:
184  case SGMLCommand:
185  case SGMLParameter:
186  case SGMLDoubleQuotedString:
187  case SGMLSingleQuotedString:
188  case SGMLSpecial:
189  case SGMLEntity:
190  case SGMLComment:
191  return QColor(0xef,0xef,0xff);
192 
193  case SGMLError:
194  return QColor(0xff,0x66,0x66);
195 
196  case SGMLBlockDefault:
197  return QColor(0xcc,0xcc,0xe0);
198  }
199 
200  return QsciLexerHTML::defaultPaper(style);
201 }
202 
203 
204 // Refresh all properties.
206 {
207  setScriptsProp();
208  emit propertyChanged("fold.html","1");
209 }
210 
211 
212 // Read properties from the settings.
213 bool QsciLexerNCL::readProperties(QSettings &qs, const QString &prefix)
214 {
215  int rc = QsciLexerHTML::readProperties(qs, prefix);
216 
217  scripts = qs.value(prefix + "scriptsstyled", true).toBool();
218 
219  return rc;
220 }
221 
222 
223 // Write properties to the settings.
224 bool QsciLexerNCL::writeProperties(QSettings &qs, const QString &prefix) const
225 {
226  int rc = QsciLexerHTML::writeProperties(qs, prefix);
227 
228  qs.setValue(prefix + "scriptsstyled", scripts);
229 
230  return rc;
231 }
232 
233 
234 // Return true if scripts are styled.
236 {
237  return scripts;
238 }
239 
240 
241 // Set if scripts are styled.
243 {
244  scripts = styled;
245 
246  setScriptsProp();
247 }
248 
249 
250 // Set the "lexer.ncl.allow.scripts" property.
251 void QsciLexerNCL::setScriptsProp()
252 {
253  emit propertyChanged("lexer.xml.allow.scripts",(scripts ? "1" : "0"));
254 }