aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquickshortcut
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2016-10-16 19:21:29 +0200
committerJ-P Nurmi <jpnurmi@qt.io>2016-10-26 13:20:05 +0000
commit93d7c26653757755ae65f14d06d6df6f9ec2fc07 (patch)
tree14aa2ddaf2cc14af8d0544944668144b33635c4c /tests/auto/quick/qquickshortcut
parentdd313c4c5e383827913bbc106f9d19667f2dd149 (diff)
QQuickShortcut: allow setting a custom context matcher
This allows Qt Quick Controls 2 to register a shortcut context matcher that makes shortcuts behave well with QQC2's item-based popups, which QQuickShortcut is not aware of. Task-number: QTBUG-56562 Change-Id: Ia2518fd6ac7140f60aa38c7d9af557007e9db23b Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'tests/auto/quick/qquickshortcut')
-rw-r--r--tests/auto/quick/qquickshortcut/tst_qquickshortcut.cpp64
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickshortcut/tst_qquickshortcut.cpp b/tests/auto/quick/qquickshortcut/tst_qquickshortcut.cpp
index 35a1aa8757..2df94bb84a 100644
--- a/tests/auto/quick/qquickshortcut/tst_qquickshortcut.cpp
+++ b/tests/auto/quick/qquickshortcut/tst_qquickshortcut.cpp
@@ -43,6 +43,8 @@ private slots:
void sequence();
void context_data();
void context();
+ void matcher_data();
+ void matcher();
};
Q_DECLARE_METATYPE(Qt::Key)
@@ -344,6 +346,68 @@ void tst_QQuickShortcut::context()
|| inactiveWindow->property("ambiguousShortcut").toString() == ambiguousShortcut);
}
+typedef bool (*ShortcutContextMatcher)(QObject *, Qt::ShortcutContext);
+extern ShortcutContextMatcher qt_quick_shortcut_context_matcher();
+extern void qt_quick_set_shortcut_context_matcher(ShortcutContextMatcher matcher);
+
+static ShortcutContextMatcher lastMatcher = nullptr;
+
+static bool trueMatcher(QObject *, Qt::ShortcutContext)
+{
+ lastMatcher = trueMatcher;
+ return true;
+}
+
+static bool falseMatcher(QObject *, Qt::ShortcutContext)
+{
+ lastMatcher = falseMatcher;
+ return false;
+}
+
+Q_DECLARE_METATYPE(ShortcutContextMatcher)
+
+void tst_QQuickShortcut::matcher_data()
+{
+ QTest::addColumn<ShortcutContextMatcher>("matcher");
+ QTest::addColumn<Qt::Key>("key");
+ QTest::addColumn<QVariant>("shortcut");
+ QTest::addColumn<QString>("activatedShortcut");
+
+ ShortcutContextMatcher tm = trueMatcher;
+ ShortcutContextMatcher fm = falseMatcher;
+
+ QTest::newRow("F1") << tm << Qt::Key_F1 << shortcutMap("F1", Qt::ApplicationShortcut) << "F1";
+ QTest::newRow("F2") << fm << Qt::Key_F2 << shortcutMap("F2", Qt::ApplicationShortcut) << "";
+}
+
+void tst_QQuickShortcut::matcher()
+{
+ QFETCH(ShortcutContextMatcher, matcher);
+ QFETCH(Qt::Key, key);
+ QFETCH(QVariant, shortcut);
+ QFETCH(QString, activatedShortcut);
+
+ ShortcutContextMatcher defaultMatcher = qt_quick_shortcut_context_matcher();
+ QVERIFY(defaultMatcher);
+
+ qt_quick_set_shortcut_context_matcher(matcher);
+ QVERIFY(qt_quick_shortcut_context_matcher() == matcher);
+
+ QQmlApplicationEngine engine(testFileUrl("shortcuts.qml"));
+ QQuickWindow *window = qobject_cast<QQuickWindow *>(engine.rootObjects().value(0));
+ QVERIFY(window);
+ window->show();
+ QVERIFY(QTest::qWaitForWindowExposed(window));
+
+ window->setProperty("shortcuts", QVariantList() << shortcut);
+ QTest::keyClick(window, key);
+
+ QVERIFY(lastMatcher == matcher);
+ QCOMPARE(window->property("activatedShortcut").toString(), activatedShortcut);
+
+ qt_quick_set_shortcut_context_matcher(defaultMatcher);
+}
+
QTEST_MAIN(tst_QQuickShortcut)
#include "tst_qquickshortcut.moc"