diff options
author | Richard Moe Gustavsen <richard.gustavsen@nokia.com> | 2010-04-20 11:44:59 (GMT) |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@nokia.com> | 2010-04-20 13:16:22 (GMT) |
commit | 327fabf8e8819b199aa24912ffe6893020b465d4 (patch) | |
tree | 305272c5ce4ac953b0c0127fc3a5ae92ee1e77af /tests | |
parent | 528ffd602cc5a501713cd768df0cf6870a36ddad (diff) | |
download | Qt-327fabf8e8819b199aa24912ffe6893020b465d4.zip Qt-327fabf8e8819b199aa24912ffe6893020b465d4.tar.gz Qt-327fabf8e8819b199aa24912ffe6893020b465d4.tar.bz2 |
Default (Parentless) QMenuBar actions do not work
This bug is a bit nasty. The problem is that Cocoa is trying
to be smart behind our back, and enable/disable menu items
depending on the menu item targets. But in Qt, we have a
different policy that Cocoa on when a menu bar should be
disabled or not. E.g. we allow a modal dialog to access the
application menu bar if it is the only window on screen.
This patch will work around cocoa being smart by setting the
menu item targets dynamically, depending on the modal state
of Qt. Setting it to nil will make the items enabled when there
is a modal dialog on screen, and setting it to the menu loader
will enable it when there is _no_ window on screen at all.
Task-number: QTBUG-9209
Reviewed-by: prasanth
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/macnativeevents/nativeeventlist.cpp | 5 | ||||
-rw-r--r-- | tests/auto/macnativeevents/nativeeventlist.h | 1 | ||||
-rw-r--r-- | tests/auto/macnativeevents/tst_macnativeevents.cpp | 67 |
3 files changed, 62 insertions, 11 deletions
diff --git a/tests/auto/macnativeevents/nativeeventlist.cpp b/tests/auto/macnativeevents/nativeeventlist.cpp index d5d7b95..1a90ee0 100644 --- a/tests/auto/macnativeevents/nativeeventlist.cpp +++ b/tests/auto/macnativeevents/nativeeventlist.cpp @@ -88,11 +88,6 @@ void NativeEventList::append(int waitMs, QNativeEvent *event) eventList.append(QPair<int, QNativeEvent *>(waitMs, event)); } -void NativeEventList::append(int waitMs) -{ - eventList.append(QPair<int, QNativeEvent *>(waitMs, 0)); -} - void NativeEventList::play(Playback playback) { waitNextEvent(); diff --git a/tests/auto/macnativeevents/nativeeventlist.h b/tests/auto/macnativeevents/nativeeventlist.h index 688665d..efcca43 100644 --- a/tests/auto/macnativeevents/nativeeventlist.h +++ b/tests/auto/macnativeevents/nativeeventlist.h @@ -57,7 +57,6 @@ class NativeEventList : public QObject void append(QNativeEvent *event); void append(int waitMs, QNativeEvent *event = 0); - void append(int waitMs); void play(Playback playback = WaitUntilFinished); void stop(); diff --git a/tests/auto/macnativeevents/tst_macnativeevents.cpp b/tests/auto/macnativeevents/tst_macnativeevents.cpp index 70a14f5..18fe81a 100644 --- a/tests/auto/macnativeevents/tst_macnativeevents.cpp +++ b/tests/auto/macnativeevents/tst_macnativeevents.cpp @@ -39,10 +39,7 @@ ** ****************************************************************************/ -#include <QApplication> -#include <QWidget> -#include <QDialog> -#include <QPushButton> +#include <QtGui> #include <QtTest/QtTest> #include "qnativeevents.h" @@ -65,8 +62,10 @@ private slots: void testMouseDragOutside(); void testMouseDragToNonClientArea(); void testDragWindow(); - void testMouseEnter(); void testChildDialogInFrontOfModalParent(); + void testMouseEnter(); + void testMenuBarWorksWithoutWindows(); + void testMenuBarWorksForModalDialog(); }; void tst_MacNativeEvents::testMouseMoveLocation() @@ -307,6 +306,64 @@ void tst_MacNativeEvents::testChildDialogInFrontOfModalParent() QVERIFY(!child.isVisible()); } +void tst_MacNativeEvents::testMenuBarWorksWithoutWindows() +{ + // Test that a global menu bar is enabled even + // when there is no window on screen (QTBUG-9209) + QEventLoop loop; + QMenuBar mb; + QMenu *fileMenu = mb.addMenu("Dummy"); + fileMenu->addAction("Dummy", &loop, SLOT(quit())); + QPoint inside1(250, 10); + QPoint inside2 = inside1 + QPoint(0, 30); + + // Post a click to press the menu item: + NativeEventList native; + native.append(new QNativeMouseButtonEvent(inside1, Qt::LeftButton, 1, Qt::NoModifier)); + native.append(new QNativeMouseButtonEvent(inside1, Qt::LeftButton, 0, Qt::NoModifier)); + native.append(new QNativeMouseButtonEvent(inside2, Qt::LeftButton, 1, Qt::NoModifier)); + native.append(new QNativeMouseButtonEvent(inside2, Qt::LeftButton, 0, Qt::NoModifier)); + + // Add a backup timer to end the test if we fail: + QTimer dontHang; + dontHang.setSingleShot(true); + connect(&dontHang, SIGNAL(timeout()), &loop, SLOT(quit())); + dontHang.start(2000); + + native.play(NativeEventList::ReturnImmediately); + loop.exec(); + QVERIFY2(dontHang.isActive(), "The item was not triggered!"); +} + +void tst_MacNativeEvents::testMenuBarWorksForModalDialog() +{ + // Test that a global menu bar is enabled even + // when there is no window on screen (QTBUG-9209) + QDialog dialog; + QMenuBar mb; + QMenu *fileMenu = mb.addMenu("Dummy"); + fileMenu->addAction("Dummy", &dialog, SLOT(hide())); + QPoint inside1(250, 10); + QPoint inside2 = inside1 + QPoint(0, 30); + + // Post a click to press the menu item: + NativeEventList native; + native.append(new QNativeMouseButtonEvent(inside1, Qt::LeftButton, 1, Qt::NoModifier)); + native.append(new QNativeMouseButtonEvent(inside1, Qt::LeftButton, 0, Qt::NoModifier)); + native.append(new QNativeMouseButtonEvent(inside2, Qt::LeftButton, 1, Qt::NoModifier)); + native.append(new QNativeMouseButtonEvent(inside2, Qt::LeftButton, 0, Qt::NoModifier)); + + // Add a backup timer to end the test if we fail: + QTimer dontHang; + dontHang.setSingleShot(true); + connect(&dontHang, SIGNAL(timeout()), &dialog, SLOT(hide())); + dontHang.start(2000); + + native.play(NativeEventList::ReturnImmediately); + dialog.exec(); + QVERIFY2(dontHang.isActive(), "The item was not triggered!"); +} + #include "tst_macnativeevents.moc" QTEST_MAIN(tst_MacNativeEvents) |