diff options
| author | Frederik Gladhorn <frederik.gladhorn@digia.com> | 2013-04-09 14:17:23 +0200 |
|---|---|---|
| committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-04-15 16:09:59 +0200 |
| commit | d48fae36dd0fb2e3f59a52ef369fb3bce24900a3 (patch) | |
| tree | 635e9c0a1463c8655599eee488109c5d7ba9ceba /src/controls/qquickaction.cpp | |
| parent | 5857ea03a77e44879191dd922b7c38c49616517b (diff) | |
Fix shortcut scoping
Window shortcuts need to be only handled in
their respective windows. Before having
two windows with the same shortcut defined
would simply bail out without triggering either
of them.
Change-Id: Ice6c695d4b8f77f8bb7fcce6397fb26f216cc6ed
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
Diffstat (limited to 'src/controls/qquickaction.cpp')
| -rw-r--r-- | src/controls/qquickaction.cpp | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/src/controls/qquickaction.cpp b/src/controls/qquickaction.cpp index c9dde259b..dc1f7bb9d 100644 --- a/src/controls/qquickaction.cpp +++ b/src/controls/qquickaction.cpp @@ -42,6 +42,9 @@ #include "qquickaction_p.h" #include "qquickexclusivegroup_p.h" +#include <QtGui/qguiapplication.h> +#include <QtQuick/qquickitem.h> +#include <QtQuick/qquickwindow.h> #include <private/qguiapplication_p.h> #include <qqmlfile.h> @@ -186,12 +189,27 @@ void QQuickAction::setText(const QString &text) emit textChanged(); } -bool qShortcutContextMatcher(QObject *, Qt::ShortcutContext) +bool qShortcutContextMatcher(QObject *o, Qt::ShortcutContext context) { - // the context matching is only interesting for non window-wide shortcuts - // it might be interesting to check for the action's window being active - // we currently only support the window wide focus so we can safely ignore this - return true; + switch (context) { + case Qt::ApplicationShortcut: + return true; + case Qt::WindowShortcut: { + QObject *w = o; + while (w && !w->isWindowType()) { + w = w->parent(); + if (QQuickItem * item = qobject_cast<QQuickItem*>(w)) + w = item->window(); + } + if (w && w == QGuiApplication::focusWindow()) + return true; + } + case Qt::WidgetShortcut: + case Qt::WidgetWithChildrenShortcut: + break; + } + + return false; } QString QQuickAction::shortcut() const |
