summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoona Petrell <joona.t.petrell@nokia.com>2010-11-01 02:32:17 (GMT)
committerJoona Petrell <joona.t.petrell@nokia.com>2010-11-01 02:58:20 (GMT)
commitb438b15b8291ce9591fbe0a64fe452383662bbda (patch)
tree82b61cf42f06443ef716d1458c94ea2954951a90
parent95e00f7d712ee51389948a018b27c0d1dde4fa99 (diff)
downloadQt-b438b15b8291ce9591fbe0a64fe452383662bbda.zip
Qt-b438b15b8291ce9591fbe0a64fe452383662bbda.tar.gz
Qt-b438b15b8291ce9591fbe0a64fe452383662bbda.tar.bz2
Quickly clicking an item that doesn't use double clicking should result in two separate clicks
Task-number: QTBUG-14832 Reviewed-by: Martin Jones
-rw-r--r--src/declarative/graphicsitems/qdeclarativemousearea.cpp3
-rw-r--r--tests/auto/declarative/qdeclarativemousearea/data/clicktwice.qml16
-rw-r--r--tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp42
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)