QMacStyle: Add back icon logic in tab layout
This was accidentally removed when we revamped the document mode tabs appearance. In retrospect, we should also consider adding CE_TabBarTabIcon so that we can set the relative position of the icon w.r.t. the tab title. Change-Id: Ic8c3a69c31837018bfdd60f8084120cae47e91f8 Task-number: QTBUG-61092 Task-number: QTBUG-61742 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
parent
333a27a8b6
commit
c12072c685
@ -1066,9 +1066,10 @@ void QMacStylePrivate::drawFocusRing(QPainter *p, const QRect &targetRect, int h
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifndef QT_NO_TABBAR
|
#ifndef QT_NO_TABBAR
|
||||||
void QMacStylePrivate::tabLayout(const QStyleOptionTab *opt, const QWidget *widget, QRect *textRect) const
|
void QMacStylePrivate::tabLayout(const QStyleOptionTab *opt, const QWidget *widget, QRect *textRect, QRect *iconRect) const
|
||||||
{
|
{
|
||||||
Q_ASSERT(textRect);
|
Q_ASSERT(textRect);
|
||||||
|
Q_ASSERT(iconRect);
|
||||||
QRect tr = opt->rect;
|
QRect tr = opt->rect;
|
||||||
const bool verticalTabs = opt->shape == QTabBar::RoundedEast
|
const bool verticalTabs = opt->shape == QTabBar::RoundedEast
|
||||||
|| opt->shape == QTabBar::RoundedWest
|
|| opt->shape == QTabBar::RoundedWest
|
||||||
@ -1102,6 +1103,26 @@ void QMacStylePrivate::tabLayout(const QStyleOptionTab *opt, const QWidget *widg
|
|||||||
tr.setLeft(tr.left() + 4 + buttonSize);
|
tr.setLeft(tr.left() + 4 + buttonSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// icon
|
||||||
|
if (!opt->icon.isNull()) {
|
||||||
|
QSize iconSize = opt->iconSize;
|
||||||
|
if (!iconSize.isValid()) {
|
||||||
|
int iconExtent = proxyStyle->pixelMetric(QStyle::PM_SmallIconSize);
|
||||||
|
iconSize = QSize(iconExtent, iconExtent);
|
||||||
|
}
|
||||||
|
QSize tabIconSize = opt->icon.actualSize(iconSize,
|
||||||
|
(opt->state & QStyle::State_Enabled) ? QIcon::Normal : QIcon::Disabled,
|
||||||
|
(opt->state & QStyle::State_Selected) ? QIcon::On : QIcon::Off);
|
||||||
|
// 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()));
|
||||||
|
|
||||||
|
*iconRect = QRect(tr.left(), tr.center().y() - tabIconSize.height() / 2,
|
||||||
|
tabIconSize.width(), tabIconSize.height());
|
||||||
|
if (!verticalTabs)
|
||||||
|
*iconRect = proxyStyle->visualRect(opt->direction, opt->rect, *iconRect);
|
||||||
|
tr.setLeft(tr.left() + tabIconSize.width() + 4);
|
||||||
|
}
|
||||||
|
|
||||||
if (!verticalTabs)
|
if (!verticalTabs)
|
||||||
tr = proxyStyle->visualRect(opt->direction, opt->rect, tr);
|
tr = proxyStyle->visualRect(opt->direction, opt->rect, tr);
|
||||||
|
|
||||||
@ -4967,7 +4988,8 @@ QRect QMacStyle::subElementRect(SubElement sr, const QStyleOption *opt,
|
|||||||
break;
|
break;
|
||||||
case SE_TabBarTabText:
|
case SE_TabBarTabText:
|
||||||
if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) {
|
if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) {
|
||||||
d->tabLayout(tab, widget, &rect);
|
QRect dummyIconRect;
|
||||||
|
d->tabLayout(tab, widget, &rect, &dummyIconRect);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SE_TabBarTabLeftButton:
|
case SE_TabBarTabLeftButton:
|
||||||
|
@ -231,7 +231,7 @@ public:
|
|||||||
void drawFocusRing(QPainter *p, const QRect &targetRect, int hMargin, int vMargin, qreal radius = 0) const;
|
void drawFocusRing(QPainter *p, const QRect &targetRect, int hMargin, int vMargin, qreal radius = 0) const;
|
||||||
|
|
||||||
#ifndef QT_NO_TABBAR
|
#ifndef QT_NO_TABBAR
|
||||||
void tabLayout(const QStyleOptionTab *opt, const QWidget *widget, QRect *textRect) const;
|
void tabLayout(const QStyleOptionTab *opt, const QWidget *widget, QRect *textRect, QRect *iconRect) const;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user