Tulip  4.3.0
Better Visualization Through Research
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Groups Pages
PythonCodeHighlighter.h
1 /*
2  *
3  * This file is part of Tulip (www.tulip-software.org)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux 1 and Inria Bordeaux - Sud Ouest
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  */
19 
20 /**
21  *
22  * This file is part of Tulip (www.tulip-software.org)
23  *
24  * Authors: David Auber and the Tulip development Team
25  * from LaBRI, University of Bordeaux 1 and Inria Bordeaux - Sud Ouest
26  *
27  * Tulip is free software; you can redistribute it and/or modify
28  * it under the terms of the GNU Lesser General Public License
29  * as published by the Free Software Foundation, either version 3
30  * of the License, or (at your option) any later version.
31  *
32  * Tulip is distributed in the hope that it will be useful,
33  * but WITHOUT ANY WARRANTY; without even the implied warranty of
34  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
35  * See the GNU General Public License for more details.
36  *
37  */
38 
39 #ifndef PYTHONCODEHIGHLIGHTER_H_
40 #define PYTHONCODEHIGHLIGHTER_H_
41 
42 #include <QSyntaxHighlighter>
43 
44 #include <QHash>
45 #include <QTextCharFormat>
46 
47 class QTextDocument;
48 
49 class PythonCodeHighlighter : public QSyntaxHighlighter {
50 
51  struct HighlightingRule {
52  QRegExp pattern;
53  QTextCharFormat format;
54  };
55 
56  QVector<HighlightingRule> _highlightingRules;
57  QTextCharFormat _keywordFormat;
58  QTextCharFormat _classFormat;
59  QTextCharFormat _commentFormat;
60  QTextCharFormat _quotationFormat;
61  QTextCharFormat _functionFormat;
62  QTextCharFormat _numberFormat;
63  QTextCharFormat _tlpApiFormat;
64  QTextCharFormat _qtApiFormat;
65 
66  bool _shellMode;
67 
68 public:
69 
70  explicit PythonCodeHighlighter(QTextDocument *parent = 0);
71 
72  void setShellMode(const bool shellMode) {
73  _shellMode = shellMode;
74  }
75 
76 protected:
77 
78  void highlightBlock(const QString &text);
79 
80 };
81 
82 #endif /* PYTHONCODEHIGHLIGHTER_H_ */