]> git.sven.stormbind.net Git - sven/vym.git/blob - highlighter.h
Import Upstream version 2.6.11
[sven/vym.git] / highlighter.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2005-2006 Trolltech ASA. All rights reserved.
4 **
5 ** This file is part of the example classes of the Qt Toolkit.
6 **
7 ** This file may be used under the terms of the GNU General Public
8 ** License version 2.0 as published by the Free Software Foundation
9 ** and appearing in the file LICENSE.GPL included in the packaging of
10 ** this file.  Please review the following information to ensure GNU
11 ** General Public Licensing requirements will be met:
12 ** http://www.trolltech.com/products/qt/opensource.html
13 **
14 ** If you are unsure which license is appropriate for your use, please
15 ** review the following information:
16 ** http://www.trolltech.com/products/qt/licensing.html or contact the
17 ** sales department at sales@trolltech.com.
18 **
19 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
20 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 **
22 ****************************************************************************/
23
24 #ifndef HIGHLIGHTER_H
25 #define HIGHLIGHTER_H
26
27 #include <QSyntaxHighlighter>
28
29 #include <QHash>
30 #include <QTextCharFormat>
31
32 class QTextDocument;
33
34 class Highlighter : public QSyntaxHighlighter
35 {
36     Q_OBJECT
37
38 public:
39     Highlighter(QTextDocument *parent = 0);
40     void addKeywords (const QStringList &sl);
41
42 protected:
43     void highlightBlock(const QString &text);
44
45 private:
46     struct HighlightingRule
47     {
48         QRegExp pattern;
49         QTextCharFormat format;
50     };
51     QVector<HighlightingRule> highlightingRules;
52
53     QRegExp commentStartExpression;
54     QRegExp commentEndExpression;
55
56     QTextCharFormat keywordFormat;
57     QTextCharFormat classFormat;
58     QTextCharFormat singleLineCommentFormat;
59     QTextCharFormat multiLineCommentFormat;
60     QTextCharFormat quotationFormat;
61     QTextCharFormat functionFormat;
62 };
63
64 #endif