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// Qt-Security score:significant reason:default
4
5#ifndef QCOREEVENT_H
6#define QCOREEVENT_H
7
8#include <QtCore/qbasictimer.h>
9#include <QtCore/qnamespace.h>
10#include <QtCore/qbytearray.h>
11#include <QtCore/qobjectdefs.h>
12
14
15template <typename Event> class QEventStorage;
16
17#define Q_EVENT_DISABLE_COPY(Class) protected
18 :
19 Class(const Class &) = default;
20 Class(Class &&) = delete;
21 Class &operator=(const Class &other) = default;
22 Class &operator=(Class &&) = delete
23
24#define Q_DECL_EVENT_COMMON(Class)
25 friend class QEventStorage<Class>;
26 protected:
27 Class(const Class &);
28 Class(Class &&) = delete;
29 Class &operator=(const Class &other) = default;
30 Class &operator=(Class &&) = delete;
31 public:
32 Class* clone() const override;
33 ~Class() override;
34 private:
35
36#define Q_IMPL_EVENT_COMMON(Class)
37 Class::Class(const Class &) = default;
38 Class::~Class() = default;
39 Class* Class::clone() const
40 {
41 auto c = new Class(*this);
42 [[maybe_unused]] QEvent *e = c;
43 /* check that covariant return is safe to add */
44 Q_ASSERT(reinterpret_cast<quintptr>(c) == reinterpret_cast<quintptr>(e));
45 return c;
46 }
47
48class QEventPrivate;
49class Q_CORE_EXPORT QEvent // event base class
50{
51 Q_GADGET
52 QDOC_PROPERTY(bool accepted READ isAccepted WRITE setAccepted)
53
55public:
56 enum Type {
57 /*
58 If you get a strange compiler error on the line with None,
59 it's probably because you're also including X11 headers,
60 which #define the symbol None. Put the X11 includes after
61 the Qt includes to solve this problem.
62 */
63 None = 0, // invalid event
64 Timer = 1, // timer event
65 MouseButtonPress = 2, // mouse button pressed
66 MouseButtonRelease = 3, // mouse button released
67 MouseButtonDblClick = 4, // mouse button double click
68 MouseMove = 5, // mouse move
69 KeyPress = 6, // key pressed
70 KeyRelease = 7, // key released
71 FocusIn = 8, // keyboard focus received
72 FocusOut = 9, // keyboard focus lost
73 FocusAboutToChange = 23, // keyboard focus is about to be lost
74 Enter = 10, // mouse enters widget
75 Leave = 11, // mouse leaves widget
76 Paint = 12, // paint widget
77 Move = 13, // move widget
78 Resize = 14, // resize widget
79 Create = 15, // after widget creation
80 Destroy = 16, // during widget destruction
81 Show = 17, // widget is shown
82 Hide = 18, // widget is hidden
83 Close = 19, // request to close widget
84 Quit = 20, // request to quit application
85 ParentChange = 21, // object has been reparented
86 ParentAboutToChange = 131, // sent just before the parent change is done
87 ThreadChange = 22, // object has changed threads
88 WindowActivate = 24, // window was activated
89 WindowDeactivate = 25, // window was deactivated
90 ShowToParent = 26, // widget is shown to parent
91 HideToParent = 27, // widget is hidden to parent
92 Wheel = 31, // wheel event
93 WindowTitleChange = 33, // window title changed
94 WindowIconChange = 34, // icon changed
95 ApplicationWindowIconChange = 35, // application icon changed
96 ApplicationFontChange = 36, // application font changed
97 ApplicationLayoutDirectionChange = 37, // application layout direction changed
98 ApplicationPaletteChange = 38, // application palette changed
99 PaletteChange = 39, // widget palette changed
100 Clipboard = 40, // internal clipboard event
101 Speech = 42, // reserved for speech input
102 MetaCall = 43, // meta call event
103 SockAct = 50, // socket activation
104 WinEventAct = 132, // win event activation
105 DeferredDelete = 52, // deferred delete event
106 DragEnter = 60, // drag moves into widget
107 DragMove = 61, // drag moves in widget
108 DragLeave = 62, // drag leaves or is cancelled
109 Drop = 63, // actual drop
110 DragResponse = 64, // drag accepted/rejected
111 ChildAdded = 68, // new child widget
112 ChildPolished = 69, // polished child widget
113 ChildRemoved = 71, // deleted child widget
114 ShowWindowRequest = 73, // widget's window should be mapped
115 PolishRequest = 74, // widget should be polished
116 Polish = 75, // widget is polished
117 LayoutRequest = 76, // widget should be relayouted
118 UpdateRequest = 77, // widget should be repainted
119 UpdateLater = 78, // request update() later
120
121 EmbeddingControl = 79, // ActiveX embedding
122 ActivateControl = 80, // ActiveX activation
123 DeactivateControl = 81, // ActiveX deactivation
124 ContextMenu = 82, // context popup menu
125 InputMethod = 83, // input method
126 TabletMove = 87, // Wacom tablet event
127 LocaleChange = 88, // the system locale changed
128 LanguageChange = 89, // the application language changed
129 LayoutDirectionChange = 90, // the layout direction changed
130 Style = 91, // internal style event
131 TabletPress = 92, // tablet press
132 TabletRelease = 93, // tablet release
133 OkRequest = 94, // CE (Ok) button pressed
134 HelpRequest = 95, // CE (?) button pressed
135
136 IconDrag = 96, // proxy icon dragged
137
138 FontChange = 97, // font has changed
139 EnabledChange = 98, // enabled state has changed
140 ActivationChange = 99, // window activation has changed
141 StyleChange = 100, // style has changed
142 IconTextChange = 101, // icon text has changed. Deprecated.
143 ModifiedChange = 102, // modified state has changed
144 MouseTrackingChange = 109, // mouse tracking state has changed
145
146 WindowBlocked = 103, // window is about to be blocked modally
147 WindowUnblocked = 104, // windows modal blocking has ended
148 WindowStateChange = 105,
149
150 ReadOnlyChange = 106, // readonly state has changed
151
152 ToolTip = 110,
153 WhatsThis = 111,
154 StatusTip = 112,
155
156 ActionChanged = 113,
157 ActionAdded = 114,
158 ActionRemoved = 115,
159
160 FileOpen = 116, // file open request
161
162 Shortcut = 117, // shortcut triggered
163 ShortcutOverride = 51, // shortcut override request
164
165 WhatsThisClicked = 118,
166
167 ToolBarChange = 120, // toolbar visibility toggled
168
169 ApplicationActivate = 121, // deprecated. Use ApplicationStateChange instead.
170 ApplicationActivated = ApplicationActivate, // deprecated
171 ApplicationDeactivate = 122, // deprecated. Use ApplicationStateChange instead.
172 ApplicationDeactivated = ApplicationDeactivate, // deprecated
173
174 QueryWhatsThis = 123, // query what's this widget help
175 EnterWhatsThisMode = 124,
176 LeaveWhatsThisMode = 125,
177
178 ZOrderChange = 126, // child widget has had its z-order changed
179
180 HoverEnter = 127, // mouse cursor enters a hover widget
181 HoverLeave = 128, // mouse cursor leaves a hover widget
182 HoverMove = 129, // mouse cursor move inside a hover widget
183
184 // last event id used = 132
185
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 SafeAreaMarginsChange = 227,
296
297 // 512 reserved for Qt Jambi's MetaCall event
298 // 513 reserved for Qt Jambi's DeleteOnMainThread event
299
300 User = 1000, // first user event id
301 MaxUser = 65535 // last user event id
302 };
303 Q_ENUM(Type)
304
305 explicit QEvent(Type type);
306 virtual ~QEvent();
307 inline Type type() const { return static_cast<Type>(t); }
308 inline bool spontaneous() const { return m_spont; }
309
310 inline virtual void setAccepted(bool accepted) { m_accept = accepted; }
311 inline bool isAccepted() const { return m_accept; }
312
313 inline void accept() { m_accept = true; }
314 inline void ignore() { m_accept = false; }
315
316 inline bool isInputEvent() const noexcept { return m_inputEvent; }
317 inline bool isPointerEvent() const noexcept { return m_pointerEvent; }
318 inline bool isSinglePointEvent() const noexcept { return m_singlePointEvent; }
319
320 static int registerEventType(int hint = -1) noexcept;
321
322 virtual QEvent *clone() const;
323
324protected:
325 QT_DEFINE_TAG_STRUCT(InputEventTag);
326 QEvent(Type type, InputEventTag) : QEvent(type) { m_inputEvent = true; }
327 QT_DEFINE_TAG_STRUCT(PointerEventTag);
328 QEvent(Type type, PointerEventTag) : QEvent(type, InputEventTag{}) { m_pointerEvent = true; }
329 QT_DEFINE_TAG_STRUCT(SinglePointEventTag);
330 QEvent(Type type, SinglePointEventTag) : QEvent(type, PointerEventTag{}) { m_singlePointEvent = true; }
331 quint16 t;
332
333private:
334 /*
335 We can assume that C++ types are 8-byte aligned, and we can't assume that compilers
336 coalesce data members from subclasses. Use bitfields to fill up to next 8-byte
337 aligned size, which is 16 bytes. That way we don't waste memory, and have plenty of room
338 for future flags.
339 Don't use bitfields for the most important flags, as that would generate more code, and
340 access is always inline. Bytes used are:
341 8 vptr + 2 type + 3 bool flags => 3 bytes left, so 24 bits. However, compilers will word-
342 align the quint16s after the bools, so add another unused bool to fill that gap, which
343 leaves us with 16 bits.
344 */
345 bool m_posted = false;
346 bool m_spont = false;
347 bool m_accept = true;
348 bool m_unused = false;
349 quint16 m_reserved : 13;
350 quint16 m_inputEvent : 1;
351 quint16 m_pointerEvent : 1;
352 quint16 m_singlePointEvent : 1;
353
354 friend class QCoreApplication;
355 friend class QCoreApplicationPrivate;
356 friend class QThreadData;
357 friend class QApplication;
358 friend class QGraphicsScenePrivate;
359 // from QtTest:
360 // QtWebEngine event handling requires forwarding events as spontaneous.
361 // Impersonated QSpontaneKeyEvent in QtWebEngine to handle such cases.
362 friend class QSpontaneKeyEvent;
363 // needs this:
364 Q_ALWAYS_INLINE
365 void setSpontaneous() { m_spont = true; }
366};
367
368class Q_CORE_EXPORT QTimerEvent : public QEvent
369{
370 Q_DECL_EVENT_COMMON(QTimerEvent)
371public:
372 explicit QTimerEvent(int timerId);
373 explicit QTimerEvent(Qt::TimerId timerId);
374
375 int timerId() const { return qToUnderlying(id()); }
376 Qt::TimerId id() const { return m_id; }
377 bool matches(const QBasicTimer &timer) const noexcept
378 { return m_id == timer.id(); }
379
380protected:
381 Qt::TimerId m_id;
382};
383
384class QObject;
385
386class Q_CORE_EXPORT QChildEvent : public QEvent
387{
388 Q_DECL_EVENT_COMMON(QChildEvent)
389public:
390 QChildEvent(Type type, QObject *child);
391
392 QObject *child() const { return c; }
393 bool added() const { return type() == ChildAdded; }
394 bool polished() const { return type() == ChildPolished; }
395 bool removed() const { return type() == ChildRemoved; }
396
397protected:
398 QObject *c;
399};
400
401class Q_CORE_EXPORT QDynamicPropertyChangeEvent : public QEvent
402{
403 Q_DECL_EVENT_COMMON(QDynamicPropertyChangeEvent)
404public:
405 explicit QDynamicPropertyChangeEvent(const QByteArray &name);
406
407 inline QByteArray propertyName() const { return n; }
408
409private:
410 QByteArray n;
411};
412
413QT_END_NAMESPACE
414
415#endif // QCOREEVENT_H
\inmodule QtCore
Definition qcoreevent.h:387
\inmodule QtCore
\inmodule QtCore
Definition qcoreevent.h:50
\inmodule QtCore
Definition qcoreevent.h:369
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)
void QT_MANGLE_NAMESPACE qt_startup_hook()
static QString qAppFileName()
QList< QtStartUpFunction > QStartUpFuncList
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)
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 qApp
#define Q_EVENT_DISABLE_COPY(Class)
Definition qcoreevent.h:17
#define Q_DECL_EVENT_COMMON(Class)
Definition qcoreevent.h:24
Q_GLOBAL_STATIC(QReadWriteLock, g_updateMutex)