From 198377b456c494272e9a73a872478c5d5ae94af4 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 8 Apr 2010 11:16:49 +1000 Subject: Don't emit clicked() after pressAndHold() Task-number: QTBUG-9676 --- .../graphicsitems/qdeclarativemousearea.cpp | 2 +- .../qdeclarativemousearea/data/clickandhold.qml | 13 +++++++++ .../tst_qdeclarativemousearea.cpp | 31 ++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 tests/auto/declarative/qdeclarativemousearea/data/clickandhold.qml diff --git a/src/declarative/graphicsitems/qdeclarativemousearea.cpp b/src/declarative/graphicsitems/qdeclarativemousearea.cpp index c95bd29..a6cc75e 100644 --- a/src/declarative/graphicsitems/qdeclarativemousearea.cpp +++ b/src/declarative/graphicsitems/qdeclarativemousearea.cpp @@ -651,7 +651,7 @@ bool QDeclarativeMouseArea::setPressed(bool p) emit positionChanged(&me); } else { emit released(&me); - if (isclick) + if (isclick && !d->longPress) emit clicked(&me); } diff --git a/tests/auto/declarative/qdeclarativemousearea/data/clickandhold.qml b/tests/auto/declarative/qdeclarativemousearea/data/clickandhold.qml new file mode 100644 index 0000000..e800f98 --- /dev/null +++ b/tests/auto/declarative/qdeclarativemousearea/data/clickandhold.qml @@ -0,0 +1,13 @@ +import Qt 4.6 + +Item { + id: root + property bool clicked: false + property bool held: false + + MouseArea { + width: 200; height: 200 + onClicked: { root.clicked = true } + onPressAndHold: { root.held = true } + } +} diff --git a/tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp b/tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp index dfe46e4..bdb8eca 100644 --- a/tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp +++ b/tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp @@ -53,6 +53,7 @@ private slots: void dragProperties(); void resetDrag(); void updateMouseAreaPosOnClick(); + void noOnClickedWithPressAndHold(); private: QDeclarativeView *createView(); }; @@ -202,6 +203,36 @@ void tst_QDeclarativeMouseArea::updateMouseAreaPosOnClick() delete canvas; } +void tst_QDeclarativeMouseArea::noOnClickedWithPressAndHold() +{ + QDeclarativeView *canvas = createView(); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/clickandhold.qml")); + canvas->show(); + canvas->setFocus(); + QVERIFY(canvas->rootObject() != 0); + + QGraphicsScene *scene = canvas->scene(); + QGraphicsSceneMouseEvent pressEvent(QEvent::GraphicsSceneMousePress); + pressEvent.setScenePos(QPointF(100, 100)); + pressEvent.setButton(Qt::LeftButton); + pressEvent.setButtons(Qt::LeftButton); + QApplication::sendEvent(scene, &pressEvent); + + QVERIFY(!canvas->rootObject()->property("clicked").toBool()); + QVERIFY(!canvas->rootObject()->property("held").toBool()); + + QTest::qWait(1000); + + QGraphicsSceneMouseEvent releaseEvent(QEvent::GraphicsSceneMousePress); + releaseEvent.setScenePos(QPointF(100, 100)); + releaseEvent.setButton(Qt::LeftButton); + releaseEvent.setButtons(Qt::LeftButton); + QApplication::sendEvent(scene, &releaseEvent); + + QVERIFY(!canvas->rootObject()->property("clicked").toBool()); + QVERIFY(canvas->rootObject()->property("held").toBool()); +} + QTEST_MAIN(tst_QDeclarativeMouseArea) #include "tst_qdeclarativemousearea.moc" -- cgit v0.12