summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAlberto Mardegan <info@mardy.it>2012-07-05 17:56:51 +0400
committerQt by Nokia <qt-info@nokia.com>2012-07-27 02:27:40 +0200
commit3b64f4d9a4c48f4e9cf19a446c551790f2658278 (patch)
treea8d4caba898c9850bc5c4d46091fb4c1d72a3911 /tests
parent4a6008dfede3c81a055792424cf5a6671e0dc41a (diff)
MouseArea: use current value of drag.axis
If the drag.axis is changed while a drag operation is in progress, put it into action immediately. This allows, for example, start a dragging operation out of an item in a scrollable ListView to anywhere on the screen. See the linked bug number for an example. Task-number: QTBUG-26440 Change-Id: I4ffa71c08b97a767aec7f69d19271000a2631327 Reviewed-by: Rick Stockton <rickstockton@reno-computerhelp.com> Reviewed-by: Andrew den Exter <andrew.den-exter@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/declarative/qdeclarativemousearea/data/changeAxis.qml22
-rw-r--r--tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp79
2 files changed, 101 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativemousearea/data/changeAxis.qml b/tests/auto/declarative/qdeclarativemousearea/data/changeAxis.qml
new file mode 100644
index 00000000..45613b9b
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativemousearea/data/changeAxis.qml
@@ -0,0 +1,22 @@
+import QtQuick 1.0
+Rectangle {
+ id: whiteRect
+ width: 200
+ height: 200
+ color: "white"
+ Rectangle {
+ id: blackRect
+ objectName: "blackrect"
+ color: "black"
+ y: 50
+ x: 50
+ width: 100
+ height: 100
+ MouseArea {
+ objectName: "mouseregion"
+ anchors.fill: parent
+ drag.target: blackRect
+ drag.axis: blackRect.x <= 75 ? Drag.XandYAxis : Drag.YAxis
+ }
+ }
+ }
diff --git a/tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp b/tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp
index 811fcd46..e81e01cb 100644
--- a/tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp
+++ b/tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp
@@ -75,6 +75,7 @@ private slots:
#ifndef QT_NO_CONTEXTMENU
void preventContextMenu();
#endif // QT_NO_CONTEXTMENU
+ void changeAxis();
private:
QDeclarativeView *createView();
@@ -702,6 +703,84 @@ void tst_QDeclarativeMouseArea::preventContextMenu()
}
#endif // QT_NO_CONTEXTMENU
+void tst_QDeclarativeMouseArea::changeAxis()
+{
+ QDeclarativeView *canvas = createView();
+
+ canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/changeAxis.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());
+
+ // Start a diagonal drag
+ 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 moveEvent(QEvent::GraphicsSceneMouseMove);
+ moveEvent.setScenePos(QPointF(111, 111));
+ moveEvent.setButton(Qt::LeftButton);
+ moveEvent.setButtons(Qt::LeftButton);
+ QApplication::sendEvent(scene, &moveEvent);
+
+ moveEvent.setScenePos(QPointF(122, 122));
+ moveEvent.setButton(Qt::LeftButton);
+ moveEvent.setButtons(Qt::LeftButton);
+ QApplication::sendEvent(scene, &moveEvent);
+
+ QVERIFY(drag->active());
+ QCOMPARE(blackRect->x(), 72.0);
+ QCOMPARE(blackRect->y(), 72.0);
+ QCOMPARE(drag->axis(), QDeclarativeDrag::XandYAxis);
+
+ /* When blackRect.x becomes bigger than 75, the drag axis is change to
+ * Drag.YAxis by the QML code. Verify that this happens, and that the drag
+ * movement is effectively constrained to the Y axis. */
+ moveEvent.setScenePos(QPointF(133, 133));
+ moveEvent.setButton(Qt::LeftButton);
+ moveEvent.setButtons(Qt::LeftButton);
+ QApplication::sendEvent(scene, &moveEvent);
+
+ QCOMPARE(blackRect->x(), 83.0);
+ QCOMPARE(blackRect->y(), 83.0);
+ QCOMPARE(drag->axis(), QDeclarativeDrag::YAxis);
+
+ moveEvent.setScenePos(QPointF(144, 144));
+ moveEvent.setButton(Qt::LeftButton);
+ moveEvent.setButtons(Qt::LeftButton);
+ QApplication::sendEvent(scene, &moveEvent);
+
+ QCOMPARE(blackRect->x(), 83.0);
+ QCOMPARE(blackRect->y(), 94.0);
+
+ QGraphicsSceneMouseEvent releaseEvent(QEvent::GraphicsSceneMouseRelease);
+ releaseEvent.setScenePos(QPointF(144, 144));
+ releaseEvent.setButton(Qt::LeftButton);
+ releaseEvent.setButtons(Qt::LeftButton);
+ QApplication::sendEvent(scene, &releaseEvent);
+
+ QVERIFY(!drag->active());
+ QCOMPARE(blackRect->x(), 83.0);
+ QCOMPARE(blackRect->y(), 94.0);
+
+ delete canvas;
+}
+
QTEST_MAIN(tst_QDeclarativeMouseArea)
#include "tst_qdeclarativemousearea.moc"