/src/gui/kernel/qevent.cpp

https://bitbucket.org/ultra_iter/qt-vtl · C++ · 4631 lines · 1221 code · 388 blank · 3022 comment · 105 complexity · 0e9cb96fb1d3a36014d010545af4fe49 MD5 · raw file

  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
  4. ** All rights reserved.
  5. ** Contact: Nokia Corporation (qt-info@nokia.com)
  6. **
  7. ** This file is part of the QtGui module of the Qt Toolkit.
  8. **
  9. ** $QT_BEGIN_LICENSE:LGPL$
  10. ** GNU Lesser General Public License Usage
  11. ** This file may be used under the terms of the GNU Lesser General Public
  12. ** License version 2.1 as published by the Free Software Foundation and
  13. ** appearing in the file LICENSE.LGPL included in the packaging of this
  14. ** file. Please review the following information to ensure the GNU Lesser
  15. ** General Public License version 2.1 requirements will be met:
  16. ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
  17. **
  18. ** In addition, as a special exception, Nokia gives you certain additional
  19. ** rights. These rights are described in the Nokia Qt LGPL Exception
  20. ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
  21. **
  22. ** GNU General Public License Usage
  23. ** Alternatively, this file may be used under the terms of the GNU General
  24. ** Public License version 3.0 as published by the Free Software Foundation
  25. ** and appearing in the file LICENSE.GPL included in the packaging of this
  26. ** file. Please review the following information to ensure the GNU General
  27. ** Public License version 3.0 requirements will be met:
  28. ** http://www.gnu.org/copyleft/gpl.html.
  29. **
  30. ** Other Usage
  31. ** Alternatively, this file may be used in accordance with the terms and
  32. ** conditions contained in a signed written agreement between you and Nokia.
  33. **
  34. **
  35. **
  36. **
  37. **
  38. ** $QT_END_LICENSE$
  39. **
  40. ****************************************************************************/
  41. #include "qevent.h"
  42. #include "qcursor.h"
  43. #include "qapplication.h"
  44. #include "private/qapplication_p.h"
  45. #include "private/qevent_p.h"
  46. #include "private/qkeysequence_p.h"
  47. #include "qwidget.h"
  48. #include "qgraphicsview.h"
  49. #include "qdebug.h"
  50. #include "qmime.h"
  51. #include "qdnd_p.h"
  52. #include "qevent_p.h"
  53. #include "qgesture.h"
  54. #include "qgesture_p.h"
  55. #ifdef Q_OS_SYMBIAN
  56. #include "private/qcore_symbian_p.h"
  57. #endif
  58. QT_BEGIN_NAMESPACE
  59. /*!
  60. \class QInputEvent
  61. \ingroup events
  62. \brief The QInputEvent class is the base class for events that
  63. describe user input.
  64. */
  65. /*!
  66. \internal
  67. */
  68. QInputEvent::QInputEvent(Type type, Qt::KeyboardModifiers modifiers)
  69. : QEvent(type), modState(modifiers)
  70. {}
  71. /*!
  72. \internal
  73. */
  74. QInputEvent::~QInputEvent()
  75. {
  76. }
  77. /*!
  78. \fn Qt::KeyboardModifiers QInputEvent::modifiers() const
  79. Returns the keyboard modifier flags that existed immediately
  80. before the event occurred.
  81. \sa QApplication::keyboardModifiers()
  82. */
  83. /*! \fn void QInputEvent::setModifiers(Qt::KeyboardModifiers modifiers)
  84. \internal
  85. Sets the keyboard modifiers flags for this event.
  86. */
  87. /*!
  88. \class QMouseEvent
  89. \ingroup events
  90. \brief The QMouseEvent class contains parameters that describe a mouse event.
  91. Mouse events occur when a mouse button is pressed or released
  92. inside a widget, or when the mouse cursor is moved.
  93. Mouse move events will occur only when a mouse button is pressed
  94. down, unless mouse tracking has been enabled with
  95. QWidget::setMouseTracking().
  96. Qt automatically grabs the mouse when a mouse button is pressed
  97. inside a widget; the widget will continue to receive mouse events
  98. until the last mouse button is released.
  99. A mouse event contains a special accept flag that indicates
  100. whether the receiver wants the event. You should call ignore() if
  101. the mouse event is not handled by your widget. A mouse event is
  102. propagated up the parent widget chain until a widget accepts it
  103. with accept(), or an event filter consumes it.
  104. \note If a mouse event is propagated to a \l{QWidget}{widget} for
  105. which Qt::WA_NoMousePropagation has been set, that mouse event
  106. will not be propagated further up the parent widget chain.
  107. The state of the keyboard modifier keys can be found by calling the
  108. \l{QInputEvent::modifiers()}{modifiers()} function, inherited from
  109. QInputEvent.
  110. The functions pos(), x(), and y() give the cursor position
  111. relative to the widget that receives the mouse event. If you
  112. move the widget as a result of the mouse event, use the global
  113. position returned by globalPos() to avoid a shaking motion.
  114. The QWidget::setEnabled() function can be used to enable or
  115. disable mouse and keyboard events for a widget.
  116. Reimplement the QWidget event handlers, QWidget::mousePressEvent(),
  117. QWidget::mouseReleaseEvent(), QWidget::mouseDoubleClickEvent(),
  118. and QWidget::mouseMoveEvent() to receive mouse events in your own
  119. widgets.
  120. \sa QWidget::setMouseTracking() QWidget::grabMouse() QCursor::pos()
  121. */
  122. /*!
  123. Constructs a mouse event object.
  124. The \a type parameter must be one of QEvent::MouseButtonPress,
  125. QEvent::MouseButtonRelease, QEvent::MouseButtonDblClick,
  126. or QEvent::MouseMove.
  127. The \a position is the mouse cursor's position relative to the
  128. receiving widget.
  129. The \a button that caused the event is given as a value from
  130. the Qt::MouseButton enum. If the event \a type is
  131. \l MouseMove, the appropriate button for this event is Qt::NoButton.
  132. The mouse and keyboard states at the time of the event are specified by
  133. \a buttons and \a modifiers.
  134. The globalPos() is initialized to QCursor::pos(), which may not
  135. be appropriate. Use the other constructor to specify the global
  136. position explicitly.
  137. */
  138. QMouseEvent::QMouseEvent(Type type, const QPoint &position, Qt::MouseButton button,
  139. Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
  140. : QInputEvent(type, modifiers), p(position), b(button), mouseState(buttons)
  141. {
  142. g = QCursor::pos();
  143. }
  144. /*!
  145. \internal
  146. */
  147. QMouseEvent::~QMouseEvent()
  148. {
  149. }
  150. #ifdef QT3_SUPPORT
  151. /*!
  152. Use QMouseEvent(\a type, \a pos, \a button, \c buttons, \c
  153. modifiers) instead, where \c buttons is \a state &
  154. Qt::MouseButtonMask and \c modifiers is \a state &
  155. Qt::KeyButtonMask.
  156. */
  157. QMouseEvent::QMouseEvent(Type type, const QPoint &pos, Qt::ButtonState button, int state)
  158. : QInputEvent(type), p(pos), b((Qt::MouseButton)button)
  159. {
  160. g = QCursor::pos();
  161. mouseState = Qt::MouseButtons((state ^ b) & Qt::MouseButtonMask);
  162. modState = Qt::KeyboardModifiers(state & (int)Qt::KeyButtonMask);
  163. }
  164. /*!
  165. Use QMouseEvent(\a type, \a pos, \a globalPos, \a button,
  166. \c buttons, \c modifiers) instead, where
  167. \c buttons is \a state & Qt::MouseButtonMask and
  168. \c modifiers is \a state & Qt::KeyButtonMask.
  169. */
  170. QMouseEvent::QMouseEvent(Type type, const QPoint &pos, const QPoint &globalPos,
  171. Qt::ButtonState button, int state)
  172. : QInputEvent(type), p(pos), g(globalPos), b((Qt::MouseButton)button)
  173. {
  174. mouseState = Qt::MouseButtons((state ^ b) & Qt::MouseButtonMask);
  175. modState = Qt::KeyboardModifiers(state & (int)Qt::KeyButtonMask);
  176. }
  177. #endif
  178. /*!
  179. Constructs a mouse event object.
  180. The \a type parameter must be QEvent::MouseButtonPress,
  181. QEvent::MouseButtonRelease, QEvent::MouseButtonDblClick,
  182. or QEvent::MouseMove.
  183. The \a pos is the mouse cursor's position relative to the
  184. receiving widget. The cursor's position in global coordinates is
  185. specified by \a globalPos. The \a button that caused the event is
  186. given as a value from the \l Qt::MouseButton enum. If the event \a
  187. type is \l MouseMove, the appropriate button for this event is
  188. Qt::NoButton. \a buttons is the state of all buttons at the
  189. time of the event, \a modifiers the state of all keyboard
  190. modifiers.
  191. */
  192. QMouseEvent::QMouseEvent(Type type, const QPoint &pos, const QPoint &globalPos,
  193. Qt::MouseButton button, Qt::MouseButtons buttons,
  194. Qt::KeyboardModifiers modifiers)
  195. : QInputEvent(type, modifiers), p(pos), g(globalPos), b(button), mouseState(buttons)
  196. {}
  197. /*!
  198. \internal
  199. */
  200. QMouseEvent *QMouseEvent::createExtendedMouseEvent(Type type, const QPointF &pos,
  201. const QPoint &globalPos, Qt::MouseButton button,
  202. Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
  203. {
  204. return new QMouseEventEx(type, pos, globalPos, button, buttons, modifiers);
  205. }
  206. /*!
  207. \fn bool QMouseEvent::hasExtendedInfo() const
  208. \internal
  209. */
  210. /*!
  211. \since 4.4
  212. Returns the position of the mouse cursor as a QPointF, relative to the
  213. widget that received the event.
  214. If you move the widget as a result of the mouse event, use the
  215. global position returned by globalPos() to avoid a shaking
  216. motion.
  217. \sa x() y() pos() globalPos()
  218. */
  219. QPointF QMouseEvent::posF() const
  220. {
  221. return hasExtendedInfo() ? reinterpret_cast<const QMouseEventEx *>(this)->posF : QPointF(pos());
  222. }
  223. /*!
  224. \internal
  225. */
  226. QMouseEventEx::QMouseEventEx(Type type, const QPointF &pos, const QPoint &globalPos,
  227. Qt::MouseButton button, Qt::MouseButtons buttons,
  228. Qt::KeyboardModifiers modifiers)
  229. : QMouseEvent(type, pos.toPoint(), globalPos, button, buttons, modifiers), posF(pos)
  230. {
  231. d = reinterpret_cast<QEventPrivate *>(this);
  232. }
  233. /*!
  234. \internal
  235. */
  236. QMouseEventEx::~QMouseEventEx()
  237. {
  238. }
  239. /*!
  240. \fn const QPoint &QMouseEvent::pos() const
  241. Returns the position of the mouse cursor, relative to the widget
  242. that received the event.
  243. If you move the widget as a result of the mouse event, use the
  244. global position returned by globalPos() to avoid a shaking
  245. motion.
  246. \sa x() y() globalPos()
  247. */
  248. /*!
  249. \fn const QPoint &QMouseEvent::globalPos() const
  250. Returns the global position of the mouse cursor \e{at the time
  251. of the event}. This is important on asynchronous window systems
  252. like X11. Whenever you move your widgets around in response to
  253. mouse events, globalPos() may differ a lot from the current
  254. pointer position QCursor::pos(), and from
  255. QWidget::mapToGlobal(pos()).
  256. \sa globalX() globalY()
  257. */
  258. /*!
  259. \fn int QMouseEvent::x() const
  260. Returns the x position of the mouse cursor, relative to the
  261. widget that received the event.
  262. \sa y() pos()
  263. */
  264. /*!
  265. \fn int QMouseEvent::y() const
  266. Returns the y position of the mouse cursor, relative to the
  267. widget that received the event.
  268. \sa x() pos()
  269. */
  270. /*!
  271. \fn int QMouseEvent::globalX() const
  272. Returns the global x position of the mouse cursor at the time of
  273. the event.
  274. \sa globalY() globalPos()
  275. */
  276. /*!
  277. \fn int QMouseEvent::globalY() const
  278. Returns the global y position of the mouse cursor at the time of
  279. the event.
  280. \sa globalX() globalPos()
  281. */
  282. /*!
  283. \fn Qt::MouseButton QMouseEvent::button() const
  284. Returns the button that caused the event.
  285. Note that the returned value is always Qt::NoButton for mouse
  286. move events.
  287. \sa buttons() Qt::MouseButton
  288. */
  289. /*!
  290. \fn Qt::MouseButton QMouseEvent::buttons() const
  291. Returns the button state when the event was generated. The button
  292. state is a combination of Qt::LeftButton, Qt::RightButton,
  293. Qt::MidButton using the OR operator. For mouse move events,
  294. this is all buttons that are pressed down. For mouse press and
  295. double click events this includes the button that caused the
  296. event. For mouse release events this excludes the button that
  297. caused the event.
  298. \sa button() Qt::MouseButton
  299. */
  300. /*!
  301. \fn Qt::ButtonState QMouseEvent::state() const
  302. Returns the button state immediately before the event was
  303. generated. The button state is a combination of mouse buttons
  304. (see Qt::ButtonState) and keyboard modifiers (Qt::MouseButtons).
  305. Use buttons() and/or modifiers() instead. Be aware that buttons()
  306. return the state immediately \e after the event was generated.
  307. */
  308. /*!
  309. \fn Qt::ButtonState QMouseEvent::stateAfter() const
  310. Returns the button state immediately after the event was
  311. generated. The button state is a combination of mouse buttons
  312. (see Qt::ButtonState) and keyboard modifiers (Qt::MouseButtons).
  313. Use buttons() and/or modifiers() instead.
  314. */
  315. /*!
  316. \class QHoverEvent
  317. \ingroup events
  318. \brief The QHoverEvent class contains parameters that describe a mouse event.
  319. Mouse events occur when a mouse cursor is moved into, out of, or within a
  320. widget, and if the widget has the Qt::WA_Hover attribute.
  321. The function pos() gives the current cursor position, while oldPos() gives
  322. the old mouse position.
  323. There are a few similarities between the events QEvent::HoverEnter
  324. and QEvent::HoverLeave, and the events QEvent::Enter and QEvent::Leave.
  325. However, they are slightly different because we do an update() in the event
  326. handler of HoverEnter and HoverLeave.
  327. QEvent::HoverMove is also slightly different from QEvent::MouseMove. Let us
  328. consider a top-level window A containing a child B which in turn contains a
  329. child C (all with mouse tracking enabled):
  330. \image hoverevents.png
  331. Now, if you move the cursor from the top to the bottom in the middle of A,
  332. you will get the following QEvent::MouseMove events:
  333. \list 1
  334. \o A::MouseMove
  335. \o B::MouseMove
  336. \o C::MouseMove
  337. \endlist
  338. You will get the same events for QEvent::HoverMove, except that the event
  339. always propagates to the top-level regardless whether the event is accepted
  340. or not. It will only stop propagating with the Qt::WA_NoMousePropagation
  341. attribute.
  342. In this case the events will occur in the following way:
  343. \list 1
  344. \o A::HoverMove
  345. \o A::HoverMove, B::HoverMove
  346. \o A::HoverMove, B::HoverMove, C::HoverMove
  347. \endlist
  348. */
  349. /*!
  350. \fn const QPoint &QHoverEvent::pos() const
  351. Returns the position of the mouse cursor, relative to the widget
  352. that received the event.
  353. On QEvent::HoverLeave events, this position will always be
  354. QPoint(-1, -1).
  355. \sa oldPos()
  356. */
  357. /*!
  358. \fn const QPoint &QHoverEvent::oldPos() const
  359. Returns the previous position of the mouse cursor, relative to the widget
  360. that received the event. If there is no previous position, oldPos() will
  361. return the same position as pos().
  362. On QEvent::HoverEnter events, this position will always be
  363. QPoint(-1, -1).
  364. \sa pos()
  365. */
  366. /*!
  367. Constructs a hover event object.
  368. The \a type parameter must be QEvent::HoverEnter,
  369. QEvent::HoverLeave, or QEvent::HoverMove.
  370. The \a pos is the current mouse cursor's position relative to the
  371. receiving widget, while \a oldPos is the previous mouse cursor's
  372. position relative to the receiving widget.
  373. */
  374. QHoverEvent::QHoverEvent(Type type, const QPoint &pos, const QPoint &oldPos)
  375. : QEvent(type), p(pos), op(oldPos)
  376. {
  377. }
  378. /*!
  379. \internal
  380. */
  381. QHoverEvent::~QHoverEvent()
  382. {
  383. }
  384. /*!
  385. \class QWheelEvent
  386. \brief The QWheelEvent class contains parameters that describe a wheel event.
  387. \ingroup events
  388. Wheel events are sent to the widget under the mouse cursor, but
  389. if that widget does not handle the event they are sent to the
  390. focus widget. The rotation distance is provided by delta().
  391. The functions pos() and globalPos() return the mouse cursor's
  392. location at the time of the event.
  393. A wheel event contains a special accept flag that indicates
  394. whether the receiver wants the event. You should call ignore() if
  395. you do not handle the wheel event; this ensures that it will be
  396. sent to the parent widget.
  397. The QWidget::setEnabled() function can be used to enable or
  398. disable mouse and keyboard events for a widget.
  399. The event handler QWidget::wheelEvent() receives wheel events.
  400. \sa QMouseEvent QWidget::grabMouse()
  401. */
  402. /*!
  403. \fn Qt::MouseButtons QWheelEvent::buttons() const
  404. Returns the mouse state when the event occurred.
  405. */
  406. /*!
  407. \fn Qt::Orientation QWheelEvent::orientation() const
  408. Returns the wheel's orientation.
  409. */
  410. /*!
  411. Constructs a wheel event object.
  412. The position, \a pos, is the location of the mouse cursor within
  413. the widget. The globalPos() is initialized to QCursor::pos()
  414. which is usually, but not always, correct.
  415. Use the other constructor if you need to specify the global
  416. position explicitly.
  417. The \a buttons describe the state of the mouse buttons at the time
  418. of the event, \a delta contains the rotation distance,
  419. \a modifiers holds the keyboard modifier flags at the time of the
  420. event, and \a orient holds the wheel's orientation.
  421. \sa pos() delta() state()
  422. */
  423. #ifndef QT_NO_WHEELEVENT
  424. QWheelEvent::QWheelEvent(const QPoint &pos, int delta,
  425. Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers,
  426. Qt::Orientation orient)
  427. : QInputEvent(Wheel, modifiers), p(pos), d(delta), mouseState(buttons), o(orient)
  428. {
  429. g = QCursor::pos();
  430. }
  431. /*!
  432. \internal
  433. */
  434. QWheelEvent::~QWheelEvent()
  435. {
  436. }
  437. #ifdef QT3_SUPPORT
  438. /*!
  439. Use one of the other constructors instead.
  440. */
  441. QWheelEvent::QWheelEvent(const QPoint &pos, int delta, int state, Qt::Orientation orient)
  442. : QInputEvent(Wheel), p(pos), d(delta), o(orient)
  443. {
  444. g = QCursor::pos();
  445. mouseState = Qt::MouseButtons(state & Qt::MouseButtonMask);
  446. modState = Qt::KeyboardModifiers(state & (int)Qt::KeyButtonMask);
  447. }
  448. #endif
  449. /*!
  450. Constructs a wheel event object.
  451. The \a pos provides the location of the mouse cursor
  452. within the widget. The position in global coordinates is specified
  453. by \a globalPos. \a delta contains the rotation distance, \a modifiers
  454. holds the keyboard modifier flags at the time of the event, and
  455. \a orient holds the wheel's orientation.
  456. \sa pos() globalPos() delta() state()
  457. */
  458. QWheelEvent::QWheelEvent(const QPoint &pos, const QPoint& globalPos, int delta,
  459. Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers,
  460. Qt::Orientation orient)
  461. : QInputEvent(Wheel, modifiers), p(pos), g(globalPos), d(delta), mouseState(buttons), o(orient)
  462. {}
  463. #ifdef QT3_SUPPORT
  464. /*!
  465. Use one of the other constructors instead.
  466. */
  467. QWheelEvent::QWheelEvent(const QPoint &pos, const QPoint& globalPos, int delta, int state,
  468. Qt::Orientation orient)
  469. : QInputEvent(Wheel), p(pos), g(globalPos), d(delta), o(orient)
  470. {
  471. mouseState = Qt::MouseButtons(state & Qt::MouseButtonMask);
  472. modState = Qt::KeyboardModifiers(state & (int) Qt::KeyButtonMask);
  473. }
  474. #endif
  475. #endif // QT_NO_WHEELEVENT
  476. /*!
  477. \fn int QWheelEvent::delta() const
  478. Returns the distance that the wheel is rotated, in eighths of a
  479. degree. A positive value indicates that the wheel was rotated
  480. forwards away from the user; a negative value indicates that the
  481. wheel was rotated backwards toward the user.
  482. Most mouse types work in steps of 15 degrees, in which case the
  483. delta value is a multiple of 120; i.e., 120 units * 1/8 = 15 degrees.
  484. However, some mice have finer-resolution wheels and send delta values
  485. that are less than 120 units (less than 15 degrees). To support this
  486. possibility, you can either cumulatively add the delta values from events
  487. until the value of 120 is reached, then scroll the widget, or you can
  488. partially scroll the widget in response to each wheel event.
  489. Example:
  490. \snippet doc/src/snippets/code/src_gui_kernel_qevent.cpp 0
  491. */
  492. /*!
  493. \fn const QPoint &QWheelEvent::pos() const
  494. Returns the position of the mouse cursor relative to the widget
  495. that received the event.
  496. If you move your widgets around in response to mouse events,
  497. use globalPos() instead of this function.
  498. \sa x() y() globalPos()
  499. */
  500. /*!
  501. \fn int QWheelEvent::x() const
  502. Returns the x position of the mouse cursor, relative to the
  503. widget that received the event.
  504. \sa y() pos()
  505. */
  506. /*!
  507. \fn int QWheelEvent::y() const
  508. Returns the y position of the mouse cursor, relative to the
  509. widget that received the event.
  510. \sa x() pos()
  511. */
  512. /*!
  513. \fn const QPoint &QWheelEvent::globalPos() const
  514. Returns the global position of the mouse pointer \e{at the time
  515. of the event}. This is important on asynchronous window systems
  516. such as X11; whenever you move your widgets around in response to
  517. mouse events, globalPos() can differ a lot from the current
  518. cursor position returned by QCursor::pos().
  519. \sa globalX() globalY()
  520. */
  521. /*!
  522. \fn int QWheelEvent::globalX() const
  523. Returns the global x position of the mouse cursor at the time of
  524. the event.
  525. \sa globalY() globalPos()
  526. */
  527. /*!
  528. \fn int QWheelEvent::globalY() const
  529. Returns the global y position of the mouse cursor at the time of
  530. the event.
  531. \sa globalX() globalPos()
  532. */
  533. /*! \obsolete
  534. \fn Qt::ButtonState QWheelEvent::state() const
  535. Returns the keyboard modifier flags at the time of the event.
  536. The returned value is a selection of the following values,
  537. combined using the OR operator: Qt::ShiftButton,
  538. Qt::ControlButton, and Qt::AltButton.
  539. */
  540. /*!
  541. \class QKeyEvent
  542. \brief The QKeyEvent class describes a key event.
  543. \ingroup events
  544. Key events are sent to the widget with keyboard input focus
  545. when keys are pressed or released.
  546. A key event contains a special accept flag that indicates whether
  547. the receiver will handle the key event. You should call ignore()
  548. if the key press or release event is not handled by your widget.
  549. A key event is propagated up the parent widget chain until a
  550. widget accepts it with accept() or an event filter consumes it.
  551. Key events for multimedia keys are ignored by default. You should
  552. call accept() if your widget handles those events.
  553. The QWidget::setEnable() function can be used to enable or disable
  554. mouse and keyboard events for a widget.
  555. The event handlers QWidget::keyPressEvent(), QWidget::keyReleaseEvent(),
  556. QGraphicsItem::keyPressEvent() and QGraphicsItem::keyReleaseEvent()
  557. receive key events.
  558. \sa QFocusEvent, QWidget::grabKeyboard()
  559. */
  560. /*!
  561. Constructs a key event object.
  562. The \a type parameter must be QEvent::KeyPress, QEvent::KeyRelease,
  563. or QEvent::ShortcutOverride.
  564. Int \a key is the code for the Qt::Key that the event loop should listen
  565. for. If \a key is 0, the event is not a result of a known key; for
  566. example, it may be the result of a compose sequence or keyboard macro.
  567. The \a modifiers holds the keyboard modifiers, and the given \a text
  568. is the Unicode text that the key generated. If \a autorep is true,
  569. isAutoRepeat() will be true. \a count is the number of keys involved
  570. in the event.
  571. */
  572. QKeyEvent::QKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers, const QString& text,
  573. bool autorep, ushort count)
  574. : QInputEvent(type, modifiers), txt(text), k(key), c(count), autor(autorep)
  575. {
  576. }
  577. /*!
  578. \internal
  579. */
  580. QKeyEvent::~QKeyEvent()
  581. {
  582. }
  583. /*!
  584. \internal
  585. */
  586. QKeyEvent *QKeyEvent::createExtendedKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers,
  587. quint32 nativeScanCode, quint32 nativeVirtualKey,
  588. quint32 nativeModifiers,
  589. const QString& text, bool autorep, ushort count)
  590. {
  591. return new QKeyEventEx(type, key, modifiers, text, autorep, count,
  592. nativeScanCode, nativeVirtualKey, nativeModifiers);
  593. }
  594. /*!
  595. \fn bool QKeyEvent::hasExtendedInfo() const
  596. \internal
  597. */
  598. /*!
  599. \since 4.2
  600. Returns the native scan code of the key event. If the key event
  601. does not contain this data 0 is returned.
  602. Note: The native scan code may be 0, even if the key event contains
  603. extended information.
  604. Note: On Mac OS/X, this function is not useful, because there is no
  605. way to get the scan code from Carbon or Cocoa. The function always
  606. returns 1 (or 0 in the case explained above).
  607. */
  608. quint32 QKeyEvent::nativeScanCode() const
  609. {
  610. return (reinterpret_cast<const QKeyEvent*>(d) != this
  611. ? 0 : reinterpret_cast<const QKeyEventEx*>(this)->nScanCode);
  612. }
  613. /*!
  614. \since 4.2
  615. Returns the native virtual key, or key sym of the key event.
  616. If the key event does not contain this data 0 is returned.
  617. Note: The native virtual key may be 0, even if the key event contains extended information.
  618. */
  619. quint32 QKeyEvent::nativeVirtualKey() const
  620. {
  621. return (reinterpret_cast<const QKeyEvent*>(d) != this
  622. ? 0 : reinterpret_cast<const QKeyEventEx*>(this)->nVirtualKey);
  623. }
  624. /*!
  625. \since 4.2
  626. Returns the native modifiers of a key event.
  627. If the key event does not contain this data 0 is returned.
  628. Note: The native modifiers may be 0, even if the key event contains extended information.
  629. */
  630. quint32 QKeyEvent::nativeModifiers() const
  631. {
  632. return (reinterpret_cast<const QKeyEvent*>(d) != this
  633. ? 0 : reinterpret_cast<const QKeyEventEx*>(this)->nModifiers);
  634. }
  635. /*!
  636. \internal
  637. Creates an extended key event object, which in addition to the normal key event data, also
  638. contains the native scan code, virtual key and modifiers. This extra data is used by the
  639. shortcut system, to determine which shortcuts to trigger.
  640. */
  641. QKeyEventEx::QKeyEventEx(Type type, int key, Qt::KeyboardModifiers modifiers,
  642. const QString &text, bool autorep, ushort count,
  643. quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers)
  644. : QKeyEvent(type, key, modifiers, text, autorep, count),
  645. nScanCode(nativeScanCode), nVirtualKey(nativeVirtualKey), nModifiers(nativeModifiers)
  646. {
  647. d = reinterpret_cast<QEventPrivate*>(this);
  648. }
  649. /*!
  650. \internal
  651. Creates a copy of an other extended key event.
  652. */
  653. QKeyEventEx::QKeyEventEx(const QKeyEventEx &other)
  654. : QKeyEvent(QEvent::Type(other.t), other.k, other.modState, other.txt, other.autor, other.c),
  655. nScanCode(other.nScanCode), nVirtualKey(other.nVirtualKey), nModifiers(other.nModifiers)
  656. {
  657. d = reinterpret_cast<QEventPrivate*>(this);
  658. }
  659. /*!
  660. \internal
  661. */
  662. QKeyEventEx::~QKeyEventEx()
  663. {
  664. }
  665. /*!
  666. \fn int QKeyEvent::key() const
  667. Returns the code of the key that was pressed or released.
  668. See \l Qt::Key for the list of keyboard codes. These codes are
  669. independent of the underlying window system. Note that this
  670. function does not distinguish between capital and non-capital
  671. letters, use the text() function (returning the Unicode text the
  672. key generated) for this purpose.
  673. A value of either 0 or Qt::Key_unknown means that the event is not
  674. the result of a known key; for example, it may be the result of
  675. a compose sequence, a keyboard macro, or due to key event
  676. compression.
  677. \sa Qt::WA_KeyCompression
  678. */
  679. /*!
  680. \fn QString QKeyEvent::text() const
  681. Returns the Unicode text that this key generated. The text
  682. returned can be an empty string in cases
  683. where modifier keys, such as Shift, Control, Alt, and Meta,
  684. are being pressed or released. In such cases key() will contain
  685. a valid value.
  686. \sa Qt::WA_KeyCompression
  687. */
  688. /*!
  689. Returns the keyboard modifier flags that existed immediately
  690. after the event occurred.
  691. \warning This function cannot always be trusted. The user can
  692. confuse it by pressing both \key{Shift} keys simultaneously and
  693. releasing one of them, for example.
  694. \sa QApplication::keyboardModifiers()
  695. */
  696. //###### We must check with XGetModifierMapping
  697. Qt::KeyboardModifiers QKeyEvent::modifiers() const
  698. {
  699. if (key() == Qt::Key_Shift)
  700. return Qt::KeyboardModifiers(QInputEvent::modifiers()^Qt::ShiftModifier);
  701. if (key() == Qt::Key_Control)
  702. return Qt::KeyboardModifiers(QInputEvent::modifiers()^Qt::ControlModifier);
  703. if (key() == Qt::Key_Alt)
  704. return Qt::KeyboardModifiers(QInputEvent::modifiers()^Qt::AltModifier);
  705. if (key() == Qt::Key_Meta)
  706. return Qt::KeyboardModifiers(QInputEvent::modifiers()^Qt::MetaModifier);
  707. return QInputEvent::modifiers();
  708. }
  709. #ifndef QT_NO_SHORTCUT
  710. /*!
  711. \fn bool QKeyEvent::matches(QKeySequence::StandardKey key) const
  712. \since 4.2
  713. Returns true if the key event matches the given standard \a key;
  714. otherwise returns false.
  715. */
  716. bool QKeyEvent::matches(QKeySequence::StandardKey matchKey) const
  717. {
  718. uint searchkey = (modifiers() | key()) & ~(Qt::KeypadModifier); //The keypad modifier should not make a difference
  719. uint platform = QApplicationPrivate::currentPlatform();
  720. #ifdef Q_WS_MAC
  721. if (qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta)) {
  722. uint oldSearchKey = searchkey;
  723. searchkey &= ~(Qt::ControlModifier | Qt::MetaModifier);
  724. if (oldSearchKey & Qt::ControlModifier)
  725. searchkey |= Qt::MetaModifier;
  726. if (oldSearchKey & Qt::MetaModifier)
  727. searchkey |= Qt::ControlModifier;
  728. }
  729. #endif
  730. uint N = QKeySequencePrivate::numberOfKeyBindings;
  731. int first = 0;
  732. int last = N - 1;
  733. while (first <= last) {
  734. int mid = (first + last) / 2;
  735. QKeyBinding midVal = QKeySequencePrivate::keyBindings[mid];
  736. if (searchkey > midVal.shortcut){
  737. first = mid + 1; // Search in top half
  738. }
  739. else if (searchkey < midVal.shortcut){
  740. last = mid - 1; // Search in bottom half
  741. }
  742. else {
  743. //found correct shortcut value, now we must check for platform match
  744. if ((midVal.platform & platform) && (midVal.standardKey == matchKey)) {
  745. return true;
  746. } else { //We may have several equal values for different platforms, so we must search in both directions
  747. //search forward
  748. for ( unsigned int i = mid + 1 ; i < N - 1 ; ++i) {
  749. QKeyBinding current = QKeySequencePrivate::keyBindings[i];
  750. if (current.shortcut != searchkey)
  751. break;
  752. else if (current.platform & platform && current.standardKey == matchKey)
  753. return true;
  754. }
  755. //search back
  756. for ( int i = mid - 1 ; i >= 0 ; --i) {
  757. QKeyBinding current = QKeySequencePrivate::keyBindings[i];
  758. if (current.shortcut != searchkey)
  759. break;
  760. else if (current.platform & platform && current.standardKey == matchKey)
  761. return true;
  762. }
  763. return false; //we could not find it among the matching keySequences
  764. }
  765. }
  766. }
  767. return false; //we could not find matching keySequences at all
  768. }
  769. #endif // QT_NO_SHORTCUT
  770. /*!
  771. \fn bool QKeyEvent::isAutoRepeat() const
  772. Returns true if this event comes from an auto-repeating key;
  773. returns false if it comes from an initial key press.
  774. Note that if the event is a multiple-key compressed event that is
  775. partly due to auto-repeat, this function could return either true
  776. or false indeterminately.
  777. */
  778. /*!
  779. \fn int QKeyEvent::count() const
  780. Returns the number of keys involved in this event. If text()
  781. is not empty, this is simply the length of the string.
  782. \sa Qt::WA_KeyCompression
  783. */
  784. #ifdef QT3_SUPPORT
  785. /*!
  786. \fn QKeyEvent::QKeyEvent(Type type, int key, int ascii,
  787. int modifiers, const QString &text,
  788. bool autorep, ushort count)
  789. Use one of the other constructors instead.
  790. */
  791. /*!
  792. \fn int QKeyEvent::ascii() const
  793. Use text() instead.
  794. */
  795. /*!
  796. \fn Qt::ButtonState QKeyEvent::state() const
  797. Use QInputEvent::modifiers() instead.
  798. */
  799. /*!
  800. \fn Qt::ButtonState QKeyEvent::stateAfter() const
  801. Use modifiers() instead.
  802. */
  803. #endif
  804. /*!
  805. \class QFocusEvent
  806. \brief The QFocusEvent class contains event parameters for widget focus
  807. events.
  808. \ingroup events
  809. Focus events are sent to widgets when the keyboard input focus
  810. changes. Focus events occur due to mouse actions, key presses
  811. (such as \gui{Tab} or \gui{Backtab}), the window system, popup
  812. menus, keyboard shortcuts, or other application-specific reasons.
  813. The reason for a particular focus event is returned by reason()
  814. in the appropriate event handler.
  815. The event handlers QWidget::focusInEvent(),
  816. QWidget::focusOutEvent(), QGraphicsItem::focusInEvent and
  817. QGraphicsItem::focusOutEvent() receive focus events.
  818. \sa QWidget::setFocus(), QWidget::setFocusPolicy(), {Keyboard Focus}
  819. */
  820. /*!
  821. Constructs a focus event object.
  822. The \a type parameter must be either QEvent::FocusIn or
  823. QEvent::FocusOut. The \a reason describes the cause of the change
  824. in focus.
  825. */
  826. QFocusEvent::QFocusEvent(Type type, Qt::FocusReason reason)
  827. : QEvent(type), m_reason(reason)
  828. {}
  829. /*!
  830. \internal
  831. */
  832. QFocusEvent::~QFocusEvent()
  833. {
  834. }
  835. // ### Qt 5: remove
  836. /*!
  837. \internal
  838. */
  839. Qt::FocusReason QFocusEvent::reason()
  840. {
  841. return m_reason;
  842. }
  843. /*!
  844. Returns the reason for this focus event.
  845. */
  846. Qt::FocusReason QFocusEvent::reason() const
  847. {
  848. return m_reason;
  849. }
  850. /*!
  851. \fn bool QFocusEvent::gotFocus() const
  852. Returns true if type() is QEvent::FocusIn; otherwise returns
  853. false.
  854. */
  855. /*!
  856. \fn bool QFocusEvent::lostFocus() const
  857. Returns true if type() is QEvent::FocusOut; otherwise returns
  858. false.
  859. */
  860. #ifdef QT3_SUPPORT
  861. /*!
  862. \enum QFocusEvent::Reason
  863. \compat
  864. Use Qt::FocusReason instead.
  865. \value Mouse Same as Qt::MouseFocusReason.
  866. \value Tab Same as Qt::TabFocusReason.
  867. \value Backtab Same as Qt::BacktabFocusReason.
  868. \value MenuBar Same as Qt::MenuBarFocusReason.
  869. \value ActiveWindow Same as Qt::ActiveWindowFocusReason
  870. \value Other Same as Qt::OtherFocusReason
  871. \value Popup Same as Qt::PopupFocusReason
  872. \value Shortcut Same as Qt::ShortcutFocusReason
  873. */
  874. #endif
  875. /*!
  876. \class QPaintEvent
  877. \brief The QPaintEvent class contains event parameters for paint events.
  878. \ingroup events
  879. Paint events are sent to widgets that need to update themselves,
  880. for instance when part of a widget is exposed because a covering
  881. widget was moved.
  882. The event contains a region() that needs to be updated, and a
  883. rect() that is the bounding rectangle of that region. Both are
  884. provided because many widgets can't make much use of region(),
  885. and rect() can be much faster than region().boundingRect().
  886. \section1 Automatic Clipping
  887. Painting is clipped to region() during the processing of a paint
  888. event. This clipping is performed by Qt's paint system and is
  889. independent of any clipping that may be applied to a QPainter used to
  890. draw on the paint device.
  891. As a result, the value returned by QPainter::clipRegion() on
  892. a newly-constructed QPainter will not reflect the clip region that is
  893. used by the paint system.
  894. \sa QPainter, QWidget::update(), QWidget::repaint(),
  895. QWidget::paintEvent()
  896. */
  897. /*!
  898. \fn bool QPaintEvent::erased() const
  899. \compat
  900. Returns true if the paint event region (or rectangle) has been
  901. erased with the widget's background; otherwise returns false.
  902. Qt 4 \e always erases regions that require painting. The exception
  903. to this rule is if the widget sets the Qt::WA_OpaquePaintEvent or
  904. Qt::WA_NoSystemBackground attributes. If either one of those
  905. attributes is set \e and the window system does not make use of
  906. subwidget alpha composition (currently X11 and Windows, but this
  907. may change), then the region is not erased.
  908. */
  909. /*!
  910. \fn void QPaintEvent::setErased(bool b) { m_erased = b; }
  911. \internal
  912. */
  913. /*!
  914. Constructs a paint event object with the region that needs to
  915. be updated. The region is specified by \a paintRegion.
  916. */
  917. QPaintEvent::QPaintEvent(const QRegion& paintRegion)
  918. : QEvent(Paint), m_rect(paintRegion.boundingRect()), m_region(paintRegion), m_erased(false)
  919. {}
  920. /*!
  921. Constructs a paint event object with the rectangle that needs
  922. to be updated. The region is specified by \a paintRect.
  923. */
  924. QPaintEvent::QPaintEvent(const QRect &paintRect)
  925. : QEvent(Paint), m_rect(paintRect),m_region(paintRect), m_erased(false)
  926. {}
  927. #ifdef QT3_SUPPORT
  928. /*!
  929. Constructs a paint event object with both a \a paintRegion and a
  930. \a paintRect, both of which represent the area of the widget that
  931. needs to be updated.
  932. */
  933. QPaintEvent::QPaintEvent(const QRegion &paintRegion, const QRect &paintRect)
  934. : QEvent(Paint), m_rect(paintRect), m_region(paintRegion), m_erased(false)
  935. {}
  936. #endif
  937. /*!
  938. \internal
  939. */
  940. QPaintEvent::~QPaintEvent()
  941. {
  942. }
  943. /*!
  944. \fn const QRect &QPaintEvent::rect() const
  945. Returns the rectangle that needs to be updated.
  946. \sa region() QPainter::setClipRect()
  947. */
  948. /*!
  949. \fn const QRegion &QPaintEvent::region() const
  950. Returns the region that needs to be updated.
  951. \sa rect() QPainter::setClipRegion()
  952. */
  953. QUpdateLaterEvent::QUpdateLaterEvent(const QRegion& paintRegion)
  954. : QEvent(UpdateLater), m_region(paintRegion)
  955. {
  956. }
  957. QUpdateLaterEvent::~QUpdateLaterEvent()
  958. {
  959. }
  960. /*!
  961. \class QMoveEvent
  962. \brief The QMoveEvent class contains event parameters for move events.
  963. \ingroup events
  964. Move events are sent to widgets that have been moved to a new
  965. position relative to their parent.
  966. The event handler QWidget::moveEvent() receives move events.
  967. \sa QWidget::move(), QWidget::setGeometry()
  968. */
  969. /*!
  970. Constructs a move event with the new and old widget positions,
  971. \a pos and \a oldPos respectively.
  972. */
  973. QMoveEvent::QMoveEvent(const QPoint &pos, const QPoint &oldPos)
  974. : QEvent(Move), p(pos), oldp(oldPos)
  975. {}
  976. /*!
  977. \internal
  978. */
  979. QMoveEvent::~QMoveEvent()
  980. {
  981. }
  982. /*!
  983. \fn const QPoint &QMoveEvent::pos() const
  984. Returns the new position of the widget. This excludes the window
  985. frame for top level widgets.
  986. */
  987. /*!
  988. \fn const QPoint &QMoveEvent::oldPos() const
  989. Returns the old position of the widget.
  990. */
  991. /*!
  992. \class QResizeEvent
  993. \brief The QResizeEvent class contains event parameters for resize events.
  994. \ingroup events
  995. Resize events are sent to widgets that have been resized.
  996. The event handler QWidget::resizeEvent() receives resize events.
  997. \sa QWidget::resize() QWidget::setGeometry()
  998. */
  999. /*!
  1000. Constructs a resize event with the new and old widget sizes, \a
  1001. size and \a oldSize respectively.
  1002. */
  1003. QResizeEvent::QResizeEvent(const QSize &size, const QSize &oldSize)
  1004. : QEvent(Resize), s(size), olds(oldSize)
  1005. {}
  1006. /*!
  1007. \internal
  1008. */
  1009. QResizeEvent::~QResizeEvent()
  1010. {
  1011. }
  1012. /*!
  1013. \fn const QSize &QResizeEvent::size() const
  1014. Returns the new size of the widget. This is the same as
  1015. QWidget::size().
  1016. */
  1017. /*!
  1018. \fn const QSize &QResizeEvent::oldSize() const
  1019. Returns the old size of the widget.
  1020. */
  1021. /*!
  1022. \class QCloseEvent
  1023. \brief The QCloseEvent class contains parameters that describe a close event.
  1024. \ingroup events
  1025. Close events are sent to widgets that the user wants to close,
  1026. usually by choosing "Close" from the window menu, or by clicking
  1027. the \gui{X} title bar button. They are also sent when you call
  1028. QWidget::close() to close a widget programmatically.
  1029. Close events contain a flag that indicates whether the receiver
  1030. wants the widget to be closed or not. When a widget accepts the
  1031. close event, it is hidden (and destroyed if it was created with
  1032. the Qt::WA_DeleteOnClose flag). If it refuses to accept the close
  1033. event nothing happens. (Under X11 it is possible that the window
  1034. manager will forcibly close the window; but at the time of writing
  1035. we are not aware of any window manager that does this.)
  1036. The event handler QWidget::closeEvent() receives close events. The
  1037. default implementation of this event handler accepts the close
  1038. event. If you do not want your widget to be hidden, or want some
  1039. special handing, you should reimplement the event handler and
  1040. ignore() the event.
  1041. The \l{mainwindows/application#close event handler}{closeEvent() in the
  1042. Application example} shows a close event handler that
  1043. asks whether to save a document before closing.
  1044. If you want the widget to be deleted when it is closed, create it
  1045. with the Qt::WA_DeleteOnClose flag. This is very useful for
  1046. independent top-level windows in a multi-window application.
  1047. \l{QObject}s emits the \l{QObject::destroyed()}{destroyed()}
  1048. signal when they are deleted.
  1049. If the last top-level window is closed, the
  1050. QApplication::lastWindowClosed() signal is emitted.
  1051. The isAccepted() function returns true if the event's receiver has
  1052. agreed to close the widget; call accept() to agree to close the
  1053. widget and call ignore() if the receiver of this event does not
  1054. want the widget to be closed.
  1055. \sa QWidget::close(), QWidget::hide(), QObject::destroyed(),
  1056. QCoreApplication::exec(), QCoreApplication::quit(),
  1057. QApplication::lastWindowClosed()
  1058. */
  1059. /*!
  1060. Constructs a close event object.
  1061. \sa accept()
  1062. */
  1063. QCloseEvent::QCloseEvent()
  1064. : QEvent(Close)
  1065. {}
  1066. /*! \internal
  1067. */
  1068. QCloseEvent::~QCloseEvent()
  1069. {
  1070. }
  1071. /*!
  1072. \class QIconDragEvent
  1073. \brief The QIconDragEvent class indicates that a main icon drag has begun.
  1074. \ingroup events
  1075. Icon drag events are sent to widgets when the main icon of a window
  1076. has been dragged away. On Mac OS X, this happens when the proxy
  1077. icon of a window is dragged off the title bar.
  1078. It is normal to begin using drag and drop in response to this
  1079. event.
  1080. \sa {Drag and Drop}, QMimeData, QDrag
  1081. */
  1082. /*!
  1083. Constructs an icon drag event object with the accept flag set to
  1084. false.
  1085. \sa accept()
  1086. */
  1087. QIconDragEvent::QIconDragEvent()
  1088. : QEvent(IconDrag)
  1089. { ignore(); }
  1090. /*! \internal */
  1091. QIconDragEvent::~QIconDragEvent()
  1092. {
  1093. }
  1094. /*!
  1095. \class QContextMenuEvent
  1096. \brief The QContextMenuEvent class contains parameters that describe a context menu event.
  1097. \ingroup events
  1098. Context menu events are sent to widgets when a user performs
  1099. an action associated with opening a context menu.
  1100. The actions required to open context menus vary between platforms;
  1101. for example, on Windows, pressing the menu button or clicking the
  1102. right mouse button will cause this event to be sent.
  1103. When this event occurs it is customary to show a QMenu with a
  1104. context menu, if this is relevant to the context.
  1105. Context menu events contain a special accept flag that indicates
  1106. whether the receiver accepted the event. If the event handler does
  1107. not accept the event then, if possible, whatever triggered the event will be
  1108. handled as a regular input event.
  1109. */
  1110. #ifndef QT_NO_CONTEXTMENU
  1111. /*!
  1112. Constructs a context menu event object with the accept parameter
  1113. flag set to false.
  1114. The \a reason parameter must be QContextMenuEvent::Mouse or
  1115. QContextMenuEvent::Keyboard.
  1116. The \a pos parameter specifies the mouse position relative to the
  1117. receiving widget. \a globalPos is the mouse position in absolute
  1118. coordinates.
  1119. */
  1120. QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos, const QPoint &globalPos)
  1121. : QInputEvent(ContextMenu), p(pos), gp(globalPos), reas(reason)
  1122. {}
  1123. /*!
  1124. Constructs a context menu event object with the accept parameter
  1125. flag set to false.
  1126. The \a reason parameter must be QContextMenuEvent::Mouse or
  1127. QContextMenuEvent::Keyboard.
  1128. The \a pos parameter specifies the mouse position relative to the
  1129. receiving widget. \a globalPos is the mouse position in absolute
  1130. coordinates. The \a modifiers holds the keyboard modifiers.
  1131. */
  1132. QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos, const QPoint &globalPos,
  1133. Qt::KeyboardModifiers modifiers)
  1134. : QInputEvent(ContextMenu, modifiers), p(pos), gp(globalPos), reas(reason)
  1135. {}
  1136. #ifdef QT3_SUPPORT
  1137. /*!
  1138. Constructs a context menu event with the given \a reason for the
  1139. position specified by \a pos in widget coordinates and \a globalPos
  1140. in global screen coordinates. \a dummy is ignored.
  1141. */
  1142. QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos, const QPoint &globalPos,
  1143. int /* dummy */)
  1144. : QInputEvent(ContextMenu), p(pos), gp(globalPos), reas(reason)
  1145. {}
  1146. #endif
  1147. /*! \internal */
  1148. QContextMenuEvent::~QContextMenuEvent()
  1149. {
  1150. }
  1151. /*!
  1152. Constructs a context menu event object with the accept parameter
  1153. flag set to false.
  1154. The \a reason parameter must be QContextMenuEvent::Mouse or
  1155. QContextMenuEvent::Keyboard.
  1156. The \a pos parameter specifies the mouse position relative to the
  1157. receiving widget.
  1158. The globalPos() is initialized to QCursor::pos(), which may not be
  1159. appropriate. Use the other constructor to specify the global
  1160. position explicitly.
  1161. */
  1162. QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos)
  1163. : QInputEvent(ContextMenu), p(pos), reas(reason)
  1164. {
  1165. gp = QCursor::pos();
  1166. }
  1167. #ifdef QT3_SUPPORT
  1168. /*!
  1169. Constructs a context menu event with the given \a reason for the
  1170. position specified by \a pos in widget coordinates. \a dummy is
  1171. ignored.
  1172. */
  1173. QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos, int /* dummy */)
  1174. : QInputEvent(ContextMenu), p(pos), reas(reason)
  1175. {
  1176. gp = QCursor::pos();
  1177. }
  1178. Qt::ButtonState QContextMenuEvent::state() const
  1179. {
  1180. return Qt::ButtonState(int(QApplication::keyboardModifiers())|QApplication::mouseButtons());
  1181. }
  1182. #endif
  1183. /*!
  1184. \fn const QPoint &QContextMenuEvent::pos() const
  1185. Returns the position of the mouse pointer relative to the widget
  1186. that received the event.
  1187. \sa x(), y(), globalPos()
  1188. */
  1189. /*!
  1190. \fn int QContextMenuEvent::x() const
  1191. Returns the x position of the mouse pointer, relative to the
  1192. widget that received the event.
  1193. \sa y(), pos()
  1194. */
  1195. /*!
  1196. \fn int QContextMenuEvent::y() const
  1197. Returns the y position of the mouse pointer, relative to the
  1198. widget that received the event.
  1199. \sa x(), pos()
  1200. */
  1201. /*!
  1202. \fn const QPoint &QContextMenuEvent::globalPos() const
  1203. Returns the global position of the mouse pointer at the time of
  1204. the event.
  1205. \sa x(), y(), pos()
  1206. */
  1207. /*!
  1208. \fn int QContextMenuEvent::globalX() const
  1209. Returns the global x position of the mouse pointer at the time of
  1210. the event.
  1211. \sa globalY(), globalPos()
  1212. */
  1213. /*!
  1214. \fn int QContextMenuEvent::globalY() const
  1215. Returns the global y position of the mouse pointer at the time of
  1216. the event.
  1217. \sa globalX(), globalPos()
  1218. */
  1219. #endif // QT_NO_CONTEXTMENU
  1220. /*!
  1221. \fn Qt::ButtonState QContextMenuEvent::state() const
  1222. Returns the button state (a combination of mouse buttons
  1223. and keyboard modifiers) immediately before the event was
  1224. generated.
  1225. The returned value is a selection of the following values,
  1226. combined with the OR operator:
  1227. Qt::LeftButton, Qt::RightButton, Qt::MidButton,
  1228. Qt::ShiftButton, Qt::ControlButton, and Qt::AltButton.
  1229. */
  1230. /*!
  1231. \enum QContextMenuEvent::Reason
  1232. This enum describes the reason why the event was sent.
  1233. \value Mouse The mouse caused the event to be sent. Normally this
  1234. means the right mouse button was clicked, but this is platform
  1235. dependent.
  1236. \value Keyboard The keyboard caused this event to be sent. On
  1237. Windows, this means the menu button was pressed.
  1238. \value Other The event was sent by some other means (i.e. not by
  1239. the mouse or keyboard).
  1240. */
  1241. /*!
  1242. \fn QContextMenuEvent::Reason QContextMenuEvent::reason() const
  1243. Returns the reason for this context event.
  1244. */
  1245. /*!
  1246. \class QInputMethodEvent
  1247. \brief The QInputMethodEvent class provides parameters for input method events.
  1248. \ingroup events
  1249. Input method events are sent to widgets when an input method is
  1250. used to enter text into a widget. Input methods are widely used
  1251. to enter text for languages with non-Latin alphabets.
  1252. Note that when creating custom text editing widgets, the
  1253. Qt::WA_InputMethodEnabled window attribute must be set explicitly
  1254. (using the QWidget::setAttribute() function) in order to receive
  1255. input method events.
  1256. The events are of interest to authors of keyboard entry widgets
  1257. who want to be able to correctly handle languages with complex
  1258. character input. Text input in such languages is usually a three
  1259. step process:
  1260. \list 1
  1261. \o \bold{Starting to Compose}
  1262. When the user presses the first key on a keyboard, an input
  1263. context is created. This input context will contain a string
  1264. of the typed characters.
  1265. \o \bold{Composing}
  1266. With every new key pressed, the input method will try to create a
  1267. matching string for the text typed so far called preedit
  1268. string. While the input context is active, the user can only move
  1269. the cursor inside the string belonging to this input context.
  1270. \o \bold{Completing}
  1271. At some point, the user will activate a user interface component
  1272. (perhaps using a particular key) where they can choose from a
  1273. number of strings matching the text they have typed so far. The
  1274. user can either confirm their choice cancel the input; in either
  1275. case the input context will be closed.
  1276. \endlist
  1277. QInputMethodEvent models these three stages, and transfers the
  1278. information needed to correctly render the intermediate result. A
  1279. QInputMethodEvent has two main parameters: preeditString() and
  1280. commitString(). The preeditString() parameter gives the currently
  1281. active preedit string. The commitString() parameter gives a text
  1282. that should get added to (or replace parts of) the text of the
  1283. editor widget. It usually is a result of the input operations and
  1284. has to be inserted to the widgets text directly before the preedit
  1285. string.
  1286. If the commitString() should replace parts of the of the text in
  1287. the editor, replacementLength() will contain the number of
  1288. characters to be replaced. replacementStart() contains the position
  1289. at which characters are to be replaced relative from the start of
  1290. the preedit string.
  1291. A number of attributes control the visual appearance of the
  1292. preedit string (the visual appearance of text outside the preedit
  1293. string is controlled by the widget only). The AttributeType enum
  1294. describes the different attributes that can be set.
  1295. A class implementing QWidget::inputMethodEvent() or
  1296. QGraphicsItem::inputMethodEvent() should at least understand and
  1297. honor the \l TextFormat and \l Cursor attributes.
  1298. Since input methods need to be able to query certain properties
  1299. from the widget or graphics item, subclasses must also implement
  1300. QWidget::inputMethodQuery() and QGraphicsItem::inputMethodQuery(),
  1301. respectively.
  1302. When receiving an input method event, the text widget has to performs the
  1303. following steps:
  1304. \list 1
  1305. \o If the widget has selected text, the selected text should get
  1306. removed.
  1307. \o Remove the text starting at replacementStart() with length
  1308. replacementLength() and replace it by the commitString(). If
  1309. replacementLength() is 0, replacementStart() gives the insertion
  1310. position for the commitString().
  1311. When doing replacement the area of the preedit
  1312. string is ignored, thus a replacement starting at -1 with a length
  1313. of 2 will remove the last character before the preedit string and
  1314. the first character afterwards, and insert the commit string
  1315. directly before the preedit string.
  1316. If the widget implements undo/redo, this operation gets added to
  1317. the undo stack.
  1318. \o If there is no current preedit string, insert the
  1319. preeditString() at the current cursor position; otherwise replace
  1320. the previous preeditString with the one received from this event.
  1321. If the widget implements undo/redo, the preeditString() should not
  1322. influence the undo/redo stack in any way.
  1323. The widget should examine the list of attributes to apply to the
  1324. preedit string. It has to understand at least the TextFormat and
  1325. Cursor attributes and render them as specified.
  1326. \endlist
  1327. \sa QInputContext
  1328. */
  1329. /*!
  1330. \enum QInputMethodEvent::AttributeType
  1331. \value TextFormat
  1332. A QTextCharFormat for the part of the preedit string specified by
  1333. start and length. value contains a QVariant of type QTextFormat
  1334. specifying rendering of this part of the preedit string. There
  1335. should be at most one format for every part of the preedit
  1336. string. If several are specified for any character in the string the
  1337. behaviour is undefined. A conforming implementation has to at least
  1338. honor the backgroundColor, textColor and fontUnderline properties
  1339. of the format.
  1340. \value Cursor If set, a cursor should be shown inside the preedit
  1341. string at position start. The length variable determines whether
  1342. the cursor is visible or not. If the length is 0 the cursor is
  1343. invisible. If value is a QVariant of type QColor this color will
  1344. be used for rendering the cursor, otherwise the color of the
  1345. surrounding text will be used. There should be at most one Cursor
  1346. attribute per event. If several are specified the behaviour is
  1347. undefined.
  1348. \value Language
  1349. The variant contains a QLocale object specifying the language of a
  1350. certain part of the preedit string. There should be at most one
  1351. language set for every part of the preedit string. If several are
  1352. specified for any character in the string the behavior is undefined.
  1353. \value Ruby
  1354. The ruby text for a part of the preedit string. There should be at
  1355. most one ruby text set for every part of the preedit string. If
  1356. several are specified for any character in the string the behaviour
  1357. is undefined.
  1358. \value Selection
  1359. If set, the edit cursor should be moved to the specified position
  1360. in the editor text contents. In contrast with \c Cursor, this
  1361. attribute does not work on the preedit text, but on the surrounding
  1362. text. The cursor will be moved after the commit string has been
  1363. committed, and the preedit string will be located at the new edit
  1364. position.
  1365. The start position specifies the new position and the length
  1366. variable can be used to set a selection starting from that point.
  1367. The value is unused.
  1368. \sa Attribute
  1369. */
  1370. /*!
  1371. \class QInputMethodEvent::Attribute
  1372. \brief The QInputMethodEvent::Attribute class stores an input method attribute.
  1373. */
  1374. /*!
  1375. \fn QInputMethodEvent::Attribute::Attribute(AttributeType type, int start, int length, QVariant value)
  1376. Constructs an input method attribute. \a type specifies the type
  1377. of attribute, \a start and \a length the position of the
  1378. attribute, and \a value the value of the attribute.
  1379. */
  1380. /*!
  1381. Constructs an event of type QEvent::InputMethod. The
  1382. attributes(), preeditString(), commitString(), replacementStart(),
  1383. and replacementLength() are initialized to default values.
  1384. \sa setCommitString()
  1385. */
  1386. QInputMethodEvent::QInputMethodEvent()
  1387. : QEvent(QEvent::InputMethod), replace_from(0), replace_length(0)
  1388. {
  1389. }
  1390. /*!
  1391. Construcs an event of type QEvent::InputMethod. The
  1392. preedit text is set to \a preeditText, the attributes to
  1393. \a attributes.
  1394. The commitString(), replacementStart(), and replacementLength()
  1395. values can be set using setCommitString().
  1396. \sa preeditString(), attributes()
  1397. */
  1398. QInputMethodEvent::QInputMethodEvent(const QString &preeditText, const QList<Attribute> &attributes)
  1399. : QEvent(QEvent::InputMethod), preedit(preeditText), attrs(attributes),
  1400. replace_from(0), replace_length(0)
  1401. {
  1402. }
  1403. /*!
  1404. Constructs a copy of \a other.
  1405. */
  1406. QInputMethodEvent::QInputMethodEvent(const QInputMethodEvent &other)
  1407. : QEvent(QEvent::InputMethod), preedit(other.preedit), attrs(other.attrs),
  1408. commit(other.commit), replace_from(other.replace_from), replace_length(other.replace_length)
  1409. {
  1410. }
  1411. /*!
  1412. Sets the commit string to \a commitString.
  1413. The commit string is the text that should get added to (or
  1414. replace parts of) the text of the editor widget. It usually is a
  1415. result of the input operations and has to be inserted to the
  1416. widgets text directly before the preedit string.
  1417. If the commit string should replace parts of the of the text in
  1418. the editor, \a replaceLength specifies the number of
  1419. characters to be replaced. \a replaceFrom specifies the position
  1420. at which characters are to be replaced relative from the start of
  1421. the preedit string.
  1422. \sa commitString(), replacementStart(), replacementLength()
  1423. */
  1424. void QInputMethodEvent::setCommitString(const QString &commitString, int replaceFrom, int replaceLength)
  1425. {
  1426. commit = commitString;
  1427. replace_from = replaceFrom;
  1428. replace_length = replaceLength;
  1429. }
  1430. /*!
  1431. \fn const QList<Attribute> &QInputMethodEvent::attributes() const
  1432. Returns the list of attributes passed to the QInputMethodEvent
  1433. constructor. The attributes control the visual appearance of the
  1434. preedit string (the visual appearance of text outside the preedit
  1435. string is controlled by the widget only).
  1436. \sa preeditString(), Attribute
  1437. */
  1438. /*!
  1439. \fn const QString &QInputMethodEvent::preeditString() const
  1440. Returns the preedit text, i.e. the text before the user started
  1441. editing it.
  1442. \sa commitString(), attributes()
  1443. */
  1444. /*!
  1445. \fn const QString &QInputMethodEvent::commitString() const
  1446. Returns the text that should get added to (or replace parts of)
  1447. the text of the editor widget. It usually is a result of the
  1448. input operations and has to be inserted to the widgets text
  1449. directly before the preedit string.
  1450. \sa setCommitString(), preeditString(), replacementStart(), replacementLength()
  1451. */
  1452. /*!
  1453. \fn int QInputMethodEvent::replacementStart() const
  1454. Returns the position at which characters are to be replaced relative
  1455. from the start of the preedit string.
  1456. \sa replacementLength(), setCommitString()
  1457. */
  1458. /*!
  1459. \fn int QInputMethodEvent::replacementLength() const
  1460. Returns the number of characters to be replaced in the preedit
  1461. string.
  1462. \sa replacementStart(), setCommitString()
  1463. */
  1464. #ifndef QT_NO_TABLETEVENT
  1465. /*!
  1466. \class QTabletEvent
  1467. \brief The QTabletEvent class contains parameters that describe a Tablet event.
  1468. \ingroup events
  1469. Tablet Events are generated from a Wacom tablet. Most of the time you will
  1470. want to deal with events from the tablet as if they were events from a
  1471. mouse; for example, you would retrieve the cursor position with x(), y(),
  1472. pos(), globalX(), globalY(), and globalPos(). In some situations you may
  1473. wish to retrieve the extra information provided by the tablet device
  1474. driver; for example, you might want to do subpixeling with higher
  1475. resolution coordinates or you may want to adjust color brightness based on
  1476. pressure. QTabletEvent allows you to read the pressure(), the xTilt(), and
  1477. yTilt(), as well as the type of device being used with device() (see
  1478. \l{TabletDevice}). It can also give you the minimum and maximum values for
  1479. each device's pressure and high resolution coordinates.
  1480. A tablet event contains a special accept flag that indicates whether the
  1481. receiver wants the event. You should call QTabletEvent::accept() if you
  1482. handle the tablet event; otherwise it will be sent to the parent widget.
  1483. The exception are TabletEnterProximity and TabletLeaveProximity events,
  1484. these are only sent to QApplication and don't check whether or not they are
  1485. accepted.
  1486. The QWidget::setEnabled() function can be used to enable or
  1487. disable mouse and keyboard events for a widget.
  1488. The event handler QWidget::tabletEvent() receives all three types of
  1489. tablet events. Qt will first send a tabletEvent then, if it is not
  1490. accepted, it will send a mouse event. This allows applications that
  1491. don't utilize tablets to use a tablet like a mouse, while also
  1492. enabling those who want to use both tablets and mouses differently.
  1493. \section1 Notes for X11 Users
  1494. Qt uses the following hard-coded names to identify tablet
  1495. devices from the xorg.conf file on X11 (apart from IRIX):
  1496. 'stylus', 'pen', and 'eraser'. If the devices have other names,
  1497. they will not be picked up Qt.
  1498. */
  1499. /*!
  1500. \enum QTabletEvent::TabletDevice
  1501. This enum defines what type of device is generating the event.
  1502. \value NoDevice No device, or an unknown device.
  1503. \value Puck A Puck (a device that is similar to a flat mouse with
  1504. a transparent circle with cross-hairs).
  1505. \value Stylus A Stylus.
  1506. \value Airbrush An airbrush
  1507. \value FourDMouse A 4D Mouse.
  1508. \value RotationStylus A special stylus that also knows about rotation
  1509. (a 6D stylus). \since 4.1
  1510. \omitvalue XFreeEraser
  1511. */
  1512. /*!
  1513. \enum QTabletEvent::PointerType
  1514. This enum defines what type of point is generating the event.
  1515. \value UnknownPointer An unknown device.
  1516. \value Pen Tip end of a stylus-like device (the narrow end of the pen).
  1517. \value Cursor Any puck-like device.
  1518. \value Eraser Eraser end of a stylus-like device (the broad end of the pen).
  1519. \sa pointerType()
  1520. */
  1521. /*!
  1522. Construct a tablet event of the given \a type.
  1523. The \a pos parameter indicates where the event occurred in the
  1524. widget; \a globalPos is the corresponding position in absolute
  1525. coordinates. The \a hiResGlobalPos contains a high resolution
  1526. measurement of the position.
  1527. \a pressure contains the pressure exerted on the \a device.
  1528. \a pointerType describes the type of pen that is being used.
  1529. \a xTilt and \a yTilt contain the device's degree of tilt from the
  1530. x and y axes respectively.
  1531. \a keyState specifies which keyboard modifiers are pressed (e.g.,
  1532. \key{Ctrl}).
  1533. The \a uniqueID parameter contains the unique ID for the current device.
  1534. The \a z parameter contains the coordinate of the device on the tablet, this
  1535. is usually given by a wheel on 4D mouse. If the device does not support a
  1536. Z-axis, pass zero here.
  1537. The \a tangentialPressure parameter contins the tangential pressure of an air
  1538. brush. If the device does not support tangential pressure, pass 0 here.
  1539. \a rotation contains the device's rotation in degrees. 4D mice support
  1540. rotation. If the device does not support rotation, pass 0 here.
  1541. \sa pos() globalPos() device() pressure() xTilt() yTilt() uniqueId(), rotation(), tangentialPressure(), z()
  1542. */
  1543. QTabletEvent::QTabletEvent(Type type, const QPoint &pos, const QPoint &globalPos,
  1544. const QPointF &hiResGlobalPos, int device, int pointerType,
  1545. qreal pressure, int xTilt, int yTilt, qreal tangentialPressure,
  1546. qreal rotation, int z, Qt::KeyboardModifiers keyState, qint64 uniqueID)
  1547. : QInputEvent(type, keyState),
  1548. mPos(pos),
  1549. mGPos(globalPos),
  1550. mHiResGlobalPos(hiResGlobalPos),
  1551. mDev(device),
  1552. mPointerType(pointerType),
  1553. mXT(xTilt),
  1554. mYT(yTilt),
  1555. mZ(z),
  1556. mPress(pressure),
  1557. mTangential(tangentialPressure),
  1558. mRot(rotation),
  1559. mUnique(uniqueID),
  1560. mExtra(0)
  1561. {
  1562. }
  1563. /*!
  1564. \internal
  1565. */
  1566. QTabletEvent::~QTabletEvent()
  1567. {
  1568. }
  1569. /*!
  1570. \fn TabletDevices QTabletEvent::device() const
  1571. Returns the type of device that generated the event.
  1572. \sa TabletDevice
  1573. */
  1574. /*!
  1575. \fn PointerType QTabletEvent::pointerType() const
  1576. Returns the type of point that generated the event.
  1577. */
  1578. /*!
  1579. \fn qreal QTabletEvent::tangentialPressure() const
  1580. Returns the tangential pressure for the device. This is typically given by a finger
  1581. wheel on an airbrush tool. The range is from -1.0 to 1.0. 0.0 indicates a
  1582. neutral position. Current airbrushes can only move in the positive
  1583. direction from the neutrual position. If the device does not support
  1584. tangential pressure, this value is always 0.0.
  1585. \sa pressure()
  1586. */
  1587. /*!
  1588. \fn qreal QTabletEvent::rotation() const
  1589. Returns the rotation of the current device in degress. This is usually
  1590. given by a 4D Mouse. If the device doesn't support rotation this value is
  1591. always 0.0.
  1592. */
  1593. /*!
  1594. \fn qreal QTabletEvent::pressure() const
  1595. Returns the pressure for the device. 0.0 indicates that the stylus is not
  1596. on the tablet, 1.0 indicates the maximum amount of pressure for the stylus.
  1597. \sa tangentialPressure()
  1598. */
  1599. /*!
  1600. \fn int QTabletEvent::xTilt() const
  1601. Returns the angle between the device (a pen, for example) and the
  1602. perpendicular in the direction of the x axis.
  1603. Positive values are towards the tablet's physical right. The angle
  1604. is in the range -60 to +60 degrees.
  1605. \img qtabletevent-tilt.png
  1606. \sa yTilt()
  1607. */
  1608. /*!
  1609. \fn int QTabletEvent::yTilt() const
  1610. Returns the angle between the device (a pen, for example) and the
  1611. perpendicular in the direction of the y axis.
  1612. Positive values are towards the bottom of the tablet. The angle is
  1613. within the range -60 to +60 degrees.
  1614. \sa xTilt()
  1615. */
  1616. /*!
  1617. \fn const QPoint &QTabletEvent::pos() const
  1618. Returns the position of the device, relative to the widget that
  1619. received the event.
  1620. If you move widgets around in response to mouse events, use
  1621. globalPos() instead of this function.
  1622. \sa x() y() globalPos()
  1623. */
  1624. /*!
  1625. \fn int QTabletEvent::x() const
  1626. Returns the x position of the device, relative to the widget that
  1627. received the event.
  1628. \sa y() pos()
  1629. */
  1630. /*!
  1631. \fn int QTabletEvent::y() const
  1632. Returns the y position of the device, relative to the widget that
  1633. received the event.
  1634. \sa x() pos()
  1635. */
  1636. /*!
  1637. \fn int QTabletEvent::z() const
  1638. Returns the z position of the device. Typically this is represented by a
  1639. wheel on a 4D Mouse. If the device does not support a Z-axis, this value is
  1640. always zero. This is \bold not the same as pressure.
  1641. \sa pressure()
  1642. */
  1643. /*!
  1644. \fn const QPoint &QTabletEvent::globalPos() const
  1645. Returns the global position of the device \e{at the time of the
  1646. event}. This is important on asynchronous windows systems like X11;
  1647. whenever you move your widgets around in response to mouse events,
  1648. globalPos() can differ significantly from the current position
  1649. QCursor::pos().
  1650. \sa globalX() globalY() hiResGlobalPos()
  1651. */
  1652. /*!
  1653. \fn int QTabletEvent::globalX() const
  1654. Returns the global x position of the mouse pointer at the time of
  1655. the event.
  1656. \sa globalY() globalPos() hiResGlobalX()
  1657. */
  1658. /*!
  1659. \fn int QTabletEvent::globalY() const
  1660. Returns the global y position of the tablet device at the time of
  1661. the event.
  1662. \sa globalX() globalPos() hiResGlobalY()
  1663. */
  1664. /*!
  1665. \fn qint64 QTabletEvent::uniqueId() const
  1666. Returns a unique ID for the current device, making it possible
  1667. to differentiate between multiple devices being used at the same
  1668. time on the tablet.
  1669. Support of this feature is dependent on the tablet.
  1670. Values for the same device may vary from OS to OS.
  1671. Later versions of the Wacom driver for Linux will now report
  1672. the ID information. If you have a tablet that supports unique ID
  1673. and are not getting the information on Linux, consider upgrading
  1674. your driver.
  1675. As of Qt 4.2, the unique ID is the same regardless of the orientation
  1676. of the pen. Earlier versions would report a different value when using
  1677. the eraser-end versus the pen-end of the stylus on some OS's.
  1678. \sa pointerType()
  1679. */
  1680. /*!
  1681. \fn const QPointF &QTabletEvent::hiResGlobalPos() const
  1682. The high precision coordinates delivered from the tablet expressed.
  1683. Sub pixeling information is in the fractional part of the QPointF.
  1684. \sa globalPos() hiResGlobalX() hiResGlobalY()
  1685. */
  1686. /*!
  1687. \fn qreal &QTabletEvent::hiResGlobalX() const
  1688. The high precision x position of the tablet device.
  1689. */
  1690. /*!
  1691. \fn qreal &QTabletEvent::hiResGlobalY() const
  1692. The high precision y position of the tablet device.
  1693. */
  1694. #endif // QT_NO_TABLETEVENT
  1695. #ifndef QT_NO_DRAGANDDROP
  1696. /*!
  1697. Creates a QDragMoveEvent of the required \a type indicating
  1698. that the mouse is at position \a pos given within a widget.
  1699. The mouse and keyboard states are specified by \a buttons and
  1700. \a modifiers, and the \a actions describe the types of drag
  1701. and drop operation that are possible.
  1702. The drag data is passed as MIME-encoded information in \a data.
  1703. \warning Do not attempt to create a QDragMoveEvent yourself.
  1704. These objects rely on Qt's internal state.
  1705. */
  1706. QDragMoveEvent::QDragMoveEvent(const QPoint& pos, Qt::DropActions actions, const QMimeData *data,
  1707. Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Type type)
  1708. : QDropEvent(pos, actions, data, buttons, modifiers, type)
  1709. , rect(pos, QSize(1, 1))
  1710. {}
  1711. /*!
  1712. Destroys the event.
  1713. */
  1714. QDragMoveEvent::~QDragMoveEvent()
  1715. {
  1716. }
  1717. /*!
  1718. \fn void QDragMoveEvent::accept(bool y)
  1719. Calls setAccepted(\a y) instead.
  1720. */
  1721. /*!
  1722. \fn void QDragMoveEvent::accept(const QRect &rectangle)
  1723. The same as accept(), but also notifies that future moves will
  1724. also be acceptable if they remain within the \a rectangle
  1725. given on the widget. This can improve performance, but may
  1726. also be ignored by the underlying system.
  1727. If the rectangle is empty, drag move events will be sent
  1728. continuously. This is useful if the source is scrolling in a
  1729. timer event.
  1730. */
  1731. /*!
  1732. \fn void QDragMoveEvent::accept()
  1733. \overload
  1734. Calls QDropEvent::accept().
  1735. */
  1736. /*!
  1737. \fn void QDragMoveEvent::ignore()
  1738. \overload
  1739. Calls QDropEvent::ignore().
  1740. */
  1741. /*!
  1742. \fn void QDragMoveEvent::ignore(const QRect &rectangle)
  1743. The opposite of the accept(const QRect&) function.
  1744. Moves within the \a rectangle are not acceptable, and will be
  1745. ignored.
  1746. */
  1747. /*!
  1748. \fn QRect QDragMoveEvent::answerRect() const
  1749. Returns the rectangle in the widget where the drop will occur if accepted.
  1750. You can use this information to restrict drops to certain places on the
  1751. widget.
  1752. */
  1753. /*!
  1754. \class QDropEvent
  1755. \ingroup events
  1756. \ingroup draganddrop
  1757. \brief The QDropEvent class provides an event which is sent when a
  1758. drag and drop action is completed.
  1759. When a widget \l{QWidget::setAcceptDrops()}{accepts drop events}, it will
  1760. receive this event if it has accepted the most recent QDragEnterEvent or
  1761. QDragMoveEvent sent to it.
  1762. The drop event contains a proposed action, available from proposedAction(), for
  1763. the widget to either accept or ignore. If the action can be handled by the
  1764. widget, you should call the acceptProposedAction() function. Since the
  1765. proposed action can be a combination of \l Qt::DropAction values, it may be
  1766. useful to either select one of these values as a default action or ask
  1767. the user to select their preferred action.
  1768. If the proposed drop action is not suitable, perhaps because your custom
  1769. widget does not support that action, you can replace it with any of the
  1770. \l{possibleActions()}{possible drop actions} by calling setDropAction()
  1771. with your preferred action. If you set a value that is not present in the
  1772. bitwise OR combination of values returned by possibleActions(), the default
  1773. copy action will be used. Once a replacement drop action has been set, call
  1774. accept() instead of acceptProposedAction() to complete the drop operation.
  1775. The mimeData() function provides the data dropped on the widget in a QMimeData
  1776. object. This contains information about the MIME type of the data in addition to
  1777. the data itself.
  1778. \sa QMimeData, QDrag, {Drag and Drop}
  1779. */
  1780. /*!
  1781. \fn const QMimeData *QDropEvent::mimeData() const
  1782. Returns the data that was dropped on the widget and its associated MIME
  1783. type information.
  1784. */
  1785. /*!
  1786. Constructs a drop event of a certain \a type corresponding to a
  1787. drop at the point specified by \a pos in the destination widget's
  1788. coordinate system.
  1789. The \a actions indicate which types of drag and drop operation can
  1790. be performed, and the drag data is stored as MIME-encoded data in \a data.
  1791. The states of the mouse buttons and keyboard modifiers at the time of
  1792. the drop are specified by \a buttons and \a modifiers.
  1793. */ // ### pos is in which coordinate system?
  1794. QDropEvent::QDropEvent(const QPoint& pos, Qt::DropActions actions, const QMimeData *data,
  1795. Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Type type)
  1796. : QEvent(type), p(pos), mouseState(buttons),
  1797. modState(modifiers), act(actions),
  1798. mdata(data)
  1799. {
  1800. default_action = QDragManager::self()->defaultAction(act, modifiers);
  1801. drop_action = default_action;
  1802. ignore();
  1803. }
  1804. /*! \internal */
  1805. QDropEvent::~QDropEvent()
  1806. {
  1807. }
  1808. /*!
  1809. \compat
  1810. Returns a byte array containing the drag's data, in \a format.
  1811. data() normally needs to get the data from the drag source, which
  1812. is potentially very slow, so it's advisable to call this function
  1813. only if you're sure that you will need the data in that
  1814. particular \a format.
  1815. The resulting data will have a size of 0 if the format was not
  1816. available.
  1817. \sa format() QByteArray::size()
  1818. */
  1819. QByteArray QDropEvent::encodedData(const char *format) const
  1820. {
  1821. return mdata->data(QLatin1String(format));
  1822. }
  1823. /*!
  1824. \compat
  1825. Returns a string describing one of the available data types for
  1826. this drag. Common examples are "text/plain" and "image/gif".
  1827. If \a n is less than zero or greater than the number of available
  1828. data types, format() returns 0.
  1829. This function is provided mainly for debugging. Most drop targets
  1830. will use provides().
  1831. \sa data() provides()
  1832. */
  1833. const char* QDropEvent::format(int n) const
  1834. {
  1835. if (fmts.isEmpty()) {
  1836. QStringList formats = mdata->formats();
  1837. for (int i = 0; i < formats.size(); ++i)
  1838. fmts.append(formats.at(i).toLatin1());
  1839. }
  1840. if (n < 0 || n >= fmts.size())
  1841. return 0;
  1842. return fmts.at(n).constData();
  1843. }
  1844. /*!
  1845. \compat
  1846. Returns true if this event provides format \a mimeType; otherwise
  1847. returns false.
  1848. \sa data()
  1849. */
  1850. bool QDropEvent::provides(const char *mimeType) const
  1851. {
  1852. return mdata->formats().contains(QLatin1String(mimeType));
  1853. }
  1854. /*!
  1855. If the source of the drag operation is a widget in this
  1856. application, this function returns that source; otherwise it
  1857. returns 0. The source of the operation is the first parameter to
  1858. the QDrag object used instantiate the drag.
  1859. This is useful if your widget needs special behavior when dragging
  1860. to itself.
  1861. \sa QDrag::QDrag()
  1862. */
  1863. QWidget* QDropEvent::source() const
  1864. {
  1865. QDragManager *manager = QDragManager::self();
  1866. return manager ? manager->source() : 0;
  1867. }
  1868. void QDropEvent::setDropAction(Qt::DropAction action)
  1869. {
  1870. if (!(action & act) && action != Qt::IgnoreAction)
  1871. action = default_action;
  1872. drop_action = action;
  1873. }
  1874. /*!
  1875. \fn const QPoint& QDropEvent::pos() const
  1876. Returns the position where the drop was made.
  1877. */
  1878. /*!
  1879. \fn Qt::MouseButtons QDropEvent::mouseButtons() const
  1880. Returns the mouse buttons that are pressed..
  1881. */
  1882. /*!
  1883. \fn Qt::KeyboardModifiers QDropEvent::keyboardModifiers() const
  1884. Returns the modifier keys that are pressed.
  1885. */
  1886. /*!
  1887. \fn void QDropEvent::accept()
  1888. \internal
  1889. */
  1890. /*!
  1891. \fn void QDropEvent::accept(bool accept)
  1892. Call setAccepted(\a accept) instead.
  1893. */
  1894. /*!
  1895. \fn void QDropEvent::acceptAction(bool accept = true)
  1896. Call this to indicate that the action described by action() is
  1897. accepted (i.e. if \a accept is true, which is the default), not merely
  1898. the default copy action. If you call acceptAction(true), there is
  1899. no need to also call accept(true).
  1900. */
  1901. /*!
  1902. \enum QDropEvent::Action
  1903. \compat
  1904. When a drag and drop action is completed, the target is expected
  1905. to perform an action on the data provided by the source. This
  1906. will be one of the following:
  1907. \value Copy The default action. The source simply uses the data
  1908. provided in the operation.
  1909. \value Link The source should somehow create a link to the
  1910. location specified by the data.
  1911. \value Move The source should somehow move the object from the
  1912. location specified by the data to a new location.
  1913. \value Private The target has special knowledge of the MIME type,
  1914. which the source should respond to in a similar way to
  1915. a Copy.
  1916. \value UserAction The source and target can co-operate using
  1917. special actions. This feature is not currently
  1918. supported.
  1919. The Link and Move actions only makes sense if the data is a
  1920. reference, for example, text/uri-list file lists (see QUriDrag).
  1921. */
  1922. /*!
  1923. \fn void QDropEvent::setDropAction(Qt::DropAction action)
  1924. Sets the \a action to be performed on the data by the target.
  1925. Use this to override the \l{proposedAction()}{proposed action}
  1926. with one of the \l{possibleActions()}{possible actions}.
  1927. If you set a drop action that is not one of the possible actions, the
  1928. drag and drop operation will default to a copy operation.
  1929. Once you have supplied a replacement drop action, call accept()
  1930. instead of acceptProposedAction().
  1931. \sa dropAction()
  1932. */
  1933. /*!
  1934. \fn Qt::DropAction QDropEvent::dropAction() const
  1935. Returns the action to be performed on the data by the target. This may be
  1936. different from the action supplied in proposedAction() if you have called
  1937. setDropAction() to explicitly choose a drop action.
  1938. \sa setDropAction()
  1939. */
  1940. /*!
  1941. \fn Qt::DropActions QDropEvent::possibleActions() const
  1942. Returns an OR-combination of possible drop actions.
  1943. \sa dropAction()
  1944. */
  1945. /*!
  1946. \fn Qt::DropAction QDropEvent::proposedAction() const
  1947. Returns the proposed drop action.
  1948. \sa dropAction()
  1949. */
  1950. /*!
  1951. \fn void QDropEvent::acceptProposedAction()
  1952. Sets the drop action to be the proposed action.
  1953. \sa setDropAction(), proposedAction(), {QEvent::accept()}{accept()}
  1954. */
  1955. #ifdef QT3_SUPPORT
  1956. /*!
  1957. Use dropAction() instead.
  1958. The table below shows the correspondance between the return type
  1959. of action() and the return type of dropAction().
  1960. \table
  1961. \header \i Old enum value \i New enum value
  1962. \row \i QDropEvent::Copy \i Qt::CopyAction
  1963. \row \i QDropEvent::Move \i Qt::MoveAction
  1964. \row \i QDropEvent::Link \i Qt::LinkAction
  1965. \row \i other \i Qt::CopyAction
  1966. \endtable
  1967. */
  1968. QT3_SUPPORT QDropEvent::Action QDropEvent::action() const
  1969. {
  1970. switch(drop_action) {
  1971. case Qt::CopyAction:
  1972. return Copy;
  1973. case Qt::MoveAction:
  1974. return Move;
  1975. case Qt::LinkAction:
  1976. return Link;
  1977. default:
  1978. return Copy;
  1979. }
  1980. }
  1981. #endif
  1982. /*!
  1983. \fn void QDropEvent::setPoint(const QPoint &point)
  1984. \compat
  1985. Sets the drop to happen at the given \a point. You do not normally
  1986. need to use this as it will be set internally before your widget
  1987. receives the drop event.
  1988. */ // ### here too - what coordinate system?
  1989. /*!
  1990. \class QDragEnterEvent
  1991. \brief The QDragEnterEvent class provides an event which is sent
  1992. to a widget when a drag and drop action enters it.
  1993. \ingroup events
  1994. \ingroup draganddrop
  1995. A widget must accept this event in order to receive the \l
  1996. {QDragMoveEvent}{drag move events} that are sent while the drag
  1997. and drop action is in progress. The drag enter event is always
  1998. immediately followed by a drag move event.
  1999. QDragEnterEvent inherits most of its functionality from
  2000. QDragMoveEvent, which in turn inherits most of its functionality
  2001. from QDropEvent.
  2002. \sa QDragLeaveEvent, QDragMoveEvent, QDropEvent
  2003. */
  2004. /*!
  2005. Constructs a QDragEnterEvent that represents a drag entering a
  2006. widget at the given \a point with mouse and keyboard states specified by
  2007. \a buttons and \a modifiers.
  2008. The drag data is passed as MIME-encoded information in \a data, and the
  2009. specified \a actions describe the possible types of drag and drop
  2010. operation that can be performed.
  2011. \warning Do not create a QDragEnterEvent yourself since these
  2012. objects rely on Qt's internal state.
  2013. */
  2014. QDragEnterEvent::QDragEnterEvent(const QPoint& point, Qt::DropActions actions, const QMimeData *data,
  2015. Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
  2016. : QDragMoveEvent(point, actions, data, buttons, modifiers, DragEnter)
  2017. {}
  2018. /*! \internal
  2019. */
  2020. QDragEnterEvent::~QDragEnterEvent()
  2021. {
  2022. }
  2023. /*!
  2024. Constructs a drag response event containing the \a accepted value,
  2025. indicating whether the drag and drop operation was accepted by the
  2026. recipient.
  2027. */
  2028. QDragResponseEvent::QDragResponseEvent(bool accepted)
  2029. : QEvent(DragResponse), a(accepted)
  2030. {}
  2031. /*! \internal
  2032. */
  2033. QDragResponseEvent::~QDragResponseEvent()
  2034. {
  2035. }
  2036. /*!
  2037. \class QDragMoveEvent
  2038. \brief The QDragMoveEvent class provides an event which is sent while a drag and drop action is in progress.
  2039. \ingroup events
  2040. \ingroup draganddrop
  2041. A widget will receive drag move events repeatedly while the drag
  2042. is within its boundaries, if it accepts
  2043. \l{QWidget::setAcceptDrops()}{drop events} and \l
  2044. {QWidget::dragEnterEvent()}{enter events}. The widget should
  2045. examine the event to see what kind of data it
  2046. \l{QDragMoveEvent::provides()}{provides}, and call the accept()
  2047. function to accept the drop if appropriate.
  2048. The rectangle supplied by the answerRect() function can be used to restrict
  2049. drops to certain parts of the widget. For example, we can check whether the
  2050. rectangle intersects with the geometry of a certain child widget and only
  2051. call \l{QDropEvent::acceptProposedAction()}{acceptProposedAction()} if that
  2052. is the case.
  2053. Note that this class inherits most of its functionality from
  2054. QDropEvent.
  2055. \sa QDragEnterEvent, QDragLeaveEvent, QDropEvent
  2056. */
  2057. /*!
  2058. \class QDragLeaveEvent
  2059. \brief The QDragLeaveEvent class provides an event that is sent to a widget when a drag and drop action leaves it.
  2060. \ingroup events
  2061. \ingroup draganddrop
  2062. This event is always preceded by a QDragEnterEvent and a series
  2063. of \l{QDragMoveEvent}s. It is not sent if a QDropEvent is sent
  2064. instead.
  2065. \sa QDragEnterEvent, QDragMoveEvent, QDropEvent
  2066. */
  2067. /*!
  2068. Constructs a QDragLeaveEvent.
  2069. \warning Do not create a QDragLeaveEvent yourself since these
  2070. objects rely on Qt's internal state.
  2071. */
  2072. QDragLeaveEvent::QDragLeaveEvent()
  2073. : QEvent(DragLeave)
  2074. {}
  2075. /*! \internal
  2076. */
  2077. QDragLeaveEvent::~QDragLeaveEvent()
  2078. {
  2079. }
  2080. #endif // QT_NO_DRAGANDDROP
  2081. /*!
  2082. \class QHelpEvent
  2083. \brief The QHelpEvent class provides an event that is used to request helpful information
  2084. about a particular point in a widget.
  2085. \ingroup events
  2086. \ingroup helpsystem
  2087. This event can be intercepted in applications to provide tooltips
  2088. or "What's This?" help for custom widgets. The type() can be
  2089. either QEvent::ToolTip or QEvent::WhatsThis.
  2090. \sa QToolTip, QWhatsThis, QStatusTipEvent, QWhatsThisClickedEvent
  2091. */
  2092. /*!
  2093. Constructs a help event with the given \a type corresponding to the
  2094. widget-relative position specified by \a pos and the global position
  2095. specified by \a globalPos.
  2096. \a type must be either QEvent::ToolTip or QEvent::WhatsThis.
  2097. \sa pos(), globalPos()
  2098. */
  2099. QHelpEvent::QHelpEvent(Type type, const QPoint &pos, const QPoint &globalPos)
  2100. : QEvent(type), p(pos), gp(globalPos)
  2101. {}
  2102. /*!
  2103. \fn int QHelpEvent::x() const
  2104. Same as pos().x().
  2105. \sa y(), pos(), globalPos()
  2106. */
  2107. /*!
  2108. \fn int QHelpEvent::y() const
  2109. Same as pos().y().
  2110. \sa x(), pos(), globalPos()
  2111. */
  2112. /*!
  2113. \fn int QHelpEvent::globalX() const
  2114. Same as globalPos().x().
  2115. \sa x(), globalY(), globalPos()
  2116. */
  2117. /*!
  2118. \fn int QHelpEvent::globalY() const
  2119. Same as globalPos().y().
  2120. \sa y(), globalX(), globalPos()
  2121. */
  2122. /*!
  2123. \fn const QPoint &QHelpEvent::pos() const
  2124. Returns the mouse cursor position when the event was generated,
  2125. relative to the widget to which the event is dispatched.
  2126. \sa globalPos(), x(), y()
  2127. */
  2128. /*!
  2129. \fn const QPoint &QHelpEvent::globalPos() const
  2130. Returns the mouse cursor position when the event was generated
  2131. in global coordinates.
  2132. \sa pos(), globalX(), globalY()
  2133. */
  2134. /*! \internal
  2135. */
  2136. QHelpEvent::~QHelpEvent()
  2137. {
  2138. }
  2139. #ifndef QT_NO_STATUSTIP
  2140. /*!
  2141. \class QStatusTipEvent
  2142. \brief The QStatusTipEvent class provides an event that is used to show messages in a status bar.
  2143. \ingroup events
  2144. \ingroup helpsystem
  2145. Status tips can be set on a widget using the
  2146. QWidget::setStatusTip() function. They are shown in the status
  2147. bar when the mouse cursor enters the widget. For example:
  2148. \table 100%
  2149. \row
  2150. \o
  2151. \snippet doc/src/snippets/qstatustipevent/main.cpp 1
  2152. \dots
  2153. \snippet doc/src/snippets/qstatustipevent/main.cpp 3
  2154. \o
  2155. \image qstatustipevent-widget.png Widget with status tip.
  2156. \endtable
  2157. Status tips can also be set on actions using the
  2158. QAction::setStatusTip() function:
  2159. \table 100%
  2160. \row
  2161. \o
  2162. \snippet doc/src/snippets/qstatustipevent/main.cpp 0
  2163. \snippet doc/src/snippets/qstatustipevent/main.cpp 2
  2164. \dots
  2165. \snippet doc/src/snippets/qstatustipevent/main.cpp 3
  2166. \o
  2167. \image qstatustipevent-action.png Action with status tip.
  2168. \endtable
  2169. Finally, status tips are supported for the item view classes
  2170. through the Qt::StatusTipRole enum value.
  2171. \sa QStatusBar, QHelpEvent, QWhatsThisClickedEvent
  2172. */
  2173. /*!
  2174. Constructs a status tip event with the text specified by \a tip.
  2175. \sa tip()
  2176. */
  2177. QStatusTipEvent::QStatusTipEvent(const QString &tip)
  2178. : QEvent(StatusTip), s(tip)
  2179. {}
  2180. /*! \internal
  2181. */
  2182. QStatusTipEvent::~QStatusTipEvent()
  2183. {
  2184. }
  2185. /*!
  2186. \fn QString QStatusTipEvent::tip() const
  2187. Returns the message to show in the status bar.
  2188. \sa QStatusBar::showMessage()
  2189. */
  2190. #endif // QT_NO_STATUSTIP
  2191. #ifndef QT_NO_WHATSTHIS
  2192. /*!
  2193. \class QWhatsThisClickedEvent
  2194. \brief The QWhatsThisClickedEvent class provides an event that
  2195. can be used to handle hyperlinks in a "What's This?" text.
  2196. \ingroup events
  2197. \ingroup helpsystem
  2198. \sa QWhatsThis, QHelpEvent, QStatusTipEvent
  2199. */
  2200. /*!
  2201. Constructs an event containing a URL specified by \a href when a link
  2202. is clicked in a "What's This?" message.
  2203. \sa href()
  2204. */
  2205. QWhatsThisClickedEvent::QWhatsThisClickedEvent(const QString &href)
  2206. : QEvent(WhatsThisClicked), s(href)
  2207. {}
  2208. /*! \internal
  2209. */
  2210. QWhatsThisClickedEvent::~QWhatsThisClickedEvent()
  2211. {
  2212. }
  2213. /*!
  2214. \fn QString QWhatsThisClickedEvent::href() const
  2215. Returns the URL that was clicked by the user in the "What's
  2216. This?" text.
  2217. */
  2218. #endif // QT_NO_WHATSTHIS
  2219. #ifndef QT_NO_ACTION
  2220. /*!
  2221. \class QActionEvent
  2222. \brief The QActionEvent class provides an event that is generated
  2223. when a QAction is added, removed, or changed.
  2224. \ingroup events
  2225. Actions can be added to widgets using QWidget::addAction(). This
  2226. generates an \l ActionAdded event, which you can handle to provide
  2227. custom behavior. For example, QToolBar reimplements
  2228. QWidget::actionEvent() to create \l{QToolButton}s for the
  2229. actions.
  2230. \sa QAction, QWidget::addAction(), QWidget::removeAction(), QWidget::actions()
  2231. */
  2232. /*!
  2233. Constructs an action event. The \a type can be \l ActionChanged,
  2234. \l ActionAdded, or \l ActionRemoved.
  2235. \a action is the action that is changed, added, or removed. If \a
  2236. type is ActionAdded, the action is to be inserted before the
  2237. action \a before. If \a before is 0, the action is appended.
  2238. */
  2239. QActionEvent::QActionEvent(int type, QAction *action, QAction *before)
  2240. : QEvent(static_cast<QEvent::Type>(type)), act(action), bef(before)
  2241. {}
  2242. /*! \internal
  2243. */
  2244. QActionEvent::~QActionEvent()
  2245. {
  2246. }
  2247. /*!
  2248. \fn QAction *QActionEvent::action() const
  2249. Returns the action that is changed, added, or removed.
  2250. \sa before()
  2251. */
  2252. /*!
  2253. \fn QAction *QActionEvent::before() const
  2254. If type() is \l ActionAdded, returns the action that should
  2255. appear before action(). If this function returns 0, the action
  2256. should be appended to already existing actions on the same
  2257. widget.
  2258. \sa action(), QWidget::actions()
  2259. */
  2260. #endif // QT_NO_ACTION
  2261. /*!
  2262. \class QHideEvent
  2263. \brief The QHideEvent class provides an event which is sent after a widget is hidden.
  2264. \ingroup events
  2265. This event is sent just before QWidget::hide() returns, and also
  2266. when a top-level window has been hidden (iconified) by the user.
  2267. If spontaneous() is true, the event originated outside the
  2268. application. In this case, the user hid the window using the
  2269. window manager controls, either by iconifying the window or by
  2270. switching to another virtual desktop where the window isn't
  2271. visible. The window will become hidden but not withdrawn. If the
  2272. window was iconified, QWidget::isMinimized() returns true.
  2273. \sa QShowEvent
  2274. */
  2275. /*!
  2276. Constructs a QHideEvent.
  2277. */
  2278. QHideEvent::QHideEvent()
  2279. : QEvent(Hide)
  2280. {}
  2281. /*! \internal
  2282. */
  2283. QHideEvent::~QHideEvent()
  2284. {
  2285. }
  2286. /*!
  2287. \class QShowEvent
  2288. \brief The QShowEvent class provides an event that is sent when a widget is shown.
  2289. \ingroup events
  2290. There are two kinds of show events: show events caused by the
  2291. window system (spontaneous), and internal show events. Spontaneous (QEvent::spontaneous())
  2292. show events are sent just after the window system shows the
  2293. window; they are also sent when a top-level window is redisplayed
  2294. after being iconified. Internal show events are delivered just
  2295. before the widget becomes visible.
  2296. \sa QHideEvent
  2297. */
  2298. /*!
  2299. Constructs a QShowEvent.
  2300. */
  2301. QShowEvent::QShowEvent()
  2302. : QEvent(Show)
  2303. {}
  2304. /*! \internal
  2305. */
  2306. QShowEvent::~QShowEvent()
  2307. {
  2308. }
  2309. /*!
  2310. \fn QByteArray QDropEvent::data(const char* f) const
  2311. \obsolete
  2312. The encoded data is in \a f.
  2313. Use QDropEvent::encodedData().
  2314. */
  2315. /*!
  2316. \class QFileOpenEvent
  2317. \brief The QFileOpenEvent class provides an event that will be
  2318. sent when there is a request to open a file or a URL.
  2319. \ingroup events
  2320. File open events will be sent to the QApplication::instance()
  2321. when the operating system requests that a file or URL should be opened.
  2322. This is a high-level event that can be caused by different user actions
  2323. depending on the user's desktop environment; for example, double
  2324. clicking on an file icon in the Finder on Mac OS X.
  2325. This event is only used to notify the application of a request.
  2326. It may be safely ignored.
  2327. \note This class is currently supported for Mac OS X and Symbian only.
  2328. */
  2329. QFileOpenEventPrivate::~QFileOpenEventPrivate()
  2330. {
  2331. #ifdef Q_OS_SYMBIAN
  2332. file.Close();
  2333. #endif
  2334. }
  2335. /*!
  2336. \internal
  2337. Constructs a file open event for the given \a file.
  2338. */
  2339. QFileOpenEvent::QFileOpenEvent(const QString &file)
  2340. : QEvent(FileOpen), f(file)
  2341. {
  2342. d = reinterpret_cast<QEventPrivate *>(new QFileOpenEventPrivate(QUrl::fromLocalFile(file)));
  2343. }
  2344. /*!
  2345. \internal
  2346. Constructs a file open event for the given \a url.
  2347. */
  2348. QFileOpenEvent::QFileOpenEvent(const QUrl &url)
  2349. : QEvent(FileOpen)
  2350. {
  2351. d = reinterpret_cast<QEventPrivate *>(new QFileOpenEventPrivate(url));
  2352. f = url.toLocalFile();
  2353. }
  2354. #ifdef Q_OS_SYMBIAN
  2355. /*! \internal
  2356. */
  2357. QFileOpenEvent::QFileOpenEvent(const RFile &fileHandle)
  2358. : QEvent(FileOpen)
  2359. {
  2360. TFileName fullName;
  2361. fileHandle.FullName(fullName);
  2362. f = qt_TDesC2QString(fullName);
  2363. QScopedPointer<QFileOpenEventPrivate> priv(new QFileOpenEventPrivate(QUrl::fromLocalFile(f)));
  2364. // Duplicate here allows the file handle to be valid after S60 app construction is complete.
  2365. qt_symbian_throwIfError(priv->file.Duplicate(fileHandle));
  2366. d = reinterpret_cast<QEventPrivate *>(priv.take());
  2367. }
  2368. #endif
  2369. /*! \internal
  2370. */
  2371. QFileOpenEvent::~QFileOpenEvent()
  2372. {
  2373. delete reinterpret_cast<QFileOpenEventPrivate *>(d);
  2374. }
  2375. /*!
  2376. \fn QString QFileOpenEvent::file() const
  2377. Returns the file that is being opened.
  2378. */
  2379. /*!
  2380. \fn QUrl QFileOpenEvent::url() const
  2381. Returns the url that is being opened.
  2382. \since 4.6
  2383. */
  2384. QUrl QFileOpenEvent::url() const
  2385. {
  2386. return reinterpret_cast<const QFileOpenEventPrivate *>(d)->url;
  2387. }
  2388. /*!
  2389. \fn bool QFileOpenEvent::openFile(QFile &file, QIODevice::OpenMode flags) const
  2390. Opens a QFile on the \a file referenced by this event in the mode specified
  2391. by \a flags. Returns true if successful; otherwise returns false.
  2392. This is necessary as some files cannot be opened by name, but require specific
  2393. information stored in this event.
  2394. For example, if this QFileOpenEvent contains a request to open a Symbian data caged file,
  2395. the QFile could only be opened from the Symbian RFile used in the construction of this event.
  2396. \since 4.8
  2397. */
  2398. bool QFileOpenEvent::openFile(QFile &file, QIODevice::OpenMode flags) const
  2399. {
  2400. file.setFileName(f);
  2401. #ifdef Q_OS_SYMBIAN
  2402. const QFileOpenEventPrivate *priv = reinterpret_cast<const QFileOpenEventPrivate *>(d);
  2403. if (priv->file.SubSessionHandle()) {
  2404. RFile dup;
  2405. // Duplicate here means that the opened QFile will continue to be valid beyond the lifetime of this QFileOpenEvent.
  2406. // It also allows openFile to be used in threads other than the thread in which the QFileOpenEvent was created.
  2407. if (dup.Duplicate(priv->file) == KErrNone) {
  2408. QScopedPointer<RFile, QScopedPointerRCloser<RFile> > dupCloser(&dup);
  2409. bool open = file.open(dup, flags, QFile::AutoCloseHandle);
  2410. dupCloser.take();
  2411. return open;
  2412. }
  2413. }
  2414. #endif
  2415. return file.open(flags);
  2416. }
  2417. #ifndef QT_NO_TOOLBAR
  2418. /*!
  2419. \internal
  2420. \class QToolBarChangeEvent
  2421. \brief The QToolBarChangeEvent class provides an event that is
  2422. sent whenever a the toolbar button is clicked on Mac OS X.
  2423. \ingroup events
  2424. The QToolBarChangeEvent is sent when the toolbar button is clicked. On Mac
  2425. OS X, this is the long oblong button on the right side of the window
  2426. title bar. The default implementation is to toggle the appearance (hidden or
  2427. shown) of the associated toolbars for the window.
  2428. */
  2429. /*!
  2430. \internal
  2431. Construct a QToolBarChangeEvent given the current button state in \a state.
  2432. */
  2433. QToolBarChangeEvent::QToolBarChangeEvent(bool t)
  2434. : QEvent(ToolBarChange), tog(t)
  2435. {}
  2436. /*! \internal
  2437. */
  2438. QToolBarChangeEvent::~QToolBarChangeEvent()
  2439. {
  2440. }
  2441. /*!
  2442. \fn bool QToolBarChangeEvent::toggle() const
  2443. \internal
  2444. */
  2445. /*
  2446. \fn Qt::ButtonState QToolBarChangeEvent::state() const
  2447. Returns the keyboard modifier flags at the time of the event.
  2448. The returned value is a selection of the following values,
  2449. combined using the OR operator:
  2450. Qt::ShiftButton, Qt::ControlButton, Qt::MetaButton, and Qt::AltButton.
  2451. */
  2452. #endif // QT_NO_TOOLBAR
  2453. #ifndef QT_NO_SHORTCUT
  2454. /*!
  2455. Constructs a shortcut event for the given \a key press,
  2456. associated with the QShortcut ID \a id.
  2457. \a ambiguous specifies whether there is more than one QShortcut
  2458. for the same key sequence.
  2459. */
  2460. QShortcutEvent::QShortcutEvent(const QKeySequence &key, int id, bool ambiguous)
  2461. : QEvent(Shortcut), sequence(key), ambig(ambiguous), sid(id)
  2462. {
  2463. }
  2464. /*!
  2465. Destroys the event object.
  2466. */
  2467. QShortcutEvent::~QShortcutEvent()
  2468. {
  2469. }
  2470. #endif // QT_NO_SHORTCUT
  2471. #ifndef QT_NO_DEBUG_STREAM
  2472. QDebug operator<<(QDebug dbg, const QEvent *e) {
  2473. #ifndef Q_BROKEN_DEBUG_STREAM
  2474. // More useful event output could be added here
  2475. if (!e)
  2476. return dbg << "QEvent(this = 0x0)";
  2477. const char *n = 0;
  2478. switch (e->type()) {
  2479. case QEvent::Timer:
  2480. n = "Timer";
  2481. break;
  2482. case QEvent::MouseButtonPress:
  2483. case QEvent::MouseMove:
  2484. case QEvent::MouseButtonRelease:
  2485. case QEvent::MouseButtonDblClick:
  2486. {
  2487. const QMouseEvent *me = static_cast<const QMouseEvent*>(e);
  2488. switch(me->type()) {
  2489. case QEvent::MouseButtonPress:
  2490. n = "MouseButtonPress";
  2491. break;
  2492. case QEvent::MouseMove:
  2493. n = "MouseMove";
  2494. break;
  2495. case QEvent::MouseButtonRelease:
  2496. n = "MouseButtonRelease";
  2497. break;
  2498. case QEvent::MouseButtonDblClick:
  2499. default:
  2500. n = "MouseButtonDblClick";
  2501. break;
  2502. }
  2503. dbg.nospace() << "QMouseEvent(" << n
  2504. << ", " << me->button()
  2505. << ", " << hex << (int)me->buttons()
  2506. << ", " << hex << (int)me->modifiers()
  2507. << ')';
  2508. }
  2509. return dbg.space();
  2510. #ifndef QT_NO_TOOLTIP
  2511. case QEvent::ToolTip:
  2512. n = "ToolTip";
  2513. break;
  2514. #endif
  2515. case QEvent::WindowActivate:
  2516. n = "WindowActivate";
  2517. break;
  2518. case QEvent::WindowDeactivate:
  2519. n = "WindowDeactivate";
  2520. break;
  2521. case QEvent::ActivationChange:
  2522. n = "ActivationChange";
  2523. break;
  2524. #ifndef QT_NO_WHEELEVENT
  2525. case QEvent::Wheel:
  2526. dbg.nospace() << "QWheelEvent(" << static_cast<const QWheelEvent *>(e)->delta()
  2527. << ')';
  2528. return dbg.space();
  2529. #endif
  2530. case QEvent::KeyPress:
  2531. case QEvent::KeyRelease:
  2532. case QEvent::ShortcutOverride:
  2533. {
  2534. const QKeyEvent *ke = static_cast<const QKeyEvent*>(e);
  2535. switch(ke->type()) {
  2536. case QEvent::ShortcutOverride:
  2537. n = "ShortcutOverride";
  2538. break;
  2539. case QEvent::KeyRelease:
  2540. n = "KeyRelease";
  2541. break;
  2542. case QEvent::KeyPress:
  2543. default:
  2544. n = "KeyPress";
  2545. break;
  2546. }
  2547. dbg.nospace() << "QKeyEvent(" << n
  2548. << ", " << hex << ke->key()
  2549. << ", " << hex << (int)ke->modifiers()
  2550. << ", \"" << ke->text()
  2551. << "\", " << ke->isAutoRepeat()
  2552. << ", " << ke->count()
  2553. << ')';
  2554. }
  2555. return dbg.space();
  2556. case QEvent::FocusIn:
  2557. n = "FocusIn";
  2558. break;
  2559. case QEvent::FocusOut:
  2560. n = "FocusOut";
  2561. break;
  2562. case QEvent::Enter:
  2563. n = "Enter";
  2564. break;
  2565. case QEvent::Leave:
  2566. n = "Leave";
  2567. break;
  2568. case QEvent::PaletteChange:
  2569. n = "PaletteChange";
  2570. break;
  2571. case QEvent::PolishRequest:
  2572. n = "PolishRequest";
  2573. break;
  2574. case QEvent::Polish:
  2575. n = "Polish";
  2576. break;
  2577. case QEvent::UpdateRequest:
  2578. n = "UpdateRequest";
  2579. break;
  2580. case QEvent::Paint:
  2581. n = "Paint";
  2582. break;
  2583. case QEvent::Move:
  2584. n = "Move";
  2585. break;
  2586. case QEvent::Resize:
  2587. n = "Resize";
  2588. break;
  2589. case QEvent::Create:
  2590. n = "Create";
  2591. break;
  2592. case QEvent::Destroy:
  2593. n = "Destroy";
  2594. break;
  2595. case QEvent::Close:
  2596. n = "Close";
  2597. break;
  2598. case QEvent::Quit:
  2599. n = "Quit";
  2600. break;
  2601. case QEvent::FileOpen:
  2602. n = "FileOpen";
  2603. break;
  2604. case QEvent::Show:
  2605. n = "Show";
  2606. break;
  2607. case QEvent::ShowToParent:
  2608. n = "ShowToParent";
  2609. break;
  2610. case QEvent::Hide:
  2611. n = "Hide";
  2612. break;
  2613. case QEvent::HideToParent:
  2614. n = "HideToParent";
  2615. break;
  2616. case QEvent::None:
  2617. n = "None";
  2618. break;
  2619. case QEvent::ParentChange:
  2620. n = "ParentChange";
  2621. break;
  2622. case QEvent::ParentAboutToChange:
  2623. n = "ParentAboutToChange";
  2624. break;
  2625. case QEvent::HoverEnter:
  2626. n = "HoverEnter";
  2627. break;
  2628. case QEvent::HoverMove:
  2629. n = "HoverMove";
  2630. break;
  2631. case QEvent::HoverLeave:
  2632. n = "HoverLeave";
  2633. break;
  2634. case QEvent::ZOrderChange:
  2635. n = "ZOrderChange";
  2636. break;
  2637. case QEvent::StyleChange:
  2638. n = "StyleChange";
  2639. break;
  2640. case QEvent::DragEnter:
  2641. n = "DragEnter";
  2642. break;
  2643. case QEvent::DragMove:
  2644. n = "DragMove";
  2645. break;
  2646. case QEvent::DragLeave:
  2647. n = "DragLeave";
  2648. break;
  2649. case QEvent::Drop:
  2650. n = "Drop";
  2651. break;
  2652. case QEvent::GraphicsSceneMouseMove:
  2653. n = "GraphicsSceneMouseMove";
  2654. break;
  2655. case QEvent::GraphicsSceneMousePress:
  2656. n = "GraphicsSceneMousePress";
  2657. break;
  2658. case QEvent::GraphicsSceneMouseRelease:
  2659. n = "GraphicsSceneMouseRelease";
  2660. break;
  2661. case QEvent::GraphicsSceneMouseDoubleClick:
  2662. n = "GraphicsSceneMouseDoubleClick";
  2663. break;
  2664. case QEvent::GraphicsSceneContextMenu:
  2665. n = "GraphicsSceneContextMenu";
  2666. break;
  2667. case QEvent::GraphicsSceneHoverEnter:
  2668. n = "GraphicsSceneHoverEnter";
  2669. break;
  2670. case QEvent::GraphicsSceneHoverMove:
  2671. n = "GraphicsSceneHoverMove";
  2672. break;
  2673. case QEvent::GraphicsSceneHoverLeave:
  2674. n = "GraphicsSceneHoverLeave";
  2675. break;
  2676. case QEvent::GraphicsSceneHelp:
  2677. n = "GraphicsSceneHelp";
  2678. break;
  2679. case QEvent::GraphicsSceneDragEnter:
  2680. n = "GraphicsSceneDragEnter";
  2681. break;
  2682. case QEvent::GraphicsSceneDragMove:
  2683. n = "GraphicsSceneDragMove";
  2684. break;
  2685. case QEvent::GraphicsSceneDragLeave:
  2686. n = "GraphicsSceneDragLeave";
  2687. break;
  2688. case QEvent::GraphicsSceneDrop:
  2689. n = "GraphicsSceneDrop";
  2690. break;
  2691. case QEvent::GraphicsSceneWheel:
  2692. n = "GraphicsSceneWheel";
  2693. break;
  2694. case QEvent::GraphicsSceneResize:
  2695. n = "GraphicsSceneResize";
  2696. break;
  2697. case QEvent::GraphicsSceneMove:
  2698. n = "GraphicsSceneMove";
  2699. break;
  2700. case QEvent::CursorChange:
  2701. n = "CursorChange";
  2702. break;
  2703. case QEvent::ToolTipChange:
  2704. n = "ToolTipChange";
  2705. break;
  2706. case QEvent::StatusTip:
  2707. n = "StatusTip";
  2708. break;
  2709. case QEvent::WhatsThis:
  2710. n = "WhatsThis";
  2711. break;
  2712. case QEvent::FontChange:
  2713. n = "FontChange";
  2714. break;
  2715. case QEvent::Style:
  2716. n = "Style";
  2717. break;
  2718. case QEvent::KeyboardLayoutChange:
  2719. n = "KeyboardLayoutChange";
  2720. break;
  2721. case QEvent::DynamicPropertyChange:
  2722. n = "DynamicPropertyChange";
  2723. break;
  2724. case QEvent::GrabMouse:
  2725. n = "GrabMouse";
  2726. break;
  2727. case QEvent::UngrabMouse:
  2728. n = "UngrabMouse";
  2729. break;
  2730. case QEvent::GrabKeyboard:
  2731. n = "GrabKeyboard";
  2732. break;
  2733. case QEvent::UngrabKeyboard:
  2734. n = "UngrabKeyboard";
  2735. break;
  2736. #ifdef QT3_SUPPORT
  2737. case QEvent::ChildInsertedRequest:
  2738. n = "ChildInsertedRequest";
  2739. break;
  2740. case QEvent::ChildInserted: n = "ChildInserted";
  2741. #endif
  2742. case QEvent::ChildAdded: n = n ? n : "ChildAdded";
  2743. case QEvent::ChildPolished: n = n ? n : "ChildPolished";
  2744. case QEvent::ChildRemoved: n = n ? n : "ChildRemoved";
  2745. dbg.nospace() << "QChildEvent(" << n << ", " << (static_cast<const QChildEvent*>(e))->child();
  2746. return dbg.space();
  2747. #ifndef QT_NO_GESTURES
  2748. case QEvent::Gesture:
  2749. n = "Gesture";
  2750. break;
  2751. #endif
  2752. default:
  2753. dbg.nospace() << "QEvent(" << (const void *)e << ", type = " << e->type() << ')';
  2754. return dbg.space();
  2755. }
  2756. dbg.nospace() << 'Q' << n << "Event(" << (const void *)e << ')';
  2757. return dbg.space();
  2758. #else
  2759. qWarning("This compiler doesn't support streaming QEvent to QDebug");
  2760. return dbg;
  2761. Q_UNUSED(e);
  2762. #endif
  2763. }
  2764. #endif
  2765. #ifndef QT_NO_CLIPBOARD
  2766. /*!
  2767. \class QClipboardEvent
  2768. \ingroup events
  2769. \internal
  2770. \brief The QClipboardEvent class provides the parameters used in a clipboard event.
  2771. This class is for internal use only, and exists to aid the clipboard on various
  2772. platforms to get all the information it needs. Use QEvent::Clipboard instead.
  2773. \sa QClipboard
  2774. */
  2775. QClipboardEvent::QClipboardEvent(QEventPrivate *data)
  2776. : QEvent(QEvent::Clipboard)
  2777. {
  2778. d = data;
  2779. }
  2780. QClipboardEvent::~QClipboardEvent()
  2781. {
  2782. }
  2783. #endif // QT_NO_CLIPBOARD
  2784. /*!
  2785. \class QShortcutEvent
  2786. \brief The QShortcutEvent class provides an event which is generated when
  2787. the user presses a key combination.
  2788. \ingroup events
  2789. Normally you don't need to use this class directly; QShortcut
  2790. provides a higher-level interface to handle shortcut keys.
  2791. \sa QShortcut
  2792. */
  2793. /*!
  2794. \fn const QKeySequence &QShortcutEvent::key() const
  2795. Returns the key sequence that triggered the event.
  2796. */
  2797. // ### Qt 5: remove
  2798. /*!
  2799. \fn const QKeySequence &QShortcutEvent::key()
  2800. \internal
  2801. */
  2802. /*!
  2803. \fn int QShortcutEvent::shortcutId() const
  2804. Returns the ID of the QShortcut object for which this event was
  2805. generated.
  2806. \sa QShortcut::id()
  2807. */
  2808. // ### Qt 5: remove
  2809. /*!
  2810. \fn int QShortcutEvent::shortcutId()
  2811. \overload
  2812. \internal
  2813. */
  2814. /*!
  2815. \fn bool QShortcutEvent::isAmbiguous() const
  2816. Returns true if the key sequence that triggered the event is
  2817. ambiguous.
  2818. \sa QShortcut::activatedAmbiguously()
  2819. */
  2820. // ### Qt 5: remove
  2821. /*!
  2822. \fn bool QShortcutEvent::isAmbiguous()
  2823. \internal
  2824. */
  2825. /*!
  2826. \class QWindowStateChangeEvent
  2827. \ingroup events
  2828. \brief The QWindowStateChangeEvent class provides the window state before a
  2829. window state change.
  2830. */
  2831. /*! \fn Qt::WindowStates QWindowStateChangeEvent::oldState() const
  2832. Returns the state of the window before the change.
  2833. */
  2834. /*! \internal
  2835. */
  2836. QWindowStateChangeEvent::QWindowStateChangeEvent(Qt::WindowStates s)
  2837. : QEvent(WindowStateChange), ostate(s)
  2838. {
  2839. }
  2840. /*! \internal
  2841. */
  2842. QWindowStateChangeEvent::QWindowStateChangeEvent(Qt::WindowStates s, bool isOverride)
  2843. : QEvent(WindowStateChange), ostate(s)
  2844. {
  2845. if (isOverride)
  2846. d = (QEventPrivate*)(this);
  2847. }
  2848. /*! \internal
  2849. */
  2850. bool QWindowStateChangeEvent::isOverride() const
  2851. {
  2852. return (d != 0);
  2853. }
  2854. /*! \internal
  2855. */
  2856. QWindowStateChangeEvent::~QWindowStateChangeEvent()
  2857. {
  2858. }
  2859. #ifdef QT3_SUPPORT
  2860. /*!
  2861. \class QMenubarUpdatedEvent
  2862. \internal
  2863. Event sent by QMenuBar to tell Q3Workspace to update itself.
  2864. */
  2865. /*! \internal
  2866. */
  2867. QMenubarUpdatedEvent::QMenubarUpdatedEvent(QMenuBar * const menuBar)
  2868. :QEvent(QEvent::MenubarUpdated), m_menuBar(menuBar) {}
  2869. /*!
  2870. \fn QMenuBar *QMenubarUpdatedEvent::menuBar()
  2871. \internal
  2872. */
  2873. /*!
  2874. \fn bool operator==(QKeyEvent *e, QKeySequence::StandardKey key)
  2875. \relates QKeyEvent
  2876. Returns true if \a key is currently bound to the key combination
  2877. specified by \a e.
  2878. Equivalent to \c {e->matches(key)}.
  2879. */
  2880. /*!
  2881. \fn bool operator==(QKeySequence::StandardKey key, QKeyEvent *e)
  2882. \relates QKeyEvent
  2883. Returns true if \a key is currently bound to the key combination
  2884. specified by \a e.
  2885. Equivalent to \c {e->matches(key)}.
  2886. */
  2887. /*!
  2888. \internal
  2889. \class QKeyEventEx
  2890. \ingroup events
  2891. \brief The QKeyEventEx class provides more extended information about a keyevent.
  2892. This class is for internal use only, and exists to aid the shortcut system on
  2893. various platforms to get all the information it needs.
  2894. */
  2895. #endif
  2896. /*!
  2897. \class QTouchEvent
  2898. \brief The QTouchEvent class contains parameters that describe a touch event.
  2899. \since 4.6
  2900. \ingroup events
  2901. \ingroup touch
  2902. \section1 Enabling Touch Events
  2903. Touch events occur when pressing, releasing, or moving one or more touch points on a touch
  2904. device (such as a touch-screen or track-pad). To receive touch events, widgets have to have the
  2905. Qt::WA_AcceptTouchEvents attribute set and graphics items need to have the
  2906. \l{QGraphicsItem::setAcceptTouchEvents()}{acceptTouchEvents} attribute set to true.
  2907. When using QAbstractScrollArea based widgets, you should enable the Qt::WA_AcceptTouchEvents
  2908. attribute on the scroll area's \l{QAbstractScrollArea::viewport()}{viewport}.
  2909. Similarly to QMouseEvent, Qt automatically grabs each touch point on the first press inside a
  2910. widget, and the widget will receive all updates for the touch point until it is released.
  2911. Note that it is possible for a widget to receive events for numerous touch points, and that
  2912. multiple widgets may be receiving touch events at the same time.
  2913. \section1 Event Handling
  2914. All touch events are of type QEvent::TouchBegin, QEvent::TouchUpdate, or QEvent::TouchEnd.
  2915. Reimplement QWidget::event() or QAbstractScrollArea::viewportEvent() for widgets and
  2916. QGraphicsItem::sceneEvent() for items in a graphics view to receive touch events.
  2917. The QEvent::TouchUpdate and QEvent::TouchEnd events are sent to the widget or item that
  2918. accepted the QEvent::TouchBegin event. If the QEvent::TouchBegin event is not accepted and not
  2919. filtered by an event filter, then no further touch events are sent until the next
  2920. QEvent::TouchBegin.
  2921. The touchPoints() function returns a list of all touch points contained in the event.
  2922. Information about each touch point can be retrieved using the QTouchEvent::TouchPoint class.
  2923. The Qt::TouchPointState enum describes the different states that a touch point may have.
  2924. \section1 Event Delivery and Propagation
  2925. By default, QWidget::event() translates the first non-primary touch point in a QTouchEvent into
  2926. a QMouseEvent. This makes it possible to enable touch events on existing widgets that do not
  2927. normally handle QTouchEvent. See below for information on some special considerations needed
  2928. when doing this.
  2929. QEvent::TouchBegin is the first touch event sent to a widget. The QEvent::TouchBegin event
  2930. contains a special accept flag that indicates whether the receiver wants the event. By default,
  2931. the event is accepted. You should call ignore() if the touch event is not handled by your
  2932. widget. The QEvent::TouchBegin event is propagated up the parent widget chain until a widget
  2933. accepts it with accept(), or an event filter consumes it. For QGraphicsItems, the
  2934. QEvent::TouchBegin event is propagated to items under the mouse (similar to mouse event
  2935. propagation for QGraphicsItems).
  2936. \section1 Touch Point Grouping
  2937. As mentioned above, it is possible that several widgets can be receiving QTouchEvents at the
  2938. same time. However, Qt makes sure to never send duplicate QEvent::TouchBegin events to the same
  2939. widget, which could theoretically happen during propagation if, for example, the user touched 2
  2940. separate widgets in a QGroupBox and both widgets ignored the QEvent::TouchBegin event.
  2941. To avoid this, Qt will group new touch points together using the following rules:
  2942. \list
  2943. \i When the first touch point is detected, the destination widget is determined firstly by the
  2944. location on screen and secondly by the propagation rules.
  2945. \i When additional touch points are detected, Qt first looks to see if there are any active
  2946. touch points on any ancestor or descendent of the widget under the new touch point. If there
  2947. are, the new touch point is grouped with the first, and the new touch point will be sent in a
  2948. single QTouchEvent to the widget that handled the first touch point. (The widget under the new
  2949. touch point will not receive an event).
  2950. \endlist
  2951. This makes it possible for sibling widgets to handle touch events independently while making
  2952. sure that the sequence of QTouchEvents is always correct.
  2953. \section1 Mouse Events and the Primary Touch Point
  2954. QTouchEvent delivery is independent from that of QMouseEvent. On some windowing systems, mouse
  2955. events are also sent for the \l{QTouchEvent::TouchPoint::isPrimary()}{primary touch point}.
  2956. This means it is possible for your widget to receive both QTouchEvent and QMouseEvent for the
  2957. same user interaction point. You can use the QTouchEvent::TouchPoint::isPrimary() function to
  2958. identify the primary touch point.
  2959. Note that on some systems, it is possible to receive touch events without a primary touch
  2960. point. All this means is that there will be no mouse event generated for the touch points in
  2961. the QTouchEvent.
  2962. \section1 Caveats
  2963. \list
  2964. \i As mentioned above, enabling touch events means multiple widgets can be receiving touch
  2965. events simultaneously. Combined with the default QWidget::event() handling for QTouchEvents,
  2966. this gives you great flexibility in designing touch user interfaces. Be aware of the
  2967. implications. For example, it is possible that the user is moving a QSlider with one finger and
  2968. pressing a QPushButton with another. The signals emitted by these widgets will be
  2969. interleaved.
  2970. \i Recursion into the event loop using one of the exec() methods (e.g., QDialog::exec() or
  2971. QMenu::exec()) in a QTouchEvent event handler is not supported. Since there are multiple event
  2972. recipients, recursion may cause problems, including but not limited to lost events
  2973. and unexpected infinite recursion.
  2974. \i QTouchEvents are not affected by a \l{QWidget::grabMouse()}{mouse grab} or an
  2975. \l{QApplication::activePopupWidget()}{active pop-up widget}. The behavior of QTouchEvents is
  2976. undefined when opening a pop-up or grabbing the mouse while there are more than one active touch
  2977. points.
  2978. \endlist
  2979. \sa QTouchEvent::TouchPoint, Qt::TouchPointState, Qt::WA_AcceptTouchEvents,
  2980. QGraphicsItem::acceptTouchEvents()
  2981. */
  2982. /*! \enum Qt::TouchPointState
  2983. \since 4.6
  2984. This enum represents the state of a touch point at the time the
  2985. QTouchEvent occurred.
  2986. \value TouchPointPressed The touch point is now pressed.
  2987. \value TouchPointMoved The touch point moved.
  2988. \value TouchPointStationary The touch point did not move.
  2989. \value TouchPointReleased The touch point was released.
  2990. \omitvalue TouchPointStateMask
  2991. \omitvalue TouchPointPrimary
  2992. */
  2993. /*! \enum QTouchEvent::DeviceType
  2994. This enum represents the type of device that generated a QTouchEvent.
  2995. \value TouchScreen In this type of device, the touch surface and display are integrated. This
  2996. means the surface and display typically have the same size, such that there
  2997. is a direct relationship between the touch points' physical positions and the
  2998. coordinate reported by QTouchEvent::TouchPoint. As a result, Qt allows the
  2999. user to interact directly with multiple QWidgets and QGraphicsItems at the
  3000. same time.
  3001. \value TouchPad In this type of device, the touch surface is separate from the display. There
  3002. is not a direct relationship between the physical touch location and the
  3003. on-screen coordinates. Instead, they are calculated relative to the current
  3004. mouse position, and the user must use the touch-pad to move this reference
  3005. point. Unlike touch-screens, Qt allows users to only interact with a single
  3006. QWidget or QGraphicsItem at a time.
  3007. */
  3008. /*!
  3009. Constructs a QTouchEvent with the given \a eventType, \a deviceType, and \a touchPoints.
  3010. The \a touchPointStates and \a modifiers are the current touch point states and keyboard
  3011. modifiers at the time of the event.
  3012. */
  3013. QTouchEvent::QTouchEvent(QEvent::Type eventType,
  3014. QTouchEvent::DeviceType deviceType,
  3015. Qt::KeyboardModifiers modifiers,
  3016. Qt::TouchPointStates touchPointStates,
  3017. const QList<QTouchEvent::TouchPoint> &touchPoints)
  3018. : QInputEvent(eventType, modifiers),
  3019. _widget(0),
  3020. _deviceType(deviceType),
  3021. _touchPointStates(touchPointStates),
  3022. _touchPoints(touchPoints)
  3023. { }
  3024. /*!
  3025. Destroys the QTouchEvent.
  3026. */
  3027. QTouchEvent::~QTouchEvent()
  3028. { }
  3029. /*! \fn QWidget *QTouchEvent::widget() const
  3030. Returns the widget on which the event occurred.
  3031. */
  3032. /*! \fn Qt::TouchPointStates QTouchEvent::touchPointStates() const
  3033. Returns a bitwise OR of all the touch point states for this event.
  3034. */
  3035. /*! \fn const QList<QTouchEvent::TouchPoint> &QTouchEvent::touchPoints() const
  3036. Returns the list of touch points contained in the touch event.
  3037. */
  3038. /*! \fn QTouchEvent::DeviceType QTouchEvent::deviceType() const
  3039. Returns the touch device Type, which is of type \l {QTouchEvent::DeviceType} {DeviceType}.
  3040. */
  3041. /*! \fn void QTouchEvent::setWidget(QWidget *widget)
  3042. \internal
  3043. Sets the widget for this event.
  3044. */
  3045. /*! \fn void QTouchEvent::setTouchPointStates(Qt::TouchPointStates touchPointStates)
  3046. \internal
  3047. Sets a bitwise OR of all the touch point states for this event.
  3048. */
  3049. /*! \fn void QTouchEvent::setTouchPoints(const QList<QTouchEvent::TouchPoint> &touchPoints)
  3050. \internal
  3051. Sets the list of touch points for this event.
  3052. */
  3053. /*! \fn void QTouchEvent::setDeviceType(DeviceType deviceType)
  3054. \internal
  3055. Sets the device type to \a deviceType, which is of type \l {QTouchEvent::DeviceType}
  3056. {DeviceType}.
  3057. */
  3058. /*! \class QTouchEvent::TouchPoint
  3059. \brief The TouchPoint class provides information about a touch point in a QTouchEvent.
  3060. \since 4.6
  3061. */
  3062. /*! \internal
  3063. Constructs a QTouchEvent::TouchPoint for use in a QTouchEvent.
  3064. */
  3065. QTouchEvent::TouchPoint::TouchPoint(int id)
  3066. : d(new QTouchEventTouchPointPrivate(id))
  3067. { }
  3068. /*! \internal
  3069. Constructs a copy of \a other.
  3070. */
  3071. QTouchEvent::TouchPoint::TouchPoint(const QTouchEvent::TouchPoint &other)
  3072. : d(other.d)
  3073. {
  3074. d->ref.ref();
  3075. }
  3076. /*! \internal
  3077. Destroys the QTouchEvent::TouchPoint.
  3078. */
  3079. QTouchEvent::TouchPoint::~TouchPoint()
  3080. {
  3081. if (!d->ref.deref())
  3082. delete d;
  3083. }
  3084. /*!
  3085. Returns the id number of this touch point.
  3086. Id numbers are globally sequential, starting at zero, meaning the
  3087. first touch point in the application has id 0, the second has id 1,
  3088. and so on.
  3089. */
  3090. int QTouchEvent::TouchPoint::id() const
  3091. {
  3092. return d->id;
  3093. }
  3094. /*!
  3095. Returns the current state of this touch point.
  3096. */
  3097. Qt::TouchPointState QTouchEvent::TouchPoint::state() const
  3098. {
  3099. return Qt::TouchPointState(int(d->state) & Qt::TouchPointStateMask);
  3100. }
  3101. /*!
  3102. Returns true if this touch point is the primary touch point. The primary touch point is the
  3103. point for which the windowing system generates mouse events.
  3104. */
  3105. bool QTouchEvent::TouchPoint::isPrimary() const
  3106. {
  3107. return (d->state & Qt::TouchPointPrimary) != 0;
  3108. }
  3109. /*!
  3110. Returns the position of this touch point, relative to the widget
  3111. or QGraphicsItem that received the event.
  3112. \sa startPos(), lastPos(), screenPos(), scenePos(), normalizedPos()
  3113. */
  3114. QPointF QTouchEvent::TouchPoint::pos() const
  3115. {
  3116. return d->rect.center();
  3117. }
  3118. /*!
  3119. Returns the scene position of this touch point.
  3120. The scene position is the position in QGraphicsScene coordinates
  3121. if the QTouchEvent is handled by a QGraphicsItem::touchEvent()
  3122. reimplementation, and identical to the screen position for
  3123. widgets.
  3124. \sa startScenePos(), lastScenePos(), pos()
  3125. */
  3126. QPointF QTouchEvent::TouchPoint::scenePos() const
  3127. {
  3128. return d->sceneRect.center();
  3129. }
  3130. /*!
  3131. Returns the screen position of this touch point.
  3132. \sa startScreenPos(), lastScreenPos(), pos()
  3133. */
  3134. QPointF QTouchEvent::TouchPoint::screenPos() const
  3135. {
  3136. return d->screenRect.center();
  3137. }
  3138. /*!
  3139. Returns the normalized position of this touch point.
  3140. The coordinates are normalized to the size of the touch device,
  3141. i.e. (0,0) is the top-left corner and (1,1) is the bottom-right corner.
  3142. \sa startNormalizedPos(), lastNormalizedPos(), pos()
  3143. */
  3144. QPointF QTouchEvent::TouchPoint::normalizedPos() const
  3145. {
  3146. return d->normalizedPos;
  3147. }
  3148. /*!
  3149. Returns the starting position of this touch point, relative to the
  3150. widget or QGraphicsItem that received the event.
  3151. \sa pos(), lastPos()
  3152. */
  3153. QPointF QTouchEvent::TouchPoint::startPos() const
  3154. {
  3155. return d->startPos;
  3156. }
  3157. /*!
  3158. Returns the starting scene position of this touch point.
  3159. The scene position is the position in QGraphicsScene coordinates
  3160. if the QTouchEvent is handled by a QGraphicsItem::touchEvent()
  3161. reimplementation, and identical to the screen position for
  3162. widgets.
  3163. \sa scenePos(), lastScenePos()
  3164. */
  3165. QPointF QTouchEvent::TouchPoint::startScenePos() const
  3166. {
  3167. return d->startScenePos;
  3168. }
  3169. /*!
  3170. Returns the starting screen position of this touch point.
  3171. \sa screenPos(), lastScreenPos()
  3172. */
  3173. QPointF QTouchEvent::TouchPoint::startScreenPos() const
  3174. {
  3175. return d->startScreenPos;
  3176. }
  3177. /*!
  3178. Returns the normalized starting position of this touch point.
  3179. The coordinates are normalized to the size of the touch device,
  3180. i.e. (0,0) is the top-left corner and (1,1) is the bottom-right corner.
  3181. \sa normalizedPos(), lastNormalizedPos()
  3182. */
  3183. QPointF QTouchEvent::TouchPoint::startNormalizedPos() const
  3184. {
  3185. return d->startNormalizedPos;
  3186. }
  3187. /*!
  3188. Returns the position of this touch point from the previous touch
  3189. event, relative to the widget or QGraphicsItem that received the event.
  3190. \sa pos(), startPos()
  3191. */
  3192. QPointF QTouchEvent::TouchPoint::lastPos() const
  3193. {
  3194. return d->lastPos;
  3195. }
  3196. /*!
  3197. Returns the scene position of this touch point from the previous
  3198. touch event.
  3199. The scene position is the position in QGraphicsScene coordinates
  3200. if the QTouchEvent is handled by a QGraphicsItem::touchEvent()
  3201. reimplementation, and identical to the screen position for
  3202. widgets.
  3203. \sa scenePos(), startScenePos()
  3204. */
  3205. QPointF QTouchEvent::TouchPoint::lastScenePos() const
  3206. {
  3207. return d->lastScenePos;
  3208. }
  3209. /*!
  3210. Returns the screen position of this touch point from the previous
  3211. touch event.
  3212. \sa screenPos(), startScreenPos()
  3213. */
  3214. QPointF QTouchEvent::TouchPoint::lastScreenPos() const
  3215. {
  3216. return d->lastScreenPos;
  3217. }
  3218. /*!
  3219. Returns the normalized position of this touch point from the
  3220. previous touch event.
  3221. The coordinates are normalized to the size of the touch device,
  3222. i.e. (0,0) is the top-left corner and (1,1) is the bottom-right corner.
  3223. \sa normalizedPos(), startNormalizedPos()
  3224. */
  3225. QPointF QTouchEvent::TouchPoint::lastNormalizedPos() const
  3226. {
  3227. return d->lastNormalizedPos;
  3228. }
  3229. /*!
  3230. Returns the rect for this touch point, relative to the widget
  3231. or QGraphicsItem that received the event. The rect is centered
  3232. around the point returned by pos().
  3233. \note This function returns an empty rect if the device does not report touch point sizes.
  3234. */
  3235. QRectF QTouchEvent::TouchPoint::rect() const
  3236. {
  3237. return d->rect;
  3238. }
  3239. /*!
  3240. Returns the rect for this touch point in scene coordinates.
  3241. \note This function returns an empty rect if the device does not report touch point sizes.
  3242. \sa scenePos(), rect()
  3243. */
  3244. QRectF QTouchEvent::TouchPoint::sceneRect() const
  3245. {
  3246. return d->sceneRect;
  3247. }
  3248. /*!
  3249. Returns the rect for this touch point in screen coordinates.
  3250. \note This function returns an empty rect if the device does not report touch point sizes.
  3251. \sa screenPos(), rect()
  3252. */
  3253. QRectF QTouchEvent::TouchPoint::screenRect() const
  3254. {
  3255. return d->screenRect;
  3256. }
  3257. /*!
  3258. Returns the pressure of this touch point. The return value is in
  3259. the range 0.0 to 1.0.
  3260. */
  3261. qreal QTouchEvent::TouchPoint::pressure() const
  3262. {
  3263. return d->pressure;
  3264. }
  3265. /*! \internal */
  3266. void QTouchEvent::TouchPoint::setId(int id)
  3267. {
  3268. if (d->ref != 1)
  3269. d = d->detach();
  3270. d->id = id;
  3271. }
  3272. /*! \internal */
  3273. void QTouchEvent::TouchPoint::setState(Qt::TouchPointStates state)
  3274. {
  3275. if (d->ref != 1)
  3276. d = d->detach();
  3277. d->state = state;
  3278. }
  3279. /*! \internal */
  3280. void QTouchEvent::TouchPoint::setPos(const QPointF &pos)
  3281. {
  3282. if (d->ref != 1)
  3283. d = d->detach();
  3284. d->rect.moveCenter(pos);
  3285. }
  3286. /*! \internal */
  3287. void QTouchEvent::TouchPoint::setScenePos(const QPointF &scenePos)
  3288. {
  3289. if (d->ref != 1)
  3290. d = d->detach();
  3291. d->sceneRect.moveCenter(scenePos);
  3292. }
  3293. /*! \internal */
  3294. void QTouchEvent::TouchPoint::setScreenPos(const QPointF &screenPos)
  3295. {
  3296. if (d->ref != 1)
  3297. d = d->detach();
  3298. d->screenRect.moveCenter(screenPos);
  3299. }
  3300. /*! \internal */
  3301. void QTouchEvent::TouchPoint::setNormalizedPos(const QPointF &normalizedPos)
  3302. {
  3303. if (d->ref != 1)
  3304. d = d->detach();
  3305. d->normalizedPos = normalizedPos;
  3306. }
  3307. /*! \internal */
  3308. void QTouchEvent::TouchPoint::setStartPos(const QPointF &startPos)
  3309. {
  3310. if (d->ref != 1)
  3311. d = d->detach();
  3312. d->startPos = startPos;
  3313. }
  3314. /*! \internal */
  3315. void QTouchEvent::TouchPoint::setStartScenePos(const QPointF &startScenePos)
  3316. {
  3317. if (d->ref != 1)
  3318. d = d->detach();
  3319. d->startScenePos = startScenePos;
  3320. }
  3321. /*! \internal */
  3322. void QTouchEvent::TouchPoint::setStartScreenPos(const QPointF &startScreenPos)
  3323. {
  3324. if (d->ref != 1)
  3325. d = d->detach();
  3326. d->startScreenPos = startScreenPos;
  3327. }
  3328. /*! \internal */
  3329. void QTouchEvent::TouchPoint::setStartNormalizedPos(const QPointF &startNormalizedPos)
  3330. {
  3331. if (d->ref != 1)
  3332. d = d->detach();
  3333. d->startNormalizedPos = startNormalizedPos;
  3334. }
  3335. /*! \internal */
  3336. void QTouchEvent::TouchPoint::setLastPos(const QPointF &lastPos)
  3337. {
  3338. if (d->ref != 1)
  3339. d = d->detach();
  3340. d->lastPos = lastPos;
  3341. }
  3342. /*! \internal */
  3343. void QTouchEvent::TouchPoint::setLastScenePos(const QPointF &lastScenePos)
  3344. {
  3345. if (d->ref != 1)
  3346. d = d->detach();
  3347. d->lastScenePos = lastScenePos;
  3348. }
  3349. /*! \internal */
  3350. void QTouchEvent::TouchPoint::setLastScreenPos(const QPointF &lastScreenPos)
  3351. {
  3352. if (d->ref != 1)
  3353. d = d->detach();
  3354. d->lastScreenPos = lastScreenPos;
  3355. }
  3356. /*! \internal */
  3357. void QTouchEvent::TouchPoint::setLastNormalizedPos(const QPointF &lastNormalizedPos)
  3358. {
  3359. if (d->ref != 1)
  3360. d = d->detach();
  3361. d->lastNormalizedPos = lastNormalizedPos;
  3362. }
  3363. /*! \internal */
  3364. void QTouchEvent::TouchPoint::setRect(const QRectF &rect)
  3365. {
  3366. if (d->ref != 1)
  3367. d = d->detach();
  3368. d->rect = rect;
  3369. }
  3370. /*! \internal */
  3371. void QTouchEvent::TouchPoint::setSceneRect(const QRectF &sceneRect)
  3372. {
  3373. if (d->ref != 1)
  3374. d = d->detach();
  3375. d->sceneRect = sceneRect;
  3376. }
  3377. /*! \internal */
  3378. void QTouchEvent::TouchPoint::setScreenRect(const QRectF &screenRect)
  3379. {
  3380. if (d->ref != 1)
  3381. d = d->detach();
  3382. d->screenRect = screenRect;
  3383. }
  3384. /*! \internal */
  3385. void QTouchEvent::TouchPoint::setPressure(qreal pressure)
  3386. {
  3387. if (d->ref != 1)
  3388. d = d->detach();
  3389. d->pressure = pressure;
  3390. }
  3391. /*! \internal */
  3392. QTouchEvent::TouchPoint &QTouchEvent::TouchPoint::operator=(const QTouchEvent::TouchPoint &other)
  3393. {
  3394. other.d->ref.ref();
  3395. if (!d->ref.deref())
  3396. delete d;
  3397. d = other.d;
  3398. return *this;
  3399. }
  3400. #ifndef QT_NO_GESTURES
  3401. /*!
  3402. \class QGestureEvent
  3403. \since 4.6
  3404. \ingroup events
  3405. \ingroup gestures
  3406. \brief The QGestureEvent class provides the description of triggered gestures.
  3407. The QGestureEvent class contains a list of gestures, which can be obtained using the
  3408. gestures() function.
  3409. The gestures are either active or canceled. A list of those that are currently being
  3410. executed can be obtained using the activeGestures() function. A list of those which
  3411. were previously active and have been canceled can be accessed using the
  3412. canceledGestures() function. A gesture might be canceled if the current window loses
  3413. focus, for example, or because of a timeout, or for other reasons.
  3414. If the event handler does not accept the event by calling the generic
  3415. QEvent::accept() function, all individual QGesture object that were not
  3416. accepted and in the Qt::GestureStarted state will be propagated up the
  3417. parent widget chain until a widget accepts them individually, by calling
  3418. QGestureEvent::accept() for each of them, or an event filter consumes the
  3419. event.
  3420. \section1 Further Reading
  3421. For an overview of gesture handling in Qt and information on using gestures
  3422. in your applications, see the \l{Gestures Programming} document.
  3423. \sa QGesture, QGestureRecognizer,
  3424. QWidget::grabGesture(), QGraphicsObject::grabGesture()
  3425. */
  3426. /*!
  3427. Creates new QGestureEvent containing a list of \a gestures.
  3428. */
  3429. QGestureEvent::QGestureEvent(const QList<QGesture *> &gestures)
  3430. : QEvent(QEvent::Gesture)
  3431. {
  3432. d = reinterpret_cast<QEventPrivate *>(new QGestureEventPrivate(gestures));
  3433. }
  3434. /*!
  3435. Destroys QGestureEvent.
  3436. */
  3437. QGestureEvent::~QGestureEvent()
  3438. {
  3439. delete reinterpret_cast<QGestureEventPrivate *>(d);
  3440. }
  3441. /*!
  3442. Returns all gestures that are delivered in the event.
  3443. */
  3444. QList<QGesture *> QGestureEvent::gestures() const
  3445. {
  3446. return d_func()->gestures;
  3447. }
  3448. /*!
  3449. Returns a gesture object by \a type.
  3450. */
  3451. QGesture *QGestureEvent::gesture(Qt::GestureType type) const
  3452. {
  3453. const QGestureEventPrivate *d = d_func();
  3454. for(int i = 0; i < d->gestures.size(); ++i)
  3455. if (d->gestures.at(i)->gestureType() == type)
  3456. return d->gestures.at(i);
  3457. return 0;
  3458. }
  3459. /*!
  3460. Returns a list of active (not canceled) gestures.
  3461. */
  3462. QList<QGesture *> QGestureEvent::activeGestures() const
  3463. {
  3464. QList<QGesture *> gestures;
  3465. foreach (QGesture *gesture, d_func()->gestures) {
  3466. if (gesture->state() != Qt::GestureCanceled)
  3467. gestures.append(gesture);
  3468. }
  3469. return gestures;
  3470. }
  3471. /*!
  3472. Returns a list of canceled gestures.
  3473. */
  3474. QList<QGesture *> QGestureEvent::canceledGestures() const
  3475. {
  3476. QList<QGesture *> gestures;
  3477. foreach (QGesture *gesture, d_func()->gestures) {
  3478. if (gesture->state() == Qt::GestureCanceled)
  3479. gestures.append(gesture);
  3480. }
  3481. return gestures;
  3482. }
  3483. /*!
  3484. Sets the accept flag of the given \a gesture object to the specified \a value.
  3485. Setting the accept flag indicates that the event receiver wants the \a gesture.
  3486. Unwanted gestures may be propagated to the parent widget.
  3487. By default, gestures in events of type QEvent::Gesture are accepted, and
  3488. gestures in QEvent::GestureOverride events are ignored.
  3489. For convenience, the accept flag can also be set with
  3490. \l{QGestureEvent::accept()}{accept(gesture)}, and cleared with
  3491. \l{QGestureEvent::ignore()}{ignore(gesture)}.
  3492. */
  3493. void QGestureEvent::setAccepted(QGesture *gesture, bool value)
  3494. {
  3495. if (gesture)
  3496. setAccepted(gesture->gestureType(), value);
  3497. }
  3498. /*!
  3499. Sets the accept flag of the given \a gesture object, the equivalent of calling
  3500. \l{QGestureEvent::setAccepted()}{setAccepted(gesture, true)}.
  3501. Setting the accept flag indicates that the event receiver wants the
  3502. gesture. Unwanted gestures may be propagated to the parent widget.
  3503. \sa QGestureEvent::ignore()
  3504. */
  3505. void QGestureEvent::accept(QGesture *gesture)
  3506. {
  3507. if (gesture)
  3508. setAccepted(gesture->gestureType(), true);
  3509. }
  3510. /*!
  3511. Clears the accept flag parameter of the given \a gesture object, the equivalent
  3512. of calling \l{QGestureEvent::setAccepted()}{setAccepted(gesture, false)}.
  3513. Clearing the accept flag indicates that the event receiver does not
  3514. want the gesture. Unwanted gestures may be propagated to the parent widget.
  3515. \sa QGestureEvent::accept()
  3516. */
  3517. void QGestureEvent::ignore(QGesture *gesture)
  3518. {
  3519. if (gesture)
  3520. setAccepted(gesture->gestureType(), false);
  3521. }
  3522. /*!
  3523. Returns true if the \a gesture is accepted; otherwise returns false.
  3524. */
  3525. bool QGestureEvent::isAccepted(QGesture *gesture) const
  3526. {
  3527. return gesture ? isAccepted(gesture->gestureType()) : false;
  3528. }
  3529. /*!
  3530. Sets the accept flag of the given \a gestureType object to the specified
  3531. \a value.
  3532. Setting the accept flag indicates that the event receiver wants to receive
  3533. gestures of the specified type, \a gestureType. Unwanted gestures may be
  3534. propagated to the parent widget.
  3535. By default, gestures in events of type QEvent::Gesture are accepted, and
  3536. gestures in QEvent::GestureOverride events are ignored.
  3537. For convenience, the accept flag can also be set with
  3538. \l{QGestureEvent::accept()}{accept(gestureType)}, and cleared with
  3539. \l{QGestureEvent::ignore()}{ignore(gestureType)}.
  3540. */
  3541. void QGestureEvent::setAccepted(Qt::GestureType gestureType, bool value)
  3542. {
  3543. setAccepted(false);
  3544. d_func()->accepted[gestureType] = value;
  3545. }
  3546. /*!
  3547. Sets the accept flag of the given \a gestureType, the equivalent of calling
  3548. \l{QGestureEvent::setAccepted()}{setAccepted(gestureType, true)}.
  3549. Setting the accept flag indicates that the event receiver wants the
  3550. gesture. Unwanted gestures may be propagated to the parent widget.
  3551. \sa QGestureEvent::ignore()
  3552. */
  3553. void QGestureEvent::accept(Qt::GestureType gestureType)
  3554. {
  3555. setAccepted(gestureType, true);
  3556. }
  3557. /*!
  3558. Clears the accept flag parameter of the given \a gestureType, the equivalent
  3559. of calling \l{QGestureEvent::setAccepted()}{setAccepted(gesture, false)}.
  3560. Clearing the accept flag indicates that the event receiver does not
  3561. want the gesture. Unwanted gestures may be propgated to the parent widget.
  3562. \sa QGestureEvent::accept()
  3563. */
  3564. void QGestureEvent::ignore(Qt::GestureType gestureType)
  3565. {
  3566. setAccepted(gestureType, false);
  3567. }
  3568. /*!
  3569. Returns true if the gesture of type \a gestureType is accepted; otherwise
  3570. returns false.
  3571. */
  3572. bool QGestureEvent::isAccepted(Qt::GestureType gestureType) const
  3573. {
  3574. return d_func()->accepted.value(gestureType, true);
  3575. }
  3576. /*!
  3577. \internal
  3578. Sets the widget for this event to the \a widget specified.
  3579. */
  3580. void QGestureEvent::setWidget(QWidget *widget)
  3581. {
  3582. d_func()->widget = widget;
  3583. }
  3584. /*!
  3585. Returns the widget on which the event occurred.
  3586. */
  3587. QWidget *QGestureEvent::widget() const
  3588. {
  3589. return d_func()->widget;
  3590. }
  3591. #ifndef QT_NO_GRAPHICSVIEW
  3592. /*!
  3593. Returns the scene-local coordinates if the \a gesturePoint is inside a
  3594. graphics view.
  3595. This functional might be useful when the gesture event is delivered to a
  3596. QGraphicsObject to translate a point in screen coordinates to scene-local
  3597. coordinates.
  3598. \sa QPointF::isNull().
  3599. */
  3600. QPointF QGestureEvent::mapToGraphicsScene(const QPointF &gesturePoint) const
  3601. {
  3602. QWidget *w = widget();
  3603. if (w) // we get the viewport as widget, not the graphics view
  3604. w = w->parentWidget();
  3605. QGraphicsView *view = qobject_cast<QGraphicsView*>(w);
  3606. if (view) {
  3607. return view->mapToScene(view->mapFromGlobal(gesturePoint.toPoint()));
  3608. }
  3609. return QPointF();
  3610. }
  3611. #endif //QT_NO_GRAPHICSVIEW
  3612. /*!
  3613. \internal
  3614. */
  3615. QGestureEventPrivate *QGestureEvent::d_func()
  3616. {
  3617. return reinterpret_cast<QGestureEventPrivate *>(d);
  3618. }
  3619. /*!
  3620. \internal
  3621. */
  3622. const QGestureEventPrivate *QGestureEvent::d_func() const
  3623. {
  3624. return reinterpret_cast<const QGestureEventPrivate *>(d);
  3625. }
  3626. #ifdef Q_NO_USING_KEYWORD
  3627. /*!
  3628. \fn void QGestureEvent::setAccepted(bool accepted)
  3629. Sets or clears the event's internal flag that determines whether it should
  3630. be delivered to other objects.
  3631. Calling this function with a value of true for \a accepted indicates that the
  3632. caller has accepted the event and that it should not be propagated further.
  3633. Calling this function with a value of false indicates that the caller has
  3634. ignored the event and that it should be delivered to other objects.
  3635. For convenience, the accept flag can also be set with accept(), and cleared
  3636. with ignore().
  3637. \sa QEvent::accepted
  3638. */
  3639. /*!
  3640. \fn bool QGestureEvent::isAccepted() const
  3641. Returns true is the event has been accepted; otherwise returns false.
  3642. \sa QEvent::accepted
  3643. */
  3644. /*!
  3645. \fn void QGestureEvent::accept()
  3646. Accepts the event, the equivalent of calling setAccepted(true).
  3647. \sa QEvent::accept()
  3648. */
  3649. /*!
  3650. \fn void QGestureEvent::ignore()
  3651. Ignores the event, the equivalent of calling setAccepted(false).
  3652. \sa QEvent::ignore()
  3653. */
  3654. #endif
  3655. #endif // QT_NO_GESTURES
  3656. QT_END_NAMESPACE