summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrederik Gladhorn <frederik.gladhorn@nokia.com>2010-10-25 16:32:21 (GMT)
committerFrederik Gladhorn <frederik.gladhorn@nokia.com>2010-10-25 16:46:42 (GMT)
commit4117403ad5170110849b7d0663337b1571304a8e (patch)
tree5f25cd55100dcc8caab0fd14aecdc1d285822d2d
parenteb2b56bc4d6a226058c36233aaf5c13e39fa3dc2 (diff)
downloadQt-4117403ad5170110849b7d0663337b1571304a8e.zip
Qt-4117403ad5170110849b7d0663337b1571304a8e.tar.gz
Qt-4117403ad5170110849b7d0663337b1571304a8e.tar.bz2
Simplify calculation of center point and scale for PinchRecongizer
Constructing a QLineF to get at the centerPoint is not precise and can be done simpler. The scale factor can be assigned directly to d->scaleFactor instead of creating a temporary scaleFactor variable. Reviewed-by: Zeno Albisser
-rw-r--r--src/gui/kernel/qstandardgestures.cpp19
1 files changed, 8 insertions, 11 deletions
diff --git a/src/gui/kernel/qstandardgestures.cpp b/src/gui/kernel/qstandardgestures.cpp
index 893ba2b..1821c3d 100644
--- a/src/gui/kernel/qstandardgestures.cpp
+++ b/src/gui/kernel/qstandardgestures.cpp
@@ -198,25 +198,22 @@ QGestureRecognizer::Result QPinchGestureRecognizer::recognize(QGesture *state,
d->startPosition[0] = p1.screenPos();
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();
d->lastCenterPoint = d->centerPoint;
- d->centerPoint = centerPoint;
- d->changeFlags |= QPinchGesture::CenterPointChanged;
+ d->centerPoint = (p1.screenPos() + p2.screenPos()) / 2.0;
- const qreal scaleFactor = line.length() / lastLine.length();
+ d->changeFlags |= QPinchGesture::CenterPointChanged;
if (d->isNewSequence) {
- d->lastScaleFactor = scaleFactor;
+ d->scaleFactor = 1.0;
+ d->lastScaleFactor = 1.0;
} else {
d->lastScaleFactor = d->scaleFactor;
+ QLineF line(p1.screenPos(), p2.screenPos());
+ QLineF lastLine(p1.lastScreenPos(), p2.lastScreenPos());
+ d->scaleFactor = line.length() / lastLine.length();
}
- d->scaleFactor = scaleFactor;
- d->totalScaleFactor = d->totalScaleFactor * scaleFactor;
+ d->totalScaleFactor = d->totalScaleFactor * d->scaleFactor;
d->changeFlags |= QPinchGesture::ScaleFactorChanged;
qreal angle = QLineF(p1.screenPos(), p2.screenPos()).angle();