diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2018-06-22 16:37:32 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2018-06-27 15:31:07 +0000 |
commit | b4d31c9ff5f0c5821ea127c663532d9fc2cae43e (patch) | |
tree | e8cbf769123e2c59a3d42fd4d9f1ae67b722a15e /src/quick/handlers/qquickpinchhandler.cpp | |
parent | a1adcf34f8784d05467cf3598064a3e83842fdc0 (diff) |
PinchHandler: rename scale to activeScale; scale means target scale
If you want to set target: null and then bind scale to some sort of
rendering scale property directly, it's a lot less trouble if the
scale property does not keep changing back to 1.0 every time a gesture
begins. Added an activeScale property to represent that value, the
one that the scale property had before.
Task-number: QTBUG-68941
Change-Id: Idcb6735d915a523afe1a948609080af7a83f82ad
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
Diffstat (limited to 'src/quick/handlers/qquickpinchhandler.cpp')
-rw-r--r-- | src/quick/handlers/qquickpinchhandler.cpp | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/src/quick/handlers/qquickpinchhandler.cpp b/src/quick/handlers/qquickpinchhandler.cpp index 412ad6227d..38e3d00e9e 100644 --- a/src/quick/handlers/qquickpinchhandler.cpp +++ b/src/quick/handlers/qquickpinchhandler.cpp @@ -88,6 +88,7 @@ Q_LOGGING_CATEGORY(lcPinchHandler, "qt.quick.handler.pinch") QQuickPinchHandler::QQuickPinchHandler(QObject *parent) : QQuickMultiPointHandler(parent, 2) , m_activeScale(1) + , m_accumulatedScale(1) , m_activeRotation(0) , m_activeTranslation(0,0) , m_minimumScale(-qInf()) @@ -304,7 +305,7 @@ void QQuickPinchHandler::onActiveChanged() m_startMatrix.rotate(m_startRotation, 0, 0, -1); m_startMatrix.translate(-xformOrigin); } else { - m_startScale = 1; + m_startScale = m_accumulatedScale; m_startRotation = 0; } qCInfo(lcPinchHandler) << "activated with starting scale" << m_startScale << "rotation" << m_startRotation; @@ -398,7 +399,7 @@ void QQuickPinchHandler::handlePointerEventImpl(QQuickPointerEvent *event) const qreal totalRotation = m_startRotation + m_activeRotation; const qreal rotation = qBound(m_minimumRotation, totalRotation, m_maximumRotation); m_activeRotation += (rotation - totalRotation); //adjust for the potential bounding above - const qreal scale = m_startScale * m_activeScale; + m_accumulatedScale = m_startScale * m_activeScale; if (target() && target()->parentItem()) { // 3. Drag/translate @@ -422,7 +423,7 @@ void QQuickPinchHandler::handlePointerEventImpl(QQuickPointerEvent *event) target()->setPosition(pos); target()->setRotation(rotation); - target()->setScale(scale); + target()->setScale(m_accumulatedScale); // TODO some translation inadvertently happens; try to hold the chosen pinch origin in place } else { @@ -431,7 +432,7 @@ void QQuickPinchHandler::handlePointerEventImpl(QQuickPointerEvent *event) qCDebug(lcPinchHandler) << "centroid" << m_centroid.scenePressPosition() << "->" << m_centroid.scenePosition() << ", distance" << m_startDistance << "->" << dist - << ", startScale" << m_startScale << "->" << scale + << ", startScale" << m_startScale << "->" << m_accumulatedScale << ", activeRotation" << m_activeRotation << ", rotation" << rotation << " from " << event->device()->type(); @@ -452,11 +453,23 @@ void QQuickPinchHandler::handlePointerEventImpl(QQuickPointerEvent *event) \readonly \qmlproperty real QtQuick::PinchHandler::scale - The scale factor. It is 1.0 when the gesture begins, increases as the - touchpoints are spread apart, and decreases as the touchpoints are brought - together. If \l target is not null, this will be automatically applied to its - \l {Item::scale}{scale}. Otherwise, bindings can be used to do arbitrary - things with this value. + The scale factor that will automatically be set on the \l target if it is not null. + Otherwise, bindings can be used to do arbitrary things with this value. + While the pinch gesture is being performed, it is continuously multiplied by + \l activeScale; after the gesture ends, it stays the same; and when the next + pinch gesture begins, it begins to be multiplied by activeScale again. +*/ + +/*! + \readonly + \qmlproperty real QtQuick::PinchHandler::activeScale + + The scale factor while the pinch gesture is being performed. + It is 1.0 when the gesture begins, increases as the touchpoints are spread + apart, and decreases as the touchpoints are brought together. + If \l target is not null, its \l {Item::scale}{scale} will be automatically + multiplied by this value. + Otherwise, bindings can be used to do arbitrary things with this value. */ /*! |