From aedbaec4979162c7f56c4dee842be298973218fb Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Sat, 31 Oct 2020 13:56:16 +0100 Subject: [PATCH] Addes support for setting DockWidgetTab icon size via stylesheet --- src/DockWidgetTab.cpp | 44 ++++++++++++++++++++++---- src/DockWidgetTab.h | 16 ++++++++++ src/stylesheets/focus_highlighting.css | 1 + 3 files changed, 55 insertions(+), 6 deletions(-) diff --git a/src/DockWidgetTab.cpp b/src/DockWidgetTab.cpp index f4a1ae93..ca299fef 100644 --- a/src/DockWidgetTab.cpp +++ b/src/DockWidgetTab.cpp @@ -51,7 +51,6 @@ #include "DockManager.h" #include "IconProvider.h" -#include namespace ads { @@ -77,6 +76,7 @@ struct DockWidgetTabPrivate QAbstractButton* CloseButton = nullptr; QSpacerItem* IconTextSpacer; QPoint TabDragStartPosition; + QSize IconSize; /** * Private data constructor @@ -186,6 +186,27 @@ struct DockWidgetTabPrivate DragStartMousePosition = _this->mapFromGlobal(GlobalPos); } + /** + * Update the icon in case the icon size changed + */ + void updateIcon() + { + if (!IconLabel || Icon.isNull()) + { + return; + } + + if (IconSize.isValid()) + { + IconLabel->setPixmap(Icon.pixmap(IconSize)); + } + else + { + IconLabel->setPixmap(Icon.pixmap(_this->style()->pixelMetric(QStyle::PM_SmallIconSize, nullptr, _this))); + } + IconLabel->setVisible(true); + } + }; // struct DockWidgetTabPrivate @@ -570,11 +591,7 @@ void CDockWidgetTab::setIcon(const QIcon& Icon) } d->Icon = Icon; - if (d->IconLabel) - { - d->IconLabel->setPixmap(Icon.pixmap(style()->pixelMetric(QStyle::PM_SmallIconSize, nullptr, this))); - d->IconLabel->setVisible(true); - } + d->updateIcon(); } @@ -688,6 +705,21 @@ void CDockWidgetTab::updateStyle() } +//============================================================================ +QSize CDockWidgetTab::iconSize() const +{ + return d->IconSize; +} + + +//============================================================================ +void CDockWidgetTab::setIconSize(const QSize& Size) +{ + d->IconSize = Size; + d->updateIcon(); +} + + } // namespace ads diff --git a/src/DockWidgetTab.h b/src/DockWidgetTab.h index 3ed7df89..6135cc79 100644 --- a/src/DockWidgetTab.h +++ b/src/DockWidgetTab.h @@ -31,6 +31,7 @@ // INCLUDES //============================================================================ #include +#include #include "ads_globals.h" @@ -50,6 +51,7 @@ class ADS_EXPORT CDockWidgetTab : public QFrame { Q_OBJECT Q_PROPERTY(bool activeTab READ isActiveTab WRITE setActiveTab NOTIFY activeTabChanged) + Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize) private: DockWidgetTabPrivate* d; ///< private data (pimpl) @@ -159,6 +161,20 @@ private slots: */ void updateStyle(); + /** + * Returns the icon size. + * If no explicit icon size has been set, the function returns an invalid + * QSize + */ + QSize iconSize() const; + + /** + * Set an explicit icon size. + * If no icon size has been set explicitely, than the tab sets the icon size + * depending on the style + */ + void setIconSize(const QSize& Size); + public slots: virtual void setVisible(bool visible) override; diff --git a/src/stylesheets/focus_highlighting.css b/src/stylesheets/focus_highlighting.css index e954b0d7..50f80e6c 100644 --- a/src/stylesheets/focus_highlighting.css +++ b/src/stylesheets/focus_highlighting.css @@ -16,6 +16,7 @@ ads--CDockWidgetTab { border-style: solid; border-width: 0 1px 0 0; padding: 0 0px; + qproperty-iconSize: 16px 16px;/* this is optional in case you would like to change icon size*/ } ads--CDockWidgetTab[activeTab="true"] {