diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2021-07-02 21:27:54 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2021-07-06 13:03:04 +0200 |
commit | f6f7233891f3ac71f18e7a994847c39362e857dd (patch) | |
tree | 2e092faf2e826828fb7554335d3f356120d1a746 /tests/auto | |
parent | 1775bbc6d4231fd10ccfcea006d78d8769b854a2 (diff) |
Send hover events with correct scene and global positions
Task-number: QTBUG-94971
Change-Id: I047223dfdb76a6f1237b9d15b54381cd085aa1ac
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 0a271b5cd4da9e13accbf63a576413c45f367adc)
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/quick/qquickitem/tst_qquickitem.cpp | 42 |
1 files changed, 38 insertions, 4 deletions
diff --git a/tests/auto/quick/qquickitem/tst_qquickitem.cpp b/tests/auto/quick/qquickitem/tst_qquickitem.cpp index 8f8ae396e3..5c2feb1c2a 100644 --- a/tests/auto/quick/qquickitem/tst_qquickitem.cpp +++ b/tests/auto/quick/qquickitem/tst_qquickitem.cpp @@ -1559,18 +1559,37 @@ public: int hoverEnterCount; int hoverMoveCount; int hoverLeaveCount; + QPoint hoverPosition; + QPoint hoverScenePosition; + QPoint hoverGlobalPosition; + QPoint hoverLastGlobalPosition; protected: - virtual void hoverEnterEvent(QHoverEvent *event) { + void hoverEnterEvent(QHoverEvent *event) override { + qCDebug(lcTests) << static_cast<QSinglePointEvent *>(event) << event->position() << event->scenePosition() << event->globalPosition(); event->accept(); ++hoverEnterCount; + hoverPosition = event->position().toPoint(); + hoverScenePosition = event->scenePosition().toPoint(); + hoverGlobalPosition = event->globalPosition().toPoint(); + hoverLastGlobalPosition = event->points().first().globalLastPosition().toPoint(); } - virtual void hoverMoveEvent(QHoverEvent *event) { + void hoverMoveEvent(QHoverEvent *event) override { + qCDebug(lcTests) << static_cast<QSinglePointEvent *>(event) << event->position() << event->scenePosition() << event->globalPosition(); event->accept(); ++hoverMoveCount; + hoverPosition = event->position().toPoint(); + hoverScenePosition = event->scenePosition().toPoint(); + hoverGlobalPosition = event->globalPosition().toPoint(); + hoverLastGlobalPosition = event->points().first().globalLastPosition().toPoint(); } - virtual void hoverLeaveEvent(QHoverEvent *event) { + void hoverLeaveEvent(QHoverEvent *event) override { + qCDebug(lcTests) << static_cast<QSinglePointEvent *>(event) << event->position() << event->scenePosition() << event->globalPosition(); event->accept(); ++hoverLeaveCount; + hoverPosition = event->position().toPoint(); + hoverScenePosition = event->scenePosition().toPoint(); + hoverGlobalPosition = event->globalPosition().toPoint(); + hoverLastGlobalPosition = event->points().first().globalLastPosition().toPoint(); } }; @@ -1620,13 +1639,28 @@ void tst_qquickitem::hoverEvent() QTest::mouseMove(window, outside); item->resetCounters(); + auto checkPositions = [=](QPoint pt) { + QCOMPARE(item->hoverPosition, pt); + QCOMPARE(item->hoverScenePosition, item->mapToScene(pt).toPoint()); + QCOMPARE(item->hoverGlobalPosition, item->mapToGlobal(pt).toPoint()); + QVERIFY(!item->hoverLastGlobalPosition.isNull()); + }; + // Enter, then move twice inside, then leave. + const bool shouldReceiveHoverEvents = visible && acceptHoverEvents; QTest::mouseMove(window, inside); + if (shouldReceiveHoverEvents) + checkPositions(inside); QTest::mouseMove(window, anotherInside); + if (shouldReceiveHoverEvents) + checkPositions(anotherInside); QTest::mouseMove(window, inside); + if (shouldReceiveHoverEvents) + checkPositions(inside); QTest::mouseMove(window, outside); + if (shouldReceiveHoverEvents) + checkPositions(outside); - const bool shouldReceiveHoverEvents = visible && acceptHoverEvents; if (shouldReceiveHoverEvents) { QCOMPARE(item->hoverEnterCount, 1); QCOMPARE(item->hoverMoveCount, 2); |