diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/kernel/qevent.cpp | 50 | ||||
-rw-r--r-- | src/gui/kernel/qevent.h | 12 |
2 files changed, 62 insertions, 0 deletions
diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index 517233482f..ea831f9a40 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -362,6 +362,30 @@ QSinglePointEvent::QSinglePointEvent(QEvent::Type type, const QPointingDevice *d } /*! + Returns true if this event represents a \l {button()}{button} being pressed. +*/ +bool QSinglePointEvent::isPressEvent() const +{ + return m_button != Qt::NoButton && m_mouseState.testFlag(m_button); +} + +/*! + Returns true if this event does not include a change in \l {buttons()}{button state}. +*/ +bool QSinglePointEvent::isUpdateEvent() const +{ + return m_button == Qt::NoButton; +} + +/*! + Returns true if this event represents a \l {button()}{button} being released. +*/ +bool QSinglePointEvent::isReleaseEvent() const +{ + return m_button != Qt::NoButton && !m_mouseState.testFlag(m_button); +} + +/*! \fn QPointingDevice::PointerType QPointerEvent::pointerType() const Returns the type of point that generated the event. @@ -4224,6 +4248,32 @@ QTouchEvent::QTouchEvent(QEvent::Type eventType, QTouchEvent::~QTouchEvent() { } +/*! + Returns true if this event includes at least one newly-pressed touchpoint. +*/ +bool QTouchEvent::isPressEvent() const +{ + return m_touchPointStates.testFlag(QEventPoint::State::Pressed); +} + +/*! + Returns true if this event does not include newly-pressed or newly-released + touchpoints. +*/ +bool QTouchEvent::isUpdateEvent() const +{ + return !m_touchPointStates.testFlag(QEventPoint::State::Pressed) && + !m_touchPointStates.testFlag(QEventPoint::State::Released); +} + +/*! + Returns true if this event includes at least one newly-released touchpoint. +*/ +bool QTouchEvent::isReleaseEvent() const +{ + return m_touchPointStates.testFlag(QEventPoint::State::Released); +} + /*! \fn QObject *QTouchEvent::target() const Returns the target object within the window on which the event occurred. diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h index cfbaf8603e..8ba138a1bb 100644 --- a/src/gui/kernel/qevent.h +++ b/src/gui/kernel/qevent.h @@ -200,6 +200,9 @@ public: virtual ~QPointerEvent(); virtual int pointCount() const = 0; virtual const QEventPoint &point(int i) const = 0; + virtual bool isPressEvent() const { return false; } + virtual bool isUpdateEvent() const { return false; } + virtual bool isReleaseEvent() const { return false; } explicit QPointerEvent(Type type, const QPointingDevice *dev, Qt::KeyboardModifiers modifiers = Qt::NoModifier); const QPointingDevice *pointingDevice() const; @@ -225,6 +228,10 @@ public: inline QPointF scenePosition() const { return m_point.scenePosition(); } inline QPointF globalPosition() const { return m_point.globalPosition(); } + bool isPressEvent() const override; + bool isUpdateEvent() const override; + bool isReleaseEvent() const override; + protected: QEventPoint m_point; Qt::MouseButton m_button = Qt::NoButton; @@ -330,6 +337,8 @@ public: inline QPointF posF() const { return position(); } #endif // QT_DEPRECATED_SINCE(6, 0) + bool isUpdateEvent() const override { return true; } + // TODO deprecate when we figure out an actual replacement (point history?) inline QPoint oldPos() const { return m_oldPos.toPoint(); } inline QPointF oldPosF() const { return m_oldPos; } @@ -954,6 +963,9 @@ public: inline QObject *target() const { return m_target; } inline QEventPoint::States touchPointStates() const { return m_touchPointStates; } const QList<QEventPoint> &touchPoints() const { return m_touchPoints; } + bool isPressEvent() const override; + bool isUpdateEvent() const override; + bool isReleaseEvent() const override; protected: QObject *m_target = nullptr; |