summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2020-07-21 22:08:36 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2020-08-06 10:23:56 +0200
commit6d6ed64d6ca27c1b5fec305e6ed9b923b5bb1037 (patch)
tree1cf102bc85019cf61a6b398c6b1fae0de367759d /src/gui/kernel
parentb9873b7dde4042445dbb5ff3c46cea96b2dea4aa (diff)
Add QPointerEvent::is[Press|Update|Release]Event accessors
QQuickPointerEvent had them, so despite how trivial they look, it's very convenient to keep using them in QQuickWindow rather than duplicating these kinds of checks in various places, and for multiple event types too. Change-Id: I32ad8110fd2361e69de50a679ddbdb2a2db7ecee Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/gui/kernel')
-rw-r--r--src/gui/kernel/qevent.cpp50
-rw-r--r--src/gui/kernel/qevent.h12
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;