diff options
author | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2009-06-03 09:56:12 (GMT) |
---|---|---|
committer | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2009-06-03 17:29:31 (GMT) |
commit | 928830fa0626499b5299386e2095c9fffbf69c8b (patch) | |
tree | 0553af9d64837f4b8a84a477670416f4cc98a7f7 | |
parent | 0cca7705c01d262c1bb008f969a9705786e1c80e (diff) | |
download | Qt-928830fa0626499b5299386e2095c9fffbf69c8b.zip Qt-928830fa0626499b5299386e2095c9fffbf69c8b.tar.gz Qt-928830fa0626499b5299386e2095c9fffbf69c8b.tar.bz2 |
Added pan gesture to the gesture autotest
-rw-r--r-- | tests/auto/gestures/customgesturerecognizer.cpp | 60 | ||||
-rw-r--r-- | tests/auto/gestures/customgesturerecognizer.h | 44 | ||||
-rw-r--r-- | tests/auto/gestures/tst_gestures.cpp | 16 |
3 files changed, 115 insertions, 5 deletions
diff --git a/tests/auto/gestures/customgesturerecognizer.cpp b/tests/auto/gestures/customgesturerecognizer.cpp index 898071a..cb3f7bf 100644 --- a/tests/auto/gestures/customgesturerecognizer.cpp +++ b/tests/auto/gestures/customgesturerecognizer.cpp @@ -4,6 +4,7 @@ const char* SingleshotGestureRecognizer::Name = "SingleshotGesture"; const char* PinchGestureRecognizer::Name = "PinchGesture"; const char* SecondFingerGestureRecognizer::Name = "SecondFingerGesture"; +const char* PanGestureRecognizer::Name = "PanGesture"; SingleshotGestureRecognizer::SingleshotGestureRecognizer(QObject *parent) : QGestureRecognizer(QString(SingleshotGestureRecognizer::Name), parent) @@ -105,3 +106,62 @@ void SecondFingerGestureRecognizer::reset() gesture->point = TouchPoint(); gesture->offset = QPoint(); } + +PanGestureRecognizer::PanGestureRecognizer(QObject *parent) + : QGestureRecognizer(PanGestureRecognizer::Name, parent) +{ + gesture = new PanGesture(this, PanGestureRecognizer::Name); +} + +QGestureRecognizer::Result PanGestureRecognizer::filterEvent(const QEvent *event) +{ + if (event->type() != QEvent::TouchBegin || + event->type() != QEvent::TouchUpdate || + event->type() != QEvent::TouchEnd) + return QGestureRecognizer::Ignore; + + const QTouchEvent *e = static_cast<const QTouchEvent*>(event); + const QList<QTouchEvent::TouchPoint*> &points = e->touchPoints(); + + if (points.size() >= 1) { + gesture->lastPoints[0] = gesture->points[0]; + gesture->points[0].id = points.at(0)->id(); + gesture->points[0].pt = points.at(0)->startPos().toPoint(); + gesture->points[0].state = (TouchPoint::State)points.at(0)->state(); + if (points.at(0)->state() == Qt::TouchPointPressed) { + gesture->startPoints[0] = gesture->points[0]; + gesture->lastPoints[0] = gesture->points[0]; + } + } + if (points.size() >= 2) { + gesture->lastPoints[1] = gesture->points[1]; + gesture->points[1].id = points.at(1)->id(); + gesture->points[1].pt = points.at(1)->startPos().toPoint(); + gesture->points[1].state = (TouchPoint::State)points.at(1)->state(); + if (points.at(1)->state() == Qt::TouchPointPressed) { + gesture->startPoints[1] = gesture->points[1]; + gesture->lastPoints[1] = gesture->points[1]; + } + } + + if (points.size() == 2) + return QGestureRecognizer::GestureStarted; + if (points.size() > 2) + return QGestureRecognizer::MaybeGesture; + if (points.at(0)->state() == Qt::TouchPointPressed) + return QGestureRecognizer::MaybeGesture; + if (points.at(0)->state() == Qt::TouchPointReleased) + return QGestureRecognizer::GestureFinished; + return QGestureRecognizer::GestureStarted; +} + +void PanGestureRecognizer::reset() +{ + gesture->startPoints[0] = TouchPoint(); + gesture->startPoints[1] = TouchPoint(); + gesture->lastPoints[0] = TouchPoint(); + gesture->lastPoints[1] = TouchPoint(); + gesture->points[0] = TouchPoint(); + gesture->points[1] = TouchPoint(); + gesture->offset = QPoint(); +} diff --git a/tests/auto/gestures/customgesturerecognizer.h b/tests/auto/gestures/customgesturerecognizer.h index 9b56433..519aba8 100644 --- a/tests/auto/gestures/customgesturerecognizer.h +++ b/tests/auto/gestures/customgesturerecognizer.h @@ -51,10 +51,10 @@ private: struct TouchPoint { enum State { - None, - Begin, - Update, - End + None = 0, + Begin = Qt::TouchPointPressed, + Update = Qt::TouchPointMoved, + End = Qt::TouchPointReleased }; int id; QPoint pt; @@ -148,4 +148,40 @@ private: SecondFingerGesture *gesture; }; +class PanGesture : public QGesture +{ + Q_OBJECT +public: + PanGesture(QObject *parent, const QString &type) + : QGesture(parent, type) { } + + TouchPoint startPoints[2]; + TouchPoint lastPoints[2]; + TouchPoint points[2]; + + QPoint offset; + +protected: + void translate(const QPoint &pt) + { + offset += pt; + } +}; + +class PanGestureRecognizer : public QGestureRecognizer +{ + Q_OBJECT +public: + static const char *Name; + + PanGestureRecognizer(QObject *parent = 0); + + QGestureRecognizer::Result filterEvent(const QEvent *event); + QGesture* getGesture() { return gesture; } + void reset(); + +private: + PanGesture *gesture; +}; + #endif diff --git a/tests/auto/gestures/tst_gestures.cpp b/tests/auto/gestures/tst_gestures.cpp index 9639fb0..a649004 100644 --- a/tests/auto/gestures/tst_gestures.cpp +++ b/tests/auto/gestures/tst_gestures.cpp @@ -156,7 +156,8 @@ class GestureWidget : public QWidget static int numberOfWidgets; public: - enum Type { DoNotGrabGestures, GrabAllGestures, GrabSingleshot, GrabPinch, GrabSecondFinger }; + enum Type { DoNotGrabGestures, GrabAllGestures, GrabSingleshot, + GrabPinch, GrabSecondFinger, GrabPan }; static const int LeftMargin = 10; static const int TopMargin = 20; @@ -179,6 +180,7 @@ public: singleshotGestureId = -1; pinchGestureId = -1; secondFingerGestureId = -1; + panGestureId = -1; if (type == GrabAllGestures || type == GrabSingleshot) { singleshotGestureId = grabGesture(SingleshotGestureRecognizer::Name); } @@ -188,6 +190,9 @@ public: if (type == GrabAllGestures || type == GrabSecondFinger) { secondFingerGestureId = grabGesture(SecondFingerGestureRecognizer::Name); } + if (type == GrabAllGestures || type == GrabPan) { + panGestureId = grabGesture(PanGestureRecognizer::Name); + } reset(); } ~GestureWidget() @@ -208,6 +213,10 @@ public: { secondFingerGestureId = grabGesture(SecondFingerGestureRecognizer::Name); } + void grabPanGesture() + { + panGestureId = grabGesture(PanGestureRecognizer::Name); + } void ungrabGestures() { releaseGesture(singleshotGestureId); @@ -216,15 +225,19 @@ public: pinchGestureId = -1; releaseGesture(secondFingerGestureId); secondFingerGestureId = -1; + releaseGesture(panGestureId); + panGestureId = -1; } int singleshotGestureId; int pinchGestureId; int secondFingerGestureId; + int panGestureId; bool shouldAcceptSingleshotGesture; bool shouldAcceptPinchGesture; bool shouldAcceptSecondFingerGesture; + bool shouldAcceptPanGesture; GestureState gesture; @@ -233,6 +246,7 @@ public: shouldAcceptSingleshotGesture = true; shouldAcceptPinchGesture = true; shouldAcceptSecondFingerGesture = true; + shouldAcceptPanGesture = true; gesture.reset(); } protected: |