aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicktemplates2/qquickshortcutcontext.cpp
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2016-10-21 22:10:39 +0200
committerJ-P Nurmi <jpnurmi@qt.io>2016-11-01 12:59:45 +0000
commitb31b4094e1728d839fef30f5128c81451ea75e4a (patch)
treed7288c7a964a1fb9f45612e9e4b98c40dc2b1a73 /src/quicktemplates2/qquickshortcutcontext.cpp
parent281469e947e6b09a44c296a26db474db815f6238 (diff)
QQuickPopup: use QShortcutMap to grab Back & Escape keys
This makes CloseOnEscape play well together with QML Shortcut, as illustrated by the Gallery example. For example, navigate to any control page, open the options menu, and hit escape twice. First, the options menu closes, and then the stackview navigates back. Another nice example is to open the style combobox in the settings dialog, while being navigated to one of the control pages, and hit escape three times. First, the combobox closes, then the settings dialog closes, and finally, the stackview navigates back. NOTE: tst_combobox had to be updated, because it was assuming that the popup is closed when escape is released. Now that the system is based on shortcut overrides, it gets closed on press instead. Task-number: QTBUG-56562 Change-Id: I8b8901bcba7deebd82b181af42f335d95a7cb469 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/quicktemplates2/qquickshortcutcontext.cpp')
-rw-r--r--src/quicktemplates2/qquickshortcutcontext.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/quicktemplates2/qquickshortcutcontext.cpp b/src/quicktemplates2/qquickshortcutcontext.cpp
index 2a3cb68a..04aa4f4d 100644
--- a/src/quicktemplates2/qquickshortcutcontext.cpp
+++ b/src/quicktemplates2/qquickshortcutcontext.cpp
@@ -50,8 +50,8 @@ static bool isBlockedByPopup(QQuickItem *item)
QQuickOverlay *overlay = QQuickOverlay::overlay(item->window());
const auto popups = QQuickOverlayPrivate::get(overlay)->stackingOrderPopups();
for (QQuickPopup *popup : popups) {
- if (popup->isModal())
- return !popup->popupItem()->isAncestorOf(item);
+ if (popup->isModal() || popup->closePolicy() & QQuickPopup::CloseOnEscape)
+ return item != popup->popupItem() && !popup->popupItem()->isAncestorOf(item);
}
return false;
@@ -67,8 +67,12 @@ bool QQuickShortcutContext::matcher(QObject *obj, Qt::ShortcutContext context)
while (obj && !obj->isWindowType()) {
obj = obj->parent();
item = qobject_cast<QQuickItem *>(obj);
- if (item)
+ if (item) {
obj = item->window();
+ } else if (QQuickPopup *popup = qobject_cast<QQuickPopup *>(obj)) {
+ obj = popup->window();
+ item = popup->popupItem();
+ }
}
return obj && obj == QGuiApplication::focusWindow() && !isBlockedByPopup(item);
default: