QtiPlot  0.9.8.2
PythonSyntaxHighlighter.h
Go to the documentation of this file.
1 /***************************************************************************
2  File : PythonSyntaxHighlighter.h
3  Project : QtiPlot
4  --------------------------------------------------------------------
5  Copyright : (C) 2008 by Ion Vasilief
6  Email (use @ for *) : ion_vasilief*yahoo.fr
7  Description : Python Syntax Highlighting based on the Qt Syntax Highlighter Example
8  (http://doc.trolltech.com/4.4/richtext-syntaxhighlighter.html)
9 
10  ***************************************************************************/
11 
12 /***************************************************************************
13  * *
14  * This program is free software; you can redistribute it and/or modify *
15  * it under the terms of the GNU General Public License as published by *
16  * the Free Software Foundation; either version 2 of the License, or *
17  * (at your option) any later version. *
18  * *
19  * This program is distributed in the hope that it will be useful, *
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
22  * GNU General Public License for more details. *
23  * *
24  * You should have received a copy of the GNU General Public License *
25  * along with this program; if not, write to the Free Software *
26  * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
27  * Boston, MA 02110-1301 USA *
28  * *
29  ***************************************************************************/
30 
31 #ifndef PYTHON_HIGHLIGHTER_H
32 #define PYTHON_HIGHLIGHTER_H
33 
34 #include <QSyntaxHighlighter>
35 #include <QHash>
36 #include <QTextCharFormat>
37 
38 #include "ScriptEdit.h"
39 
40 QT_BEGIN_NAMESPACE
41 class QTextDocument;
42 QT_END_NAMESPACE
43 
44 class SyntaxHighlighter : public QSyntaxHighlighter
45 {
46  Q_OBJECT
47 
48 public:
49  SyntaxHighlighter(ScriptEdit * parent);
50 
51 protected:
52  void highlightBlock(const QString &text);
53 
55  {
56  QRegExp pattern;
57  QTextCharFormat format;
58  };
59 
60  QVector<HighlightingRule> highlightingRules;
61 
62  QTextCharFormat commentFormat;
63  QTextCharFormat quotationFormat;
64  QTextCharFormat functionFormat;
65  QTextCharFormat numericFormat;
66 };
67 
69 {
70  Q_OBJECT
71 
72 public:
74 
75  static QStringList keywordsList(){return d_keywords;};
76 
77 protected:
78  void highlightBlock(const QString &text);
79 
80 private:
81  QVector<HighlightingRule> pythonHighlightingRules;
82 
83  QTextCharFormat keywordFormat;
84  QTextCharFormat classFormat;
85 
86  static const QStringList d_keywords;
87 };
88 
89 #endif
static QStringList keywordsList()
Definition: PythonSyntaxHighlighter.h:75
SyntaxHighlighter(ScriptEdit *parent)
Definition: PythonSyntaxHighlighter.cpp:123
QTextCharFormat format
Definition: PythonSyntaxHighlighter.h:57
QRegExp pattern
Definition: PythonSyntaxHighlighter.h:56
QVector< HighlightingRule > pythonHighlightingRules
Definition: PythonSyntaxHighlighter.h:81
Definition: PythonSyntaxHighlighter.h:54
static const QStringList d_keywords
Definition: PythonSyntaxHighlighter.h:86
void highlightBlock(const QString &text)
Parentheses matching code taken from Qt Quarterly Issue 31 · Q3 2009.
Definition: PythonSyntaxHighlighter.cpp:152
QTextCharFormat classFormat
Definition: PythonSyntaxHighlighter.h:84
QTextCharFormat functionFormat
Definition: PythonSyntaxHighlighter.h:64
QVector< HighlightingRule > highlightingRules
Definition: PythonSyntaxHighlighter.h:60
Editor widget with support for evaluating expressions and executing code.
Definition: ScriptEdit.h:50
Definition: PythonSyntaxHighlighter.h:68
QTextCharFormat keywordFormat
Definition: PythonSyntaxHighlighter.h:83
QTextCharFormat numericFormat
Definition: PythonSyntaxHighlighter.h:65
QTextCharFormat commentFormat
Definition: PythonSyntaxHighlighter.h:62
QTextCharFormat quotationFormat
Definition: PythonSyntaxHighlighter.h:63
Definition: PythonSyntaxHighlighter.h:44