diff options
| author | Gabriel de Dietrich <gabriel.dedietrich@digia.com> | 2014-03-06 23:28:48 +0100 |
|---|---|---|
| committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-03-07 17:39:35 +0100 |
| commit | b1c53e9f9954376b0eebfed9b9e3b6f2660d8a0c (patch) | |
| tree | 7a70362a79edd93a2c99bac4be3143ffaf395025 /src | |
| parent | 88bb2aa7030d2958056f4e6b588e796e1f4538b1 (diff) | |
Menu: Adding sloppy submenu navigation
Because that's how human beings operate.
[ChangeLog][QtQuickControls]Added sloppy submenu navigation
Change-Id: Ife520229f1b57a76d049bb7e72826e5f1a0cd5ad
Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@digia.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/controls/Private/ColumnMenuContent.qml | 46 |
1 files changed, 43 insertions, 3 deletions
diff --git a/src/controls/Private/ColumnMenuContent.qml b/src/controls/Private/ColumnMenuContent.qml index 5a56b007c..e9bc42fcc 100644 --- a/src/controls/Private/ColumnMenuContent.qml +++ b/src/controls/Private/ColumnMenuContent.qml @@ -69,25 +69,65 @@ Item { readonly property bool shouldUseScrollers: scrollView.style === emptyScrollerStyle && itemsModel.length > fittingItems readonly property real upScrollerHeight: upScroller.visible ? upScroller.height : 0 readonly property real downScrollerHeight: downScroller.visible ? downScroller.height : 0 + property var oldMousePos: undefined + property var openedSubmenu: null function updateCurrentItem(mouse) { var pos = mapToItem(list.contentItem, mouse.x, mouse.y) + var dx = 0 + var dy = 0 + var dist = 0 + var angle = 0 + if (openedSubmenu && oldMousePos !== undefined) { + dx = mouse.x - oldMousePos.x + dy = mouse.y - oldMousePos.y + dist = Math.sqrt(dx * dx + dy * dy) + } + oldMousePos = mouse + if (dist > 10) { + angle = Math.atan2(dy, dx) + if (openedSubmenu.__popupGeometry.x < __menu.__popupGeometry.x) + angle = Math.PI - angle // Submenu opened on the left side + if (-Math.PI / 10 < angle && angle < Math.PI / 4) { + sloppyTimer.start() + return + } + } + if (!currentItem || !currentItem.contains(Qt.point(pos.x - currentItem.x, pos.y - currentItem.y))) { if (currentItem && !hoverArea.pressed - && currentItem.styleData.type === MenuItemType.Menu) + && currentItem.styleData.type === MenuItemType.Menu) { currentItem.__closeSubMenu() + openedSubmenu = null + } currentItem = list.itemAt(pos.x, pos.y) if (currentItem) { __menu.__currentIndex = currentItem.__menuItemIndex if (currentItem.styleData.type === MenuItemType.Menu - && !currentItem.__menuItem.__popupVisible) + && !currentItem.__menuItem.__popupVisible) { currentItem.__showSubMenu(false) + openedSubmenu = currentItem.__menuItem + } } else { __menu.__currentIndex = -1 } } } + Timer { + id: sloppyTimer + interval: 500 + + // Stop timer as soon as we hover one of the submenu items + property int currentIndex: openedSubmenu ? openedSubmenu.__currentIndex : -1 + onCurrentIndexChanged: if (currentIndex !== -1) stop() + + onTriggered: { + if (openedSubmenu && openedSubmenu.__currentIndex === -1) + updateCurrentItem(oldMousePos) + } + } + Component { id: emptyScrollerStyle Style { @@ -130,7 +170,7 @@ Item { hoverEnabled: true acceptedButtons: Qt.AllButtons - onPositionChanged: updateCurrentItem(mouse) + onPositionChanged: updateCurrentItem({ "x": mouse.x, "y": mouse.y }) onReleased: content.triggered(currentItem) onExited: { if (currentItem && !currentItem.__menuItem.__popupVisible) { |
