itom  4.1.0
syntaxHighlighterBase.h
1 /* ********************************************************************
2  itom software
3  URL: http://www.uni-stuttgart.de/ito
4  Copyright (C) 2020, Institut fuer Technische Optik (ITO),
5  Universitaet Stuttgart, Germany
6 
7  This file is part of itom.
8 
9  itom is free software; you can redistribute it and/or modify it
10  under the terms of the GNU Library General Public Licence as published by
11  the Free Software Foundation; either version 2 of the Licence, or (at
12  your option) any later version.
13 
14  itom is distributed in the hope that it will be useful, but
15  WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
17  General Public Licence for more details.
18 
19  You should have received a copy of the GNU Library General Public License
20  along with itom. If not, see <http://www.gnu.org/licenses/>.
21 
22  Further hints:
23  ------------------------
24 
25  This file belongs to the code editor of itom. The code editor is
26  in major parts a fork / rewritten version of the python-based source
27  code editor PyQode from Colin Duquesnoy and others
28  (see https://github.com/pyQode). PyQode itself is licensed under
29  the MIT License (MIT).
30 
31  Some parts of the code editor of itom are also inspired by the
32  source code editor of the Spyder IDE (https://github.com/spyder-ide),
33  also licensed under the MIT License and developed by the Spyder Project
34  Contributors.
35 
36 *********************************************************************** */
37 
38 #ifndef SYNTAXHIGHLIGHTERBASE_H
39 #define SYNTAXHIGHLIGHTERBASE_H
40 
41 #include <qstring.h>
42 #include <qtextedit.h>
43 #include <qsyntaxhighlighter.h>
44 #include <qpointer.h>
45 #include <qmap.h>
46 
47 #include "../textBlockUserData.h"
48 #include "../mode.h"
49 #include "../foldDetector/foldDetector.h"
50 #include "codeEditorStyle.h"
51 
52 namespace ito {
53 
54 class CodeEditor; //forware declaration
55 
56 /*
57 Syntax Highlighters should derive from this mode instead of mode directly.
58 */
59 class SyntaxHighlighterBase : public QSyntaxHighlighter, public Mode
60 {
61  Q_OBJECT
62 public:
63  SyntaxHighlighterBase(const QString &name, QTextDocument *parent, const QString &description = "", QSharedPointer<CodeEditorStyle> editorStyle = QSharedPointer<CodeEditorStyle>());
64 
65  virtual ~SyntaxHighlighterBase();
66 
67  void setFoldDetector(QSharedPointer<FoldDetector> foldDetector);
68 
69  virtual void onStateChanged(bool state);
70  virtual void onInstall(CodeEditor *editor);
71 
72  QSharedPointer<CodeEditorStyle> editorStyle() const { return m_editorStyle; }
73 
74  /*
75  Highlights a block of text. Please do not override, this method.
76  Instead you should implement
77  :func:`pyqode.core.api.SyntaxHighlighter.highlight_block`.
78 
79  :param text: text to highlight.
80  */
81  void highlightBlock(const QString &text);
82 
83  void refreshEditor(QSharedPointer<CodeEditorStyle> editorStyle);
84 
85  /*
86  Abstract method. Override this to apply syntax highlighting.
87 
88  :param text: Line of text to highlight.
89  :param block: current block
90  */
91  virtual void highlight_block(const QString &text, QTextBlock &block) = 0;
92 
93  virtual void default_highlight_block(const QString &text, bool outputNotError) = 0;
94 
95  virtual void rehighlight();
96 
97 protected:
98  static QTextBlock findPrevNonBlankBlock(const QTextBlock &currentBlock);
99 
100  void highlightWhitespaces(const QString &text);
101 
102  QRegExp m_regWhitespaces;
103  QRegExp m_regSpacesPtrn;
104  QSharedPointer<CodeEditorStyle> m_editorStyle;
105  QSharedPointer<FoldDetector> m_foldDetector;
106 };
107 
108 } //end namespace ito
109 
110 #endif
Definition: codeEditor.h:110
Definition: syntaxHighlighterBase.h:59
Definition: apiFunctionsGraph.cpp:39
Definition: mode.h:69