From 34a58b0eb7c0c40be87e62251bc714d63293d51a Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Wed, 25 Feb 2015 15:32:07 +0100 Subject: 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 --- src/widgets/kernel/qstandardgestures.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/widgets') 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 @@ QT_BEGIN_NAMESPACE +// 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; -- cgit v1.2.3