From: Liang Qi Date: Tue, 9 Apr 2013 10:09:24 +0000 (+0200) Subject: Added more tests for activeFocusOnTab X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=8190355557c13bba836cef49585556f0c823f672;p=konrad%2Fqtdeclarative.git Added more tests for activeFocusOnTab The ignored key events will go to parent. Change-Id: I5e002ee9df44d1c7865c1c50a1631e8e206c68af Reviewed-by: Alan Alpert (Personal) <416365416c@gmail.com> --- diff --git a/tests/auto/quick/qquickitem2/data/activeFocusOnTab4.qml b/tests/auto/quick/qquickitem2/data/activeFocusOnTab4.qml new file mode 100644 index 0000000..0c85862 --- /dev/null +++ b/tests/auto/quick/qquickitem2/data/activeFocusOnTab4.qml @@ -0,0 +1,56 @@ +import QtQuick 2.1 + +Item { + id: main + objectName: "main" + width: 800 + height: 600 + focus: true + Component.onCompleted: button11.focus = true + Item { + id: sub1 + objectName: "sub1" + width: 230 + height: 600 + activeFocusOnTab: false + anchors.top: parent.top + anchors.left: parent.left + Item { + id: button11 + objectName: "button11" + width: 100 + height: 50 + activeFocusOnTab: false + Rectangle { + anchors.fill: parent + color: parent.activeFocus ? "red" : "black" + } + + anchors.top: parent.top + anchors.topMargin: 100 + } + } + Item { + id: sub2 + objectName: "sub2" + activeFocusOnTab: false + width: 230 + height: 600 + anchors.top: parent.top + anchors.left: sub1.right + Item { + id: button21 + objectName: "button21" + width: 100 + height: 50 + activeFocusOnTab: true + Rectangle { + anchors.fill: parent + color: parent.activeFocus ? "red" : "black" + } + + anchors.top: parent.top + anchors.topMargin: 100 + } + } +} diff --git a/tests/auto/quick/qquickitem2/tst_qquickitem.cpp b/tests/auto/quick/qquickitem2/tst_qquickitem.cpp index 668b5e2..f2d25e8 100644 --- a/tests/auto/quick/qquickitem2/tst_qquickitem.cpp +++ b/tests/auto/quick/qquickitem2/tst_qquickitem.cpp @@ -67,6 +67,8 @@ private slots: void activeFocusOnTab(); void activeFocusOnTab2(); void activeFocusOnTab3(); + void activeFocusOnTab4(); + void activeFocusOnTab5(); void keys(); void keysProcessingOrder(); @@ -602,6 +604,66 @@ void tst_QQuickItem::activeFocusOnTab3() delete window; } +void tst_QQuickItem::activeFocusOnTab4() +{ + QQuickView *window = new QQuickView(0); + window->setBaseSize(QSize(800,600)); + + window->setSource(testFileUrl("activeFocusOnTab4.qml")); + window->show(); + window->requestActivate(); + QVERIFY(QTest::qWaitForWindowActive(window)); + QVERIFY(QGuiApplication::focusWindow() == window); + + // original: button11 + QQuickItem *item = findItem(window->rootObject(), "button11"); + item->setActiveFocusOnTab(true); + QVERIFY(item); + QVERIFY(item->hasActiveFocus()); + + // Tab: button11->button21 + QKeyEvent key(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier, "", false, 1); + QGuiApplication::sendEvent(window, &key); + QVERIFY(key.isAccepted()); + + item = findItem(window->rootObject(), "button21"); + QVERIFY(item); + QVERIFY(item->hasActiveFocus()); + + delete window; +} + +void tst_QQuickItem::activeFocusOnTab5() +{ + QQuickView *window = new QQuickView(0); + window->setBaseSize(QSize(800,600)); + + window->setSource(testFileUrl("activeFocusOnTab4.qml")); + window->show(); + window->requestActivate(); + QVERIFY(QTest::qWaitForWindowActive(window)); + QVERIFY(QGuiApplication::focusWindow() == window); + + // original: button11 in sub1 + QQuickItem *item = findItem(window->rootObject(), "button11"); + QVERIFY(item); + QVERIFY(item->hasActiveFocus()); + + QQuickItem *item2 = findItem(window->rootObject(), "sub1"); + item2->setActiveFocusOnTab(true); + + // Tab: button11->button21 + QKeyEvent key(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier, "", false, 1); + QGuiApplication::sendEvent(window, &key); + QVERIFY(key.isAccepted()); + + item = findItem(window->rootObject(), "button21"); + QVERIFY(item); + QVERIFY(item->hasActiveFocus()); + + delete window; +} + void tst_QQuickItem::keys() { QQuickView *window = new QQuickView(0);