~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/corelib/kernel/qcoreevent.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the core module of the Qt Toolkit.
 
6
**
 
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.
 
10
**
 
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.
 
15
**
 
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.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
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.
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
#include "qcoreevent.h"
 
30
#include "qcoreapplication.h"
 
31
#include "qcoreapplication_p.h"
 
32
 
 
33
/*!
 
34
    \class QEvent
 
35
    \brief The QEvent class is the base class of all
 
36
    event classes. Event objects contain event parameters.
 
37
 
 
38
    \ingroup events
 
39
    \ingroup environment
 
40
 
 
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.
 
44
 
 
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).
 
49
 
 
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.
 
57
 
 
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.
 
62
 
 
63
    Subclasses of QEvent contain additional parameters that describe
 
64
    the particular event.
 
65
 
 
66
    \sa QObject::event(), QObject::installEventFilter(),
 
67
        QWidget::event(), QCoreApplication::sendEvent(),
 
68
        QCoreApplication::postEvent(), QCoreApplication::processEvents()
 
69
*/
 
70
 
 
71
 
 
72
/*!
 
73
    \enum QEvent::Type
 
74
 
 
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:
 
77
 
 
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.
 
168
 
 
169
    User events should have values between \c User and \c{MaxUser}:
 
170
 
 
171
    \value User                             User-defined event.
 
172
    \value MaxUser                          Last user event ID.
 
173
 
 
174
    \omitvalue Accel
 
175
    \omitvalue AccelAvailable
 
176
    \omitvalue AccelOverride
 
177
    \omitvalue ActivateControl
 
178
    \omitvalue CaptionChange
 
179
    \omitvalue ChildInserted
 
180
    \omitvalue Create
 
181
    \omitvalue DeactivateControl
 
182
    \omitvalue Destroy
 
183
    \omitvalue DragResponse
 
184
    \omitvalue EmbeddingControl
 
185
    \omitvalue HelpRequest
 
186
    \omitvalue IconChange
 
187
    \omitvalue LayoutHint
 
188
    \omitvalue OkRequest
 
189
    \omitvalue QWSUpdate
 
190
    \omitvalue Quit
 
191
    \omitvalue Reparent
 
192
    \omitvalue ShowWindowRequest
 
193
    \omitvalue Speech
 
194
    \omitvalue Style
 
195
    \omitvalue ThreadChange
 
196
*/
 
197
 
 
198
/*!
 
199
    Contructs an event object of type \a type.
 
200
*/
 
201
QEvent::QEvent(Type type)
 
202
    : d(0), t(type), posted(false), spont(false), m_accept(true)
 
203
{}
 
204
 
 
205
/*!
 
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.
 
209
*/
 
210
 
 
211
QEvent::~QEvent()
 
212
{
 
213
    if (posted && QCoreApplication::instance())
 
214
        QCoreApplicationPrivate::removePostedEvent(this);
 
215
}
 
216
 
 
217
 
 
218
/*!
 
219
    \property  QEvent::accepted
 
220
    the accept flag of the event object
 
221
 
 
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.
 
226
 
 
227
    For convenience, the accept flag can also be set with accept(),
 
228
    and cleared with ignore().
 
229
*/
 
230
 
 
231
/*!
 
232
    \fn void QEvent::accept()
 
233
 
 
234
    Sets the accept flag of the event object, the equivalent of
 
235
    callign setAccepted(true).
 
236
 
 
237
    Setting the accept parameter indicates that the event receiver
 
238
    wants the event. Unwanted events might be propagated to the parent
 
239
    widget.
 
240
 
 
241
    \sa ignore()
 
242
*/
 
243
 
 
244
 
 
245
/*!
 
246
    \fn void QEvent::ignore()
 
247
 
 
248
    Clears the accept flag parameter of the event object, the
 
249
    equivalent of calling setAccepted(false).
 
250
 
 
251
    Clearing the accept parameter indicates that the event receiver
 
252
    does not want the event. Unwanted events might be propgated to the
 
253
    parent widget.
 
254
 
 
255
    \sa accept()
 
256
*/
 
257
 
 
258
 
 
259
/*!
 
260
    \fn QEvent::Type QEvent::type() const
 
261
 
 
262
    Returns the event type.
 
263
*/
 
264
 
 
265
/*!
 
266
    \fn bool QEvent::spontaneous() const
 
267
 
 
268
    Returns true if the event originated outside the application (a
 
269
    system event); otherwise returns false.
 
270
 
 
271
    As an exception, paint events generated by Qt as a result of
 
272
    calling QWidget::repaint() are also considered spontaneous.
 
273
*/
 
