diff options
author | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2009-10-14 12:45:27 (GMT) |
---|---|---|
committer | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2009-10-22 14:59:18 (GMT) |
commit | c5c1b878891b5ace5a71b95ea62229e26722fdba (patch) | |
tree | 7ef44d068a73c35efd938870c24fe6f0b778969e /tests/auto/gestures | |
parent | d1a60dcbddbae46aaea655bb55c0c8fd46f38b2c (diff) | |
download | Qt-c5c1b878891b5ace5a71b95ea62229e26722fdba.zip Qt-c5c1b878891b5ace5a71b95ea62229e26722fdba.tar.gz Qt-c5c1b878891b5ace5a71b95ea62229e26722fdba.tar.bz2 |
Fixed gesture event delivery when several gestures are triggered.
When there are two different gestures are being triggered and they are
supposed to be sent to different widgets, don't stop event "propagation"
when the first event is successfully delivered.
Reviewed-by: trustme
Diffstat (limited to 'tests/auto/gestures')
-rw-r--r-- | tests/auto/gestures/tst_gestures.cpp | 45 |
1 files changed, 39 insertions, 6 deletions
diff --git a/tests/auto/gestures/tst_gestures.cpp b/tests/auto/gestures/tst_gestures.cpp index 3ce5b86..a5e66cf 100644 --- a/tests/auto/gestures/tst_gestures.cpp +++ b/tests/auto/gestures/tst_gestures.cpp @@ -105,8 +105,8 @@ class CustomGestureRecognizer : public QGestureRecognizer public: CustomGestureRecognizer() { - CustomEvent::EventType = QEvent::registerEventType(); - eventsCounter = 0; + if (!CustomEvent::EventType) + CustomEvent::EventType = QEvent::registerEventType(); } QGesture* createGesture(QObject *) @@ -123,7 +123,6 @@ public: g->serial = e->serial; if (e->hasHotSpot) g->setHotSpot(e->hotSpot); - ++eventsCounter; if (g->serial >= CustomGesture::SerialFinishedThreshold) result |= QGestureRecognizer::GestureFinished; else if (g->serial >= CustomGesture::SerialStartedThreshold) @@ -143,9 +142,6 @@ public: g->serial = 0; QGestureRecognizer::reset(state); } - - int eventsCounter; - QString name; }; class GestureWidget : public QWidget @@ -272,6 +268,7 @@ private slots: void graphicsItemGesture(); void explicitGraphicsObjectTarget(); void gestureOverChildGraphicsItem(); + void multipleGestures(); }; tst_Gestures::tst_Gestures() @@ -785,5 +782,41 @@ void tst_Gestures::gestureOverChildGraphicsItem() QCOMPARE(item1->gestureOverrideEventsReceived, TotalGestureEventsCount); } +void tst_Gestures::multipleGestures() +{ + GestureWidget parent("parent"); + QVBoxLayout *l = new QVBoxLayout(&parent); + GestureWidget *child = new GestureWidget("child"); + l->addWidget(child); + + Qt::GestureType SecondGesture = qApp->registerGestureRecognizer(new CustomGestureRecognizer); + + parent.grabGesture(CustomGesture::GestureType, Qt::WidgetWithChildrenGesture); + child->grabGesture(SecondGesture, Qt::WidgetWithChildrenGesture); + + CustomEvent event; + // sending events that form a gesture to one widget, but they will be + // filtered by two different gesture recognizers and will generate two + // QGesture objects. Check that those gesture objects are delivered to + // different widgets properly. + sendCustomGesture(&event, child); + + static const int TotalGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialStartedThreshold + 1; + static const int TotalCustomEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialMaybeThreshold + 1; + + QCOMPARE(child->customEventsReceived, TotalCustomEventsCount); + QCOMPARE(child->gestureEventsReceived, TotalGestureEventsCount); + QCOMPARE(child->gestureOverrideEventsReceived, 0); + QCOMPARE(child->events.all.size(), TotalGestureEventsCount); + for(int i = 0; i < child->events.all.size(); ++i) + QCOMPARE(child->events.all.at(i), SecondGesture); + + QCOMPARE(parent.gestureEventsReceived, TotalGestureEventsCount); + QCOMPARE(parent.gestureOverrideEventsReceived, 0); + QCOMPARE(parent.events.all.size(), TotalGestureEventsCount); + for(int i = 0; i < child->events.all.size(); ++i) + QCOMPARE(parent.events.all.at(i), CustomGesture::GestureType); +} + QTEST_MAIN(tst_Gestures) #include "tst_gestures.moc" |