diff options
-rw-r--r-- | src/gui/widgets/qmenu.cpp | 7 | ||||
-rw-r--r-- | tests/auto/qmenu/tst_qmenu.cpp | 56 |
2 files changed, 4 insertions, 59 deletions
diff --git a/src/gui/widgets/qmenu.cpp b/src/gui/widgets/qmenu.cpp index b752ae2..3ea783f 100644 --- a/src/gui/widgets/qmenu.cpp +++ b/src/gui/widgets/qmenu.cpp @@ -1913,9 +1913,10 @@ void QMenu::popup(const QPoint &p, QAction *atAction) pos.setX(screen.left() + desktopFrame); } if (pos.y() + size.height() - 1 > screen.bottom() - desktopFrame) { - const int bestPos = (snapToMouse ? mouse.y() : p.y()) - desktopFrame - size.height() + 1; - const int fallbackPos = screen.bottom() - desktopFrame - size.height() + 1; - pos.setY(qMin(bestPos, fallbackPos)); + if(snapToMouse) + pos.setY(qMin(mouse.y() - (size.height() + desktopFrame), screen.bottom()-desktopFrame-size.height()+1)); + else + pos.setY(qMax(p.y() - (size.height() + desktopFrame), screen.bottom()-desktopFrame-size.height()+1)); } else if (pos.y() < screen.top() + desktopFrame) { pos.setY(screen.top() + desktopFrame); } diff --git a/tests/auto/qmenu/tst_qmenu.cpp b/tests/auto/qmenu/tst_qmenu.cpp index 4be6fdd..e10d7ee 100644 --- a/tests/auto/qmenu/tst_qmenu.cpp +++ b/tests/auto/qmenu/tst_qmenu.cpp @@ -106,8 +106,6 @@ private slots: void pushButtonPopulateOnAboutToShow(); void QTBUG7907_submenus_autoselect(); void QTBUG7411_submenus_activate(); - void menuGeometry_data(); - void menuGeometry(); protected slots: void onActivated(QAction*); void onHighlighted(QAction*); @@ -969,60 +967,6 @@ void tst_QMenu::QTBUG7411_submenus_activate() QTRY_VERIFY(sub1.isVisible()); } -void tst_QMenu::menuGeometry_data() -{ - QTest::addColumn<QRect>("screen"); - QTest::addColumn<QPoint>("pos"); - QTest::addColumn<QPoint>("expectedPos"); - - QMenu menu("Test Menu"); - for (int i = 0; i < 3; ++i) - menu.addAction("Hello World!"); - - menu.adjustSize(); - - const int screenCount = QApplication::desktop()->screenCount(); - const int desktopFrame = menu.style()->pixelMetric(QStyle::PM_MenuDesktopFrameWidth, 0, &menu); - - for (int i = 0; i < screenCount; ++i) { - const QRect screen = QApplication::desktop()->screenGeometry(i); - - if (screen.width() < menu.width() || screen.height() < menu.height()) - continue; - - QTest::newRow("topLeft") << screen << screen.topLeft() - << QPoint(screen.left() + desktopFrame, screen.top() + desktopFrame); - - QTest::newRow("topRight") << screen << screen.topRight() - << QPoint(screen.right() - desktopFrame - menu.width() + 1, screen.top() + desktopFrame); - - QTest::newRow("bottomLeft") << screen << screen.bottomLeft() - << QPoint(screen.left() + desktopFrame, screen.bottom() - desktopFrame - menu.height() + 1); - - QTest::newRow("bottomRight") << screen << screen.bottomRight() - << QPoint(screen.right() - desktopFrame - menu.width() + 1, screen.bottom() - desktopFrame - menu.height() + 1); - - const QPoint pos = QPoint(screen.right() - qMax(desktopFrame, 20), screen.bottom() - qMax(desktopFrame, 20)); - QTest::newRow("position") << screen << pos - << QPoint(screen.right() - menu.width() + 1, pos.y() - menu.height() + 1); - } -} - -void tst_QMenu::menuGeometry() -{ - QFETCH(QRect, screen); - QFETCH(QPoint, pos); - QFETCH(QPoint, expectedPos); - - QMenu menu("Test Menu"); - for (int i = 0; i < 3; ++i) - menu.addAction("Hello World!"); - - menu.popup(pos); - QTest::qWaitForWindowShown(&menu); - QVERIFY(screen.contains(menu.geometry())); - QCOMPARE(menu.pos(), expectedPos); -} QTEST_MAIN(tst_QMenu) |