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 <Friedemann.Kleint@theqtcompany.com>
Reviewed-by: Laszlo Agocs <laszlo.agocs@theqtcompany.com>
bb10
Shawn Rutledge 2015-02-25 15:32:07 +01:00
parent a9515cd02f
commit 34a58b0eb7
1 changed files with 9 additions and 1 deletions

View File

@ -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;