summaryrefslogtreecommitdiffstats
path: root/src/widgets/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/kernel')
-rw-r--r--src/widgets/kernel/qgesture_p.h10
-rw-r--r--src/widgets/kernel/qstandardgestures.cpp23
2 files changed, 23 insertions, 10 deletions
diff --git a/src/widgets/kernel/qgesture_p.h b/src/widgets/kernel/qgesture_p.h
index 8668145d8a..183a2eba0f 100644
--- a/src/widgets/kernel/qgesture_p.h
+++ b/src/widgets/kernel/qgesture_p.h
@@ -134,11 +134,17 @@ class QSwipeGesturePrivate : public QGesturePrivate
Q_DECLARE_PUBLIC(QSwipeGesture)
public:
+ enum State {
+ NoGesture,
+ Started,
+ ThreePointsReached
+ };
+
QSwipeGesturePrivate()
: horizontalDirection(QSwipeGesture::NoDirection),
verticalDirection(QSwipeGesture::NoDirection),
swipeAngle(0),
- started(false), velocityValue(0)
+ state(NoGesture), velocityValue(0)
{
}
@@ -150,7 +156,7 @@ public:
qreal swipeAngle;
QPoint lastPositions[3];
- bool started;
+ State state;
qreal velocityValue;
QElapsedTimer time;
};
diff --git a/src/widgets/kernel/qstandardgestures.cpp b/src/widgets/kernel/qstandardgestures.cpp
index 0822c04033..9e3cb473e5 100644
--- a/src/widgets/kernel/qstandardgestures.cpp
+++ b/src/widgets/kernel/qstandardgestures.cpp
@@ -283,7 +283,7 @@ QGestureRecognizer::Result QSwipeGestureRecognizer::recognize(QGesture *state,
case QEvent::TouchBegin: {
d->velocityValue = 1;
d->time.start();
- d->started = true;
+ d->state = QSwipeGesturePrivate::Started;
result = QGestureRecognizer::MayBeGesture;
break;
}
@@ -297,9 +297,10 @@ QGestureRecognizer::Result QSwipeGestureRecognizer::recognize(QGesture *state,
}
case QEvent::TouchUpdate: {
const QTouchEvent *ev = static_cast<const QTouchEvent *>(event);
- if (!d->started)
+ if (d->state == QSwipeGesturePrivate::NoGesture)
result = QGestureRecognizer::CancelGesture;
else if (ev->touchPoints().size() == 3) {
+ d->state = QSwipeGesturePrivate::ThreePointsReached;
QTouchEvent::TouchPoint p1 = ev->touchPoints().at(0);
QTouchEvent::TouchPoint p2 = ev->touchPoints().at(1);
QTouchEvent::TouchPoint p3 = ev->touchPoints().at(2);
@@ -354,12 +355,18 @@ QGestureRecognizer::Result QSwipeGestureRecognizer::recognize(QGesture *state,
} else if (ev->touchPoints().size() > 3) {
result = QGestureRecognizer::CancelGesture;
} else { // less than 3 touch points
- if (d->started && (ev->touchPointStates() & Qt::TouchPointPressed))
- result = QGestureRecognizer::CancelGesture;
- else if (d->started)
- result = QGestureRecognizer::Ignore;
- else
+ switch (d->state) {
+ case QSwipeGesturePrivate::NoGesture:
result = QGestureRecognizer::MayBeGesture;
+ break;
+ case QSwipeGesturePrivate::Started:
+ result = QGestureRecognizer::Ignore;
+ break;
+ case QSwipeGesturePrivate::ThreePointsReached:
+ result = (ev->touchPointStates() & Qt::TouchPointPressed)
+ ? QGestureRecognizer::CancelGesture : QGestureRecognizer::Ignore;
+ break;
+ }
}
break;
}
@@ -378,7 +385,7 @@ void QSwipeGestureRecognizer::reset(QGesture *state)
d->swipeAngle = 0;
d->lastPositions[0] = d->lastPositions[1] = d->lastPositions[2] = QPoint();
- d->started = false;
+ d->state = QSwipeGesturePrivate::NoGesture;
d->velocityValue = 0;
d->time.invalidate();