itom  4.1.0
symbolMatcherMode.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 SYMBOLMATCHERMODE_H
39 #define SYMBOLMATCHERMODE_H
40 
41 /*
42 This module contains the symbol matcher mode
43 */
44 
45 #include "../textDecoration.h"
46 #include "../mode.h"
47 #include "../utils/utils.h"
48 
49 #include <qcolor.h>
50 #include <qbrush.h>
51 #include <qcolor.h>
52 #include <qtextcursor.h>
53 
54 namespace ito {
55 
56 /*
57 Highlights matching symbols (parentheses, braces,...)
58 
59 .. note:: This mode requires the document to be filled with
60  :class:`pyqode.core.api.TextBlockUserData`, i.e. a
61  :class:`pyqode.core.api.SyntaxHighlighter` must be installed on
62  the editor instance.
63 */
64 class SymbolMatcherMode : public QObject, public Mode
65 {
66  Q_OBJECT
67 public:
68 
69  // symbols indices
70  enum Symbols { Paren = 0, Square = 2, Brace = 4 }; //Position of Symbol in chars bytearray
71 
72  enum CharType { Open = 0, Close = 1}; //Sub-Position of Symbol in chars bytearray
73 
74  static const QByteArray chars;
75 
76  SymbolMatcherMode(const QString &description = "", QObject *parent = NULL);
77  virtual ~SymbolMatcherMode();
78 
79  QBrush matchBackground() const;
80  void setMatchBackground(const QBrush &value);
81 
82  QColor matchForeground() const;
83  void setMatchForeground(const QColor &value);
84 
85  QBrush unmatchBackground() const;
86  void setUnmatchBackground(const QBrush &value);
87 
88  QColor unmatchForeground() const;
89  void setUnmatchForeground(const QColor &value);
90 
91  virtual void onStateChanged(bool state);
92 
93  QPoint symbolPos(const QTextCursor &cursor, CharType charType = Open, Symbols symbolType =Paren);
94 
95 private slots:
96  void doSymbolsMatching();
97 
98 protected:
99  QTextCursor createDecoration(int pos, bool match = true);
100  void clearDecorations();
101  void match(Symbols symbol, QList<Utils::ParenthesisInfo> &data, int cursorPos);
102  bool matchLeft(SymbolMatcherMode::Symbols symbol, const QTextBlock &currentBlock, int i, int cpt);
103  bool matchRight(SymbolMatcherMode::Symbols symbol, const QTextBlock &currentBlock, int i, int nbRightParen);
104  void refreshDecorations();
105 
106  QBrush m_matchBackground;
107  QColor m_matchForeground;
108  QBrush m_unmatchBackground;
109  QColor m_unmatchForeground;
110  QList<TextDecoration::Ptr> m_decorations;
111 };
112 
113 } //end namespace ito
114 
115 #endif
Definition: symbolMatcherMode.h:64
Definition: apiFunctionsGraph.cpp:39
Definition: mode.h:69
QPoint symbolPos(const QTextCursor &cursor, CharType charType=Open, Symbols symbolType=Paren)
return value is line (x) and column (y)
Definition: symbolMatcherMode.cpp:379