From 287f548d4c7cc594ffecc9c050dc5ec9fdaa6d37 Mon Sep 17 00:00:00 2001 From: Dmitry Shachnev Date: Wed, 2 Nov 2016 10:51:39 +0300 Subject: Make shortcuts work for platform menu bars MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a platform menu bar is used, the QMenuBar is hidden, so shortcuts for QActions attached only to it do not work. Extend the macOS-specific code to treat such menubars as visible to other platforms, to make the shortcuts work. The exception is made for internal QMenuBar shortcuts, which are forwarded to the platform menu. A follow-up change will add support for this to QDBusPlatformMenu. The updateGeometries() method is called for platform menu bars too to make sure the internal shortcuts are registered even if the global menu is in use. Add two cases to the tst_QMenuBar::activatedCount() test to test both native and non-native menu bars when possible (it now passes with native menu bars too). Change-Id: I2d7128512719ac199cd3f8f7ba28333d04d84ed4 Reviewed-by: Tor Arne Vestbø --- .../auto/widgets/widgets/qmenubar/tst_qmenubar.cpp | 25 +++++++++++++++------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp') diff --git a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp index b04fb7cd5d..f19d7619cc 100644 --- a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp +++ b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp @@ -93,6 +93,7 @@ private slots: #if !defined(Q_OS_DARWIN) void accel(); void activatedCount(); + void activatedCount_data(); void check_accelKeys(); void check_cursorKeys1(); @@ -144,8 +145,8 @@ protected slots: void slotForTaskQTBUG53205(); private: - TestMenu initSimpleMenuBar(QMenuBar *mb); - TestMenu initWindowWithSimpleMenuBar(QMainWindow &w); + TestMenu initSimpleMenuBar(QMenuBar *mb, bool forceNonNative = true); + TestMenu initWindowWithSimpleMenuBar(QMainWindow &w, bool forceNonNative = true); QAction *createCharacterAction(QMenu *menu, char lowerAscii); QMenu *addNumberedMenu(QMenuBar *mb, int n); TestMenu initComplexMenuBar(QMenuBar *mb); @@ -213,10 +214,10 @@ void tst_QMenuBar::cleanup() // Create a simple menu bar and connect its actions to onSimpleActivated(). -TestMenu tst_QMenuBar::initSimpleMenuBar(QMenuBar *mb) -{ +TestMenu tst_QMenuBar::initSimpleMenuBar(QMenuBar *mb, bool forceNonNative) { TestMenu result; - mb->setNativeMenuBar(false); + if (forceNonNative) + mb->setNativeMenuBar(false); connect(mb, SIGNAL(triggered(QAction*)), this, SLOT(onSimpleActivated(QAction*))); QMenu *menu = mb->addMenu(QStringLiteral("&accel")); QAction *action = menu->addAction(QStringLiteral("menu1") ); @@ -239,11 +240,11 @@ TestMenu tst_QMenuBar::initSimpleMenuBar(QMenuBar *mb) return result; } -inline TestMenu tst_QMenuBar::initWindowWithSimpleMenuBar(QMainWindow &w) +inline TestMenu tst_QMenuBar::initWindowWithSimpleMenuBar(QMainWindow &w, bool forceNonNative) { w.resize(200, 200); centerOnScreen(&w); - return initSimpleMenuBar(w.menuBar()); + return initSimpleMenuBar(w.menuBar(), forceNonNative); } // add a menu with number n, set number as data. @@ -341,7 +342,8 @@ void tst_QMenuBar::activatedCount() { // create a popup menu with menu items set the accelerators later... QMainWindow w; - initWindowWithSimpleMenuBar(w); + QFETCH( bool, forceNonNative ); + initWindowWithSimpleMenuBar(w, forceNonNative); w.show(); QApplication::setActiveWindow(&w); QVERIFY(QTest::qWaitForWindowActive(&w)); @@ -350,6 +352,13 @@ void tst_QMenuBar::activatedCount() //wait(5000); QCOMPARE( m_simpleActivatedCount, 2 ); //1 from the popupmenu and 1 from the menubar } + +void tst_QMenuBar::activatedCount_data() +{ + QTest::addColumn("forceNonNative"); + QTest::newRow( "forcing non-native menubar" ) << true; + QTest::newRow( "not forcing non-native menubar" ) << false; +} #endif void tst_QMenuBar::clear() -- cgit v1.2.3