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#ifdef QT_KEYPAD_NAVIGATION
187 EnterEditFocus = 150, // enter edit mode in keypad navigation
188 LeaveEditFocus = 151, // enter edit mode in keypad navigation
189#endif
190 AcceptDropsChange = 152,
191
192 ZeroTimerEvent = 154, // Used for Windows Zero timer events
193
194 GraphicsSceneMouseMove = 155, // GraphicsView
195 GraphicsSceneMousePress = 156,
196 GraphicsSceneMouseRelease = 157,
197 GraphicsSceneMouseDoubleClick = 158,
198 GraphicsSceneContextMenu = 159,
199 GraphicsSceneHoverEnter = 160,
200 GraphicsSceneHoverMove = 161,
201 GraphicsSceneHoverLeave = 162,
202 GraphicsSceneHelp = 163,
203 GraphicsSceneDragEnter = 164,
204 GraphicsSceneDragMove = 165,
205 GraphicsSceneDragLeave = 166,
206 GraphicsSceneDrop = 167,
207 GraphicsSceneWheel = 168,
208 GraphicsSceneLeave = 220,
209
210 KeyboardLayoutChange = 169, // keyboard layout changed
211
212 DynamicPropertyChange = 170, // A dynamic property was changed through setProperty/property
213
214 TabletEnterProximity = 171,
215 TabletLeaveProximity = 172,
216
217 NonClientAreaMouseMove = 173,
218 NonClientAreaMouseButtonPress = 174,
219 NonClientAreaMouseButtonRelease = 175,
220 NonClientAreaMouseButtonDblClick = 176,
221
222 MacSizeChange = 177, // when the Qt::WA_Mac{Normal,Small,Mini}Size changes
223
224 ContentsRectChange = 178, // sent by QWidget::setContentsMargins (internal)
225
226 MacGLWindowChange = 179, // Internal! the window of the GLWidget has changed
227
228 FutureCallOut = 180,
229
230 GraphicsSceneResize = 181,
231 GraphicsSceneMove = 182,
232
233 CursorChange = 183,
234 ToolTipChange = 184,
235
236 NetworkReplyUpdated = 185, // Internal for QNetworkReply
237
238 GrabMouse = 186,
239 UngrabMouse = 187,
240 GrabKeyboard = 188,
241 UngrabKeyboard = 189,
242
243 StateMachineSignal = 192,
244 StateMachineWrapped = 193,
245
246 TouchBegin = 194,
247 TouchUpdate = 195,
248 TouchEnd = 196,
249
250#ifndef QT_NO_GESTURES
251 NativeGesture = 197, // QtGui native gesture
252#endif
253 RequestSoftwareInputPanel = 199,
254 CloseSoftwareInputPanel = 200,
255
256 WinIdChange = 203,
257#ifndef QT_NO_GESTURES
258 Gesture = 198,
259 GestureOverride = 202,
260#endif
261 ScrollPrepare = 204,
262 Scroll = 205,
263
264 Expose = 206,
265
266 InputMethodQuery = 207,
267 OrientationChange = 208, // Screen orientation has changed
268
269 TouchCancel = 209,
270
271 ThemeChange = 210,
272
273 SockClose = 211, // socket closed
274
275 PlatformPanel = 212,
276
277 StyleAnimationUpdate = 213, // style animation target should be updated
278 ApplicationStateChange = 214,
279
280 WindowChangeInternal = 215, // internal for QQuickWidget and texture-based widgets
281 ScreenChangeInternal = 216,
282
283 PlatformSurface = 217, // Platform surface created or about to be destroyed
284
285 Pointer = 218, // Qt 5: QQuickPointerEvent; Qt 6: unused so far
286
287 TabletTrackingChange = 219, // tablet tracking state has changed
288
289 // GraphicsSceneLeave = 220,
290 WindowAboutToChangeInternal = 221, // internal for QQuickWidget and texture-based widgets
291
292 DevicePixelRatioChange = 222,
293
294 ChildWindowAdded = 223,
295 ChildWindowRemoved = 224,
296 ParentWindowAboutToChange = 225,
297 ParentWindowChange = 226,
298
299 SafeAreaMarginsChange = 227,
300
301 // 512 reserved for Qt Jambi's MetaCall event
302 // 513 reserved for Qt Jambi's DeleteOnMainThread event
303
304 User = 1000, // first user event id
305 MaxUser = 65535 // last user event id
306 };
307 Q_ENUM(Type)
308
309 explicit QEvent(Type type);
310 virtual ~QEvent();
311 inline Type type() const { return static_cast<Type>(t); }
312 inline bool spontaneous() const { return m_spont; }
313
314 inline virtual void setAccepted(bool accepted) { m_accept = accepted; }
315 inline bool isAccepted() const { return m_accept; }
316
317 inline void accept() { m_accept = true; }
318 inline void ignore() { m_accept = false; }
319
320 inline bool isInputEvent() const noexcept { return m_inputEvent; }
321 inline bool isPointerEvent() const noexcept { return m_pointerEvent; }
322 inline bool isSinglePointEvent() const noexcept { return m_singlePointEvent; }
323
324 static int registerEventType(int hint = -1) noexcept;
325
326 virtual QEvent *clone() const;
327
328protected:
329 QT_DEFINE_TAG_STRUCT(InputEventTag);
330 QEvent(Type type, InputEventTag) : QEvent(type) { m_inputEvent = true; }
331 QT_DEFINE_TAG_STRUCT(PointerEventTag);
332 QEvent(Type type, PointerEventTag) : QEvent(type, InputEventTag{}) { m_pointerEvent = true; }
333 QT_DEFINE_TAG_STRUCT(SinglePointEventTag);
334 QEvent(Type type, SinglePointEventTag) : QEvent(type, PointerEventTag{}) { m_singlePointEvent = true; }
335 quint16 t;
336
337private:
338 /*
339 We can assume that C++ types are 8-byte aligned, and we can't assume that compilers
340 coalesce data members from subclasses. Use bitfields to fill up to next 8-byte
341 aligned size, which is 16 bytes. That way we don't waste memory, and have plenty of room
342 for future flags.
343 Don't use bitfields for the most important flags, as that would generate more code, and
344 access is always inline. Bytes used are:
345 8 vptr + 2 type + 3 bool flags => 3 bytes left, so 24 bits. However, compilers will word-
346 align the quint16s after the bools, so add another unused bool to fill that gap, which
347 leaves us with 16 bits.
348 */
349 bool m_posted = false;
350 bool m_spont = false;
351 bool m_accept = true;
352 bool m_unused = false;
353 quint16 m_reserved : 13;
354 quint16 m_inputEvent : 1;
355 quint16 m_pointerEvent : 1;
356 quint16 m_singlePointEvent : 1;
357
358 friend class QCoreApplication;
359 friend class QCoreApplicationPrivate;
360 friend class QThreadData;
361 friend class QApplication;
362 friend class QGraphicsScenePrivate;
363 // from QtTest:
364 // QtWebEngine event handling requires forwarding events as spontaneous.
365 // Impersonated QSpontaneKeyEvent in QtWebEngine to handle such cases.
366 friend class QSpontaneKeyEvent;
367 // needs this:
368 Q_ALWAYS_INLINE
369 void setSpontaneous() { m_spont = true; }
370};
371
372class Q_CORE_EXPORT QTimerEvent : public QEvent
373{
374 Q_DECL_EVENT_COMMON(QTimerEvent)
375public:
376 explicit QTimerEvent(int timerId);
377 explicit QTimerEvent(Qt::TimerId timerId);
378
379 int timerId() const { return qToUnderlying(id()); }
380 Qt::TimerId id() const { return m_id; }
381 bool matches(const QBasicTimer &timer) const noexcept
382 { return m_id == timer.id(); }
383
384protected:
385 Qt::TimerId m_id;
386};
387
388class QObject;
389
390class Q_CORE_EXPORT QChildEvent : public QEvent
391{
392 Q_DECL_EVENT_COMMON(QChildEvent)
393public:
394 QChildEvent(Type type, QObject *child);
395
396 QObject *child() const { return c; }
397 bool added() const { return type() == ChildAdded; }
398 bool polished() const { return type() == ChildPolished; }
399 bool removed() const { return type() == ChildRemoved; }
400
401protected:
402 QObject *c;
403};
404
405class Q_CORE_EXPORT QDynamicPropertyChangeEvent : public QEvent
406{
407 Q_DECL_EVENT_COMMON(QDynamicPropertyChangeEvent)
408public:
409 explicit QDynamicPropertyChangeEvent(const QByteArray &name);
410
411 inline QByteArray propertyName() const { return n; }
412
413private:
414 QByteArray n;
415};
416
417QT_END_NAMESPACE
418
419#endif // QCOREEVENT_H
\inmodule QtCore
Definition qcoreevent.h:391
\inmodule QtCore
\inmodule QtCore
Definition qcoreevent.h:50
\inmodule QtCore
Definition qcoreevent.h:373
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)