From bdd5a67e6543aa4159ab4aa4b466baa453b622aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C5=82a=C5=BCej=20Szczygie=C5=82?= Date: Mon, 9 May 2016 20:01:36 +0200 Subject: QtWidgets: Don't open submenus when mouse is moving between actions Don't set the current action during closing submenu when mouse moved more than one action in the menu to the top or to the bottom. Task-number: QTBUG-53215 Change-Id: I2383363bc48f644df046198662dfa4d080fe3f1d Reviewed-by: Shawn Rutledge --- src/widgets/widgets/qmenu.cpp | 10 +++++++--- src/widgets/widgets/qmenu_p.h | 14 ++++++++++++-- 2 files changed, 19 insertions(+), 5 deletions(-) (limited to 'src/widgets/widgets') diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp index 1925b58326..6da56c926c 100644 --- a/src/widgets/widgets/qmenu.cpp +++ b/src/widgets/widgets/qmenu.cpp @@ -632,6 +632,7 @@ void QMenuSloppyState::reset() m_enabled = false; m_first_mouse = true; m_init_guard = false; + m_use_reset_action = true; m_uni_dir_discarded_count = 0; m_time.stop(); m_reset_action = Q_NULLPTR; @@ -684,6 +685,7 @@ void QMenuSloppyState::setSubMenuPopup(const QRect &actionRect, QAction *resetAc { m_enabled = true; m_init_guard = true; + m_use_reset_action = true; m_time.stop(); m_action_rect = actionRect; m_sub_menu = subMenu; @@ -744,10 +746,12 @@ void QMenuSloppyState::timeout() if (m_sub_menu) menu_priv->hideMenu(m_sub_menu); - if (reallyHasMouse) - menu_priv->setCurrentAction(m_reset_action,0); - else + if (reallyHasMouse) { + if (m_use_reset_action) + menu_priv->setCurrentAction(m_reset_action, 0); + } else { menu_priv->setCurrentAction(Q_NULLPTR, 0); + } } //return the top causedPopup.widget that is not a QMenu diff --git a/src/widgets/widgets/qmenu_p.h b/src/widgets/widgets/qmenu_p.h index 898fa3161b..0bce269831 100644 --- a/src/widgets/widgets/qmenu_p.h +++ b/src/widgets/widgets/qmenu_p.h @@ -95,6 +95,7 @@ public: , m_select_other_actions(false) , m_first_mouse(true) , m_init_guard(false) + , m_use_reset_action(true) , m_uni_dir_discarded_count(0) , m_uni_dir_fail_at_count(0) , m_timeout(0) @@ -182,9 +183,17 @@ public: QSetValueOnDestroy setFirstMouse(m_first_mouse, false); QSetValueOnDestroy setPreviousPoint(m_previous_point, mousePos); - if (resetAction && resetAction->isSeparator()) + if (resetAction && resetAction->isSeparator()) { m_reset_action = Q_NULLPTR; - else { + m_use_reset_action = true; + } else if (m_reset_action != resetAction) { + if (m_use_reset_action && resetAction) { + const QList actions = m_menu->actions(); + const int resetIdx = actions.indexOf(resetAction); + const int originIdx = actions.indexOf(m_origin_action); + if (resetIdx > -1 && originIdx > -1 && qAbs(resetIdx - originIdx) > 1) + m_use_reset_action = false; + } m_reset_action = resetAction; } @@ -249,6 +258,7 @@ private: bool m_init_guard; bool m_discard_state_when_entering_parent; bool m_dont_start_time_on_leave; + bool m_use_reset_action; short m_uni_dir_discarded_count; short m_uni_dir_fail_at_count; short m_timeout; -- cgit v1.2.3