1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the core module of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
29
#include "qcoreevent.h"
30
#include "qcoreapplication.h"
31
#include "qcoreapplication_p.h"
35
\brief The QEvent class is the base class of all
36
event classes. Event objects contain event parameters.
41
Qt's main event loop (QCoreApplication::exec()) fetches native
42
window system events from the event queue, translates them into
43
QEvents, and sends the translated events to \l{QObject}s.
45
In general, events come from the underlying window system
46
(spontaneous() returns true), but it is also possible to manually
47
send events using QCoreApplication::sendEvent() and
48
QCoreApplication::postEvent() (spontaneous() returns false).
50
QObjects receive events by having their QObject::event() function
51
called. The function can be reimplemented in subclasses to
52
customize event handling and add additional event types;
53
QWidget::event() is a notable example. By default, events are
54
dispatched to event handlers like QObject::timerEvent() and
55
QWidget::mouseMoveEvent(). QObject::installEventFilter() allows an
56
object to intercept events destined for another object.
58
The basic QEvent contains only an event type parameter and an
59
"accept" flag. The accept flag set with accept(), and cleared
60
with ignore(). It is set by default, but don't rely on this as
61
subclasses may choose to clear it in their constructor.
63
Subclasses of QEvent contain additional parameters that describe
66
\sa QObject::event(), QObject::installEventFilter(),
67
QWidget::event(), QCoreApplication::sendEvent(),
68
QCoreApplication::postEvent(), QCoreApplication::processEvents()
75
This enum type defines the valid event types in Qt. The event
76
types and the specialized classes for each type are as follows:
78
\value None Not an event.
79
\value AccessibilityDescription Used to query accessibility description texts (QAccessibleEvent).
80
\value AccessibilityHelp Used to query accessibility help texts (QAccessibleEvent).
81
\value AccessibilityPrepare Accessibility information is requested.
82
\value ActionAdded A new action has been added (QActionEvent).
83
\value ActionChanged An action has been changed (QActionEvent).
84
\value ActionRemoved An action has been removed (QActionEvent).
85
\value ActivationChange A widget's top-level window activation state has changed.
86
\value ApplicationActivated The application has been made available to the user.
87
\value ApplicationDeactivated The application has been suspended, and is unavailable to the user.
88
\value ApplicationFontChange The default application font has changed.
89
\value ApplicationLayoutDirectionChange The default application layout direction has changed.
90
\value ApplicationPaletteChange The default application palette has changed.
91
\value ApplicationWindowIconChange The application's icon has changed.
92
\value ChildAdded An object gets a child (QChildEvent).
93
\value ChildPolished A widget child gets polished (QChildEvent).
94
\value ChildRemoved An object loses a child (QChildEvent).
95
\value Clipboard The clipboard contents have changed (QClipboardEvent).
96
\value Close Widget was closed (QCloseEvent).
97
\value ContextMenu Context popup menu (QContextMenuEvent).
98
\value DeferredDelete The object will be deleted after it has cleaned up.
99
\value DragEnter The cursor enters a widget during a drag and drop action (QDragEnterEvent).
100
\value DragLeave The cursor leaves a widget during a drag and drop action (QDragLeaveEvent).
101
\value DragMove A drag and drop action is in progress (QDragMoveEvent).
102
\value Drop A drag and drop action is completed (QDropEvent).
103
\value EnabledChange Widget's enabled state has changed.
104
\value Enter Mouse enters widget's boundaries.
105
\value EnterWhatsThisMode Send to toplevel widgets when the application enters "What's This?" mode.
106
\value FileOpen File open request (QFileOpenEvent).
107
\value FocusIn Widget gains keyboard focus (QFocusEvent).
108
\value FocusOut Widget loses keyboard focus (QFocusEvent).
109
\value FontChange Widget's font has changed.
110
\value Hide Widget was hidden (QHideEvent).
111
\value HideToParent A child widget has been hidden.
112
\value HoverEnter The mouse cursor enters a hover widget (QHoverEvent).
113
\value HoverLeave The mouse cursor leaves a hover widget (QHoverEvent).
114
\value HoverMove The mouse cursor moves inside a hover widget (QHoverEvent).
115
\value IconDrag The main icon of a window has been dragged away (QIconDragEvent).
116
\value IconTextChange Widget's icon text has been changed.
117
\value InputMethod An input method is being used (QInputMethodEvent).
118
\value KeyPress Key press (QKeyEvent).
119
\value KeyRelease Key release (QKeyEvent).
120
\value LanguageChange The application translation changed.
121
\value LayoutDirectionChange The direction of layouts changed.
122
\value LayoutRequest Widget layout needs to be redone.
123
\value Leave Mouse leaves widget's boundaries.
124
\value LeaveWhatsThisMode Send to toplevel widgets when the application leaves "What's This?" mode.
125
\value LocaleChange The system locale has changed.
126
\value MetaCall An asynchronous method invocation via QMetaObject::invokeMethod().
127
\value ModifiedChange Widgets modification state has been changed.
128
\value MouseButtonDblClick Mouse press again (QMouseEvent).
129
\value MouseButtonPress Mouse press (QMouseEvent).
130
\value MouseButtonRelease Mouse release (QMouseEvent).
131
\value MouseMove Mouse move (QMouseEvent).
132
\value MouseTrackingChange The mouse tracking state has changed.
133
\value Move Widget's position changed (QMoveEvent).
134
\value Paint Screen update necessary (QPaintEvent).
135
\value PaletteChange Palette of the widget changed.
136
\value ParentAboutToChange The widget parent is about to change.
137
\value ParentChange The widget parent has changed.
138
\value Polish The widget is polished.
139
\value PolishRequest The widget should be polished.
140
\value QueryWhatsThis The widget should accept the event if it has "What's This?" help.
141
\value Resize Widget's size changed (QResizeEvent).
142
\value Shortcut Key press in child for shortcut key handling (QShortcutEvent).
143
\value ShortcutOverride Key press in child, for overriding shortcut key handling (QKeyEvent).
144
\value Show Widget was shown on screen (QShowEvent).
145
\value ShowToParent A child widget has been shown.
146
\value SockAct Socket activated, used to implement QSocketNotifier.
147
\value StatusTip A status tip is requested (QStatusTipEvent).
148
\value StyleChange Widget's style has been changed.
149
\value TabletMove Wacom tablet move (QTabletEvent).
150
\value TabletPress Wacom tablet press (QTabletEvent).
151
\value TabletRelease Wacom tablet release (QTabletEvent).
152
\value Timer Regular timer events (QTimerEvent).
153
\value ToolBarChange The toolbar button is toggled on Mac OS X.
154
\value ToolTip A tooltip was requested (QHelpEvent).
155
\value UpdateRequest The widget should be repainted.
156
\value WhatsThis The widget should reveal "What's This?" help (QHelpEvent).
157
\value WhatsThisClicked A link in a widget's "What's This?" help was clicked.
158
\value Wheel Mouse wheel rolled (QWheelEvent).
159
\value WinEventAct A Windows-specific activation event has occurred.
160
\value WindowActivate Window was activated.
161
\value WindowBlocked The window is blocked by a modal dialog.
162
\value WindowDeactivate Window was deactivated.
163
\value WindowIconChange The window's icon has changed.
164
\value WindowStateChange The \l{QWidget::windowState()}{window's state} (minimized, maximized or full-screen) has changed (QWindowStateChangeEvent).
165
\value WindowTitleChange The window title has changed.
166
\value WindowUnblocked The window is unblocked after a modal dialog exited.
167
\value ZOrderChange The widget's z-order has changed. This event is never sent to top level windows.
169
User events should have values between \c User and \c{MaxUser}:
171
\value User User-defined event.
172
\value MaxUser Last user event ID.
175
\omitvalue AccelAvailable
176
\omitvalue AccelOverride
177
\omitvalue ActivateControl
178
\omitvalue CaptionChange
179
\omitvalue ChildInserted
181
\omitvalue DeactivateControl
183
\omitvalue DragResponse
184
\omitvalue EmbeddingControl
185
\omitvalue HelpRequest
186
\omitvalue IconChange
187
\omitvalue LayoutHint
192
\omitvalue ShowWindowRequest
195
\omitvalue ThreadChange
199
Contructs an event object of type \a type.
201
QEvent::QEvent(Type type)
202
: d(0), t(type), posted(false), spont(false), m_accept(true)
206
Destroys the event. If it was \link
207
QCoreApplication::postEvent() posted \endlink,
208
it will be removed from the list of events to be posted.
213
if (posted && QCoreApplication::instance())
214
QCoreApplicationPrivate::removePostedEvent(this);
219
\property QEvent::accepted
220
the accept flag of the event object
222
Setting the accept parameter indicates that the event receiver
223
wants the event. Unwanted events might be propagated to the parent
224
widget. By default, isAccepted() is set to true, but don't rely on
225
this as subclasses may choose to clear it in their constructor.
227
For convenience, the accept flag can also be set with accept(),
228
and cleared with ignore().
232
\fn void QEvent::accept()
234
Sets the accept flag of the event object, the equivalent of
235
callign setAccepted(true).
237
Setting the accept parameter indicates that the event receiver
238
wants the event. Unwanted events might be propagated to the parent
246
\fn void QEvent::ignore()
248
Clears the accept flag parameter of the event object, the
249
equivalent of calling setAccepted(false).
251
Clearing the accept parameter indicates that the event receiver
252
does not want the event. Unwanted events might be propgated to the
260
\fn QEvent::Type QEvent::type() const
262
Returns the event type.
266
\fn bool QEvent::spontaneous() const
268
Returns true if the event originated outside the application (a
269
system event); otherwise returns false.
271
As an exception, paint events generated by Qt as a result of
272
calling QWidget::repaint() are also considered spontaneous.
277
\class QTimerEvent qcoreevent.h
278
\brief The QTimerEvent class contains parameters that describe a
283
Timer events are sent at regular intervals to objects that have
284
started one or more timers. Each timer has a unique identifier. A
285
timer is started with QObject::startTimer().
287
The QTimer class provides a high-level programming interface that
288
uses signals instead of events. It also provides single-shot timers.
290
The event handler QObject::timerEvent() receives timer events.
292
\sa QTimer, QObject::timerEvent(), QObject::startTimer(),
297
Constructs a timer event object with the timer identifier set to
300
QTimerEvent::QTimerEvent(int timerId)
301
: QEvent(Timer), id(timerId)
306
QTimerEvent::~QTimerEvent()
311
\fn int QTimerEvent::timerId() const
313
Returns the unique timer identifier, which is the same identifier
314
as returned from QObject::startTimer().
319
\brief The QChildEvent class contains event parameters for child object
324
Child events are sent immediately to objects when children are
327
In both cases you can only rely on the child being a QObject (or,
328
if QObject::isWidgetType() returns true, a QWidget). This is
329
because in the QEvent::ChildAdded case the child is not yet fully
330
constructed; in the QEvent::ChildRemoved case it might have
331
already been destructed.
333
The handler for these events is QObject::childEvent().
337
Constructs a child event object of a particular \a type for the
340
\a type can be QEvent::ChildAdded, QEvent::ChildRemoved,
341
QEvent::ChildPolished, or QEvent::ChildRemoved.
345
QChildEvent::QChildEvent(Type type, QObject *child)
346
: QEvent(type), c(child)
351
QChildEvent::~QChildEvent()
356
\fn QObject *QChildEvent::child() const
358
Returns the child object that was added or removed.
362
\fn bool QChildEvent::added() const
364
Returns true if type() is QEvent::ChildAdded; otherwise returns
369
\fn bool QChildEvent::removed() const
371
Returns true if type() is QEvent::ChildRemoved; otherwise returns
376
\fn bool QChildEvent::polished() const
378
Returns true if type() is QEvent::ChildPolished; otherwise returns
384
\brief The QCustomEvent class provides support for custom events.
388
QCustomEvent has a \c{void *} that can be used to store custom
391
In Qt 3, QObject::customEvent() took a QCustomEvent pointer. We
392
found out that this approach was unsatisfactory, because
393
there was often no safe way of deleting the data held in the
396
In Qt 4, QObject::customEvent() takes a plain QEvent pointer.
397
You can add custom data by subclassing.
399
\sa QObject::customEvent(), QCoreApplication::notify()
403
\fn QCustomEvent::QCustomEvent(int type, void *data)
405
Constructs a custom event object with the event \a type and a
406
pointer to \a data. The value of \a type must be at least as
407
large as QEvent::User. By default, the data pointer is set to 0.
410
QCustomEvent::QCustomEvent(int type, void *data)
411
: QEvent(static_cast<Type>(type))
413
d = reinterpret_cast<QEventPrivate *>(data);
418
QCustomEvent::~QCustomEvent()
423
\fn void QCustomEvent::setData(void *data)
427
Sets the generic data pointer to \a data.
433
\fn void *QCustomEvent::data() const
437
Returns a pointer to the generic event data.
443
\fn bool QChildEvent::inserted() const
447
A child has been inserted if the event's type() is ChildInserted.