274
 
 
275
 
 
276
/*!
 
277
    \class QTimerEvent qcoreevent.h
 
278
    \brief The QTimerEvent class contains parameters that describe a
 
279
    timer event.
 
280
 
 
281
    \ingroup events
 
282
 
 
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().
 
286
 
 
287
    The QTimer class provides a high-level programming interface that
 
288
    uses signals instead of events. It also provides single-shot timers.
 
289
 
 
290
    The event handler QObject::timerEvent() receives timer events.
 
291
 
 
292
    \sa QTimer, QObject::timerEvent(), QObject::startTimer(),
 
293
    QObject::killTimer()
 
294
*/
 
295
 
 
296
/*!
 
297
    Constructs a timer event object with the timer identifier set to
 
298
    \a timerId.
 
299
*/
 
300
QTimerEvent::QTimerEvent(int timerId)
 
301
    : QEvent(Timer), id(timerId)
 
302
{}
 
303
 
 
304
/*! \internal
 
305
*/
 
306
QTimerEvent::~QTimerEvent()
 
307
{
 
308
}
 
309
 
 
310
/*!
 
311
    \fn int QTimerEvent::timerId() const
 
312
 
 
313
    Returns the unique timer identifier, which is the same identifier
 
314
    as returned from QObject::startTimer().
 
315
*/
 
316
 
 
317
/*!
 
318
    \class QChildEvent
 
319
    \brief The QChildEvent class contains event parameters for child object
 
320
    events.
 
321
 
 
322
    \ingroup events
 
323
 
 
324
    Child events are sent immediately to objects when children are
 
325
    added or removed.
 
326
 
 
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.
 
332
 
 
333
    The handler for these events is QObject::childEvent().
 
334
*/
 
335
 
 
336
/*!
 
337
    Constructs a child event object of a particular \a type for the
 
338
    \a child.
 
339
 
 
340
    \a type can be QEvent::ChildAdded, QEvent::ChildRemoved,
 
341
    QEvent::ChildPolished, or QEvent::ChildRemoved.
 
342
 
 
343
    \sa child()
 
344
*/
 
345
QChildEvent::QChildEvent(Type type, QObject *child)
 
346
    : QEvent(type), c(child)
 
347
{}
 
348
 
 
349
/*! \internal
 
350
*/
 
351
QChildEvent::~QChildEvent()
 
352
{
 
353
}
 
354
 
 
355
/*!
 
356
    \fn QObject *QChildEvent::child() const
 
357
 
 
358
    Returns the child object that was added or removed.
 
359
*/
 
360
 
 
361
/*!
 
362
    \fn bool QChildEvent::added() const
 
363
 
 
364
    Returns true if type() is QEvent::ChildAdded; otherwise returns
 
365
    false.
 
366
*/
 
367
 
 
368
/*!
 
369
    \fn bool QChildEvent::removed() const
 
370
 
 
371
    Returns true if type() is QEvent::ChildRemoved; otherwise returns
 
372
    false.
 
373
*/
 
374
 
 
375
/*!
 
376
    \fn bool QChildEvent::polished() const
 
377
 
 
378
    Returns true if type() is QEvent::ChildPolished; otherwise returns
 
379
    false.
 
380
*/
 
381
 
 
382
/*!
 
383
    \class QCustomEvent
 
384
    \brief The QCustomEvent class provides support for custom events.
 
385
 
 
386
    \compat
 
387
 
 
388
    QCustomEvent has a \c{void *} that can be used to store custom
 
389
    data.
 
390
 
 
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
 
394
    \c{void *}.
 
395
 
 
396
    In Qt 4, QObject::customEvent() takes a plain QEvent pointer.
 
397
    You can add custom data by subclassing.
 
398
 
 
399
    \sa QObject::customEvent(), QCoreApplication::notify()
 
400
*/
 
401
 
 
402
/*!
 
403
    \fn QCustomEvent::QCustomEvent(int type, void *data)
 
404
 
 
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.
 
408
*/
 
409
#ifdef QT3_SUPPORT
 
410
QCustomEvent::QCustomEvent(int type, void *data)
 
411
    : QEvent(static_cast<Type>(type))
 
412
{
 
413
    d = reinterpret_cast<QEventPrivate *>(data);
 
414
}
 
415
 
 
416
/*! \internal
 
417
*/
 
418
QCustomEvent::~QCustomEvent()
 
419
{
 
420
}
 
421
#endif
 
422
/*!
 
423
    \fn void QCustomEvent::setData(void *data)
 
424
 
 
425
    \compat
 
426
 
 
427
    Sets the generic data pointer to \a data.
 
428
 
 
429
    \sa data()
 
430
*/
 
431
 
 
432
/*!
 
433
    \fn void *QCustomEvent::data() const
 
434
 
 
435
    \compat
 
436
 
 
437
    Returns a pointer to the generic event data.
 
438
 
 
439
    \sa setData()
 
440
*/
 
441
 
 
442
/*!
 
443
    \fn bool QChildEvent::inserted() const
 
444
 
 
445
    \compat
 
446
 
 
447
    A child has been inserted if the event's type() is ChildInserted.
 
448
*/
 
449
 
 
450