Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qcoreevent.h
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QCOREEVENT_H
5#define QCOREEVENT_H
6
7#include <QtCore/qbasictimer.h>
8#include <QtCore/qnamespace.h>
9#include <QtCore/qbytearray.h>
10#include <QtCore/qobjectdefs.h>
11
13
14#define Q_EVENT_DISABLE_COPY(Class) protected
15 :
16 Class(const Class &) = default;
17 Class(Class &&) = delete;
18 Class &operator=(const Class &other) = default;
19 Class &operator=(Class &&) = delete
20
21#define Q_DECL_EVENT_COMMON(Class)
22 protected:
23 Class(const Class &);
24 Class(Class &&) = delete;
25 Class &operator=(const Class &other) = default;
26 Class &operator=(Class &&) = delete;
27 public:
28 Class* clone() const override;
29 ~Class() override;
30 private:
31
32#define Q_IMPL_EVENT_COMMON(Class)
33 Class::Class(const Class &) = default;
34 Class::~Class() = default;
35 Class* Class::clone() const
36 {
37 auto c = new Class(*this);
38 [[maybe_unused]] QEvent *e = c;
39 /* check that covariant return is safe to add */
40 Q_ASSERT(reinterpret_cast<quintptr>(c) == reinterpret_cast<quintptr>(e));
41 return c;
42 }
43
44class QEventPrivate;
45class Q_CORE_EXPORT QEvent // event base class
46{
47 Q_GADGET
48 QDOC_PROPERTY(bool accepted READ isAccepted WRITE setAccepted)
49
51public:
52 enum Type {
53 /*
54 If you get a strange compiler error on the line with None,
55 it's probably because you're also including X11 headers,
56 which #define the symbol None. Put the X11 includes after
57 the Qt includes to solve this problem.
58 */
59 None = 0, // invalid event
60 Timer = 1, // timer event
61 MouseButtonPress = 2, // mouse button pressed
62 MouseButtonRelease = 3, // mouse button released
63 MouseButtonDblClick = 4, // mouse button double click
64 MouseMove = 5, // mouse move
65 KeyPress = 6, // key pressed
66 KeyRelease = 7, // key released
67 FocusIn = 8, // keyboard focus received
68 FocusOut = 9, // keyboard focus lost
69 FocusAboutToChange = 23, // keyboard focus is about to be lost
70 Enter = 10, // mouse enters widget
71 Leave = 11, // mouse leaves widget
72 Paint = 12, // paint widget
73 Move = 13, // move widget
74 Resize = 14, // resize widget
75 Create = 15, // after widget creation
76 Destroy = 16, // during widget destruction
77 Show = 17, // widget is shown
78 Hide = 18, // widget is hidden
79 Close = 19, // request to close widget
80 Quit = 20, // request to quit application
81 ParentChange = 21, // object has been reparented
82 ParentAboutToChange = 131, // sent just before the parent change is done
83 ThreadChange = 22, // object has changed threads
84 WindowActivate = 24, // window was activated
85 WindowDeactivate = 25, // window was deactivated
86 ShowToParent = 26, // widget is shown to parent
87 HideToParent = 27, // widget is hidden to parent
88 Wheel = 31, // wheel event
89 WindowTitleChange = 33, // window title changed
90 WindowIconChange = 34, // icon changed
91 ApplicationWindowIconChange = 35, // application icon changed
92 ApplicationFontChange = 36, // application font changed
93 ApplicationLayoutDirectionChange = 37, // application layout direction changed
94 ApplicationPaletteChange = 38, // application palette changed
95 PaletteChange = 39, // widget palette changed
96 Clipboard = 40, // internal clipboard event
97 Speech = 42, // reserved for speech input
98 MetaCall = 43, // meta call event
99 SockAct = 50, // socket activation
100 WinEventAct = 132, // win event activation
101 DeferredDelete = 52, // deferred delete event
102 DragEnter = 60, // drag moves into widget
103 DragMove = 61, // drag moves in widget
104 DragLeave = 62, // drag leaves or is cancelled
105 Drop = 63, // actual drop
106 DragResponse = 64, // drag accepted/rejected
107 ChildAdded = 68, // new child widget
108 ChildPolished = 69, // polished child widget
109 ChildRemoved = 71, // deleted child widget
110 ShowWindowRequest = 73, // widget's window should be mapped
111 PolishRequest = 74, // widget should be polished
112 Polish = 75, // widget is polished
113 LayoutRequest = 76, // widget should be relayouted
114 UpdateRequest = 77, // widget should be repainted
115 UpdateLater = 78, // request update() later
116
117 EmbeddingControl = 79, // ActiveX embedding
118 ActivateControl = 80, // ActiveX activation
119 DeactivateControl = 81, // ActiveX deactivation
120 ContextMenu = 82, // context popup menu
121 InputMethod = 83, // input method
122 TabletMove = 87, // Wacom tablet event
123 LocaleChange = 88, // the system locale changed
124 LanguageChange = 89, // the application language changed
125 LayoutDirectionChange = 90, // the layout direction changed
126 Style = 91, // internal style event
127 TabletPress = 92, // tablet press
128 TabletRelease = 93, // tablet release
129 OkRequest = 94, // CE (Ok) button pressed
130 HelpRequest = 95, // CE (?) button pressed
131
132 IconDrag = 96, // proxy icon dragged
133
134 FontChange = 97, // font has changed
135 EnabledChange = 98, // enabled state has changed
136 ActivationChange = 99, // window activation has changed
137 StyleChange = 100, // style has changed
138 IconTextChange = 101, // icon text has changed. Deprecated.
139 ModifiedChange = 102, // modified state has changed
140 MouseTrackingChange = 109, // mouse tracking state has changed
141
142 WindowBlocked = 103, // window is about to be blocked modally
143 WindowUnblocked = 104, // windows modal blocking has ended
144 WindowStateChange = 105,
145
146 ReadOnlyChange = 106, // readonly state has changed
147
148 ToolTip = 110,
149 WhatsThis = 111,
150 StatusTip = 112,
151
152 ActionChanged = 113,
153 ActionAdded = 114,
154 ActionRemoved = 115,
155
156 FileOpen = 116, // file open request
157
158 Shortcut = 117, // shortcut triggered
159 ShortcutOverride = 51, // shortcut override request
160
161 WhatsThisClicked = 118,
162
163 ToolBarChange = 120, // toolbar visibility toggled
164
165 ApplicationActivate = 121, // deprecated. Use ApplicationStateChange instead.
166 ApplicationActivated = ApplicationActivate, // deprecated
167 ApplicationDeactivate = 122, // deprecated. Use ApplicationStateChange instead.
168 ApplicationDeactivated = ApplicationDeactivate, // deprecated
169
170 QueryWhatsThis = 123, // query what's this widget help
171 EnterWhatsThisMode = 124,
172 LeaveWhatsThisMode = 125,
173
174 ZOrderChange = 126, // child widget has had its z-order changed
175
176 HoverEnter = 127, // mouse cursor enters a hover widget
177 HoverLeave = 128, // mouse cursor leaves a hover widget
178 HoverMove = 129, // mouse cursor move inside a hover widget
179
180 // last event id used = 132
181
182#ifdef QT_KEYPAD_NAVIGATION
183 EnterEditFocus = 150, // enter edit mode in keypad navigation
184 LeaveEditFocus = 151, // enter edit mode in keypad navigation
185#endif
186 AcceptDropsChange = 152,
187
188 ZeroTimerEvent = 154, // Used for Windows Zero timer events
189
190 GraphicsSceneMouseMove = 155, // GraphicsView
191 GraphicsSceneMousePress = 156,
192 GraphicsSceneMouseRelease = 157,
193 GraphicsSceneMouseDoubleClick = 158,
194 GraphicsSceneContextMenu = 159,
195 GraphicsSceneHoverEnter = 160,
196 GraphicsSceneHoverMove = 161,
197 GraphicsSceneHoverLeave = 162,
198 GraphicsSceneHelp = 163,
199 GraphicsSceneDragEnter = 164,
200 GraphicsSceneDragMove = 165,
201 GraphicsSceneDragLeave = 166,
202 GraphicsSceneDrop = 167,
203 GraphicsSceneWheel = 168,
204 GraphicsSceneLeave = 220,
205
206 KeyboardLayoutChange = 169, // keyboard layout changed
207
208 DynamicPropertyChange = 170, // A dynamic property was changed through setProperty/property
209
210 TabletEnterProximity = 171,
211 TabletLeaveProximity = 172,
212
213 NonClientAreaMouseMove = 173,
214 NonClientAreaMouseButtonPress = 174,
215 NonClientAreaMouseButtonRelease = 175,
216 NonClientAreaMouseButtonDblClick = 176,
217
218 MacSizeChange = 177, // when the Qt::WA_Mac{Normal,Small,Mini}Size changes
219
220 ContentsRectChange = 178, // sent by QWidget::setContentsMargins (internal)
221
222 MacGLWindowChange = 179, // Internal! the window of the GLWidget has changed
223
224 FutureCallOut = 180,
225
226 GraphicsSceneResize = 181,
227 GraphicsSceneMove = 182,
228
229 CursorChange = 183,
230 ToolTipChange = 184,
231
232 NetworkReplyUpdated = 185, // Internal for QNetworkReply
233
234 GrabMouse = 186,
235 UngrabMouse = 187,
236 GrabKeyboard = 188,
237 UngrabKeyboard = 189,
238
239 StateMachineSignal = 192,
240 StateMachineWrapped = 193,
241
242 TouchBegin = 194,
243 TouchUpdate = 195,
244 TouchEnd = 196,
245
246#ifndef QT_NO_GESTURES
247 NativeGesture = 197, // QtGui native gesture
248#endif
249 RequestSoftwareInputPanel = 199,
250 CloseSoftwareInputPanel = 200,
251
252 WinIdChange = 203,
253#ifndef QT_NO_GESTURES
254 Gesture = 198,
255 GestureOverride = 202,
256#endif
257 ScrollPrepare = 204,
258 Scroll = 205,
259
260 Expose = 206,
261
262 InputMethodQuery = 207,
263 OrientationChange = 208, // Screen orientation has changed
264
265 TouchCancel = 209,
266
267 ThemeChange = 210,
268
269 SockClose = 211, // socket closed
270
271 PlatformPanel = 212,
272
273 StyleAnimationUpdate = 213, // style animation target should be updated
274 ApplicationStateChange = 214,
275
276 WindowChangeInternal = 215, // internal for QQuickWidget and texture-based widgets
277 ScreenChangeInternal = 216,
278
279 PlatformSurface = 217, // Platform surface created or about to be destroyed
280
281 Pointer = 218, // Qt 5: QQuickPointerEvent; Qt 6: unused so far
282
283 TabletTrackingChange = 219, // tablet tracking state has changed
284
285 // GraphicsSceneLeave = 220,
286 WindowAboutToChangeInternal = 221, // internal for QQuickWidget and texture-based widgets
287
288 DevicePixelRatioChange = 222,
289
290 ChildWindowAdded = 223,
291 ChildWindowRemoved = 224,
292 ParentWindowAboutToChange = 225,
293 ParentWindowChange = 226,
294
295 // 512 reserved for Qt Jambi's MetaCall event
296 // 513 reserved for Qt Jambi's DeleteOnMainThread event
297
298 User = 1000, // first user event id
299 MaxUser = 65535 // last user event id
300 };
301 Q_ENUM(Type)
302
303 explicit QEvent(Type type);
304 virtual ~QEvent();
305 inline Type type() const { return static_cast<Type>(t); }
306 inline bool spontaneous() const { return m_spont; }
307
308 inline virtual void setAccepted(bool accepted) { m_accept = accepted; }
309 inline bool isAccepted() const { return m_accept; }
310
311 inline void accept() { m_accept = true; }
312 inline void ignore() { m_accept = false; }
313
314 inline bool isInputEvent() const noexcept { return m_inputEvent; }
315 inline bool isPointerEvent() const noexcept { return m_pointerEvent; }
316 inline bool isSinglePointEvent() const noexcept { return m_singlePointEvent; }
317
318 static int registerEventType(int hint = -1) noexcept;
319
320 virtual QEvent *clone() const;
321
322protected:
323 QT_DEFINE_TAG_STRUCT(InputEventTag);
324 QEvent(Type type, InputEventTag) : QEvent(type) { m_inputEvent = true; }
325 QT_DEFINE_TAG_STRUCT(PointerEventTag);
326 QEvent(Type type, PointerEventTag) : QEvent(type, InputEventTag{}) { m_pointerEvent = true; }
327 QT_DEFINE_TAG_STRUCT(SinglePointEventTag);
328 QEvent(Type type, SinglePointEventTag) : QEvent(type, PointerEventTag{}) { m_singlePointEvent = true; }
329 quint16 t;
330
331private:
332 /*
333 We can assume that C++ types are 8-byte aligned, and we can't assume that compilers
334 coalesce data members from subclasses. Use bitfields to fill up to next 8-byte
335 aligned size, which is 16 bytes. That way we don't waste memory, and have plenty of room
336 for future flags.
337 Don't use bitfields for the most important flags, as that would generate more code, and
338 access is always inline. Bytes used are:
339 8 vptr + 2 type + 3 bool flags => 3 bytes left, so 24 bits. However, compilers will word-
340 align the quint16s after the bools, so add another unused bool to fill that gap, which
341 leaves us with 16 bits.
342 */
343 bool m_posted = false;
344 bool m_spont = false;
345 bool m_accept = true;
346 bool m_unused = false;
347 quint16 m_reserved : 13;
348 quint16 m_inputEvent : 1;
349 quint16 m_pointerEvent : 1;
350 quint16 m_singlePointEvent : 1;
351
352 friend class QCoreApplication;
353 friend class QCoreApplicationPrivate;
354 friend class QThreadData;
355 friend class QApplication;
356 friend class QGraphicsScenePrivate;
357 // from QtTest:
358 // QtWebEngine event handling requires forwarding events as spontaneous.
359 // Impersonated QSpontaneKeyEvent in QtWebEngine to handle such cases.
360 friend class QSpontaneKeyEvent;
361 // needs this:
362 Q_ALWAYS_INLINE
363 void setSpontaneous() { m_spont = true; }
364};
365
366class Q_CORE_EXPORT QTimerEvent : public QEvent
367{
368 Q_DECL_EVENT_COMMON(QTimerEvent)
369public:
370 explicit QTimerEvent(int timerId);
371 explicit QTimerEvent(Qt::TimerId timerId);
372
373 int timerId() const { return qToUnderlying(id()); }
374 Qt::TimerId id() const { return m_id; }
375 bool matches(const QBasicTimer &timer) const noexcept
376 { return m_id == timer.id(); }
377
378protected:
379 Qt::TimerId m_id;
380};
381
382class QObject;
383
384class Q_CORE_EXPORT QChildEvent : public QEvent
385{
386 Q_DECL_EVENT_COMMON(QChildEvent)
387public:
388 QChildEvent(Type type, QObject *child);
389
390 QObject *child() const { return c; }
391 bool added() const { return type() == ChildAdded; }
392 bool polished() const { return type() == ChildPolished; }
393 bool removed() const { return type() == ChildRemoved; }
394
395protected:
396 QObject *c;
397};
398
399class Q_CORE_EXPORT QDynamicPropertyChangeEvent : public QEvent
400{
401 Q_DECL_EVENT_COMMON(QDynamicPropertyChangeEvent)
402public:
403 explicit QDynamicPropertyChangeEvent(const QByteArray &name);
404
405 inline QByteArray propertyName() const { return n; }
406
407private:
408 QByteArray n;
409};
410
411QT_END_NAMESPACE
412
413#endif // QCOREEVENT_H
\inmodule QtCore
Definition qcoreevent.h:385
\inmodule QtCore
\inmodule QtCore
Definition qcoreevent.h:46
\inmodule QtCore
Definition qcoreevent.h:367
Combined button and popup list for selecting options.
#define __has_include(x)
QString qAppName()
Q_TRACE_POINT(qtcore, QCoreApplication_notify_exit, bool consumed, bool filtered)
static QString qAppFileName()
QList< QtStartUpFunction > QStartUpFuncList
void qt_startup_hook()
Q_TRACE_METADATA(qtcore, "ENUM { AUTO, RANGE User ... MaxUser } QEvent::Type;")
QString qtTrId(const char *id, int n)
Q_TRACE_POINT(qtcore, QCoreApplication_postEvent_exit)
static void qt_call_pre_routines()
qsizetype qGlobalPostedEventsCount()
static Q_CONSTINIT bool preRoutinesCalled
QList< QtCleanUpFunction > QVFuncList
static void replacePercentN(QString *result, int n)
Q_TRACE_POINT(qtcore, QCoreApplication_postEvent_event_compressed, QObject *receiver, QEvent *event)
Q_TRACE_POINT(qtcore, QCoreApplication_postEvent_entry, QObject *receiver, QEvent *event, QEvent::Type type)
#define qApp
Q_TRACE_PREFIX(qtcore, "#include <qcoreevent.h>")
Q_CORE_EXPORT void qAddPostRoutine(QtCleanUpFunction)
void(* QtCleanUpFunction)()
void(* QtStartUpFunction)()
Q_CORE_EXPORT void qAddPreRoutine(QtStartUpFunction)
Q_CORE_EXPORT void qRemovePostRoutine(QtCleanUpFunction)
#define Q_EVENT_DISABLE_COPY(Class)
Definition qcoreevent.h:14
#define Q_DECL_EVENT_COMMON(Class)
Definition qcoreevent.h:21
Q_GLOBAL_STATIC(QReadWriteLock, g_updateMutex)
#define Q_LOGGING_CATEGORY(name,...)
#define qCDebug(category,...)