itom  4.1.0
occurrences.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 OCCURRENCES_H
39 #define OCCURRENCES_H
40 
41 /*
42 This module contains the occurrences highlighter mode.
43 */
44 
45 #include "../textDecoration.h"
46 #include "../mode.h"
47 #include "../delayJobRunner.h"
48 
49 #include <qfuturewatcher.h>
50 
51 
52 namespace ito {
53 /*
54 Highlights the caret line
55 */
56 class OccurrencesHighlighterMode : public QObject, public Mode
57 {
58  Q_OBJECT
59 public:
60  OccurrencesHighlighterMode(const QString &description = "", QObject *parent = NULL);
61  virtual ~OccurrencesHighlighterMode();
62 
63  QColor background() const;
64  void setBackground(const QColor &color);
65 
66  QColor foreground() const;
67  void setForeground(const QColor &color);
68 
69  int delay() const;
70  void setDelay(int delay);
71 
72  bool underlined() const;
73  void setUnderlined(bool value);
74 
75  bool caseSensitive() const;
76  void setCaseSensitive(bool value);
77 
78  bool wholeWord() const;
79  void setWholeWord(bool value);
80 
81  bool selectOnDoubleClick() const;
82  void setSelectOnDoubleClick(bool value);
83 
84  virtual void onStateChanged(bool state);
85 
86 private slots:
87  void requestHighlightPosChanged();
88  void requestHighlightDoubleClick();
89  void requestHighlight();
90  void sendRequest();
91  void onResultsAvailable(QList<QPair<int,int> > results);
92  void asyncFindAllWatcherFinished();
93 
94 protected:
95  typedef QList<QPair<int, int> > MatchesList;
96  void clearDecorations();
97  MatchesList findAll(const QString &text, const QString &sub, bool wholeWord, bool caseSensitive);
98 
99  QColor m_background;
100  QColor m_foreground;
101  bool m_underlined;
102  bool m_caseSensitive;
103  QString m_sub;
104  bool m_wholeWord;
105  bool m_selectOnDoubleClick;
106 
107  QList<TextDecoration::Ptr> m_decorations;
108 
109  QFutureWatcher<MatchesList> m_asyncFindAllWatcher;
110 
111  DelayJobRunnerBase *m_pTimer;
112 };
113 
114 } //end namespace ito
115 
116 #endif
Definition: occurrences.h:56
Definition: apiFunctionsGraph.cpp:39
Definition: delayJobRunner.h:54
Definition: mode.h:69