CuteLogger
Fast and simple logging solution for Qt based applications
highlighter.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the Graphics Dojo project on Qt Labs.
7 **
8 ** This file may be used under the terms of the GNU General Public
9 ** License version 2.0 or 3.0 as published by the Free Software Foundation
10 ** and appearing in the file LICENSE.GPL included in the packaging of
11 ** this file. Please review the following information to ensure GNU
12 ** General Public Licensing requirements will be met:
13 ** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
14 ** http://www.gnu.org/copyleft/gpl.html.
15 **
16 ** If you are unsure which license is appropriate for your use, please
17 ** contact the sales department at qt-sales@nokia.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 <QHash>
28 #include <QSyntaxHighlighter>
29 
30 // based on http://doc.trolltech.com/qq/qq21-syntaxhighlighter.html
31 
32 class Highlighter : public QSyntaxHighlighter
33 {
34  Q_OBJECT
35 
36 public:
37 
38  Highlighter(QTextDocument *document);
39 
40  enum Construct {
41  DocType,
42  Entity,
43  Tag,
44  Comment,
45  AttributeName,
46  AttributeValue
47  };
48 
49 protected:
50  enum State {
51  State_Text = -1,
52  State_DocType,
53  State_Comment,
54  State_TagStart,
55  State_TagName,
56  State_InsideTag,
57  State_AttributeName,
58  State_SingleQuote,
59  State_DoubleQuote,
60  State_AttributeValue,
61  };
62 
63  void highlightBlock(const QString &text);
64 
65 private:
66  QHash<int, QColor> m_colors;
67 };
68 
69 
70 #endif // HIGHLIGHTER_H