From 0bad605066f4cacabb2547b9b8895b69dac3d431 Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Mon, 23 Nov 2009 15:48:51 +0100 Subject: Make the menubar filter out EScape only if there is a current action Task-number: QTBUG-4965 Reviewed-by: gabi --- src/gui/widgets/qmenubar.cpp | 3 ++- tests/auto/qmenubar/tst_qmenubar.cpp | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/gui/widgets/qmenubar.cpp b/src/gui/widgets/qmenubar.cpp index e50de02..40cfe1a 100644 --- a/src/gui/widgets/qmenubar.cpp +++ b/src/gui/widgets/qmenubar.cpp @@ -1486,7 +1486,8 @@ bool QMenuBar::event(QEvent *e) break; case QEvent::ShortcutOverride: { QKeyEvent *kev = static_cast(e); - if (kev->key() == Qt::Key_Escape) { + //we only filter out escape if there is a current action + if (kev->key() == Qt::Key_Escape && d->currentAction) { e->accept(); return true; } diff --git a/tests/auto/qmenubar/tst_qmenubar.cpp b/tests/auto/qmenubar/tst_qmenubar.cpp index 4291c3e..320cd8d 100644 --- a/tests/auto/qmenubar/tst_qmenubar.cpp +++ b/tests/auto/qmenubar/tst_qmenubar.cpp @@ -167,6 +167,7 @@ private slots: void task223138_triggered(); void task256322_highlight(); void menubarSizeHint(); + void taskQTBUG4965_escapeEaten(); #if defined(QT3_SUPPORT) void indexBasedInsertion_data(); @@ -1664,6 +1665,27 @@ void tst_QMenuBar::menubarSizeHint() QCOMPARE(resSize, mb.sizeHint()); } +void tst_QMenuBar::taskQTBUG4965_escapeEaten() +{ + QMenuBar menubar; + QMenu menu("menu1"); + QAction *first = menubar.addMenu(&menu); + menu.addAction("quit", &menubar, SLOT(close()), QKeySequence("ESC")); + menubar.show(); + menubar.setActiveWindow(); + QTest::qWaitForWindowShown(&menubar); + menubar.setActiveAction(first); + QTRY_VERIFY(menu.isVisible()); + QCOMPARE(menubar.activeAction(), first); + QTest::keyClick(0, Qt::Key_Escape); + QVERIFY(!menu.isVisible()); + QTRY_VERIFY(menubar.hasFocus()); + QCOMPARE(menubar.activeAction(), first); + QTest::keyClick(0, Qt::Key_Escape); + QVERIFY(!menubar.activeAction()); + QTest::keyClick(0, Qt::Key_Escape); //now the action should be triggered + QTRY_VERIFY(!menubar.isVisible()); +} #if defined(QT3_SUPPORT) void tst_QMenuBar::indexBasedInsertion_data() -- cgit v0.12