From a7fd83cd0cecb789006baecabfc6a49c49b7f48c Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Sat, 22 Oct 2016 07:31:37 +0200 Subject: Shortcut: add support for multiple key sequences [ChangeLog][QtQuick][Shortcut] Added support for multiple shortcut sequences. Previously it was possible to specify a single sequence that could consist of up to four key presses. Now it is possible to specify multiple sequences that can each consist of multiple key presses. Change-Id: Id12f25da2f352cc542ec776049d8e81593951d41 Reviewed-by: Robin Burchell Reviewed-by: Mitch Curtis --- tests/auto/quick/qquickshortcut/data/multiple.qml | 45 ++++++++++++++++++++++ .../quick/qquickshortcut/tst_qquickshortcut.cpp | 45 ++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 tests/auto/quick/qquickshortcut/data/multiple.qml (limited to 'tests') diff --git a/tests/auto/quick/qquickshortcut/data/multiple.qml b/tests/auto/quick/qquickshortcut/data/multiple.qml new file mode 100644 index 0000000000..2b58327cf0 --- /dev/null +++ b/tests/auto/quick/qquickshortcut/data/multiple.qml @@ -0,0 +1,45 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtQuick module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** 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. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.9 +import QtQuick.Window 2.2 + +Window { + id: window + + width: 300 + height: 300 + + property bool activated: false + property alias shortcut: shortcut + + Shortcut { + id: shortcut + onActivated: window.activated = true + } +} diff --git a/tests/auto/quick/qquickshortcut/tst_qquickshortcut.cpp b/tests/auto/quick/qquickshortcut/tst_qquickshortcut.cpp index 2df94bb84a..75ccf26af9 100644 --- a/tests/auto/quick/qquickshortcut/tst_qquickshortcut.cpp +++ b/tests/auto/quick/qquickshortcut/tst_qquickshortcut.cpp @@ -45,6 +45,8 @@ private slots: void context(); void matcher_data(); void matcher(); + void multiple_data(); + void multiple(); }; Q_DECLARE_METATYPE(Qt::Key) @@ -408,6 +410,49 @@ void tst_QQuickShortcut::matcher() qt_quick_set_shortcut_context_matcher(defaultMatcher); } +void tst_QQuickShortcut::multiple_data() +{ + QTest::addColumn("sequences"); + QTest::addColumn("key"); + QTest::addColumn("modifiers"); + QTest::addColumn("enabled"); + QTest::addColumn("activated"); + + // first + QTest::newRow("Ctrl+X,(Shift+Del)") << (QStringList() << "Ctrl+X" << "Shift+Del") << Qt::Key_X << Qt::KeyboardModifiers(Qt::ControlModifier) << true << true; + // second + QTest::newRow("(Ctrl+X),Shift+Del") << (QStringList() << "Ctrl+X" << "Shift+Del") << Qt::Key_Delete << Qt::KeyboardModifiers(Qt::ShiftModifier) << true << true; + // disabled + QTest::newRow("(Ctrl+X,Shift+Del)") << (QStringList() << "Ctrl+X" << "Shift+Del") << Qt::Key_X << Qt::KeyboardModifiers(Qt::ControlModifier) << false << false; +} + +void tst_QQuickShortcut::multiple() +{ + QFETCH(QStringList, sequences); + QFETCH(Qt::Key, key); + QFETCH(Qt::KeyboardModifiers, modifiers); + QFETCH(bool, enabled); + QFETCH(bool, activated); + + QQmlApplicationEngine engine; + + engine.load(testFileUrl("multiple.qml")); + QQuickWindow *window = qobject_cast(engine.rootObjects().value(0)); + QVERIFY(window); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window)); + + QObject *shortcut = window->property("shortcut").value(); + QVERIFY(shortcut); + + shortcut->setProperty("enabled", enabled); + shortcut->setProperty("sequences", sequences); + + QTest::keyPress(window, key, modifiers); + + QCOMPARE(window->property("activated").toBool(), activated); +} + QTEST_MAIN(tst_QQuickShortcut) #include "tst_qquickshortcut.moc" -- cgit v1.2.3