summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2011-01-24 23:30:45 (GMT)
committerMichael Brasser <michael.brasser@nokia.com>2011-01-25 00:41:05 (GMT)
commitb36859acae472916c35ac31174c8230543d900ab (patch)
treec57eb42b3eb8be9d0c11df6dd0dacb30f7c72024
parent4768e23056691ee14a91e1f2cf258e8f51847aaf (diff)
downloadQt-b36859acae472916c35ac31174c8230543d900ab.zip
Qt-b36859acae472916c35ac31174c8230543d900ab.tar.gz
Qt-b36859acae472916c35ac31174c8230543d900ab.tar.bz2
Notify that pressed has changed before calling the onClicked handler.
This is a more natural ordering, and makes it trivial to control different state groups with pressed and onClicked. Reviewed-by: Martin Jones
-rw-r--r--src/declarative/graphicsitems/qdeclarativemousearea.cpp3
-rw-r--r--tests/auto/declarative/qdeclarativemousearea/data/pressedOrdering.qml28
-rw-r--r--tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp35
3 files changed, 65 insertions, 1 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativemousearea.cpp b/src/declarative/graphicsitems/qdeclarativemousearea.cpp
index ee6765c..273fc53 100644
--- a/src/declarative/graphicsitems/qdeclarativemousearea.cpp
+++ b/src/declarative/graphicsitems/qdeclarativemousearea.cpp
@@ -863,15 +863,16 @@ bool QDeclarativeMouseArea::setPressed(bool p)
me.setX(d->lastPos.x());
me.setY(d->lastPos.y());
emit mousePositionChanged(&me);
+ emit pressedChanged();
} else {
emit released(&me);
me.setX(d->lastPos.x());
me.setY(d->lastPos.y());
+ emit pressedChanged();
if (isclick && !d->longPress && !d->doubleClick)
emit clicked(&me);
}
- emit pressedChanged();
return me.isAccepted();
}
return false;
diff --git a/tests/auto/declarative/qdeclarativemousearea/data/pressedOrdering.qml b/tests/auto/declarative/qdeclarativemousearea/data/pressedOrdering.qml
new file mode 100644
index 0000000..4a80e83
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativemousearea/data/pressedOrdering.qml
@@ -0,0 +1,28 @@
+import QtQuick 1.0
+
+Item {
+ id: root
+ property string value: "base"
+
+ MouseArea {
+ id: mouseArea
+ width: 200; height: 200
+ onClicked: toggleState.state = "toggled"
+ }
+
+ StateGroup {
+ states: State {
+ name: "pressed"
+ when: mouseArea.pressed
+ PropertyChanges { target: root; value: "pressed" }
+ }
+ }
+
+ StateGroup {
+ id: toggleState
+ states: State {
+ name: "toggled"
+ PropertyChanges { target: root; value: "toggled" }
+ }
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp b/tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp
index 9d7cc05..845d6bb 100644
--- a/tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp
+++ b/tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp
@@ -64,6 +64,7 @@ private slots:
void onMousePressRejected();
void doubleClick();
void clickTwice();
+ void pressedOrdering();
private:
QDeclarativeView *createView();
@@ -477,6 +478,40 @@ void tst_QDeclarativeMouseArea::clickTwice()
QCOMPARE(canvas->rootObject()->property("clicked").toInt(), 2);
}
+void tst_QDeclarativeMouseArea::pressedOrdering()
+{
+ QDeclarativeView *canvas = createView();
+ canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/pressedOrdering.qml"));
+ canvas->show();
+ canvas->setFocus();
+ QVERIFY(canvas->rootObject() != 0);
+
+ QCOMPARE(canvas->rootObject()->property("value").toString(), QLatin1String("base"));
+
+ 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);
+
+ QCOMPARE(canvas->rootObject()->property("value").toString(), QLatin1String("pressed"));
+
+ 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("value").toString(), QLatin1String("toggled"));
+
+ QApplication::sendEvent(scene, &pressEvent);
+
+ QCOMPARE(canvas->rootObject()->property("value").toString(), QLatin1String("pressed"));
+
+ delete canvas;
+}
+
QTEST_MAIN(tst_QDeclarativeMouseArea)
#include "tst_qdeclarativemousearea.moc"