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>
This commit is contained in:
parent
8e36b8de02
commit
bf178c77dd
@ -1856,7 +1856,7 @@ void QMenu::popup(const QPoint &p, QAction *atAction)
|
|||||||
|
|
||||||
QPoint mouse = QCursor::pos();
|
QPoint mouse = QCursor::pos();
|
||||||
d->mousePopupPos = mouse;
|
d->mousePopupPos = mouse;
|
||||||
const bool snapToMouse = (QRect(p.x() - 3, p.y() - 3, 6, 6).contains(mouse));
|
const bool snapToMouse = !d->causedPopup.widget && (QRect(p.x() - 3, p.y() - 3, 6, 6).contains(mouse));
|
||||||
|
|
||||||
const QSize menuSize(sizeHint());
|
const QSize menuSize(sizeHint());
|
||||||
if (adjustToDesktop) {
|
if (adjustToDesktop) {
|
||||||
|
@ -1016,6 +1016,25 @@ void tst_QMenuBar::check_shortcutPress()
|
|||||||
}
|
}
|
||||||
#endif
|
#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
|
// Qt/Mac,WinCE does not use the native popups/menubar
|
||||||
#if !defined(Q_OS_MAC) && !defined(Q_OS_WINCE)
|
#if !defined(Q_OS_MAC) && !defined(Q_OS_WINCE)
|
||||||
void tst_QMenuBar::check_menuPosition()
|
void tst_QMenuBar::check_menuPosition()
|
||||||
@ -1070,10 +1089,9 @@ void tst_QMenuBar::check_menuPosition()
|
|||||||
menu.close();
|
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();
|
LayoutDirectionSaver directionSaver(Qt::RightToLeft);
|
||||||
qApp->setLayoutDirection(Qt::RightToLeft);
|
|
||||||
menu.clear();
|
menu.clear();
|
||||||
QObject::connect(&menu, SIGNAL(aboutToShow()), &menu, SLOT(addActions()));
|
QObject::connect(&menu, SIGNAL(aboutToShow()), &menu, SLOT(addActions()));
|
||||||
QRect mbItemRect = mw->menuBar()->actionGeometry(menu_action);
|
QRect mbItemRect = mw->menuBar()->actionGeometry(menu_action);
|
||||||
@ -1082,8 +1100,23 @@ void tst_QMenuBar::check_menuPosition()
|
|||||||
QVERIFY(menu.isActiveWindow());
|
QVERIFY(menu.isActiveWindow());
|
||||||
QCOMPARE(menu.geometry().right(), mbItemRect.right());
|
QCOMPARE(menu.geometry().right(), mbItemRect.right());
|
||||||
menu.close();
|
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
|
#endif
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user