aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/quicktemplates2/qquickpopup.cpp2
-rw-r--r--tests/auto/qquickpopup/data/tabFence.qml97
-rw-r--r--tests/auto/qquickpopup/tst_qquickpopup.cpp57
3 files changed, 156 insertions, 0 deletions
diff --git a/src/quicktemplates2/qquickpopup.cpp b/src/quicktemplates2/qquickpopup.cpp
index f0cf1869..b798c82c 100644
--- a/src/quicktemplates2/qquickpopup.cpp
+++ b/src/quicktemplates2/qquickpopup.cpp
@@ -1836,6 +1836,8 @@ void QQuickPopup::setModal(bool modal)
d->toggleOverlay();
emit modalChanged();
+ QQuickItemPrivate::get(d->popupItem)->isTabFence = modal;
+
if (!d->hasDim) {
setDim(modal);
d->hasDim = false;
diff --git a/tests/auto/qquickpopup/data/tabFence.qml b/tests/auto/qquickpopup/data/tabFence.qml
new file mode 100644
index 00000000..2cf408e9
--- /dev/null
+++ b/tests/auto/qquickpopup/data/tabFence.qml
@@ -0,0 +1,97 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.15
+import QtQuick.Layouts 1.15
+import QtQuick.Window 2.15
+import QtQuick.Controls 2.15
+
+ApplicationWindow {
+ width: 400
+ height: 400
+ objectName: "Rectangle"
+
+ property alias dialog: dialog
+ property alias outsideButton1: outsideButton1
+ property alias outsideButton2: outsideButton2
+ property alias dialogButton1: dialogButton1
+ property alias dialogButton2: dialogButton2
+
+ ColumnLayout {
+ Button {
+ id: outsideButton1
+ text: "Button1"
+ }
+ Button {
+ id: outsideButton2
+ text: "Button2"
+ }
+ }
+
+ Dialog {
+ id: dialog
+ objectName: "Dialog"
+ width: 200
+ height: 200
+ anchors.centerIn: parent
+ visible: true
+
+ ColumnLayout {
+ Button {
+ id: dialogButton1
+ text: "Button3"
+ }
+ Button {
+ id: dialogButton2
+ text: "Button4"
+ }
+ }
+ }
+}
diff --git a/tests/auto/qquickpopup/tst_qquickpopup.cpp b/tests/auto/qquickpopup/tst_qquickpopup.cpp
index c36edd6d..2c173c63 100644
--- a/tests/auto/qquickpopup/tst_qquickpopup.cpp
+++ b/tests/auto/qquickpopup/tst_qquickpopup.cpp
@@ -91,6 +91,7 @@ private slots:
void countChanged();
void toolTipCrashOnClose();
void setOverlayParentToNull();
+ void tabFence();
};
void tst_QQuickPopup::initTestCase()
@@ -1233,6 +1234,62 @@ void tst_QQuickPopup::setOverlayParentToNull()
// While nullifying the overlay parent doesn't make much sense, it shouldn't crash.
}
+void tst_QQuickPopup::tabFence()
+{
+ if (QGuiApplication::styleHints()->tabFocusBehavior() != Qt::TabFocusAllControls)
+ QSKIP("This platform only allows tab focus for text controls");
+
+ QQuickApplicationHelper helper(this, "tabFence.qml");
+
+ QQuickWindow *window = helper.window;
+ window->show();
+ QVERIFY(QTest::qWaitForWindowActive(window));
+
+ QQuickPopup *popup = window->property("dialog").value<QQuickPopup*>();
+ QVERIFY(popup);
+ popup->open();
+ popup->setModal(true);
+
+ QQuickButton *outsideButton1 = window->property("outsideButton1").value<QQuickButton*>();
+ QVERIFY(outsideButton1);
+ QQuickButton *outsideButton2 = window->property("outsideButton2").value<QQuickButton*>();
+ QVERIFY(outsideButton2);
+ QQuickButton *dialogButton1 = window->property("dialogButton1").value<QQuickButton*>();
+ QVERIFY(dialogButton1);
+ QQuickButton *dialogButton2 = window->property("dialogButton2").value<QQuickButton*>();
+ QVERIFY(dialogButton2);
+
+ // When modal, focus loops between the two external buttons
+ outsideButton1->forceActiveFocus();
+ QVERIFY(outsideButton1->hasActiveFocus());
+ QTest::keyClick(window, Qt::Key_Tab);
+ QVERIFY(outsideButton2->hasActiveFocus());
+ QTest::keyClick(window, Qt::Key_Tab);
+ QVERIFY(outsideButton1->hasActiveFocus());
+
+ // Same thing for dialog's buttons
+ dialogButton1->forceActiveFocus();
+ QVERIFY(dialogButton1->hasActiveFocus());
+ QTest::keyClick(window, Qt::Key_Tab);
+ QVERIFY(dialogButton2->hasActiveFocus());
+ QTest::keyClick(window, Qt::Key_Tab);
+ QVERIFY(dialogButton1->hasActiveFocus());
+
+ popup->setModal(false);
+
+ // When not modal, focus goes in and out of the dialog
+ outsideButton1->forceActiveFocus();
+ QVERIFY(outsideButton1->hasActiveFocus());
+ QTest::keyClick(window, Qt::Key_Tab);
+ QVERIFY(outsideButton2->hasActiveFocus());
+ QTest::keyClick(window, Qt::Key_Tab);
+ QVERIFY(dialogButton1->hasActiveFocus());
+ QTest::keyClick(window, Qt::Key_Tab);
+ QVERIFY(dialogButton2->hasActiveFocus());
+ QTest::keyClick(window, Qt::Key_Tab);
+ QVERIFY(outsideButton1->hasActiveFocus());
+}
+
QTEST_QUICKCONTROLS_MAIN(tst_QQuickPopup)
#include "tst_qquickpopup.moc"