diff --git a/src/DockAreaTitleBar.cpp b/src/DockAreaTitleBar.cpp index e8c3991..255acd8 100644 --- a/src/DockAreaTitleBar.cpp +++ b/src/DockAreaTitleBar.cpp @@ -182,7 +182,7 @@ void DockAreaTitleBarPrivate::createButtons() TabsMenuButton->setObjectName("tabsMenuButton"); TabsMenuButton->setAutoRaise(true); TabsMenuButton->setPopupMode(QToolButton::InstantPopup); - internal::setButtonIcon(TabsMenuButton, QStyle::SP_TitleBarUnshadeButton, ads::DockAreaMenuIcon); + internal::setButtonIcon(TabsMenuButton, QStyle::SP_TitleBarUnshadeButton, _this->titleBarButtonCustomIcon(TitleBarButtonTabsMenu)); QMenu* TabsMenu = new QMenu(TabsMenuButton); #ifndef QT_NO_TOOLTIP TabsMenu->setToolTipsVisible(true); @@ -200,7 +200,7 @@ void DockAreaTitleBarPrivate::createButtons() UndockButton->setObjectName("detachGroupButton"); UndockButton->setAutoRaise(true); internal::setToolTip(UndockButton, QObject::tr("Detach Group")); - internal::setButtonIcon(UndockButton, QStyle::SP_TitleBarNormalButton, ads::DockAreaUndockIcon); + internal::setButtonIcon(UndockButton, QStyle::SP_TitleBarNormalButton, _this->titleBarButtonCustomIcon(TitleBarButtonUndock)); UndockButton->setSizePolicy(ButtonSizePolicy); Layout->addWidget(UndockButton, 0); _this->connect(UndockButton, SIGNAL(clicked()), SLOT(onUndockButtonClicked())); @@ -211,7 +211,7 @@ void DockAreaTitleBarPrivate::createButtons() AutoHideButton->setObjectName("dockAreaAutoHideButton"); AutoHideButton->setAutoRaise(true); internal::setToolTip(AutoHideButton, _this->titleBarButtonToolTip(TitleBarButtonAutoHide)); - internal::setButtonIcon(AutoHideButton, QStyle::SP_DialogOkButton, ads::AutoHideIcon); + internal::setButtonIcon(AutoHideButton, QStyle::SP_DialogOkButton, _this->titleBarButtonCustomIcon(TitleBarButtonAutoHide)); AutoHideButton->setSizePolicy(ButtonSizePolicy); AutoHideButton->setCheckable(testAutoHideConfigFlag(CDockManager::AutoHideButtonCheckable)); AutoHideButton->setChecked(false); @@ -222,7 +222,7 @@ void DockAreaTitleBarPrivate::createButtons() CloseButton = new CTitleBarButton(testConfigFlag(CDockManager::DockAreaHasCloseButton)); CloseButton->setObjectName("dockAreaCloseButton"); CloseButton->setAutoRaise(true); - internal::setButtonIcon(CloseButton, QStyle::SP_TitleBarCloseButton, ads::DockAreaCloseIcon); + internal::setButtonIcon(CloseButton, QStyle::SP_TitleBarCloseButton, _this->titleBarButtonCustomIcon(TitleBarButtonClose)); internal::setToolTip(CloseButton, _this->titleBarButtonToolTip(TitleBarButtonClose)); CloseButton->setSizePolicy(ButtonSizePolicy); CloseButton->setIconSize(QSize(16, 16)); @@ -831,6 +831,74 @@ QString CDockAreaTitleBar::titleBarButtonToolTip(TitleBarButton Button) const return QString(); } + +//============================================================================ +QIcon getAutoHideCustomIcon(TitleBarButton Button) +{ + switch (Button) + { + case TitleBarButtonTabsMenu: + { + return CDockManager::iconProvider().customIcon(AutoHideDockAreaMenuIcon); + } + case TitleBarButtonUndock: + { + return CDockManager::iconProvider().customIcon(AutoHideDockAreaUndockIcon); + } + case TitleBarButtonClose: + { + return CDockManager::iconProvider().customIcon(AutoHideDockAreaCloseIcon); + } + case TitleBarButtonAutoHide: + { + return CDockManager::iconProvider().customIcon(AutoHideAutoHideIcon); + } + } + return {}; +} + + +//============================================================================ +QIcon getCustomIcon(TitleBarButton Button) +{ + switch (Button) + { + case TitleBarButtonTabsMenu: + { + return CDockManager::iconProvider().customIcon(DockAreaMenuIcon); + } + case TitleBarButtonUndock: + { + return CDockManager::iconProvider().customIcon(DockAreaUndockIcon); + } + case TitleBarButtonClose: + { + return CDockManager::iconProvider().customIcon(DockAreaCloseIcon); + } + case TitleBarButtonAutoHide: + { + return CDockManager::iconProvider().customIcon(AutoHideIcon); + } + } + return {}; +} + + +//============================================================================ +QIcon CDockAreaTitleBar::titleBarButtonCustomIcon(TitleBarButton Button) const +{ + QIcon icon; + if (d->DockArea != nullptr && d->DockArea->isAutoHide()) + { + icon = getAutoHideCustomIcon(Button); + } + if (icon.isNull()) + { + icon = getCustomIcon(Button); + } + return icon; +} + //============================================================================ CTitleBarButton::CTitleBarButton(bool showInTitleBar, QWidget* parent) : tTitleBarButton(parent), diff --git a/src/DockAreaTitleBar.h b/src/DockAreaTitleBar.h index 2de2ed6..07e56af 100644 --- a/src/DockAreaTitleBar.h +++ b/src/DockAreaTitleBar.h @@ -204,6 +204,11 @@ public: */ QString titleBarButtonToolTip(TitleBarButton Button) const; + /** + * Custom icon based on the current state + */ + QIcon titleBarButtonCustomIcon(TitleBarButton Button) const; + /** * Moves the dock area into its own floating widget if the area * DockWidgetFloatable flag is true diff --git a/src/DockAreaWidget.cpp b/src/DockAreaWidget.cpp index 6a140bc..84d1300 100644 --- a/src/DockAreaWidget.cpp +++ b/src/DockAreaWidget.cpp @@ -467,6 +467,7 @@ void CDockAreaWidget::setAutoHideDockContainer(CAutoHideDockContainer* AutoHideD d->AutoHideDockContainer = AutoHideDockContainer; updateAutoHideButtonCheckState(); updateTitleBarButtonsToolTips(); + updateTitleBarButtonsIcons(); d->TitleBar->button(TitleBarButtonAutoHide)->setShowInTitleBar(true); } @@ -891,6 +892,21 @@ void CDockAreaWidget::updateTitleBarButtonsToolTips() titleBar()->titleBarButtonToolTip(TitleBarButtonAutoHide)); } +void CDockAreaWidget::updateTitleBarButtonsIcons() +{ + internal::setButtonIcon(titleBarButton(TitleBarButtonTabsMenu), + QStyle::SP_TitleBarUnshadeButton, + titleBar()->titleBarButtonCustomIcon(TitleBarButtonTabsMenu)); + internal::setButtonIcon(titleBarButton(TitleBarButtonUndock), + QStyle::SP_TitleBarNormalButton, + titleBar()->titleBarButtonCustomIcon(TitleBarButtonUndock)); + internal::setButtonIcon(titleBarButton(TitleBarButtonClose), + QStyle::SP_TitleBarCloseButton, + titleBar()->titleBarButtonCustomIcon(TitleBarButtonClose)); + internal::setButtonIcon(titleBarButton(TitleBarButtonAutoHide), + QStyle::SP_DialogOkButton, + titleBar()->titleBarButtonCustomIcon(TitleBarButtonAutoHide)); +} //============================================================================ void CDockAreaWidget::saveState(QXmlStreamWriter& s) const diff --git a/src/DockAreaWidget.h b/src/DockAreaWidget.h index e88153e..0385371 100644 --- a/src/DockAreaWidget.h +++ b/src/DockAreaWidget.h @@ -89,6 +89,11 @@ private Q_SLOTS: */ void updateTitleBarButtonsToolTips(); + /* + * Update the title bar button icons + */ + void updateTitleBarButtonsIcons(); + /** * Calculate the auto hide side bar location depending on the dock area * widget position in the container diff --git a/src/IconProvider.cpp b/src/IconProvider.cpp index 25e7be1..9c569c7 100644 --- a/src/IconProvider.cpp +++ b/src/IconProvider.cpp @@ -20,6 +20,7 @@ struct IconProviderPrivate { CIconProvider *_this; QVector UserIcons{IconCount, QIcon()}; + QVector UserAutoHideIcons{AutoHideIconCount, QIcon()}; /** * Private data constructor @@ -57,6 +58,14 @@ QIcon CIconProvider::customIcon(eIcon IconId) const } +//============================================================================ +QIcon CIconProvider::customIcon(eAutoHideIcon IconId) const +{ + Q_ASSERT(IconId < d->UserAutoHideIcons.size()); + return d->UserAutoHideIcons[IconId]; +} + + //============================================================================ void CIconProvider::registerCustomIcon(eIcon IconId, const QIcon &icon) { @@ -64,6 +73,14 @@ void CIconProvider::registerCustomIcon(eIcon IconId, const QIcon &icon) d->UserIcons[IconId] = icon; } + +//============================================================================ +void CIconProvider::registerCustomIcon(eAutoHideIcon IconId, const QIcon &icon) +{ + Q_ASSERT(IconId < d->UserAutoHideIcons.size()); + d->UserAutoHideIcons[IconId] = icon; +} + } // namespace ads diff --git a/src/IconProvider.h b/src/IconProvider.h index fa7d150..a1662c8 100644 --- a/src/IconProvider.h +++ b/src/IconProvider.h @@ -47,11 +47,13 @@ public: * if no custom icon is registered */ QIcon customIcon(eIcon IconId) const; + QIcon customIcon(eAutoHideIcon IconId) const; - /** + /** * Registers a custom icon for the given IconId */ void registerCustomIcon(eIcon IconId, const QIcon &icon); + void registerCustomIcon(eAutoHideIcon IconId, const QIcon& icon); }; // class IconProvider } // namespace ads diff --git a/src/ads_globals.cpp b/src/ads_globals.cpp index dd0b33c..26d52cf 100644 --- a/src/ads_globals.cpp +++ b/src/ads_globals.cpp @@ -412,17 +412,35 @@ void setButtonIcon(QAbstractButton* Button, QStyle::StandardPixmap StandarPixmap return; } + Button->setIcon(getStandardPixmapIcon(Button, StandarPixmap)); +} + +void setButtonIcon(QAbstractButton *Button, QStyle::StandardPixmap StandardPixmap, QIcon Icon) + { + // First we try to use custom icons if available + if (!Icon.isNull()) + { + Button->setIcon(Icon); + return; + } + Button->setIcon(getStandardPixmapIcon(Button, StandardPixmap)); + } + +//============================================================================ +QIcon getStandardPixmapIcon(QAbstractButton* Button, QStyle::StandardPixmap Pixmap) + { #if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS) - Button->setIcon(Button->style()->standardIcon(StandarPixmap)); + return Button->style()->standardIcon(Pixmap); #else // The standard icons does not look good on high DPI screens so we create // our own "standard" icon here. - QPixmap normalPixmap = Button->style()->standardPixmap(StandarPixmap, 0, Button); - Icon.addPixmap(internal::createTransparentPixmap(normalPixmap, 0.25), QIcon::Disabled); - Icon.addPixmap(normalPixmap, QIcon::Normal); - Button->setIcon(Icon); + const QPixmap normalPixmap = Button->style()->standardPixmap(Pixmap, 0, Button); + QIcon icon; + icon.addPixmap(internal::createTransparentPixmap(normalPixmap, 0.25), QIcon::Disabled); + icon.addPixmap(normalPixmap, QIcon::Normal); + return icon; #endif -} + } //============================================================================ diff --git a/src/ads_globals.h b/src/ads_globals.h index d2460f5..ceafcf7 100644 --- a/src/ads_globals.h +++ b/src/ads_globals.h @@ -135,6 +135,19 @@ enum eIcon IconCount, //!< just a delimiter for range checks }; +/** + * The different icons used in the UI for Auto Hide + */ +enum eAutoHideIcon +{ + AutoHideAutoHideIcon, //!< AutoHideIcon + AutoHideDockAreaMenuIcon, //!< DockAreaMenuIcon + AutoHideDockAreaUndockIcon,//!< DockAreaUndockIcon + AutoHideDockAreaCloseIcon, //!< DockAreaCloseIcon + + AutoHideIconCount, //!< just a delimiter for range checks +}; + /** * For bitwise combination of dock wdget features */ @@ -344,6 +357,14 @@ void setButtonIcon(QAbstractButton* Button, QStyle::StandardPixmap StandarPixmap ads::eIcon CustomIconId); +void setButtonIcon(QAbstractButton* Button, QStyle::StandardPixmap StandardPixmap, QIcon Icon); + + +/** + * Return the icon of standard pixmap for button. + */ +QIcon getStandardPixmapIcon(QAbstractButton* Button, QStyle::StandardPixmap Pixmap); + enum eRepolishChildOptions { RepolishIgnoreChildren,