diff options
author | Leonardo Sobral Cunha <leo.cunha@nokia.com> | 2010-04-20 00:56:04 (GMT) |
---|---|---|
committer | Leonardo Sobral Cunha <leo.cunha@nokia.com> | 2010-04-20 01:11:13 (GMT) |
commit | fca7ddd5522f1462192b6c2b4b9e9e5a0f8449d9 (patch) | |
tree | 61c30b5562b53fa5997c05abfb66c248e5082482 /tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp | |
parent | 8efa7be3fd66119753730be643d0882afe329348 (diff) | |
download | Qt-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/tst_qdeclarativemousearea.cpp')
-rw-r--r-- | tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp | 56 |
1 files changed, 56 insertions, 0 deletions
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); |