diff options
author | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2010-02-25 15:48:33 (GMT) |
---|---|---|
committer | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2010-03-01 12:28:52 (GMT) |
commit | 9fe43ff4e313220a1ecb02a990324cb6b768e585 (patch) | |
tree | c64a6d40bc78e486b21f00820e1ccf8fda770f95 /tests/auto/gestures | |
parent | 57686d28fed85c9f8fbb340cd05f3fb6322332f7 (diff) | |
download | Qt-9fe43ff4e313220a1ecb02a990324cb6b768e585.zip Qt-9fe43ff4e313220a1ecb02a990324cb6b768e585.tar.gz Qt-9fe43ff4e313220a1ecb02a990324cb6b768e585.tar.bz2 |
Fixed coordinate system conversion for gestures.
When converting hotspot position (which is in global coordinates) to graphics
scene coordinates we should use the viewport because the mapToScene() takes a
position in a viewport.
Task-number: related to QTBUG-6876
Reviewed-by: Thomas Zander
Diffstat (limited to 'tests/auto/gestures')
-rw-r--r-- | tests/auto/gestures/tst_gestures.cpp | 45 |
1 files changed, 42 insertions, 3 deletions
diff --git a/tests/auto/gestures/tst_gestures.cpp b/tests/auto/gestures/tst_gestures.cpp index a2058cd..a1afa0a 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,7 @@ private slots: void deleteGestureTargetWidget(); void deleteGestureTargetItem_data(); void deleteGestureTargetItem(); + void viewportCoordinates(); }; tst_Gestures::tst_Gestures() @@ -742,7 +743,6 @@ public: ignoredFinishedGestures.clear(); } -protected: QRectF boundingRect() const { return size; @@ -1771,7 +1771,6 @@ void tst_Gestures::panelStacksBehindParent() void tst_Gestures::deleteGestureTargetWidget() { - } void tst_Gestures::deleteGestureTargetItem_data() @@ -1857,5 +1856,45 @@ 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); +} + QTEST_MAIN(tst_Gestures) #include "tst_gestures.moc" |