summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/gestures/imagegestures/imagewidget.cpp13
-rw-r--r--examples/gestures/imagegestures/imagewidget.h1
-rw-r--r--src/gui/kernel/qmacgesturerecognizer_mac.mm2
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;