From 60324267fbb8a8554e62aaf9ef01360709292320 Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Tue, 2 Mar 2010 16:27:46 +0100 Subject: Make the sub-menu accessible via its shortcut even if it is the current Task-number: QTBUG-7411 Reviewed-by: ogoffart --- src/gui/widgets/qmenu.cpp | 12 ++---------- tests/auto/qmenu/tst_qmenu.cpp | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/gui/widgets/qmenu.cpp b/src/gui/widgets/qmenu.cpp index e2cf25b..5db14b8 100644 --- a/src/gui/widgets/qmenu.cpp +++ b/src/gui/widgets/qmenu.cpp @@ -487,7 +487,7 @@ void QMenuPrivate::popupAction(QAction *action, int delay, bool activateFirst) if (action && action->isEnabled()) { if (!delay) q->internalDelayedPopup(); - else + else if (!QMenuPrivate::menuDelayTimer.isActive() && (!action->menu() || !action->menu()->isVisible())) QMenuPrivate::menuDelayTimer.start(delay, q); if (activateFirst && action->menu()) action->menu()->d_func()->setFirstActionActive(); @@ -543,15 +543,6 @@ void QMenuPrivate::setCurrentAction(QAction *action, int popup, SelectionReason { Q_Q(QMenu); tearoffHighlighted = 0; - if (action == currentAction) { - if (!action || !action->menu() || action->menu() == activeMenu) { - if(QMenu *menu = qobject_cast(causedPopup.widget)) { - if(causedPopup.action && menu->d_func()->activeMenu == q) - menu->d_func()->setCurrentAction(causedPopup.action, 0, reason, false); - } - } - return; - } if (currentAction) q->update(actionRect(currentAction)); @@ -565,6 +556,7 @@ void QMenuPrivate::setCurrentAction(QAction *action, int popup, SelectionReason #ifdef QT3_SUPPORT emitHighlighted = action; #endif + currentAction = action; if (action) { if (!action->isSeparator()) { diff --git a/tests/auto/qmenu/tst_qmenu.cpp b/tests/auto/qmenu/tst_qmenu.cpp index 3559b15..e10d7ee 100644 --- a/tests/auto/qmenu/tst_qmenu.cpp +++ b/tests/auto/qmenu/tst_qmenu.cpp @@ -105,6 +105,7 @@ private slots: void deleteActionInTriggered(); void pushButtonPopulateOnAboutToShow(); void QTBUG7907_submenus_autoselect(); + void QTBUG7411_submenus_activate(); protected slots: void onActivated(QAction*); void onHighlighted(QAction*); @@ -948,6 +949,25 @@ void tst_QMenu::QTBUG7907_submenus_autoselect() QVERIFY(!subset.isVisible()); } +void tst_QMenu::QTBUG7411_submenus_activate() +{ + QMenu menu("Test Menu"); + QAction *act = menu.addAction("foo"); + QMenu sub1("&sub1"); + sub1.addAction("foo"); + sub1.setTitle("&sub1"); + QAction *act1 = menu.addMenu(&sub1); + menu.show(); + QTest::qWaitForWindowShown(&menu); + menu.setActiveAction(act); + QTest::keyPress(&menu, Qt::Key_Down); + QCOMPARE(menu.activeAction(), act1); + QVERIFY(!sub1.isVisible()); + QTest::keyPress(&menu, Qt::Key_S); + QTRY_VERIFY(sub1.isVisible()); +} + + QTEST_MAIN(tst_QMenu) #include "tst_qmenu.moc" -- cgit v0.12