| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Copyright (C) 2016 Intel Corporation. |
| 5 | ** Contact: https://www.qt.io/licensing/ |
| 6 | ** |
| 7 | ** This file is part of the QtCore module of the Qt Toolkit. |
| 8 | ** |
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ |
| 10 | ** Commercial License Usage |
| 11 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 12 | ** accordance with the commercial license agreement provided with the |
| 13 | ** Software or, alternatively, in accordance with the terms contained in |
| 14 | ** a written agreement between you and The Qt Company. For licensing terms |
| 15 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 16 | ** information use the contact form at https://www.qt.io/contact-us. |
| 17 | ** |
| 18 | ** GNU Lesser General Public License Usage |
| 19 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 20 | ** General Public License version 3 as published by the Free Software |
| 21 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 22 | ** packaging of this file. Please review the following information to |
| 23 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 24 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 25 | ** |
| 26 | ** GNU General Public License Usage |
| 27 | ** Alternatively, this file may be used under the terms of the GNU |
| 28 | ** General Public License version 2.0 or (at your option) the GNU General |
| 29 | ** Public license version 3 or any later version approved by the KDE Free |
| 30 | ** Qt Foundation. The licenses are as published by the Free Software |
| 31 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 32 | ** included in the packaging of this file. Please review the following |
| 33 | ** information to ensure the GNU General Public License requirements will |
| 34 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 35 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 36 | ** |
| 37 | ** $QT_END_LICENSE$ |
| 38 | ** |
| 39 | ****************************************************************************/ |
| 40 | |
| 41 | #include "qcoreevent.h" |
| 42 | #include "qcoreapplication.h" |
| 43 | #include "qcoreapplication_p.h" |
| 44 | |
| 45 | #include "qbasicatomic.h" |
| 46 | |
| 47 | #include <qtcore_tracepoints_p.h> |
| 48 | |
| 49 | #include <limits> |
| 50 | |
| 51 | QT_BEGIN_NAMESPACE |
| 52 | |
| 53 | /*! |
| 54 | \class QEvent |
| 55 | \inmodule QtCore |
| 56 | \brief The QEvent class is the base class of all |
| 57 | event classes. Event objects contain event parameters. |
| 58 | |
| 59 | \ingroup events |
| 60 | |
| 61 | Qt's main event loop (QCoreApplication::exec()) fetches native |
| 62 | window system events from the event queue, translates them into |
| 63 | QEvents, and sends the translated events to \l{QObject}s. |
| 64 | |
| 65 | In general, events come from the underlying window system |
| 66 | (spontaneous() returns \c true), but it is also possible to manually |
| 67 | send events using QCoreApplication::sendEvent() and |
| 68 | QCoreApplication::postEvent() (spontaneous() returns \c false). |
| 69 | |
| 70 | \l {QObject}{QObjects} receive events by having their QObject::event() function |
| 71 | called. The function can be reimplemented in subclasses to |
| 72 | customize event handling and add additional event types; |
| 73 | QWidget::event() is a notable example. By default, events are |
| 74 | dispatched to event handlers like QObject::timerEvent() and |
| 75 | QWidget::mouseMoveEvent(). QObject::installEventFilter() allows an |
| 76 | object to intercept events destined for another object. |
| 77 | |
| 78 | The basic QEvent contains only an event type parameter and an |
| 79 | "accept" flag. The accept flag set with accept(), and cleared |
| 80 | with ignore(). It is set by default, but don't rely on this as |
| 81 | subclasses may choose to clear it in their constructor. |
| 82 | |
| 83 | Subclasses of QEvent contain additional parameters that describe |
| 84 | the particular event. |
| 85 | |
| 86 | \sa QObject::event(), QObject::installEventFilter(), |
| 87 | QCoreApplication::sendEvent(), |
| 88 | QCoreApplication::postEvent(), QCoreApplication::processEvents() |
| 89 | */ |
| 90 | |
| 91 | |
| 92 | /*! |
| 93 | \enum QEvent::Type |
| 94 | |
| 95 | This enum type defines the valid event types in Qt. The event |
| 96 | types and the specialized classes for each type are as follows: |
| 97 | |
| 98 | \value None Not an event. |
| 99 | \value ActionAdded A new action has been added (QActionEvent). |
| 100 | \value ActionChanged An action has been changed (QActionEvent). |
| 101 | \value ActionRemoved An action has been removed (QActionEvent). |
| 102 | \value ActivationChange A widget's top-level window activation state has changed. |
| 103 | \value ApplicationActivate This enum has been deprecated. Use ApplicationStateChange instead. |
| 104 | \value ApplicationActivated This enum has been deprecated. Use ApplicationStateChange instead. |
| 105 | \value ApplicationDeactivate This enum has been deprecated. Use ApplicationStateChange instead. |
| 106 | \value ApplicationFontChange The default application font has changed. |
| 107 | \value ApplicationLayoutDirectionChange The default application layout direction has changed. |
| 108 | \value ApplicationPaletteChange The default application palette has changed. |
| 109 | \value ApplicationStateChange The state of the application has changed. |
| 110 | \value ApplicationWindowIconChange The application's icon has changed. |
| 111 | \value ChildAdded An object gets a child (QChildEvent). |
| 112 | \value ChildPolished A widget child gets polished (QChildEvent). |
| 113 | \value ChildRemoved An object loses a child (QChildEvent). |
| 114 | \value Clipboard The clipboard contents have changed. |
| 115 | \value Close Widget was closed (QCloseEvent). |
| 116 | \value CloseSoftwareInputPanel A widget wants to close the software input panel (SIP). |
| 117 | \value ContentsRectChange The margins of the widget's content rect changed. |
| 118 | \value ContextMenu Context popup menu (QContextMenuEvent). |
| 119 | \value CursorChange The widget's cursor has changed. |
| 120 | \value DeferredDelete The object will be deleted after it has cleaned up (QDeferredDeleteEvent) |
| 121 | \value DragEnter The cursor enters a widget during a drag and drop operation (QDragEnterEvent). |
| 122 | \value DragLeave The cursor leaves a widget during a drag and drop operation (QDragLeaveEvent). |
| 123 | \value DragMove A drag and drop operation is in progress (QDragMoveEvent). |
| 124 | \value Drop A drag and drop operation is completed (QDropEvent). |
| 125 | \value DynamicPropertyChange A dynamic property was added, changed, or removed from the object. |
| 126 | \value EnabledChange Widget's enabled state has changed. |
| 127 | \value Enter Mouse enters widget's boundaries (QEnterEvent). |
| 128 | \value EnterEditFocus An editor widget gains focus for editing. \c QT_KEYPAD_NAVIGATION must be defined. |
| 129 | \value EnterWhatsThisMode Send to toplevel widgets when the application enters "What's This?" mode. |
| 130 | \value Expose Sent to a window when its on-screen contents are invalidated and need to be flushed from the backing store. |
| 131 | \value FileOpen File open request (QFileOpenEvent). |
| 132 | \value FocusIn Widget or Window gains keyboard focus (QFocusEvent). |
| 133 | \value FocusOut Widget or Window loses keyboard focus (QFocusEvent). |
| 134 | \value FocusAboutToChange Widget or Window focus is about to change (QFocusEvent) |
| 135 | \value FontChange Widget's font has changed. |
| 136 | \value Gesture A gesture was triggered (QGestureEvent). |
| 137 | \value GestureOverride A gesture override was triggered (QGestureEvent). |
| 138 | \value GrabKeyboard Item gains keyboard grab (QGraphicsItem only). |
| 139 | \value GrabMouse Item gains mouse grab (QGraphicsItem only). |
| 140 | \value GraphicsSceneContextMenu Context popup menu over a graphics scene (QGraphicsSceneContextMenuEvent). |
| 141 | \value GraphicsSceneDragEnter The cursor enters a graphics scene during a drag and drop operation (QGraphicsSceneDragDropEvent). |
| 142 | \value GraphicsSceneDragLeave The cursor leaves a graphics scene during a drag and drop operation (QGraphicsSceneDragDropEvent). |
| 143 | \value GraphicsSceneDragMove A drag and drop operation is in progress over a scene (QGraphicsSceneDragDropEvent). |
| 144 | \value GraphicsSceneDrop A drag and drop operation is completed over a scene (QGraphicsSceneDragDropEvent). |
| 145 | \value GraphicsSceneHelp The user requests help for a graphics scene (QHelpEvent). |
| 146 | \value GraphicsSceneHoverEnter The mouse cursor enters a hover item in a graphics scene (QGraphicsSceneHoverEvent). |
| 147 | \value GraphicsSceneHoverLeave The mouse cursor leaves a hover item in a graphics scene (QGraphicsSceneHoverEvent). |
| 148 | \value GraphicsSceneHoverMove The mouse cursor moves inside a hover item in a graphics scene (QGraphicsSceneHoverEvent). |
| 149 | \value GraphicsSceneMouseDoubleClick Mouse press again (double click) in a graphics scene (QGraphicsSceneMouseEvent). |
| 150 | \value GraphicsSceneMouseMove Move mouse in a graphics scene (QGraphicsSceneMouseEvent). |
| 151 | \value GraphicsSceneMousePress Mouse press in a graphics scene (QGraphicsSceneMouseEvent). |
| 152 | \value GraphicsSceneMouseRelease Mouse release in a graphics scene (QGraphicsSceneMouseEvent). |
| 153 | \value GraphicsSceneMove Widget was moved (QGraphicsSceneMoveEvent). |
| 154 | \value GraphicsSceneResize Widget was resized (QGraphicsSceneResizeEvent). |
| 155 | \value GraphicsSceneWheel Mouse wheel rolled in a graphics scene (QGraphicsSceneWheelEvent). |
| 156 | \value Hide Widget was hidden (QHideEvent). |
| 157 | \value HideToParent A child widget has been hidden. |
| 158 | \value HoverEnter The mouse cursor enters a hover widget (QHoverEvent). |
| 159 | \value HoverLeave The mouse cursor leaves a hover widget (QHoverEvent). |
| 160 | \value HoverMove The mouse cursor moves inside a hover widget (QHoverEvent). |
| 161 | \value IconDrag The main icon of a window has been dragged away (QIconDragEvent). |
| 162 | \value IconTextChange Widget's icon text has been changed. (Deprecated) |
| 163 | \value InputMethod An input method is being used (QInputMethodEvent). |
| 164 | \value InputMethodQuery A input method query event (QInputMethodQueryEvent) |
| 165 | \value KeyboardLayoutChange The keyboard layout has changed. |
| 166 | \value KeyPress Key press (QKeyEvent). |
| 167 | \value KeyRelease Key release (QKeyEvent). |
| 168 | \value LanguageChange The application translation changed. |
| 169 | \value LayoutDirectionChange The direction of layouts changed. |
| 170 | \value LayoutRequest Widget layout needs to be redone. |
| 171 | \value Leave Mouse leaves widget's boundaries. |
| 172 | \value LeaveEditFocus An editor widget loses focus for editing. QT_KEYPAD_NAVIGATION must be defined. |
| 173 | \value LeaveWhatsThisMode Send to toplevel widgets when the application leaves "What's This?" mode. |
| 174 | \value LocaleChange The system locale has changed. |
| 175 | \value NonClientAreaMouseButtonDblClick A mouse double click occurred outside the client area (QMouseEvent). |
| 176 | \value NonClientAreaMouseButtonPress A mouse button press occurred outside the client area (QMouseEvent). |
| 177 | \value NonClientAreaMouseButtonRelease A mouse button release occurred outside the client area (QMouseEvent). |
| 178 | \value NonClientAreaMouseMove A mouse move occurred outside the client area (QMouseEvent). |
| 179 | \value MacSizeChange The user changed his widget sizes (\macos only). |
| 180 | \value MetaCall An asynchronous method invocation via QMetaObject::invokeMethod(). |
| 181 | \value ModifiedChange Widgets modification state has been changed. |
| 182 | \value MouseButtonDblClick Mouse press again (QMouseEvent). |
| 183 | \value MouseButtonPress Mouse press (QMouseEvent). |
| 184 | \value MouseButtonRelease Mouse release (QMouseEvent). |
| 185 | \value MouseMove Mouse move (QMouseEvent). |
| 186 | \value MouseTrackingChange The mouse tracking state has changed. |
| 187 | \value Move Widget's position changed (QMoveEvent). |
| 188 | \value NativeGesture The system has detected a gesture (QNativeGestureEvent). |
| 189 | \value OrientationChange The screens orientation has changes (QScreenOrientationChangeEvent). |
| 190 | \value Paint Screen update necessary (QPaintEvent). |
| 191 | \value PaletteChange Palette of the widget changed. |
| 192 | \value ParentAboutToChange The widget parent is about to change. |
| 193 | \value ParentChange The widget parent has changed. |
| 194 | \value PlatformPanel A platform specific panel has been requested. |
| 195 | \value PlatformSurface A native platform surface has been created or is about to be destroyed (QPlatformSurfaceEvent). |
| 196 | \omitvalue Pointer |
| 197 | \value Polish The widget is polished. |
| 198 | \value PolishRequest The widget should be polished. |
| 199 | \value QueryWhatsThis The widget should accept the event if it has "What's This?" help (QHelpEvent). |
| 200 | \value ReadOnlyChange Widget's read-only state has changed (since Qt 5.4). |
| 201 | \value RequestSoftwareInputPanel A widget wants to open a software input panel (SIP). |
| 202 | \value Resize Widget's size changed (QResizeEvent). |
| 203 | \value ScrollPrepare The object needs to fill in its geometry information (QScrollPrepareEvent). |
| 204 | \value Scroll The object needs to scroll to the supplied position (QScrollEvent). |
| 205 | \value Shortcut Key press in child for shortcut key handling (QShortcutEvent). |
| 206 | \value ShortcutOverride Key press in child, for overriding shortcut key handling (QKeyEvent). |
| 207 | When a shortcut is about to trigger, \c ShortcutOverride |
| 208 | is sent to the active window. This allows clients (e.g. widgets) |
| 209 | to signal that they will handle the shortcut themselves, by |
| 210 | accepting the event. If the shortcut override is accepted, the |
| 211 | event is delivered as a normal key press to the focus widget. |
| 212 | Otherwise, it triggers the shortcut action, if one exists. |
| 213 | \value Show Widget was shown on screen (QShowEvent). |
| 214 | \value ShowToParent A child widget has been shown. |
| 215 | \value SockAct Socket activated, used to implement QSocketNotifier. |
| 216 | \omitvalue SockClose |
| 217 | \value StateMachineSignal A signal delivered to a state machine (QStateMachine::SignalEvent). |
| 218 | \value StateMachineWrapped The event is a wrapper for, i.e., contains, another event (QStateMachine::WrappedEvent). |
| 219 | \value StatusTip A status tip is requested (QStatusTipEvent). |
| 220 | \value StyleChange Widget's style has been changed. |
| 221 | \value TabletMove Wacom tablet move (QTabletEvent). |
| 222 | \value TabletPress Wacom tablet press (QTabletEvent). |
| 223 | \value TabletRelease Wacom tablet release (QTabletEvent). |
| 224 | \omitvalue OkRequest |
| 225 | \value TabletEnterProximity Wacom tablet enter proximity event (QTabletEvent), sent to QApplication. |
| 226 | \value TabletLeaveProximity Wacom tablet leave proximity event (QTabletEvent), sent to QApplication. |
| 227 | \value TabletTrackingChange The Wacom tablet tracking state has changed (since Qt 5.9). |
| 228 | \omitvalue ThemeChange |
| 229 | \value ThreadChange The object is moved to another thread. This is the last event sent to this object in the previous thread. See QObject::moveToThread(). |
| 230 | \value Timer Regular timer events (QTimerEvent). |
| 231 | \value ToolBarChange The toolbar button is toggled on \macos. |
| 232 | \value ToolTip A tooltip was requested (QHelpEvent). |
| 233 | \value ToolTipChange The widget's tooltip has changed. |
| 234 | \value TouchBegin Beginning of a sequence of touch-screen or track-pad events (QTouchEvent). |
| 235 | \value TouchCancel Cancellation of touch-event sequence (QTouchEvent). |
| 236 | \value TouchEnd End of touch-event sequence (QTouchEvent). |
| 237 | \value TouchUpdate Touch-screen event (QTouchEvent). |
| 238 | \value UngrabKeyboard Item loses keyboard grab (QGraphicsItem only). |
| 239 | \value UngrabMouse Item loses mouse grab (QGraphicsItem, QQuickItem). |
| 240 | \value UpdateLater The widget should be queued to be repainted at a later time. |
| 241 | \value UpdateRequest The widget should be repainted. |
| 242 | \value WhatsThis The widget should reveal "What's This?" help (QHelpEvent). |
| 243 | \value WhatsThisClicked A link in a widget's "What's This?" help was clicked. |
| 244 | \value Wheel Mouse wheel rolled (QWheelEvent). |
| 245 | \value WinEventAct A Windows-specific activation event has occurred. |
| 246 | \value WindowActivate Window was activated. |
| 247 | \value WindowBlocked The window is blocked by a modal dialog. |
| 248 | \value WindowDeactivate Window was deactivated. |
| 249 | \value WindowIconChange The window's icon has changed. |
| 250 | \value WindowStateChange The \l{QWindow::windowState()}{window's state} (minimized, maximized or full-screen) has changed (QWindowStateChangeEvent). |
| 251 | \value WindowTitleChange The window title has changed. |
| 252 | \value WindowUnblocked The window is unblocked after a modal dialog exited. |
| 253 | \value WinIdChange The window system identifer for this native widget has changed. |
| 254 | \value ZOrderChange The widget's z-order has changed. This event is never sent to top level windows. |
| 255 | |
| 256 | User events should have values between \c User and \c{MaxUser}: |
| 257 | |
| 258 | \value User User-defined event. |
| 259 | \value MaxUser Last user event ID. |
| 260 | |
| 261 | For convenience, you can use the registerEventType() function to |
| 262 | register and reserve a custom event type for your |
| 263 | application. Doing so will allow you to avoid accidentally |
| 264 | re-using a custom event type already in use elsewhere in your |
| 265 | application. |
| 266 | |
| 267 | \omitvalue AcceptDropsChange |
| 268 | \omitvalue ActivateControl |
| 269 | \omitvalue Create |
| 270 | \omitvalue DeactivateControl |
| 271 | \omitvalue Destroy |
| 272 | \omitvalue DragResponse |
| 273 | \omitvalue EmbeddingControl |
| 274 | \omitvalue HelpRequest |
| 275 | \omitvalue Quit |
| 276 | \omitvalue ShowWindowRequest |
| 277 | \omitvalue Speech |
| 278 | \omitvalue Style |
| 279 | \omitvalue StyleAnimationUpdate |
| 280 | \omitvalue ZeroTimerEvent |
| 281 | \omitvalue ApplicationActivate |
| 282 | \omitvalue ApplicationActivated |
| 283 | \omitvalue ApplicationDeactivate |
| 284 | \omitvalue ApplicationDeactivated |
| 285 | \omitvalue MacGLWindowChange |
| 286 | \omitvalue NetworkReplyUpdated |
| 287 | \omitvalue FutureCallOut |
| 288 | \omitvalue NativeGesture |
| 289 | \omitvalue WindowChangeInternal |
| 290 | \omitvalue ScreenChangeInternal |
| 291 | */ |
| 292 | |
| 293 | /*! |
| 294 | Contructs an event object of type \a type. |
| 295 | */ |
| 296 | QEvent::QEvent(Type type) |
| 297 | : d(nullptr), t(type), posted(false), spont(false), m_accept(true), m_inputEvent(false), m_pointerEvent(false) |
| 298 | { |
| 299 | Q_TRACE(QEvent_ctor, this, t); |
| 300 | } |
| 301 | |
| 302 | /*! |
| 303 | \internal |
| 304 | Copies the \a other event. |
| 305 | */ |
| 306 | QEvent::QEvent(const QEvent &other) |
| 307 | : d(other.d), t(other.t), posted(other.posted), spont(other.spont), |
| 308 | m_accept(other.m_accept), m_inputEvent(other.m_inputEvent), m_pointerEvent(other.m_pointerEvent) |
| 309 | { |
| 310 | Q_TRACE(QEvent_ctor, this, t); |
| 311 | // if QEventPrivate becomes available, make sure to implement a |
| 312 | // virtual QEventPrivate *clone() const; function so we can copy here |
| 313 | Q_ASSERT_X(!d, "QEvent" , "Impossible, this can't happen: QEventPrivate isn't defined anywhere" ); |
| 314 | } |
| 315 | |
| 316 | /*! |
| 317 | \internal |
| 318 | \since 6.0 |
| 319 | \fn QEvent::QEvent(Type type, QEvent::InputEventTag) |
| 320 | |
| 321 | Constructs an event object of type \a type, setting the inputEvent flag to \c true. |
| 322 | */ |
| 323 | |
| 324 | /*! |
| 325 | \internal |
| 326 | \since 6.0 |
| 327 | \fn QEvent::QEvent(Type type, QEvent::PointerEventTag) |
| 328 | |
| 329 | Constructs an event object of type \a type, setting the pointerEvent and |
| 330 | inputEvent flags to \c true. |
| 331 | */ |
| 332 | |
| 333 | /*! |
| 334 | \internal |
| 335 | Attempts to copy the \a other event. |
| 336 | |
| 337 | Copying events is a bad idea, yet some Qt 4 code does it (notably, |
| 338 | QApplication and the state machine). |
| 339 | */ |
| 340 | QEvent &QEvent::operator=(const QEvent &other) |
| 341 | { |
| 342 | // if QEventPrivate becomes available, make sure to implement a |
| 343 | // virtual QEventPrivate *clone() const; function so we can copy here |
| 344 | Q_ASSERT_X(!other.d, "QEvent" , "Impossible, this can't happen: QEventPrivate isn't defined anywhere" ); |
| 345 | |
| 346 | t = other.t; |
| 347 | posted = other.posted; |
| 348 | spont = other.spont; |
| 349 | m_accept = other.m_accept; |
| 350 | return *this; |
| 351 | } |
| 352 | |
| 353 | /*! |
| 354 | Destroys the event. If it was \l{QCoreApplication::postEvent()}{posted}, |
| 355 | it will be removed from the list of events to be posted. |
| 356 | */ |
| 357 | |
| 358 | QEvent::~QEvent() |
| 359 | { |
| 360 | Q_TRACE(QEvent_dtor, this, t); |
| 361 | if (posted && QCoreApplication::instance()) |
| 362 | QCoreApplicationPrivate::removePostedEvent(this); |
| 363 | Q_ASSERT_X(!d, "QEvent" , "Impossible, this can't happen: QEventPrivate isn't defined anywhere" ); |
| 364 | } |
| 365 | |
| 366 | |
| 367 | /*! |
| 368 | \property QEvent::accepted |
| 369 | the accept flag of the event object |
| 370 | |
| 371 | Setting the accept parameter indicates that the event receiver |
| 372 | wants the event. Unwanted events might be propagated to the parent |
| 373 | widget. By default, isAccepted() is set to true, but don't rely on |
| 374 | this as subclasses may choose to clear it in their constructor. |
| 375 | |
| 376 | For convenience, the accept flag can also be set with accept(), |
| 377 | and cleared with ignore(). |
| 378 | |
| 379 | \note Accepting a QPointerEvent implicitly |
| 380 | \l {QEventPoint::setAccepted()}{accepts} all the |
| 381 | \l {QPointerEvent::points()}{points} that the event carries. |
| 382 | */ |
| 383 | |
| 384 | /*! |
| 385 | \fn void QEvent::accept() |
| 386 | |
| 387 | Sets the accept flag of the event object, the equivalent of |
| 388 | calling setAccepted(true). |
| 389 | |
| 390 | Setting the accept parameter indicates that the event receiver |
| 391 | wants the event. Unwanted events might be propagated to the parent |
| 392 | widget. |
| 393 | |
| 394 | \sa ignore() |
| 395 | */ |
| 396 | |
| 397 | |
| 398 | /*! |
| 399 | \fn void QEvent::ignore() |
| 400 | |
| 401 | Clears the accept flag parameter of the event object, the |
| 402 | equivalent of calling setAccepted(false). |
| 403 | |
| 404 | Clearing the accept parameter indicates that the event receiver |
| 405 | does not want the event. Unwanted events might be propagated to the |
| 406 | parent widget. |
| 407 | |
| 408 | \sa accept() |
| 409 | */ |
| 410 | |
| 411 | |
| 412 | /*! |
| 413 | \fn QEvent::Type QEvent::type() const |
| 414 | |
| 415 | Returns the event type. |
| 416 | */ |
| 417 | |
| 418 | /*! |
| 419 | \fn bool QEvent::spontaneous() const |
| 420 | |
| 421 | Returns \c true if the event originated outside the application (a |
| 422 | system event); otherwise returns \c false. |
| 423 | */ |
| 424 | |
| 425 | /*! |
| 426 | \fn bool QEvent::isInputEvent() const |
| 427 | \since 6.0 |
| 428 | |
| 429 | Returns \c true if the event object is a QInputEvent or one of its |
| 430 | subclasses. |
| 431 | */ |
| 432 | |
| 433 | /*! |
| 434 | \fn bool QEvent::isPointerEvent() const |
| 435 | \since 6.0 |
| 436 | |
| 437 | Returns \c true if the event object is a QPointerEvent or one of its |
| 438 | subclasses. |
| 439 | */ |
| 440 | |
| 441 | namespace { |
| 442 | template <size_t N> |
| 443 | struct QBasicAtomicBitField { |
| 444 | enum { |
| 445 | BitsPerInt = std::numeric_limits<uint>::digits, |
| 446 | NumInts = (N + BitsPerInt - 1) / BitsPerInt, |
| 447 | NumBits = N |
| 448 | }; |
| 449 | |
| 450 | // This atomic int points to the next (possibly) free ID saving |
| 451 | // the otherwise necessary scan through 'data': |
| 452 | QBasicAtomicInteger<uint> next; |
| 453 | QBasicAtomicInteger<uint> data[NumInts]; |
| 454 | |
| 455 | bool allocateSpecific(int which) noexcept |
| 456 | { |
| 457 | QBasicAtomicInteger<uint> &entry = data[which / BitsPerInt]; |
| 458 | const uint old = entry.loadRelaxed(); |
| 459 | const uint bit = 1U << (which % BitsPerInt); |
| 460 | return !(old & bit) // wasn't taken |
| 461 | && entry.testAndSetRelaxed(old, old | bit); // still wasn't taken |
| 462 | |
| 463 | // don't update 'next' here - it's unlikely that it will need |
| 464 | // to be updated, in the general case, and having 'next' |
| 465 | // trailing a bit is not a problem, as it is just a starting |
| 466 | // hint for allocateNext(), which, when wrong, will just |
| 467 | // result in a few more rounds through the allocateNext() |
| 468 | // loop. |
| 469 | } |
| 470 | |
| 471 | int allocateNext() noexcept |
| 472 | { |
| 473 | // Unroll loop to iterate over ints, then bits? Would save |
| 474 | // potentially a lot of cmpxchgs, because we can scan the |
| 475 | // whole int before having to load it again. |
| 476 | |
| 477 | // Then again, this should never execute many iterations, so |
| 478 | // leave like this for now: |
| 479 | for (uint i = next.loadRelaxed(); i < NumBits; ++i) { |
| 480 | if (allocateSpecific(i)) { |
| 481 | // remember next (possibly) free id: |
| 482 | const uint oldNext = next.loadRelaxed(); |
| 483 | next.testAndSetRelaxed(oldNext, qMax(i + 1, oldNext)); |
| 484 | return i; |
| 485 | } |
| 486 | } |
| 487 | return -1; |
| 488 | } |
| 489 | }; |
| 490 | |
| 491 | } // unnamed namespace |
| 492 | |
| 493 | typedef QBasicAtomicBitField<QEvent::MaxUser - QEvent::User + 1> UserEventTypeRegistry; |
| 494 | |
| 495 | static UserEventTypeRegistry userEventTypeRegistry; |
| 496 | |
| 497 | static inline int registerEventTypeZeroBased(int id) noexcept |
| 498 | { |
| 499 | // if the type hint hasn't been registered yet, take it: |
| 500 | if (id < UserEventTypeRegistry::NumBits && id >= 0 && userEventTypeRegistry.allocateSpecific(id)) |
| 501 | return id; |
| 502 | |
| 503 | // otherwise, ignore hint: |
| 504 | return userEventTypeRegistry.allocateNext(); |
| 505 | } |
| 506 | |
| 507 | /*! |
| 508 | \since 4.4 |
| 509 | \threadsafe |
| 510 | |
| 511 | Registers and returns a custom event type. The \a hint provided |
| 512 | will be used if it is available, otherwise it will return a value |
| 513 | between QEvent::User and QEvent::MaxUser that has not yet been |
| 514 | registered. The \a hint is ignored if its value is not between |
| 515 | QEvent::User and QEvent::MaxUser. |
| 516 | |
| 517 | Returns -1 if all available values are already taken or the |
| 518 | program is shutting down. |
| 519 | */ |
| 520 | int QEvent::registerEventType(int hint) noexcept |
| 521 | { |
| 522 | const int result = registerEventTypeZeroBased(QEvent::MaxUser - hint); |
| 523 | return result < 0 ? -1 : QEvent::MaxUser - result ; |
| 524 | } |
| 525 | |
| 526 | /*! |
| 527 | \class QTimerEvent |
| 528 | \inmodule QtCore |
| 529 | \brief The QTimerEvent class contains parameters that describe a |
| 530 | timer event. |
| 531 | |
| 532 | \ingroup events |
| 533 | |
| 534 | Timer events are sent at regular intervals to objects that have |
| 535 | started one or more timers. Each timer has a unique identifier. A |
| 536 | timer is started with QObject::startTimer(). |
| 537 | |
| 538 | The QTimer class provides a high-level programming interface that |
| 539 | uses signals instead of events. It also provides single-shot timers. |
| 540 | |
| 541 | The event handler QObject::timerEvent() receives timer events. |
| 542 | |
| 543 | \sa QTimer, QObject::timerEvent(), QObject::startTimer(), |
| 544 | QObject::killTimer() |
| 545 | */ |
| 546 | |
| 547 | /*! |
| 548 | Constructs a timer event object with the timer identifier set to |
| 549 | \a timerId. |
| 550 | */ |
| 551 | QTimerEvent::QTimerEvent(int timerId) |
| 552 | : QEvent(Timer), id(timerId) |
| 553 | {} |
| 554 | |
| 555 | /*! |
| 556 | \internal |
| 557 | */ |
| 558 | QTimerEvent::~QTimerEvent() |
| 559 | { |
| 560 | } |
| 561 | |
| 562 | /*! |
| 563 | \fn int QTimerEvent::timerId() const |
| 564 | |
| 565 | Returns the unique timer identifier, which is the same identifier |
| 566 | as returned from QObject::startTimer(). |
| 567 | */ |
| 568 | |
| 569 | /*! |
| 570 | \class QChildEvent |
| 571 | \inmodule QtCore |
| 572 | \brief The QChildEvent class contains event parameters for child object |
| 573 | events. |
| 574 | |
| 575 | \ingroup events |
| 576 | |
| 577 | Child events are sent immediately to objects when children are |
| 578 | added or removed. |
| 579 | |
| 580 | In both cases you can only rely on the child being a QObject (or, |
| 581 | if QObject::isWidgetType() returns \c true, a QWidget). This is |
| 582 | because in the QEvent::ChildAdded case the child is not yet fully |
| 583 | constructed; in the QEvent::ChildRemoved case it might have |
| 584 | already been destructed. |
| 585 | |
| 586 | The handler for these events is QObject::childEvent(). |
| 587 | */ |
| 588 | |
| 589 | /*! |
| 590 | Constructs a child event object of a particular \a type for the |
| 591 | \a child. |
| 592 | |
| 593 | \a type can be QEvent::ChildAdded, QEvent::ChildRemoved, |
| 594 | or QEvent::ChildPolished. |
| 595 | |
| 596 | \sa child() |
| 597 | */ |
| 598 | QChildEvent::QChildEvent(Type type, QObject *child) |
| 599 | : QEvent(type), c(child) |
| 600 | {} |
| 601 | |
| 602 | /*! |
| 603 | \internal |
| 604 | */ |
| 605 | QChildEvent::~QChildEvent() |
| 606 | { |
| 607 | } |
| 608 | |
| 609 | /*! |
| 610 | \fn QObject *QChildEvent::child() const |
| 611 | |
| 612 | Returns the child object that was added or removed. |
| 613 | */ |
| 614 | |
| 615 | /*! |
| 616 | \fn bool QChildEvent::added() const |
| 617 | |
| 618 | Returns \c true if type() is QEvent::ChildAdded; otherwise returns |
| 619 | false. |
| 620 | */ |
| 621 | |
| 622 | /*! |
| 623 | \fn bool QChildEvent::removed() const |
| 624 | |
| 625 | Returns \c true if type() is QEvent::ChildRemoved; otherwise returns |
| 626 | false. |
| 627 | */ |
| 628 | |
| 629 | /*! |
| 630 | \fn bool QChildEvent::polished() const |
| 631 | |
| 632 | Returns \c true if type() is QEvent::ChildPolished; otherwise returns |
| 633 | false. |
| 634 | */ |
| 635 | |
| 636 | |
| 637 | /*! |
| 638 | \class QDynamicPropertyChangeEvent |
| 639 | \inmodule QtCore |
| 640 | \since 4.2 |
| 641 | \brief The QDynamicPropertyChangeEvent class contains event parameters for dynamic |
| 642 | property change events. |
| 643 | |
| 644 | \ingroup events |
| 645 | |
| 646 | Dynamic property change events are sent to objects when properties are |
| 647 | dynamically added, changed or removed using QObject::setProperty(). |
| 648 | */ |
| 649 | |
| 650 | /*! |
| 651 | Constructs a dynamic property change event object with the property name set to |
| 652 | \a name. |
| 653 | */ |
| 654 | QDynamicPropertyChangeEvent::QDynamicPropertyChangeEvent(const QByteArray &name) |
| 655 | : QEvent(QEvent::DynamicPropertyChange), n(name) |
| 656 | { |
| 657 | } |
| 658 | |
| 659 | /*! |
| 660 | \internal |
| 661 | */ |
| 662 | QDynamicPropertyChangeEvent::~QDynamicPropertyChangeEvent() |
| 663 | { |
| 664 | } |
| 665 | |
| 666 | /*! |
| 667 | \fn QByteArray QDynamicPropertyChangeEvent::propertyName() const |
| 668 | |
| 669 | Returns the name of the dynamic property that was added, changed or |
| 670 | removed. |
| 671 | |
| 672 | \sa QObject::setProperty(), QObject::dynamicPropertyNames() |
| 673 | */ |
| 674 | |
| 675 | /*! |
| 676 | Constructs a deferred delete event with an initial loopLevel() of zero. |
| 677 | */ |
| 678 | QDeferredDeleteEvent::QDeferredDeleteEvent() |
| 679 | : QEvent(QEvent::DeferredDelete) |
| 680 | , level(0) |
| 681 | { } |
| 682 | |
| 683 | /*! |
| 684 | \internal |
| 685 | */ |
| 686 | QDeferredDeleteEvent::~QDeferredDeleteEvent() |
| 687 | { } |
| 688 | |
| 689 | /*! \fn int QDeferredDeleteEvent::loopLevel() const |
| 690 | |
| 691 | Returns the loop-level in which the event was posted. The |
| 692 | loop-level is set by QCoreApplication::postEvent(). |
| 693 | |
| 694 | \sa QObject::deleteLater() |
| 695 | */ |
| 696 | |
| 697 | QT_END_NAMESPACE |
| 698 | |
| 699 | #include "moc_qcoreevent.cpp" |
| 700 | |