path: root/src
diff options
authorShawn Rutledge <>2015-02-25 15:32:07 +0100
committerShawn Rutledge <>2015-03-03 13:30:32 +0000
commit34a58b0eb7c0c40be87e62251bc714d63293d51a (patch)
tree0bc63cdddd3aefb685b0b2c411b9a97f23d1648c /src
parenta9515cd02fabcb90691093c388be9849282a9e22 (diff)
avoid sending QPinchGestures based on unreasonable pinch deltas
On some devices there can be spurious events indicating that the two touchpoints are very close together, so that the ratio of present line length to previous line length can be very large, and the angle delta can be random. But in the normal scenario, there will be a lot of events, in which the touch point movements are small. So if the line length ratio is unreasonable, it's safe to ignore one event and wait for the next. Task-number: QTBUG-44665 Change-Id: Ibb7fe560b6a3f7db72d73aad3468c61f24a95d13 Reviewed-by: Friedemann Kleint <> Reviewed-by: Laszlo Agocs <>
Diffstat (limited to 'src')
1 files changed, 9 insertions, 1 deletions
diff --git a/src/widgets/kernel/qstandardgestures.cpp b/src/widgets/kernel/qstandardgestures.cpp
index cf9ac52de3..d19e473d18 100644
--- a/src/widgets/kernel/qstandardgestures.cpp
+++ b/src/widgets/kernel/qstandardgestures.cpp
@@ -44,6 +44,11 @@
+// If the change in scale for a single touch event is out of this range,
+// we consider it to be spurious.
+static const qreal kSingleStepScaleMax = 2.0;
+static const qreal kSingleStepScaleMin = 0.1;
QGesture *QPanGestureRecognizer::create(QObject *target)
if (target && target->isWidgetType()) {
@@ -197,7 +202,10 @@ QGestureRecognizer::Result QPinchGestureRecognizer::recognize(QGesture *state,
d->lastScaleFactor = d->scaleFactor;
QLineF line(p1.screenPos(), p2.screenPos());
QLineF lastLine(p1.lastScreenPos(), p2.lastScreenPos());
- d->scaleFactor = line.length() / lastLine.length();
+ qreal newScaleFactor = line.length() / lastLine.length();
+ if (newScaleFactor > kSingleStepScaleMax || newScaleFactor < kSingleStepScaleMin)
+ return QGestureRecognizer::Ignore;
+ d->scaleFactor = newScaleFactor;
d->totalScaleFactor = d->totalScaleFactor * d->scaleFactor;
d->changeFlags |= QPinchGesture::ScaleFactorChanged;