From 1e9e6c6e70a213cb0ba4e58049b7ad48aef8e48b Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Wed, 14 Jul 2021 13:16:13 +0200 Subject: Add note about precision of QNativeGestureEvent::delta; fix in Qt 7 We keep QVector2D storage Qt 6 BC (to avoid making QNativeGestureEvent larger), but in Qt 7 we should return exactly the same value as given (for what it's worth, in spite of this being overkill for panning a reasonable distance). Change-Id: Iecbd4c9b60ad9ae5e0466c7027b038ddb85b8c8b Pick-to: 6.2 Reviewed-by: Volker Hilsheimer --- src/gui/kernel/qevent.cpp | 10 +++++++--- src/gui/kernel/qevent.h | 14 ++++++++++++-- 2 files changed, 19 insertions(+), 5 deletions(-) (limited to 'src/gui/kernel') diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index f7532d4481..73a591f34c 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -2837,18 +2837,22 @@ QNativeGestureEvent::QNativeGestureEvent(Qt::NativeGestureType type, const QPoin indicating that the target item should have its scale adjusted like this: item.scale = item.scale * (1 + event.value) - For PanNativeGesture, \a deltas gives the distance in pixels that the + For PanNativeGesture, \a delta gives the distance in pixels that the viewport, widget or item should be moved or panned. + \note The \a delta is stored in single precision (QVector2D), so \l delta() + may return slightly different values in some cases. This is subject to change + in future versions of Qt. + \since 6.2 */ QNativeGestureEvent::QNativeGestureEvent(Qt::NativeGestureType type, const QPointingDevice *device, int fingerCount, const QPointF &localPos, const QPointF &scenePos, - const QPointF &globalPos, qreal value, const QPointF &deltas, + const QPointF &globalPos, qreal value, const QPointF &delta, quint64 sequenceId) : QSinglePointEvent(QEvent::NativeGesture, device, localPos, scenePos, globalPos, Qt::NoButton, Qt::NoButton, Qt::NoModifier), - m_sequenceId(sequenceId), m_delta(deltas), m_realValue(value), m_gestureType(type), m_fingerCount(fingerCount) + m_sequenceId(sequenceId), m_delta(delta), m_realValue(value), m_gestureType(type), m_fingerCount(fingerCount) { Q_ASSERT(fingerCount < 16); // we store it in 4 bits unsigned } diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h index 9796886ae1..9c53f7ce92 100644 --- a/src/gui/kernel/qevent.h +++ b/src/gui/kernel/qevent.h @@ -416,7 +416,7 @@ public: #endif QNativeGestureEvent(Qt::NativeGestureType type, const QPointingDevice *dev, int fingerCount, const QPointF &localPos, const QPointF &scenePos, const QPointF &globalPos, - qreal value, const QPointF &deltas, quint64 sequenceId = UINT64_MAX); + qreal value, const QPointF &delta, quint64 sequenceId = UINT64_MAX); ~QNativeGestureEvent(); QNativeGestureEvent *clone() const override { return new QNativeGestureEvent(*this); } @@ -424,7 +424,13 @@ public: Qt::NativeGestureType gestureType() const { return m_gestureType; } int fingerCount() const { return m_fingerCount; } qreal value() const { return m_realValue; } - QPointF delta() const { return m_delta.toPointF(); } + QPointF delta() const { +#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) + return m_delta.toPointF(); +#else + return m_delta; +#endif + } #if QT_DEPRECATED_SINCE(6, 0) #ifndef QT_NO_INTEGER_EVENT_COORDINATES @@ -443,7 +449,11 @@ public: protected: quint64 m_sequenceId; +#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) QVector2D m_delta; +#else + QPointF m_delta; +#endif qreal m_realValue; Qt::NativeGestureType m_gestureType; quint32 m_fingerCount : 4; -- cgit v1.2.3