summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2018-01-16 14:29:40 +0100
committerJani Heikkinen <jani.heikkinen@qt.io>2018-01-17 13:09:16 +0000
commit317908e72a6ea0b4ca179690539cb352bbf60832 (patch)
treee32226a67a3de6b084a096f8d1cf0c2d12fe35e0
parent6b1682870c20a0fc86e0bb2ea8d63c3d1df1be86 (diff)
Use localPos for windowPos when passing mouse events to QQuickWidgetv5.9.4
QQuickWidget thinks of itself as a toplevel window, so it cannot process the offsets in a parent window. Amends 41293196b4db1aa7a0c616af312875c484639644. Task-number: QTBUG-65800 Change-Id: I8c5dcb8f44a6cbdb58bcc956d8263e68d8180bec Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
-rw-r--r--src/quickwidgets/qquickwidget.cpp18
-rw-r--r--tests/auto/quickwidgets/qquickwidget/data/mouse.qml18
-rw-r--r--tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp29
3 files changed, 56 insertions, 9 deletions
diff --git a/src/quickwidgets/qquickwidget.cpp b/src/quickwidgets/qquickwidget.cpp
index fd1ae52298..b15df88112 100644
--- a/src/quickwidgets/qquickwidget.cpp
+++ b/src/quickwidgets/qquickwidget.cpp
@@ -1246,11 +1246,11 @@ void QQuickWidget::mouseMoveEvent(QMouseEvent *e)
Q_QUICK_INPUT_PROFILE(QQuickProfiler::Mouse, QQuickProfiler::InputMouseMove, e->localPos().x(),
e->localPos().y());
- // Use the constructor taking localPos and screenPos. That puts localPos into the
- // event's localPos and windowPos, and screenPos into the event's screenPos. This way
- // the windowPos in e is ignored and is replaced by localPos. This is necessary
- // because QQuickWindow thinks of itself as a top-level window always.
- QMouseEvent mappedEvent(e->type(), e->localPos(), e->windowPos(), e->screenPos(),
+ // Put localPos into the event's localPos and windowPos, and screenPos into the
+ // event's screenPos. This way the windowPos in e is ignored and is replaced by
+ // localPos. This is necessary because QQuickWindow thinks of itself as a
+ // top-level window always.
+ QMouseEvent mappedEvent(e->type(), e->localPos(), e->localPos(), e->screenPos(),
e->button(), e->buttons(), e->modifiers(), e->source());
QCoreApplication::sendEvent(d->offscreenWindow, &mappedEvent);
e->setAccepted(mappedEvent.isAccepted());
@@ -1265,11 +1265,11 @@ void QQuickWidget::mouseDoubleClickEvent(QMouseEvent *e)
// As the second mouse press is suppressed in widget windows we emulate it here for QML.
// See QTBUG-25831
- QMouseEvent pressEvent(QEvent::MouseButtonPress, e->localPos(), e->windowPos(), e->screenPos(),
+ QMouseEvent pressEvent(QEvent::MouseButtonPress, e->localPos(), e->localPos(), e->screenPos(),
e->button(), e->buttons(), e->modifiers(), e->source());
QCoreApplication::sendEvent(d->offscreenWindow, &pressEvent);
e->setAccepted(pressEvent.isAccepted());
- QMouseEvent mappedEvent(e->type(), e->localPos(), e->windowPos(), e->screenPos(),
+ QMouseEvent mappedEvent(e->type(), e->localPos(), e->localPos(), e->screenPos(),
e->button(), e->buttons(), e->modifiers(), e->source());
QCoreApplication::sendEvent(d->offscreenWindow, &mappedEvent);
}
@@ -1330,7 +1330,7 @@ void QQuickWidget::mousePressEvent(QMouseEvent *e)
Q_QUICK_INPUT_PROFILE(QQuickProfiler::Mouse, QQuickProfiler::InputMousePress, e->button(),
e->buttons());
- QMouseEvent mappedEvent(e->type(), e->localPos(), e->windowPos(), e->screenPos(),
+ QMouseEvent mappedEvent(e->type(), e->localPos(), e->localPos(), e->screenPos(),
e->button(), e->buttons(), e->modifiers(), e->source());
QCoreApplication::sendEvent(d->offscreenWindow, &mappedEvent);
e->setAccepted(mappedEvent.isAccepted());
@@ -1343,7 +1343,7 @@ void QQuickWidget::mouseReleaseEvent(QMouseEvent *e)
Q_QUICK_INPUT_PROFILE(QQuickProfiler::Mouse, QQuickProfiler::InputMouseRelease, e->button(),
e->buttons());
- QMouseEvent mappedEvent(e->type(), e->localPos(), e->windowPos(), e->screenPos(),
+ QMouseEvent mappedEvent(e->type(), e->localPos(), e->localPos(), e->screenPos(),
e->button(), e->buttons(), e->modifiers(), e->source());
QCoreApplication::sendEvent(d->offscreenWindow, &mappedEvent);
e->setAccepted(mappedEvent.isAccepted());
diff --git a/tests/auto/quickwidgets/qquickwidget/data/mouse.qml b/tests/auto/quickwidgets/qquickwidget/data/mouse.qml
new file mode 100644
index 0000000000..5d1c6e8443
--- /dev/null
+++ b/tests/auto/quickwidgets/qquickwidget/data/mouse.qml
@@ -0,0 +1,18 @@
+import QtQuick 2.0
+
+Rectangle {
+ width: 50
+ height: 50
+
+ property bool wasClicked: false
+ property bool wasDoubleClicked: false
+ property bool wasMoved: false
+
+ MouseArea {
+ anchors.fill: parent
+ hoverEnabled: true
+ onClicked: wasClicked = true
+ onDoubleClicked: wasDoubleClicked = true
+ onMouseXChanged: wasMoved = true
+ }
+}
diff --git a/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp b/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp
index e4991a5f26..6c8d8191a5 100644
--- a/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp
+++ b/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp
@@ -62,6 +62,7 @@ private slots:
void keyEvents();
void shortcuts();
void enterLeave();
+ void mouseEventWindowPos();
};
@@ -433,6 +434,34 @@ void tst_qquickwidget::enterLeave()
QTRY_VERIFY(!rootItem->property("hasMouse").toBool());
}
+void tst_qquickwidget::mouseEventWindowPos()
+{
+ QWidget widget;
+ widget.resize(100, 100);
+ QQuickWidget *quick = new QQuickWidget(&widget);
+ quick->setSource(testFileUrl("mouse.qml"));
+ quick->move(50, 50);
+ widget.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&widget, 5000));
+ QQuickItem *rootItem = quick->rootObject();
+ QVERIFY(rootItem);
+
+ QVERIFY(!rootItem->property("wasClicked").toBool());
+ QVERIFY(!rootItem->property("wasDoubleClicked").toBool());
+ QVERIFY(!rootItem->property("wasMoved").toBool());
+
+ QWindow *window = widget.windowHandle();
+ QVERIFY(window);
+
+ QTest::mouseMove(window, QPoint(60, 60));
+ QTest::mouseClick(window, Qt::LeftButton, Qt::KeyboardModifiers(), QPoint(60, 60));
+ QTRY_VERIFY(rootItem->property("wasClicked").toBool());
+ QTest::mouseDClick(window, Qt::LeftButton, Qt::KeyboardModifiers(), QPoint(60, 60));
+ QTRY_VERIFY(rootItem->property("wasDoubleClicked").toBool());
+ QTest::mouseMove(window, QPoint(70, 70));
+ QTRY_VERIFY(rootItem->property("wasMoved").toBool());
+}
+
QTEST_MAIN(tst_qquickwidget)
#include "tst_qquickwidget.moc"