summaryrefslogtreecommitdiffstats
path: root/src/widgets/widgets/qmenu.cpp
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2017-03-20 08:44:28 +0100
committerLiang Qi <liang.qi@qt.io>2017-03-20 09:00:44 +0100
commitae2695535a2f1abbd4c6596a22dd33319b9388dd (patch)
tree91df41df365a13ea71b1361d909535e5b7a7360a /src/widgets/widgets/qmenu.cpp
parent8066ae49433ed7604e710eef7b15d15de171608e (diff)
parentc1a2f97a3b3a8c058b1760b57e5c83bf7815b84a (diff)
Merge remote-tracking branch 'origin/5.9' into dev
Conflicts: src/corelib/io/qfilesystemengine_win.cpp src/gui/text/qdistancefield.cpp src/plugins/platforms/xcb/qxcbconnection.h Change-Id: I1be4a6f440ccb7599991159e3cb9de60990e4b1e
Diffstat (limited to 'src/widgets/widgets/qmenu.cpp')
-rw-r--r--src/widgets/widgets/qmenu.cpp60
1 files changed, 29 insertions, 31 deletions
diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp
index 295fb7d89c..4e55f0b132 100644
--- a/src/widgets/widgets/qmenu.cpp
+++ b/src/widgets/widgets/qmenu.cpp
@@ -401,17 +401,6 @@ void QMenuPrivate::updateActionRects(const QRect &screen) const
itemsDirty = 0;
}
-QSize QMenuPrivate::adjustMenuSizeForScreen(const QRect &screen)
-{
- Q_Q(QMenu);
- QSize ret = screen.size();
- itemsDirty = true;
- updateActionRects(screen);
- const int fw = q->style()->pixelMetric(QStyle::PM_MenuPanelWidth, 0, q);
- ret.setWidth(actionRects.at(getLastVisibleAction()).right() + fw);
- return ret;
-}
-
int QMenuPrivate::getLastVisibleAction() const
{
//let's try to get the last visible action
@@ -2266,7 +2255,8 @@ void QMenu::popup(const QPoint &p, QAction *atAction)
else
pos = p;
- QSize size = sizeHint();
+ const QSize menuSizeHint(sizeHint());
+ QSize size = menuSizeHint;
QRect screen;
#ifndef QT_NO_GRAPHICSVIEW
bool isEmbedded = !bypassGraphicsProxyWidget(this) && d->nearestGraphicsProxyWidget(this);
@@ -2279,13 +2269,11 @@ void QMenu::popup(const QPoint &p, QAction *atAction)
bool adjustToDesktop = !window()->testAttribute(Qt::WA_DontShowOnScreen);
// if the screens have very different geometries and the menu is too big, we have to recalculate
- if (size.height() > screen.height() || size.width() > screen.width()) {
- size = d->adjustMenuSizeForScreen(screen);
- adjustToDesktop = true;
- }
- // Layout is not right, we might be able to save horizontal space
- if (d->ncols >1 && size.height() < screen.height()) {
- size = d->adjustMenuSizeForScreen(screen);
+ if ((size.height() > screen.height() || size.width() > screen.width()) ||
+ // Layout is not right, we might be able to save horizontal space
+ (d->ncols >1 && size.height() < screen.height())) {
+ size.setWidth(qMin(menuSizeHint.width(), screen.width() - desktopFrame * 2));
+ size.setHeight(qMin(menuSizeHint.height(), screen.height() - desktopFrame * 2));
adjustToDesktop = true;
}
@@ -2338,7 +2326,6 @@ void QMenu::popup(const QPoint &p, QAction *atAction)
d->mousePopupPos = mouse;
const bool snapToMouse = !d->causedPopup.widget && (QRect(p.x() - 3, p.y() - 3, 6, 6).contains(mouse));
- const QSize menuSize(sizeHint());
if (adjustToDesktop) {
// handle popup falling "off screen"
if (isRightToLeft()) {
@@ -2372,7 +2359,7 @@ void QMenu::popup(const QPoint &p, QAction *atAction)
if (pos.y() < screen.top() + desktopFrame)
pos.setY(screen.top() + desktopFrame);
- if (pos.y() + menuSize.height() - 1 > screen.bottom() - desktopFrame) {
+ if (pos.y() + menuSizeHint.height() - 1 > screen.bottom() - desktopFrame) {
if (d->scroll) {
d->scroll->scrollFlags |= uint(QMenuPrivate::QMenuScroller::ScrollDown);
int y = qMax(screen.y(),pos.y());
@@ -2385,29 +2372,29 @@ void QMenu::popup(const QPoint &p, QAction *atAction)
}
const int subMenuOffset = style()->pixelMetric(QStyle::PM_SubMenuOverlap, 0, this);
QMenu *caused = qobject_cast<QMenu*>(d_func()->causedPopup.widget);
- if (caused && caused->geometry().width() + menuSize.width() + subMenuOffset < screen.width()) {
+ if (caused && caused->geometry().width() + menuSizeHint.width() + subMenuOffset < screen.width()) {
QRect parentActionRect(caused->d_func()->actionRect(caused->d_func()->currentAction));
const QPoint actionTopLeft = caused->mapToGlobal(parentActionRect.topLeft());
parentActionRect.moveTopLeft(actionTopLeft);
if (isRightToLeft()) {
- if ((pos.x() + menuSize.width() > parentActionRect.left() - subMenuOffset)
+ if ((pos.x() + menuSizeHint.width() > parentActionRect.left() - subMenuOffset)
&& (pos.x() < parentActionRect.right()))
{
- pos.rx() = parentActionRect.left() - menuSize.width();
+ pos.rx() = parentActionRect.left() - menuSizeHint.width();
if (pos.x() < screen.x())
pos.rx() = parentActionRect.right();
- if (pos.x() + menuSize.width() > screen.x() + screen.width())
+ if (pos.x() + menuSizeHint.width() > screen.x() + screen.width())
pos.rx() = screen.x();
}
} else {
if ((pos.x() < parentActionRect.right() + subMenuOffset)
- && (pos.x() + menuSize.width() > parentActionRect.left()))
+ && (pos.x() + menuSizeHint.width() > parentActionRect.left()))
{
pos.rx() = parentActionRect.right();
- if (pos.x() + menuSize.width() > screen.x() + screen.width())
- pos.rx() = parentActionRect.left() - menuSize.width();
+ if (pos.x() + menuSizeHint.width() > screen.x() + screen.width())
+ pos.rx() = parentActionRect.left() - menuSizeHint.width();
if (pos.x() < screen.x())
- pos.rx() = screen.x() + screen.width() - menuSize.width();
+ pos.rx() = screen.x() + screen.width() - menuSizeHint.width();
}
}
}
@@ -3515,11 +3502,22 @@ void QMenu::internalDelayedPopup()
d->activeMenu->d_func()->causedPopup.widget = this;
d->activeMenu->d_func()->causedPopup.action = d->currentAction;
+ QRect screen;
+#ifndef QT_NO_GRAPHICSVIEW
+ bool isEmbedded = !bypassGraphicsProxyWidget(this) && d->nearestGraphicsProxyWidget(this);
+ if (isEmbedded)
+ screen = d->popupGeometry(this);
+ else
+#endif
+ screen = d->popupGeometry(QApplication::desktop()->screenNumber(pos()));
+
int subMenuOffset = style()->pixelMetric(QStyle::PM_SubMenuOverlap, 0, this);
const QRect actionRect(d->actionRect(d->currentAction));
- const QPoint rightPos(mapToGlobal(QPoint(actionRect.right() + subMenuOffset + 1, actionRect.top())));
+ QPoint subMenuPos(mapToGlobal(QPoint(actionRect.right() + subMenuOffset + 1, actionRect.top())));
+ if (subMenuPos.x() > screen.right())
+ subMenuPos.setX(QCursor::pos().x());
- d->activeMenu->popup(rightPos);
+ d->activeMenu->popup(subMenuPos);
d->sloppyState.setSubMenuPopup(actionRect, d->currentAction, d->activeMenu);
#if !defined(Q_OS_DARWIN)