diff options
author | Friedemann Kleint <Friedemann.Kleint@digia.com> | 2012-12-11 13:47:26 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-12-12 21:55:30 +0100 |
commit | bf178c77dda1db56ae698c1d31a6e3f685f4830f (patch) | |
tree | 9bfe026bfd8b93c3dda4b10b8c006c2982597ad0 /tests/auto/widgets | |
parent | 8e36b8de02548310570ea6b45a68801d0f035880 (diff) |
QMenu: Do not set snapToMouse if a caused-widget exists.
When clicking at the bottom-right corner of a menu in a menu
bar, it appears at the wrong position. Add test and stabilize
RTL-tests by making sure the layout direction is cleared should
they fail.
Task-number: QTBUG-28031
Task-number: QTBUG-2596
Change-Id: Ibc5ae916388753908e9f3ee98e8859faaa0c8723
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'tests/auto/widgets')
-rw-r--r-- | tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp index 2535e23ab8..3aefe26b1c 100644 --- a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp +++ b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp @@ -1016,6 +1016,25 @@ void tst_QMenuBar::check_shortcutPress() } #endif +class LayoutDirectionSaver +{ + Q_DISABLE_COPY(LayoutDirectionSaver) +public: + explicit LayoutDirectionSaver(Qt::LayoutDirection direction) + : m_oldDirection(qApp->layoutDirection()) + { + qApp->setLayoutDirection(direction); + } + + ~LayoutDirectionSaver() + { + qApp->setLayoutDirection(m_oldDirection); + } + +private: + const Qt::LayoutDirection m_oldDirection; +}; + // Qt/Mac,WinCE does not use the native popups/menubar #if !defined(Q_OS_MAC) && !defined(Q_OS_WINCE) void tst_QMenuBar::check_menuPosition() @@ -1070,10 +1089,9 @@ void tst_QMenuBar::check_menuPosition() menu.close(); } - //in RTL, the menu should be stuck at the right of the action geometry + // QTBUG-2596: in RTL, the menu should be stuck at the right of the action geometry { - Qt::LayoutDirection dir = qApp->layoutDirection(); - qApp->setLayoutDirection(Qt::RightToLeft); + LayoutDirectionSaver directionSaver(Qt::RightToLeft); menu.clear(); QObject::connect(&menu, SIGNAL(aboutToShow()), &menu, SLOT(addActions())); QRect mbItemRect = mw->menuBar()->actionGeometry(menu_action); @@ -1082,8 +1100,23 @@ void tst_QMenuBar::check_menuPosition() QVERIFY(menu.isActiveWindow()); QCOMPARE(menu.geometry().right(), mbItemRect.right()); menu.close(); - qApp->setLayoutDirection(dir); } + +# ifndef QTEST_NO_CURSOR + // QTBUG-28031: Click at bottom-right corner. + { + mw->move(400, 200); + LayoutDirectionSaver directionSaver(Qt::RightToLeft); + QMenuBar *mb = mw->menuBar(); + const QPoint localPos = mb->actionGeometry(menu.menuAction()).bottomRight() - QPoint(1, 1); + const QPoint globalPos = mb->mapToGlobal(localPos); + QCursor::setPos(globalPos); + QTest::mouseClick(mb, Qt::LeftButton, 0, localPos); + QTRY_VERIFY(menu.isActiveWindow()); + QCOMPARE(menu.geometry().right() - 1, globalPos.x()); + menu.close(); + } +# endif // QTEST_NO_CURSOR } #endif |