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 <shawn.rutledge@qt.io>
This commit is contained in:
Błażej Szczygieł 2016-05-09 20:01:36 +02:00 committed by Shawn Rutledge
parent 11ed95ac9c
commit bdd5a67e65
2 changed files with 19 additions and 5 deletions

View File

@ -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

View File

@ -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<bool> setFirstMouse(m_first_mouse, false);
QSetValueOnDestroy<QPointF> 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<QAction *> 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;