From 5683c0afdaf942e81ba614bd44eda0cc59d0d7a1 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Fri, 16 Oct 2020 10:12:36 +0200 Subject: Add QSinglePointEvent::exclusivePointGrabber convenience property Since a single-point event (such as a QMouseEvent) only carries one point, it only has one grabber, so we can have a normal Q_PROPERTY. It's named exclusivePointGrabber to avoid shadowing the QPointerEvent::[set]exclusiveGrabber functions that take QEventPoint&. Change-Id: Ie18f1c1849ed057b98f229de7b17b7fc3f3eea36 Reviewed-by: Volker Hilsheimer --- src/gui/kernel/qevent.cpp | 15 +++++++++++++++ src/gui/kernel/qevent.h | 8 ++++++++ 2 files changed, 23 insertions(+) (limited to 'src') diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index 5a539ccaf6..51100f56ff 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -963,6 +963,21 @@ bool QSinglePointEvent::isEndEvent() const return m_button != Qt::NoButton && !m_mouseState.testFlag(m_button); } +/*! + \property QSinglePointEvent::exclusivePointGrabber + \brief the object that will receive future updates + + The exclusive grabber is an object that has chosen to receive all future + update events and the release event containing the same point that this + event carries. + + Setting the exclusivePointGrabber property is a convenience equivalent to: + \code + setExclusiveGrabber(points().first(), exclusiveGrabber); + \endcode +*/ + + /*! \class QMouseEvent \ingroup events diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h index 6abbae07be..07d5be51c6 100644 --- a/src/gui/kernel/qevent.h +++ b/src/gui/kernel/qevent.h @@ -233,6 +233,9 @@ protected: class Q_GUI_EXPORT QSinglePointEvent : public QPointerEvent { + Q_GADGET + Q_PROPERTY(QObject *exclusivePointGrabber READ exclusivePointGrabber WRITE setExclusivePointGrabber) + public: QSinglePointEvent(Type type, const QPointingDevice *dev, const QPointF &localPos, const QPointF &scenePos, const QPointF &globalPos, @@ -253,6 +256,11 @@ public: bool isUpdateEvent() const override; bool isEndEvent() const override; + QObject *exclusivePointGrabber() const + { return QPointerEvent::exclusiveGrabber(points().first()); } + void setExclusivePointGrabber(QObject *exclusiveGrabber) + { QPointerEvent::setExclusiveGrabber(points().first(), exclusiveGrabber); } + protected: QSinglePointEvent(Type type, const QPointingDevice *dev, const QEventPoint &point, Qt::MouseButton button, Qt::MouseButtons buttons, -- cgit v1.2.3