QtiPlot  0.9.8.2
PythonSyntaxHighlighter.h
Go to the documentation of this file.
00001 /***************************************************************************
00002     File                 : PythonSyntaxHighlighter.h
00003     Project              : QtiPlot
00004     --------------------------------------------------------------------
00005     Copyright            : (C) 2008 by Ion Vasilief
00006     Email (use @ for *)  : ion_vasilief*yahoo.fr
00007     Description          : Python Syntax Highlighting based on the Qt Syntax Highlighter Example
00008                             (http://doc.trolltech.com/4.4/richtext-syntaxhighlighter.html)
00009 
00010  ***************************************************************************/
00011 
00012 /***************************************************************************
00013  *                                                                         *
00014  *  This program is free software; you can redistribute it and/or modify   *
00015  *  it under the terms of the GNU General Public License as published by   *
00016  *  the Free Software Foundation; either version 2 of the License, or      *
00017  *  (at your option) any later version.                                    *
00018  *                                                                         *
00019  *  This program is distributed in the hope that it will be useful,        *
00020  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
00021  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
00022  *  GNU General Public License for more details.                           *
00023  *                                                                         *
00024  *   You should have received a copy of the GNU General Public License     *
00025  *   along with this program; if not, write to the Free Software           *
00026  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
00027  *   Boston, MA  02110-1301  USA                                           *
00028  *                                                                         *
00029  ***************************************************************************/
00030 
00031 #ifndef PYTHON_HIGHLIGHTER_H
00032 #define PYTHON_HIGHLIGHTER_H
00033 
00034 #include <QSyntaxHighlighter>
00035 #include <QHash>
00036 #include <QTextCharFormat>
00037 
00038 #include "ScriptEdit.h"
00039 
00040 QT_BEGIN_NAMESPACE
00041 class QTextDocument;
00042 QT_END_NAMESPACE
00043 
00044 class SyntaxHighlighter : public QSyntaxHighlighter
00045 {
00046     Q_OBJECT
00047 
00048 public:
00049     SyntaxHighlighter(ScriptEdit * parent);
00050 
00051 protected:
00052     void highlightBlock(const QString &text);
00053 
00054     struct HighlightingRule
00055     {
00056         QRegExp pattern;
00057         QTextCharFormat format;
00058     };
00059 
00060     QVector<HighlightingRule> highlightingRules;
00061 
00062     QTextCharFormat commentFormat;
00063     QTextCharFormat quotationFormat;
00064     QTextCharFormat functionFormat;
00065     QTextCharFormat numericFormat;
00066 };
00067 
00068 class PythonSyntaxHighlighter : public SyntaxHighlighter
00069 {
00070     Q_OBJECT
00071 
00072 public:
00073     PythonSyntaxHighlighter(ScriptEdit *parent);
00074 
00075     static QStringList keywordsList(){return d_keywords;};
00076 
00077 protected:
00078     void highlightBlock(const QString &text);
00079 
00080 private:
00081     QVector<HighlightingRule> pythonHighlightingRules;
00082 
00083     QTextCharFormat keywordFormat;
00084     QTextCharFormat classFormat;
00085 
00086     static const QStringList d_keywords;
00087 };
00088 
00089 #endif