QMdiArea: on macOS using tabs, render document icons next to the text

This is closer to what titles of documents look like in macOS apps,
even though MDI is not a well-defined concept on this platform.

To implement this, the QCommonStylePrivate::tabLayout method had to be
made virtual, as it is called by the QCommonStyle class. It was already
reimplemented in QMacStylePrivate, but didn't get called in all cases.
Now that it is called as an override, adjust the icon placement to
include the padding so that we get identical results to 5.13 for
normal tab widgets.

Change-Id: I7a63f6d76891146ca713259096a7737a86584d81
Fixes: QTBUG-63445
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
Volker Hilsheimer 2019-12-03 11:25:27 +01:00
parent b6632443d4
commit 2ed59f0d42
3 changed files with 15 additions and 7 deletions

View File

@ -1388,14 +1388,22 @@ void QMacStylePrivate::tabLayout(const QStyleOptionTab *opt, const QWidget *widg
// High-dpi icons do not need adjustment; make sure tabIconSize is not larger than iconSize // High-dpi icons do not need adjustment; make sure tabIconSize is not larger than iconSize
tabIconSize = QSize(qMin(tabIconSize.width(), iconSize.width()), qMin(tabIconSize.height(), iconSize.height())); tabIconSize = QSize(qMin(tabIconSize.width(), iconSize.width()), qMin(tabIconSize.height(), iconSize.height()));
*iconRect = QRect(tr.left(), tr.center().y() - tabIconSize.height() / 2, const int stylePadding = proxyStyle->pixelMetric(QStyle::PM_TabBarTabHSpace, opt, widget) / 2 - hpadding;
tabIconSize.width(), tabIconSize.height());
if (opt->documentMode) {
// documents show the icon as part of the the text
const int textWidth =
opt->fontMetrics.boundingRect(tr, Qt::AlignCenter | Qt::TextShowMnemonic, opt->text).width();
*iconRect = QRect(tr.center().x() - textWidth / 2 - stylePadding - tabIconSize.width(),
tr.center().y() - tabIconSize.height() / 2,
tabIconSize.width(), tabIconSize.height());
} else {
*iconRect = QRect(tr.left() + stylePadding, tr.center().y() - tabIconSize.height() / 2,
tabIconSize.width(), tabIconSize.height());
}
if (!verticalTabs) if (!verticalTabs)
*iconRect = proxyStyle->visualRect(opt->direction, opt->rect, *iconRect); *iconRect = proxyStyle->visualRect(opt->direction, opt->rect, *iconRect);
int stylePadding = proxyStyle->pixelMetric(QStyle::PM_TabBarTabHSpace, opt, widget) / 2;
stylePadding -= hpadding;
tr.setLeft(tr.left() + stylePadding + tabIconSize.width() + 4); tr.setLeft(tr.left() + stylePadding + tabIconSize.width() + 4);
tr.setRight(tr.right() - stylePadding - tabIconSize.width() - 4); tr.setRight(tr.right() - stylePadding - tabIconSize.width() - 4);
} }

View File

@ -284,7 +284,7 @@ public:
CocoaControlType windowButtonCocoaControl(QStyle::SubControl sc) const; CocoaControlType windowButtonCocoaControl(QStyle::SubControl sc) const;
#if QT_CONFIG(tabbar) #if QT_CONFIG(tabbar)
void tabLayout(const QStyleOptionTab *opt, const QWidget *widget, QRect *textRect, QRect *iconRect) const; void tabLayout(const QStyleOptionTab *opt, const QWidget *widget, QRect *textRect, QRect *iconRect) const override;
static Direction tabDirection(QTabBar::Shape shape); static Direction tabDirection(QTabBar::Shape shape);
static bool verticalTabs(QMacStylePrivate::Direction tabDirection); static bool verticalTabs(QMacStylePrivate::Direction tabDirection);
#endif #endif

View File

@ -122,7 +122,7 @@ public:
mutable QIcon tabBarcloseButtonIcon; mutable QIcon tabBarcloseButtonIcon;
#if QT_CONFIG(tabbar) #if QT_CONFIG(tabbar)
void tabLayout(const QStyleOptionTab *opt, const QWidget *widget, QRect *textRect, QRect *pixmapRect) const; virtual void tabLayout(const QStyleOptionTab *opt, const QWidget *widget, QRect *textRect, QRect *pixmapRect) const;
#endif #endif
int animationFps; int animationFps;