diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp index 4d43186..0a27cc1 100644 --- a/src/widgets/widgets/qmenu.cpp +++ b/src/widgets/widgets/qmenu.cpp @@ -168,23 +168,30 @@ int QMenuPrivate::scrollerHeight() const //Windows and KDE allows menus to cover the taskbar, while GNOME and Mac don't QRect QMenuPrivate::popupGeometry(const QWidget *widget) const { + QRect r; if (QGuiApplicationPrivate::platformTheme() && QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::UseFullScreenForPopupMenu).toBool()) { - return QApplication::desktop()->screenGeometry(widget); + r = QApplication::desktop()->screenGeometry(widget); } else { - return QApplication::desktop()->availableGeometry(widget); + r = QApplication::desktop()->availableGeometry(widget); } +// qDebug() << Q_FUNC_INFO << r; + return r; } //Windows and KDE allows menus to cover the taskbar, while GNOME and Mac don't QRect QMenuPrivate::popupGeometry(int screen) const { + QRect r; if (QGuiApplicationPrivate::platformTheme() && QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::UseFullScreenForPopupMenu).toBool()) { - return QApplication::desktop()->screenGeometry(screen); + r = QApplication::desktop()->screenGeometry(screen); } else { - return QApplication::desktop()->availableGeometry(screen); + r= QApplication::desktop()->availableGeometry(screen); } + // qDebug() << Q_FUNC_INFO << r; + return r; + } QList > QMenuPrivate::calcCausedStack() const @@ -796,6 +803,7 @@ void QMenuPrivate::scrollMenu(QAction *action, QMenuScroller::ScrollLocation loc geom.setBottom(screen.bottom() - desktopFrame); if (geom.top() < desktopFrame+screen.top()) geom.setTop(desktopFrame+screen.top()); + qDebug() << Q_FUNC_INFO << geom; if (geom != q->geometry()) { #if 0 if (newScrollFlags & QMenuScroller::ScrollDown && @@ -1758,6 +1766,7 @@ QSize QMenu::sizeHint() const void QMenu::popup(const QPoint &p, QAction *atAction) { Q_D(QMenu); + qDebug() << __FUNCTION__ << '1' << p; if (d->scroll) { // reset scroll state from last popup if (d->scroll->scrollOffset) d->itemsDirty = 1; // sizeHint will be incorrect if there is previous scroll @@ -1785,7 +1794,7 @@ void QMenu::popup(const QPoint &p, QAction *atAction) pos = QPushButtonPrivate::get(causedButton)->adjustedMenuPosition(); else pos = p; - + qDebug() << __FUNCTION__ << '2' << pos; QSize size = sizeHint(); QRect screen; #ifndef QT_NO_GRAPHICSVIEW @@ -1795,6 +1804,7 @@ void QMenu::popup(const QPoint &p, QAction *atAction) else #endif screen = d->popupGeometry(QApplication::desktop()->screenNumber(p)); + qDebug() << __FUNCTION__ << screen; const int desktopFrame = style()->pixelMetric(QStyle::PM_MenuDesktopFrameWidth, 0, this); bool adjustToDesktop = !window()->testAttribute(Qt::WA_DontShowOnScreen); @@ -1853,41 +1863,54 @@ void QMenu::popup(const QPoint &p, QAction *atAction) } } } + qDebug() << '3' <mousePopupPos = mouse; - const bool snapToMouse = (QRect(p.x() - 3, p.y() - 3, 6, 6).contains(mouse)); + const QRect mr = QRect(p.x() - 3, p.y() - 3, 6, 6); + const bool snapToMouse = mr.contains(mouse); + qDebug() << "snapToMouse p=" << p << " mouse " << mouse << snapToMouse << mr; const QSize menuSize(sizeHint()); if (adjustToDesktop) { // handle popup falling "off screen" if (isRightToLeft()) { - if (snapToMouse) // position flowing left from the mouse + qDebug() << "RTL snapToMouse" << snapToMouse; + if (snapToMouse) { // position flowing left from the mouse pos.setX(mouse.x() - size.width()); + qDebug() << "RTL snapped " << pos; + } #ifndef QT_NO_MENUBAR // if in a menubar, it should be right-aligned - if (qobject_cast(d->causedPopup.widget)) + if (qobject_cast(d->causedPopup.widget)) { pos.rx() -= size.width(); + qDebug() << ">>>> RTL right-aligned in menu bar <<< " << pos; + } #endif //QT_NO_MENUBAR if (pos.x() < screen.left() + desktopFrame) pos.setX(qMax(p.x(), screen.left() + desktopFrame)); if (pos.x() + size.width() - 1 > screen.right() - desktopFrame) pos.setX(qMax(p.x() - size.width(), screen.right() - desktopFrame - size.width() + 1)); + qDebug() << "RTL branch menu bar " << pos; } else { if (pos.x() + size.width() - 1 > screen.right() - desktopFrame) pos.setX(screen.right() - desktopFrame - size.width() + 1); if (pos.x() < screen.left() + desktopFrame) pos.setX(screen.left() + desktopFrame); + qDebug() << "RTL branch default " << pos; } + qDebug() << "RTL 1" << pos; if (pos.y() + size.height() - 1 > screen.bottom() - desktopFrame) { 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)); + qDebug() << "RTL 2" << pos; } else if (pos.y() < screen.top() + desktopFrame) { pos.setY(screen.top() + desktopFrame); + qDebug() << "RTL 3" << pos; } if (pos.y() < screen.top() + desktopFrame) @@ -1900,9 +1923,11 @@ void QMenu::popup(const QPoint &p, QAction *atAction) } else { // Too big for screen, bias to see bottom of menu (for some reason) pos.setY(screen.bottom() - size.height() + 1); + qDebug() << "RTL 4" << pos; } } } + qDebug() << '4' << pos; const int subMenuOffset = style()->pixelMetric(QStyle::PM_SubMenuOverlap, 0, this); QMenu *caused = qobject_cast(d_func()->causedPopup.widget); if (caused && caused->geometry().width() + menuSize.width() + subMenuOffset < screen.width()) { @@ -1931,6 +1956,7 @@ void QMenu::popup(const QPoint &p, QAction *atAction) } } } + qDebug() << '5' << pos; setGeometry(QRect(pos, size)); #ifndef QT_NO_EFFECTS int hGuess = isRightToLeft() ? QEffects::LeftScroll : QEffects::RightScroll; @@ -2009,6 +2035,7 @@ void QMenu::popup(const QPoint &p, QAction *atAction) */ QAction *QMenu::exec() { + qDebug() << __FUNCTION__ << pos(); return exec(pos()); }