/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

Large files are truncated click here to view the full 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. repla…