on xenial help sign in
Auto open submenus on hover
commit5a0e98aee8c5013810341f83368e30b83273d0bc authorAlbert Astals Cid <albert.astals@canonical.com> dateWed 25 Jan 2017, 15:10 (10 years ago) parent322539b
2 files changed+27−2
qml/ApplicationMenus/MenuPopup.qml+13−2 tests/qmltests/ApplicationMenus/tst_MenuPopup.qml+14
qml/ApplicationMenus/MenuPopup.qml+13−2
@@ -208,6 +208,12 @@ UbuntuShape {
208208 contentHeight: menuColumn.height
209209 interactive: height < contentHeight
210210
211+ Timer {
212+ id: submenuHoverTimer
213+ interval: 225 // GTK MENU_POPUP_DELAY, Qt SH_Menu_SubMenuPopupDelay in QCommonStyle is 256
214+ onTriggered: d.currentItem.item.trigger();
215+ }
216+
211217 MouseArea {
212218 anchors.fill: parent
213219 hoverEnabled: true
@@ -221,12 +227,17 @@ UbuntuShape {
221227
222228 if (!d.hoveredItem || !d.currentItem ||
223229 !d.hoveredItem.contains(Qt.point(pos.x - d.currentItem.x, pos.y - d.currentItem.y))) {
230+ submenuHoverTimer.stop();
231+
224232 d.hoveredItem = menuColumn.childAt(pos.x, pos.y)
225233 if (!d.hoveredItem || !d.hoveredItem.enabled)
226− return false;
234+ return;
227235 d.currentItem = d.hoveredItem;
236+
237+ if (!d.currentItem.__isSeparator && d.currentItem.item.hasSubmenu) {
238+ submenuHoverTimer.start();
239+ }
228240 }
229− return true;
230241 }
231242 }
232243
tests/qmltests/ApplicationMenus/tst_MenuPopup.qml+14
@@ -223,6 +223,20 @@ Item {
223223 tryCompareFunction(function() { return menuItem.popup !== null && menuItem.popup.visible }, false);
224224 }
225225
226+ function test_mouseHoverOpensSubMenu() {
227+ menu.unityMenuModel.modelData = appMenuData.generateTestData(3,3,1,0,"menu",false);
228+
229+ var menuItem = findChild(menu, "menu-item0");
230+
231+ var priv = findInvisibleChild(menu, "d");
232+ priv.currentItem = menuItem;
233+
234+ mouseMove(menuItem, menuItem.width/2, menuItem.height/2);
235+ verify(!menuItem.popup);
236+
237+ tryCompareFunction(function() { return menuItem.popup != null; }, true);
238+ }
239+
226240 function test_differentSizes() {
227241 var differentSizesMenu = [{
228242 "rowData": { "label": "Short" }}, {