From a1c91787264f6f535b5cf094b57ee53058856df4 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Fri, 19 Jun 2020 12:44:59 +0200 Subject: Add QQuickHandlerPoint::device property MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The HandlerPoint type is used as the memory of an event or TouchPoint that a handler has already handled. Maybe in the future we'll store a copy of a QEventPoint instead. But for now, it's nice to have the device pointer available for binding properties, instead of only in QQuickEventPoint, which was only exposed in signals like TapHandler.tapped(). Change-Id: I314fc8c76311dc2620f1d97d4cadacf2e9869274 Reviewed-by: Jan Arve Sæther --- src/quick/handlers/qquickhandlerpoint.cpp | 3 +++ src/quick/handlers/qquickhandlerpoint_p.h | 4 ++++ tests/manual/pointer/singlePointHandlerProperties.qml | 3 ++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/quick/handlers/qquickhandlerpoint.cpp b/src/quick/handlers/qquickhandlerpoint.cpp index 1155d27afe..2e4602affa 100644 --- a/src/quick/handlers/qquickhandlerpoint.cpp +++ b/src/quick/handlers/qquickhandlerpoint.cpp @@ -83,6 +83,7 @@ void QQuickHandlerPoint::localize(QQuickItem *item) void QQuickHandlerPoint::reset() { m_id = 0; + m_device = QPointingDevice::primaryPointingDevice(); m_uniqueId = QPointingDeviceUniqueId(); m_position = QPointF(); m_scenePosition = QPointF(); @@ -100,6 +101,7 @@ void QQuickHandlerPoint::reset() void QQuickHandlerPoint::reset(const QQuickEventPoint *point) { m_id = point->pointId(); + m_device = point->pointerEvent()->device(); const QQuickPointerEvent *event = point->pointerEvent(); switch (point->state()) { case QQuickEventPoint::Pressed: @@ -166,6 +168,7 @@ void QQuickHandlerPoint::reset(const QVector &points) ellipseDiameterSum += point.ellipseDiameters(); } m_id = 0; + m_device = nullptr; m_uniqueId = QPointingDeviceUniqueId(); // all points are required to be from the same event, so pressed buttons and modifiers should be the same m_pressedButtons = points.first().pressedButtons(); diff --git a/src/quick/handlers/qquickhandlerpoint_p.h b/src/quick/handlers/qquickhandlerpoint_p.h index 44fd830af2..6ba5e3bf28 100644 --- a/src/quick/handlers/qquickhandlerpoint_p.h +++ b/src/quick/handlers/qquickhandlerpoint_p.h @@ -73,6 +73,7 @@ class Q_QUICK_PRIVATE_EXPORT QQuickHandlerPoint { Q_PROPERTY(qreal rotation READ rotation) Q_PROPERTY(qreal pressure READ pressure) Q_PROPERTY(QSizeF ellipseDiameters READ ellipseDiameters) + Q_PROPERTY(QPointingDevice *device READ device) public: QQuickHandlerPoint(); @@ -90,6 +91,8 @@ public: qreal pressure() const { return m_pressure; } QSizeF ellipseDiameters() const { return m_ellipseDiameters; } QPointingDeviceUniqueId uniqueId() const { return m_uniqueId; } + // non-const only because of QML engine limitations (similar to QTBUG-61749) + QPointingDevice *device() const { return const_cast(m_device); } void localize(QQuickItem *item); void reset(); @@ -98,6 +101,7 @@ public: private: int m_id = 0; + const QPointingDevice *m_device = QPointingDevice::primaryPointingDevice(); QPointingDeviceUniqueId m_uniqueId; Qt::MouseButtons m_pressedButtons = Qt::NoButton; Qt::KeyboardModifiers m_pressedModifiers = Qt::NoModifier; diff --git a/tests/manual/pointer/singlePointHandlerProperties.qml b/tests/manual/pointer/singlePointHandlerProperties.qml index d5c35fff22..c2500770f0 100644 --- a/tests/manual/pointer/singlePointHandlerProperties.qml +++ b/tests/manual/pointer/singlePointHandlerProperties.qml @@ -69,7 +69,8 @@ Rectangle { implicitHeight: label.implicitHeight Text { id: label - text: 'id: ' + pointHandler.point.id.toString(16) + " uid: " + pointHandler.point.uniqueId.numericId + + text: 'seat: ' + pointHandler.point.device.seatName + '\ndevice: ' + pointHandler.point.device.name + + '\nid: ' + pointHandler.point.id.toString(16) + " uid: " + pointHandler.point.uniqueId.numericId + '\npos: (' + pointHandler.point.position.x.toFixed(2) + ', ' + pointHandler.point.position.y.toFixed(2) + ')' + '\nmodifiers: ' + pointHandler.point.modifiers.toString(16) } -- cgit v1.2.3