File indexing completed on 2026-08-28 09:22:45
0001
0002
0003
0004
0005 #ifndef QCOREEVENT_H
0006 #define QCOREEVENT_H
0007
0008 #include <QtCore/qbasictimer.h>
0009 #include <QtCore/qnamespace.h>
0010 #include <QtCore/qbytearray.h>
0011 #include <QtCore/qobjectdefs.h>
0012
0013 QT_BEGIN_NAMESPACE
0014
0015 template <typename Event> class QEventStorage;
0016
0017 #define Q_EVENT_DISABLE_COPY(Class) \
0018 protected: \
0019 Class(const Class &) = default; \
0020 Class(Class &&) = delete; \
0021 Class &operator=(const Class &other) = default; \
0022 Class &operator=(Class &&) = delete
0023
0024 #define Q_DECL_EVENT_COMMON(Class) \
0025 friend class QEventStorage<Class>; \
0026 protected: \
0027 Class(const Class &); \
0028 Class(Class &&) = delete; \
0029 Class &operator=(const Class &other) = default; \
0030 Class &operator=(Class &&) = delete; \
0031 public: \
0032 Class* clone() const override; \
0033 ~Class() override; \
0034 private:
0035
0036 #define Q_IMPL_EVENT_COMMON(Class) \
0037 Class::Class(const Class &) = default; \
0038 Class::~Class() = default; \
0039 Class* Class::clone() const \
0040 { \
0041 auto c = new Class(*this); \
0042 [[maybe_unused]] QEvent *e = c; \
0043 \
0044 Q_ASSERT(reinterpret_cast<quintptr>(c) == reinterpret_cast<quintptr>(e)); \
0045 return c; \
0046 }
0047
0048 class QEventPrivate;
0049 class Q_CORE_EXPORT QEvent
0050 {
0051 Q_GADGET
0052 QDOC_PROPERTY(bool accepted READ isAccepted WRITE setAccepted)
0053
0054 Q_EVENT_DISABLE_COPY(QEvent);
0055 public:
0056 enum Type {
0057
0058
0059
0060
0061
0062
0063 None = 0,
0064 Timer = 1,
0065 MouseButtonPress = 2,
0066 MouseButtonRelease = 3,
0067 MouseButtonDblClick = 4,
0068 MouseMove = 5,
0069 KeyPress = 6,
0070 KeyRelease = 7,
0071 FocusIn = 8,
0072 FocusOut = 9,
0073 FocusAboutToChange = 23,
0074 Enter = 10,
0075 Leave = 11,
0076 Paint = 12,
0077 Move = 13,
0078 Resize = 14,
0079 Create = 15,
0080 Destroy = 16,
0081 Show = 17,
0082 Hide = 18,
0083 Close = 19,
0084 Quit = 20,
0085 ParentChange = 21,
0086 ParentAboutToChange = 131,
0087 ThreadChange = 22,
0088 WindowActivate = 24,
0089 WindowDeactivate = 25,
0090 ShowToParent = 26,
0091 HideToParent = 27,
0092 Wheel = 31,
0093 WindowTitleChange = 33,
0094 WindowIconChange = 34,
0095 ApplicationWindowIconChange = 35,
0096 ApplicationFontChange = 36,
0097 ApplicationLayoutDirectionChange = 37,
0098 ApplicationPaletteChange = 38,
0099 PaletteChange = 39,
0100 Clipboard = 40,
0101 Speech = 42,
0102 MetaCall = 43,
0103 SockAct = 50,
0104 WinEventAct = 132,
0105 DeferredDelete = 52,
0106 DragEnter = 60,
0107 DragMove = 61,
0108 DragLeave = 62,
0109 Drop = 63,
0110 DragResponse = 64,
0111 ChildAdded = 68,
0112 ChildPolished = 69,
0113 ChildRemoved = 71,
0114 ShowWindowRequest = 73,
0115 PolishRequest = 74,
0116 Polish = 75,
0117 LayoutRequest = 76,
0118 UpdateRequest = 77,
0119 UpdateLater = 78,
0120
0121 EmbeddingControl = 79,
0122 ActivateControl = 80,
0123 DeactivateControl = 81,
0124 ContextMenu = 82,
0125 InputMethod = 83,
0126 TabletMove = 87,
0127 LocaleChange = 88,
0128 LanguageChange = 89,
0129 LayoutDirectionChange = 90,
0130 Style = 91,
0131 TabletPress = 92,
0132 TabletRelease = 93,
0133 OkRequest = 94,
0134 HelpRequest = 95,
0135
0136 IconDrag = 96,
0137
0138 FontChange = 97,
0139 EnabledChange = 98,
0140 ActivationChange = 99,
0141 StyleChange = 100,
0142 IconTextChange = 101,
0143 ModifiedChange = 102,
0144 MouseTrackingChange = 109,
0145
0146 WindowBlocked = 103,
0147 WindowUnblocked = 104,
0148 WindowStateChange = 105,
0149
0150 ReadOnlyChange = 106,
0151
0152 ToolTip = 110,
0153 WhatsThis = 111,
0154 StatusTip = 112,
0155
0156 ActionChanged = 113,
0157 ActionAdded = 114,
0158 ActionRemoved = 115,
0159
0160 FileOpen = 116,
0161
0162 Shortcut = 117,
0163 ShortcutOverride = 51,
0164
0165 WhatsThisClicked = 118,
0166
0167 ToolBarChange = 120,
0168
0169 ApplicationActivate = 121,
0170 ApplicationActivated = ApplicationActivate,
0171 ApplicationDeactivate = 122,
0172 ApplicationDeactivated = ApplicationDeactivate,
0173
0174 QueryWhatsThis = 123,
0175 EnterWhatsThisMode = 124,
0176 LeaveWhatsThisMode = 125,
0177
0178 ZOrderChange = 126,
0179
0180 HoverEnter = 127,
0181 HoverLeave = 128,
0182 HoverMove = 129,
0183
0184
0185
0186 #ifdef QT_KEYPAD_NAVIGATION
0187 EnterEditFocus = 150,
0188 LeaveEditFocus = 151,
0189 #endif
0190 AcceptDropsChange = 152,
0191
0192 ZeroTimerEvent = 154,
0193
0194 GraphicsSceneMouseMove = 155,
0195 GraphicsSceneMousePress = 156,
0196 GraphicsSceneMouseRelease = 157,
0197 GraphicsSceneMouseDoubleClick = 158,
0198 GraphicsSceneContextMenu = 159,
0199 GraphicsSceneHoverEnter = 160,
0200 GraphicsSceneHoverMove = 161,
0201 GraphicsSceneHoverLeave = 162,
0202 GraphicsSceneHelp = 163,
0203 GraphicsSceneDragEnter = 164,
0204 GraphicsSceneDragMove = 165,
0205 GraphicsSceneDragLeave = 166,
0206 GraphicsSceneDrop = 167,
0207 GraphicsSceneWheel = 168,
0208 GraphicsSceneLeave = 220,
0209
0210 KeyboardLayoutChange = 169,
0211
0212 DynamicPropertyChange = 170,
0213
0214 TabletEnterProximity = 171,
0215 TabletLeaveProximity = 172,
0216
0217 NonClientAreaMouseMove = 173,
0218 NonClientAreaMouseButtonPress = 174,
0219 NonClientAreaMouseButtonRelease = 175,
0220 NonClientAreaMouseButtonDblClick = 176,
0221
0222 MacSizeChange = 177,
0223
0224 ContentsRectChange = 178,
0225
0226 MacGLWindowChange = 179,
0227
0228 FutureCallOut = 180,
0229
0230 GraphicsSceneResize = 181,
0231 GraphicsSceneMove = 182,
0232
0233 CursorChange = 183,
0234 ToolTipChange = 184,
0235
0236 NetworkReplyUpdated = 185,
0237
0238 GrabMouse = 186,
0239 UngrabMouse = 187,
0240 GrabKeyboard = 188,
0241 UngrabKeyboard = 189,
0242
0243 StateMachineSignal = 192,
0244 StateMachineWrapped = 193,
0245
0246 TouchBegin = 194,
0247 TouchUpdate = 195,
0248 TouchEnd = 196,
0249
0250 #ifndef QT_NO_GESTURES
0251 NativeGesture = 197,
0252 #endif
0253 RequestSoftwareInputPanel = 199,
0254 CloseSoftwareInputPanel = 200,
0255
0256 WinIdChange = 203,
0257 #ifndef QT_NO_GESTURES
0258 Gesture = 198,
0259 GestureOverride = 202,
0260 #endif
0261 ScrollPrepare = 204,
0262 Scroll = 205,
0263
0264 Expose = 206,
0265
0266 InputMethodQuery = 207,
0267 OrientationChange = 208,
0268
0269 TouchCancel = 209,
0270
0271 ThemeChange = 210,
0272
0273 SockClose = 211,
0274
0275 PlatformPanel = 212,
0276
0277 StyleAnimationUpdate = 213,
0278 ApplicationStateChange = 214,
0279
0280 WindowChangeInternal = 215,
0281 ScreenChangeInternal = 216,
0282
0283 PlatformSurface = 217,
0284
0285 Pointer = 218,
0286
0287 TabletTrackingChange = 219,
0288
0289
0290 WindowAboutToChangeInternal = 221,
0291
0292 DevicePixelRatioChange = 222,
0293
0294 ChildWindowAdded = 223,
0295 ChildWindowRemoved = 224,
0296 ParentWindowAboutToChange = 225,
0297 ParentWindowChange = 226,
0298
0299 SafeAreaMarginsChange = 227,
0300
0301
0302
0303
0304 User = 1000,
0305 MaxUser = 65535
0306 };
0307 Q_ENUM(Type)
0308
0309 explicit QEvent(Type type);
0310 virtual ~QEvent();
0311 inline Type type() const { return static_cast<Type>(t); }
0312 inline bool spontaneous() const { return m_spont; }
0313
0314 inline virtual void setAccepted(bool accepted) { m_accept = accepted; }
0315 inline bool isAccepted() const { return m_accept; }
0316
0317 inline void accept() { m_accept = true; }
0318 inline void ignore() { m_accept = false; }
0319
0320 inline bool isInputEvent() const noexcept { return m_inputEvent; }
0321 inline bool isPointerEvent() const noexcept { return m_pointerEvent; }
0322 inline bool isSinglePointEvent() const noexcept { return m_singlePointEvent; }
0323
0324 static int registerEventType(int hint = -1) noexcept;
0325
0326 virtual QEvent *clone() const;
0327
0328 protected:
0329 QT_DEFINE_TAG_STRUCT(InputEventTag);
0330 QEvent(Type type, InputEventTag) : QEvent(type) { m_inputEvent = true; }
0331 QT_DEFINE_TAG_STRUCT(PointerEventTag);
0332 QEvent(Type type, PointerEventTag) : QEvent(type, InputEventTag{}) { m_pointerEvent = true; }
0333 QT_DEFINE_TAG_STRUCT(SinglePointEventTag);
0334 QEvent(Type type, SinglePointEventTag) : QEvent(type, PointerEventTag{}) { m_singlePointEvent = true; }
0335 quint16 t;
0336
0337 private:
0338
0339
0340
0341
0342
0343
0344
0345
0346
0347
0348
0349 bool m_posted = false;
0350 bool m_spont = false;
0351 bool m_accept = true;
0352 bool m_unused = false;
0353 quint16 m_reserved : 13;
0354 quint16 m_inputEvent : 1;
0355 quint16 m_pointerEvent : 1;
0356 quint16 m_singlePointEvent : 1;
0357
0358 friend class QCoreApplication;
0359 friend class QCoreApplicationPrivate;
0360 friend class QThreadData;
0361 friend class QApplication;
0362 friend class QGraphicsScenePrivate;
0363
0364
0365
0366 friend class QSpontaneKeyEvent;
0367
0368 Q_ALWAYS_INLINE
0369 void setSpontaneous() { m_spont = true; }
0370 };
0371
0372 class Q_CORE_EXPORT QTimerEvent : public QEvent
0373 {
0374 Q_DECL_EVENT_COMMON(QTimerEvent)
0375 public:
0376 explicit QTimerEvent(int timerId);
0377 explicit QTimerEvent(Qt::TimerId timerId);
0378
0379 int timerId() const { return qToUnderlying(id()); }
0380 Qt::TimerId id() const { return m_id; }
0381 bool matches(const QBasicTimer &timer) const noexcept
0382 { return m_id == timer.id(); }
0383
0384 protected:
0385 Qt::TimerId m_id;
0386 };
0387
0388 class QObject;
0389
0390 class Q_CORE_EXPORT QChildEvent : public QEvent
0391 {
0392 Q_DECL_EVENT_COMMON(QChildEvent)
0393 public:
0394 QChildEvent(Type type, QObject *child);
0395
0396 QObject *child() const { return c; }
0397 bool added() const { return type() == ChildAdded; }
0398 bool polished() const { return type() == ChildPolished; }
0399 bool removed() const { return type() == ChildRemoved; }
0400
0401 protected:
0402 QObject *c;
0403 };
0404
0405 class Q_CORE_EXPORT QDynamicPropertyChangeEvent : public QEvent
0406 {
0407 Q_DECL_EVENT_COMMON(QDynamicPropertyChangeEvent)
0408 public:
0409 explicit QDynamicPropertyChangeEvent(const QByteArray &name);
0410
0411 inline QByteArray propertyName() const { return n; }
0412
0413 private:
0414 QByteArray n;
0415 };
0416
0417 QT_END_NAMESPACE
0418
0419 #endif