qgesture.h 10.0 KB

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