diff options
author | Friedemann Kleint <Friedemann.Kleint@digia.com> | 2012-12-11 12:47:26 (GMT) |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-12-19 13:33:17 (GMT) |
commit | 0a24cec5a11678ebefe08b331812adbb9b3368aa (patch) | |
tree | 15c0161167424190cb42d89ebdc899733f159835 /tests/auto | |
parent | 99288633373ecc8ba808cf0ecf18f4a81d62ac84 (diff) | |
download | Qt-0a24cec5a11678ebefe08b331812adbb9b3368aa.zip Qt-0a24cec5a11678ebefe08b331812adbb9b3368aa.tar.gz Qt-0a24cec5a11678ebefe08b331812adbb9b3368aa.tar.bz2 |
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>
(cherry picked from qtbase/bf178c77dda1db56ae698c1d31a6e3f685f4830f)
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/qmenubar/tst_qmenubar.cpp | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/tests/auto/qmenubar/tst_qmenubar.cpp b/tests/auto/qmenubar/tst_qmenubar.cpp index e197ae2..0d00953 100644 --- a/tests/auto/qmenubar/tst_qmenubar.cpp +++ b/tests/auto/qmenubar/tst_qmenubar.cpp @@ -1454,6 +1454,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; +}; + void tst_QMenuBar::check_menuPosition() { #ifdef Q_WS_MAC @@ -1516,10 +1535,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); @@ -1528,9 +1546,23 @@ void tst_QMenuBar::check_menuPosition() QVERIFY(menu.isActiveWindow()); QCOMPARE(menu.geometry().right(), mbItemRect.right()); menu.close(); - qApp->setLayoutDirection(dir); } +#ifndef QT_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 // QT_NO_CURSOR } void tst_QMenuBar::task223138_triggered() |