From 52470e2d6ff707762c38b81d4dedcdc55b898323 Mon Sep 17 00:00:00 2001 From: Oleg Yadrov Date: Thu, 16 Feb 2017 11:04:44 -0800 Subject: QQuickWindowPrivate::deliverWheelEvent: fix global position of the event [ChangeLog][QtQuick] QWheelEvent in QQuickItem::wheelEvent now keeps correct global position. Task-number: QTBUG-58845 Change-Id: I7f88d5152927a157e2bd07ee4d5f2208be884eec Reviewed-by: Friedemann Kleint Reviewed-by: Shawn Rutledge --- tests/auto/quick/qquickitem/tst_qquickitem.cpp | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'tests/auto/quick/qquickitem') diff --git a/tests/auto/quick/qquickitem/tst_qquickitem.cpp b/tests/auto/quick/qquickitem/tst_qquickitem.cpp index 8d974f4d17..10a3a0bfa8 100644 --- a/tests/auto/quick/qquickitem/tst_qquickitem.cpp +++ b/tests/auto/quick/qquickitem/tst_qquickitem.cpp @@ -48,7 +48,8 @@ public: TestItem(QQuickItem *parent = 0) : QQuickItem(parent), focused(false), pressCount(0), releaseCount(0) , wheelCount(0), acceptIncomingTouchEvents(true) - , touchEventReached(false), timestamp(0) {} + , touchEventReached(false), timestamp(0) + , lastWheelEventPos(0, 0), lastWheelEventGlobalPos(0, 0) {} bool focused; int pressCount; @@ -57,6 +58,8 @@ public: bool acceptIncomingTouchEvents; bool touchEventReached; ulong timestamp; + QPoint lastWheelEventPos; + QPoint lastWheelEventGlobalPos; protected: virtual void focusInEvent(QFocusEvent *) { Q_ASSERT(!focused); focused = true; } virtual void focusOutEvent(QFocusEvent *) { Q_ASSERT(focused); focused = false; } @@ -66,7 +69,13 @@ protected: touchEventReached = true; event->setAccepted(acceptIncomingTouchEvents); } - virtual void wheelEvent(QWheelEvent *event) { event->accept(); ++wheelCount; timestamp = event->timestamp(); } + virtual void wheelEvent(QWheelEvent *event) { + event->accept(); + ++wheelCount; + timestamp = event->timestamp(); + lastWheelEventPos = event->pos(); + lastWheelEventGlobalPos = event->globalPos(); + } }; class TestWindow: public QQuickWindow @@ -1422,19 +1431,24 @@ void tst_qquickitem::wheelEvent() const bool shouldReceiveWheelEvents = visible && enabled; + const int width = 200; + const int height = 200; + QQuickWindow window; - window.resize(200, 200); + window.resize(width, height); window.show(); QTest::qWaitForWindowExposed(&window); TestItem *item = new TestItem; - item->setSize(QSizeF(200, 100)); + item->setSize(QSizeF(width, height)); item->setParentItem(window.contentItem()); item->setEnabled(enabled); item->setVisible(visible); - QWheelEvent event(QPoint(100, 50), -120, Qt::NoButton, Qt::NoModifier, Qt::Vertical); + QPoint localPoint(width / 2, height / 2); + QPoint globalPoint = window.mapToGlobal(localPoint); + QWheelEvent event(localPoint, globalPoint, -120, Qt::NoButton, Qt::NoModifier, Qt::Vertical); event.setTimestamp(123456UL); event.setAccepted(false); QGuiApplication::sendEvent(&window, &event); @@ -1443,6 +1457,8 @@ void tst_qquickitem::wheelEvent() QVERIFY(event.isAccepted()); QCOMPARE(item->wheelCount, 1); QCOMPARE(item->timestamp, 123456UL); + QCOMPARE(item->lastWheelEventPos, localPoint); + QCOMPARE(item->lastWheelEventGlobalPos, globalPoint); } else { QVERIFY(!event.isAccepted()); QCOMPARE(item->wheelCount, 0); -- cgit v1.2.3