itom
Loading...
Searching...
No Matches
wordclick.h
1
2
3/* ********************************************************************
4 itom software
5 URL: http://www.uni-stuttgart.de/ito
6 Copyright (C) 2020, Institut für Technische Optik (ITO),
7 Universität Stuttgart, Germany
8
9 This file is part of itom.
10
11 itom is free software; you can redistribute it and/or modify it
12 under the terms of the GNU Library General Public Licence as published by
13 the Free Software Foundation; either version 2 of the Licence, or (at
14 your option) any later version.
15
16 itom is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
19 General Public Licence for more details.
20
21 You should have received a copy of the GNU Library General Public License
22 along with itom. If not, see <http://www.gnu.org/licenses/>.
23
24 Further hints:
25 ------------------------
26
27 This file belongs to the code editor of itom. The code editor is
28 in major parts a fork / rewritten version of the python-based source
29 code editor PyQode from Colin Duquesnoy and others
30 (see https://github.com/pyQode). PyQode itself is licensed under
31 the MIT License (MIT).
32
33 Some parts of the code editor of itom are also inspired by the
34 source code editor of the Spyder IDE (https://github.com/spyder-ide),
35 also licensed under the MIT License and developed by the Spyder Project
36 Contributors.
37
38*********************************************************************** */
39
40#ifndef WORDCLICK_H
41#define WORDCLICK_H
42
43/*
44This module contains the WordClickMode
45*/
46
47#include "../mode.h"
48#include "../textDecoration.h"
49#include "../delayJobRunner.h"
50#include <qobject.h>
51#include <qstring.h>
52#include <qtextcursor.h>
53#include <qevent.h>
54
55namespace ito {
56
57/*
58Adds support for word click events.
59
60It will highlight the click-able word when the user press control and move
61the mouse over a word.
62
63Detecting whether a word is click-able is the responsibility of the
64subclasses. You must override ``_check_word_cursor`` and call
65``_select_word_cursor`` if this is a click-able word (this
66process might be asynchrone) otherwise _clear_selection.
67
68:attr:`pyqode.core.modes.WordClickMode.word_clicked` is emitted
69when the word is clicked by the user (while keeping control pressed).
70*/
71class WordClickMode : public QObject, public Mode
72{
73 Q_OBJECT
74public:
75 WordClickMode(const QString &name = "WordClickMode", const QString &description = "", QObject *parent = NULL);
76 virtual ~WordClickMode();
77
78 virtual void onStateChanged(bool state);
79
80 Qt::KeyboardModifiers wordClickModifiers() const { return m_mouseMoveKeyboardModifiers; }
81 void setWordClickModifiers(Qt::KeyboardModifiers modifiers) { m_mouseMoveKeyboardModifiers = modifiers; }
82
83protected:
84 void selectWordCursor();
85 virtual void clearSelection();
86 virtual void checkWordCursor(const QTextCursor &cursor) = 0;
87 void addDecoration(const QTextCursor &cursor);
88 void removeDecoration();
89
90private:
91 int m_previousCursorStart;
92 int m_previousCursorEnd;
93 DelayJobRunnerBase *m_pTimer;
94 TextDecoration::Ptr m_deco;
95 QTextCursor m_cursor;
96
97 void emitWordClicked(QTextCursor cursor)
98 {
99 emit wordClicked(cursor);
100 }
101
102 Qt::KeyboardModifiers m_mouseMoveKeyboardModifiers;
103
104private slots:
105 void onMouseDoubleClicked(QMouseEvent *e);
106 void onMouseMoved(QMouseEvent *e);
107 void onMouseReleased(QMouseEvent *e);
108 void onKeyReleased(QKeyEvent *e);
109
110signals:
111 void wordClicked(const QTextCursor &cursor);
112
113
114};
115
116} //end namespace ito
117
118#endif
Definition delayJobRunner.h:55
Definition mode.h:70
Definition wordclick.h:72
Definition apiFunctionsGraph.cpp:40