Stellarium 0.13.2
StelScriptSyntaxHighlighter.hpp
1 /*
2  * Stellarium
3  * Copyright (C) 2009 Matthew Gates
4  *
5  * Derived from the QT syntax highlighter example under the GNU GPL.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
20  */
21 
22 #ifndef _STELSCRIPTSYNTAXHIGHLIGHTER_HPP_
23 #define _STELSCRIPTSYNTAXHIGHLIGHTER_HPP_
24 
25 #include <QSyntaxHighlighter>
26 #include <QHash>
27 #include <QTextCharFormat>
28 
29 class QTextDocument;
30 
31 class StelScriptSyntaxHighlighter : public QSyntaxHighlighter
32 {
33  Q_OBJECT
34 
35 public:
36  StelScriptSyntaxHighlighter(QTextDocument* parent=0);
37  void setFormats(void);
38 
39 protected:
40  void highlightBlock(const QString &text);
41 
42 private:
43  struct HighlightingRule
44  {
45  QRegExp pattern;
46  QTextCharFormat* format;
47  };
48  QVector<HighlightingRule> highlightingRules;
49 
50  QTextCharFormat keywordFormat;
51  QTextCharFormat moduleFormat;
52  QTextCharFormat commentFormat;
53  QTextCharFormat constantFormat;
54  QTextCharFormat functionFormat;
55 };
56 
57 #endif // _STELSCRIPTSYNTAXHIGHLIGHTER_HPP_
58