PinchHandler: don't confine activeScale and activeRotation to min/max

It was inconsistent to do this for the active values only on one
handler's axis objects. The main purpose of the minimum and maximum
values is to avoid modifying the target item's respective properties
beyond reasonable limits, whereas the active values are supposed to be
derived directly from the gesture. If the users modify target properties
based on active values, or based on the activeValueChanged signal
argument, they need to enforce the property limits themselves.

[ChangeLog][QtQuick][Event Handlers] PinchHandler's activeScale (which
was previously called scale) is no longer restricted to the range
between minimumScale and maximumScale: these limits apply only to
persistentScale. Likewise, activeRotation (previously rotation)
is no longer restricted to the range between minimumRotation and
maximumRotation.

Change-Id: I5757e3d931e6165c81cecff19fc30b50033d89ce
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
This commit is contained in:
Shawn Rutledge 2022-12-01 18:55:30 +01:00
parent 71db3d449e
commit 2482a00596
4 changed files with 14 additions and 13 deletions

View File

@ -9,10 +9,8 @@ QT_BEGIN_NAMESPACE
Q_LOGGING_CATEGORY(lcDragAxis, "qt.quick.pointer.dragaxis")
QQuickDragAxis::QQuickDragAxis(QQuickPointerHandler *handler, const QString &propertyName,
bool boundedActiveValue, qreal initValue)
: QObject(handler), m_accumulatedValue(initValue), m_propertyName(propertyName),
m_boundedActiveValue(boundedActiveValue)
QQuickDragAxis::QQuickDragAxis(QQuickPointerHandler *handler, const QString &propertyName, qreal initValue)
: QObject(handler), m_accumulatedValue(initValue), m_propertyName(propertyName)
{
}
@ -56,7 +54,7 @@ void QQuickDragAxis::updateValue(qreal activeValue, qreal accumulatedValue, qrea
if (!m_enabled)
return;
m_activeValue = m_boundedActiveValue ? qBound(m_minimum, activeValue, m_maximum) : activeValue;
m_activeValue = activeValue;
m_accumulatedValue = qBound(m_minimum, accumulatedValue, m_maximum);
qCDebug(lcDragAxis) << parent() << m_propertyName << "values: active" << activeValue
<< "accumulated" << m_accumulatedValue << "delta" << delta;

View File

@ -38,7 +38,7 @@ class Q_QUICK_PRIVATE_EXPORT QQuickDragAxis : public QObject
public:
QQuickDragAxis(QQuickPointerHandler *handler, const QString &propertyName,
bool boundedActiveValue = false, qreal initValue = 0);
qreal initValue = 0);
qreal minimum() const { return m_minimum; }
void setMinimum(qreal minimum);
@ -73,7 +73,6 @@ private:
qreal m_accumulatedValue = 0;
QString m_propertyName;
bool m_enabled = true;
bool m_boundedActiveValue = false;
friend class QQuickDragHandler;
friend class QQuickPinchHandler;

View File

@ -116,8 +116,8 @@ protected:
private:
QQuickDragAxis m_xAxis = {this, u"x"_s};
QQuickDragAxis m_yAxis = {this, u"y"_s};
QQuickDragAxis m_scaleAxis = {this, u"scale"_s, true, 1};
QQuickDragAxis m_rotationAxis = {this, u"rotation"_s, true};
QQuickDragAxis m_scaleAxis = {this, u"scale"_s, 1};
QQuickDragAxis m_rotationAxis = {this, u"rotation"_s};
// internal
qreal m_startDistance = 0;

View File

@ -403,8 +403,12 @@ void tst_QQuickPinchHandler::scaleThreeFingers()
QVERIFY(withinBounds(1.163, pinchHandler->scale(), 1.183));
// should not rotate
QCOMPARE(root->rotation(), 0);
QCOMPARE(pinchHandler->rotation(), 0);
QCOMPARE(pinchHandler->rotationAxis()->activeValue(), 0);
// rotation should be 0, but could be something tiny
qCDebug(lcPointerTests) << "pinch scale expected zero:" << pinchHandler->rotation()
<< pinchHandler->rotationAxis()->activeValue()
<< pinchHandler->rotationAxis()->persistentValue();
QCOMPARE_LE(qAbs(pinchHandler->rotation()), 0.001);
QCOMPARE(pinchHandler->rotationAxis()->activeValue(), pinchHandler->rotation());
QCOMPARE(pinchHandler->rotationAxis()->persistentValue(), 0);
for (int i = 0; i < 5;++i) {
@ -489,8 +493,8 @@ void tst_QQuickPinchHandler::scaleNativeGesture()
QVERIFY(qAbs(target->position().x() - expectedPos.x()) < 0.001);
QVERIFY(qAbs(target->position().y() - expectedPos.y()) < 0.001);
QCOMPARE(pinchHandler->scale(), expectedScale);
QCOMPARE(pinchHandler->activeScale(), expectedScale);
QCOMPARE(pinchHandler->scaleAxis()->activeValue(), expectedScale);
QCOMPARE(pinchHandler->activeScale(), scale);
QCOMPARE(pinchHandler->scaleAxis()->activeValue(), scale);
QCOMPARE(pinchHandler->translation(), QVector2D());
QCOMPARE(pinchHandler->rotation(), 0);
QCOMPARE(pinchHandler->rotationAxis()->persistentValue(), 0);