diff options
author | Gabriel de Dietrich <gabriel.dedietrich@digia.com> | 2013-09-18 15:19:06 +0200 |
---|---|---|
committer | Gabriel de Dietrich <gabriel.dedietrich@digia.com> | 2013-09-18 15:19:06 +0200 |
commit | 46f3cc477fc00aae887f085e063d6cb10bfdcd4c (patch) | |
tree | 0585601759ccbae2ed2abecedaf16e06b80676d0 /src/controls/MenuBar.qml | |
parent | 4c184095d378622fb0c3bb1692b331b3cc04e010 (diff) | |
parent | 04e000d2b1719696581bb4ae6ec21e39236ef38c (diff) | |
download | qtquickcontrols-46f3cc477fc00aae887f085e063d6cb10bfdcd4c.tar.gz |
Merge branch 'stable' into dev
Conflicts:
src/controls/qquickaction.cpp
Change-Id: I85255ba5c27c0d8ea023d0867e5963d43f8f1ddb
Diffstat (limited to 'src/controls/MenuBar.qml')
-rw-r--r-- | src/controls/MenuBar.qml | 62 |
1 files changed, 59 insertions, 3 deletions
diff --git a/src/controls/MenuBar.qml b/src/controls/MenuBar.qml index 85944d23..0a7585f6 100644 --- a/src/controls/MenuBar.qml +++ b/src/controls/MenuBar.qml @@ -82,6 +82,8 @@ MenuBarPrivate { sourceComponent: __menuBarComponent active: !root.__isNative focus: true + Keys.forwardTo: [item] + property bool altPressed: item ? item.altPressed : false } /*! \internal */ @@ -118,7 +120,51 @@ MenuBarPrivate { value: menuMouseArea.z - 1 } - focus: openedMenuIndex !== -1 + focus: true + + property bool altPressed: false + property bool altPressedAgain: false + property var mnemonicsMap: ({}) + + Keys.onPressed: { + var action = null + if (event.key === Qt.Key_Alt) { + if (!altPressed) + altPressed = true + else + altPressedAgain = true + } else if (altPressed && (action = mnemonicsMap[event.text.toUpperCase()])) { + preselectMenuItem = true + action.trigger() + event.accepted = true + } + } + + function dismissActiveFocus(event, reason) { + if (reason) { + altPressedAgain = false + altPressed = false + openedMenuIndex = -1 + root.__contentItem.parent.forceActiveFocus() + } else { + event.accepted = false + } + } + + Keys.onReleased: dismissActiveFocus(event, altPressedAgain && openedMenuIndex === -1) + Keys.onEscapePressed: dismissActiveFocus(event, openedMenuIndex === -1) + + function maybeOpenFirstMenu(event) { + if (altPressed && openedMenuIndex === -1) { + preselectMenuItem = true + openedMenuIndex = 0 + } else { + event.accepted = false + } + } + + Keys.onUpPressed: maybeOpenFirstMenu(event) + Keys.onDownPressed: maybeOpenFirstMenu(event) Keys.onLeftPressed: { if (openedMenuIndex > 0) { @@ -128,7 +174,7 @@ MenuBarPrivate { } Keys.onRightPressed: { - if (openedMenuIndex < root.menus.length - 1) { + if (openedMenuIndex !== -1 && openedMenuIndex < root.menus.length - 1) { preselectMenuItem = true openedMenuIndex++ } @@ -179,6 +225,7 @@ MenuBarPrivate { property var menuItem: modelData property bool selected: menuMouseArea.hoveredItem === menuItemLoader property bool sunken: menuItem.__popupVisible || menuBarLoader.openedMenuIndex === index + property bool showUnderlined: menuBarLoader.altPressed sourceComponent: menuBarLoader.menuItemStyle property int menuItemIndex: index @@ -208,9 +255,18 @@ MenuBarPrivate { } } + Connections { + target: menuItem.__action + onTriggered: menuBarLoader.openedMenuIndex = menuItemIndex + } + Component.onCompleted: { menuItem.__visualItem = menuItemLoader - menuItem.__menuBar = menuBarLoader + + var title = menuItem.title + var ampersandPos = title.indexOf("&") + if (ampersandPos !== -1) + menuBarLoader.mnemonicsMap[title[ampersandPos + 1].toUpperCase()] = menuItem.__action } } } |