diff options
author | Frederik Gladhorn <frederik.gladhorn@digia.com> | 2014-05-09 16:25:58 +0200 |
---|---|---|
committer | Gunnar Sletta <gunnar.sletta@jollamobile.com> | 2014-05-10 11:53:47 +0200 |
commit | 66646dd8c37adb488a79ab274b2396a649674e6d (patch) | |
tree | b0f5ac752a52cec3de1d47692e09295197622dcd /tests/auto/quick/qquickitem2 | |
parent | da15ea0f3b5805db657f13060c21efa78f10cde2 (diff) | |
parent | d82a17b929dd88fe76258b0f801beaa1b2ee343e (diff) |
Merge remote-tracking branch 'origin/stable' into dev
Conflicts:
.qmake.conf
src/plugins/accessible/quick/quick.pro
src/quick/items/qquickpincharea.cpp
src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp
src/quick/scenegraph/qsgthreadedrenderloop.cpp
Manually adjusted for TestHTTPServer constructor change:
tests/auto/quick/qquickimage/tst_qquickimage.cpp
Change-Id: I5e58a7c08ea92d6fc5e3bce98571c54f7b2ce08f
Diffstat (limited to 'tests/auto/quick/qquickitem2')
-rw-r--r-- | tests/auto/quick/qquickitem2/data/activeFocusOnTab9.qml | 50 | ||||
-rw-r--r-- | tests/auto/quick/qquickitem2/data/keysforward.qml | 84 | ||||
-rw-r--r-- | tests/auto/quick/qquickitem2/tst_qquickitem.cpp | 209 |
3 files changed, 343 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickitem2/data/activeFocusOnTab9.qml b/tests/auto/quick/qquickitem2/data/activeFocusOnTab9.qml new file mode 100644 index 0000000000..09bb73639a --- /dev/null +++ b/tests/auto/quick/qquickitem2/data/activeFocusOnTab9.qml @@ -0,0 +1,50 @@ +import QtQuick 2.1 + +Item { + id: main + objectName: "main" + width: 300 + height: 300 + TextInput { + id: textinput1 + objectName: "textinput1" + width: 300 + height: 75 + activeFocusOnTab: true + text: "Text Input 1" + anchors.top: parent.top + anchors.left: parent.left + } + TextInput { + id: textinput2 + objectName: "textinput2" + width: 300 + height: 75 + activeFocusOnTab: true + text: "Text Input 2" + readOnly: true + anchors.top: textinput1.bottom + anchors.left: parent.left + } + TextEdit { + id: textedit1 + objectName: "textedit1" + width: 300 + height: 75 + activeFocusOnTab: true + text: "Text Edit 1" + anchors.top: textinput2.bottom + anchors.left: parent.left + } + TextEdit { + id: textedit2 + objectName: "textedit2" + width: 300 + height: 75 + activeFocusOnTab: true + text: "Text Edit 2" + readOnly: true + anchors.top: textedit1.bottom + anchors.left: parent.left + } +} diff --git a/tests/auto/quick/qquickitem2/data/keysforward.qml b/tests/auto/quick/qquickitem2/data/keysforward.qml new file mode 100644 index 0000000000..f0cb4d9508 --- /dev/null +++ b/tests/auto/quick/qquickitem2/data/keysforward.qml @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Item { + id: root + + property alias source: source + property alias primaryTarget: primaryTarget + property alias secondaryTarget: secondaryTarget + + property var pressedKeys: [] + property var releasedKeys: [] + Keys.onPressed: { var keys = pressedKeys; keys.push(event.key); pressedKeys = keys } + Keys.onReleased: { var keys = releasedKeys; keys.push(event.key); releasedKeys = keys } + + Item { + id: primaryTarget + objectName: "primary" + property var pressedKeys: [] + property var releasedKeys: [] + Keys.forwardTo: secondaryTarget + Keys.onPressed: { event.accepted = event.key === Qt.Key_P; var keys = pressedKeys; keys.push(event.key); pressedKeys = keys } + Keys.onReleased: { event.accepted = event.key === Qt.Key_P; var keys = releasedKeys; keys.push(event.key); releasedKeys = keys } + + Item { + id: source + objectName: "source" + property var pressedKeys: [] + property var releasedKeys: [] + Keys.forwardTo: primaryTarget + Keys.onPressed: { var keys = pressedKeys; keys.push(event.key); pressedKeys = keys } + Keys.onReleased: { var keys = releasedKeys; keys.push(event.key); releasedKeys = keys } + } + } + + Item { + id: secondaryTarget + objectName: "secondary" + property var pressedKeys: [] + property var releasedKeys: [] + Keys.onPressed: { event.accepted = event.key === Qt.Key_S; var keys = pressedKeys; keys.push(event.key); pressedKeys = keys } + Keys.onReleased: { event.accepted = event.key === Qt.Key_S; var keys = releasedKeys; keys.push(event.key); releasedKeys = keys } + } +} diff --git a/tests/auto/quick/qquickitem2/tst_qquickitem.cpp b/tests/auto/quick/qquickitem2/tst_qquickitem.cpp index 10f4aa2c83..9d2188253a 100644 --- a/tests/auto/quick/qquickitem2/tst_qquickitem.cpp +++ b/tests/auto/quick/qquickitem2/tst_qquickitem.cpp @@ -73,6 +73,8 @@ private slots: void activeFocusOnTab6(); void activeFocusOnTab7(); void activeFocusOnTab8(); + void activeFocusOnTab9(); + void activeFocusOnTab10(); void nextItemInFocusChain(); void nextItemInFocusChain2(); @@ -83,6 +85,7 @@ private slots: void standardKeys(); void keysProcessingOrder(); void keysim(); + void keysForward(); void keyNavigation_data(); void keyNavigation(); void keyNavigation_RightToLeft(); @@ -856,6 +859,140 @@ void tst_QQuickItem::activeFocusOnTab8() delete window; } +void tst_QQuickItem::activeFocusOnTab9() +{ + if (qt_tab_all_widgets()) + QSKIP("This function doesn't support iterating all."); + + QQuickView *window = new QQuickView(0); + window->setBaseSize(QSize(300,300)); + + window->setSource(testFileUrl("activeFocusOnTab9.qml")); + window->show(); + window->requestActivate(); + QVERIFY(QTest::qWaitForWindowActive(window)); + QVERIFY(QGuiApplication::focusWindow() == window); + + QQuickItem *content = window->contentItem(); + QVERIFY(content); + QVERIFY(content->hasActiveFocus()); + + QQuickItem *textinput1 = findItem<QQuickItem>(window->rootObject(), "textinput1"); + QVERIFY(textinput1); + QQuickItem *textedit1 = findItem<QQuickItem>(window->rootObject(), "textedit1"); + QVERIFY(textedit1); + + QVERIFY(!textinput1->hasActiveFocus()); + textinput1->forceActiveFocus(); + QVERIFY(textinput1->hasActiveFocus()); + + // Tab: textinput1->textedit1 + QKeyEvent key(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier, "", false, 1); + QGuiApplication::sendEvent(window, &key); + QVERIFY(key.isAccepted()); + + QVERIFY(textedit1->hasActiveFocus()); + + // BackTab: textedit1->textinput1 + key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1); + QGuiApplication::sendEvent(window, &key); + QVERIFY(key.isAccepted()); + + QVERIFY(textinput1->hasActiveFocus()); + + // BackTab: textinput1->textedit1 + key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1); + QGuiApplication::sendEvent(window, &key); + QVERIFY(key.isAccepted()); + + QVERIFY(textedit1->hasActiveFocus()); + + delete window; +} + +void tst_QQuickItem::activeFocusOnTab10() +{ + if (!qt_tab_all_widgets()) + QSKIP("This function doesn't support NOT iterating all."); + + QQuickView *window = new QQuickView(0); + window->setBaseSize(QSize(300,300)); + + window->setSource(testFileUrl("activeFocusOnTab9.qml")); + window->show(); + window->requestActivate(); + QVERIFY(QTest::qWaitForWindowActive(window)); + QVERIFY(QGuiApplication::focusWindow() == window); + + QQuickItem *content = window->contentItem(); + QVERIFY(content); + QVERIFY(content->hasActiveFocus()); + + QQuickItem *textinput1 = findItem<QQuickItem>(window->rootObject(), "textinput1"); + QVERIFY(textinput1); + QQuickItem *textedit1 = findItem<QQuickItem>(window->rootObject(), "textedit1"); + QVERIFY(textedit1); + QQuickItem *textinput2 = findItem<QQuickItem>(window->rootObject(), "textinput2"); + QVERIFY(textinput2); + QQuickItem *textedit2 = findItem<QQuickItem>(window->rootObject(), "textedit2"); + QVERIFY(textedit2); + + QVERIFY(!textinput1->hasActiveFocus()); + textinput1->forceActiveFocus(); + QVERIFY(textinput1->hasActiveFocus()); + + // Tab: textinput1->textinput2 + QKeyEvent key(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier, "", false, 1); + QGuiApplication::sendEvent(window, &key); + QVERIFY(key.isAccepted()); + + QVERIFY(textinput2->hasActiveFocus()); + + // Tab: textinput2->textedit1 + key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier, "", false, 1); + QGuiApplication::sendEvent(window, &key); + QVERIFY(key.isAccepted()); + + QVERIFY(textedit1->hasActiveFocus()); + + // BackTab: textedit1->textinput2 + key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1); + QGuiApplication::sendEvent(window, &key); + QVERIFY(key.isAccepted()); + + QVERIFY(textinput2->hasActiveFocus()); + + // BackTab: textinput2->textinput1 + key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1); + QGuiApplication::sendEvent(window, &key); + QVERIFY(key.isAccepted()); + + QVERIFY(textinput1->hasActiveFocus()); + + // BackTab: textinput1->textedit2 + key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1); + QGuiApplication::sendEvent(window, &key); + QVERIFY(key.isAccepted()); + + QVERIFY(textedit2->hasActiveFocus()); + + // BackTab: textedit2->textedit1 + key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1); + QGuiApplication::sendEvent(window, &key); + QVERIFY(key.isAccepted()); + + QVERIFY(textedit1->hasActiveFocus()); + + // BackTab: textedit1->textinput2 + key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1); + QGuiApplication::sendEvent(window, &key); + QVERIFY(key.isAccepted()); + + QVERIFY(textinput2->hasActiveFocus()); + + delete window; +} + void tst_QQuickItem::nextItemInFocusChain() { if (!qt_tab_all_widgets()) @@ -1268,6 +1405,78 @@ void tst_QQuickItem::keysim() delete window; } +void tst_QQuickItem::keysForward() +{ + QQuickView window; + window.setBaseSize(QSize(240,320)); + + window.setSource(testFileUrl("keysforward.qml")); + window.show(); + window.requestActivate(); + QVERIFY(QTest::qWaitForWindowActive(&window)); + QVERIFY(QGuiApplication::focusWindow() == &window); + + QQuickItem *rootItem = qobject_cast<QQuickItem *>(window.rootObject()); + QVERIFY(rootItem); + QQuickItem *sourceItem = rootItem->property("source").value<QQuickItem *>(); + QVERIFY(sourceItem); + QQuickItem *primaryTarget = rootItem->property("primaryTarget").value<QQuickItem *>(); + QVERIFY(primaryTarget); + QQuickItem *secondaryTarget = rootItem->property("secondaryTarget").value<QQuickItem *>(); + QVERIFY(secondaryTarget); + + // primary target accepts/consumes Key_P + QKeyEvent pressKeyP(QEvent::KeyPress, Qt::Key_P, Qt::NoModifier, "P"); + QCoreApplication::sendEvent(sourceItem, &pressKeyP); + QCOMPARE(rootItem->property("pressedKeys").toList(), QVariantList()); + QCOMPARE(sourceItem->property("pressedKeys").toList(), QVariantList()); + QCOMPARE(primaryTarget->property("pressedKeys").toList(), QVariantList() << Qt::Key_P); + QCOMPARE(secondaryTarget->property("pressedKeys").toList(), QVariantList() << Qt::Key_P); + QVERIFY(pressKeyP.isAccepted()); + + QKeyEvent releaseKeyP(QEvent::KeyRelease, Qt::Key_P, Qt::NoModifier, "P"); + QCoreApplication::sendEvent(sourceItem, &releaseKeyP); + QCOMPARE(rootItem->property("releasedKeys").toList(), QVariantList()); + QCOMPARE(sourceItem->property("releasedKeys").toList(), QVariantList()); + QCOMPARE(primaryTarget->property("releasedKeys").toList(), QVariantList() << Qt::Key_P); + QCOMPARE(secondaryTarget->property("releasedKeys").toList(), QVariantList() << Qt::Key_P); + QVERIFY(releaseKeyP.isAccepted()); + + // secondary target accepts/consumes Key_S + QKeyEvent pressKeyS(QEvent::KeyPress, Qt::Key_S, Qt::NoModifier, "S"); + QCoreApplication::sendEvent(sourceItem, &pressKeyS); + QCOMPARE(rootItem->property("pressedKeys").toList(), QVariantList()); + QCOMPARE(sourceItem->property("pressedKeys").toList(), QVariantList()); + QCOMPARE(primaryTarget->property("pressedKeys").toList(), QVariantList() << Qt::Key_P); + QCOMPARE(secondaryTarget->property("pressedKeys").toList(), QVariantList() << Qt::Key_P << Qt::Key_S); + QVERIFY(pressKeyS.isAccepted()); + + QKeyEvent releaseKeyS(QEvent::KeyRelease, Qt::Key_S, Qt::NoModifier, "S"); + QCoreApplication::sendEvent(sourceItem, &releaseKeyS); + QCOMPARE(rootItem->property("releasedKeys").toList(), QVariantList()); + QCOMPARE(sourceItem->property("releasedKeys").toList(), QVariantList()); + QCOMPARE(primaryTarget->property("releasedKeys").toList(), QVariantList() << Qt::Key_P); + QCOMPARE(secondaryTarget->property("releasedKeys").toList(), QVariantList() << Qt::Key_P << Qt::Key_S); + QVERIFY(releaseKeyS.isAccepted()); + + // neither target accepts/consumes Key_Q + QKeyEvent pressKeyQ(QEvent::KeyPress, Qt::Key_Q, Qt::NoModifier, "Q"); + QCoreApplication::sendEvent(sourceItem, &pressKeyQ); + QCOMPARE(rootItem->property("pressedKeys").toList(), QVariantList()); + QCOMPARE(sourceItem->property("pressedKeys").toList(), QVariantList() << Qt::Key_Q); + QCOMPARE(primaryTarget->property("pressedKeys").toList(), QVariantList() << Qt::Key_P << Qt::Key_Q); + QCOMPARE(secondaryTarget->property("pressedKeys").toList(), QVariantList() << Qt::Key_P << Qt::Key_S << Qt::Key_Q); + QVERIFY(!pressKeyQ.isAccepted()); + + QKeyEvent releaseKeyQ(QEvent::KeyRelease, Qt::Key_Q, Qt::NoModifier, "Q"); + QCoreApplication::sendEvent(sourceItem, &releaseKeyQ); + QCOMPARE(rootItem->property("releasedKeys").toList(), QVariantList()); + QCOMPARE(sourceItem->property("releasedKeys").toList(), QVariantList() << Qt::Key_Q); + QCOMPARE(primaryTarget->property("releasedKeys").toList(), QVariantList() << Qt::Key_P << Qt::Key_Q); + QCOMPARE(secondaryTarget->property("releasedKeys").toList(), QVariantList() << Qt::Key_P << Qt::Key_S << Qt::Key_Q); + QVERIFY(!releaseKeyQ.isAccepted()); +} + QQuickItemPrivate *childPrivate(QQuickItem *rootItem, const char * itemString) { QQuickItem *item = findItem<QQuickItem>(rootItem, QString(QLatin1String(itemString))); |