summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2010-04-07 01:56:07 (GMT)
committerMartin Jones <martin.jones@nokia.com>2010-04-07 01:56:07 (GMT)
commit9c4140af1cbc650905de698daa4ab0183efba477 (patch)
tree2c59269f67505831e0dc574f23f8f1919e485383 /tests/auto
parent173c1194f3fc35ba7249c30e3e99bd975dcdcc64 (diff)
downloadQt-9c4140af1cbc650905de698daa4ab0183efba477.zip
Qt-9c4140af1cbc650905de698daa4ab0183efba477.tar.gz
Qt-9c4140af1cbc650905de698daa4ab0183efba477.tar.bz2
Allow MouseArea.Drag.target to be reset.
Task-number: QTBUG-9637
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/declarative/qdeclarativemousearea/data/dragreset.qml28
-rw-r--r--tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp45
2 files changed, 67 insertions, 6 deletions
diff --git a/tests/auto/declarative/qdeclarativemousearea/data/dragreset.qml b/tests/auto/declarative/qdeclarativemousearea/data/dragreset.qml
new file mode 100644
index 0000000..4bfb9c3
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativemousearea/data/dragreset.qml
@@ -0,0 +1,28 @@
+import Qt 4.6
+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: haveTarget ? blackRect : undefined
+ 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 9b664e5..dfe46e4 100644
--- a/tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp
+++ b/tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp
@@ -44,20 +44,23 @@
#include <private/qdeclarativemousearea_p.h>
#include <private/qdeclarativerectangle_p.h>
#include <QtDeclarative/qdeclarativeview.h>
+#include <QtDeclarative/qdeclarativecontext.h>
class tst_QDeclarativeMouseArea: public QObject
{
Q_OBJECT
private slots:
void dragProperties();
+ void resetDrag();
void updateMouseAreaPosOnClick();
private:
- QDeclarativeView *createView(const QString &filename);
+ QDeclarativeView *createView();
};
void tst_QDeclarativeMouseArea::dragProperties()
{
- QDeclarativeView *canvas = createView(SRCDIR "/data/dragproperties.qml");
+ QDeclarativeView *canvas = createView();
+ canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/dragproperties.qml"));
canvas->show();
canvas->setFocus();
QVERIFY(canvas->rootObject() != 0);
@@ -127,19 +130,49 @@ void tst_QDeclarativeMouseArea::dragProperties()
delete canvas;
}
-QDeclarativeView *tst_QDeclarativeMouseArea::createView(const QString &filename)
+void tst_QDeclarativeMouseArea::resetDrag()
+{
+ QDeclarativeView *canvas = createView();
+
+ canvas->rootContext()->setContextProperty("haveTarget", QVariant(true));
+ canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/dragreset.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());
+ QDeclarativeItem *rootItem = qobject_cast<QDeclarativeItem*>(canvas->rootObject());
+ QVERIFY(rootItem != 0);
+ QSignalSpy targetSpy(drag, SIGNAL(targetChanged()));
+ QVERIFY(drag->target() != 0);
+ canvas->rootContext()->setContextProperty("haveTarget", QVariant(false));
+ QCOMPARE(targetSpy.count(),1);
+ QVERIFY(drag->target() == 0);
+
+ delete canvas;
+}
+
+
+QDeclarativeView *tst_QDeclarativeMouseArea::createView()
{
QDeclarativeView *canvas = new QDeclarativeView(0);
canvas->setFixedSize(240,320);
- canvas->setSource(QUrl::fromLocalFile(filename));
-
return canvas;
}
void tst_QDeclarativeMouseArea::updateMouseAreaPosOnClick()
{
- QDeclarativeView *canvas = createView(SRCDIR "/data/updateMousePosOnClick.qml");
+ QDeclarativeView *canvas = createView();
+ canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/updateMousePosOnClick.qml"));
canvas->show();
canvas->setFocus();
QVERIFY(canvas->rootObject() != 0);