summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qdeclarativemousearea
diff options
context:
space:
mode:
authorLeonardo Sobral Cunha <leo.cunha@nokia.com>2010-04-16 06:50:27 (GMT)
committerLeonardo Sobral Cunha <leo.cunha@nokia.com>2010-04-19 00:20:18 (GMT)
commit5efb732bc78e15605ac9d9f770e1bd24c01bb778 (patch)
tree952639777368bcdfd444415d9890cf1403d0ec3b /tests/auto/declarative/qdeclarativemousearea
parent465f4df8ad4be9485c37ecc379c45e758b2842ad (diff)
downloadQt-5efb732bc78e15605ac9d9f770e1bd24c01bb778.zip
Qt-5efb732bc78e15605ac9d9f770e1bd24c01bb778.tar.gz
Qt-5efb732bc78e15605ac9d9f770e1bd24c01bb778.tar.bz2
Update mouse area coordinates automatically when changing position
Mouse area coordinates are now updated when the mouse area changes position and positionChanged signals are not emitted on mousePress anymore (only mousePosChanged signals). Task-number: QTBUG-9716 Reviewed-by: Michael Brasser
Diffstat (limited to 'tests/auto/declarative/qdeclarativemousearea')
-rw-r--r--tests/auto/declarative/qdeclarativemousearea/data/updateMousePosOnResize.qml38
-rw-r--r--tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp41
2 files changed, 79 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativemousearea/data/updateMousePosOnResize.qml b/tests/auto/declarative/qdeclarativemousearea/data/updateMousePosOnResize.qml
new file mode 100644
index 0000000..138c25a
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativemousearea/data/updateMousePosOnResize.qml
@@ -0,0 +1,38 @@
+import Qt 4.6
+
+Rectangle {
+ color: "#ffffff"
+ width: 320; height: 240
+ Rectangle {
+ id: brother
+ objectName: "brother"
+ color: "lightgreen"
+ x: 200; y: 100
+ width: 120; height: 120
+ }
+ MouseArea {
+ id: mouseRegion
+ objectName: "mouseregion"
+
+ property int x1
+ property int y1
+ property int x2
+ property int y2
+ property bool emitPositionChanged: false
+ property bool mouseMatchesPos: true
+
+ anchors.fill: brother
+ onPressed: {
+ if (mouse.x != mouseX || mouse.y != mouseY)
+ mouseMatchesPos = false
+ x1 = mouseX; y1 = mouseY
+ anchors.fill = parent
+ }
+ onPositionChanged: { emitPositionChanged = true }
+ onMousePosChanged: {
+ if (mouse.x != mouseX || mouse.y != mouseY)
+ mouseMatchesPos = false
+ x2 = mouseX; y2 = mouseY
+ }
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp b/tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp
index bdb8eca..4a58049 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 updateMouseAreaPosOnResize();
void noOnClickedWithPressAndHold();
private:
QDeclarativeView *createView();
@@ -203,6 +204,46 @@ void tst_QDeclarativeMouseArea::updateMouseAreaPosOnClick()
delete canvas;
}
+void tst_QDeclarativeMouseArea::updateMouseAreaPosOnResize()
+{
+ QDeclarativeView *canvas = createView();
+ canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/updateMousePosOnResize.qml"));
+ canvas->show();
+ canvas->setFocus();
+ QVERIFY(canvas->rootObject() != 0);
+
+ QDeclarativeMouseArea *mouseRegion = canvas->rootObject()->findChild<QDeclarativeMouseArea*>("mouseregion");
+ QVERIFY(mouseRegion != 0);
+
+ QDeclarativeRectangle *rect = canvas->rootObject()->findChild<QDeclarativeRectangle*>("brother");
+ QVERIFY(rect != 0);
+
+ QCOMPARE(mouseRegion->mouseX(), 0.0);
+ QCOMPARE(mouseRegion->mouseY(), 0.0);
+
+ QGraphicsScene *scene = canvas->scene();
+ QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress);
+ event.setScenePos(rect->pos());
+ event.setButton(Qt::LeftButton);
+ event.setButtons(Qt::LeftButton);
+ QApplication::sendEvent(scene, &event);
+
+ QVERIFY(!mouseRegion->property("emitPositionChanged").toBool());
+ QVERIFY(mouseRegion->property("mouseMatchesPos").toBool());
+
+ QCOMPARE(mouseRegion->property("x1").toInt(), 0);
+ QCOMPARE(mouseRegion->property("y1").toInt(), 0);
+
+ // XXX: is it on purpose that mouseX is real and mouse.x is int?
+ QCOMPARE(mouseRegion->property("x2").toInt(), (int) rect->x());
+ QCOMPARE(mouseRegion->property("y2").toInt(), (int) rect->y());
+
+ QCOMPARE(mouseRegion->mouseX(), rect->x());
+ QCOMPARE(mouseRegion->mouseY(), rect->y());
+
+ delete canvas;
+}
+
void tst_QDeclarativeMouseArea::noOnClickedWithPressAndHold()
{
QDeclarativeView *canvas = createView();