diff options
author | Andy Shaw <andy.shaw@qt.io> | 2018-02-01 20:59:58 +0100 |
---|---|---|
committer | Andy Shaw <andy.shaw@qt.io> | 2018-02-08 21:25:01 +0000 |
commit | c48f4bde0044bd5b23af231f3639d0779ecbdb03 (patch) | |
tree | 8aa425ef2b68f8afd990cb0268173cc3644b86b8 /tests/auto/widgets | |
parent | 83b0abf928af6cd9f301e3367c439eca22aab323 (diff) |
Set the ellipseDiameters back to the original size in QGraphicsView
When calling setSceneRect() on a QTouchPoint it will cause the
ellipseDiameters to be changed, whereas this should not be affected by
the scene rectangle as it should be in logical pixels.
Also add a manual test for visually checking the ellipse diameters on
various devices.
Change-Id: I1ee9207cb1a63cfef33fe904594c73aba221af5c
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'tests/auto/widgets')
-rw-r--r-- | tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp index bfdb540c2b..e7cf8f17a2 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp @@ -254,6 +254,7 @@ private slots: void zeroScale(); void focusItemChangedSignal(); void minimumRenderSize(); + void checkTouchPointsEllipseDiameters(); // task specific tests below me void task139710_bspTreeCrash(); @@ -4764,6 +4765,81 @@ void tst_QGraphicsScene::minimumRenderSize() QVERIFY(smallChild->repaints > smallerGrandChild->repaints); } +class TouchItem : public QGraphicsRectItem +{ +public: + TouchItem() : QGraphicsRectItem(QRectF(-10, -10, 20, 20)), + seenTouch(false) + { + setAcceptTouchEvents(true); + setFlag(QGraphicsItem::ItemIgnoresTransformations); + } + bool seenTouch; + QList<QTouchEvent::TouchPoint> touchPoints; +protected: + bool sceneEvent(QEvent *event) override + { + switch (event->type()) { + case QEvent::TouchBegin: + case QEvent::TouchUpdate: + case QEvent::TouchEnd: + seenTouch = true; + touchPoints = static_cast<QTouchEvent *>(event)->touchPoints(); + event->accept(); + return true; + default: + break; + } + return QGraphicsRectItem::sceneEvent(event); + } +}; + +void tst_QGraphicsScene::checkTouchPointsEllipseDiameters() +{ + QGraphicsScene scene; + QGraphicsView view(&scene); + scene.setSceneRect(1, 1, 198, 198); + view.scale(1.5, 1.5); + view.setFocus(); + TouchItem *rect = new TouchItem; + scene.addItem(rect); + view.show(); + QApplication::setActiveWindow(&view); + QVERIFY(QTest::qWaitForWindowActive(&view)); + + const QSizeF ellipseDiameters(10.0, 10.0); + QTouchEvent::TouchPoint touchPoint(0); + touchPoint.setState(Qt::TouchPointPressed); + touchPoint.setPos(view.mapFromScene(rect->mapToScene(rect->boundingRect().center()))); + touchPoint.setScreenPos(view.mapToGlobal(touchPoint.pos().toPoint())); + touchPoint.setEllipseDiameters(ellipseDiameters); + + QList<QTouchEvent::TouchPoint> touchPoints = { touchPoint }; + + QTouchDevice *testDevice = QTest::createTouchDevice(QTouchDevice::TouchPad); + QTouchEvent touchEvent(QEvent::TouchBegin, + testDevice, + Qt::NoModifier, + Qt::TouchPointPressed, + touchPoints); + QApplication::sendEvent(view.viewport(), &touchEvent); + QVERIFY(rect->seenTouch); + QVERIFY(rect->touchPoints.size() == 1); + QCOMPARE(ellipseDiameters, rect->touchPoints.first().ellipseDiameters()); + + rect->seenTouch = false; + rect->touchPoints.clear(); + QTouchEvent touchUpdateEvent(QEvent::TouchUpdate, + testDevice, + Qt::NoModifier, + Qt::TouchPointMoved, + touchPoints); + QApplication::sendEvent(view.viewport(), &touchEvent); + QVERIFY(rect->seenTouch); + QVERIFY(rect->touchPoints.size() == 1); + QCOMPARE(ellipseDiameters, rect->touchPoints.first().ellipseDiameters()); +} + void tst_QGraphicsScene::taskQTBUG_15977_renderWithDeviceCoordinateCache() { QGraphicsScene scene; |