From 445191bba8216276e6200157906ca9d138d7be04 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Tue, 25 Apr 2017 16:54:29 -0700 Subject: QMenu: Display the menu title on the torn-off menu's title bar Change-Id: If16e262a6c8b39dff517cc105cf55686d4c22582 Task-number: QTBUG-11693 Reviewed-by: Shawn Rutledge --- src/widgets/widgets/qmenu.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/widgets/widgets/qmenu.cpp') diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp index 98dc6d0a11..d62c010c60 100644 --- a/src/widgets/widgets/qmenu.cpp +++ b/src/widgets/widgets/qmenu.cpp @@ -72,6 +72,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -127,7 +128,7 @@ 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) setStyleSheet(p->styleSheet()); @@ -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; -- cgit v1.2.3 From 9b8a7de7946c6fa32d72fef37aa18a59054208d7 Mon Sep 17 00:00:00 2001 From: Tasuku Suzuki Date: Wed, 26 Apr 2017 10:03:52 +0900 Subject: Fix build without features.style-stylesheet Change-Id: Ib7cf5db6c9a49e7f359410bc0ec3d1ceadcde5cf Reviewed-by: Stephan Binner Reviewed-by: Paul Olav Tvete --- src/widgets/widgets/qmenu.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/widgets/widgets/qmenu.cpp') diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp index d62c010c60..4a3291b2ca 100644 --- a/src/widgets/widgets/qmenu.cpp +++ b/src/widgets/widgets/qmenu.cpp @@ -130,7 +130,7 @@ public: setAttribute(Qt::WA_X11NetWmWindowTypeMenu, true); updateWindowTitle(); setEnabled(p->isEnabled()); -#if QT_CONFIG(cssparser) +#if QT_CONFIG(style_stylesheet) setStyleSheet(p->styleSheet()); #endif if (style() != p->style()) -- cgit v1.2.3 From 46543bb462c4709d622080a0c32901a95f8d8963 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Mon, 1 May 2017 12:54:48 +0700 Subject: QMenu: Refactor column layout logic Change-Id: I30f1c87092447abf1c94e69c0124eeeee43666e2 Reviewed-by: Friedemann Kleint --- src/widgets/widgets/qmenu.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src/widgets/widgets/qmenu.cpp') diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp index 4a3291b2ca..75704f73de 100644 --- a/src/widgets/widgets/qmenu.cpp +++ b/src/widgets/widgets/qmenu.cpp @@ -327,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 @@ -406,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 { @@ -433,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; } -- cgit v1.2.3 From 35f927e719eb50b90dcfc76ca63c72a38ef821d7 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Mon, 1 May 2017 11:43:05 +0700 Subject: QMenu: Ensure popup() gets the right screen geometry Many QMenu related functions end up calling sizeHint() which does call updateActionRects(). Since we try not to update the action rects if no action has changed, we must be careful to call it the first time with the right screen geometry. Other- wise, multi-display setups may get the action rects based on the wrong display. In QMenu::popup(), this can be solved by using the position passed as argument. Incidentally, we were already computing the right display geometry in the same function, only a bit later. The updated position around an eventual push button menu should not change the screen onto which the menu popup will be displayed. Tested with the multiscreen-menus manual test. Change-Id: Id7fc24be6908b4a9d24b8b9c8b8006efe45d69be Reviewed-by: Friedemann Kleint Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/widgets/widgets/qmenu.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'src/widgets/widgets/qmenu.cpp') diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp index 75704f73de..2cafe462b1 100644 --- a/src/widgets/widgets/qmenu.cpp +++ b/src/widgets/widgets/qmenu.cpp @@ -2323,16 +2323,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(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); @@ -2341,6 +2332,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(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); -- cgit v1.2.3