QtBase  v6.3.1
qgesture.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtWidgets module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #ifndef QGESTURE_H
41 #define QGESTURE_H
42 
43 #include <QtWidgets/qtwidgetsglobal.h>
44 #include <QtCore/qobject.h>
45 #include <QtCore/qlist.h>
46 #include <QtCore/qdatetime.h>
47 #include <QtCore/qpoint.h>
48 #include <QtCore/qrect.h>
49 #include <QtCore/qmetatype.h>
50 #include <QtGui/qevent.h>
51 
52 #ifndef QT_NO_GESTURES
53 
56 
58 
59 
60 class QGesturePrivate;
61 class Q_WIDGETS_EXPORT QGesture : public QObject
62 {
63  Q_OBJECT
64  Q_DECLARE_PRIVATE(QGesture)
65 
67  Q_PROPERTY(Qt::GestureType gestureType READ gestureType)
68  Q_PROPERTY(QGesture::GestureCancelPolicy gestureCancelPolicy READ gestureCancelPolicy
69  WRITE setGestureCancelPolicy)
70  Q_PROPERTY(QPointF hotSpot READ hotSpot WRITE setHotSpot RESET unsetHotSpot)
71  Q_PROPERTY(bool hasHotSpot READ hasHotSpot)
72 
73 public:
74  explicit QGesture(QObject *parent = nullptr);
75  ~QGesture();
76 
77  Qt::GestureType gestureType() const;
78 
79  Qt::GestureState state() const;
80 
81  QPointF hotSpot() const;
82  void setHotSpot(const QPointF &value);
83  bool hasHotSpot() const;
84  void unsetHotSpot();
85 
87  CancelNone = 0,
88  CancelAllInContext
89  };
90 
91  void setGestureCancelPolicy(GestureCancelPolicy policy);
92  GestureCancelPolicy gestureCancelPolicy() const;
93 
94 protected:
96 
97 private:
98  friend class QGestureEvent;
99  friend class QGestureRecognizer;
100  friend class QGestureManager;
101  friend class QGraphicsScenePrivate;
102 };
103 
104 class QPanGesturePrivate;
105 class Q_WIDGETS_EXPORT QPanGesture : public QGesture
106 {
107  Q_OBJECT
108  Q_DECLARE_PRIVATE(QPanGesture)
109 
110  Q_PROPERTY(QPointF lastOffset READ lastOffset WRITE setLastOffset)
111  Q_PROPERTY(QPointF offset READ offset WRITE setOffset)
112  Q_PROPERTY(QPointF delta READ delta STORED false)
113  Q_PROPERTY(qreal acceleration READ acceleration WRITE setAcceleration)
114  Q_PRIVATE_PROPERTY(QPanGesture::d_func(), qreal horizontalVelocity READ horizontalVelocity WRITE setHorizontalVelocity)
115  Q_PRIVATE_PROPERTY(QPanGesture::d_func(), qreal verticalVelocity READ verticalVelocity WRITE setVerticalVelocity)
116 
117 public:
118  explicit QPanGesture(QObject *parent = nullptr);
119  ~QPanGesture();
120 
121  QPointF lastOffset() const;
122  QPointF offset() const;
123  QPointF delta() const;
124  qreal acceleration() const;
125 
126  void setLastOffset(const QPointF &value);
127  void setOffset(const QPointF &value);
128  void setAcceleration(qreal value);
129 
130  friend class QPanGestureRecognizer;
131  friend class QWinNativePanGestureRecognizer;
132 };
133 
135 class Q_WIDGETS_EXPORT QPinchGesture : public QGesture
136 {
137  Q_OBJECT
138  Q_DECLARE_PRIVATE(QPinchGesture)
139 
140 public:
141  enum ChangeFlag {
142  ScaleFactorChanged = 0x1,
143  RotationAngleChanged = 0x2,
144  CenterPointChanged = 0x4
145  };
146  Q_ENUM(ChangeFlag)
147  Q_DECLARE_FLAGS(ChangeFlags, ChangeFlag)
148  Q_FLAG(ChangeFlags)
149 
150  Q_PROPERTY(ChangeFlags totalChangeFlags READ totalChangeFlags WRITE setTotalChangeFlags)
151  Q_PROPERTY(ChangeFlags changeFlags READ changeFlags WRITE setChangeFlags)
152 
153  Q_PROPERTY(qreal totalScaleFactor READ totalScaleFactor WRITE setTotalScaleFactor)
154  Q_PROPERTY(qreal lastScaleFactor READ lastScaleFactor WRITE setLastScaleFactor)
155  Q_PROPERTY(qreal scaleFactor READ scaleFactor WRITE setScaleFactor)
156 
157  Q_PROPERTY(qreal totalRotationAngle READ totalRotationAngle WRITE setTotalRotationAngle)
158  Q_PROPERTY(qreal lastRotationAngle READ lastRotationAngle WRITE setLastRotationAngle)
159  Q_PROPERTY(qreal rotationAngle READ rotationAngle WRITE setRotationAngle)
160 
161  Q_PROPERTY(QPointF startCenterPoint READ startCenterPoint WRITE setStartCenterPoint)
162  Q_PROPERTY(QPointF lastCenterPoint READ lastCenterPoint WRITE setLastCenterPoint)
163  Q_PROPERTY(QPointF centerPoint READ centerPoint WRITE setCenterPoint)
164 
165 public:
166  explicit QPinchGesture(QObject *parent = nullptr);
167  ~QPinchGesture();
168 
169  ChangeFlags totalChangeFlags() const;
170  void setTotalChangeFlags(ChangeFlags value);
171 
172  ChangeFlags changeFlags() const;
173  void setChangeFlags(ChangeFlags value);
174 
175  QPointF startCenterPoint() const;
176  QPointF lastCenterPoint() const;
177  QPointF centerPoint() const;
178  void setStartCenterPoint(const QPointF &value);
179  void setLastCenterPoint(const QPointF &value);
180  void setCenterPoint(const QPointF &value);
181 
182  qreal totalScaleFactor() const;
183  qreal lastScaleFactor() const;
184  qreal scaleFactor() const;
185  void setTotalScaleFactor(qreal value);
186  void setLastScaleFactor(qreal value);
187  void setScaleFactor(qreal value);
188 
189  qreal totalRotationAngle() const;
190  qreal lastRotationAngle() const;
191  qreal rotationAngle() const;
192  void setTotalRotationAngle(qreal value);
193  void setLastRotationAngle(qreal value);
194  void setRotationAngle(qreal value);
195 
197 };
198 
199 Q_DECLARE_OPERATORS_FOR_FLAGS(QPinchGesture::ChangeFlags)
200 
202 
203 Q_DECLARE_METATYPE(QPinchGesture::ChangeFlags)
204 
206 
208 class Q_WIDGETS_EXPORT QSwipeGesture : public QGesture
209 {
210  Q_OBJECT
211  Q_DECLARE_PRIVATE(QSwipeGesture)
212 
213  Q_PROPERTY(SwipeDirection horizontalDirection READ horizontalDirection STORED false)
214  Q_PROPERTY(SwipeDirection verticalDirection READ verticalDirection STORED false)
215  Q_PROPERTY(qreal swipeAngle READ swipeAngle WRITE setSwipeAngle)
216  Q_PRIVATE_PROPERTY(QSwipeGesture::d_func(), qreal velocity READ velocity WRITE setVelocity)
217 
218 public:
219  enum SwipeDirection { NoDirection, Left, Right, Up, Down };
220  Q_ENUM(SwipeDirection)
221 
222  explicit QSwipeGesture(QObject *parent = nullptr);
223  ~QSwipeGesture();
224 
225  SwipeDirection horizontalDirection() const;
226  SwipeDirection verticalDirection() const;
227 
228  qreal swipeAngle() const;
229  void setSwipeAngle(qreal value);
230 
232 };
233 
234 class QTapGesturePrivate;
235 class Q_WIDGETS_EXPORT QTapGesture : public QGesture
236 {
237  Q_OBJECT
238  Q_DECLARE_PRIVATE(QTapGesture)
239 
240  Q_PROPERTY(QPointF position READ position WRITE setPosition)
241 
242 public:
243  explicit QTapGesture(QObject *parent = nullptr);
244  ~QTapGesture();
245 
246  QPointF position() const;
247  void setPosition(const QPointF &pos);
248 
249  friend class QTapGestureRecognizer;
250 };
251 
253 class Q_WIDGETS_EXPORT QTapAndHoldGesture : public QGesture
254 {
255  Q_OBJECT
256  Q_DECLARE_PRIVATE(QTapAndHoldGesture)
257 
258  Q_PROPERTY(QPointF position READ position WRITE setPosition)
259 
260 public:
261  explicit QTapAndHoldGesture(QObject *parent = nullptr);
263 
264  QPointF position() const;
265  void setPosition(const QPointF &pos);
266 
267  static void setTimeout(int msecs);
268  static int timeout();
269 
271 };
272 
273 class QGesture;
274 class QGestureEventPrivate;
275 class Q_WIDGETS_EXPORT QGestureEvent : public QEvent
276 {
277 public:
278  explicit QGestureEvent(const QList<QGesture *> &gestures);
279  ~QGestureEvent();
280 
281  QList<QGesture *> gestures() const;
282  QGesture *gesture(Qt::GestureType type) const;
283 
284  QList<QGesture *> activeGestures() const;
285  QList<QGesture *> canceledGestures() const;
286 
287  using QEvent::setAccepted;
288  using QEvent::isAccepted;
289  using QEvent::accept;
290  using QEvent::ignore;
291 
292  void setAccepted(QGesture *, bool);
293  void accept(QGesture *);
294  void ignore(QGesture *);
295  bool isAccepted(QGesture *) const;
296 
297  void setAccepted(Qt::GestureType, bool);
298  void accept(Qt::GestureType);
299  void ignore(Qt::GestureType);
300  bool isAccepted(Qt::GestureType) const;
301 
302  void setWidget(QWidget *widget);
303  QWidget *widget() const;
304 
305 #if QT_CONFIG(graphicsview)
306  QPointF mapToGraphicsScene(const QPointF &gesturePoint) const;
307 #endif
308 
309 private:
310  QList<QGesture *> m_gestures;
311  QWidget *m_widget;
312  QMap<Qt::GestureType, bool> m_accepted;
313  QMap<Qt::GestureType, QWidget *> m_targetWidgets;
314 
315  friend class QApplication;
316  friend class QGestureManager;
317 };
318 
319 # ifndef QT_NO_DEBUG_STREAM
320 Q_WIDGETS_EXPORT QDebug operator<<(QDebug, const QGesture *);
321 Q_WIDGETS_EXPORT QDebug operator<<(QDebug, const QGestureEvent *);
322 # endif
323 
325 
327 #endif // QT_NO_GESTURES
328 
329 #endif // QGESTURE_H
The QApplication class manages the GUI application's control flow and main settings.
Definition: qapplication.h:68
operator<<(QDataStream &ds, qfloat16 f)
Definition: qfloat16.cpp:327
The QDebug class provides an output stream for debugging information.
Definition: qdebug.h:65
The QEvent class is the base class of all event classes. Event objects contain event parameters.
Definition: qcoreevent.h:58
virtual void setAccepted(bool accepted)
Definition: qcoreevent.h:310
void ignore()
Definition: qcoreevent.h:314
bool isAccepted() const
Definition: qcoreevent.h:311
void accept()
Definition: qcoreevent.h:313
The QGestureEvent class provides the description of triggered gestures.
Definition: qgesture.h:276
The QGesture class represents a gesture, containing properties that describe the corresponding user i...
Definition: qgesture.h:62
GestureCancelPolicy
Definition: qgesture.h:86
The QGestureRecognizer class provides the infrastructure for gesture recognition.\inmodule QtWidgets.
The QObject class is the base class of all Qt objects.
Definition: qobject.h:125
The QPanGesture class describes a panning gesture made by the user.\inmodule QtWidgets.
Definition: qgesture.h:106
The QPinchGesture class describes a pinch gesture made by the user.\inmodule QtWidgets.
Definition: qgesture.h:136
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:242
The QSwipeGesture class describes a swipe gesture made by the user.\inmodule QtWidgets.
Definition: qgesture.h:209
The QTapAndHoldGesture class describes a tap-and-hold (aka LongTap) gesture made by the user....
Definition: qgesture.h:254
The QTapGesture class describes a tap gesture made by the user.\inmodule QtWidgets.
Definition: qgesture.h:236
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:133
QOpenGLWidget * widget
[1]
else opt state
[0]
@ STORED
Definition: infutil.h:17
QHighDpiScaling::Point position(T, QHighDpiScaling::Point::Kind)
GestureState
Definition: qnamespace.h:1632
GestureType
Definition: qnamespace.h:1641
@ Down
EGLOutputLayerEXT EGLint EGLAttrib value
#define Q_DECLARE_FLAGS(Flags, Enum)
Definition: qflags.h:210
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
Definition: qflags.h:227
QT_END_INCLUDE_NAMESPACE typedef double qreal
Definition: qglobal.h:341
#define Q_DECLARE_METATYPE(TYPE)
Definition: qmetatype.h:1417
GLenum type
Definition: qopengl.h:270
GLbitfield GLuint64 timeout
[4]
GLenum GLuint GLintptr offset
@ Left
@ Right
#define Q_ENUM(x)
Definition: qtmetamacros.h:104
#define Q_PROPERTY(...)
Definition: qtmetamacros.h:92
#define Q_OBJECT
Definition: qtmetamacros.h:158
#define Q_FLAG(x)
Definition: qtmetamacros.h:105
#define Q_PRIVATE_PROPERTY(d, text)
Definition: qtmetamacros.h:93
scrollArea setWidget(imageLabel)
QSizePolicy policy
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent