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 "config.h"
26 #include <QSyntaxHighlighter>
27 #include <QHash>
28 #include <QTextCharFormat>
29 
30 class QTextDocument;
31 
32 class StelScriptSyntaxHighlighter : public QSyntaxHighlighter
33 {
34  Q_OBJECT
35 
36 public:
37  StelScriptSyntaxHighlighter(QTextDocument* parent=0);
38  void setFormats(void);
39 
40 protected:
41  void highlightBlock(const QString &text);
42 
43 private:
44  struct HighlightingRule
45  {
46  QRegExp pattern;
47  QTextCharFormat* format;
48  };
49  QVector<HighlightingRule> highlightingRules;
50 
51  QTextCharFormat keywordFormat;
52  QTextCharFormat moduleFormat;
53  QTextCharFormat commentFormat;
54  QTextCharFormat constantFormat;
55  QTextCharFormat functionFormat;
56 };
57 
58 #endif // _STELSCRIPTSYNTAXHIGHLIGHTER_HPP_
59