summaryrefslogtreecommitdiffstats
path: root/tests/auto/gestures/tst_gestures.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/gestures/tst_gestures.cpp')
-rw-r--r--tests/auto/gestures/tst_gestures.cpp98
1 files changed, 95 insertions, 3 deletions
diff --git a/tests/auto/gestures/tst_gestures.cpp b/tests/auto/gestures/tst_gestures.cpp
index a2058cd..f8ecca3 100644
--- a/tests/auto/gestures/tst_gestures.cpp
+++ b/tests/auto/gestures/tst_gestures.cpp
@@ -58,7 +58,7 @@
static QPointF mapToGlobal(const QPointF &pt, QGraphicsItem *item, QGraphicsView *view)
{
- return view->mapToGlobal(view->mapFromScene(item->mapToScene(pt)));
+ return view->viewport()->mapToGlobal(view->mapFromScene(item->mapToScene(pt)));
}
class CustomGesture : public QGesture
@@ -353,6 +353,8 @@ private slots:
void deleteGestureTargetWidget();
void deleteGestureTargetItem_data();
void deleteGestureTargetItem();
+ void viewportCoordinates();
+ void partialGesturePropagation();
};
tst_Gestures::tst_Gestures()
@@ -742,7 +744,6 @@ public:
ignoredFinishedGestures.clear();
}
-protected:
QRectF boundingRect() const
{
return size;
@@ -1771,7 +1772,6 @@ void tst_Gestures::panelStacksBehindParent()
void tst_Gestures::deleteGestureTargetWidget()
{
-
}
void tst_Gestures::deleteGestureTargetItem_data()
@@ -1857,5 +1857,97 @@ void tst_Gestures::deleteGestureTargetItem()
sendCustomGesture(&event, item1, &scene);
}
+class GraphicsView : public QGraphicsView
+{
+public:
+ GraphicsView(QGraphicsScene *scene, QWidget *parent = 0)
+ : QGraphicsView(scene, parent)
+ {
+ }
+
+ using QGraphicsView::setViewportMargins;
+};
+
+// just making sure that even if the graphicsview has margins hotspot still
+// works properly. It should use viewport for converting global coordinates to
+// scene coordinates.
+void tst_Gestures::viewportCoordinates()
+{
+ QGraphicsScene scene;
+ GraphicsView view(&scene);
+ view.setViewportMargins(10,20,15,25);
+ view.setWindowFlags(Qt::X11BypassWindowManagerHint);
+
+ GestureItem *item1 = new GestureItem("item1");
+ item1->grabGesture(CustomGesture::GestureType);
+ item1->size = QRectF(0, 0, 3, 3);
+ item1->setZValue(2);
+ scene.addItem(item1);
+
+ view.show();
+ QTest::qWaitForWindowShown(&view);
+ view.ensureVisible(scene.sceneRect());
+
+ view.viewport()->grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren);
+
+ CustomEvent event;
+ event.hotSpot = mapToGlobal(item1->boundingRect().center(), item1, &view);
+ event.hasHotSpot = true;
+ sendCustomGesture(&event, item1, &scene);
+ QVERIFY(item1->gestureEventsReceived != 0);
+}
+
+void tst_Gestures::partialGesturePropagation()
+{
+ QGraphicsScene scene;
+ QGraphicsView view(&scene);
+ view.setWindowFlags(Qt::X11BypassWindowManagerHint);
+
+ GestureItem *item1 = new GestureItem("item1");
+ item1->grabGesture(CustomGesture::GestureType);
+ item1->setZValue(8);
+ scene.addItem(item1);
+
+ GestureItem *item2 = new GestureItem("item2[partial]");
+ item2->grabGesture(CustomGesture::GestureType, Qt::ReceivePartialGestures);
+ item2->setZValue(6);
+ scene.addItem(item2);
+
+ GestureItem *item3 = new GestureItem("item3");
+ item3->grabGesture(CustomGesture::GestureType);
+ item3->setZValue(4);
+ scene.addItem(item3);
+
+ GestureItem *item4 = new GestureItem("item4[partial]");
+ item4->grabGesture(CustomGesture::GestureType, Qt::ReceivePartialGestures);
+ item4->setZValue(2);
+ scene.addItem(item4);
+
+ view.show();
+ QTest::qWaitForWindowShown(&view);
+ view.ensureVisible(scene.sceneRect());
+
+ view.viewport()->grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren);
+
+ item1->ignoredUpdatedGestures << CustomGesture::GestureType;
+
+ CustomEvent event;
+ event.hotSpot = mapToGlobal(QPointF(5, 5), item1, &view);
+ event.hasHotSpot = true;
+ sendCustomGesture(&event, item1, &scene);
+
+ static const int TotalGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialStartedThreshold + 1;
+
+ QCOMPARE(item1->gestureOverrideEventsReceived, 1);
+ QCOMPARE(item2->gestureOverrideEventsReceived, 1);
+ QCOMPARE(item3->gestureOverrideEventsReceived, 1);
+ QCOMPARE(item4->gestureOverrideEventsReceived, 1);
+
+ QCOMPARE(item1->gestureEventsReceived, TotalGestureEventsCount);
+ QCOMPARE(item2->gestureEventsReceived, TotalGestureEventsCount-2); // except for started and finished
+ QCOMPARE(item3->gestureEventsReceived, 0);
+ QCOMPARE(item4->gestureEventsReceived, 0);
+}
+
QTEST_MAIN(tst_Gestures)
#include "tst_gestures.moc"