QtBase  v6.3.1
qcoreevent.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2020 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtCore module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #ifndef QCOREEVENT_H
41 #define QCOREEVENT_H
42 
43 #include <QtCore/qnamespace.h>
44 #include <QtCore/qbytearray.h>
45 #include <QtCore/qobjectdefs.h>
46 
48 
49 #define Q_EVENT_DISABLE_COPY(Class) \
50 protected: \
51  Class(const Class &) = default; \
52  Class(Class &&) = delete; \
53  Class &operator=(const Class &other) = default; \
54  Class &operator=(Class &&) = delete
55 
56 class QEventPrivate;
57 class Q_CORE_EXPORT QEvent // event base class
58 {
59  Q_GADGET
60  QDOC_PROPERTY(bool accepted READ isAccepted WRITE setAccepted)
61 
63 public:
64  enum Type {
65  /*
66  If you get a strange compiler error on the line with None,
67  it's probably because you're also including X11 headers,
68  which #define the symbol None. Put the X11 includes after
69  the Qt includes to solve this problem.
70  */
71  None = 0, // invalid event
72  Timer = 1, // timer event
73  MouseButtonPress = 2, // mouse button pressed
74  MouseButtonRelease = 3, // mouse button released
75  MouseButtonDblClick = 4, // mouse button double click
76  MouseMove = 5, // mouse move
77  KeyPress = 6, // key pressed
78  KeyRelease = 7, // key released
79  FocusIn = 8, // keyboard focus received
80  FocusOut = 9, // keyboard focus lost
81  FocusAboutToChange = 23, // keyboard focus is about to be lost
82  Enter = 10, // mouse enters widget
83  Leave = 11, // mouse leaves widget
84  Paint = 12, // paint widget
85  Move = 13, // move widget
86  Resize = 14, // resize widget
87  Create = 15, // after widget creation
88  Destroy = 16, // during widget destruction
89  Show = 17, // widget is shown
90  Hide = 18, // widget is hidden
91  Close = 19, // request to close widget
92  Quit = 20, // request to quit application
93  ParentChange = 21, // widget has been reparented
94  ParentAboutToChange = 131, // sent just before the parent change is done
95  ThreadChange = 22, // object has changed threads
96  WindowActivate = 24, // window was activated
97  WindowDeactivate = 25, // window was deactivated
98  ShowToParent = 26, // widget is shown to parent
99  HideToParent = 27, // widget is hidden to parent
100  Wheel = 31, // wheel event
101  WindowTitleChange = 33, // window title changed
102  WindowIconChange = 34, // icon changed
103  ApplicationWindowIconChange = 35, // application icon changed
104  ApplicationFontChange = 36, // application font changed
105  ApplicationLayoutDirectionChange = 37, // application layout direction changed
106  ApplicationPaletteChange = 38, // application palette changed
107  PaletteChange = 39, // widget palette changed
108  Clipboard = 40, // internal clipboard event
109  Speech = 42, // reserved for speech input
110  MetaCall = 43, // meta call event
111  SockAct = 50, // socket activation
112  WinEventAct = 132, // win event activation
113  DeferredDelete = 52, // deferred delete event
114  DragEnter = 60, // drag moves into widget
115  DragMove = 61, // drag moves in widget
116  DragLeave = 62, // drag leaves or is cancelled
117  Drop = 63, // actual drop
118  DragResponse = 64, // drag accepted/rejected
119  ChildAdded = 68, // new child widget
120  ChildPolished = 69, // polished child widget
121  ChildRemoved = 71, // deleted child widget
122  ShowWindowRequest = 73, // widget's window should be mapped
123  PolishRequest = 74, // widget should be polished
124  Polish = 75, // widget is polished
125  LayoutRequest = 76, // widget should be relayouted
126  UpdateRequest = 77, // widget should be repainted
127  UpdateLater = 78, // request update() later
128 
129  EmbeddingControl = 79, // ActiveX embedding
130  ActivateControl = 80, // ActiveX activation
131  DeactivateControl = 81, // ActiveX deactivation
132  ContextMenu = 82, // context popup menu
133  InputMethod = 83, // input method
134  TabletMove = 87, // Wacom tablet event
135  LocaleChange = 88, // the system locale changed
136  LanguageChange = 89, // the application language changed
137  LayoutDirectionChange = 90, // the layout direction changed
138  Style = 91, // internal style event
139  TabletPress = 92, // tablet press
140  TabletRelease = 93, // tablet release
141  OkRequest = 94, // CE (Ok) button pressed
142  HelpRequest = 95, // CE (?) button pressed
143 
144  IconDrag = 96, // proxy icon dragged
145 
146  FontChange = 97, // font has changed
147  EnabledChange = 98, // enabled state has changed
148  ActivationChange = 99, // window activation has changed
149  StyleChange = 100, // style has changed
150  IconTextChange = 101, // icon text has changed. Deprecated.
151  ModifiedChange = 102, // modified state has changed
152  MouseTrackingChange = 109, // mouse tracking state has changed
153 
154  WindowBlocked = 103, // window is about to be blocked modally
155  WindowUnblocked = 104, // windows modal blocking has ended
156  WindowStateChange = 105,
157 
158  ReadOnlyChange = 106, // readonly state has changed
159 
160  ToolTip = 110,
161  WhatsThis = 111,
162  StatusTip = 112,
163 
164  ActionChanged = 113,
165  ActionAdded = 114,
166  ActionRemoved = 115,
167 
168  FileOpen = 116, // file open request
169 
170  Shortcut = 117, // shortcut triggered
171  ShortcutOverride = 51, // shortcut override request
172 
173  WhatsThisClicked = 118,
174 
175  ToolBarChange = 120, // toolbar visibility toggled
176 
177  ApplicationActivate = 121, // deprecated. Use ApplicationStateChange instead.
178  ApplicationActivated = ApplicationActivate, // deprecated
179  ApplicationDeactivate = 122, // deprecated. Use ApplicationStateChange instead.
180  ApplicationDeactivated = ApplicationDeactivate, // deprecated
181 
182  QueryWhatsThis = 123, // query what's this widget help
183  EnterWhatsThisMode = 124,
184  LeaveWhatsThisMode = 125,
185 
186  ZOrderChange = 126, // child widget has had its z-order changed
187 
188  HoverEnter = 127, // mouse cursor enters a hover widget
189  HoverLeave = 128, // mouse cursor leaves a hover widget
190  HoverMove = 129, // mouse cursor move inside a hover widget
191 
192  // last event id used = 132
193 
194 #ifdef QT_KEYPAD_NAVIGATION
195  EnterEditFocus = 150, // enter edit mode in keypad navigation
196  LeaveEditFocus = 151, // enter edit mode in keypad navigation
197 #endif
198  AcceptDropsChange = 152,
199 
200  ZeroTimerEvent = 154, // Used for Windows Zero timer events
201 
202  GraphicsSceneMouseMove = 155, // GraphicsView
203  GraphicsSceneMousePress = 156,
204  GraphicsSceneMouseRelease = 157,
205  GraphicsSceneMouseDoubleClick = 158,
206  GraphicsSceneContextMenu = 159,
207  GraphicsSceneHoverEnter = 160,
208  GraphicsSceneHoverMove = 161,
209  GraphicsSceneHoverLeave = 162,
210  GraphicsSceneHelp = 163,
211  GraphicsSceneDragEnter = 164,
212  GraphicsSceneDragMove = 165,
213  GraphicsSceneDragLeave = 166,
214  GraphicsSceneDrop = 167,
215  GraphicsSceneWheel = 168,
216  GraphicsSceneLeave = 220,
217 
218  KeyboardLayoutChange = 169, // keyboard layout changed
219 
220  DynamicPropertyChange = 170, // A dynamic property was changed through setProperty/property
221 
222  TabletEnterProximity = 171,
223  TabletLeaveProximity = 172,
224 
225  NonClientAreaMouseMove = 173,
226  NonClientAreaMouseButtonPress = 174,
227  NonClientAreaMouseButtonRelease = 175,
228  NonClientAreaMouseButtonDblClick = 176,
229 
230  MacSizeChange = 177, // when the Qt::WA_Mac{Normal,Small,Mini}Size changes
231 
232  ContentsRectChange = 178, // sent by QWidget::setContentsMargins (internal)
233 
234  MacGLWindowChange = 179, // Internal! the window of the GLWidget has changed
235 
236  FutureCallOut = 180,
237 
238  GraphicsSceneResize = 181,
239  GraphicsSceneMove = 182,
240 
241  CursorChange = 183,
242  ToolTipChange = 184,
243 
244  NetworkReplyUpdated = 185, // Internal for QNetworkReply
245 
246  GrabMouse = 186,
247  UngrabMouse = 187,
248  GrabKeyboard = 188,
249  UngrabKeyboard = 189,
250 
251  StateMachineSignal = 192,
252  StateMachineWrapped = 193,
253 
254  TouchBegin = 194,
255  TouchUpdate = 195,
256  TouchEnd = 196,
257 
258 #ifndef QT_NO_GESTURES
259  NativeGesture = 197, // QtGui native gesture
260 #endif
261  RequestSoftwareInputPanel = 199,
262  CloseSoftwareInputPanel = 200,
263 
264  WinIdChange = 203,
265 #ifndef QT_NO_GESTURES
266  Gesture = 198,
267  GestureOverride = 202,
268 #endif
269  ScrollPrepare = 204,
270  Scroll = 205,
271 
272  Expose = 206,
273 
275  OrientationChange = 208, // Screen orientation has changed
276 
277  TouchCancel = 209,
278 
279  ThemeChange = 210,
280 
281  SockClose = 211, // socket closed
282 
283  PlatformPanel = 212,
284 
285  StyleAnimationUpdate = 213, // style animation target should be updated
286  ApplicationStateChange = 214,
287 
288  WindowChangeInternal = 215, // internal for QQuickWidget
289  ScreenChangeInternal = 216,
290 
291  PlatformSurface = 217, // Platform surface created or about to be destroyed
292 
293  Pointer = 218, // Qt 5: QQuickPointerEvent; Qt 6: unused so far
294 
295  TabletTrackingChange = 219, // tablet tracking state has changed
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 
324 protected:
325  struct InputEventTag { explicit InputEventTag() = default; };
326  QEvent(Type type, InputEventTag) : QEvent(type) { m_inputEvent = true; }
327  struct PointerEventTag { explicit PointerEventTag() = default; };
328  QEvent(Type type, PointerEventTag) : QEvent(type, InputEventTag{}) { m_pointerEvent = true; }
329  struct SinglePointEventTag { explicit SinglePointEventTag() = default; };
330  QEvent(Type type, SinglePointEventTag) : QEvent(type, PointerEventTag{}) { m_singlePointEvent = true; }
332 
333 private:
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;
356  friend class QThreadData;
357  friend class QApplication;
358  friend class QGraphicsScenePrivate;
359  // from QtTest:
360  friend class QSpontaneKeyEvent;
361  // needs this:
362  Q_ALWAYS_INLINE
363  void setSpontaneous() { m_spont = true; }
364 };
365 
366 class Q_CORE_EXPORT QTimerEvent : public QEvent
367 {
369 public:
370  explicit QTimerEvent(int timerId);
371  ~QTimerEvent();
372  int timerId() const { return id; }
373 
374  QTimerEvent *clone() const override { return new QTimerEvent(*this); }
375 
376 protected:
377  int id;
378 };
379 
380 class QObject;
381 
382 class Q_CORE_EXPORT QChildEvent : public QEvent
383 {
385 public:
387  ~QChildEvent();
388  QObject *child() const { return c; }
389  bool added() const { return type() == ChildAdded; }
390  bool polished() const { return type() == ChildPolished; }
391  bool removed() const { return type() == ChildRemoved; }
392 
393  QChildEvent *clone() const override { return new QChildEvent(*this); }
394 
395 protected:
397 };
398 
399 class Q_CORE_EXPORT QDynamicPropertyChangeEvent : public QEvent
400 {
402 public:
405 
406  inline QByteArray propertyName() const { return n; }
407 
408  QDynamicPropertyChangeEvent *clone() const override { return new QDynamicPropertyChangeEvent(*this); }
409 
410 private:
411  QByteArray n;
412 };
413 
414 class Q_CORE_EXPORT QDeferredDeleteEvent : public QEvent
415 {
417 public:
418  explicit QDeferredDeleteEvent();
420  int loopLevel() const { return level; }
421 
422  QDeferredDeleteEvent *clone() const override { return new QDeferredDeleteEvent(*this); }
423 
424 private:
425  int level;
426  friend class QCoreApplication;
427 };
428 
430 
431 #endif // QCOREEVENT_H
The QApplication class manages the GUI application's control flow and main settings.
Definition: qapplication.h:68
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:85
The QChildEvent class contains event parameters for child object events.
Definition: qcoreevent.h:383
QChildEvent * clone() const override
Definition: qcoreevent.h:393
bool removed() const
Definition: qcoreevent.h:391
bool added() const
Definition: qcoreevent.h:389
QObject * child() const
Definition: qcoreevent.h:388
QObject * c
Definition: qcoreevent.h:396
bool polished() const
Definition: qcoreevent.h:390
The QCoreApplication class provides an event loop for Qt applications without UI.
int loopLevel() const
Definition: qcoreevent.h:420
QDeferredDeleteEvent * clone() const override
Definition: qcoreevent.h:422
The QDynamicPropertyChangeEvent class contains event parameters for dynamic property change events.
Definition: qcoreevent.h:400
QByteArray propertyName() const
Definition: qcoreevent.h:406
QDynamicPropertyChangeEvent * clone() const override
Definition: qcoreevent.h:408
The QEvent class is the base class of all event classes. Event objects contain event parameters.
Definition: qcoreevent.h:58
QEvent(Type type, InputEventTag)
Definition: qcoreevent.h:326
virtual void setAccepted(bool accepted)
Definition: qcoreevent.h:310
bool isSinglePointEvent() const noexcept
Definition: qcoreevent.h:318
bool spontaneous() const
Definition: qcoreevent.h:308
QEvent(Type type, SinglePointEventTag)
Definition: qcoreevent.h:330
Type type() const
Definition: qcoreevent.h:307
void ignore()
Definition: qcoreevent.h:314
bool isPointerEvent() const noexcept
Definition: qcoreevent.h:317
bool isAccepted() const
Definition: qcoreevent.h:311
QEvent(Type type, PointerEventTag)
Definition: qcoreevent.h:328
quint16 t
Definition: qcoreevent.h:331
void accept()
Definition: qcoreevent.h:313
bool isInputEvent() const noexcept
Definition: qcoreevent.h:316
The QObject class is the base class of all Qt objects.
Definition: qobject.h:125
static void setSpontaneous(QEvent *ev)
The QTimerEvent class contains parameters that describe a timer event.
Definition: qcoreevent.h:367
QTimerEvent * clone() const override
Definition: qcoreevent.h:374
int timerId() const
Definition: qcoreevent.h:372
Definition: main.cpp:626
[user-class]
Definition: user.h:59
auto it unsigned count const
Definition: hb-iter.hh:848
@ Shortcut
Definition: qtestkeyboard.h:73
@ MouseMove
Definition: qtestmouse.h:78
InputMethodQuery
Definition: qnamespace.h:1380
@ ToolTip
Definition: qnamespace.h:238
@ Wheel
#define Q_EVENT_DISABLE_COPY(Class)
Definition: qcoreevent.h:49
unsigned short quint16
Definition: qglobal.h:286
GLenum GLuint id
[6]
Definition: qopengl.h:270
GLenum type
Definition: qopengl.h:270
GLenum GLuint GLint level
GLuint name
GLfloat n
const GLubyte * c
Definition: qopenglext.h:12701
GLdouble GLdouble t
[9]
Definition: qopenglext.h:243
#define Q_ENUM(x)
Definition: qtmetamacros.h:104
#define Q_GADGET
Definition: qtmetamacros.h:193
#define QDOC_PROPERTY(text)
Definition: qtmetamacros.h:98
QLayoutItem * child
[0]
Definition: moc.h:48
@ TabletMove
Definition: main.cpp:58
#define protected
virtual HRESULT STDMETHODCALLTYPE Close(void)=0
virtual HRESULT STDMETHODCALLTYPE Move(enum TextUnit unit, int count, __RPC__out int *pRetVal)=0