itom  4.1.0
foldingPanel.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 FOLDINGPANEL_H
39 #define FOLDINGPANEL_H
40 
41 /*
42 This module contains the marker panel
43 */
44 
45 #include "../panel.h"
46 #include "../utils/utils.h"
47 
48 #include <qevent.h>
49 #include <qsize.h>
50 #include <qcolor.h>
51 #include "../foldDetector/foldDetector.h"
52 #include "../textDecoration.h"
53 
54 namespace ito {
55 
56 class DelayJobRunnerBase;
57 
58 /*
59 Displays the document outline and lets the user collapse/expand blocks.
60 
61 The data represented by the panel come from the text block user state and
62 is set by the SyntaxHighlighter mode.
63 
64 The panel does not expose any function that you can use directly. To
65 interact with the fold tree, you need to modify text block fold level or
66 trigger state using :class:`pyqode.core.api.utils.TextBlockHelper` or
67 :mod:`pyqode.core.api.folding`
68 */
69 class FoldingPanel : public Panel
70 {
71  Q_OBJECT
72 public:
73  FoldingPanel(bool highlightCaretScope = false, const QString &description = "", QWidget *parent = NULL);
74  virtual ~FoldingPanel();
75 
76  bool nativeLook() const;
77  void setNativeLook(bool native);
78 
79  QStringList customIndicatorIcons() const;
80  void setCustomIndicatorIcons(const QStringList &icons);
81 
82  QColor customFoldRegionBackground() const;
83  void setCustomFoldRegionBackground(const QColor &color);
84 
85  bool highlightCaretScope() const;
86  void setHighlightCaretScope(bool value);
87 
88  virtual void onInstall(CodeEditor *editor);
89  virtual void onStateChanged(bool state);
90  virtual QSize sizeHint() const;
91 
92  void collapseAll();
93  void expandAll();
94  void toggleFold(bool topLevelOnly);
95 
96  void toggleFoldTrigger(const QTextBlock &block, bool refreshEditor = true);
97 
98  void refreshDecorations(bool force = false);
99 
100 signals:
101  void triggerStateChanged(QTextBlock, bool);
102  void collapseAllTriggered();
103  void expandAllTriggered();
104 
105 protected:
106  virtual void paintEvent(QPaintEvent *e);
107  virtual void mouseMoveEvent(QMouseEvent *e);
108  virtual void mousePressEvent(QMouseEvent *e);
109  virtual void leaveEvent(QEvent *e);
110 
111  void drawFoldRegionBackground(const QTextBlock &block, QPainter &painter) const;
112  void drawRect(const QRectF &rect, QPainter &painter) const;
113  void drawFoldIndicator(int top, bool mouseOver, bool collapsed, QPainter *painter) const;
114  void addFoldDecoration(const QTextBlock &block, const FoldScope &region);
115  void addScopeDecorations(const QTextBlock &block, int start, int end);
116  QColor getScopeHighlightColor() const;
117  void clearScopeDecos();
118 
119  void addScopeDeco(int start, int end, int parentStart, int parentEnd, const QColor &baseColor, int factor);
120  void refreshEditorAndScrollbars();
121 
122 
123  static QColor getSystemBckColor();
124  static void showPreviousBlankLines(const QTextBlock &block);
125  static QTextBlock findParentScope(const QTextBlock &block);
126 
127  void highlightSurroundingScopes(QTextBlock block);
128 
129 private slots:
130  void clearBlockDeco();
131  void highlightCaretScopeSlot();
132  void onFoldDecoClicked(TextDecoration::Ptr deco);
133  void onKeyPressed(QKeyEvent *e);
134 
135 private:
136  bool m_native;
137  QStringList m_customIndicators;
138  FoldScope m_currentScope;
139  QColor m_customColor;
140  bool m_highlightCaret;
141  bool m_highlightCaretScope;
142  int m_blockNbr;
143  int m_indicSize;
144  QList<TextDecoration::Ptr> m_scopeDecos;
145  QList<TextDecoration::Ptr> m_blockDecos;
146  int m_mouseOverLine; //-1 -> invalid
147  DelayJobRunnerBase *m_pHighlightRunner;
148  QTextCursor m_prevCursor;
149 };
150 
151 } //end namespace ito
152 
153 #endif
Definition: foldingPanel.h:69
Definition: codeEditor.h:110
Definition: foldDetector.h:106
Definition: apiFunctionsGraph.cpp:39
Definition: delayJobRunner.h:54
Definition: panel.h:66