diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2021-07-19 14:02:10 +0200 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2021-07-20 15:20:21 +0200 |
commit | aa5a595a98f1af4a514485268a18e6cb9cfec783 (patch) | |
tree | 0482cf97089a3d19d9710a86f0f836ad41171b56 /src/widgets/styles | |
parent | 33c916577389fa6607b0b2f6a78da4a0eb485000 (diff) |
QStyle: Add SP_TabCloseButton
Move the static tabBarCloseButtonIcon helper into the standardIcon()
implementation, simplified by using QIcon::addFile and the
iconResourcePrefix helper.
Add corresponding support in standardPixmap().
Use standardIcon() in PE_IndicatorTabClose where tabBarCloseButtonIcon()
was previously used to get the icon, leave the caching in place.
Fixes: QTBUG-95264
Change-Id: I89c161734553db762caa29f8ab738e3c6e64ea0a
Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'src/widgets/styles')
-rw-r--r-- | src/widgets/styles/qcommonstyle.cpp | 42 | ||||
-rw-r--r-- | src/widgets/styles/qstyle.cpp | 2 | ||||
-rw-r--r-- | src/widgets/styles/qstyle.h | 1 |
3 files changed, 20 insertions, 25 deletions
diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index 9d09fbe2b5..d784315ca7 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -126,30 +126,6 @@ static qreal qt_getDevicePixelRatio(const QWidget *widget) return widget ? widget->devicePixelRatio() : qApp->devicePixelRatio(); } -static QIcon tabBarCloseButtonIcon() -{ - QIcon result; - result.addPixmap(QPixmap( - QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-closetab-16.png")), - QIcon::Normal, QIcon::Off); - result.addPixmap(QPixmap( - QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-closetab-32.png")), - QIcon::Normal, QIcon::Off); - result.addPixmap(QPixmap( - QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-closetab-down-16.png")), - QIcon::Normal, QIcon::On); - result.addPixmap(QPixmap( - QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-closetab-down-32.png")), - QIcon::Normal, QIcon::On); - result.addPixmap(QPixmap( - QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-closetab-hover-16.png")), - QIcon::Active, QIcon::Off); - result.addPixmap(QPixmap( - QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-closetab-hover-32.png")), - QIcon::Active, QIcon::Off); - return result; -} - /*! \class QCommonStyle \brief The QCommonStyle class encapsulates the common Look and Feel of a GUI. @@ -441,7 +417,7 @@ void QCommonStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, Q break; case PE_IndicatorTabClose: { if (d->tabBarcloseButtonIcon.isNull()) - d->tabBarcloseButtonIcon = tabBarCloseButtonIcon(); + d->tabBarcloseButtonIcon = proxy()->standardIcon(QStyle::SP_TabCloseButton, opt, widget); const int size = proxy()->pixelMetric(QStyle::PM_SmallIconSize, opt); QIcon::Mode mode = opt->state & State_Enabled ? @@ -5775,6 +5751,8 @@ QPixmap QCommonStyle::standardPixmap(StandardPixmap sp, const QStyleOption *opti return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/media-volume-muted-16.png")); case SP_LineEditClearButton: return QPixmap(clearText16IconPath()); + case SP_TabCloseButton: + return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-closetab-16.png")); #endif // QT_NO_IMAGEFORMAT_PNG default: break; @@ -6392,6 +6370,20 @@ QIcon QCommonStyle::standardIcon(StandardPixmap standardIcon, const QStyleOption toolBarExtVSizes, sizeof(toolBarExtVSizes)/sizeof(toolBarExtVSizes[0]), icon); break; #endif // QT_NO_IMAGEFORMAT_PNG + case SP_TabCloseButton: + icon.addFile(iconResourcePrefix() + u"standardbutton-closetab-16.png", QSize(16, 16), + QIcon::Normal, QIcon::Off); + icon.addFile(iconResourcePrefix() + u"standardbutton-closetab-32.png", QSize(32, 32), + QIcon::Normal, QIcon::Off); + icon.addFile(iconResourcePrefix() + u"standardbutton-closetab-down-16.png", QSize(16, 16), + QIcon::Normal, QIcon::On); + icon.addFile(iconResourcePrefix() + u"standardbutton-closetab-down-32.png", QSize(32, 32), + QIcon::Normal, QIcon::On); + icon.addFile(iconResourcePrefix() + u"standardbutton-closetab-hover-16.png", QSize(16, 16), + QIcon::Active, QIcon::Off); + icon.addFile(iconResourcePrefix() + u"standardbutton-closetab-hover-16.png", QSize(32, 32), + QIcon::Active, QIcon::Off); + break; default: icon.addPixmap(proxy()->standardPixmap(standardIcon, option, widget)); break; diff --git a/src/widgets/styles/qstyle.cpp b/src/widgets/styles/qstyle.cpp index 5e760b4531..368eda3396 100644 --- a/src/widgets/styles/qstyle.cpp +++ b/src/widgets/styles/qstyle.cpp @@ -2124,6 +2124,8 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, This enum value was added in Qt 5.14. \value SP_RestoreDefaultsButton Icon for a standard RestoreDefaults button in a QDialogButtonBox. This enum value was added in Qt 5.14. + \value SP_TabCloseButton Icon for the close button in the tab of a QTabBar. + This enum value was added in Qt 6.3. \value SP_CustomBase Base value for custom standard pixmaps; custom values must be greater than this value. diff --git a/src/widgets/styles/qstyle.h b/src/widgets/styles/qstyle.h index 66768be671..fc94ed2bf5 100644 --- a/src/widgets/styles/qstyle.h +++ b/src/widgets/styles/qstyle.h @@ -825,6 +825,7 @@ public: SP_DialogRetryButton, SP_DialogIgnoreButton, SP_RestoreDefaultsButton, + SP_TabCloseButton, // do not add any values below/greater than this SP_CustomBase = 0xf0000000 }; |