summaryrefslogtreecommitdiff
path: root/src/controls/qquickaction.cpp
diff options
context:
space:
mode:
authorGabriel de Dietrich <gabriel.dedietrich@digia.com>2013-09-05 17:29:10 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-13 14:56:38 +0200
commit4eb3400843cafcedffa47fb8a272704bca4e9473 (patch)
tree6541694bca4cca47ea8fa8b4cc8db38fb3ead11a /src/controls/qquickaction.cpp
parent82081e737038262c82c2e408d412fc80a607bf9f (diff)
downloadqtquickcontrols-4eb3400843cafcedffa47fb8a272704bca4e9473.tar.gz
Menu: Enable mnemonic menu navigation
We also added a new mnemonic specific shortcut context matcher. This prevents two menu items with the same mnemonic but within different menus to be reported as ambiguous. Task-number: QTBUG-33030 ChangeLog: Added mnemonic navigation for menus Change-Id: I192c9aacba4d15851fe65bf9201251962fe976d5 Reviewed-by: J-P Nurmi <jpnurmi@digia.com>
Diffstat (limited to 'src/controls/qquickaction.cpp')
-rw-r--r--src/controls/qquickaction.cpp37
1 files changed, 36 insertions, 1 deletions
diff --git a/src/controls/qquickaction.cpp b/src/controls/qquickaction.cpp
index e240d111..6a031404 100644
--- a/src/controls/qquickaction.cpp
+++ b/src/controls/qquickaction.cpp
@@ -41,6 +41,7 @@
#include "qquickaction_p.h"
#include "qquickexclusivegroup_p.h"
+#include "qquickmenuitem_p.h"
#include <QtGui/qguiapplication.h>
#include <QtQuick/qquickitem.h>
@@ -203,6 +204,8 @@ void QQuickAction::setText(const QString &text)
emit textChanged();
}
+namespace {
+
bool qShortcutContextMatcher(QObject *o, Qt::ShortcutContext context)
{
switch (context) {
@@ -226,6 +229,38 @@ bool qShortcutContextMatcher(QObject *o, Qt::ShortcutContext context)
return false;
}
+bool qMnemonicContextMatcher(QObject *o, Qt::ShortcutContext context)
+{
+ 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();
+ else if (QQuickMenuBase *mb = qobject_cast<QQuickMenuBase *>(w)) {
+ QQuickItem *vi = mb->visualItem();
+ if (vi && vi->isVisible())
+ w = vi->window();
+ else
+ break; // Non visible menu objects don't get mnemonic match
+ }
+ }
+ if (w && w == QGuiApplication::focusWindow())
+ return true;
+ }
+ case Qt::WidgetShortcut:
+ case Qt::WidgetWithChildrenShortcut:
+ break;
+ }
+
+ return false;
+}
+
+} // namespace
+
QString QQuickAction::shortcut() const
{
return m_shortcut.toString(QKeySequence::NativeText);
@@ -262,7 +297,7 @@ void QQuickAction::setMnemonicFromText(const QString &text)
if (!m_mnemonic.isEmpty()) {
Qt::ShortcutContext context = Qt::WindowShortcut;
- QGuiApplicationPrivate::instance()->shortcutMap.addShortcut(this, m_mnemonic, context, qShortcutContextMatcher);
+ QGuiApplicationPrivate::instance()->shortcutMap.addShortcut(this, m_mnemonic, context, qMnemonicContextMatcher);
}
}