diff options
author | Pasi Pentikainen <ext-pasi.a.pentikainen@nokia.com> | 2012-05-04 17:47:55 +0300 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-05-08 02:39:44 +0200 |
commit | 0f73af96c8ac823761f6ad4f364ce346688e4621 (patch) | |
tree | 3d3c34648ec1cf2d877253f9ed245903e41476e4 | |
parent | b889b3c8e83a56526eae04289ab9b1608d268b2a (diff) | |
download | qt4-tools-0f73af96c8ac823761f6ad4f364ce346688e4621.tar.gz |
Clicking on a disabled ListView's delegate breaks mouse interaction
A disabled Flickable should not filter children.
This is a backport of change I9f0d8fbfd0922b5c6a9eaffa69212867359f79e0,
from Qt5 (later discarded in QtQuick1 restructuring of Qt5).
Task-number: QTBUG-20584
Change-Id: Id279907ee90faf19284c12b548467850662a7019
Reviewed-by: Martin Jones <martin.jones@nokia.com>
3 files changed, 66 insertions, 1 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativeflickable.cpp b/src/declarative/graphicsitems/qdeclarativeflickable.cpp index 229d04bd7a..8b07054378 100644 --- a/src/declarative/graphicsitems/qdeclarativeflickable.cpp +++ b/src/declarative/graphicsitems/qdeclarativeflickable.cpp @@ -1582,7 +1582,7 @@ bool QDeclarativeFlickable::sendMouseEvent(QGraphicsSceneMouseEvent *event) bool QDeclarativeFlickable::sceneEventFilter(QGraphicsItem *i, QEvent *e) { Q_D(QDeclarativeFlickable); - 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/qdeclarativeflickable/data/disabled.qml b/tests/auto/declarative/qdeclarativeflickable/data/disabled.qml new file mode 100644 index 0000000000..ac63cd461b --- /dev/null +++ b/tests/auto/declarative/qdeclarativeflickable/data/disabled.qml @@ -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 + } +} diff --git a/tests/auto/declarative/qdeclarativeflickable/tst_qdeclarativeflickable.cpp b/tests/auto/declarative/qdeclarativeflickable/tst_qdeclarativeflickable.cpp index 748760a95b..c248d8cfb0 100644 --- a/tests/auto/declarative/qdeclarativeflickable/tst_qdeclarativeflickable.cpp +++ b/tests/auto/declarative/qdeclarativeflickable/tst_qdeclarativeflickable.cpp @@ -79,6 +79,7 @@ private slots: void testQtQuick11Attributes_data(); void wheel(); void flickVelocity(); + void disabled(); private: QDeclarativeEngine engine; @@ -528,6 +529,40 @@ void tst_qdeclarativeflickable::flick(QGraphicsView *canvas, const QPoint &from, QTest::mouseRelease(canvas->viewport(), Qt::LeftButton, 0, canvas->mapFromScene(to)); } +void tst_qdeclarativeflickable::disabled() +{ + QDeclarativeView *canvas = new QDeclarativeView; + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/disabled.qml")); + canvas->show(); + canvas->setFocus(); + QVERIFY(canvas->rootObject() != 0); + + QDeclarativeFlickable *flick = canvas->rootObject()->findChild<QDeclarativeFlickable*>("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) { |