summaryrefslogtreecommitdiffstats
path: root/src/widgets/widgets/qmenu.cpp
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2017-05-07 13:07:34 +0200
committerLiang Qi <liang.qi@qt.io>2017-05-07 13:08:18 +0200
commitd1ea4813458b383e66ce4df69d1833b8b6a279c4 (patch)
tree3bdc16da993e5de56b669e6774fb0748075ddd90 /src/widgets/widgets/qmenu.cpp
parent1c87d4e1a1d0e1972f6dc85e55ea9be8a42797ba (diff)
parent0b1ec78c2d4871afcc89d5b046926b88f0819a7c (diff)
Merge remote-tracking branch 'origin/5.9' into dev
Conflicts: src/network/access/qnetworkreply.cpp tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp Change-Id: Iadf766269454087e69fb216fc3857d85b0ddfaad
Diffstat (limited to 'src/widgets/widgets/qmenu.cpp')
-rw-r--r--src/widgets/widgets/qmenu.cpp46
1 files changed, 30 insertions, 16 deletions
diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp
index 8498835a34..4567f7c2a3 100644
--- a/src/widgets/widgets/qmenu.cpp
+++ b/src/widgets/widgets/qmenu.cpp
@@ -72,6 +72,7 @@
#include <private/qpushbutton_p.h>
#include <private/qaction_p.h>
#include <private/qguiapplication_p.h>
+#include <qpa/qplatformtheme.h>
QT_BEGIN_NAMESPACE
@@ -127,9 +128,9 @@ public:
setParent(parentWidget, Qt::Window | Qt::Tool);
setAttribute(Qt::WA_DeleteOnClose, true);
setAttribute(Qt::WA_X11NetWmWindowTypeMenu, true);
- setWindowTitle(p->windowTitle());
+ updateWindowTitle();
setEnabled(p->isEnabled());
-#if QT_CONFIG(cssparser)
+#if QT_CONFIG(style_stylesheet)
setStyleSheet(p->styleSheet());
#endif
if (style() != p->style())
@@ -165,6 +166,15 @@ public:
}
}
+ void updateWindowTitle()
+ {
+ Q_D(QTornOffMenu);
+ if (!d->causedMenu)
+ return;
+ const QString &cleanTitle = QPlatformTheme::removeMnemonics(d->causedMenu->title()).trimmed();
+ setWindowTitle(cleanTitle);
+ }
+
public slots:
void onTrigger(QAction *action) { d_func()->activateAction(action, QAction::Trigger, false); }
void onHovered(QAction *action) { d_func()->activateAction(action, QAction::Hover, false); }
@@ -183,6 +193,10 @@ void QMenuPrivate::init()
q->setAttribute(Qt::WA_X11NetWmWindowTypePopupMenu);
defaultMenuAction = menuAction = new QAction(q);
menuAction->d_func()->menu = q;
+ QObject::connect(menuAction, &QAction::changed, [=] {
+ if (!tornPopup.isNull())
+ tornPopup->updateWindowTitle();
+ });
q->setMouseTracking(q->style()->styleHint(QStyle::SH_Menu_MouseTracking, 0, q));
if (q->style()->styleHint(QStyle::SH_Menu_Scrollable, 0, q)) {
scroll = new QMenuPrivate::QMenuScroller;
@@ -313,8 +327,8 @@ void QMenuPrivate::updateActionRects(const QRect &screen) const
const int deskFw = style->pixelMetric(QStyle::PM_MenuDesktopFrameWidth, &opt, q);
const int tearoffHeight = tearoff ? style->pixelMetric(QStyle::PM_MenuTearoffHeight, &opt, q) : 0;
const int base_y = vmargin + fw + topmargin + (scroll ? scroll->scrollOffset : 0) + tearoffHeight;
+ const int column_max_y = screen.height() - 2 * deskFw - (vmargin + bottommargin + fw);
int max_column_width = 0;
- int dh = screen.height();
int y = base_y;
//for compatibility now - will have to refactor this away
@@ -392,8 +406,7 @@ void QMenuPrivate::updateActionRects(const QRect &screen) const
if (!sz.isEmpty()) {
max_column_width = qMax(max_column_width, sz.width());
//wrapping
- if (!scroll &&
- y + sz.height() + vmargin + bottommargin + fw > dh - (deskFw * 2)) {
+ if (!scroll && y + sz.height() > column_max_y) {
ncols++;
y = base_y;
} else {
@@ -419,8 +432,7 @@ void QMenuPrivate::updateActionRects(const QRect &screen) const
QRect &rect = actionRects[i];
if (rect.isNull())
continue;
- if (!scroll &&
- y + rect.height() + vmargin + bottommargin + fw > dh - deskFw * 2) {
+ if (!scroll && y + rect.height() > column_max_y) {
x += max_column_width + hmargin;
y = base_y;
}
@@ -2310,16 +2322,7 @@ void QMenu::popup(const QPoint &p, QAction *atAction)
ensurePolished(); // Get the right font
emit aboutToShow();
const bool actionListChanged = d->itemsDirty;
- d->updateActionRects();
- QPoint pos;
- QPushButton *causedButton = qobject_cast<QPushButton*>(d->causedPopup.widget);
- if (actionListChanged && causedButton)
- pos = QPushButtonPrivate::get(causedButton)->adjustedMenuPosition();
- else
- pos = p;
- const QSize menuSizeHint(sizeHint());
- QSize size = menuSizeHint;
QRect screen;
#ifndef QT_NO_GRAPHICSVIEW
bool isEmbedded = !bypassGraphicsProxyWidget(this) && d->nearestGraphicsProxyWidget(this);
@@ -2328,6 +2331,17 @@ void QMenu::popup(const QPoint &p, QAction *atAction)
else
#endif
screen = d->popupGeometry(QApplication::desktop()->screenNumber(p));
+ d->updateActionRects(screen);
+
+ QPoint pos;
+ QPushButton *causedButton = qobject_cast<QPushButton*>(d->causedPopup.widget);
+ if (actionListChanged && causedButton)
+ pos = QPushButtonPrivate::get(causedButton)->adjustedMenuPosition();
+ else
+ pos = p;
+
+ const QSize menuSizeHint(sizeHint());
+ QSize size = menuSizeHint;
const int desktopFrame = style()->pixelMetric(QStyle::PM_MenuDesktopFrameWidth, 0, this);
bool adjustToDesktop = !window()->testAttribute(Qt::WA_DontShowOnScreen);