summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qdeclarativemousearea
diff options
context:
space:
mode:
authorLeonardo Sobral Cunha <leo.cunha@nokia.com>2010-04-20 00:56:04 (GMT)
committerLeonardo Sobral Cunha <leo.cunha@nokia.com>2010-04-20 01:11:13 (GMT)
commitfca7ddd5522f1462192b6c2b4b9e9e5a0f8449d9 (patch)
tree61c30b5562b53fa5997c05abfb66c248e5082482 /tests/auto/declarative/qdeclarativemousearea
parent8efa7be3fd66119753730be643d0882afe329348 (diff)
downloadQt-fca7ddd5522f1462192b6c2b4b9e9e5a0f8449d9.zip
Qt-fca7ddd5522f1462192b6c2b4b9e9e5a0f8449d9.tar.gz
Qt-fca7ddd5522f1462192b6c2b4b9e9e5a0f8449d9.tar.bz2
Add drag.active property to MouseArea in qml
The drag.active property specifies if the target item is being dragged. Task-number: QTBUG-9833 Reviewed-by: Martin Jones
Diffstat (limited to 'tests/auto/declarative/qdeclarativemousearea')
-rw-r--r--tests/auto/declarative/qdeclarativemousearea/data/dragging.qml28
-rw-r--r--tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp56
2 files changed, 84 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativemousearea/data/dragging.qml b/tests/auto/declarative/qdeclarativemousearea/data/dragging.qml
new file mode 100644
index 0000000..a28f049
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativemousearea/data/dragging.qml
@@ -0,0 +1,28 @@
+import Qt 4.7
+Rectangle {
+ id: whiteRect
+ width: 200
+ height: 200
+ color: "white"
+ Rectangle {
+ id: blackRect
+ objectName: "blackrect"
+ color: "black"
+ y: 50
+ x: 50
+ width: 100
+ height: 100
+ opacity: (whiteRect.width-blackRect.x+whiteRect.height-blackRect.y-199)/200
+ Text { text: blackRect.opacity}
+ MouseArea {
+ objectName: "mouseregion"
+ anchors.fill: parent
+ drag.target: blackRect
+ drag.axis: Drag.XandYAxis
+ drag.minimumX: 0
+ drag.maximumX: whiteRect.width-blackRect.width
+ drag.minimumY: 0
+ drag.maximumY: whiteRect.height-blackRect.height
+ }
+ }
+ }
diff --git a/tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp b/tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp
index 4a58049..eb4aa12 100644
--- a/tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp
+++ b/tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp
@@ -52,6 +52,7 @@ class tst_QDeclarativeMouseArea: public QObject
private slots:
void dragProperties();
void resetDrag();
+ void dragging();
void updateMouseAreaPosOnClick();
void updateMouseAreaPosOnResize();
void noOnClickedWithPressAndHold();
@@ -163,6 +164,61 @@ void tst_QDeclarativeMouseArea::resetDrag()
}
+void tst_QDeclarativeMouseArea::dragging()
+{
+ QDeclarativeView *canvas = createView();
+
+ canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/dragging.qml"));
+ canvas->show();
+ canvas->setFocus();
+ QVERIFY(canvas->rootObject() != 0);
+
+ QDeclarativeMouseArea *mouseRegion = canvas->rootObject()->findChild<QDeclarativeMouseArea*>("mouseregion");
+ QDeclarativeDrag *drag = mouseRegion->drag();
+ QVERIFY(mouseRegion != 0);
+ QVERIFY(drag != 0);
+
+ // target
+ QDeclarativeItem *blackRect = canvas->rootObject()->findChild<QDeclarativeItem*>("blackrect");
+ QVERIFY(blackRect != 0);
+ QVERIFY(blackRect == drag->target());
+
+ QVERIFY(!drag->active());
+
+ 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(!drag->active());
+ QCOMPARE(blackRect->x(), 50.0);
+ QCOMPARE(blackRect->y(), 50.0);
+
+ QGraphicsSceneMouseEvent moveEvent(QEvent::GraphicsSceneMouseMove);
+ moveEvent.setScenePos(QPointF(110, 110));
+ moveEvent.setButton(Qt::LeftButton);
+ moveEvent.setButtons(Qt::LeftButton);
+ QApplication::sendEvent(scene, &moveEvent);
+
+ QVERIFY(drag->active());
+ QCOMPARE(blackRect->x(), 60.0);
+ QCOMPARE(blackRect->y(), 60.0);
+
+ QGraphicsSceneMouseEvent releaseEvent(QEvent::GraphicsSceneMouseRelease);
+ releaseEvent.setScenePos(QPointF(110, 110));
+ releaseEvent.setButton(Qt::LeftButton);
+ releaseEvent.setButtons(Qt::LeftButton);
+ QApplication::sendEvent(scene, &releaseEvent);
+
+ QVERIFY(!drag->active());
+ QCOMPARE(blackRect->x(), 60.0);
+ QCOMPARE(blackRect->y(), 60.0);
+
+ delete canvas;
+}
+
QDeclarativeView *tst_QDeclarativeMouseArea::createView()
{
QDeclarativeView *canvas = new QDeclarativeView(0);