diff options
author | Shawn Rutledge <shawn.rutledge@digia.com> | 2014-03-12 16:54:24 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-03-18 10:18:57 +0100 |
commit | 17643c829d15d43a7d5e2955089595198903775c (patch) | |
tree | 6c17e64c7c5de9e51f3a735b42c0dd58f13d9374 /src/quick/items/qquickpincharea.cpp | |
parent | a412d0aa7e98d98c6f8ee82050766cc8fd6f7903 (diff) |
PinchArea: zooming requires pinch distance to exceed the threshold
If you use a PinchArea and a Flickable together on OSX, you will be
able to use two fingers on the trackpad to flick the Flickable because
the OS will send scroll events which Qt turns into QWheelEvents; and
at the same time you will have two touch points, which the PinchArea
will grab and use. That's nice, but it means we need to be more
selective about gesture recognition, so that when you mean to flick
you can do it without simultaneously pinch-zooming.
Therefore, iff pinch.dragAxis is Pinch.NoDrag, the startDragDistance
(threshold) is treated as a pinch distance threshold rather than
allowing any direction of movement to begin the pinch gesture.
[Changelog][QtQuick][PinchArea] do not begin zooming until the
change in distance between two touch points exceeds startDragDistance
Task-number: QTBUG-37294
Change-Id: I01026364970428aae9a4c5436517db719387f8e8
Reviewed-by: Laszlo Agocs <laszlo.agocs@digia.com>
Reviewed-by: Ulf Hermann <ulf.hermann@digia.com>
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@digia.com>
Diffstat (limited to 'src/quick/items/qquickpincharea.cpp')
-rw-r--r-- | src/quick/items/qquickpincharea.cpp | 71 |
1 files changed, 39 insertions, 32 deletions
diff --git a/src/quick/items/qquickpincharea.cpp b/src/quick/items/qquickpincharea.cpp index f741a08512..98661d8f00 100644 --- a/src/quick/items/qquickpincharea.cpp +++ b/src/quick/items/qquickpincharea.cpp @@ -393,48 +393,55 @@ void QQuickPinchArea::updatePinch() if (angle > 180) angle -= 360; if (!d->inPinch || d->initPinch) { - if (d->touchPoints.count() >= 2 - && (qAbs(p1.x()-d->sceneStartPoint1.x()) >= dragThreshold - || qAbs(p1.y()-d->sceneStartPoint1.y()) >= dragThreshold - || qAbs(p2.x()-d->sceneStartPoint2.x()) >= dragThreshold - || qAbs(p2.y()-d->sceneStartPoint2.y()) >= dragThreshold)) { - d->initPinch = false; + if (d->touchPoints.count() >= 2) { + if (d->initPinch) { + if (!d->inPinch) + d->pinchStartDist = dist; + d->initPinch = false; + } d->sceneStartCenter = sceneCenter; d->sceneLastCenter = sceneCenter; d->pinchStartCenter = mapFromScene(sceneCenter); - d->pinchStartDist = dist; d->pinchStartAngle = angle; d->pinchLastScale = 1.0; d->pinchLastAngle = angle; d->pinchRotation = 0.0; d->lastPoint1 = p1; d->lastPoint2 = p2; - QQuickPinchEvent pe(d->pinchStartCenter, 1.0, angle, 0.0); - pe.setStartCenter(d->pinchStartCenter); - pe.setPreviousCenter(d->pinchStartCenter); - pe.setPreviousAngle(d->pinchLastAngle); - pe.setPreviousScale(d->pinchLastScale); - pe.setStartPoint1(mapFromScene(d->sceneStartPoint1)); - pe.setStartPoint2(mapFromScene(d->sceneStartPoint2)); - pe.setPoint1(mapFromScene(d->lastPoint1)); - pe.setPoint2(mapFromScene(d->lastPoint2)); - pe.setPointCount(d->touchPoints.count()); - emit pinchStarted(&pe); - if (pe.accepted()) { - d->inPinch = true; - d->stealMouse = true; - QQuickWindow *c = window(); - if (c && c->mouseGrabberItem() != this) - grabMouse(); - setKeepMouseGrab(true); - if (d->pinch && d->pinch->target()) { - d->pinchStartPos = pinch()->target()->position(); - d->pinchStartScale = d->pinch->target()->scale(); - d->pinchStartRotation = d->pinch->target()->rotation(); - d->pinch->setActive(true); + if (qAbs(dist - d->pinchStartDist) >= dragThreshold || + (pinch()->axis() != QQuickPinch::NoDrag && + (qAbs(p1.x()-d->sceneStartPoint1.x()) >= dragThreshold + || qAbs(p1.y()-d->sceneStartPoint1.y()) >= dragThreshold + || qAbs(p2.x()-d->sceneStartPoint2.x()) >= dragThreshold + || qAbs(p2.y()-d->sceneStartPoint2.y()) >= dragThreshold))) { + QQuickPinchEvent pe(d->pinchStartCenter, 1.0, angle, 0.0); + d->pinchStartDist = dist; + pe.setStartCenter(d->pinchStartCenter); + pe.setPreviousCenter(d->pinchStartCenter); + pe.setPreviousAngle(d->pinchLastAngle); + pe.setPreviousScale(d->pinchLastScale); + pe.setStartPoint1(mapFromScene(d->sceneStartPoint1)); + pe.setStartPoint2(mapFromScene(d->sceneStartPoint2)); + pe.setPoint1(mapFromScene(d->lastPoint1)); + pe.setPoint2(mapFromScene(d->lastPoint2)); + pe.setPointCount(d->touchPoints.count()); + emit pinchStarted(&pe); + if (pe.accepted()) { + d->inPinch = true; + d->stealMouse = true; + QQuickWindow *c = window(); + if (c && c->mouseGrabberItem() != this) + grabMouse(); + setKeepMouseGrab(true); + if (d->pinch && d->pinch->target()) { + d->pinchStartPos = pinch()->target()->position(); + d->pinchStartScale = d->pinch->target()->scale(); + d->pinchStartRotation = d->pinch->target()->rotation(); + d->pinch->setActive(true); + } + } else { + d->pinchRejected = true; } - } else { - d->pinchRejected = true; } } } else if (d->pinchStartDist > 0) { |