From 673973acc20ce4e068d63fa5b0391f5c785be8a3 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Wed, 4 Nov 2009 15:37:18 +0100 Subject: Mac: pinch gesture scales to fast and event below zero Make the math correct. Plus, update the imagegesture example. Rev-By: denis --- examples/gestures/imagegestures/imagewidget.cpp | 13 +++++++++---- examples/gestures/imagegestures/imagewidget.h | 1 + src/gui/kernel/qmacgesturerecognizer_mac.mm | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/examples/gestures/imagegestures/imagewidget.cpp b/examples/gestures/imagegestures/imagewidget.cpp index f615129..df8f56d 100644 --- a/examples/gestures/imagegestures/imagewidget.cpp +++ b/examples/gestures/imagegestures/imagewidget.cpp @@ -50,7 +50,8 @@ ImageWidget::ImageWidget(QWidget *parent) horizontalOffset(0), verticalOffset(0), rotationAngle(0), - scaleFactor(1) + scaleFactor(1), + currentStepScaleFactor(1) { setMinimumSize(QSize(100,100)); @@ -85,7 +86,7 @@ void ImageWidget::paintEvent(QPaintEvent*) p.translate(ww/2, wh/2); p.translate(horizontalOffset, verticalOffset); p.rotate(rotationAngle); - p.scale(scaleFactor, scaleFactor); + p.scale(currentStepScaleFactor * scaleFactor, currentStepScaleFactor * scaleFactor); p.translate(-iw/2, -ih/2); p.drawImage(0, 0, currentImage); } @@ -140,8 +141,12 @@ void ImageWidget::pinchTriggered(QPinchGesture *gesture) } if (changeFlags & QPinchGesture::ScaleFactorChanged) { qreal value = gesture->property("scaleFactor").toReal(); - qreal lastValue = gesture->property("lastScaleFactor").toReal(); - scaleFactor += value - lastValue; + if (gesture->state() == Qt::GestureFinished) { + scaleFactor *= currentStepScaleFactor; + currentStepScaleFactor = 1; + } else { + currentStepScaleFactor = value; + } } update(); } diff --git a/examples/gestures/imagegestures/imagewidget.h b/examples/gestures/imagegestures/imagewidget.h index 56e2316..7a68488 100644 --- a/examples/gestures/imagegestures/imagewidget.h +++ b/examples/gestures/imagegestures/imagewidget.h @@ -93,6 +93,7 @@ private: float verticalOffset; float rotationAngle; float scaleFactor; + float currentStepScaleFactor; //! [class definition end] }; //! [class definition end] diff --git a/src/gui/kernel/qmacgesturerecognizer_mac.mm b/src/gui/kernel/qmacgesturerecognizer_mac.mm index d842322..f142d71 100644 --- a/src/gui/kernel/qmacgesturerecognizer_mac.mm +++ b/src/gui/kernel/qmacgesturerecognizer_mac.mm @@ -120,7 +120,7 @@ QMacPinchGestureRecognizer::recognize(QGesture *gesture, QObject *obj, QEvent *e case QNativeGestureEvent::Zoom: g->setLastScaleFactor(g->scaleFactor()); g->setLastRotationAngle(g->rotationAngle()); - g->setScaleFactor(g->scaleFactor() + ev->percentage); + g->setScaleFactor(g->scaleFactor() * (1 + ev->percentage)); g->setChangeFlags(QPinchGesture::ScaleFactorChanged); g->setTotalChangeFlags(g->totalChangeFlags() | g->changeFlags()); return QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint; -- cgit v0.12