Salome HOME
Remove unnecessary trace from CMake.
[modules/gui.git] / src / PyEditor / PyEditor_PyHighlighter.h
1 // Copyright (C) 2015-2016  OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // File   : PyEditor_PyHighlighter.h
20 // Author : Maxim GLIBIN, Open CASCADE S.A.S. (maxim.glibin@opencascade.com)
21 //
22
23 #ifndef PYEDITOR_PYHIGHLIGHTER_H
24 #define PYEDITOR_PYHIGHLIGHTER_H
25
26 #include <QSyntaxHighlighter>
27
28 class QTextDocument;
29
30 class PyEditor_PyHighlighter : public QSyntaxHighlighter
31 {
32   Q_OBJECT
33
34 public:
35
36   struct ParenthesisInfo
37   {
38     char character;
39     int position;
40   };
41
42   class TextBlockData : public QTextBlockUserData
43   {
44   public:
45     TextBlockData();
46
47     QVector<ParenthesisInfo*> parentheses();
48     void insert( ParenthesisInfo* );
49
50   private:
51     QVector<ParenthesisInfo*> my_Parentheses;
52   };
53
54 public:
55   PyEditor_PyHighlighter( QTextDocument* = 0 );
56
57   void initialize();
58   QStringList keywords();
59   QStringList specialKeywords();
60
61 protected:
62   struct HighlightingRule
63   {
64     QRegExp pattern;
65     QTextCharFormat format;
66     int capture;
67   };
68   QVector<HighlightingRule> highlightingRules;
69
70   enum Brackets { RoundBrackets, CurlyBrackets, SquareBrackets };
71
72   QRegExp tripleQuotesExpression;
73   QRegExp tripleSingleExpression;
74   QRegExp tripleDoubleExpression;
75
76   QTextCharFormat classFormat;
77   QTextCharFormat referenceClassFormat;
78   QTextCharFormat functionFormat;
79   QTextCharFormat keywordFormat;
80   QTextCharFormat specialFromat;
81   QTextCharFormat numberFormat;
82   QTextCharFormat singleLineCommentFormat;
83   QTextCharFormat multiLineCommentFormat;
84   QTextCharFormat quotationFormat;
85
86   void highlightBlock( const QString& );
87   void insertBracketsData( char, char, TextBlockData*, const QString& );
88   void insertBracketsData( Brackets, TextBlockData*, const QString& );
89 };
90
91 #endif // PYEDITOR_PYHIGHLIGHTER_H