diff options
author | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2009-11-02 18:26:44 (GMT) |
---|---|---|
committer | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2009-11-03 10:26:08 (GMT) |
commit | 93e9bc06427c6a8e1b6d6f939cf53ae5c95e0827 (patch) | |
tree | b4e677abcb3b69dc602e29fe113041895f1e0e5f /tests | |
parent | cfcfae65778f2e1e7fc3936c66689e3685f1cc77 (diff) | |
download | Qt-93e9bc06427c6a8e1b6d6f939cf53ae5c95e0827.zip Qt-93e9bc06427c6a8e1b6d6f939cf53ae5c95e0827.tar.gz Qt-93e9bc06427c6a8e1b6d6f939cf53ae5c95e0827.tar.bz2 |
Gesture api review.
Changes to the gesture api after the review.
Reviewed-by: Jasmin Blanchette
Diffstat (limited to 'tests')
9 files changed, 161 insertions, 171 deletions
diff --git a/tests/auto/gestures/tst_gestures.cpp b/tests/auto/gestures/tst_gestures.cpp index 9b2bc57..20b53f2 100644 --- a/tests/auto/gestures/tst_gestures.cpp +++ b/tests/auto/gestures/tst_gestures.cpp @@ -111,12 +111,12 @@ public: CustomEvent::EventType = QEvent::registerEventType(); } - QGesture* createGesture(QObject *) + QGesture* create(QObject *) { return new CustomGesture; } - QGestureRecognizer::Result filterEvent(QGesture *state, QObject*o , QEvent *event) + QGestureRecognizer::Result recognize(QGesture *state, QObject*, QEvent *event) { if (event->type() == CustomEvent::EventType) { QGestureRecognizer::Result result = 0; @@ -128,13 +128,13 @@ public: if (e->hasHotSpot) g->setHotSpot(e->hotSpot); if (g->serial >= CustomGesture::SerialFinishedThreshold) - result |= QGestureRecognizer::GestureFinished; + result |= QGestureRecognizer::FinishGesture; else if (g->serial >= CustomGesture::SerialStartedThreshold) - result |= QGestureRecognizer::GestureTriggered; + result |= QGestureRecognizer::TriggerGesture; else if (g->serial >= CustomGesture::SerialMaybeThreshold) - result |= QGestureRecognizer::MaybeGesture; + result |= QGestureRecognizer::MayBeGesture; else - result = QGestureRecognizer::NotGesture; + result = QGestureRecognizer::CancelGesture; return result; } return QGestureRecognizer::Ignore; @@ -142,7 +142,7 @@ public: void reset(QGesture *state) { - CustomGesture *g = static_cast<CustomGesture*>(state); + CustomGesture *g = static_cast<CustomGesture *>(state); g->serial = 0; QGestureRecognizer::reset(state); } @@ -159,26 +159,26 @@ public: CustomEvent::EventType = QEvent::registerEventType(); } - QGesture* createGesture(QObject *) + QGesture* create(QObject *) { return new CustomGesture; } - QGestureRecognizer::Result filterEvent(QGesture *state, QObject*, QEvent *event) + QGestureRecognizer::Result recognize(QGesture *state, QObject*, QEvent *event) { if (event->type() == CustomEvent::EventType) { QGestureRecognizer::Result result = QGestureRecognizer::ConsumeEventHint; - CustomGesture *g = static_cast<CustomGesture*>(state); - CustomEvent *e = static_cast<CustomEvent*>(event); + CustomGesture *g = static_cast<CustomGesture *>(state); + CustomEvent *e = static_cast<CustomEvent *>(event); g->serial = e->serial; if (e->hasHotSpot) g->setHotSpot(e->hotSpot); if (g->serial >= CustomGesture::SerialFinishedThreshold) - result |= QGestureRecognizer::GestureFinished; + result |= QGestureRecognizer::FinishGesture; else if (g->serial >= CustomGesture::SerialMaybeThreshold) - result |= QGestureRecognizer::GestureTriggered; + result |= QGestureRecognizer::TriggerGesture; else - result = QGestureRecognizer::NotGesture; + result = QGestureRecognizer::CancelGesture; return result; } return QGestureRecognizer::Ignore; @@ -186,7 +186,7 @@ public: void reset(QGesture *state) { - CustomGesture *g = static_cast<CustomGesture*>(state); + CustomGesture *g = static_cast<CustomGesture *>(state); g->serial = 0; QGestureRecognizer::reset(state); } @@ -256,7 +256,7 @@ protected: } if (eventsPtr) { QGestureEvent *e = static_cast<QGestureEvent*>(event); - QList<QGesture*> gestures = e->allGestures(); + QList<QGesture*> gestures = e->gestures(); foreach(QGesture *g, gestures) { eventsPtr->all << g->gestureType(); switch(g->state()) { @@ -345,14 +345,14 @@ tst_Gestures::~tst_Gestures() void tst_Gestures::initTestCase() { - CustomGesture::GestureType = QApplication::registerGestureRecognizer(new CustomGestureRecognizer); + CustomGesture::GestureType = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer); QVERIFY(CustomGesture::GestureType != Qt::GestureType(0)); QVERIFY(CustomGesture::GestureType != Qt::CustomGesture); } void tst_Gestures::cleanupTestCase() { - QApplication::unregisterGestureRecognizer(CustomGesture::GestureType); + QGestureRecognizer::unregisterRecognizer(CustomGesture::GestureType); } void tst_Gestures::init() @@ -366,7 +366,7 @@ void tst_Gestures::cleanup() void tst_Gestures::customGesture() { GestureWidget widget; - widget.grabGesture(CustomGesture::GestureType, Qt::WidgetGesture); + widget.grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); CustomEvent event; sendCustomGesture(&event, &widget); @@ -387,7 +387,7 @@ void tst_Gestures::customGesture() void tst_Gestures::consumeEventHint() { GestureWidget widget; - widget.grabGesture(CustomGesture::GestureType, Qt::WidgetGesture); + widget.grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); CustomGestureRecognizer::ConsumeEvents = true; CustomEvent event; @@ -400,7 +400,7 @@ void tst_Gestures::consumeEventHint() void tst_Gestures::autoCancelingGestures() { GestureWidget widget; - widget.grabGesture(CustomGesture::GestureType, Qt::WidgetGesture); + widget.grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); // send partial gesture. The gesture will be in the "maybe" state, but will // never get enough events to fire, so Qt will have to kill it. CustomEvent ev; @@ -424,7 +424,7 @@ void tst_Gestures::gestureOverChild() GestureWidget *child = new GestureWidget("child"); l->addWidget(child); - widget.grabGesture(CustomGesture::GestureType, Qt::WidgetGesture); + widget.grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); CustomEvent event; sendCustomGesture(&event, child); @@ -440,7 +440,7 @@ void tst_Gestures::gestureOverChild() QCOMPARE(widget.gestureOverrideEventsReceived, 0); // enable gestures over the children - widget.grabGesture(CustomGesture::GestureType, Qt::WidgetWithChildrenGesture); + widget.grabGesture(CustomGesture::GestureType); widget.reset(); child->reset(); @@ -469,8 +469,8 @@ void tst_Gestures::multipleWidgetOnlyGestureInTree() GestureWidget *child = new GestureWidget("child"); l->addWidget(child); - parent.grabGesture(CustomGesture::GestureType, Qt::WidgetGesture); - child->grabGesture(CustomGesture::GestureType, Qt::WidgetGesture); + parent.grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); + child->grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); static const int TotalGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialStartedThreshold + 1; static const int TotalCustomEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialMaybeThreshold + 1; @@ -507,8 +507,8 @@ void tst_Gestures::conflictingGestures() GestureWidget *child = new GestureWidget("child"); l->addWidget(child); - parent.grabGesture(CustomGesture::GestureType, Qt::WidgetWithChildrenGesture); - child->grabGesture(CustomGesture::GestureType, Qt::WidgetWithChildrenGesture); + parent.grabGesture(CustomGesture::GestureType); + child->grabGesture(CustomGesture::GestureType); static const int TotalGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialStartedThreshold + 1; @@ -579,7 +579,7 @@ void tst_Gestures::conflictingGestures() child->reset(); // we set an attribute to make sure all gesture events are propagated - parent.grabGesture(CustomGesture::GestureType, Qt::WidgetWithChildrenGesture | Qt::AcceptPartialGesturesHint); + parent.grabGesture(CustomGesture::GestureType, Qt::ReceivePartialGestures); parent.acceptGestureOverride = false; child->acceptGestureOverride = false; parent.ignoredGestures << CustomGesture::GestureType; @@ -596,7 +596,7 @@ void tst_Gestures::conflictingGestures() parent.reset(); child->reset(); - Qt::GestureType ContinuousGesture = QApplication::registerGestureRecognizer(new CustomContinuousGestureRecognizer); + Qt::GestureType ContinuousGesture = QGestureRecognizer::registerRecognizer(new CustomContinuousGestureRecognizer); static const int ContinuousGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialMaybeThreshold + 1; child->grabGesture(ContinuousGesture); // child accepts override. And it also receives another custom gesture. @@ -610,13 +610,13 @@ void tst_Gestures::conflictingGestures() QCOMPARE(parent.gestureOverrideEventsReceived, 0); QCOMPARE(parent.gestureEventsReceived, 0); - QApplication::unregisterGestureRecognizer(ContinuousGesture); + QGestureRecognizer::unregisterRecognizer(ContinuousGesture); } void tst_Gestures::finishedWithoutStarted() { GestureWidget widget; - widget.grabGesture(CustomGesture::GestureType, Qt::WidgetGesture); + widget.grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); // the gesture will claim it finished, but it was never started. CustomEvent ev; @@ -636,9 +636,9 @@ void tst_Gestures::finishedWithoutStarted() void tst_Gestures::unknownGesture() { GestureWidget widget; - widget.grabGesture(CustomGesture::GestureType, Qt::WidgetGesture); - widget.grabGesture(Qt::CustomGesture, Qt::WidgetGesture); - widget.grabGesture(Qt::GestureType(Qt::PanGesture+512), Qt::WidgetGesture); + widget.grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); + widget.grabGesture(Qt::CustomGesture, Qt::DontStartGestureOnChildren); + widget.grabGesture(Qt::GestureType(Qt::PanGesture+512), Qt::DontStartGestureOnChildren); CustomEvent event; sendCustomGesture(&event, &widget); @@ -740,7 +740,7 @@ protected: } if (eventsPtr) { QGestureEvent *e = static_cast<QGestureEvent*>(event); - QList<QGesture*> gestures = e->allGestures(); + QList<QGesture*> gestures = e->gestures(); foreach(QGesture *g, gestures) { eventsPtr->all << g->gestureType(); switch(g->state()) { @@ -784,7 +784,7 @@ void tst_Gestures::graphicsItemGesture() QTest::qWaitForWindowShown(&view); view.ensureVisible(scene.sceneRect()); - view.viewport()->grabGesture(CustomGesture::GestureType, Qt::WidgetGesture); + view.viewport()->grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); item->grabGesture(CustomGesture::GestureType); static const int TotalGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialStartedThreshold + 1; @@ -858,7 +858,7 @@ void tst_Gestures::graphicsItemTreeGesture() QTest::qWaitForWindowShown(&view); view.ensureVisible(scene.sceneRect()); - view.viewport()->grabGesture(CustomGesture::GestureType, Qt::WidgetGesture); + view.viewport()->grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); item1->grabGesture(CustomGesture::GestureType); static const int TotalGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialStartedThreshold + 1; @@ -916,10 +916,10 @@ void tst_Gestures::explicitGraphicsObjectTarget() QTest::qWaitForWindowShown(&view); view.ensureVisible(scene.sceneRect()); - view.viewport()->grabGesture(CustomGesture::GestureType, Qt::WidgetGesture); - item1->grabGesture(CustomGesture::GestureType, Qt::ItemGesture); - item2->grabGesture(CustomGesture::GestureType, Qt::ItemGesture); - item2_child1->grabGesture(CustomGesture::GestureType, Qt::ItemGesture); + view.viewport()->grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); + item1->grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); + item2->grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); + item2_child1->grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); static const int TotalGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialStartedThreshold + 1; @@ -976,7 +976,7 @@ void tst_Gestures::gestureOverChildGraphicsItem() QTest::qWaitForWindowShown(&view); view.ensureVisible(scene.sceneRect()); - view.viewport()->grabGesture(CustomGesture::GestureType, Qt::WidgetGesture); + view.viewport()->grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); item1->grabGesture(CustomGesture::GestureType); static const int TotalGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialStartedThreshold + 1; @@ -1030,7 +1030,7 @@ void tst_Gestures::gestureOverChildGraphicsItem() item2->grabGesture(CustomGesture::GestureType); item2->ignoredGestures << CustomGesture::GestureType; item1->ignoredGestures << CustomGesture::GestureType; - item1->grabGesture(CustomGesture::GestureType, Qt::WidgetWithChildrenGesture | Qt::AcceptPartialGesturesHint); + item1->grabGesture(CustomGesture::GestureType, Qt::ReceivePartialGestures); event.hotSpot = mapToGlobal(QPointF(10, 10), item2_child1, &view); event.hasHotSpot = true; @@ -1051,10 +1051,10 @@ void tst_Gestures::twoGesturesOnDifferentLevel() GestureWidget *child = new GestureWidget("child"); l->addWidget(child); - Qt::GestureType SecondGesture = QApplication::registerGestureRecognizer(new CustomGestureRecognizer); + Qt::GestureType SecondGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer); - parent.grabGesture(CustomGesture::GestureType, Qt::WidgetWithChildrenGesture); - child->grabGesture(SecondGesture, Qt::WidgetWithChildrenGesture); + parent.grabGesture(CustomGesture::GestureType); + child->grabGesture(SecondGesture); CustomEvent event; // sending events that form a gesture to one widget, but they will be @@ -1079,7 +1079,7 @@ void tst_Gestures::twoGesturesOnDifferentLevel() for(int i = 0; i < child->events.all.size(); ++i) QCOMPARE(parent.events.all.at(i), CustomGesture::GestureType); - QApplication::unregisterGestureRecognizer(SecondGesture); + QGestureRecognizer::unregisterRecognizer(SecondGesture); } void tst_Gestures::multipleGesturesInTree() @@ -1091,19 +1091,19 @@ void tst_Gestures::multipleGesturesInTree() GestureWidget *D = new GestureWidget("D", C); Qt::GestureType FirstGesture = CustomGesture::GestureType; - Qt::GestureType SecondGesture = QApplication::registerGestureRecognizer(new CustomGestureRecognizer); - Qt::GestureType ThirdGesture = QApplication::registerGestureRecognizer(new CustomGestureRecognizer); - - Qt::GestureContext context = Qt::WidgetWithChildrenGesture | Qt::AcceptPartialGesturesHint; - A->grabGesture(FirstGesture, context); // A [1 3] - A->grabGesture(ThirdGesture, context); // | - B->grabGesture(SecondGesture, context); // B [ 2 3] - B->grabGesture(ThirdGesture, context); // | - C->grabGesture(FirstGesture, context); // C [1 2 3] - C->grabGesture(SecondGesture, context); // | - C->grabGesture(ThirdGesture, context); // D [1 3] - D->grabGesture(FirstGesture, context); - D->grabGesture(ThirdGesture, context); + Qt::GestureType SecondGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer); + Qt::GestureType ThirdGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer); + + Qt::GestureFlags flags = Qt::ReceivePartialGestures; + A->grabGesture(FirstGesture, flags); // A [1 3] + A->grabGesture(ThirdGesture, flags); // | + B->grabGesture(SecondGesture, flags); // B [ 2 3] + B->grabGesture(ThirdGesture, flags); // | + C->grabGesture(FirstGesture, flags); // C [1 2 3] + C->grabGesture(SecondGesture, flags); // | + C->grabGesture(ThirdGesture, flags); // D [1 3] + D->grabGesture(FirstGesture, flags); + D->grabGesture(ThirdGesture, flags); // make sure all widgets ignore events, so they get propagated. A->ignoredGestures << FirstGesture << ThirdGesture; @@ -1150,8 +1150,8 @@ void tst_Gestures::multipleGesturesInTree() QCOMPARE(A->events.all.count(SecondGesture), 0); QCOMPARE(A->events.all.count(ThirdGesture), TotalGestureEventsCount); - QApplication::unregisterGestureRecognizer(SecondGesture); - QApplication::unregisterGestureRecognizer(ThirdGesture); + QGestureRecognizer::unregisterRecognizer(SecondGesture); + QGestureRecognizer::unregisterRecognizer(ThirdGesture); } void tst_Gestures::multipleGesturesInComplexTree() @@ -1163,27 +1163,27 @@ void tst_Gestures::multipleGesturesInComplexTree() GestureWidget *D = new GestureWidget("D", C); Qt::GestureType FirstGesture = CustomGesture::GestureType; - Qt::GestureType SecondGesture = QApplication::registerGestureRecognizer(new CustomGestureRecognizer); - Qt::GestureType ThirdGesture = QApplication::registerGestureRecognizer(new CustomGestureRecognizer); - Qt::GestureType FourthGesture = QApplication::registerGestureRecognizer(new CustomGestureRecognizer); - Qt::GestureType FifthGesture = QApplication::registerGestureRecognizer(new CustomGestureRecognizer); - Qt::GestureType SixthGesture = QApplication::registerGestureRecognizer(new CustomGestureRecognizer); - Qt::GestureType SeventhGesture = QApplication::registerGestureRecognizer(new CustomGestureRecognizer); - - Qt::GestureContext context = Qt::WidgetWithChildrenGesture | Qt::AcceptPartialGesturesHint; - A->grabGesture(FirstGesture, context); // A [1,3,4] - A->grabGesture(ThirdGesture, context); // | - A->grabGesture(FourthGesture, context); // B [2,3,5] - B->grabGesture(SecondGesture, context); // | - B->grabGesture(ThirdGesture, context); // C [1,2,3,6] - B->grabGesture(FifthGesture, context); // | - C->grabGesture(FirstGesture, context); // D [1,3,7] - C->grabGesture(SecondGesture, context); - C->grabGesture(ThirdGesture, context); - C->grabGesture(SixthGesture, context); - D->grabGesture(FirstGesture, context); - D->grabGesture(ThirdGesture, context); - D->grabGesture(SeventhGesture, context); + Qt::GestureType SecondGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer); + Qt::GestureType ThirdGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer); + Qt::GestureType FourthGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer); + Qt::GestureType FifthGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer); + Qt::GestureType SixthGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer); + Qt::GestureType SeventhGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer); + + Qt::GestureFlags flags = Qt::ReceivePartialGestures; + A->grabGesture(FirstGesture, flags); // A [1,3,4] + A->grabGesture(ThirdGesture, flags); // | + A->grabGesture(FourthGesture, flags); // B [2,3,5] + B->grabGesture(SecondGesture, flags); // | + B->grabGesture(ThirdGesture, flags); // C [1,2,3,6] + B->grabGesture(FifthGesture, flags); // | + C->grabGesture(FirstGesture, flags); // D [1,3,7] + C->grabGesture(SecondGesture, flags); + C->grabGesture(ThirdGesture, flags); + C->grabGesture(SixthGesture, flags); + D->grabGesture(FirstGesture, flags); + D->grabGesture(ThirdGesture, flags); + D->grabGesture(SeventhGesture, flags); // make sure all widgets ignore events, so they get propagated. QSet<Qt::GestureType> allGestureTypes; @@ -1247,12 +1247,12 @@ void tst_Gestures::multipleGesturesInComplexTree() QCOMPARE(A->events.all.count(SixthGesture), 0); QCOMPARE(A->events.all.count(SeventhGesture), 0); - QApplication::unregisterGestureRecognizer(SecondGesture); - QApplication::unregisterGestureRecognizer(ThirdGesture); - QApplication::unregisterGestureRecognizer(FourthGesture); - QApplication::unregisterGestureRecognizer(FifthGesture); - QApplication::unregisterGestureRecognizer(SixthGesture); - QApplication::unregisterGestureRecognizer(SeventhGesture); + QGestureRecognizer::unregisterRecognizer(SecondGesture); + QGestureRecognizer::unregisterRecognizer(ThirdGesture); + QGestureRecognizer::unregisterRecognizer(FourthGesture); + QGestureRecognizer::unregisterRecognizer(FifthGesture); + QGestureRecognizer::unregisterRecognizer(SixthGesture); + QGestureRecognizer::unregisterRecognizer(SeventhGesture); } void tst_Gestures::testMapToScene() @@ -1261,7 +1261,7 @@ void tst_Gestures::testMapToScene() QList<QGesture*> list; list << &gesture; QGestureEvent event(list); - QCOMPARE(event.mapToScene(gesture.hotSpot()), QPointF()); // not set, can't do much + QCOMPARE(event.mapToGraphicsScene(gesture.hotSpot()), QPointF()); // not set, can't do much QGraphicsScene scene; QGraphicsView view(&scene); @@ -1278,7 +1278,7 @@ void tst_Gestures::testMapToScene() QPoint origin = view.mapToGlobal(QPoint()); event.setWidget(view.viewport()); - QCOMPARE(event.mapToScene(origin + QPoint(100, 200)), view.mapToScene(QPoint(100, 200))); + QCOMPARE(event.mapToGraphicsScene(origin + QPoint(100, 200)), view.mapToScene(QPoint(100, 200))); } void tst_Gestures::ungrabGesture() // a method on QWidget @@ -1296,7 +1296,7 @@ void tst_Gestures::ungrabGesture() // a method on QWidget if (event->type() == QEvent::Gesture) { QGestureEvent *gestureEvent = static_cast<QGestureEvent*>(event); if (gestureEvent) - foreach (QGesture *g, gestureEvent->allGestures()) + foreach (QGesture *g, gestureEvent->gestures()) gestures.insert(g); } return GestureWidget::event(event); @@ -1307,8 +1307,8 @@ void tst_Gestures::ungrabGesture() // a method on QWidget MockGestureWidget *a = &parent; MockGestureWidget *b = new MockGestureWidget("B", a); - a->grabGesture(CustomGesture::GestureType, Qt::WidgetGesture); - b->grabGesture(CustomGesture::GestureType, Qt::WidgetWithChildrenGesture); + a->grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); + b->grabGesture(CustomGesture::GestureType); b->ignoredGestures << CustomGesture::GestureType; CustomEvent event; @@ -1375,14 +1375,14 @@ void tst_Gestures::autoCancelGestures() { if (event->type() == QEvent::Gesture) { QGestureEvent *ge = static_cast<QGestureEvent*>(event); - Q_ASSERT(ge->allGestures().count() == 1); // can't use QCOMPARE here... - ge->allGestures().first()->setGestureCancelPolicy(QGesture::CancelAllInContext); + Q_ASSERT(ge->gestures().count() == 1); // can't use QCOMPARE here... + ge->gestures().first()->setGestureCancelPolicy(QGesture::CancelAllInContext); } return GestureWidget::event(event); } }; - const Qt::GestureType secondGesture = QApplication::registerGestureRecognizer(new CustomGestureRecognizer); + const Qt::GestureType secondGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer); MockWidget parent("parent"); // this one sets the cancel policy to CancelAllInContext parent.resize(300, 100); @@ -1390,8 +1390,8 @@ void tst_Gestures::autoCancelGestures() GestureWidget *child = new GestureWidget("child", &parent); child->setGeometry(10, 10, 100, 80); - parent.grabGesture(CustomGesture::GestureType, Qt::WidgetWithChildrenGesture); - child->grabGesture(secondGesture, Qt::WidgetWithChildrenGesture); + parent.grabGesture(CustomGesture::GestureType); + child->grabGesture(secondGesture); parent.show(); QTest::qWaitForWindowShown(&parent); @@ -1425,14 +1425,14 @@ void tst_Gestures::autoCancelGestures2() bool event(QEvent *event) { if (event->type() == QEvent::Gesture) { QGestureEvent *ge = static_cast<QGestureEvent*>(event); - Q_ASSERT(ge->allGestures().count() == 1); // can't use QCOMPARE here... - ge->allGestures().first()->setGestureCancelPolicy(QGesture::CancelAllInContext); + Q_ASSERT(ge->gestures().count() == 1); // can't use QCOMPARE here... + ge->gestures().first()->setGestureCancelPolicy(QGesture::CancelAllInContext); } return GestureItem::event(event); } }; - const Qt::GestureType secondGesture = QApplication::registerGestureRecognizer(new CustomGestureRecognizer); + const Qt::GestureType secondGesture = QGestureRecognizer ::registerRecognizer(new CustomGestureRecognizer); QGraphicsScene scene; QGraphicsView view(&scene); @@ -1444,10 +1444,10 @@ void tst_Gestures::autoCancelGestures2() parent->setPos(0, 0); child->setPos(10, 10); scene.addItem(parent); - view.viewport()->grabGesture(CustomGesture::GestureType, Qt::WidgetGesture); - view.viewport()->grabGesture(secondGesture, Qt::WidgetGesture); - parent->grabGesture(CustomGesture::GestureType, Qt::WidgetWithChildrenGesture); - child->grabGesture(secondGesture, Qt::WidgetWithChildrenGesture); + view.viewport()->grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); + view.viewport()->grabGesture(secondGesture, Qt::DontStartGestureOnChildren); + parent->grabGesture(CustomGesture::GestureType); + child->grabGesture(secondGesture); view.show(); QTest::qWaitForWindowShown(&view); diff --git a/tests/manual/gestures/graphicsview/gestures.cpp b/tests/manual/gestures/graphicsview/gestures.cpp index 5416457..4c21712 100644 --- a/tests/manual/gestures/graphicsview/gestures.cpp +++ b/tests/manual/gestures/graphicsview/gestures.cpp @@ -45,41 +45,41 @@ Qt::GestureType ThreeFingerSlideGesture::Type = Qt::CustomGesture; -QGesture *ThreeFingerSlideGestureRecognizer::createGesture(QObject *) +QGesture *ThreeFingerSlideGestureRecognizer::create(QObject *) { return new ThreeFingerSlideGesture; } -QGestureRecognizer::Result ThreeFingerSlideGestureRecognizer::filterEvent(QGesture *state, QObject *, QEvent *event) +QGestureRecognizer::Result ThreeFingerSlideGestureRecognizer::recognize(QGesture *state, QObject *, QEvent *event) { ThreeFingerSlideGesture *d = static_cast<ThreeFingerSlideGesture *>(state); QGestureRecognizer::Result result; switch (event->type()) { case QEvent::TouchBegin: - result = QGestureRecognizer::MaybeGesture; + result = QGestureRecognizer::MayBeGesture; case QEvent::TouchEnd: if (d->gestureFired) - result = QGestureRecognizer::GestureFinished; + result = QGestureRecognizer::FinishGesture; else - result = QGestureRecognizer::NotGesture; + result = QGestureRecognizer::CancelGesture; case QEvent::TouchUpdate: if (d->state() != Qt::NoGesture) { QTouchEvent *ev = static_cast<QTouchEvent*>(event); if (ev->touchPoints().size() == 3) { d->gestureFired = true; - result = QGestureRecognizer::GestureTriggered; + result = QGestureRecognizer::TriggerGesture; } else { - result = QGestureRecognizer::MaybeGesture; + result = QGestureRecognizer::MayBeGesture; for (int i = 0; i < ev->touchPoints().size(); ++i) { const QTouchEvent::TouchPoint &pt = ev->touchPoints().at(i); const int distance = (pt.pos().toPoint() - pt.startPos().toPoint()).manhattanLength(); if (distance > 20) { - result = QGestureRecognizer::NotGesture; + result = QGestureRecognizer::CancelGesture; } } } } else { - result = QGestureRecognizer::NotGesture; + result = QGestureRecognizer::CancelGesture; } break; @@ -89,7 +89,7 @@ QGestureRecognizer::Result ThreeFingerSlideGestureRecognizer::filterEvent(QGestu if (d->state() != Qt::NoGesture) result = QGestureRecognizer::Ignore; else - result = QGestureRecognizer::NotGesture; + result = QGestureRecognizer::CancelGesture; break; default: result = QGestureRecognizer::Ignore; @@ -105,12 +105,12 @@ void ThreeFingerSlideGestureRecognizer::reset(QGesture *state) } -QGesture *RotateGestureRecognizer::createGesture(QObject *) +QGesture *RotateGestureRecognizer::create(QObject *) { return new QGesture; } -QGestureRecognizer::Result RotateGestureRecognizer::filterEvent(QGesture *, QObject *, QEvent *event) +QGestureRecognizer::Result RotateGestureRecognizer::recognize(QGesture *, QObject *, QEvent *event) { switch (event->type()) { case QEvent::TouchBegin: diff --git a/tests/manual/gestures/graphicsview/gestures.h b/tests/manual/gestures/graphicsview/gestures.h index 6140b12..8a31b71 100644 --- a/tests/manual/gestures/graphicsview/gestures.h +++ b/tests/manual/gestures/graphicsview/gestures.h @@ -59,8 +59,8 @@ public: class ThreeFingerSlideGestureRecognizer : public QGestureRecognizer { private: - QGesture* createGesture(QObject *target); - QGestureRecognizer::Result filterEvent(QGesture *state, QObject *watched, QEvent *event); + QGesture *create(QObject *target); + QGestureRecognizer::Result recognize(QGesture *state, QObject *watched, QEvent *event); void reset(QGesture *state); }; @@ -70,8 +70,8 @@ public: RotateGestureRecognizer(); private: - QGesture* createGesture(QObject *target); - QGestureRecognizer::Result filterEvent(QGesture *state, QObject *watched, QEvent *event); + QGesture *create(QObject *target); + QGestureRecognizer::Result recognize(QGesture *state, QObject *watched, QEvent *event); void reset(QGesture *state); }; diff --git a/tests/manual/gestures/graphicsview/main.cpp b/tests/manual/gestures/graphicsview/main.cpp index de92afe..f8433b5 100644 --- a/tests/manual/gestures/graphicsview/main.cpp +++ b/tests/manual/gestures/graphicsview/main.cpp @@ -66,11 +66,11 @@ protected: default: qDebug("view: Pan: <unknown state>"); break; } - const QPointF offset = pan->offset(); + const QPointF delta = pan->delta(); QScrollBar *vbar = verticalScrollBar(); QScrollBar *hbar = horizontalScrollBar(); - vbar->setValue(vbar->value() - offset.y()); - hbar->setValue(hbar->value() - offset.x()); + vbar->setValue(vbar->value() - delta.y()); + hbar->setValue(hbar->value() - delta.x()); ge->accept(pan); return true; } @@ -152,8 +152,8 @@ private: MainWindow::MainWindow() { - (void)QApplication::registerGestureRecognizer(new MousePanGestureRecognizer); - ThreeFingerSlideGesture::Type = QApplication::registerGestureRecognizer(new ThreeFingerSlideGestureRecognizer); + (void)QGestureRecognizer::registerRecognizer(new MousePanGestureRecognizer); + ThreeFingerSlideGesture::Type = QGestureRecognizer::registerRecognizer(new ThreeFingerSlideGestureRecognizer); tabWidget = new QTabWidget; diff --git a/tests/manual/gestures/graphicsview/mousepangesturerecognizer.cpp b/tests/manual/gestures/graphicsview/mousepangesturerecognizer.cpp index 6cdbe12..82adfbd 100644 --- a/tests/manual/gestures/graphicsview/mousepangesturerecognizer.cpp +++ b/tests/manual/gestures/graphicsview/mousepangesturerecognizer.cpp @@ -51,12 +51,12 @@ MousePanGestureRecognizer::MousePanGestureRecognizer() { } -QGesture* MousePanGestureRecognizer::createGesture(QObject *) +QGesture* MousePanGestureRecognizer::create(QObject *) { return new QPanGesture; } -QGestureRecognizer::Result MousePanGestureRecognizer::filterEvent(QGesture *state, QObject *, QEvent *event) +QGestureRecognizer::Result MousePanGestureRecognizer::recognize(QGesture *state, QObject *, QEvent *event) { QPanGesture *g = static_cast<QPanGesture *>(state); QPoint globalPos; @@ -78,23 +78,19 @@ QGestureRecognizer::Result MousePanGestureRecognizer::filterEvent(QGesture *stat if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonDblClick || event->type() == QEvent::GraphicsSceneMousePress || event->type() == QEvent::GraphicsSceneMouseDoubleClick) { g->setHotSpot(globalPos); - g->setProperty("lastPos", globalPos); + g->setProperty("startPos", globalPos); g->setProperty("pressed", QVariant::fromValue<bool>(true)); - return QGestureRecognizer::GestureTriggered | QGestureRecognizer::ConsumeEventHint; + return QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint; } else if (event->type() == QEvent::MouseMove || event->type() == QEvent::GraphicsSceneMouseMove) { if (g->property("pressed").toBool()) { - QPoint pos = globalPos; - QPoint lastPos = g->property("lastPos").toPoint(); + QPoint offset = globalPos - g->property("startPos").toPoint(); g->setLastOffset(g->offset()); - lastPos = pos - lastPos; - g->setOffset(QPointF(lastPos.x(), lastPos.y())); - g->setTotalOffset(g->totalOffset() + QPointF(lastPos.x(), lastPos.y())); - g->setProperty("lastPos", pos); - return QGestureRecognizer::GestureTriggered | QGestureRecognizer::ConsumeEventHint; + g->setOffset(QPointF(offset.x(), offset.y())); + return QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint; } - return QGestureRecognizer::NotGesture; + return QGestureRecognizer::CancelGesture; } else if (event->type() == QEvent::MouseButtonRelease || event->type() == QEvent::GraphicsSceneMouseRelease) { - return QGestureRecognizer::GestureFinished | QGestureRecognizer::ConsumeEventHint; + return QGestureRecognizer::FinishGesture | QGestureRecognizer::ConsumeEventHint; } return QGestureRecognizer::Ignore; } @@ -102,11 +98,10 @@ QGestureRecognizer::Result MousePanGestureRecognizer::filterEvent(QGesture *stat void MousePanGestureRecognizer::reset(QGesture *state) { QPanGesture *g = static_cast<QPanGesture *>(state); - g->setTotalOffset(QPointF()); g->setLastOffset(QPointF()); g->setOffset(QPointF()); g->setAcceleration(0); - g->setProperty("lastPos", QVariant()); + g->setProperty("startPos", QVariant()); g->setProperty("pressed", QVariant::fromValue<bool>(false)); QGestureRecognizer::reset(state); } diff --git a/tests/manual/gestures/graphicsview/mousepangesturerecognizer.h b/tests/manual/gestures/graphicsview/mousepangesturerecognizer.h index b062fd0..6e04621 100644 --- a/tests/manual/gestures/graphicsview/mousepangesturerecognizer.h +++ b/tests/manual/gestures/graphicsview/mousepangesturerecognizer.h @@ -49,8 +49,8 @@ class MousePanGestureRecognizer : public QGestureRecognizer public: MousePanGestureRecognizer(); - QGesture* createGesture(QObject *target); - QGestureRecognizer::Result filterEvent(QGesture *state, QObject *watched, QEvent *event); + QGesture* create(QObject *target); + QGestureRecognizer::Result recognize(QGesture *state, QObject *watched, QEvent *event); void reset(QGesture *state); }; diff --git a/tests/manual/gestures/scrollarea/main.cpp b/tests/manual/gestures/scrollarea/main.cpp index 9a5eb02..4f33b28 100644 --- a/tests/manual/gestures/scrollarea/main.cpp +++ b/tests/manual/gestures/scrollarea/main.cpp @@ -50,7 +50,7 @@ public: ScrollArea(QWidget *parent = 0) : QScrollArea(parent), outside(false) { - viewport()->grabGesture(Qt::PanGesture); + viewport()->grabGesture(Qt::PanGesture, Qt::ReceivePartialGestures); } protected: @@ -87,8 +87,8 @@ protected: if (outside) return; - const QPointF offset = pan->offset(); - const QPointF totalOffset = pan->totalOffset(); + const QPointF delta = pan->delta(); + const QPointF totalOffset = pan->offset(); QScrollBar *vbar = verticalScrollBar(); QScrollBar *hbar = horizontalScrollBar(); @@ -102,8 +102,8 @@ protected: outside = true; return; } - vbar->setValue(vbar->value() - offset.y()); - hbar->setValue(hbar->value() - offset.x()); + vbar->setValue(vbar->value() - delta.y()); + hbar->setValue(hbar->value() - delta.x()); event->accept(pan); } } @@ -147,8 +147,8 @@ protected: event->ignore(pan); if (outside) return; - const QPointF offset = pan->offset(); - const QPointF totalOffset = pan->totalOffset(); + const QPointF delta = pan->delta(); + const QPointF totalOffset = pan->offset(); if (orientation() == Qt::Horizontal) { if ((value() == minimum() && totalOffset.x() < -10) || (value() == maximum() && totalOffset.x() > 10)) { @@ -156,7 +156,7 @@ protected: return; } if (totalOffset.y() < 40 && totalOffset.y() > -40) { - setValue(value() + offset.x()); + setValue(value() + delta.x()); event->accept(pan); } else { outside = true; @@ -168,7 +168,7 @@ protected: return; } if (totalOffset.x() < 40 && totalOffset.x() > -40) { - setValue(value() - offset.y()); + setValue(value() - delta.y()); event->accept(pan); } else { outside = true; @@ -232,7 +232,7 @@ private: int main(int argc, char **argv) { QApplication app(argc, argv); - app.registerGestureRecognizer(new MousePanGestureRecognizer); + QGestureRecognizer::registerRecognizer(new MousePanGestureRecognizer); MainWindow w; w.show(); return app.exec(); diff --git a/tests/manual/gestures/scrollarea/mousepangesturerecognizer.cpp b/tests/manual/gestures/scrollarea/mousepangesturerecognizer.cpp index ce5ef57..66fcf18 100644 --- a/tests/manual/gestures/scrollarea/mousepangesturerecognizer.cpp +++ b/tests/manual/gestures/scrollarea/mousepangesturerecognizer.cpp @@ -49,12 +49,12 @@ MousePanGestureRecognizer::MousePanGestureRecognizer() { } -QGesture* MousePanGestureRecognizer::createGesture(QObject *) +QGesture *MousePanGestureRecognizer::create(QObject *) { return new QPanGesture; } -QGestureRecognizer::Result MousePanGestureRecognizer::filterEvent(QGesture *state, QObject *, QEvent *event) +QGestureRecognizer::Result MousePanGestureRecognizer::recognize(QGesture *state, QObject *, QEvent *event) { QPanGesture *g = static_cast<QPanGesture *>(state); if (event->type() == QEvent::TouchBegin) { @@ -68,24 +68,20 @@ QGestureRecognizer::Result MousePanGestureRecognizer::filterEvent(QGesture *stat if (g->property("ignoreMousePress").toBool()) return QGestureRecognizer::Ignore; g->setHotSpot(me->globalPos()); - g->setProperty("lastPos", me->globalPos()); + g->setProperty("startPos", me->globalPos()); g->setProperty("pressed", QVariant::fromValue<bool>(true)); - return QGestureRecognizer::GestureTriggered | QGestureRecognizer::ConsumeEventHint; + return QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint; } else if (event->type() == QEvent::MouseMove) { if (g->property("pressed").toBool()) { - QPoint pos = me->globalPos(); - QPoint lastPos = g->property("lastPos").toPoint(); + QPoint offset = me->globalPos() - g->property("startPos").toPoint(); g->setLastOffset(g->offset()); - lastPos = pos - lastPos; - g->setOffset(QPointF(lastPos.x(), lastPos.y())); - g->setTotalOffset(g->totalOffset() + QPointF(lastPos.x(), lastPos.y())); - g->setProperty("lastPos", pos); - return QGestureRecognizer::GestureTriggered | QGestureRecognizer::ConsumeEventHint; + g->setOffset(QPointF(offset.x(), offset.y())); + return QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint; } - return QGestureRecognizer::NotGesture; + return QGestureRecognizer::CancelGesture; } else if (event->type() == QEvent::MouseButtonRelease) { if (g->property("pressed").toBool()) - return QGestureRecognizer::GestureFinished | QGestureRecognizer::ConsumeEventHint; + return QGestureRecognizer::FinishGesture | QGestureRecognizer::ConsumeEventHint; } return QGestureRecognizer::Ignore; } @@ -93,11 +89,10 @@ QGestureRecognizer::Result MousePanGestureRecognizer::filterEvent(QGesture *stat void MousePanGestureRecognizer::reset(QGesture *state) { QPanGesture *g = static_cast<QPanGesture *>(state); - g->setTotalOffset(QPointF()); g->setLastOffset(QPointF()); g->setOffset(QPointF()); g->setAcceleration(0); - g->setProperty("lastPos", QVariant()); + g->setProperty("startPos", QVariant()); g->setProperty("pressed", QVariant::fromValue<bool>(false)); g->setProperty("ignoreMousePress", QVariant::fromValue<bool>(false)); QGestureRecognizer::reset(state); diff --git a/tests/manual/gestures/scrollarea/mousepangesturerecognizer.h b/tests/manual/gestures/scrollarea/mousepangesturerecognizer.h index b062fd0..6e04621 100644 --- a/tests/manual/gestures/scrollarea/mousepangesturerecognizer.h +++ b/tests/manual/gestures/scrollarea/mousepangesturerecognizer.h @@ -49,8 +49,8 @@ class MousePanGestureRecognizer : public QGestureRecognizer public: MousePanGestureRecognizer(); - QGesture* createGesture(QObject *target); - QGestureRecognizer::Result filterEvent(QGesture *state, QObject *watched, QEvent *event); + QGesture* create(QObject *target); + QGestureRecognizer::Result recognize(QGesture *state, QObject *watched, QEvent *event); void reset(QGesture *state); }; |