Skip to content

Commit

Permalink
Addes support for setting DockWidgetTab icon size via stylesheet
Browse files Browse the repository at this point in the history
  • Loading branch information
githubuser0xFFFF committed Oct 31, 2020
1 parent f6d3d6d commit aedbaec
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 6 deletions.
44 changes: 38 additions & 6 deletions src/DockWidgetTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
#include "DockManager.h"
#include "IconProvider.h"

#include <iostream>

namespace ads
{
Expand All @@ -77,6 +76,7 @@ struct DockWidgetTabPrivate
QAbstractButton* CloseButton = nullptr;
QSpacerItem* IconTextSpacer;
QPoint TabDragStartPosition;
QSize IconSize;

/**
* Private data constructor
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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();
}


Expand Down Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions src/DockWidgetTab.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
// INCLUDES
//============================================================================
#include <QFrame>
#include <QSize>

#include "ads_globals.h"

Expand All @@ -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)
Expand Down Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions src/stylesheets/focus_highlighting.css
Original file line number Diff line number Diff line change
Expand Up @@ -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"] {
Expand Down

0 comments on commit aedbaec

Please sign in to comment.