diff options
author | Gabriel de Dietrich <gabriel.dedietrich@qt.io> | 2017-07-05 12:27:24 -0700 |
---|---|---|
committer | Gabriel de Dietrich <gabriel.dedietrich@qt.io> | 2017-07-10 17:39:03 +0000 |
commit | c12072c685f7e93d5b84e289ca23106482379eff (patch) | |
tree | 5a2d249e8979a547ab17f78c4407e2044993a4d8 | |
parent | 333a27a8b67ec8bef2f435e2dc8cc233e31a1721 (diff) |
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>
-rw-r--r-- | src/widgets/styles/qmacstyle_mac.mm | 26 | ||||
-rw-r--r-- | src/widgets/styles/qmacstyle_mac_p_p.h | 2 |
2 files changed, 25 insertions, 3 deletions
diff --git a/src/widgets/styles/qmacstyle_mac.mm b/src/widgets/styles/qmacstyle_mac.mm index 906bc85fa6..fafe9c9e2c 100644 --- a/src/widgets/styles/qmacstyle_mac.mm +++ b/src/widgets/styles/qmacstyle_mac.mm @@ -1066,9 +1066,10 @@ void QMacStylePrivate::drawFocusRing(QPainter *p, const QRect &targetRect, int h } #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(iconRect); QRect tr = opt->rect; const bool verticalTabs = opt->shape == QTabBar::RoundedEast || opt->shape == QTabBar::RoundedWest @@ -1102,6 +1103,26 @@ void QMacStylePrivate::tabLayout(const QStyleOptionTab *opt, const QWidget *widg 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) tr = proxyStyle->visualRect(opt->direction, opt->rect, tr); @@ -4967,7 +4988,8 @@ QRect QMacStyle::subElementRect(SubElement sr, const QStyleOption *opt, break; case SE_TabBarTabText: if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) { - d->tabLayout(tab, widget, &rect); + QRect dummyIconRect; + d->tabLayout(tab, widget, &rect, &dummyIconRect); } break; case SE_TabBarTabLeftButton: diff --git a/src/widgets/styles/qmacstyle_mac_p_p.h b/src/widgets/styles/qmacstyle_mac_p_p.h index 1201ae3955..2b388091a6 100644 --- a/src/widgets/styles/qmacstyle_mac_p_p.h +++ b/src/widgets/styles/qmacstyle_mac_p_p.h @@ -231,7 +231,7 @@ public: void drawFocusRing(QPainter *p, const QRect &targetRect, int hMargin, int vMargin, qreal radius = 0) const; #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 public: |