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

source code of qtbase/src/corelib/kernel/qcoreevent.h