summaryrefslogtreecommitdiffstats
path: root/tests/auto/qgraphicsview
diff options
context:
space:
mode:
authorGabriel de Dietrich <gabriel.dietrich-de@nokia.com>2009-08-17 11:29:09 (GMT)
committerGabriel de Dietrich <gabriel.dietrich-de@nokia.com>2009-08-17 11:39:47 (GMT)
commitabdf1befb8de4b88da43561dae2e1beb09c2a532 (patch)
tree5980f79a54bd1b8f1b2b650381c4b38a25e3390d /tests/auto/qgraphicsview
parent9b4982af65e533b0613abd0f889bcf6e7673e410 (diff)
downloadQt-abdf1befb8de4b88da43561dae2e1beb09c2a532.zip
Qt-abdf1befb8de4b88da43561dae2e1beb09c2a532.tar.gz
Qt-abdf1befb8de4b88da43561dae2e1beb09c2a532.tar.bz2
Transforms do not obey AnchorUnderMouse with viewport margins set
setTransformationAnchor(QGraphicsView::AnchorUnderMouse) would not work properly if viewport margins were set. When centering the view in QGraphicsViewPrivate::centerView, the viewport margins were not being taken into account. Mapping from global cursor coordinates in the viewport instead of the view fixes the issue. Task-number: 255529 Reviewed-by: Olivier
Diffstat (limited to 'tests/auto/qgraphicsview')
-rw-r--r--tests/auto/qgraphicsview/tst_qgraphicsview.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp
index 0c65b87..c12fb11 100644
--- a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp
+++ b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp
@@ -216,6 +216,7 @@ private slots:
void task239047_fitInViewSmallViewport();
void task245469_itemsAtPointWithClip();
void task253415_reconnectUpdateSceneOnSceneChanged();
+ void task255529_transformationAnchorMouseAndViewportMargins();
};
void tst_QGraphicsView::initTestCase()
@@ -3617,5 +3618,41 @@ void tst_QGraphicsView::task253415_reconnectUpdateSceneOnSceneChanged()
QVERIFY(wasConnected2);
}
+void tst_QGraphicsView::task255529_transformationAnchorMouseAndViewportMargins()
+{
+ QGraphicsScene scene(-100, -100, 200, 200);
+ scene.addRect(QRectF(-50, -50, 100, 100), QPen(Qt::black), QBrush(Qt::blue));
+
+ class VpGraphicsView: public QGraphicsView
+ {
+ public:
+ VpGraphicsView(QGraphicsScene *scene)
+ : QGraphicsView(scene)
+ {
+ setViewportMargins(8, 16, 12, 20);
+ setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
+ setMouseTracking(true);
+ }
+ };
+
+ VpGraphicsView view(&scene);
+ view.show();
+ QPoint mouseViewPos(20, 20);
+ sendMouseMove(view.viewport(), mouseViewPos);
+ QTest::qWait(125);
+
+ QPointF mouseScenePos = view.mapToScene(mouseViewPos);
+ view.setTransform(QTransform().scale(5, 5));
+ QTest::qWait(125);
+ view.setTransform(QTransform().rotate(5, Qt::ZAxis), true);
+ QTest::qWait(125);
+
+ QPointF newMouseScenePos = view.mapToScene(mouseViewPos);
+ qreal slack = 3;
+ QVERIFY(qAbs(newMouseScenePos.x() - mouseScenePos.x()) < slack);
+ QVERIFY(qAbs(newMouseScenePos.y() - mouseScenePos.y()) < slack);
+}
+
+
QTEST_MAIN(tst_QGraphicsView)
#include "tst_qgraphicsview.moc"