summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qdeclarativeitem
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/declarative/qdeclarativeitem')
-rw-r--r--tests/auto/declarative/qdeclarativeitem/data/mouseFocus.qml20
-rw-r--r--tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp37
2 files changed, 57 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativeitem/data/mouseFocus.qml b/tests/auto/declarative/qdeclarativeitem/data/mouseFocus.qml
new file mode 100644
index 0000000..a562b8b
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeitem/data/mouseFocus.qml
@@ -0,0 +1,20 @@
+import Qt 4.7
+
+QGraphicsWidget {
+ size: "200x100"
+ focusPolicy: QGraphicsWidget.ClickFocus
+ Item {
+ objectName: "declarativeItem"
+ id: item
+ width: 200
+ height: 100
+ MouseArea {
+ anchors.fill: parent
+ onPressed: {
+ if (!item.focus) {
+ item.focus = true;
+ }
+ }
+ }
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp
index e0ca746..f4edeb2 100644
--- a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp
+++ b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp
@@ -45,6 +45,7 @@
#include <QtDeclarative/qdeclarativecontext.h>
#include <QtDeclarative/qdeclarativeview.h>
#include <QtDeclarative/qdeclarativeitem.h>
+#include "../../../shared/util.h"
class tst_QDeclarativeItem : public QObject
@@ -67,6 +68,7 @@ private slots:
void childrenProperty();
void resourcesProperty();
+ void mouseFocus();
private:
template<typename T>
@@ -466,6 +468,41 @@ void tst_QDeclarativeItem::resourcesProperty()
delete o;
}
+void tst_QDeclarativeItem::mouseFocus()
+{
+ QDeclarativeView *canvas = new QDeclarativeView(0);
+ QVERIFY(canvas);
+ canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/mouseFocus.qml"));
+ canvas->show();
+ QVERIFY(canvas->rootObject());
+ QApplication::setActiveWindow(canvas);
+ QTest::qWaitForWindowShown(canvas);
+ QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(canvas));
+
+ QDeclarativeItem *item = findItem<QDeclarativeItem>(canvas->rootObject(), "declarativeItem");
+ QVERIFY(item);
+ QSignalSpy focusSpy(item, SIGNAL(focusChanged(bool)));
+
+ QTest::mouseClick(canvas->viewport(), Qt::LeftButton, 0, canvas->mapFromScene(item->scenePos()));
+ QApplication::processEvents();
+ QCOMPARE(focusSpy.count(), 1);
+ QVERIFY(item->hasFocus());
+
+ // make sure focusable graphics widget underneath does not steal focus
+ QTest::mouseClick(canvas->viewport(), Qt::LeftButton, 0, canvas->mapFromScene(item->scenePos()));
+ QApplication::processEvents();
+ QCOMPARE(focusSpy.count(), 1);
+ QVERIFY(item->hasFocus());
+
+ item->setFocus(false);
+ QVERIFY(!item->hasFocus());
+ QCOMPARE(focusSpy.count(), 2);
+ item->setFocus(true);
+ QCOMPARE(focusSpy.count(), 3);
+
+ delete canvas;
+}
+
void tst_QDeclarativeItem::propertyChanges()
{
QDeclarativeView *canvas = new QDeclarativeView(0);