diff options
3 files changed, 60 insertions, 1 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativemousearea.cpp b/src/declarative/graphicsitems/qdeclarativemousearea.cpp index 1b7dce0..d9edd11 100644 --- a/src/declarative/graphicsitems/qdeclarativemousearea.cpp +++ b/src/declarative/graphicsitems/qdeclarativemousearea.cpp @@ -566,7 +566,8 @@ void QDeclarativeMouseArea::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *even if (!d->absorb) { QDeclarativeItem::mouseDoubleClickEvent(event); } else { - d->doubleClick = true; + if (d->isDoubleClickConnected()) + d->doubleClick = true; d->saveEvent(event); QDeclarativeMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, true, false); me.setAccepted(d->isDoubleClickConnected()); diff --git a/tests/auto/declarative/qdeclarativemousearea/data/clicktwice.qml b/tests/auto/declarative/qdeclarativemousearea/data/clicktwice.qml new file mode 100644 index 0000000..c6b1f89 --- /dev/null +++ b/tests/auto/declarative/qdeclarativemousearea/data/clicktwice.qml @@ -0,0 +1,16 @@ +import QtQuick 1.0 + +Item { + id: root + property int clicked: 0 + property int pressed: 0 + property int released: 0 + + MouseArea { + width: 200; height: 200 + onPressed: { root.pressed++ } + onClicked: { root.clicked++ } + onReleased: { root.released++ } + } +} + diff --git a/tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp b/tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp index 5a50e0d..57a58e9 100644 --- a/tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp +++ b/tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp @@ -63,6 +63,7 @@ private slots: void noOnClickedWithPressAndHold(); void onMousePressRejected(); void doubleClick(); + void clickTwice(); private: QDeclarativeView *createView(); @@ -426,6 +427,47 @@ void tst_QDeclarativeMouseArea::doubleClick() QCOMPARE(canvas->rootObject()->property("clicked").toInt(), 1); QCOMPARE(canvas->rootObject()->property("doubleClicked").toInt(), 1); QCOMPARE(canvas->rootObject()->property("released").toInt(), 2); + +} + +// QTBUG-14832 +void tst_QDeclarativeMouseArea::clickTwice() +{ + QDeclarativeView *canvas = createView(); + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/clicktwice.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); + + QGraphicsSceneMouseEvent releaseEvent(QEvent::GraphicsSceneMouseRelease); + releaseEvent.setScenePos(QPointF(100, 100)); + releaseEvent.setButton(Qt::LeftButton); + releaseEvent.setButtons(Qt::LeftButton); + QApplication::sendEvent(scene, &releaseEvent); + + QCOMPARE(canvas->rootObject()->property("pressed").toInt(), 1); + QCOMPARE(canvas->rootObject()->property("released").toInt(), 1); + QCOMPARE(canvas->rootObject()->property("clicked").toInt(), 1); + + QGraphicsSceneMouseEvent dblClickEvent(QEvent::GraphicsSceneMouseDoubleClick); + dblClickEvent.setScenePos(QPointF(100, 100)); + dblClickEvent.setButton(Qt::LeftButton); + dblClickEvent.setButtons(Qt::LeftButton); + QApplication::sendEvent(scene, &dblClickEvent); + + QApplication::sendEvent(scene, &pressEvent); + QApplication::sendEvent(scene, &releaseEvent); + + QCOMPARE(canvas->rootObject()->property("pressed").toInt(), 2); + QCOMPARE(canvas->rootObject()->property("released").toInt(), 2); + QCOMPARE(canvas->rootObject()->property("clicked").toInt(), 2); } QTEST_MAIN(tst_QDeclarativeMouseArea) |