| 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 | |
| 4 | #ifndef QGESTURE_H |
| 5 | #define QGESTURE_H |
| 6 | |
| 7 | #include <QtWidgets/qtwidgetsglobal.h> |
| 8 | #include <QtCore/qobject.h> |
| 9 | #include <QtCore/qmap.h> |
| 10 | #include <QtCore/qlist.h> |
| 11 | #include <QtCore/qdatetime.h> |
| 12 | #include <QtCore/qpoint.h> |
| 13 | #include <QtCore/qrect.h> |
| 14 | #include <QtCore/qmetatype.h> |
| 15 | #include <QtGui/qevent.h> |
| 16 | |
| 17 | #ifndef QT_NO_GESTURES |
| 18 | |
| 19 | // ### move to qnamespace.h |
| 20 | QT_DECL_METATYPE_EXTERN_TAGGED(Qt::GestureState, Qt__GestureState, Q_WIDGETS_EXPORT) |
| 21 | // ### move to qnamespace.h |
| 22 | QT_DECL_METATYPE_EXTERN_TAGGED(Qt::GestureType, Qt__GestureType, Q_WIDGETS_EXPORT) |
| 23 | |
| 24 | QT_BEGIN_NAMESPACE |
| 25 | |
| 26 | |
| 27 | class QGesturePrivate; |
| 28 | class Q_WIDGETS_EXPORT QGesture : public QObject |
| 29 | { |
| 30 | Q_OBJECT |
| 31 | Q_DECLARE_PRIVATE(QGesture) |
| 32 | |
| 33 | Q_PROPERTY(Qt::GestureState state READ state) |
| 34 | Q_PROPERTY(Qt::GestureType gestureType READ gestureType) |
| 35 | Q_PROPERTY(QGesture::GestureCancelPolicy gestureCancelPolicy READ gestureCancelPolicy |
| 36 | WRITE setGestureCancelPolicy) |
| 37 | Q_PROPERTY(QPointF hotSpot READ hotSpot WRITE setHotSpot RESET unsetHotSpot) |
| 38 | Q_PROPERTY(bool hasHotSpot READ hasHotSpot) |
| 39 | |
| 40 | public: |
| 41 | explicit QGesture(QObject *parent = nullptr); |
| 42 | ~QGesture(); |
| 43 | |
| 44 | Qt::GestureType gestureType() const; |
| 45 | |
| 46 | Qt::GestureState state() const; |
| 47 | |
| 48 | QPointF hotSpot() const; |
| 49 | void setHotSpot(const QPointF &value); |
| 50 | bool hasHotSpot() const; |
| 51 | void unsetHotSpot(); |
| 52 | |
| 53 | enum GestureCancelPolicy { |
| 54 | CancelNone = 0, |
| 55 | CancelAllInContext |
| 56 | }; |
| 57 | |
| 58 | void setGestureCancelPolicy(GestureCancelPolicy policy); |
| 59 | GestureCancelPolicy gestureCancelPolicy() const; |
| 60 | |
| 61 | protected: |
| 62 | QGesture(QGesturePrivate &dd, QObject *parent); |
| 63 | |
| 64 | private: |
| 65 | friend class QGestureEvent; |
| 66 | friend class QGestureRecognizer; |
| 67 | friend class QGestureManager; |
| 68 | friend class QGraphicsScenePrivate; |
| 69 | }; |
| 70 | |
| 71 | class QPanGesturePrivate; |
| 72 | class Q_WIDGETS_EXPORT QPanGesture : public QGesture |
| 73 | { |
| 74 | Q_OBJECT |
| 75 | Q_DECLARE_PRIVATE(QPanGesture) |
| 76 | |
| 77 | Q_PROPERTY(QPointF lastOffset READ lastOffset WRITE setLastOffset) |
| 78 | Q_PROPERTY(QPointF offset READ offset WRITE setOffset) |
| 79 | Q_PROPERTY(QPointF delta READ delta STORED false) |
| 80 | Q_PROPERTY(qreal acceleration READ acceleration WRITE setAcceleration) |
| 81 | Q_PRIVATE_PROPERTY(QPanGesture::d_func(), qreal horizontalVelocity READ horizontalVelocity WRITE setHorizontalVelocity) |
| 82 | Q_PRIVATE_PROPERTY(QPanGesture::d_func(), qreal verticalVelocity READ verticalVelocity WRITE setVerticalVelocity) |
| 83 | |
| 84 | public: |
| 85 | explicit QPanGesture(QObject *parent = nullptr); |
| 86 | ~QPanGesture(); |
| 87 | |
| 88 | QPointF lastOffset() const; |
| 89 | QPointF offset() const; |
| 90 | QPointF delta() const; |
| 91 | qreal acceleration() const; |
| 92 | |
| 93 | void setLastOffset(const QPointF &value); |
| 94 | void setOffset(const QPointF &value); |
| 95 | void setAcceleration(qreal value); |
| 96 | |
| 97 | friend class QPanGestureRecognizer; |
| 98 | friend class QWinNativePanGestureRecognizer; |
| 99 | }; |
| 100 | |
| 101 | class QPinchGesturePrivate; |
| 102 | class Q_WIDGETS_EXPORT QPinchGesture : public QGesture |
| 103 | { |
| 104 | Q_OBJECT |
| 105 | Q_DECLARE_PRIVATE(QPinchGesture) |
| 106 | |
| 107 | public: |
| 108 | enum ChangeFlag { |
| 109 | ScaleFactorChanged = 0x1, |
| 110 | RotationAngleChanged = 0x2, |
| 111 | CenterPointChanged = 0x4 |
| 112 | }; |
| 113 | Q_ENUM(ChangeFlag) |
| 114 | Q_DECLARE_FLAGS(ChangeFlags, ChangeFlag) |
| 115 | Q_FLAG(ChangeFlags) |
| 116 | |
| 117 | Q_PROPERTY(ChangeFlags totalChangeFlags READ totalChangeFlags WRITE setTotalChangeFlags) |
| 118 | Q_PROPERTY(ChangeFlags changeFlags READ changeFlags WRITE setChangeFlags) |
| 119 | |
| 120 | Q_PROPERTY(qreal totalScaleFactor READ totalScaleFactor WRITE setTotalScaleFactor) |
| 121 | Q_PROPERTY(qreal lastScaleFactor READ lastScaleFactor WRITE setLastScaleFactor) |
| 122 | Q_PROPERTY(qreal scaleFactor READ scaleFactor WRITE setScaleFactor) |
| 123 | |
| 124 | Q_PROPERTY(qreal totalRotationAngle READ totalRotationAngle WRITE setTotalRotationAngle) |
| 125 | Q_PROPERTY(qreal lastRotationAngle READ lastRotationAngle WRITE setLastRotationAngle) |
| 126 | Q_PROPERTY(qreal rotationAngle READ rotationAngle WRITE setRotationAngle) |
| 127 | |
| 128 | Q_PROPERTY(QPointF startCenterPoint READ startCenterPoint WRITE setStartCenterPoint) |
| 129 | Q_PROPERTY(QPointF lastCenterPoint READ lastCenterPoint WRITE setLastCenterPoint) |
| 130 | Q_PROPERTY(QPointF centerPoint READ centerPoint WRITE setCenterPoint) |
| 131 | |
| 132 | public: |
| 133 | explicit QPinchGesture(QObject *parent = nullptr); |
| 134 | ~QPinchGesture(); |
| 135 | |
| 136 | ChangeFlags totalChangeFlags() const; |
| 137 | void setTotalChangeFlags(ChangeFlags value); |
| 138 | |
| 139 | ChangeFlags changeFlags() const; |
| 140 | void setChangeFlags(ChangeFlags value); |
| 141 | |
| 142 | QPointF startCenterPoint() const; |
| 143 | QPointF lastCenterPoint() const; |
| 144 | QPointF centerPoint() const; |
| 145 | void setStartCenterPoint(const QPointF &value); |
| 146 | void setLastCenterPoint(const QPointF &value); |
| 147 | void setCenterPoint(const QPointF &value); |
| 148 | |
| 149 | qreal totalScaleFactor() const; |
| 150 | qreal lastScaleFactor() const; |
| 151 | qreal scaleFactor() const; |
| 152 | void setTotalScaleFactor(qreal value); |
| 153 | void setLastScaleFactor(qreal value); |
| 154 | void setScaleFactor(qreal value); |
| 155 | |
| 156 | qreal totalRotationAngle() const; |
| 157 | qreal lastRotationAngle() const; |
| 158 | qreal rotationAngle() const; |
| 159 | void setTotalRotationAngle(qreal value); |
| 160 | void setLastRotationAngle(qreal value); |
| 161 | void setRotationAngle(qreal value); |
| 162 | |
| 163 | friend class QPinchGestureRecognizer; |
| 164 | }; |
| 165 | |
| 166 | Q_DECLARE_OPERATORS_FOR_FLAGS(QPinchGesture::ChangeFlags) |
| 167 | |
| 168 | QT_END_NAMESPACE |
| 169 | |
| 170 | QT_DECL_METATYPE_EXTERN_TAGGED(QPinchGesture::ChangeFlags, |
| 171 | QPinchGesture__ChangeFlags, Q_WIDGETS_EXPORT) |
| 172 | |
| 173 | QT_BEGIN_NAMESPACE |
| 174 | |
| 175 | class QSwipeGesturePrivate; |
| 176 | class Q_WIDGETS_EXPORT QSwipeGesture : public QGesture |
| 177 | { |
| 178 | Q_OBJECT |
| 179 | Q_DECLARE_PRIVATE(QSwipeGesture) |
| 180 | |
| 181 | Q_PROPERTY(SwipeDirection horizontalDirection READ horizontalDirection STORED false) |
| 182 | Q_PROPERTY(SwipeDirection verticalDirection READ verticalDirection STORED false) |
| 183 | Q_PROPERTY(qreal swipeAngle READ swipeAngle WRITE setSwipeAngle) |
| 184 | Q_PRIVATE_PROPERTY(QSwipeGesture::d_func(), qreal velocity READ velocity WRITE setVelocity) |
| 185 | |
| 186 | public: |
| 187 | enum SwipeDirection { NoDirection, Left, Right, Up, Down }; |
| 188 | Q_ENUM(SwipeDirection) |
| 189 | |
| 190 | explicit QSwipeGesture(QObject *parent = nullptr); |
| 191 | ~QSwipeGesture(); |
| 192 | |
| 193 | SwipeDirection horizontalDirection() const; |
| 194 | SwipeDirection verticalDirection() const; |
| 195 | |
| 196 | qreal swipeAngle() const; |
| 197 | void setSwipeAngle(qreal value); |
| 198 | |
| 199 | friend class QSwipeGestureRecognizer; |
| 200 | }; |
| 201 | |
| 202 | class QTapGesturePrivate; |
| 203 | class Q_WIDGETS_EXPORT QTapGesture : public QGesture |
| 204 | { |
| 205 | Q_OBJECT |
| 206 | Q_DECLARE_PRIVATE(QTapGesture) |
| 207 | |
| 208 | Q_PROPERTY(QPointF position READ position WRITE setPosition) |
| 209 | |
| 210 | public: |
| 211 | explicit QTapGesture(QObject *parent = nullptr); |
| 212 | ~QTapGesture(); |
| 213 | |
| 214 | QPointF position() const; |
| 215 | void setPosition(const QPointF &pos); |
| 216 | |
| 217 | friend class QTapGestureRecognizer; |
| 218 | }; |
| 219 | |
| 220 | class QTapAndHoldGesturePrivate; |
| 221 | class Q_WIDGETS_EXPORT QTapAndHoldGesture : public QGesture |
| 222 | { |
| 223 | Q_OBJECT |
| 224 | Q_DECLARE_PRIVATE(QTapAndHoldGesture) |
| 225 | |
| 226 | Q_PROPERTY(QPointF position READ position WRITE setPosition) |
| 227 | |
| 228 | public: |
| 229 | explicit QTapAndHoldGesture(QObject *parent = nullptr); |
| 230 | ~QTapAndHoldGesture(); |
| 231 | |
| 232 | QPointF position() const; |
| 233 | void setPosition(const QPointF &pos); |
| 234 | |
| 235 | static void setTimeout(int msecs); |
| 236 | static int timeout(); |
| 237 | |
| 238 | friend class QTapAndHoldGestureRecognizer; |
| 239 | }; |
| 240 | |
| 241 | class QGesture; |
| 242 | class QGestureEventPrivate; |
| 243 | class Q_WIDGETS_EXPORT QGestureEvent : public QEvent |
| 244 | { |
| 245 | public: |
| 246 | explicit QGestureEvent(const QList<QGesture *> &gestures); |
| 247 | ~QGestureEvent(); |
| 248 | |
| 249 | QList<QGesture *> gestures() const; |
| 250 | QGesture *gesture(Qt::GestureType type) const; |
| 251 | |
| 252 | QList<QGesture *> activeGestures() const; |
| 253 | QList<QGesture *> canceledGestures() const; |
| 254 | |
| 255 | using QEvent::setAccepted; |
| 256 | using QEvent::isAccepted; |
| 257 | using QEvent::accept; |
| 258 | using QEvent::ignore; |
| 259 | |
| 260 | void setAccepted(QGesture *, bool); |
| 261 | void accept(QGesture *); |
| 262 | void ignore(QGesture *); |
| 263 | bool isAccepted(QGesture *) const; |
| 264 | |
| 265 | void setAccepted(Qt::GestureType, bool); |
| 266 | void accept(Qt::GestureType); |
| 267 | void ignore(Qt::GestureType); |
| 268 | bool isAccepted(Qt::GestureType) const; |
| 269 | |
| 270 | void setWidget(QWidget *widget); |
| 271 | QWidget *widget() const; |
| 272 | |
| 273 | #if QT_CONFIG(graphicsview) |
| 274 | QPointF mapToGraphicsScene(const QPointF &gesturePoint) const; |
| 275 | #endif |
| 276 | |
| 277 | private: |
| 278 | QList<QGesture *> m_gestures; |
| 279 | QWidget *m_widget; |
| 280 | QMap<Qt::GestureType, bool> m_accepted; |
| 281 | QMap<Qt::GestureType, QWidget *> m_targetWidgets; |
| 282 | |
| 283 | friend class QApplication; |
| 284 | friend class QGestureManager; |
| 285 | }; |
| 286 | |
| 287 | # ifndef QT_NO_DEBUG_STREAM |
| 288 | Q_WIDGETS_EXPORT QDebug operator<<(QDebug, const QGesture *); |
| 289 | Q_WIDGETS_EXPORT QDebug operator<<(QDebug, const QGestureEvent *); |
| 290 | # endif |
| 291 | |
| 292 | QT_END_NAMESPACE |
| 293 | |
| 294 | QT_DECL_METATYPE_EXTERN_TAGGED(QGesture::GestureCancelPolicy, |
| 295 | QGesture__GestureCancelPolicy, Q_WIDGETS_EXPORT) |
| 296 | |
| 297 | #endif // QT_NO_GESTURES |
| 298 | |
| 299 | #endif // QGESTURE_H |
| 300 | |