Marble

MarbleInputHandler.h
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2005-2007 Torsten Rahn <tackat@kde.org>
4// SPDX-FileCopyrightText: 2007 Inge Wallin <ingwa@kde.org>
5// SPDX-FileCopyrightText: 2014 Adam Dabrowski <adamdbrw@gmail.com>
6//
7
8#ifndef MARBLE_MARBLEINPUTHANDLER_H
9#define MARBLE_MARBLEINPUTHANDLER_H
10
11#include <QObject>
12
13#include "GeoDataCoordinates.h"
14#include "marble_export.h"
15
16class QEvent;
17class QKeyEvent;
18class QMouseEvent;
19class QTouchEvent;
20class QWheelEvent;
21class QGestureEvent;
22class QCursor;
23class QTimer;
24class QString;
25class QRect;
26
27namespace Marble
28{
29
30class MarbleAbstractPresenter;
31class AbstractDataPluginItem;
32class RenderPlugin;
33
34class MARBLE_EXPORT MarbleInputHandler : public QObject
35{
36 Q_OBJECT
37
38public:
39 explicit MarbleInputHandler(MarbleAbstractPresenter *);
40 ~MarbleInputHandler() override;
41
42 void setPositionSignalConnected(bool connected);
43 bool isPositionSignalConnected() const;
44
45 /**
46//
47// The MarbleInputHandler handles mouse and keyboard input.
48//
49
50 * @brief Set whether a popup menu appears on a click (not drag) with the left mouse button
51 * @param enabled True to enable the popup menu (default), false to disable it
52 */
53 void setMouseButtonPopupEnabled(Qt::MouseButton mouseButton, bool enabled);
54
55 /**
56 * @brief Return whether the left mouse button popup menu is active
57 * @return True iff a popup menu is shown on left mouse button clicks
58 */
59 bool isMouseButtonPopupEnabled(Qt::MouseButton mouseButton) const;
60
61 void setPanViaArrowsEnabled(bool enabled);
62
63 bool panViaArrowsEnabled() const;
64
65 void setInertialEarthRotationEnabled(bool enabled);
66
67 /**
68 * @brief Returns true iff dragging the map with the mouse keeps spinning
69 * in the chosen direction for a slightly longer time than the mouse is
70 * actually performing the drag operation
71 */
72 bool inertialEarthRotationEnabled() const;
73
74 void setMouseViewRotationEnabled(bool enabled);
75
76 bool mouseViewRotationEnabled() const;
77
78 /// should the map do kinetic scrolling, this would stop the operation
79 virtual void stopInertialEarthRotation();
80
81Q_SIGNALS:
82 // Mouse button menus
83 void lmbRequest(int, int);
84 void rmbRequest(int, int);
85
86 // Gps coordinates
87 void mouseClickScreenPosition(int, int);
88 void mouseMoveGeoPosition(const QString &);
89
90 /*
91 * To detect mouse click followed by mouse move
92 * with no mouse move in between
93 */
94 void mouseClickGeoPosition(qreal, qreal, GeoDataCoordinates::Unit);
95
96protected Q_SLOTS:
97 void restoreViewContext();
98
99protected:
100 class Protected;
101 Protected *const d;
102
103private Q_SLOTS:
104 virtual void installPluginEventFilter(RenderPlugin *renderPlugin) = 0;
105
106private:
107 Q_DISABLE_COPY(MarbleInputHandler)
108};
109
110class AbstractSelectionRubber
111{
112public:
113 virtual ~AbstractSelectionRubber() = default;
114 virtual void show() = 0;
115 virtual void hide() = 0;
116 virtual bool isVisible() const = 0;
117 virtual const QRect &geometry() const = 0;
118 virtual void setGeometry(const QRect &geometry) = 0;
119};
120
121class MARBLE_EXPORT MarbleDefaultInputHandler : public MarbleInputHandler
122{
123 Q_OBJECT
124
125public:
126 explicit MarbleDefaultInputHandler(MarbleAbstractPresenter *marblePresenter);
127 ~MarbleDefaultInputHandler() override;
128
129 void stopInertialEarthRotation() override;
130
131protected:
132 bool eventFilter(QObject *, QEvent *) override;
133 bool handleMouseEvent(QMouseEvent *e);
134 bool handlePinch(const QPointF &center, qreal scaleFactor, Qt::GestureState state);
135
136 // FIXME - refactor (abstraction & composition)
137 const AbstractDataPluginItem *lastToolTipItem() const;
138 QTimer *toolTipTimer();
139 QPoint toolTipPosition() const;
140
141 virtual bool handleKeyPress(QKeyEvent *e);
142 virtual void handleMouseButtonPressAndHold(const QPoint &position);
143
144private Q_SLOTS:
145 void installPluginEventFilter(RenderPlugin *renderPlugin) override = 0;
146 virtual void showLmbMenu(int, int) = 0;
147 virtual void showRmbMenu(int, int) = 0;
148 void handlePressAndHold();
149
150 virtual void openItemToolTip() = 0;
151 virtual void setCursor(const QCursor &) = 0;
152
153 void lmbTimeout();
154
155private:
156 virtual AbstractSelectionRubber *selectionRubber() = 0;
157 virtual bool layersEventFilter(QObject *, QEvent *) = 0;
158
159 virtual bool handleTouch(QTouchEvent *e);
160 virtual bool handleDoubleClick(QMouseEvent *e);
161 virtual bool handleWheel(QWheelEvent *e);
162 virtual bool handleGesture(QGestureEvent *e);
163
164 virtual void handleMouseButtonPress(QMouseEvent *e);
165 virtual void handleLeftMouseButtonPress(QMouseEvent *e);
166 virtual void handleRightMouseButtonPress(QMouseEvent *e);
167 virtual void handleMiddleMouseButtonPress(QMouseEvent *e);
168 virtual void handleMouseButtonRelease(QMouseEvent *e);
169
170 virtual void hideSelectionIfCtrlReleased(QEvent *e);
171 virtual void checkReleasedMove(QMouseEvent *e);
172
173 // Returns whatever should be returned from mouse event handling loop
174 virtual bool acceptMouse();
175
176 void notifyPosition(bool isAboveMap, qreal mouseLon, qreal mouseLat);
177 QPoint mouseMovedOutside(QMouseEvent *event);
178 void adjustCursorShape(const QPoint &mousePosition, const QPoint &mouseDirection);
179
180 Q_DISABLE_COPY(MarbleDefaultInputHandler)
181 class Private;
182 Private *const d;
183};
184
185}
186
187#endif // MARBLE_MARBLEINPUTHANDLER_H
Binds a QML item to a specific geodetic location in screen coordinates.
GestureState
MouseButton
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:04:14 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.