Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qgesture.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QGESTURE_H
6#define QGESTURE_H
7
8#include <QtWidgets/qtwidgetsglobal.h>
9#include <QtCore/qobject.h>
10#include <QtCore/qmap.h>
11#include <QtCore/qlist.h>
12#include <QtCore/qdatetime.h>
13#include <QtCore/qpoint.h>
14#include <QtCore/qrect.h>
15#include <QtCore/qmetatype.h>
16#include <QtGui/qevent.h>
17
18#ifndef QT_NO_GESTURES
19
20// ### move to qnamespace.h
21QT_DECL_METATYPE_EXTERN_TAGGED(Qt::GestureState, Qt__GestureState, Q_WIDGETS_EXPORT)
22// ### move to qnamespace.h
23QT_DECL_METATYPE_EXTERN_TAGGED(Qt::GestureType, Qt__GestureType, Q_WIDGETS_EXPORT)
24
25QT_BEGIN_NAMESPACE
26
27
28class QGesturePrivate;
29class Q_WIDGETS_EXPORT QGesture : public QObject
30{
31 Q_OBJECT
32 Q_DECLARE_PRIVATE(QGesture)
33
34 Q_PROPERTY(Qt::GestureState state READ state)
35 Q_PROPERTY(Qt::GestureType gestureType READ gestureType)
36 Q_PROPERTY(QGesture::GestureCancelPolicy gestureCancelPolicy READ gestureCancelPolicy
37 WRITE setGestureCancelPolicy)
38 Q_PROPERTY(QPointF hotSpot READ hotSpot WRITE setHotSpot RESET unsetHotSpot)
39 Q_PROPERTY(bool hasHotSpot READ hasHotSpot)
40
41public:
42 explicit QGesture(QObject *parent = nullptr);
43 ~QGesture();
44
45 Qt::GestureType gestureType() const;
46
47 Qt::GestureState state() const;
48
49 QPointF hotSpot() const;
50 void setHotSpot(const QPointF &value);
51 bool hasHotSpot() const;
52 void unsetHotSpot();
53
54 enum GestureCancelPolicy {
55 CancelNone = 0,
56 CancelAllInContext
57 };
58
59 void setGestureCancelPolicy(GestureCancelPolicy policy);
60 GestureCancelPolicy gestureCancelPolicy() const;
61
62protected:
63 QGesture(QGesturePrivate &dd, QObject *parent);
64
65private:
66 friend class QGestureEvent;
67 friend class QGestureRecognizer;
68 friend class QGestureManager;
69 friend class QGraphicsScenePrivate;
70};
71
73class Q_WIDGETS_EXPORT QPanGesture : public QGesture
74{
75 Q_OBJECT
76 Q_DECLARE_PRIVATE(QPanGesture)
77
78 Q_PROPERTY(QPointF lastOffset READ lastOffset WRITE setLastOffset)
79 Q_PROPERTY(QPointF offset READ offset WRITE setOffset)
80 Q_PROPERTY(QPointF delta READ delta STORED false)
81 Q_PROPERTY(qreal acceleration READ acceleration WRITE setAcceleration)
82 Q_PRIVATE_PROPERTY(QPanGesture::d_func(), qreal horizontalVelocity READ horizontalVelocity WRITE setHorizontalVelocity)
83 Q_PRIVATE_PROPERTY(QPanGesture::d_func(), qreal verticalVelocity READ verticalVelocity WRITE setVerticalVelocity)
84
85public:
86 explicit QPanGesture(QObject *parent = nullptr);
87 ~QPanGesture();
88
89 QPointF lastOffset() const;
90 QPointF offset() const;
91 QPointF delta() const;
92 qreal acceleration() const;
93
94 void setLastOffset(const QPointF &value);
95 void setOffset(const QPointF &value);
96 void setAcceleration(qreal value);
97
98 friend class QPanGestureRecognizer;
99 friend class QWinNativePanGestureRecognizer;
100};
101
103class Q_WIDGETS_EXPORT QPinchGesture : public QGesture
104{
105 Q_OBJECT
106 Q_DECLARE_PRIVATE(QPinchGesture)
107
108public:
109 enum ChangeFlag {
110 ScaleFactorChanged = 0x1,
111 RotationAngleChanged = 0x2,
112 CenterPointChanged = 0x4
113 };
114 Q_ENUM(ChangeFlag)
115 Q_DECLARE_FLAGS(ChangeFlags, ChangeFlag)
116 Q_FLAG(ChangeFlags)
117
118 Q_PROPERTY(ChangeFlags totalChangeFlags READ totalChangeFlags WRITE setTotalChangeFlags)
119 Q_PROPERTY(ChangeFlags changeFlags READ changeFlags WRITE setChangeFlags)
120
121 Q_PROPERTY(qreal totalScaleFactor READ totalScaleFactor WRITE setTotalScaleFactor)
122 Q_PROPERTY(qreal lastScaleFactor READ lastScaleFactor WRITE setLastScaleFactor)
123 Q_PROPERTY(qreal scaleFactor READ scaleFactor WRITE setScaleFactor)
124
125 Q_PROPERTY(qreal totalRotationAngle READ totalRotationAngle WRITE setTotalRotationAngle)
126 Q_PROPERTY(qreal lastRotationAngle READ lastRotationAngle WRITE setLastRotationAngle)
127 Q_PROPERTY(qreal rotationAngle READ rotationAngle WRITE setRotationAngle)
128
129 Q_PROPERTY(QPointF startCenterPoint READ startCenterPoint WRITE setStartCenterPoint)
130 Q_PROPERTY(QPointF lastCenterPoint READ lastCenterPoint WRITE setLastCenterPoint)
131 Q_PROPERTY(QPointF centerPoint READ centerPoint WRITE setCenterPoint)
132
133public:
134 explicit QPinchGesture(QObject *parent = nullptr);
135 ~QPinchGesture();
136
137 ChangeFlags totalChangeFlags() const;
138 void setTotalChangeFlags(ChangeFlags value);
139
140 ChangeFlags changeFlags() const;
141 void setChangeFlags(ChangeFlags value);
142
143 QPointF startCenterPoint() const;
144 QPointF lastCenterPoint() const;
145 QPointF centerPoint() const;
146 void setStartCenterPoint(const QPointF &value);
147 void setLastCenterPoint(const QPointF &value);
148 void setCenterPoint(const QPointF &value);
149
150 qreal totalScaleFactor() const;
151 qreal lastScaleFactor() const;
152 qreal scaleFactor() const;
153 void setTotalScaleFactor(qreal value);
154 void setLastScaleFactor(qreal value);
155 void setScaleFactor(qreal value);
156
157 qreal totalRotationAngle() const;
158 qreal lastRotationAngle() const;
159 qreal rotationAngle() const;
160 void setTotalRotationAngle(qreal value);
161 void setLastRotationAngle(qreal value);
162 void setRotationAngle(qreal value);
163
164 friend class QPinchGestureRecognizer;
165};
166
167Q_DECLARE_OPERATORS_FOR_FLAGS(QPinchGesture::ChangeFlags)
168
169QT_END_NAMESPACE
170
171QT_DECL_METATYPE_EXTERN_TAGGED(QPinchGesture::ChangeFlags,
172 QPinchGesture__ChangeFlags, Q_WIDGETS_EXPORT)
173
174QT_BEGIN_NAMESPACE
175
176class QSwipeGesturePrivate;
177class Q_WIDGETS_EXPORT QSwipeGesture : public QGesture
178{
179 Q_OBJECT
180 Q_DECLARE_PRIVATE(QSwipeGesture)
181
182 Q_PROPERTY(SwipeDirection horizontalDirection READ horizontalDirection STORED false)
183 Q_PROPERTY(SwipeDirection verticalDirection READ verticalDirection STORED false)
184 Q_PROPERTY(qreal swipeAngle READ swipeAngle WRITE setSwipeAngle)
185 Q_PRIVATE_PROPERTY(QSwipeGesture::d_func(), qreal velocity READ velocity WRITE setVelocity)
186
187public:
188 enum SwipeDirection { NoDirection, Left, Right, Up, Down };
189 Q_ENUM(SwipeDirection)
190
191 explicit QSwipeGesture(QObject *parent = nullptr);
192 ~QSwipeGesture();
193
194 SwipeDirection horizontalDirection() const;
195 SwipeDirection verticalDirection() const;
196
197 qreal swipeAngle() const;
198 void setSwipeAngle(qreal value);
199
200 friend class QSwipeGestureRecognizer;
201};
202
204class Q_WIDGETS_EXPORT QTapGesture : public QGesture
205{
206 Q_OBJECT
207 Q_DECLARE_PRIVATE(QTapGesture)
208
209 Q_PROPERTY(QPointF position READ position WRITE setPosition)
210
211public:
212 explicit QTapGesture(QObject *parent = nullptr);
213 ~QTapGesture();
214
215 QPointF position() const;
216 void setPosition(const QPointF &pos);
217
218 friend class QTapGestureRecognizer;
219};
220
222class Q_WIDGETS_EXPORT QTapAndHoldGesture : public QGesture
223{
224 Q_OBJECT
225 Q_DECLARE_PRIVATE(QTapAndHoldGesture)
226
227 Q_PROPERTY(QPointF position READ position WRITE setPosition)
228
229public:
230 explicit QTapAndHoldGesture(QObject *parent = nullptr);
231 ~QTapAndHoldGesture();
232
233 QPointF position() const;
234 void setPosition(const QPointF &pos);
235
236 static void setTimeout(int msecs);
237 static int timeout();
238
239 friend class QTapAndHoldGestureRecognizer;
240};
241
242class QGesture;
243class QGestureEventPrivate;
244class Q_WIDGETS_EXPORT QGestureEvent : public QEvent
245{
246public:
247 explicit QGestureEvent(const QList<QGesture *> &gestures);
248 ~QGestureEvent();
249
250 QList<QGesture *> gestures() const;
251 QGesture *gesture(Qt::GestureType type) const;
252
253 QList<QGesture *> activeGestures() const;
254 QList<QGesture *> canceledGestures() const;
255
256 using QEvent::setAccepted;
257 using QEvent::isAccepted;
258 using QEvent::accept;
259 using QEvent::ignore;
260
261 void setAccepted(QGesture *, bool);
262 void accept(QGesture *);
263 void ignore(QGesture *);
264 bool isAccepted(QGesture *) const;
265
266 void setAccepted(Qt::GestureType, bool);
267 void accept(Qt::GestureType);
268 void ignore(Qt::GestureType);
269 bool isAccepted(Qt::GestureType) const;
270
271 void setWidget(QWidget *widget);
272 QWidget *widget() const;
273
274#if QT_CONFIG(graphicsview)
275 QPointF mapToGraphicsScene(const QPointF &gesturePoint) const;
276#endif
277
278private:
279 QList<QGesture *> m_gestures;
280 QWidget *m_widget;
281 QMap<Qt::GestureType, bool> m_accepted;
282 QMap<Qt::GestureType, QWidget *> m_targetWidgets;
283
284 friend class QApplication;
285 friend class QGestureManager;
286};
287
288# ifndef QT_NO_DEBUG_STREAM
289Q_WIDGETS_EXPORT QDebug operator<<(QDebug, const QGesture *);
290Q_WIDGETS_EXPORT QDebug operator<<(QDebug, const QGestureEvent *);
291# endif
292
293QT_END_NAMESPACE
294
295QT_DECL_METATYPE_EXTERN_TAGGED(QGesture::GestureCancelPolicy,
296 QGesture__GestureCancelPolicy, Q_WIDGETS_EXPORT)
297
298#endif // QT_NO_GESTURES
299
300#endif // QGESTURE_H
The QGestureEvent class provides the description of triggered gestures.
Definition qgesture.h:245
The QGesture class represents a gesture, containing properties that describe the corresponding user i...
Definition qgesture.h:30
friend class QWidget
Definition qpainter.h:431
friend class QPaintEngine
Definition qpainter.h:437
The QPanGesture class describes a panning gesture made by the user.\inmodule QtWidgets.
Definition qgesture.h:74
The QPinchGesture class describes a pinch gesture made by the user.\inmodule QtWidgets.
Definition qgesture.h:104
The QStyleFactory class creates QStyle objects.
The QSwipeGesture class describes a swipe gesture made by the user.\inmodule QtWidgets.
Definition qgesture.h:178
The QTapAndHoldGesture class describes a tap-and-hold (aka LongTap) gesture made by the user....
Definition qgesture.h:223
The QTapGesture class describes a tap gesture made by the user.\inmodule QtWidgets.
Definition qgesture.h:205
const QRegion & region() const
Definition qwidget_p.h:84
QUpdateLaterEvent(const QRegion &paintRegion)
Definition qwidget_p.h:79
void setNativeWindowVisibility(bool visible)
QObject * focusObject() const override
Returns the QObject that will be the final receiver of events tied focus, such as key events.
void handleMoveEvent(QMoveEvent *)
void handleMouseEvent(QMouseEvent *)
void handleFocusInEvent(QFocusEvent *)
void handleResizeEvent(QResizeEvent *)
void handleEnterLeaveEvent(QEvent *)
void handleTouchEvent(QTouchEvent *)
static void focusNextPrevChild(QWidget *widget, bool next)
void handleKeyEvent(QKeyEvent *)
void handleContextMenuEvent(QContextMenuEvent *)
bool nativeEvent(const QByteArray &eventType, void *message, qintptr *result) override
Override this to handle platform dependent events.
bool event(QEvent *) override
Override this to handle any event (ev) sent to the window.
void handleExposeEvent(QExposeEvent *)
void closeEvent(QCloseEvent *) override
Override this to handle close events (ev).
void handleNonClientAreaMouseEvent(QMouseEvent *)
void handleGestureEvent(QNativeGestureEvent *)
void handleWindowStateChangedEvent(QWindowStateChangeEvent *event)
QWidget * widget() const
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
Q_GLOBAL_STATIC(DefaultRoleNames, qDefaultRoleNames, { { Qt::DisplayRole, "display" }, { Qt::DecorationRole, "decoration" }, { Qt::EditRole, "edit" }, { Qt::ToolTipRole, "toolTip" }, { Qt::StatusTipRole, "statusTip" }, { Qt::WhatsThisRole, "whatsThis" }, }) const QHash< int
Q_STATIC_LOGGING_CATEGORY(lcAccessibilityCore, "qt.accessibility.core")
static int uiEffectToFlag(Qt::UIEffect effect)
static void initResources()
void qt_init_tooltip_palette()
static void ungrabMouseForPopup(QWidget *popup)
static void ungrabKeyboardForPopup(QWidget *popup)
Q_TRACE_POINT(qtwidgets, QApplication_notify_entry, QObject *receiver, QEvent *event, QEvent::Type type)
Q_WIDGETS_EXPORT bool qt_tryModalHelper(QWidget *widget, QWidget **rettop)
int qt_antialiasing_threshold
bool qt_in_tab_key_event
static bool popupGrabOk
void qRegisterWidgetsVariant()
static void grabForPopup(QWidget *popup)
QWidget * qt_tlw_for_window(QWindow *wnd)
Q_GUI_EXPORT bool qt_sendShortcutOverrideEvent(QObject *o, ulong timestamp, int k, Qt::KeyboardModifiers mods, const QString &text=QString(), bool autorep=false, ushort count=1)
bool qt_try_modal(QWidget *widget, QEvent::Type type)
void qt_qpa_set_cursor(QWidget *w, bool force)
Definition qwidget.cpp:5073
QHash< QByteArray, QFont > FontHash
QClipboard * qt_clipboard
Q_TRACE_POINT(qtcore, QCoreApplication_notify_exit, bool consumed, bool filtered)
Q_TRACE_METADATA(qtcore, "ENUM { AUTO, RANGE User ... MaxUser } QEvent::Type;")
Q_TRACE_PREFIX(qtcore, "#include <qcoreevent.h>")
#define qApp
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
Definition qdir.cpp:2568
Q_CORE_EXPORT void qt_call_post_routines()
Q_CONSTINIT Q_GUI_EXPORT bool qt_is_tty_app
#define CHECK_QAPP_INSTANCE(...)
void qSendWindowChangeToTextureChildrenRecursively(QWidget *widget, QEvent::Type eventType)
bool qt_sendSpontaneousEvent(QObject *, QEvent *)
#define QWIDGETSIZE_MAX
Definition qwidget.h:922
Q_DECLARE_LOGGING_CATEGORY(lcWidgetShowHide)
QPointer< QWindow > qt_last_mouse_receiver
QRect frameStrut
Definition qwidget_p.h:112
QString role
Definition qwidget_p.h:105
QString iconText
Definition qwidget_p.h:104
QString caption
Definition qwidget_p.h:103
QPointer< QScreen > initialScreen
Definition qwidget_p.h:115
std::unique_ptr< QWidgetRepaintManager > repaintManager
Definition qwidget_p.h:97
uint posIncludesFrame
Definition qwidget_p.h:121
QRect normalGeometry
Definition qwidget_p.h:113
Qt::WindowFlags savedFlags
Definition qwidget_p.h:114
QPainter * sharedPainter
Definition qwidget_p.h:99
uint explicitContentsMarginsRespectsSafeArea
Definition qwidget_p.h:124
std::unique_ptr< QIcon > icon
Definition qwidget_p.h:96
uint opacity
Definition qwidget_p.h:120
std::vector< std::unique_ptr< QPlatformTextureList > > widgetTextures
Definition qwidget_p.h:117
uint sizeAdjusted
Definition qwidget_p.h:122
short baseh
Definition qwidget_p.h:110
QBackingStore * backingStore
Definition qwidget_p.h:98
QString filePath
Definition qwidget_p.h:106
short inch
Definition qwidget_p.h:109
short basew
Definition qwidget_p.h:110
QWidgetWindow * window
Definition qwidget_p.h:100
uint embedded
Definition qwidget_p.h:123
short incw
Definition qwidget_p.h:109
uint hasMask
Definition qwidget_p.h:161
uint hasWindowContainer
Definition qwidget_p.h:162
QString styleSheet
Definition qwidget_p.h:144
QRegion mask
Definition qwidget_p.h:143
qint32 minw
Definition qwidget_p.h:147
QSize staticContentsSize
Definition qwidget_p.h:153
QPointer< QWidget > focus_proxy
Definition qwidget_p.h:140
uint inRenderWithPainter
Definition qwidget_p.h:160
qint32 maxh
Definition qwidget_p.h:150
quint16 customDpiY
Definition qwidget_p.h:152
uint nativeChildrenForced
Definition qwidget_p.h:159
quint16 customDpiX
Definition qwidget_p.h:151
std::unique_ptr< QTLWExtra > topextra
Definition qwidget_p.h:132
void * glContext
Definition qwidget_p.h:131
std::unique_ptr< QCursor > curs
Definition qwidget_p.h:137
uint explicitMinSize
Definition qwidget_p.h:156
uint autoFillBackground
Definition qwidget_p.h:158
QPointer< QStyle > style
Definition qwidget_p.h:139
uint explicitMaxSize
Definition qwidget_p.h:157
qint32 maxw
Definition qwidget_p.h:149
qint32 minh
Definition qwidget_p.h:148