Clicking on a disabled ListView's delegate breaks mouse interaction
authorMartin Jones <martin.jones@nokia.com>
Thu, 28 Jul 2011 23:29:04 +0000 (09:29 +1000)
committerQt by Nokia <qt-info@nokia.com>
Fri, 29 Jul 2011 02:08:13 +0000 (04:08 +0200)
A disabled Flickable should not filter children.

Change-Id: I9f0d8fbfd0922b5c6a9eaffa69212867359f79e0
Fixes: QTBUG-20584
Reviewed-on: http://codereview.qt.nokia.com/2354
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Bea Lam <bea.lam@nokia.com>
src/declarative/items/qsgflickable.cpp
src/qtquick1/graphicsitems/qdeclarativeflickable.cpp
tests/auto/declarative/qsgflickable/data/disabled.qml [new file with mode: 0644]
tests/auto/declarative/qsgflickable/tst_qsgflickable.cpp
tests/auto/qtquick1/qdeclarativeflickable/data/disabled.qml [new file with mode: 0644]
tests/auto/qtquick1/qdeclarativeflickable/tst_qdeclarativeflickable.cpp

index 2c04ab0..be6e97f 100644 (file)
@@ -1346,7 +1346,7 @@ bool QSGFlickable::sendMouseEvent(QGraphicsSceneMouseEvent *event)
 bool QSGFlickable::childMouseEventFilter(QSGItem *i, QEvent *e)
 {
     Q_D(QSGFlickable);
-    if (!isVisible() || !d->interactive)
+    if (!isVisible() || !d->interactive || !isEnabled())
         return QSGItem::childMouseEventFilter(i, e);
     switch (e->type()) {
     case QEvent::GraphicsSceneMousePress:
index 34bbb89..04e926a 100644 (file)
@@ -1579,7 +1579,7 @@ bool QDeclarative1Flickable::sendMouseEvent(QGraphicsSceneMouseEvent *event)
 bool QDeclarative1Flickable::sceneEventFilter(QGraphicsItem *i, QEvent *e)
 {
     Q_D(QDeclarative1Flickable);
-    if (!isVisible() || !d->interactive)
+    if (!isVisible() || !d->interactive || !isEnabled())
         return QDeclarativeItem::sceneEventFilter(i, e);
     switch (e->type()) {
     case QEvent::GraphicsSceneMousePress:
diff --git a/tests/auto/declarative/qsgflickable/data/disabled.qml b/tests/auto/declarative/qsgflickable/data/disabled.qml
new file mode 100644 (file)
index 0000000..9b67982
--- /dev/null
@@ -0,0 +1,30 @@
+import QtQuick 2.0
+
+Rectangle {
+    id: root
+    width: 100; height: 100
+    property bool clicked: false
+
+    Flickable {
+        objectName: "flickable"
+        width: 100; height: 100
+        contentWidth: column.width; contentHeight: column.height
+        enabled: false
+
+        Column {
+            id: column
+            Repeater {
+                model: 4
+                Rectangle {
+                    width: 200; height: 300; color: "blue"
+                    MouseArea { anchors.fill: parent; onClicked: {  } }
+                }
+            }
+        }
+    }
+
+    MouseArea {
+        width: 100; height: 30
+        onClicked: root.clicked = true
+    }
+}
index b7c43ce..fe96453 100644 (file)
@@ -78,6 +78,7 @@ private slots:
     void returnToBounds();
     void wheel();
     void movingAndDragging();
+    void disabled();
 
 private:
     QDeclarativeEngine engine;
@@ -512,6 +513,39 @@ void tst_qsgflickable::movingAndDragging()
     delete canvas;
 }
 
+void tst_qsgflickable::disabled()
+{
+    QSGView *canvas = new QSGView;
+    canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/disabled.qml"));
+    canvas->show();
+    canvas->setFocus();
+    QVERIFY(canvas->rootObject() != 0);
+
+    QSGFlickable *flick = canvas->rootObject()->findChild<QSGFlickable*>("flickable");
+    QVERIFY(flick != 0);
+
+    QTest::mousePress(canvas, Qt::LeftButton, 0, QPoint(50, 90));
+
+    QMouseEvent moveEvent(QEvent::MouseMove, QPoint(50, 80), Qt::LeftButton, Qt::LeftButton, 0);
+    QApplication::sendEvent(canvas, &moveEvent);
+
+    moveEvent = QMouseEvent(QEvent::MouseMove, QPoint(50, 70), Qt::LeftButton, Qt::LeftButton, 0);
+    QApplication::sendEvent(canvas, &moveEvent);
+
+    moveEvent = QMouseEvent(QEvent::MouseMove, QPoint(50, 60), Qt::LeftButton, Qt::LeftButton, 0);
+    QApplication::sendEvent(canvas, &moveEvent);
+
+    QVERIFY(flick->isMoving() == false);
+
+    QTest::mouseRelease(canvas, Qt::LeftButton, 0, QPoint(50, 60));
+
+    // verify that mouse clicks on other elements still work (QTBUG-20584)
+    QTest::mousePress(canvas, Qt::LeftButton, 0, QPoint(50, 10));
+    QTest::mouseRelease(canvas, Qt::LeftButton, 0, QPoint(50, 10));
+
+    QVERIFY(canvas->rootObject()->property("clicked").toBool() == true);
+}
+
 template<typename T>
 T *tst_qsgflickable::findItem(QSGItem *parent, const QString &objectName)
 {
diff --git a/tests/auto/qtquick1/qdeclarativeflickable/data/disabled.qml b/tests/auto/qtquick1/qdeclarativeflickable/data/disabled.qml
new file mode 100644 (file)
index 0000000..ac63cd4
--- /dev/null
@@ -0,0 +1,30 @@
+import QtQuick 1.0
+
+Rectangle {
+    id: root
+    width: 100; height: 100
+    property bool clicked: false
+
+    Flickable {
+        objectName: "flickable"
+        width: 100; height: 100
+        contentWidth: column.width; contentHeight: column.height
+        enabled: false
+
+        Column {
+            id: column
+            Repeater {
+                model: 4
+                Rectangle {
+                    width: 200; height: 300; color: "blue"
+                    MouseArea { anchors.fill: parent; onClicked: {  } }
+                }
+            }
+        }
+    }
+
+    MouseArea {
+        width: 100; height: 30
+        onClicked: root.clicked = true
+    }
+}
index f74f02c..a0473a6 100644 (file)
@@ -78,6 +78,7 @@ private slots:
     void testQtQuick11Attributes();
     void testQtQuick11Attributes_data();
     void wheel();
+    void disabled();
 
 private:
     QDeclarativeEngine engine;
@@ -480,6 +481,38 @@ void tst_qdeclarativeflickable::wheel()
     delete canvas;
 }
 
+void tst_qdeclarativeflickable::disabled()
+{
+    QDeclarativeView *canvas = new QDeclarativeView;
+    canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/disabled.qml"));
+    canvas->show();
+    canvas->setFocus();
+    QVERIFY(canvas->rootObject() != 0);
+
+    QDeclarative1Flickable *flick = canvas->rootObject()->findChild<QDeclarative1Flickable*>("flickable");
+    QVERIFY(flick != 0);
+
+    QTest::mousePress(canvas->viewport(), Qt::LeftButton, 0, canvas->mapFromScene(QPoint(50,90)));
+
+    QMouseEvent moveEvent(QEvent::MouseMove, canvas->mapFromScene(QPoint(50, 80)), Qt::LeftButton, Qt::LeftButton,Qt::NoModifier);
+    QApplication::sendEvent(canvas, &moveEvent);
+
+    moveEvent = QMouseEvent(QEvent::MouseMove, canvas->mapFromScene(QPoint(50, 70)), Qt::LeftButton, Qt::LeftButton,Qt::NoModifier);
+    QApplication::sendEvent(canvas, &moveEvent);
+
+    moveEvent = QMouseEvent(QEvent::MouseMove, canvas->mapFromScene(QPoint(50, 60)), Qt::LeftButton, Qt::LeftButton,Qt::NoModifier);
+    QApplication::sendEvent(canvas, &moveEvent);
+
+    QVERIFY(flick->isMoving() == false);
+
+    QTest::mouseRelease(canvas->viewport(), Qt::LeftButton, 0, canvas->mapFromScene(QPoint(50, 60)));
+
+    // verify that mouse clicks on other elements still work (QTBUG-20584)
+    QTest::mousePress(canvas->viewport(), Qt::LeftButton, 0, canvas->mapFromScene(QPoint(50, 10)));
+    QTest::mouseRelease(canvas->viewport(), Qt::LeftButton, 0, canvas->mapFromScene(QPoint(50, 10)));
+
+    QVERIFY(canvas->rootObject()->property("clicked").toBool() == true);
+}
 
 template<typename T>
 T *tst_qdeclarativeflickable::findItem(QGraphicsObject *parent, const QString &objectName)