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