diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/kernel/qcoreevent.cpp | 32 | ||||
-rw-r--r-- | src/corelib/kernel/qcoreevent.h | 29 | ||||
-rw-r--r-- | src/gui/kernel/qevent.cpp | 87 | ||||
-rw-r--r-- | src/gui/kernel/qevent.h | 85 |
4 files changed, 112 insertions, 121 deletions
diff --git a/src/corelib/kernel/qcoreevent.cpp b/src/corelib/kernel/qcoreevent.cpp index 847f3227ea..86d43d2d96 100644 --- a/src/corelib/kernel/qcoreevent.cpp +++ b/src/corelib/kernel/qcoreevent.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Copyright (C) 2016 Intel Corporation. ** Contact: https://www.qt.io/licensing/ ** @@ -295,9 +295,8 @@ QT_BEGIN_NAMESPACE Contructs an event object of type \a type. */ QEvent::QEvent(Type type) - : d(nullptr), t(type), m_posted(false), m_spont(false), m_accept(true), - m_inputEvent(false), m_pointerEvent(false), m_singlePointEvent(false), - m_reserved(0) + : t(type), m_reserved(0), + m_inputEvent(false), m_pointerEvent(false), m_singlePointEvent(false) { Q_TRACE(QEvent_ctor, this, t); } @@ -306,17 +305,7 @@ QEvent::QEvent(Type type) \internal Copies the \a other event. */ -QEvent::QEvent(const QEvent &other) - : d(other.d), t(other.t), m_posted(other.m_posted), m_spont(other.m_spont), - m_accept(other.m_accept), m_inputEvent(other.m_inputEvent), - m_pointerEvent(other.m_pointerEvent), m_singlePointEvent(other.m_singlePointEvent), - m_reserved(other.m_reserved) -{ - Q_TRACE(QEvent_ctor, this, t); - // if QEventPrivate becomes available, make sure to implement a - // virtual QEventPrivate *clone() const; function so we can copy here - Q_ASSERT_X(!d, "QEvent", "Impossible, this can't happen: QEventPrivate isn't defined anywhere"); -} +QEvent::QEvent(const QEvent &other) = default; /*! \internal @@ -351,18 +340,7 @@ QEvent::QEvent(const QEvent &other) Copying events is a bad idea, yet some Qt 4 code does it (notably, QApplication and the state machine). */ -QEvent &QEvent::operator=(const QEvent &other) -{ - // if QEventPrivate becomes available, make sure to implement a - // virtual QEventPrivate *clone() const; function so we can copy here - Q_ASSERT_X(!other.d, "QEvent", "Impossible, this can't happen: QEventPrivate isn't defined anywhere"); - - t = other.t; - m_posted = other.m_posted; - m_spont = other.m_spont; - m_accept = other.m_accept; - return *this; -} +QEvent &QEvent::operator=(const QEvent &other) = default; /*! Destroys the event. If it was \l{QCoreApplication::postEvent()}{posted}, diff --git a/src/corelib/kernel/qcoreevent.h b/src/corelib/kernel/qcoreevent.h index dbca4adaab..cfaa959dec 100644 --- a/src/corelib/kernel/qcoreevent.h +++ b/src/corelib/kernel/qcoreevent.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. @@ -320,27 +320,34 @@ protected: QEvent(Type type, PointerEventTag) : QEvent(type, InputEventTag{}) { m_pointerEvent = true; } struct SinglePointEventTag { explicit SinglePointEventTag() = default; }; QEvent(Type type, SinglePointEventTag) : QEvent(type, PointerEventTag{}) { m_singlePointEvent = true; } - QEventPrivate *d; + QEventPrivate *d = nullptr; quint16 t; private: - quint16 m_posted : 1; - quint16 m_spont : 1; - quint16 m_accept : 1; + /* + We can assume that C++ types are 8-byte aligned, and we can't assume that compilers + coalesce data members from subclasses. Use bitfields to fill up to next 8-byte + aligned size, which is 24 bytes. That way we don't waste memory, and have plenty of room + for future flags. + Don't use bitfields for the most important flags, as that would generate more code, and + access is always inline. Bytes used are: + 8 vptr + 8 d-pointer + 2 type + 3 bool flags => 3 bytes left, so 24 bits. However, + compiler will add padding after the booleans, so add another unused bool, which leaves + us with 16 bits. + */ + bool m_posted = false; + bool m_spont = false; + bool m_accept = true; + bool m_unused = false; + quint16 m_reserved : 13; quint16 m_inputEvent : 1; quint16 m_pointerEvent : 1; quint16 m_singlePointEvent : 1; - quint16 m_reserved : 10; friend class QCoreApplication; friend class QCoreApplicationPrivate; friend class QThreadData; friend class QApplication; -#if QT_CONFIG(shortcut) - friend class QShortcutMap; -#endif - friend class QGraphicsView; - friend class QGraphicsScene; friend class QGraphicsScenePrivate; // from QtTest: friend class QSpontaneKeyEvent; diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index 91b387324a..659f0e353b 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -151,21 +151,21 @@ QEnterEvent::~QEnterEvent() \internal */ QInputEvent::QInputEvent(Type type, const QInputDevice *dev, Qt::KeyboardModifiers modifiers) - : QEvent(type, QEvent::InputEventTag{}), m_dev(dev), m_modState(modifiers) + : QEvent(type, QEvent::InputEventTag{}), m_dev(dev), m_modState(modifiers), m_reserved(0) {} /*! \internal */ QInputEvent::QInputEvent(QEvent::Type type, QEvent::PointerEventTag, const QInputDevice *dev, Qt::KeyboardModifiers modifiers) - : QEvent(type, QEvent::PointerEventTag{}), m_dev(dev), m_modState(modifiers) + : QEvent(type, QEvent::PointerEventTag{}), m_dev(dev), m_modState(modifiers), m_reserved(0) {} /*! \internal */ QInputEvent::QInputEvent(QEvent::Type type, QEvent::SinglePointEventTag, const QInputDevice *dev, Qt::KeyboardModifiers modifiers) - : QEvent(type, QEvent::SinglePointEventTag{}), m_dev(dev), m_modState(modifiers) + : QEvent(type, QEvent::SinglePointEventTag{}), m_dev(dev), m_modState(modifiers), m_reserved(0) {} /*! @@ -214,14 +214,14 @@ QInputEvent::~QInputEvent() */ /*! - \fn ulong QInputEvent::timestamp() const + \fn quint64 QInputEvent::timestamp() const Returns the window system's timestamp for this event. It will normally be in milliseconds since some arbitrary point in time, such as the time when the system was started. */ -/*! \fn void QInputEvent::setTimestamp(ulong atimestamp) +/*! \fn void QInputEvent::setTimestamp(quint64 atimestamp) \internal @@ -336,7 +336,7 @@ const QPointingDevice *QPointerEvent::pointingDevice() const /*! \internal Sets the timestamp for this event and its points(). */ -void QPointerEvent::setTimestamp(ulong timestamp) +void QPointerEvent::setTimestamp(quint64 timestamp) { QInputEvent::setTimestamp(timestamp); for (auto &p : m_points) @@ -521,8 +521,8 @@ QSinglePointEvent::QSinglePointEvent(QEvent::Type type, const QPointingDevice *d m_button(button), m_mouseState(buttons), m_source(source), - m_doubleClick(false), - m_reserved(0) + m_reserved(0), m_reserved2(0), + m_doubleClick(false), m_phase(0), m_invertedScrolling(0) { bool isPress = (button != Qt::NoButton && (button | buttons) == buttons); bool isWheel = (type == QEvent::Type::Wheel); @@ -569,8 +569,8 @@ QSinglePointEvent::QSinglePointEvent(QEvent::Type type, const QPointingDevice *d m_button(button), m_mouseState(buttons), m_source(source), - m_doubleClick(false), - m_reserved(0) + m_reserved(0), m_reserved2(0), + m_doubleClick(false), m_phase(0), m_invertedScrolling(0) { m_points << point; } @@ -1159,8 +1159,10 @@ QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF &globalPos, QPoint pi Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::ScrollPhase phase, bool inverted, Qt::MouseEventSource source, const QPointingDevice *device) : QSinglePointEvent(Wheel, device, pos, pos, globalPos, Qt::NoButton, buttons, modifiers, source), - m_phase(phase), m_invertedScrolling(inverted), m_pixelDelta(pixelDelta), m_angleDelta(angleDelta) + m_pixelDelta(pixelDelta), m_angleDelta(angleDelta) { + m_phase = phase; + m_invertedScrolling = inverted; } /*! @@ -1311,7 +1313,7 @@ bool QWheelEvent::isEndEvent() const QKeyEvent::QKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers, const QString& text, bool autorep, quint16 count) : QInputEvent(type, QInputDevice::primaryKeyboard(), modifiers), m_text(text), m_key(key), - m_scanCode(0), m_virtualKey(0), m_modifiers(0), + m_scanCode(0), m_virtualKey(0), m_nativeModifiers(0), m_count(count), m_autoRepeat(autorep) { if (type == QEvent::ShortcutOverride) @@ -1340,7 +1342,7 @@ QKeyEvent::QKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers, quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers, const QString &text, bool autorep, quint16 count, const QInputDevice *device) : QInputEvent(type, device, modifiers), m_text(text), m_key(key), - m_scanCode(nativeScanCode), m_virtualKey(nativeVirtualKey), m_modifiers(nativeModifiers), + m_scanCode(nativeScanCode), m_virtualKey(nativeVirtualKey), m_nativeModifiers(nativeModifiers), m_count(count), m_autoRepeat(autorep) { if (type == QEvent::ShortcutOverride) @@ -1938,21 +1940,6 @@ QIconDragEvent::~QIconDragEvent() The \a pos parameter specifies the mouse position relative to the receiving widget. \a globalPos is the mouse position in absolute - coordinates. -*/ -QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos, const QPoint &globalPos) - : QContextMenuEvent(reason, pos, globalPos, Qt::NoModifier) -{} - -/*! - Constructs a context menu event object with the accept parameter - flag set to false. - - The \a reason parameter must be QContextMenuEvent::Mouse or - QContextMenuEvent::Keyboard. - - The \a pos parameter specifies the mouse position relative to the - receiving widget. \a globalPos is the mouse position in absolute coordinates. The \a modifiers holds the keyboard modifiers. */ QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos, const QPoint &globalPos, @@ -2280,8 +2267,9 @@ QInputMethodEvent::QInputMethodEvent(const QString &preeditText, const QList<Att Constructs a copy of \a other. */ QInputMethodEvent::QInputMethodEvent(const QInputMethodEvent &other) - : QEvent(QEvent::InputMethod), m_preedit(other.m_preedit), m_attributes(other.m_attributes), - m_commit(other.m_commit), m_replacementStart(other.m_replacementStart), m_replacementLength(other.m_replacementLength) + : QEvent(QEvent::InputMethod), m_preedit(other.m_preedit), m_commit(other.m_commit), + m_attributes(other.m_attributes), m_replacementStart(other.m_replacementStart), + m_replacementLength(other.m_replacementLength) { } @@ -2536,15 +2524,15 @@ QVariant QInputMethodQueryEvent::value(Qt::InputMethodQuery query) const tangentialPressure(), z() */ QTabletEvent::QTabletEvent(Type type, const QPointingDevice *dev, const QPointF &pos, const QPointF &globalPos, - qreal pressure, int xTilt, int yTilt, - qreal tangentialPressure, qreal rotation, int z, + qreal pressure, float xTilt, float yTilt, + float tangentialPressure, qreal rotation, float z, Qt::KeyboardModifiers keyState, Qt::MouseButton button, Qt::MouseButtons buttons) : QSinglePointEvent(type, dev, pos, pos, globalPos, button, buttons, keyState), + m_tangential(tangentialPressure), m_xTilt(xTilt), m_yTilt(yTilt), - m_z(z), - m_tangential(tangentialPressure) + m_z(z) { QMutableEventPoint &mut = QMutableEventPoint::from(point(0)); mut.setPressure(pressure); @@ -2567,6 +2555,8 @@ QTabletEvent::~QTabletEvent() direction from the neutrual position. If the device does not support tangential pressure, this value is always 0.0. + \note The value is stored as a single-precision float. + \sa pressure() */ @@ -2591,7 +2581,7 @@ QTabletEvent::~QTabletEvent() */ /*! - \fn int QTabletEvent::xTilt() const + \fn qreal QTabletEvent::xTilt() const Returns the angle between the device (a pen, for example) and the perpendicular in the direction of the x axis. @@ -2600,17 +2590,21 @@ QTabletEvent::~QTabletEvent() \image qtabletevent-tilt.png + \note The value is stored as a single-precision float. + \sa yTilt() */ /*! - \fn int QTabletEvent::yTilt() const + \fn qreal QTabletEvent::yTilt() const Returns the angle between the device (a pen, for example) and the perpendicular in the direction of the y axis. Positive values are towards the bottom of the tablet. The angle is within the range -60 to +60 degrees. + \note The value is stored as a single-precision float. + \sa xTilt() */ @@ -2645,12 +2639,14 @@ QTabletEvent::~QTabletEvent() */ /*! - \fn int QTabletEvent::z() const + \fn qreal QTabletEvent::z() const Returns the z position of the device. Typically this is represented by a wheel on a 4D Mouse. If the device does not support a Z-axis, this value is always zero. This is \b not the same as pressure. + \note The value is stored as a single-precision float. + \sa pressure() */ @@ -2787,16 +2783,17 @@ QTabletEvent::~QTabletEvent() \a realValue is the \macos event parameter, \a sequenceId and \a intValue are the Windows event parameters. \since 5.10 */ -QNativeGestureEvent::QNativeGestureEvent(Qt::NativeGestureType type, const QPointingDevice *device, const QPointF &localPos, const QPointF &scenePos, - const QPointF &globalPos, qreal realValue, ulong sequenceId, quint64 intValue) - : QSinglePointEvent(QEvent::NativeGesture, device, localPos, scenePos, globalPos, Qt::NoButton, Qt::NoButton, Qt::NoModifier), - m_gestureType(type), m_realValue(realValue), m_sequenceId(sequenceId), - m_intValue(intValue) +QNativeGestureEvent::QNativeGestureEvent(Qt::NativeGestureType type, const QPointingDevice *device, + const QPointF &localPos, const QPointF &scenePos, + const QPointF &globalPos, qreal realValue, quint64 sequenceId, + quint64 intValue) + : QSinglePointEvent(QEvent::NativeGesture, device, localPos, scenePos, globalPos, Qt::NoButton, + Qt::NoButton, Qt::NoModifier), + m_sequenceId(sequenceId), m_intValue(intValue), m_realValue(realValue), m_gestureType(type) { } -QNativeGestureEvent::~QNativeGestureEvent() - = default; +QNativeGestureEvent::~QNativeGestureEvent() = default; /*! \fn QNativeGestureEvent::gestureType() const @@ -3666,7 +3663,7 @@ QToolBarChangeEvent::~QToolBarChangeEvent() for the same key sequence. */ QShortcutEvent::QShortcutEvent(const QKeySequence &key, int id, bool ambiguous) - : QEvent(Shortcut), m_sequence(key), m_ambiguous(ambiguous), m_shortcutId(id) + : QEvent(Shortcut), m_sequence(key), m_shortcutId(id), m_ambiguous(ambiguous) { } diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h index ce61b3a34f..609d59740e 100644 --- a/src/gui/kernel/qevent.h +++ b/src/gui/kernel/qevent.h @@ -81,17 +81,18 @@ public: QInputDevice::DeviceType deviceType() const { return m_dev ? m_dev->type() : QInputDevice::DeviceType::Unknown; } inline Qt::KeyboardModifiers modifiers() const { return m_modState; } inline void setModifiers(Qt::KeyboardModifiers modifiers) { m_modState = modifiers; } - inline ulong timestamp() const { return m_timeStamp; } - virtual void setTimestamp(ulong timestamp) { m_timeStamp = timestamp; } + inline quint64 timestamp() const { return m_timeStamp; } + virtual void setTimestamp(quint64 timestamp) { m_timeStamp = timestamp; } protected: QInputEvent(Type type, PointerEventTag, const QInputDevice *dev, Qt::KeyboardModifiers modifiers = Qt::NoModifier); QInputEvent(Type type, SinglePointEventTag, const QInputDevice *dev, Qt::KeyboardModifiers modifiers = Qt::NoModifier); const QInputDevice *m_dev = nullptr; + quint64 m_timeStamp = 0; Qt::KeyboardModifiers m_modState = Qt::NoModifier; - ulong m_timeStamp = 0; - qint64 m_extra = 0; // reserved, unused for now + // fill up to the closest 8-byte aligned size: 48 + quint32 m_reserved = 0; }; class Q_GUI_EXPORT QPointerEvent : public QInputEvent @@ -104,7 +105,7 @@ public: QPointingDevice::PointerType pointerType() const { return pointingDevice() ? pointingDevice()->pointerType() : QPointingDevice::PointerType::Unknown; } - void setTimestamp(ulong timestamp) override; + void setTimestamp(quint64 timestamp) override; qsizetype pointCount() const { return m_points.count(); } QEventPoint &point(qsizetype i) { return m_points[i]; } const QList<QEventPoint> &points() const { return m_points; } @@ -165,9 +166,20 @@ protected: Qt::MouseButton m_button = Qt::NoButton; Qt::MouseButtons m_mouseState = Qt::NoButton; - quint32 m_source : 8; // actually Qt::MouseEventSource - quint32 m_doubleClick : 1; - quint32 m_reserved : 7; // subclasses dovetail their flags, so we don't reserve all 32 bits here + Qt::MouseEventSource m_source; + /* + Fill up to the next 8-byte aligned size: 88 + We have 32bits left, use some for QSinglePointEvent subclasses so that + we don't end up with gaps. + */ + // split this in two quint16; with a quint32, MSVC would 32-bit align it + quint16 m_reserved; + quint16 m_reserved2 : 11; + // for QMouseEvent + quint16 m_doubleClick : 1; + // for QWheelEvent + quint16 m_phase : 3; + quint16 m_invertedScrolling : 1; }; class Q_GUI_EXPORT QEnterEvent : public QSinglePointEvent @@ -273,7 +285,6 @@ public: inline QPointF oldPosF() const { return m_oldPos; } protected: - quint32 m_reserved : 16; QPointF m_oldPos; // TODO remove? }; @@ -309,9 +320,6 @@ public: Qt::MouseEventSource source() const { return Qt::MouseEventSource(m_source); } protected: - quint32 m_phase : 3; - quint32 m_invertedScrolling : 1; - quint32 m_reserved : 12; QPoint m_pixelDelta; QPoint m_angleDelta; }; @@ -323,8 +331,8 @@ class Q_GUI_EXPORT QTabletEvent : public QSinglePointEvent public: QTabletEvent(Type t, const QPointingDevice *device, const QPointF &pos, const QPointF &globalPos, - qreal pressure, int xTilt, int yTilt, - qreal tangentialPressure, qreal rotation, int z, + qreal pressure, float xTilt, float yTilt, + float tangentialPressure, qreal rotation, float z, Qt::KeyboardModifiers keyState, Qt::MouseButton button, Qt::MouseButtons buttons); ~QTabletEvent(); @@ -356,15 +364,16 @@ public: #endif inline qreal pressure() const { Q_ASSERT(!points().isEmpty()); return points().first().pressure(); } inline qreal rotation() const { Q_ASSERT(!points().isEmpty()); return points().first().rotation(); } - inline int z() const { return m_z; } + inline qreal z() const { return m_z; } inline qreal tangentialPressure() const { return m_tangential; } - inline int xTilt() const { return m_xTilt; } - inline int yTilt() const { return m_yTilt; } + inline qreal xTilt() const { return m_xTilt; } + inline qreal yTilt() const { return m_yTilt; } protected: - quint32 m_reserved : 16; - int m_xTilt, m_yTilt, m_z; - qreal m_tangential; + float m_tangential; + float m_xTilt; + float m_yTilt; + float m_z; }; #endif // QT_CONFIG(tabletevent) @@ -373,9 +382,9 @@ class Q_GUI_EXPORT QNativeGestureEvent : public QSinglePointEvent { public: QNativeGestureEvent(Qt::NativeGestureType type, const QPointingDevice *dev, const QPointF &localPos, const QPointF &scenePos, - const QPointF &globalPos, qreal value, ulong sequenceId, quint64 intArgument); + const QPointF &globalPos, qreal value, quint64 sequenceId, quint64 intArgument); ~QNativeGestureEvent(); - Qt::NativeGestureType gestureType() const { return Qt::NativeGestureType(m_gestureType); } + Qt::NativeGestureType gestureType() const { return m_gestureType; } qreal value() const { return m_realValue; } #if QT_DEPRECATED_SINCE(6, 0) @@ -394,11 +403,11 @@ public: #endif protected: - quint32 m_gestureType : 4; - quint32 m_reserved : 12; - qreal m_realValue; - ulong m_sequenceId; + quint64 m_sequenceId; quint64 m_intValue; + qreal m_realValue; + Qt::NativeGestureType m_gestureType; + quint32 m_reserved; }; #endif // QT_CONFIG(gestures) @@ -428,7 +437,7 @@ public: inline quint32 nativeScanCode() const { return m_scanCode; } inline quint32 nativeVirtualKey() const { return m_virtualKey; } - inline quint32 nativeModifiers() const { return m_modifiers; } + inline quint32 nativeModifiers() const { return m_nativeModifiers; } #if QT_CONFIG(shortcut) friend inline bool operator==(QKeyEvent *e, QKeySequence::StandardKey key) @@ -442,10 +451,9 @@ protected: int m_key; quint32 m_scanCode; quint32 m_virtualKey; - quint32 m_modifiers; - quint16 m_count; + quint32 m_nativeModifiers; + quint16 m_count : 15; quint16 m_autoRepeat : 1; - // ushort reserved:15; }; @@ -578,8 +586,7 @@ public: enum Reason { Mouse, Keyboard, Other }; QContextMenuEvent(Reason reason, const QPoint &pos, const QPoint &globalPos, - Qt::KeyboardModifiers modifiers); - QContextMenuEvent(Reason reason, const QPoint &pos, const QPoint &globalPos); + Qt::KeyboardModifiers modifiers = Qt::NoModifier); QContextMenuEvent(Reason reason, const QPoint &pos); ~QContextMenuEvent(); @@ -650,8 +657,8 @@ public: private: QString m_preedit; - QList<Attribute> m_attributes; QString m_commit; + QList<Attribute> m_attributes; int m_replacementStart; int m_replacementLength; }; @@ -814,13 +821,15 @@ private: #if QT_CONFIG(action) class Q_GUI_EXPORT QActionEvent : public QEvent { - QAction *m_action, *m_before; public: QActionEvent(int type, QAction *action, QAction *before = nullptr); ~QActionEvent(); inline QAction *action() const { return m_action; } inline QAction *before() const { return m_before; } +private: + QAction *m_action; + QAction *m_before; }; #endif // QT_CONFIG(action) @@ -848,7 +857,7 @@ public: inline bool toggle() const { return m_toggle; } private: - uint m_toggle : 1; + bool m_toggle; }; #endif @@ -864,8 +873,8 @@ public: inline bool isAmbiguous() const { return m_ambiguous; } protected: QKeySequence m_sequence; - bool m_ambiguous; int m_shortcutId; + bool m_ambiguous; }; #endif @@ -939,9 +948,9 @@ public: void setContentPos(const QPointF &pos); private: - QPointF m_startPos; - QSizeF m_viewportSize; QRectF m_contentPosRange; + QSizeF m_viewportSize; + QPointF m_startPos; QPointF m_contentPos; }; |