Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 09:26:25

0001 // Copyright (C) 2020 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
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         /* check that covariant return is safe to add */ \
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           // event base class
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           If you get a strange compiler error on the line with None,
0058           it's probably because you're also including X11 headers,
0059           which #define the symbol None. Put the X11 includes after
0060           the Qt includes to solve this problem.
0061         */
0062         None = 0,                               // invalid event
0063         Timer = 1,                              // timer event
0064         MouseButtonPress = 2,                   // mouse button pressed
0065         MouseButtonRelease = 3,                 // mouse button released
0066         MouseButtonDblClick = 4,                // mouse button double click
0067         MouseMove = 5,                          // mouse move
0068         KeyPress = 6,                           // key pressed
0069         KeyRelease = 7,                         // key released
0070         FocusIn = 8,                            // keyboard focus received
0071         FocusOut = 9,                           // keyboard focus lost
0072         FocusAboutToChange = 23,                // keyboard focus is about to be lost
0073         Enter = 10,                             // mouse enters widget
0074         Leave = 11,                             // mouse leaves widget
0075         Paint = 12,                             // paint widget
0076         Move = 13,                              // move widget
0077         Resize = 14,                            // resize widget
0078         Create = 15,                            // after widget creation
0079         Destroy = 16,                           // during widget destruction
0080         Show = 17,                              // widget is shown
0081         Hide = 18,                              // widget is hidden
0082         Close = 19,                             // request to close widget
0083         Quit = 20,                              // request to quit application
0084         ParentChange = 21,                      // object has been reparented
0085         ParentAboutToChange = 131,              // sent just before the parent change is done
0086         ThreadChange = 22,                      // object has changed threads
0087         WindowActivate = 24,                    // window was activated
0088         WindowDeactivate = 25,                  // window was deactivated
0089         ShowToParent = 26,                      // widget is shown to parent
0090         HideToParent = 27,                      // widget is hidden to parent
0091         Wheel = 31,                             // wheel event
0092         WindowTitleChange = 33,                 // window title changed
0093         WindowIconChange = 34,                  // icon changed
0094         ApplicationWindowIconChange = 35,       // application icon changed
0095         ApplicationFontChange = 36,             // application font changed
0096         ApplicationLayoutDirectionChange = 37,  // application layout direction changed
0097         ApplicationPaletteChange = 38,          // application palette changed
0098         PaletteChange = 39,                     // widget palette changed
0099         Clipboard = 40,                         // internal clipboard event
0100         Speech = 42,                            // reserved for speech input
0101         MetaCall =  43,                         // meta call event
0102         SockAct = 50,                           // socket activation
0103         WinEventAct = 132,                      // win event activation
0104         DeferredDelete = 52,                    // deferred delete event
0105         DragEnter = 60,                         // drag moves into widget
0106         DragMove = 61,                          // drag moves in widget
0107         DragLeave = 62,                         // drag leaves or is cancelled
0108         Drop = 63,                              // actual drop
0109         DragResponse = 64,                      // drag accepted/rejected
0110         ChildAdded = 68,                        // new child widget
0111         ChildPolished = 69,                     // polished child widget
0112         ChildRemoved = 71,                      // deleted child widget
0113         ShowWindowRequest = 73,                 // widget's window should be mapped
0114         PolishRequest = 74,                     // widget should be polished
0115         Polish = 75,                            // widget is polished
0116         LayoutRequest = 76,                     // widget should be relayouted
0117         UpdateRequest = 77,                     // widget should be repainted
0118         UpdateLater = 78,                       // request update() later
0119 
0120         EmbeddingControl = 79,                  // ActiveX embedding
0121         ActivateControl = 80,                   // ActiveX activation
0122         DeactivateControl = 81,                 // ActiveX deactivation
0123         ContextMenu = 82,                       // context popup menu
0124         InputMethod = 83,                       // input method
0125         TabletMove = 87,                        // Wacom tablet event
0126         LocaleChange = 88,                      // the system locale changed
0127         LanguageChange = 89,                    // the application language changed
0128         LayoutDirectionChange = 90,             // the layout direction changed
0129         Style = 91,                             // internal style event
0130         TabletPress = 92,                       // tablet press
0131         TabletRelease = 93,                     // tablet release
0132         OkRequest = 94,                         // CE (Ok) button pressed
0133         HelpRequest = 95,                       // CE (?)  button pressed
0134 
0135         IconDrag = 96,                          // proxy icon dragged
0136 
0137         FontChange = 97,                        // font has changed
0138         EnabledChange = 98,                     // enabled state has changed
0139         ActivationChange = 99,                  // window activation has changed
0140         StyleChange = 100,                      // style has changed
0141         IconTextChange = 101,                   // icon text has changed.  Deprecated.
0142         ModifiedChange = 102,                   // modified state has changed
0143         MouseTrackingChange = 109,              // mouse tracking state has changed
0144 
0145         WindowBlocked = 103,                    // window is about to be blocked modally
0146         WindowUnblocked = 104,                  // windows modal blocking has ended
0147         WindowStateChange = 105,
0148 
0149         ReadOnlyChange = 106,                   // readonly state has changed
0150 
0151         ToolTip = 110,
0152         WhatsThis = 111,
0153         StatusTip = 112,
0154 
0155         ActionChanged = 113,
0156         ActionAdded = 114,
0157         ActionRemoved = 115,
0158 
0159         FileOpen = 116,                         // file open request
0160 
0161         Shortcut = 117,                         // shortcut triggered
0162         ShortcutOverride = 51,                  // shortcut override request
0163 
0164         WhatsThisClicked = 118,
0165 
0166         ToolBarChange = 120,                    // toolbar visibility toggled
0167 
0168         ApplicationActivate = 121,              // deprecated. Use ApplicationStateChange instead.
0169         ApplicationActivated = ApplicationActivate, // deprecated
0170         ApplicationDeactivate = 122,            // deprecated. Use ApplicationStateChange instead.
0171         ApplicationDeactivated = ApplicationDeactivate, // deprecated
0172 
0173         QueryWhatsThis = 123,                   // query what's this widget help
0174         EnterWhatsThisMode = 124,
0175         LeaveWhatsThisMode = 125,
0176 
0177         ZOrderChange = 126,                     // child widget has had its z-order changed
0178 
0179         HoverEnter = 127,                       // mouse cursor enters a hover widget
0180         HoverLeave = 128,                       // mouse cursor leaves a hover widget
0181         HoverMove = 129,                        // mouse cursor move inside a hover widget
0182 
0183         // last event id used = 132
0184 
0185 #ifdef QT_KEYPAD_NAVIGATION
0186         EnterEditFocus = 150,                   // enter edit mode in keypad navigation
0187         LeaveEditFocus = 151,                   // enter edit mode in keypad navigation
0188 #endif
0189         AcceptDropsChange = 152,
0190 
0191         ZeroTimerEvent = 154,                   // Used for Windows Zero timer events
0192 
0193         GraphicsSceneMouseMove = 155,           // GraphicsView
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,             // keyboard layout changed
0210 
0211         DynamicPropertyChange = 170,            // A dynamic property was changed through setProperty/property
0212 
0213         TabletEnterProximity = 171,
0214         TabletLeaveProximity = 172,
0215 
0216         NonClientAreaMouseMove = 173,
0217         NonClientAreaMouseButtonPress = 174,
0218         NonClientAreaMouseButtonRelease = 175,
0219         NonClientAreaMouseButtonDblClick = 176,
0220 
0221         MacSizeChange = 177,                    // when the Qt::WA_Mac{Normal,Small,Mini}Size changes
0222 
0223         ContentsRectChange = 178,               // sent by QWidget::setContentsMargins (internal)
0224 
0225         MacGLWindowChange = 179,                // Internal! the window of the GLWidget has changed
0226 
0227         FutureCallOut = 180,
0228 
0229         GraphicsSceneResize  = 181,
0230         GraphicsSceneMove  = 182,
0231 
0232         CursorChange = 183,
0233         ToolTipChange = 184,
0234 
0235         NetworkReplyUpdated = 185,              // Internal for QNetworkReply
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,                    // QtGui native gesture
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,                // Screen orientation has changed
0267 
0268         TouchCancel = 209,
0269 
0270         ThemeChange = 210,
0271 
0272         SockClose = 211,                        // socket closed
0273 
0274         PlatformPanel = 212,
0275 
0276         StyleAnimationUpdate = 213,             // style animation target should be updated
0277         ApplicationStateChange = 214,
0278 
0279         WindowChangeInternal = 215,             // internal for QQuickWidget and texture-based widgets
0280         ScreenChangeInternal = 216,
0281 
0282         PlatformSurface = 217,                  // Platform surface created or about to be destroyed
0283 
0284         Pointer = 218,                          // Qt 5: QQuickPointerEvent; Qt 6: unused so far
0285 
0286         TabletTrackingChange = 219,             // tablet tracking state has changed
0287 
0288         // GraphicsSceneLeave = 220,
0289         WindowAboutToChangeInternal = 221,      // internal for QQuickWidget and texture-based widgets
0290 
0291         DevicePixelRatioChange = 222,
0292 
0293         ChildWindowAdded = 223,
0294         ChildWindowRemoved = 224,
0295         ParentWindowAboutToChange = 225,
0296         ParentWindowChange = 226,
0297 
0298         SafeAreaMarginsChange = 227,
0299 
0300         // 512 reserved for Qt Jambi's MetaCall event
0301         // 513 reserved for Qt Jambi's DeleteOnMainThread event
0302 
0303         User = 1000,                            // first user event id
0304         MaxUser = 65535                         // last user event id
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         We can assume that C++ types are 8-byte aligned, and we can't assume that compilers
0339         coalesce data members from subclasses. Use bitfields to fill up to next 8-byte
0340         aligned size, which is 16 bytes. That way we don't waste memory, and have plenty of room
0341         for future flags.
0342         Don't use bitfields for the most important flags, as that would generate more code, and
0343         access is always inline. Bytes used are:
0344         8 vptr + 2 type + 3 bool flags => 3 bytes left, so 24 bits. However, compilers will word-
0345         align the quint16s after the bools, so add another unused bool to fill that gap, which
0346         leaves us with 16 bits.
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     // from QtTest:
0363     // QtWebEngine event handling requires forwarding events as spontaneous.
0364     // Impersonated QSpontaneKeyEvent in QtWebEngine to handle such cases.
0365     friend class QSpontaneKeyEvent;
0366     // needs this:
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 // QCOREEVENT_H