summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZeno Albisser <zeno.albisser@nokia.com>2010-08-11 11:37:21 (GMT)
committerZeno Albisser <zeno.albisser@nokia.com>2010-09-13 14:43:13 (GMT)
commite6b2bb6d6a48e722311cd2c5fd86c015eab24b4d (patch)
treed81a58f8b0e6c33f41029329413b22a8bc4992af
parentd65259a3444a08919f1f19b9d2dcbe9b182752aa (diff)
downloadQt-e6b2bb6d6a48e722311cd2c5fd86c015eab24b4d.zip
Qt-e6b2bb6d6a48e722311cd2c5fd86c015eab24b4d.tar.gz
Qt-e6b2bb6d6a48e722311cd2c5fd86c015eab24b4d.tar.bz2
fix scaleFactor/totalScaleFactor in QPinchGestureRecognizer
The scaleFactor/totalScaleFactor should now represent a proper value to allow an object tracking a touchpoint during a Pinch Gesture. Reviewed-by: Frederik Gladhorn
-rw-r--r--src/gui/kernel/qgesture_p.h2
-rw-r--r--src/gui/kernel/qstandardgestures.cpp10
2 files changed, 6 insertions, 6 deletions
diff --git a/src/gui/kernel/qgesture_p.h b/src/gui/kernel/qgesture_p.h
index baf0d33..e8f8fe3 100644
--- a/src/gui/kernel/qgesture_p.h
+++ b/src/gui/kernel/qgesture_p.h
@@ -112,7 +112,7 @@ class QPinchGesturePrivate : public QGesturePrivate
public:
QPinchGesturePrivate()
: totalChangeFlags(0), changeFlags(0),
- totalScaleFactor(0), lastScaleFactor(0), scaleFactor(0),
+ totalScaleFactor(1), lastScaleFactor(1), scaleFactor(1),
totalRotationAngle(0), lastRotationAngle(0), rotationAngle(0),
isNewSequence(true)
{
diff --git a/src/gui/kernel/qstandardgestures.cpp b/src/gui/kernel/qstandardgestures.cpp
index 503fa18..893ba2b 100644
--- a/src/gui/kernel/qstandardgestures.cpp
+++ b/src/gui/kernel/qstandardgestures.cpp
@@ -199,6 +199,7 @@ QGestureRecognizer::Result QPinchGestureRecognizer::recognize(QGesture *state,
d->startPosition[1] = p2.screenPos();
}
QLineF line(p1.screenPos(), p2.screenPos());
+ QLineF lastLine(p1.lastScreenPos(), p2.lastScreenPos());
QLineF tmp(line);
tmp.setLength(line.length() / 2.);
QPointF centerPoint = tmp.p2();
@@ -207,16 +208,15 @@ QGestureRecognizer::Result QPinchGestureRecognizer::recognize(QGesture *state,
d->centerPoint = centerPoint;
d->changeFlags |= QPinchGesture::CenterPointChanged;
- const qreal scaleFactor =
- QLineF(p1.screenPos(), p2.screenPos()).length()
- / QLineF(d->startPosition[0], d->startPosition[1]).length();
+ const qreal scaleFactor = line.length() / lastLine.length();
+
if (d->isNewSequence) {
d->lastScaleFactor = scaleFactor;
} else {
d->lastScaleFactor = d->scaleFactor;
}
d->scaleFactor = scaleFactor;
- d->totalScaleFactor += d->scaleFactor - d->lastScaleFactor;
+ d->totalScaleFactor = d->totalScaleFactor * scaleFactor;
d->changeFlags |= QPinchGesture::ScaleFactorChanged;
qreal angle = QLineF(p1.screenPos(), p2.screenPos()).angle();
@@ -266,7 +266,7 @@ void QPinchGestureRecognizer::reset(QGesture *state)
d->totalChangeFlags = d->changeFlags = 0;
d->startCenterPoint = d->lastCenterPoint = d->centerPoint = QPointF();
- d->totalScaleFactor = d->lastScaleFactor = d->scaleFactor = 0;
+ d->totalScaleFactor = d->lastScaleFactor = d->scaleFactor = 1;
d->totalRotationAngle = d->lastRotationAngle = d->rotationAngle = 0;
d->isNewSequence = true;