qevent.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011
  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 QtGui 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 QEVENT_H
  40. #define QEVENT_H
  41. #include <QtGui/qwindowdefs.h>
  42. #include <QtGui/qregion.h>
  43. #include <QtCore/qnamespace.h>
  44. #include <QtCore/qstring.h>
  45. #include <QtGui/qkeysequence.h>
  46. #include <QtCore/qcoreevent.h>
  47. #include <QtCore/qvariant.h>
  48. #include <QtCore/qmap.h> // ### Qt 6: Remove
  49. #include <QtCore/qvector.h>
  50. #include <QtCore/qset.h> // ### Qt 6: Remove
  51. #include <QtCore/qurl.h>
  52. #include <QtCore/qfile.h> // ### Qt 6: Replace by <qiodevice.h> and forward declare QFile
  53. #include <QtGui/qvector2d.h>
  54. #include <QtGui/qtouchdevice.h> // ### Qt 6: Replace by forward declaration
  55. QT_BEGIN_NAMESPACE
  56. class QAction;
  57. #ifndef QT_NO_GESTURES
  58. class QGesture;
  59. #endif
  60. class QScreen;
  61. class Q_GUI_EXPORT QInputEvent : public QEvent
  62. {
  63. public:
  64. explicit QInputEvent(Type type, Qt::KeyboardModifiers modifiers = Qt::NoModifier);
  65. ~QInputEvent();
  66. inline Qt::KeyboardModifiers modifiers() const { return modState; }
  67. inline void setModifiers(Qt::KeyboardModifiers amodifiers) { modState = amodifiers; }
  68. inline ulong timestamp() const { return ts; }
  69. inline void setTimestamp(ulong atimestamp) { ts = atimestamp; }
  70. protected:
  71. Qt::KeyboardModifiers modState;
  72. ulong ts;
  73. };
  74. class Q_GUI_EXPORT QEnterEvent : public QEvent
  75. {
  76. public:
  77. QEnterEvent(const QPointF &localPos, const QPointF &windowPos, const QPointF &screenPos);
  78. ~QEnterEvent();
  79. #ifndef QT_NO_INTEGER_EVENT_COORDINATES
  80. inline QPoint pos() const { return l.toPoint(); }
  81. inline QPoint globalPos() const { return s.toPoint(); }
  82. inline int x() const { return qRound(l.x()); }
  83. inline int y() const { return qRound(l.y()); }
  84. inline int globalX() const { return qRound(s.x()); }
  85. inline int globalY() const { return qRound(s.y()); }
  86. #endif
  87. const QPointF &localPos() const { return l; }
  88. const QPointF &windowPos() const { return w; }
  89. const QPointF &screenPos() const { return s; }
  90. protected:
  91. QPointF l, w, s;
  92. };
  93. class Q_GUI_EXPORT QMouseEvent : public QInputEvent
  94. {
  95. public:
  96. QMouseEvent(Type type, const QPointF &localPos, Qt::MouseButton button,
  97. Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers);
  98. QMouseEvent(Type type, const QPointF &localPos, const QPointF &screenPos,
  99. Qt::MouseButton button, Qt::MouseButtons buttons,
  100. Qt::KeyboardModifiers modifiers);
  101. QMouseEvent(Type type, const QPointF &localPos, const QPointF &windowPos, const QPointF &screenPos,
  102. Qt::MouseButton button, Qt::MouseButtons buttons,
  103. Qt::KeyboardModifiers modifiers);
  104. QMouseEvent(Type type, const QPointF &localPos, const QPointF &windowPos, const QPointF &screenPos,
  105. Qt::MouseButton button, Qt::MouseButtons buttons,
  106. Qt::KeyboardModifiers modifiers, Qt::MouseEventSource source);
  107. ~QMouseEvent();
  108. #ifndef QT_NO_INTEGER_EVENT_COORDINATES
  109. inline QPoint pos() const { return l.toPoint(); }
  110. inline QPoint globalPos() const { return s.toPoint(); }
  111. inline int x() const { return qRound(l.x()); }
  112. inline int y() const { return qRound(l.y()); }
  113. inline int globalX() const { return qRound(s.x()); }
  114. inline int globalY() const { return qRound(s.y()); }
  115. #endif
  116. const QPointF &localPos() const { return l; }
  117. const QPointF &windowPos() const { return w; }
  118. const QPointF &screenPos() const { return s; }
  119. inline Qt::MouseButton button() const { return b; }
  120. inline Qt::MouseButtons buttons() const { return mouseState; }
  121. #if QT_DEPRECATED_SINCE(5, 0)
  122. QT_DEPRECATED inline QPointF posF() const { return l; }
  123. #endif
  124. Qt::MouseEventSource source() const;
  125. Qt::MouseEventFlags flags() const;
  126. protected:
  127. QPointF l, w, s;
  128. Qt::MouseButton b;
  129. Qt::MouseButtons mouseState;
  130. int caps;
  131. QVector2D velocity;
  132. friend class QGuiApplicationPrivate;
  133. };
  134. class Q_GUI_EXPORT QHoverEvent : public QInputEvent
  135. {
  136. public:
  137. QHoverEvent(Type type, const QPointF &pos, const QPointF &oldPos, Qt::KeyboardModifiers modifiers = Qt::NoModifier);
  138. ~QHoverEvent();
  139. #ifndef QT_NO_INTEGER_EVENT_COORDINATES
  140. inline QPoint pos() const { return p.toPoint(); }
  141. inline QPoint oldPos() const { return op.toPoint(); }
  142. #endif
  143. inline const QPointF &posF() const { return p; }
  144. inline const QPointF &oldPosF() const { return op; }
  145. protected:
  146. QPointF p, op;
  147. };
  148. #ifndef QT_NO_WHEELEVENT
  149. class Q_GUI_EXPORT QWheelEvent : public QInputEvent
  150. {
  151. public:
  152. enum { DefaultDeltasPerStep = 120 };
  153. QWheelEvent(const QPointF &pos, int delta,
  154. Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers,
  155. Qt::Orientation orient = Qt::Vertical);
  156. QWheelEvent(const QPointF &pos, const QPointF& globalPos, int delta,
  157. Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers,
  158. Qt::Orientation orient = Qt::Vertical);
  159. QWheelEvent(const QPointF &pos, const QPointF& globalPos,
  160. QPoint pixelDelta, QPoint angleDelta, int qt4Delta, Qt::Orientation qt4Orientation,
  161. Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers);
  162. QWheelEvent(const QPointF &pos, const QPointF& globalPos,
  163. QPoint pixelDelta, QPoint angleDelta, int qt4Delta, Qt::Orientation qt4Orientation,
  164. Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::ScrollPhase phase);
  165. QWheelEvent(const QPointF &pos, const QPointF &globalPos, QPoint pixelDelta, QPoint angleDelta,
  166. int qt4Delta, Qt::Orientation qt4Orientation, Qt::MouseButtons buttons,
  167. Qt::KeyboardModifiers modifiers, Qt::ScrollPhase phase, Qt::MouseEventSource source);
  168. QWheelEvent(const QPointF &pos, const QPointF &globalPos, QPoint pixelDelta, QPoint angleDelta,
  169. int qt4Delta, Qt::Orientation qt4Orientation, Qt::MouseButtons buttons,
  170. Qt::KeyboardModifiers modifiers, Qt::ScrollPhase phase, Qt::MouseEventSource source, bool inverted);
  171. ~QWheelEvent();
  172. inline QPoint pixelDelta() const { return pixelD; }
  173. inline QPoint angleDelta() const { return angleD; }
  174. inline int delta() const { return qt4D; }
  175. inline Qt::Orientation orientation() const { return qt4O; }
  176. #ifndef QT_NO_INTEGER_EVENT_COORDINATES
  177. inline QPoint pos() const { return p.toPoint(); }
  178. inline QPoint globalPos() const { return g.toPoint(); }
  179. inline int x() const { return p.x(); }
  180. inline int y() const { return p.y(); }
  181. inline int globalX() const { return g.x(); }
  182. inline int globalY() const { return g.y(); }
  183. #endif
  184. inline const QPointF &posF() const { return p; }
  185. inline const QPointF &globalPosF() const { return g; }
  186. inline Qt::MouseButtons buttons() const { return mouseState; }
  187. inline Qt::ScrollPhase phase() const { return Qt::ScrollPhase(ph); }
  188. inline bool inverted() const { return invertedScrolling; }
  189. Qt::MouseEventSource source() const { return Qt::MouseEventSource(src); }
  190. protected:
  191. QPointF p;
  192. QPointF g;
  193. QPoint pixelD;
  194. QPoint angleD;
  195. int qt4D;
  196. Qt::Orientation qt4O;
  197. Qt::MouseButtons mouseState;
  198. uint ph : 2;
  199. uint src: 2;
  200. bool invertedScrolling : 1;
  201. int reserved : 27;
  202. friend class QApplication;
  203. };
  204. #endif
  205. #ifndef QT_NO_TABLETEVENT
  206. class Q_GUI_EXPORT QTabletEvent : public QInputEvent
  207. {
  208. Q_GADGET
  209. public:
  210. enum TabletDevice { NoDevice, Puck, Stylus, Airbrush, FourDMouse,
  211. XFreeEraser /*internal*/, RotationStylus };
  212. Q_ENUM(TabletDevice)
  213. enum PointerType { UnknownPointer, Pen, Cursor, Eraser };
  214. Q_ENUM(PointerType)
  215. QTabletEvent(Type t, const QPointF &pos, const QPointF &globalPos,
  216. int device, int pointerType, qreal pressure, int xTilt, int yTilt,
  217. qreal tangentialPressure, qreal rotation, int z,
  218. Qt::KeyboardModifiers keyState, qint64 uniqueID); // ### remove in Qt 6
  219. QTabletEvent(Type t, const QPointF &pos, const QPointF &globalPos,
  220. int device, int pointerType, qreal pressure, int xTilt, int yTilt,
  221. qreal tangentialPressure, qreal rotation, int z,
  222. Qt::KeyboardModifiers keyState, qint64 uniqueID,
  223. Qt::MouseButton button, Qt::MouseButtons buttons);
  224. ~QTabletEvent();
  225. inline QPoint pos() const { return mPos.toPoint(); }
  226. inline QPoint globalPos() const { return mGPos.toPoint(); }
  227. #if QT_DEPRECATED_SINCE(5,0)
  228. QT_DEPRECATED inline const QPointF &hiResGlobalPos() const { return mPos; }
  229. #endif
  230. inline const QPointF &posF() const { return mPos; }
  231. inline const QPointF &globalPosF() const { return mGPos; }
  232. inline int x() const { return qRound(mPos.x()); }
  233. inline int y() const { return qRound(mPos.y()); }
  234. inline int globalX() const { return qRound(mGPos.x()); }
  235. inline int globalY() const { return qRound(mGPos.y()); }
  236. inline qreal hiResGlobalX() const { return mGPos.x(); }
  237. inline qreal hiResGlobalY() const { return mGPos.y(); }
  238. inline TabletDevice device() const { return TabletDevice(mDev); }
  239. inline PointerType pointerType() const { return PointerType(mPointerType); }
  240. inline qint64 uniqueId() const { return mUnique; }
  241. inline qreal pressure() const { return mPress; }
  242. inline int z() const { return mZ; }
  243. inline qreal tangentialPressure() const { return mTangential; }
  244. inline qreal rotation() const { return mRot; }
  245. inline int xTilt() const { return mXT; }
  246. inline int yTilt() const { return mYT; }
  247. Qt::MouseButton button() const;
  248. Qt::MouseButtons buttons() const;
  249. protected:
  250. QPointF mPos, mGPos;
  251. int mDev, mPointerType, mXT, mYT, mZ;
  252. qreal mPress, mTangential, mRot;
  253. qint64 mUnique;
  254. // QTabletEventPrivate for extra storage.
  255. // ### Qt 6: QPointingEvent will have Buttons, QTabletEvent will inherit
  256. void *mExtra;
  257. };
  258. #endif // QT_NO_TABLETEVENT
  259. #ifndef QT_NO_GESTURES
  260. class Q_GUI_EXPORT QNativeGestureEvent : public QInputEvent
  261. {
  262. public:
  263. QNativeGestureEvent(Qt::NativeGestureType type, const QPointF &localPos, const QPointF &windowPos,
  264. const QPointF &screenPos, qreal value, ulong sequenceId, quint64 intArgument);
  265. Qt::NativeGestureType gestureType() const { return mGestureType; }
  266. qreal value() const { return mRealValue; }
  267. #ifndef QT_NO_INTEGER_EVENT_COORDINATES
  268. inline const QPoint pos() const { return mLocalPos.toPoint(); }
  269. inline const QPoint globalPos() const { return mScreenPos.toPoint(); }
  270. #endif
  271. const QPointF &localPos() const { return mLocalPos; }
  272. const QPointF &windowPos() const { return mWindowPos; }
  273. const QPointF &screenPos() const { return mScreenPos; }
  274. protected:
  275. Qt::NativeGestureType mGestureType;
  276. QPointF mLocalPos;
  277. QPointF mWindowPos;
  278. QPointF mScreenPos;
  279. qreal mRealValue;
  280. ulong mSequenceId;
  281. quint64 mIntValue;
  282. };
  283. #endif // QT_NO_GESTURES
  284. class Q_GUI_EXPORT QKeyEvent : public QInputEvent
  285. {
  286. public:
  287. QKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers, const QString& text = QString(),
  288. bool autorep = false, ushort count = 1);
  289. QKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers,
  290. quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers,
  291. const QString &text = QString(), bool autorep = false, ushort count = 1);
  292. ~QKeyEvent();
  293. int key() const { return k; }
  294. #ifndef QT_NO_SHORTCUT
  295. bool matches(QKeySequence::StandardKey key) const;
  296. #endif
  297. Qt::KeyboardModifiers modifiers() const;
  298. inline QString text() const { return txt; }
  299. inline bool isAutoRepeat() const { return autor; }
  300. inline int count() const { return int(c); }
  301. inline quint32 nativeScanCode() const { return nScanCode; }
  302. inline quint32 nativeVirtualKey() const { return nVirtualKey; }
  303. inline quint32 nativeModifiers() const { return nModifiers; }
  304. // Functions for the extended key event information
  305. #if QT_DEPRECATED_SINCE(5, 0)
  306. static inline QKeyEvent *createExtendedKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers,
  307. quint32 nativeScanCode, quint32 nativeVirtualKey,
  308. quint32 nativeModifiers,
  309. const QString& text = QString(), bool autorep = false,
  310. ushort count = 1)
  311. {
  312. return new QKeyEvent(type, key, modifiers,
  313. nativeScanCode, nativeVirtualKey, nativeModifiers,
  314. text, autorep, count);
  315. }
  316. inline bool hasExtendedInfo() const { return true; }
  317. #endif
  318. protected:
  319. QString txt;
  320. int k;
  321. quint32 nScanCode;
  322. quint32 nVirtualKey;
  323. quint32 nModifiers;
  324. ushort c;
  325. ushort autor:1;
  326. // ushort reserved:15;
  327. };
  328. class Q_GUI_EXPORT QFocusEvent : public QEvent
  329. {
  330. public:
  331. explicit QFocusEvent(Type type, Qt::FocusReason reason=Qt::OtherFocusReason);
  332. ~QFocusEvent();
  333. inline bool gotFocus() const { return type() == FocusIn; }
  334. inline bool lostFocus() const { return type() == FocusOut; }
  335. Qt::FocusReason reason() const;
  336. private:
  337. Qt::FocusReason m_reason;
  338. };
  339. class Q_GUI_EXPORT QPaintEvent : public QEvent
  340. {
  341. public:
  342. explicit QPaintEvent(const QRegion& paintRegion);
  343. explicit QPaintEvent(const QRect &paintRect);
  344. ~QPaintEvent();
  345. inline const QRect &rect() const { return m_rect; }
  346. inline const QRegion &region() const { return m_region; }
  347. protected:
  348. QRect m_rect;
  349. QRegion m_region;
  350. bool m_erased;
  351. };
  352. class Q_GUI_EXPORT QMoveEvent : public QEvent
  353. {
  354. public:
  355. QMoveEvent(const QPoint &pos, const QPoint &oldPos);
  356. ~QMoveEvent();
  357. inline const QPoint &pos() const { return p; }
  358. inline const QPoint &oldPos() const { return oldp;}
  359. protected:
  360. QPoint p, oldp;
  361. friend class QApplication;
  362. };
  363. class Q_GUI_EXPORT QExposeEvent : public QEvent
  364. {
  365. public:
  366. explicit QExposeEvent(const QRegion &rgn);
  367. ~QExposeEvent();
  368. inline const QRegion &region() const { return rgn; }
  369. protected:
  370. QRegion rgn;
  371. };
  372. class Q_GUI_EXPORT QPlatformSurfaceEvent : public QEvent
  373. {
  374. public:
  375. enum SurfaceEventType {
  376. SurfaceCreated,
  377. SurfaceAboutToBeDestroyed
  378. };
  379. explicit QPlatformSurfaceEvent(SurfaceEventType surfaceEventType);
  380. ~QPlatformSurfaceEvent();
  381. inline SurfaceEventType surfaceEventType() const { return m_surfaceEventType; }
  382. protected:
  383. SurfaceEventType m_surfaceEventType;
  384. };
  385. class Q_GUI_EXPORT QResizeEvent : public QEvent
  386. {
  387. public:
  388. QResizeEvent(const QSize &size, const QSize &oldSize);
  389. ~QResizeEvent();
  390. inline const QSize &size() const { return s; }
  391. inline const QSize &oldSize()const { return olds;}
  392. protected:
  393. QSize s, olds;
  394. friend class QApplication;
  395. };
  396. class Q_GUI_EXPORT QCloseEvent : public QEvent
  397. {
  398. public:
  399. QCloseEvent();
  400. ~QCloseEvent();
  401. };
  402. class Q_GUI_EXPORT QIconDragEvent : public QEvent
  403. {
  404. public:
  405. QIconDragEvent();
  406. ~QIconDragEvent();
  407. };
  408. class Q_GUI_EXPORT QShowEvent : public QEvent
  409. {
  410. public:
  411. QShowEvent();
  412. ~QShowEvent();
  413. };
  414. class Q_GUI_EXPORT QHideEvent : public QEvent
  415. {
  416. public:
  417. QHideEvent();
  418. ~QHideEvent();
  419. };
  420. #ifndef QT_NO_CONTEXTMENU
  421. class Q_GUI_EXPORT QContextMenuEvent : public QInputEvent
  422. {
  423. public:
  424. enum Reason { Mouse, Keyboard, Other };
  425. QContextMenuEvent(Reason reason, const QPoint &pos, const QPoint &globalPos,
  426. Qt::KeyboardModifiers modifiers);
  427. QContextMenuEvent(Reason reason, const QPoint &pos, const QPoint &globalPos);
  428. QContextMenuEvent(Reason reason, const QPoint &pos);
  429. ~QContextMenuEvent();
  430. inline int x() const { return p.x(); }
  431. inline int y() const { return p.y(); }
  432. inline int globalX() const { return gp.x(); }
  433. inline int globalY() const { return gp.y(); }
  434. inline const QPoint& pos() const { return p; }
  435. inline const QPoint& globalPos() const { return gp; }
  436. inline Reason reason() const { return Reason(reas); }
  437. protected:
  438. QPoint p;
  439. QPoint gp;
  440. uint reas : 8;
  441. };
  442. #endif // QT_NO_CONTEXTMENU
  443. #ifndef QT_NO_INPUTMETHOD
  444. class Q_GUI_EXPORT QInputMethodEvent : public QEvent
  445. {
  446. public:
  447. enum AttributeType {
  448. TextFormat,
  449. Cursor,
  450. Language,
  451. Ruby,
  452. Selection
  453. };
  454. class Attribute {
  455. public:
  456. Attribute(AttributeType typ, int s, int l, QVariant val) : type(typ), start(s), length(l), value(qMove(val)) {}
  457. AttributeType type;
  458. int start;
  459. int length;
  460. QVariant value;
  461. };
  462. QInputMethodEvent();
  463. QInputMethodEvent(const QString &preeditText, const QList<Attribute> &attributes);
  464. ~QInputMethodEvent();
  465. void setCommitString(const QString &commitString, int replaceFrom = 0, int replaceLength = 0);
  466. inline const QList<Attribute> &attributes() const { return attrs; }
  467. inline const QString &preeditString() const { return preedit; }
  468. inline const QString &commitString() const { return commit; }
  469. inline int replacementStart() const { return replace_from; }
  470. inline int replacementLength() const { return replace_length; }
  471. QInputMethodEvent(const QInputMethodEvent &other);
  472. private:
  473. QString preedit;
  474. QList<Attribute> attrs;
  475. QString commit;
  476. int replace_from;
  477. int replace_length;
  478. };
  479. Q_DECLARE_TYPEINFO(QInputMethodEvent::Attribute, Q_MOVABLE_TYPE);
  480. class Q_GUI_EXPORT QInputMethodQueryEvent : public QEvent
  481. {
  482. public:
  483. explicit QInputMethodQueryEvent(Qt::InputMethodQueries queries);
  484. ~QInputMethodQueryEvent();
  485. Qt::InputMethodQueries queries() const { return m_queries; }
  486. void setValue(Qt::InputMethodQuery query, const QVariant &value);
  487. QVariant value(Qt::InputMethodQuery query) const;
  488. private:
  489. Qt::InputMethodQueries m_queries;
  490. struct QueryPair {
  491. Qt::InputMethodQuery query;
  492. QVariant value;
  493. };
  494. friend QTypeInfo<QueryPair>;
  495. QVector<QueryPair> m_values;
  496. };
  497. Q_DECLARE_TYPEINFO(QInputMethodQueryEvent::QueryPair, Q_MOVABLE_TYPE);
  498. #endif // QT_NO_INPUTMETHOD
  499. #ifndef QT_NO_DRAGANDDROP
  500. class QMimeData;
  501. class Q_GUI_EXPORT QDropEvent : public QEvent
  502. {
  503. public:
  504. QDropEvent(const QPointF& pos, Qt::DropActions actions, const QMimeData *data,
  505. Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Type type = Drop);
  506. ~QDropEvent();
  507. inline QPoint pos() const { return p.toPoint(); }
  508. inline const QPointF &posF() const { return p; }
  509. inline Qt::MouseButtons mouseButtons() const { return mouseState; }
  510. inline Qt::KeyboardModifiers keyboardModifiers() const { return modState; }
  511. inline Qt::DropActions possibleActions() const { return act; }
  512. inline Qt::DropAction proposedAction() const { return default_action; }
  513. inline void acceptProposedAction() { drop_action = default_action; accept(); }
  514. inline Qt::DropAction dropAction() const { return drop_action; }
  515. void setDropAction(Qt::DropAction action);
  516. QObject* source() const;
  517. inline const QMimeData *mimeData() const { return mdata; }
  518. protected:
  519. friend class QApplication;
  520. QPointF p;
  521. Qt::MouseButtons mouseState;
  522. Qt::KeyboardModifiers modState;
  523. Qt::DropActions act;
  524. Qt::DropAction drop_action;
  525. Qt::DropAction default_action;
  526. const QMimeData *mdata;
  527. };
  528. class Q_GUI_EXPORT QDragMoveEvent : public QDropEvent
  529. {
  530. public:
  531. QDragMoveEvent(const QPoint &pos, Qt::DropActions actions, const QMimeData *data,
  532. Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Type type = DragMove);
  533. ~QDragMoveEvent();
  534. inline QRect answerRect() const { return rect; }
  535. inline void accept() { QDropEvent::accept(); }
  536. inline void ignore() { QDropEvent::ignore(); }
  537. inline void accept(const QRect & r) { accept(); rect = r; }
  538. inline void ignore(const QRect & r) { ignore(); rect = r; }
  539. protected:
  540. QRect rect;
  541. };
  542. class Q_GUI_EXPORT QDragEnterEvent : public QDragMoveEvent
  543. {
  544. public:
  545. QDragEnterEvent(const QPoint &pos, Qt::DropActions actions, const QMimeData *data,
  546. Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers);
  547. ~QDragEnterEvent();
  548. };
  549. class Q_GUI_EXPORT QDragLeaveEvent : public QEvent
  550. {
  551. public:
  552. QDragLeaveEvent();
  553. ~QDragLeaveEvent();
  554. };
  555. #endif // QT_NO_DRAGANDDROP
  556. class Q_GUI_EXPORT QHelpEvent : public QEvent
  557. {
  558. public:
  559. QHelpEvent(Type type, const QPoint &pos, const QPoint &globalPos);
  560. ~QHelpEvent();
  561. inline int x() const { return p.x(); }
  562. inline int y() const { return p.y(); }
  563. inline int globalX() const { return gp.x(); }
  564. inline int globalY() const { return gp.y(); }
  565. inline const QPoint& pos() const { return p; }
  566. inline const QPoint& globalPos() const { return gp; }
  567. private:
  568. QPoint p;
  569. QPoint gp;
  570. };
  571. #ifndef QT_NO_STATUSTIP
  572. class Q_GUI_EXPORT QStatusTipEvent : public QEvent
  573. {
  574. public:
  575. explicit QStatusTipEvent(const QString &tip);
  576. ~QStatusTipEvent();
  577. inline QString tip() const { return s; }
  578. private:
  579. QString s;
  580. };
  581. #endif
  582. #ifndef QT_NO_WHATSTHIS
  583. class Q_GUI_EXPORT QWhatsThisClickedEvent : public QEvent
  584. {
  585. public:
  586. explicit QWhatsThisClickedEvent(const QString &href);
  587. ~QWhatsThisClickedEvent();
  588. inline QString href() const { return s; }
  589. private:
  590. QString s;
  591. };
  592. #endif
  593. #ifndef QT_NO_ACTION
  594. class Q_GUI_EXPORT QActionEvent : public QEvent
  595. {
  596. QAction *act, *bef;
  597. public:
  598. QActionEvent(int type, QAction *action, QAction *before = Q_NULLPTR);
  599. ~QActionEvent();
  600. inline QAction *action() const { return act; }
  601. inline QAction *before() const { return bef; }
  602. };
  603. #endif
  604. class Q_GUI_EXPORT QFileOpenEvent : public QEvent
  605. {
  606. public:
  607. explicit QFileOpenEvent(const QString &file);
  608. explicit QFileOpenEvent(const QUrl &url);
  609. ~QFileOpenEvent();
  610. inline QString file() const { return f; }
  611. QUrl url() const { return m_url; }
  612. bool openFile(QFile &file, QIODevice::OpenMode flags) const;
  613. private:
  614. QString f;
  615. QUrl m_url;
  616. };
  617. #ifndef QT_NO_TOOLBAR
  618. class Q_GUI_EXPORT QToolBarChangeEvent : public QEvent
  619. {
  620. public:
  621. explicit QToolBarChangeEvent(bool t);
  622. ~QToolBarChangeEvent();
  623. inline bool toggle() const { return tog; }
  624. private:
  625. uint tog : 1;
  626. };
  627. #endif
  628. #ifndef QT_NO_SHORTCUT
  629. class Q_GUI_EXPORT QShortcutEvent : public QEvent
  630. {
  631. public:
  632. QShortcutEvent(const QKeySequence &key, int id, bool ambiguous = false);
  633. ~QShortcutEvent();
  634. inline const QKeySequence &key() const { return sequence; }
  635. inline int shortcutId() const { return sid; }
  636. inline bool isAmbiguous() const { return ambig; }
  637. protected:
  638. QKeySequence sequence;
  639. bool ambig;
  640. int sid;
  641. };
  642. #endif
  643. class Q_GUI_EXPORT QWindowStateChangeEvent: public QEvent
  644. {
  645. public:
  646. explicit QWindowStateChangeEvent(Qt::WindowStates aOldState, bool isOverride = false);
  647. ~QWindowStateChangeEvent();
  648. inline Qt::WindowStates oldState() const { return ostate; }
  649. bool isOverride() const;
  650. private:
  651. Qt::WindowStates ostate;
  652. bool m_override;
  653. };
  654. #ifndef QT_NO_DEBUG_STREAM
  655. Q_GUI_EXPORT QDebug operator<<(QDebug, const QEvent *);
  656. #endif
  657. #ifndef QT_NO_SHORTCUT
  658. inline bool operator==(QKeyEvent *e, QKeySequence::StandardKey key){return (e ? e->matches(key) : false);}
  659. inline bool operator==(QKeySequence::StandardKey key, QKeyEvent *e){return (e ? e->matches(key) : false);}
  660. #endif // QT_NO_SHORTCUT
  661. class QTouchEventTouchPointPrivate;
  662. class Q_GUI_EXPORT QTouchEvent : public QInputEvent
  663. {
  664. public:
  665. class Q_GUI_EXPORT TouchPoint
  666. {
  667. public:
  668. enum InfoFlag {
  669. Pen = 0x0001
  670. };
  671. #ifndef Q_MOC_RUN
  672. // otherwise moc gives
  673. // Error: Meta object features not supported for nested classes
  674. Q_DECLARE_FLAGS(InfoFlags, InfoFlag)
  675. #endif
  676. explicit TouchPoint(int id = -1);
  677. TouchPoint(const TouchPoint &other);
  678. #ifdef Q_COMPILER_RVALUE_REFS
  679. TouchPoint(TouchPoint &&other) Q_DECL_NOEXCEPT
  680. : d(Q_NULLPTR)
  681. { qSwap(d, other.d); }
  682. TouchPoint &operator=(TouchPoint &&other) Q_DECL_NOEXCEPT
  683. { qSwap(d, other.d); return *this; }
  684. #endif
  685. ~TouchPoint();
  686. TouchPoint &operator=(const TouchPoint &other)
  687. { if ( d != other.d ) { TouchPoint copy(other); swap(copy); } return *this; }
  688. void swap(TouchPoint &other) Q_DECL_NOEXCEPT
  689. { qSwap(d, other.d); }
  690. int id() const;
  691. Qt::TouchPointState state() const;
  692. QPointF pos() const;
  693. QPointF startPos() const;
  694. QPointF lastPos() const;
  695. QPointF scenePos() const;
  696. QPointF startScenePos() const;
  697. QPointF lastScenePos() const;
  698. QPointF screenPos() const;
  699. QPointF startScreenPos() const;
  700. QPointF lastScreenPos() const;
  701. QPointF normalizedPos() const;
  702. QPointF startNormalizedPos() const;
  703. QPointF lastNormalizedPos() const;
  704. QRectF rect() const;
  705. QRectF sceneRect() const;
  706. QRectF screenRect() const;
  707. qreal pressure() const;
  708. QVector2D velocity() const;
  709. InfoFlags flags() const;
  710. QVector<QPointF> rawScreenPositions() const;
  711. // internal
  712. void setId(int id);
  713. void setState(Qt::TouchPointStates state);
  714. void setPos(const QPointF &pos);
  715. void setScenePos(const QPointF &scenePos);
  716. void setScreenPos(const QPointF &screenPos);
  717. void setNormalizedPos(const QPointF &normalizedPos);
  718. void setStartPos(const QPointF &startPos);
  719. void setStartScenePos(const QPointF &startScenePos);
  720. void setStartScreenPos(const QPointF &startScreenPos);
  721. void setStartNormalizedPos(const QPointF &startNormalizedPos);
  722. void setLastPos(const QPointF &lastPos);
  723. void setLastScenePos(const QPointF &lastScenePos);
  724. void setLastScreenPos(const QPointF &lastScreenPos);
  725. void setLastNormalizedPos(const QPointF &lastNormalizedPos);
  726. void setRect(const QRectF &rect);
  727. void setSceneRect(const QRectF &sceneRect);
  728. void setScreenRect(const QRectF &screenRect);
  729. void setPressure(qreal pressure);
  730. void setVelocity(const QVector2D &v);
  731. void setFlags(InfoFlags flags);
  732. void setRawScreenPositions(const QVector<QPointF> &positions);
  733. private:
  734. QTouchEventTouchPointPrivate *d;
  735. friend class QGuiApplication;
  736. friend class QGuiApplicationPrivate;
  737. friend class QApplication;
  738. friend class QApplicationPrivate;
  739. };
  740. #if QT_DEPRECATED_SINCE(5, 0)
  741. enum DeviceType {
  742. TouchScreen,
  743. TouchPad
  744. };
  745. #endif
  746. explicit QTouchEvent(QEvent::Type eventType,
  747. QTouchDevice *device = Q_NULLPTR,
  748. Qt::KeyboardModifiers modifiers = Qt::NoModifier,
  749. Qt::TouchPointStates touchPointStates = Qt::TouchPointStates(),
  750. const QList<QTouchEvent::TouchPoint> &touchPoints = QList<QTouchEvent::TouchPoint>());
  751. ~QTouchEvent();
  752. inline QWindow *window() const { return _window; }
  753. inline QObject *target() const { return _target; }
  754. #if QT_DEPRECATED_SINCE(5, 0)
  755. QT_DEPRECATED inline QTouchEvent::DeviceType deviceType() const { return static_cast<DeviceType>(int(_device->type())); }
  756. #endif
  757. inline Qt::TouchPointStates touchPointStates() const { return _touchPointStates; }
  758. inline const QList<QTouchEvent::TouchPoint> &touchPoints() const { return _touchPoints; }
  759. inline QTouchDevice *device() const { return _device; }
  760. // internal
  761. inline void setWindow(QWindow *awindow) { _window = awindow; }
  762. inline void setTarget(QObject *atarget) { _target = atarget; }
  763. inline void setTouchPointStates(Qt::TouchPointStates aTouchPointStates) { _touchPointStates = aTouchPointStates; }
  764. inline void setTouchPoints(const QList<QTouchEvent::TouchPoint> &atouchPoints) { _touchPoints = atouchPoints; }
  765. inline void setDevice(QTouchDevice *adevice) { _device = adevice; }
  766. protected:
  767. QWindow *_window;
  768. QObject *_target;
  769. QTouchDevice *_device;
  770. Qt::TouchPointStates _touchPointStates;
  771. QList<QTouchEvent::TouchPoint> _touchPoints;
  772. friend class QGuiApplication;
  773. friend class QGuiApplicationPrivate;
  774. friend class QApplication;
  775. friend class QApplicationPrivate;
  776. #ifndef QT_NO_GRAPHICSVIEW
  777. friend class QGraphicsScenePrivate; // direct access to _touchPoints
  778. #endif
  779. };
  780. Q_DECLARE_TYPEINFO(QTouchEvent::TouchPoint, Q_MOVABLE_TYPE);
  781. Q_DECLARE_OPERATORS_FOR_FLAGS(QTouchEvent::TouchPoint::InfoFlags)
  782. #ifndef QT_NO_DEBUG_STREAM
  783. Q_GUI_EXPORT QDebug operator<<(QDebug, const QTouchEvent::TouchPoint &);
  784. #endif
  785. class Q_GUI_EXPORT QScrollPrepareEvent : public QEvent
  786. {
  787. public:
  788. explicit QScrollPrepareEvent(const QPointF &startPos);
  789. ~QScrollPrepareEvent();
  790. QPointF startPos() const;
  791. QSizeF viewportSize() const;
  792. QRectF contentPosRange() const;
  793. QPointF contentPos() const;
  794. void setViewportSize(const QSizeF &size);
  795. void setContentPosRange(const QRectF &rect);
  796. void setContentPos(const QPointF &pos);
  797. private:
  798. QObject* m_target; // Qt 6 remove.
  799. QPointF m_startPos;
  800. QSizeF m_viewportSize;
  801. QRectF m_contentPosRange;
  802. QPointF m_contentPos;
  803. };
  804. class Q_GUI_EXPORT QScrollEvent : public QEvent
  805. {
  806. public:
  807. enum ScrollState
  808. {
  809. ScrollStarted,
  810. ScrollUpdated,
  811. ScrollFinished
  812. };
  813. QScrollEvent(const QPointF &contentPos, const QPointF &overshoot, ScrollState scrollState);
  814. ~QScrollEvent();
  815. QPointF contentPos() const;
  816. QPointF overshootDistance() const;
  817. ScrollState scrollState() const;
  818. private:
  819. QPointF m_contentPos;
  820. QPointF m_overshoot;
  821. QScrollEvent::ScrollState m_state;
  822. };
  823. class Q_GUI_EXPORT QScreenOrientationChangeEvent : public QEvent
  824. {
  825. public:
  826. QScreenOrientationChangeEvent(QScreen *screen, Qt::ScreenOrientation orientation);
  827. ~QScreenOrientationChangeEvent();
  828. QScreen *screen() const;
  829. Qt::ScreenOrientation orientation() const;
  830. private:
  831. QScreen *m_screen;
  832. Qt::ScreenOrientation m_orientation;
  833. };
  834. class Q_GUI_EXPORT QApplicationStateChangeEvent : public QEvent
  835. {
  836. public:
  837. explicit QApplicationStateChangeEvent(Qt::ApplicationState state);
  838. Qt::ApplicationState applicationState() const;
  839. private:
  840. Qt::ApplicationState m_applicationState;
  841. };
  842. QT_END_NAMESPACE
  843. #endif // QEVENT_H