Mercurial > hg > forks > UniversalIndentGUI
comparison src/UiGuiHighlighter.cpp @ 751:ac165b6ae67e
Done some refactoring:
- Moved includes into the cpp files where possible and using class pre-declarations if possible
- Made class member variable names begin with an underscore
- Made by uic created header files be used as class members instead of inherting them
- Renamed some variables to reflect their purpose better
- Added some NULL initializations and added some comments
- Rearranged some include and declaration code parts to be consistent and better readable
- Updated for QScintilla 2.4.5
- Made UiGuiSettings be accessed via a shared pointer only
git-svn-id: svn://svn.code.sf.net/p/universalindent/code/trunk@1028 59b1889a-e5ac-428c-b0c7-476e01d41282
author | thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282> |
---|---|
date | Thu, 14 Oct 2010 19:52:47 +0000 |
parents | aae5a8d04f70 |
children | f3631db17328 |
comparison
equal
deleted
inserted
replaced
750:a884b5861e93 | 751:ac165b6ae67e |
---|---|
15 * along with this program in the file LICENSE.GPL; if not, write to the * | 15 * along with this program in the file LICENSE.GPL; if not, write to the * |
16 * Free Software Foundation, Inc., * | 16 * Free Software Foundation, Inc., * |
17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * | 17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
18 ***************************************************************************/ | 18 ***************************************************************************/ |
19 | 19 |
20 #include <QtGui> | |
21 | |
22 #include "UiGuiHighlighter.h" | 20 #include "UiGuiHighlighter.h" |
23 | 21 |
24 #include "SettingsPaths.h" | 22 #include "SettingsPaths.h" |
23 | |
24 #include <QSettings> | |
25 #include <QMenu> | |
26 #include <QScrollBar> | |
27 #include <QCoreApplication> | |
28 | |
29 #include <Qsci/qsciscintilla.h> | |
30 #include <Qsci/qscilexer.h> | |
31 #include <Qsci/qscilexerbash.h> | |
32 #include <Qsci/qscilexerbatch.h> | |
33 #include <Qsci/qscilexercmake.h> | |
34 #include <Qsci/qscilexercpp.h> | |
35 #include <Qsci/qscilexercsharp.h> | |
36 #include <Qsci/qscilexercss.h> | |
37 #include <Qsci/qscilexerd.h> | |
38 #include <Qsci/qscilexerdiff.h> | |
39 #if ( QSCINTILLA_VERSION >= 0x020300 ) | |
40 #include <Qsci/qscilexerfortran.h> | |
41 #include <Qsci/qscilexerfortran77.h> | |
42 #endif | |
43 #include <Qsci/qscilexerhtml.h> | |
44 #include <Qsci/qscilexeridl.h> | |
45 #include <Qsci/qscilexerjava.h> | |
46 #include <Qsci/qscilexerjavascript.h> | |
47 #include <Qsci/qscilexerlua.h> | |
48 #include <Qsci/qscilexermakefile.h> | |
49 #if ( QSCINTILLA_VERSION >= 0x020300 ) | |
50 #include <Qsci/qscilexerpascal.h> | |
51 #endif | |
52 #include <Qsci/qscilexerperl.h> | |
53 #if ( QSCINTILLA_VERSION >= 0x020300 ) | |
54 #include <Qsci/qscilexerpostscript.h> | |
55 #endif | |
56 #include <Qsci/qscilexerpov.h> | |
57 #include <Qsci/qscilexerproperties.h> | |
58 #include <Qsci/qscilexerpython.h> | |
59 #include <Qsci/qscilexerruby.h> | |
60 #if ( QSCINTILLA_VERSION >= 0x020400 ) | |
61 #include <Qsci/qscilexerspice.h> | |
62 #endif | |
63 #include <Qsci/qscilexersql.h> | |
64 #if ( QSCINTILLA_VERSION >= 0x020300 ) | |
65 #include <Qsci/qscilexertcl.h> | |
66 #endif | |
67 #include <Qsci/qscilexertex.h> | |
68 #if ( QSCINTILLA_VERSION >= 0x020400 ) | |
69 #include <Qsci/qscilexerverilog.h> | |
70 #endif | |
71 #include <Qsci/qscilexervhdl.h> | |
72 #if ( QSCINTILLA_VERSION >= 0x020300 ) | |
73 #include <Qsci/qscilexerxml.h> | |
74 #include <Qsci/qscilexeryaml.h> | |
75 #endif | |
25 | 76 |
26 //! \defgroup grp_EditorComponent All concerning editor widget. | 77 //! \defgroup grp_EditorComponent All concerning editor widget. |
27 | 78 |
28 /*! | 79 /*! |
29 \class UiGuiHighlighter | 80 \class UiGuiHighlighter |
33 | 84 |
34 /*! | 85 /*! |
35 \brief The constructor initializes some regular expressions and keywords to identify cpp tokens | 86 \brief The constructor initializes some regular expressions and keywords to identify cpp tokens |
36 */ | 87 */ |
37 UiGuiHighlighter::UiGuiHighlighter(QsciScintilla *parent) : QObject(parent) { | 88 UiGuiHighlighter::UiGuiHighlighter(QsciScintilla *parent) : QObject(parent) { |
38 this->qsciEditorParent = parent; | 89 _qsciEditorParent = parent; |
39 | 90 |
40 // Create the highlighter settings object from the UiGuiSyntaxHighlightConfig.ini file. | 91 // Create the highlighter _settings object from the UiGuiSyntaxHighlightConfig.ini file. |
41 this->settings = new QSettings(SettingsPaths::getSettingsPath() + "/UiGuiSyntaxHighlightConfig.ini", QSettings::IniFormat, this); | 92 _settings = new QSettings(SettingsPaths::getSettingsPath() + "/UiGuiSyntaxHighlightConfig.ini", QSettings::IniFormat, this); |
42 | 93 |
43 highlightningIsOn = true; | 94 _highlightningIsOn = true; |
44 | 95 |
45 mapHighlighternameToExtension["Bash"] = QStringList() << "sh"; | 96 _mapHighlighternameToExtension["Bash"] = QStringList() << "sh"; |
46 mapHighlighternameToExtension["Batch"] = QStringList() << "bat"; | 97 _mapHighlighternameToExtension["Batch"] = QStringList() << "bat"; |
47 mapHighlighternameToExtension["CMake"] = QStringList() << "cmake"; | 98 _mapHighlighternameToExtension["CMake"] = QStringList() << "cmake"; |
48 mapHighlighternameToExtension["C++"] = QStringList() << "c" << "h" << "cpp" << "hpp" << "cxx" << "hxx"; | 99 _mapHighlighternameToExtension["C++"] = QStringList() << "c" << "h" << "cpp" << "hpp" << "cxx" << "hxx"; |
49 mapHighlighternameToExtension["C#"] = QStringList() << "cs"; | 100 _mapHighlighternameToExtension["C#"] = QStringList() << "cs"; |
50 mapHighlighternameToExtension["CSS"] = QStringList() << "css"; | 101 _mapHighlighternameToExtension["CSS"] = QStringList() << "css"; |
51 mapHighlighternameToExtension["D"] = QStringList() << "d"; | 102 _mapHighlighternameToExtension["D"] = QStringList() << "d"; |
52 mapHighlighternameToExtension["Diff"] = QStringList() << "diff"; | 103 _mapHighlighternameToExtension["Diff"] = QStringList() << "diff"; |
53 #if ( QSCINTILLA_VERSION >= 0x020300 ) | 104 #if ( QSCINTILLA_VERSION >= 0x020300 ) |
54 mapHighlighternameToExtension["Fortran"] = QStringList() << "f" << "for" << "f90"; | 105 _mapHighlighternameToExtension["Fortran"] = QStringList() << "f" << "for" << "f90"; |
55 mapHighlighternameToExtension["Fortran77"] = QStringList() << "f77"; | 106 _mapHighlighternameToExtension["Fortran77"] = QStringList() << "f77"; |
56 #endif | 107 #endif |
57 mapHighlighternameToExtension["HTML"] = QStringList() << "html" << "htm"; | 108 _mapHighlighternameToExtension["HTML"] = QStringList() << "html" << "htm"; |
58 mapHighlighternameToExtension["IDL"] = QStringList() << "idl"; | 109 _mapHighlighternameToExtension["IDL"] = QStringList() << "idl"; |
59 mapHighlighternameToExtension["Java"] = QStringList() << "java"; | 110 _mapHighlighternameToExtension["Java"] = QStringList() << "java"; |
60 mapHighlighternameToExtension["JavaScript"] = QStringList() << "js"; | 111 _mapHighlighternameToExtension["JavaScript"] = QStringList() << "js"; |
61 mapHighlighternameToExtension["LUA"] = QStringList() << "lua"; | 112 _mapHighlighternameToExtension["LUA"] = QStringList() << "lua"; |
62 mapHighlighternameToExtension["Makefile"] = QStringList() << "makefile"; | 113 _mapHighlighternameToExtension["Makefile"] = QStringList() << "makefile"; |
63 #if ( QSCINTILLA_VERSION >= 0x020300 ) | 114 #if ( QSCINTILLA_VERSION >= 0x020300 ) |
64 mapHighlighternameToExtension["Pascal"] = QStringList() << "pas"; | 115 _mapHighlighternameToExtension["Pascal"] = QStringList() << "pas"; |
65 #endif | 116 #endif |
66 mapHighlighternameToExtension["Perl"] = QStringList() << "perl" << "pl" << "pm"; | 117 _mapHighlighternameToExtension["Perl"] = QStringList() << "perl" << "pl" << "pm"; |
67 mapHighlighternameToExtension["PHP"] = QStringList() << "php"; | 118 _mapHighlighternameToExtension["PHP"] = QStringList() << "php"; |
68 #if ( QSCINTILLA_VERSION >= 0x020300 ) | 119 #if ( QSCINTILLA_VERSION >= 0x020300 ) |
69 mapHighlighternameToExtension["PostScript"] = QStringList() << "ps" << "eps" << "pdf" << "ai" << "fh"; | 120 _mapHighlighternameToExtension["PostScript"] = QStringList() << "ps" << "eps" << "pdf" << "ai" << "fh"; |
70 #endif | 121 #endif |
71 mapHighlighternameToExtension["POV"] = QStringList() << "pov"; | 122 _mapHighlighternameToExtension["POV"] = QStringList() << "pov"; |
72 mapHighlighternameToExtension["Ini"] = QStringList() << "ini"; | 123 _mapHighlighternameToExtension["Ini"] = QStringList() << "ini"; |
73 mapHighlighternameToExtension["Python"] = QStringList() << "py"; | 124 _mapHighlighternameToExtension["Python"] = QStringList() << "py"; |
74 mapHighlighternameToExtension["Ruby"] = QStringList() << "rub" << "rb"; | 125 _mapHighlighternameToExtension["Ruby"] = QStringList() << "rub" << "rb"; |
75 mapHighlighternameToExtension["SQL"] = QStringList() << "sql"; | 126 #if ( QSCINTILLA_VERSION >= 0x020400 ) |
76 #if ( QSCINTILLA_VERSION >= 0x020300 ) | 127 _mapHighlighternameToExtension["Spice"] = QStringList() << "cir"; |
77 mapHighlighternameToExtension["TCL"] = QStringList() << "tcl"; | 128 #endif |
78 #endif | 129 _mapHighlighternameToExtension["SQL"] = QStringList() << "sql"; |
79 mapHighlighternameToExtension["TeX"] = QStringList() << "tex"; | 130 #if ( QSCINTILLA_VERSION >= 0x020300 ) |
80 mapHighlighternameToExtension["VHDL"] = QStringList() << "vhdl"; | 131 _mapHighlighternameToExtension["TCL"] = QStringList() << "tcl"; |
81 mapHighlighternameToExtension["XML"] = QStringList() << "xml"; | 132 #endif |
82 #if ( QSCINTILLA_VERSION >= 0x020300 ) | 133 _mapHighlighternameToExtension["TeX"] = QStringList() << "tex"; |
83 mapHighlighternameToExtension["YAML"] = QStringList() << "yaml"; | 134 #if ( QSCINTILLA_VERSION >= 0x020400 ) |
84 #endif | 135 _mapHighlighternameToExtension["Verilog"] = QStringList() << "v" << "vh"; |
85 | 136 #endif |
86 lexer = NULL; | 137 _mapHighlighternameToExtension["VHDL"] = QStringList() << "vhdl"; |
138 _mapHighlighternameToExtension["XML"] = QStringList() << "xml"; | |
139 #if ( QSCINTILLA_VERSION >= 0x020300 ) | |
140 _mapHighlighternameToExtension["YAML"] = QStringList() << "yaml"; | |
141 #endif | |
142 | |
143 _lexer = NULL; | |
87 | 144 |
88 // This code is only for testing. | 145 // This code is only for testing. |
89 /* | 146 /* |
90 foreach(QStringList extensionList, mapHighlighternameToExtension.values() ) { | 147 foreach(QStringList extensionList, _mapHighlighternameToExtension.values() ) { |
91 setLexerForExtension( extensionList.at(0) ); | 148 setLexerForExtension( extensionList.at(0) ); |
92 } | 149 } |
93 */ | 150 */ |
94 | 151 |
95 // Set default highlighter to C++ highlighter. | 152 // Set default highlighter to C++ highlighter. |
99 | 156 |
100 /*! | 157 /*! |
101 \brief Returns the available highlighters as QStringList. | 158 \brief Returns the available highlighters as QStringList. |
102 */ | 159 */ |
103 QStringList UiGuiHighlighter::getAvailableHighlighters() { | 160 QStringList UiGuiHighlighter::getAvailableHighlighters() { |
104 return mapHighlighternameToExtension.keys(); | 161 return _mapHighlighternameToExtension.keys(); |
105 } | 162 } |
106 | 163 |
107 | 164 |
108 /*! | 165 /*! |
109 \brief This slot handles signals coming from selecting another syntax highlighter. | 166 \brief This slot handles signals coming from selecting another syntax highlighter. |
110 */ | 167 */ |
111 void UiGuiHighlighter::setHighlighterByAction(QAction* highlighterAction) { | 168 void UiGuiHighlighter::setHighlighterByAction(QAction* highlighterAction) { |
112 QString highlighterName = highlighterAction->text(); | 169 QString highlighterName = highlighterAction->text(); |
113 setLexerForExtension( mapHighlighternameToExtension[highlighterName].first() ); | 170 setLexerForExtension( _mapHighlighternameToExtension[highlighterName].first() ); |
114 //TODO: This is really no nice way. How do it better? | 171 //TODO: This is really no nice way. How do it better? |
115 // Need to do this "text update" to update the syntax highlighting. Otherwise highlighting is wrong. | 172 // Need to do this "text update" to update the syntax highlighting. Otherwise highlighting is wrong. |
116 int scrollPos = qsciEditorParent->verticalScrollBar()->value(); | 173 int scrollPos = _qsciEditorParent->verticalScrollBar()->value(); |
117 qsciEditorParent->setText( qsciEditorParent->text() ); | 174 _qsciEditorParent->setText( _qsciEditorParent->text() ); |
118 qsciEditorParent->verticalScrollBar()->setValue(scrollPos); | 175 _qsciEditorParent->verticalScrollBar()->setValue(scrollPos); |
119 } | 176 } |
120 | 177 |
121 | 178 |
122 /*! | 179 /*! |
123 \brief Turns the syntax parser on. | 180 \brief Turns the syntax parser on. |
124 */ | 181 */ |
125 void UiGuiHighlighter::turnHighlightOn() { | 182 void UiGuiHighlighter::turnHighlightOn() { |
126 highlightningIsOn = true; | 183 _highlightningIsOn = true; |
127 qsciEditorParent->setLexer(lexer); | 184 _qsciEditorParent->setLexer(_lexer); |
128 readCurrentSettings(""); | 185 readCurrentSettings(""); |
129 } | 186 } |
130 | 187 |
131 /*! | 188 /*! |
132 \brief Turns the syntax parser off. | 189 \brief Turns the syntax parser off. |
133 */ | 190 */ |
134 void UiGuiHighlighter::turnHighlightOff() { | 191 void UiGuiHighlighter::turnHighlightOff() { |
135 highlightningIsOn = false; | 192 _highlightningIsOn = false; |
136 qsciEditorParent->setLexer(); | 193 _qsciEditorParent->setLexer(); |
137 #if defined(Q_OS_WIN) || defined(Q_OS_MAC) | 194 #if defined(Q_OS_WIN) || defined(Q_OS_MAC) |
138 qsciEditorParent->setFont( QFont("Courier", 10, QFont::Normal) ); | 195 _qsciEditorParent->setFont( QFont("Courier", 10, QFont::Normal) ); |
139 qsciEditorParent->setMarginsFont( QFont("Courier", 10, QFont::Normal) ); | 196 _qsciEditorParent->setMarginsFont( QFont("Courier", 10, QFont::Normal) ); |
140 #else | 197 #else |
141 qsciEditorParent->setFont( QFont("Monospace", 10, QFont::Normal) ); | 198 _qsciEditorParent->setFont( QFont("Monospace", 10, QFont::Normal) ); |
142 qsciEditorParent->setMarginsFont( QFont("Monospace", 10, QFont::Normal) ); | 199 _qsciEditorParent->setMarginsFont( QFont("Monospace", 10, QFont::Normal) ); |
143 #endif | 200 #endif |
144 } | 201 } |
145 | 202 |
146 | 203 |
147 /*! | 204 /*! |
152 bool ok, flag, rc = true; | 209 bool ok, flag, rc = true; |
153 int num; | 210 int num; |
154 QString key; | 211 QString key; |
155 | 212 |
156 // Reset lists containing fonts and colors for each style | 213 // Reset lists containing fonts and colors for each style |
157 fontForStyles.clear(); | 214 _fontForStyles.clear(); |
158 colorForStyles.clear(); | 215 _colorForStyles.clear(); |
159 | 216 |
160 // Read the styles. | 217 // Read the styles. |
161 for (int i = 0; i < 128; ++i) { | 218 for (int i = 0; i < 128; ++i) { |
162 // Ignore invalid styles. | 219 // Ignore invalid styles. |
163 if ( lexer->description(i).isEmpty() ) | 220 if ( _lexer->description(i).isEmpty() ) |
164 continue; | 221 continue; |
165 | 222 |
166 key.sprintf( "%s/%s/style%d/", prefix, lexer->language(), i ); | 223 key.sprintf( "%s/%s/style%d/", prefix, _lexer->language(), i ); |
167 key.replace("+", "p"); | 224 key.replace("+", "p"); |
168 | 225 |
169 // Read the foreground color. | 226 // Read the foreground color. |
170 ok = settings->contains(key + "color"); | 227 ok = _settings->contains(key + "color"); |
171 num = settings->value(key + "color", 0).toInt(); | 228 num = _settings->value(key + "color", 0).toInt(); |
172 | 229 |
173 if (ok) | 230 if (ok) |
174 setColor( QColor((num >> 16) & 0xff, (num >> 8) & 0xff, num & 0xff), i ); | 231 setColor( QColor((num >> 16) & 0xff, (num >> 8) & 0xff, num & 0xff), i ); |
175 else | 232 else |
176 rc = false; | 233 rc = false; |
177 | 234 |
178 // Read the end-of-line fill. | 235 // Read the end-of-line fill. |
179 ok = settings->contains(key + "eolfill"); | 236 ok = _settings->contains(key + "eolfill"); |
180 flag = settings->value(key + "eolfill", false).toBool(); | 237 flag = _settings->value(key + "eolfill", false).toBool(); |
181 | 238 |
182 if (ok) | 239 if (ok) |
183 lexer->setEolFill( flag, i ); | 240 _lexer->setEolFill( flag, i ); |
184 else | 241 else |
185 rc = false; | 242 rc = false; |
186 | 243 |
187 // Read the font | 244 // Read the font |
188 QStringList fdesc; | 245 QStringList fdesc; |
189 | 246 |
190 ok = settings->contains(key + "font"); | 247 ok = _settings->contains(key + "font"); |
191 fdesc = settings->value(key + "font").toStringList(); | 248 fdesc = _settings->value(key + "font").toStringList(); |
192 | 249 |
193 if (ok && fdesc.count() == 5) { | 250 if (ok && fdesc.count() == 5) { |
194 QFont f; | 251 QFont f; |
195 | 252 |
196 #if defined(Q_OS_WIN) || defined(Q_OS_MAC) | 253 #if defined(Q_OS_WIN) || defined(Q_OS_MAC) |
210 } | 267 } |
211 else | 268 else |
212 rc = false; | 269 rc = false; |
213 | 270 |
214 // Read the background color. | 271 // Read the background color. |
215 ok = settings->contains(key + "paper"); | 272 ok = _settings->contains(key + "paper"); |
216 num = settings->value(key + "paper", 0).toInt(); | 273 num = _settings->value(key + "paper", 0).toInt(); |
217 | 274 |
218 if (ok) | 275 if (ok) |
219 lexer->setPaper( QColor((num >> 16) & 0xff, (num >> 8) & 0xff, num & 0xff), i ); | 276 _lexer->setPaper( QColor((num >> 16) & 0xff, (num >> 8) & 0xff, num & 0xff), i ); |
220 else | 277 else |
221 rc = false; | 278 rc = false; |
222 } | 279 } |
223 | 280 |
224 // Read the properties. | 281 // Read the properties. |
225 key.sprintf( "%s/%s/properties/", prefix, lexer->language() ); | 282 key.sprintf( "%s/%s/properties/", prefix, _lexer->language() ); |
226 | 283 |
227 lexer->refreshProperties(); | 284 _lexer->refreshProperties(); |
228 | 285 |
229 return rc; | 286 return rc; |
230 } | 287 } |
231 | 288 |
232 | 289 |
237 QString key; | 294 QString key; |
238 | 295 |
239 // Write the styles. | 296 // Write the styles. |
240 for (int i = 0; i < 128; ++i) { | 297 for (int i = 0; i < 128; ++i) { |
241 // Ignore invalid styles. | 298 // Ignore invalid styles. |
242 if ( lexer->description(i).isEmpty() ) | 299 if ( _lexer->description(i).isEmpty() ) |
243 continue; | 300 continue; |
244 | 301 |
245 int num; | 302 int num; |
246 QColor c; | 303 QColor c; |
247 | 304 |
248 key.sprintf( "%s/%s/style%d/", prefix, lexer->language(), i ); | 305 key.sprintf( "%s/%s/style%d/", prefix, _lexer->language(), i ); |
249 key.replace("+", "p"); | 306 key.replace("+", "p"); |
250 | 307 |
251 // Write style name | 308 // Write style name |
252 settings->setValue( key + "", lexer->description(i) ); | 309 _settings->setValue( key + "", _lexer->description(i) ); |
253 | 310 |
254 // Write the foreground color. | 311 // Write the foreground color. |
255 if ( colorForStyles.contains(i) ) { | 312 if ( _colorForStyles.contains(i) ) { |
256 c = colorForStyles[i]; | 313 c = _colorForStyles[i]; |
257 } | 314 } |
258 else { | 315 else { |
259 c = lexer->color(i); | 316 c = _lexer->color(i); |
260 } | 317 } |
261 num = (c.red() << 16) | (c.green() << 8) | c.blue(); | 318 num = (c.red() << 16) | (c.green() << 8) | c.blue(); |
262 | 319 |
263 settings->setValue(key + "color", num); | 320 _settings->setValue(key + "color", num); |
264 | 321 |
265 // Write the end-of-line fill. | 322 // Write the end-of-line fill. |
266 settings->setValue( key + "eolfill", lexer->eolFill(i) ); | 323 _settings->setValue( key + "eolfill", _lexer->eolFill(i) ); |
267 | 324 |
268 // Write the font | 325 // Write the font |
269 QStringList fdesc; | 326 QStringList fdesc; |
270 QString fmt("%1"); | 327 QString fmt("%1"); |
271 QFont f; | 328 QFont f; |
272 | 329 |
273 if ( fontForStyles.contains(i) ) { | 330 if ( _fontForStyles.contains(i) ) { |
274 f = fontForStyles[i]; | 331 f = _fontForStyles[i]; |
275 } | 332 } |
276 else { | 333 else { |
277 f = lexer->font(i); | 334 f = _lexer->font(i); |
278 } | 335 } |
279 | 336 |
280 fdesc += f.family(); | 337 fdesc += f.family(); |
281 fdesc += fmt.arg( f.pointSize() ); | 338 fdesc += fmt.arg( f.pointSize() ); |
282 | 339 |
283 // The casts are for Borland. | 340 // The casts are for Borland. |
284 fdesc += fmt.arg( (int)f.bold() ); | 341 fdesc += fmt.arg( (int)f.bold() ); |
285 fdesc += fmt.arg( (int)f.italic() ); | 342 fdesc += fmt.arg( (int)f.italic() ); |
286 fdesc += fmt.arg( (int)f.underline() ); | 343 fdesc += fmt.arg( (int)f.underline() ); |
287 | 344 |
288 settings->setValue(key + "font", fdesc); | 345 _settings->setValue(key + "font", fdesc); |
289 | 346 |
290 // Write the background color. | 347 // Write the background color. |
291 c = lexer->paper(i); | 348 c = _lexer->paper(i); |
292 num = (c.red() << 16) | (c.green() << 8) | c.blue(); | 349 num = (c.red() << 16) | (c.green() << 8) | c.blue(); |
293 | 350 |
294 settings->setValue(key + "paper", num); | 351 _settings->setValue(key + "paper", num); |
295 } | 352 } |
296 } | 353 } |
297 | 354 |
298 | 355 |
299 /*! | 356 /*! |
300 \brief Sets the \a color for the given \a style. | 357 \brief Sets the \a color for the given \a style. |
301 */ | 358 */ |
302 void UiGuiHighlighter::setColor(const QColor &color, int style) { | 359 void UiGuiHighlighter::setColor(const QColor &color, int style) { |
303 colorForStyles[style] = color; | 360 _colorForStyles[style] = color; |
304 lexer->setColor( color, style ); | 361 _lexer->setColor( color, style ); |
305 } | 362 } |
306 | 363 |
307 | 364 |
308 /*! | 365 /*! |
309 \brief Sets the \a font for the given \a style. | 366 \brief Sets the \a font for the given \a style. |
310 */ | 367 */ |
311 void UiGuiHighlighter::setFont(const QFont &font, int style) { | 368 void UiGuiHighlighter::setFont(const QFont &font, int style) { |
312 fontForStyles[style] = font; | 369 _fontForStyles[style] = font; |
313 lexer->setFont( font, style ); | 370 _lexer->setFont( font, style ); |
314 } | 371 } |
315 | 372 |
316 | 373 |
317 /*! | 374 /*! |
318 \brief Sets the to be used lexer by giving his name. | 375 \brief Sets the to be used lexer by giving his name. |
319 */ | 376 */ |
320 void UiGuiHighlighter::setLexerByName( QString lexerName ) { | 377 void UiGuiHighlighter::setLexerByName( QString lexerName ) { |
321 setLexerForExtension( mapHighlighternameToExtension[lexerName].first() ); | 378 setLexerForExtension( _mapHighlighternameToExtension[lexerName].first() ); |
322 } | 379 } |
323 | 380 |
324 | 381 |
325 /*! | 382 /*! |
326 \brief Sets the proper highlighter / lexer for the given file \a extension. Returns the index of the used lexer in the list. | 383 \brief Sets the proper highlighter / lexer for the given file \a extension. Returns the index of the used lexer in the list. |
327 */ | 384 */ |
328 int UiGuiHighlighter::setLexerForExtension( QString extension ) { | 385 int UiGuiHighlighter::setLexerForExtension( QString extension ) { |
329 int indexOfHighlighter = 0; | 386 int indexOfHighlighter = 0; |
330 extension = extension.toLower(); | 387 extension = extension.toLower(); |
331 | 388 |
332 if ( lexer != NULL ) { | 389 if ( _lexer != NULL ) { |
333 writeCurrentSettings(""); | 390 writeCurrentSettings(""); |
334 delete lexer; | 391 delete _lexer; |
335 } | 392 } |
336 | 393 |
337 if ( extension == "cpp" || extension == "hpp" || extension == "c" || extension == "h" || extension == "cxx" || extension == "hxx" ) { | 394 if ( extension == "cpp" || extension == "hpp" || extension == "c" || extension == "h" || extension == "cxx" || extension == "hxx" ) { |
338 lexer = new QsciLexerCPP(); | 395 _lexer = new QsciLexerCPP(); |
339 } | 396 } |
340 else if ( extension == "sh" ) { | 397 else if ( extension == "sh" ) { |
341 lexer = new QsciLexerBash(); | 398 _lexer = new QsciLexerBash(); |
342 } | 399 } |
343 else if ( extension == "bat" ) { | 400 else if ( extension == "bat" ) { |
344 lexer = new QsciLexerBatch(); | 401 _lexer = new QsciLexerBatch(); |
345 } | 402 } |
346 else if ( extension == "cmake" ) { | 403 else if ( extension == "cmake" ) { |
347 lexer = new QsciLexerCMake(); | 404 _lexer = new QsciLexerCMake(); |
348 } | 405 } |
349 else if ( extension == "cs" ) { | 406 else if ( extension == "cs" ) { |
350 lexer = new QsciLexerCSharp(); | 407 _lexer = new QsciLexerCSharp(); |
351 } | 408 } |
352 else if ( extension == "css" ) { | 409 else if ( extension == "css" ) { |
353 lexer = new QsciLexerCSS(); | 410 _lexer = new QsciLexerCSS(); |
354 } | 411 } |
355 else if ( extension == "d" ) { | 412 else if ( extension == "d" ) { |
356 lexer = new QsciLexerD(); | 413 _lexer = new QsciLexerD(); |
357 } | 414 } |
358 else if ( extension == "diff" ) { | 415 else if ( extension == "diff" ) { |
359 lexer = new QsciLexerDiff(); | 416 _lexer = new QsciLexerDiff(); |
360 } | 417 } |
361 #if ( QSCINTILLA_VERSION >= 0x020300 ) | 418 #if ( QSCINTILLA_VERSION >= 0x020300 ) |
362 else if ( extension == "f" || extension == "for" || extension == "f90" ) { | 419 else if ( extension == "f" || extension == "for" || extension == "f90" ) { |
363 lexer = new QsciLexerFortran(); | 420 _lexer = new QsciLexerFortran(); |
364 } | 421 } |
365 else if ( extension == "f77" ) { | 422 else if ( extension == "f77" ) { |
366 lexer = new QsciLexerFortran77(); | 423 _lexer = new QsciLexerFortran77(); |
367 } | 424 } |
368 #endif | 425 #endif |
369 else if ( extension == "html" || extension == "htm" ) { | 426 else if ( extension == "html" || extension == "htm" ) { |
370 lexer = new QsciLexerHTML(); | 427 _lexer = new QsciLexerHTML(); |
371 } | 428 } |
372 else if ( extension == "idl" ) { | 429 else if ( extension == "idl" ) { |
373 lexer = new QsciLexerIDL(); | 430 _lexer = new QsciLexerIDL(); |
374 } | 431 } |
375 else if ( extension == "java" ) { | 432 else if ( extension == "java" ) { |
376 lexer = new QsciLexerJava(); | 433 _lexer = new QsciLexerJava(); |
377 } | 434 } |
378 else if ( extension == "js" ) { | 435 else if ( extension == "js" ) { |
379 lexer = new QsciLexerJavaScript(); | 436 _lexer = new QsciLexerJavaScript(); |
380 } | 437 } |
381 else if ( extension == "lua" ) { | 438 else if ( extension == "lua" ) { |
382 lexer = new QsciLexerLua(); | 439 _lexer = new QsciLexerLua(); |
383 } | 440 } |
384 else if ( extension == "makefile" ) { | 441 else if ( extension == "makefile" ) { |
385 lexer = new QsciLexerMakefile(); | 442 _lexer = new QsciLexerMakefile(); |
386 } | 443 } |
387 #if ( QSCINTILLA_VERSION >= 0x020300 ) | 444 #if ( QSCINTILLA_VERSION >= 0x020300 ) |
388 else if ( extension == "pas" ) { | 445 else if ( extension == "pas" ) { |
389 lexer = new QsciLexerPascal(); | 446 _lexer = new QsciLexerPascal(); |
390 } | 447 } |
391 #endif | 448 #endif |
392 else if ( extension == "perl" || extension == "pl" || extension == "pm" ) { | 449 else if ( extension == "perl" || extension == "pl" || extension == "pm" ) { |
393 lexer = new QsciLexerPerl(); | 450 _lexer = new QsciLexerPerl(); |
394 } | 451 } |
395 else if ( extension == "php" ) { | 452 else if ( extension == "php" ) { |
396 lexer = new QsciLexerHTML(); | 453 _lexer = new QsciLexerHTML(); |
397 } | 454 } |
398 #if ( QSCINTILLA_VERSION >= 0x020300 ) | 455 #if ( QSCINTILLA_VERSION >= 0x020300 ) |
399 else if ( extension == "ps" || extension == "eps" || extension == "pdf" || extension == "ai" || extension == "fh") { | 456 else if ( extension == "ps" || extension == "eps" || extension == "pdf" || extension == "ai" || extension == "fh") { |
400 lexer = new QsciLexerPostScript(); | 457 _lexer = new QsciLexerPostScript(); |
401 } | 458 } |
402 #endif | 459 #endif |
403 else if ( extension == "pov" ) { | 460 else if ( extension == "pov" ) { |
404 lexer = new QsciLexerPOV(); | 461 _lexer = new QsciLexerPOV(); |
405 } | 462 } |
406 else if ( extension == "ini" ) { | 463 else if ( extension == "ini" ) { |
407 lexer = new QsciLexerProperties(); | 464 _lexer = new QsciLexerProperties(); |
408 } | 465 } |
409 else if ( extension == "py" ) { | 466 else if ( extension == "py" ) { |
410 lexer = new QsciLexerPython(); | 467 _lexer = new QsciLexerPython(); |
411 } | 468 } |
412 else if ( extension == "rub" || extension == "rb" ) { | 469 else if ( extension == "rub" || extension == "rb" ) { |
413 lexer = new QsciLexerRuby(); | 470 _lexer = new QsciLexerRuby(); |
414 } | 471 } |
472 #if ( QSCINTILLA_VERSION >= 0x020400 ) | |
473 else if ( extension == "spice?" ) { | |
474 _lexer = new QsciLexerSpice(); | |
475 } | |
476 #endif | |
415 else if ( extension == "sql" ) { | 477 else if ( extension == "sql" ) { |
416 lexer = new QsciLexerSQL(); | 478 _lexer = new QsciLexerSQL(); |
417 } | 479 } |
418 #if ( QSCINTILLA_VERSION >= 0x020300 ) | 480 #if ( QSCINTILLA_VERSION >= 0x020300 ) |
419 else if ( extension == "tcl" ) { | 481 else if ( extension == "tcl" ) { |
420 lexer = new QsciLexerTCL(); | 482 _lexer = new QsciLexerTCL(); |
421 } | 483 } |
422 #endif | 484 #endif |
423 else if ( extension == "tex" ) { | 485 else if ( extension == "tex" ) { |
424 lexer = new QsciLexerTeX(); | 486 _lexer = new QsciLexerTeX(); |
425 } | 487 } |
488 #if ( QSCINTILLA_VERSION >= 0x020400 ) | |
489 else if ( extension == "vlog?" ) { | |
490 _lexer = new QsciLexerVerilog(); | |
491 } | |
492 #endif | |
426 else if ( extension == "vhdl" ) { | 493 else if ( extension == "vhdl" ) { |
427 lexer = new QsciLexerVHDL(); | 494 _lexer = new QsciLexerVHDL(); |
428 } | 495 } |
429 else if ( extension == "xml" ) { | 496 else if ( extension == "xml" ) { |
430 #if ( QSCINTILLA_VERSION >= 0x020300 ) | 497 #if ( QSCINTILLA_VERSION >= 0x020300 ) |
431 lexer = new QsciLexerXML(); | 498 _lexer = new QsciLexerXML(); |
432 #else | 499 #else |
433 lexer = new QsciLexerHTML(); | 500 _lexer = new QsciLexerHTML(); |
434 #endif | 501 #endif |
435 } | 502 } |
436 #if ( QSCINTILLA_VERSION >= 0x020300 ) | 503 #if ( QSCINTILLA_VERSION >= 0x020300 ) |
437 else if ( extension == "yaml" ) { | 504 else if ( extension == "yaml" ) { |
438 lexer = new QsciLexerYAML(); | 505 _lexer = new QsciLexerYAML(); |
439 } | 506 } |
440 #endif | 507 #endif |
441 else { | 508 else { |
442 lexer = new QsciLexerCPP(); | 509 _lexer = new QsciLexerCPP(); |
443 extension = "cpp"; | 510 extension = "cpp"; |
444 } | 511 } |
445 | 512 |
446 // Find the index of the selected lexer. | 513 // Find the index of the selected _lexer. |
447 indexOfHighlighter = 0; | 514 indexOfHighlighter = 0; |
448 while ( !mapHighlighternameToExtension.values().at(indexOfHighlighter).contains(extension) ) { | 515 while ( !_mapHighlighternameToExtension.values().at(indexOfHighlighter).contains(extension) ) { |
449 indexOfHighlighter++; | 516 indexOfHighlighter++; |
450 } | 517 } |
451 | 518 |
452 // Set the lexer for the QScintilla widget. | 519 // Set the _lexer for the QScintilla widget. |
453 if ( highlightningIsOn ) { | 520 if ( _highlightningIsOn ) { |
454 qsciEditorParent->setLexer(lexer); | 521 _qsciEditorParent->setLexer(_lexer); |
455 } | 522 } |
456 | 523 |
457 // Read the settings for the lexer properties from file. | 524 // Read the _settings for the _lexer properties from file. |
458 readCurrentSettings(""); | 525 readCurrentSettings(""); |
459 | 526 |
460 return indexOfHighlighter; | 527 return indexOfHighlighter; |
461 } | 528 } |