aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Cape <dcape@qnx.com>2015-10-07 15:46:14 -0400
committerShawn Rutledge <shawn.rutledge@qt.io>2016-07-21 14:42:39 +0000
commit0a87552e8122cdda58160da2dd549da411d9093c (patch)
tree659149c08681eb12e7f40ba651d499c50fccadb4
parentc016634478a4c9f480f7d9d5c85dded307a80d13 (diff)
Fix QQuickItem's setAcceptedMouseButtons function
When using setAcceptedMouseButtons to only allow the LeftButton, the user can click the LeftButton and while still holding it press the RightButton. There would be a press event sent for both. To resolve this, a check needed to be added to ensure the acceptedMouseButtons are checked when a second press comes in. [ChangeLog][QtQuick][QQuickItem] Fixed issue with mouse button events being sent even when they were disabled by setAcceptedMouseButtons. Change-Id: I064f3ff56ede12b1572e172be326eb337e280750 Task-number: QTBUG-31861 Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io> Reviewed-by: Robin Burchell <robin.burchell@viroteck.net> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
-rw-r--r--src/quick/items/qquickwindow.cpp6
-rw-r--r--tests/auto/quick/qquickitem/tst_qquickitem.cpp23
2 files changed, 29 insertions, 0 deletions
diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp
index de1b5f236e..8a2471b34f 100644
--- a/src/quick/items/qquickwindow.cpp
+++ b/src/quick/items/qquickwindow.cpp
@@ -1584,6 +1584,12 @@ bool QQuickWindowPrivate::deliverMouseEvent(QMouseEvent *event)
}
if (mouseGrabberItem) {
+ if (event->button() != Qt::NoButton
+ && mouseGrabberItem->acceptedMouseButtons()
+ && !(mouseGrabberItem->acceptedMouseButtons() & event->button())) {
+ event->ignore();
+ return false;
+ }
QPointF localPos = mouseGrabberItem->mapFromScene(event->windowPos());
QScopedPointer<QMouseEvent> me(cloneMouseEvent(event, &localPos));
me->accept();
diff --git a/tests/auto/quick/qquickitem/tst_qquickitem.cpp b/tests/auto/quick/qquickitem/tst_qquickitem.cpp
index 73e691b08c..6a49c4dd7e 100644
--- a/tests/auto/quick/qquickitem/tst_qquickitem.cpp
+++ b/tests/auto/quick/qquickitem/tst_qquickitem.cpp
@@ -172,6 +172,8 @@ private slots:
void contains_data();
void contains();
+ void ignoreButtonPressNotInAcceptedMouseButtons();
+
private:
enum PaintOrderOp {
@@ -1971,6 +1973,27 @@ void tst_qquickitem::contains()
QCOMPARE(result.toBool(), contains);
}
+void tst_qquickitem::ignoreButtonPressNotInAcceptedMouseButtons()
+{
+ // Verify the fix for QTBUG-31861
+ TestItem item;
+ QCOMPARE(item.acceptedMouseButtons(), Qt::MouseButtons(Qt::NoButton));
+
+ QQuickWindow window;
+ item.setSize(QSizeF(200,100));
+ item.setParentItem(window.contentItem());
+
+ item.setAcceptedMouseButtons(Qt::LeftButton);
+ QCOMPARE(item.acceptedMouseButtons(), Qt::MouseButtons(Qt::LeftButton));
+
+ QTest::mousePress(&window, Qt::LeftButton, 0, QPoint(50, 50));
+ QTest::mousePress(&window, Qt::RightButton, 0, QPoint(50, 50)); // ignored because it's not LeftButton
+ QTest::mouseRelease(&window, Qt::RightButton, 0, QPoint(50, 50)); // ignored because it didn't grab the RightButton press
+ QTest::mouseRelease(&window, Qt::LeftButton, 0, QPoint(50, 50));
+
+ QCOMPARE(item.pressCount, 1);
+ QCOMPARE(item.releaseCount, 1);
+}
QTEST_MAIN(tst_qquickitem)