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