From fa94da00d4603f37bd9f5e689d5a28f875ebeda6 Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Mon, 6 Nov 2023 11:06:12 +0100 Subject: [PATCH] Added optional Minimize button to AutoHide dock widget title bar --- src/DockAreaTitleBar.cpp | 39 ++++++++++++++++---- src/DockAreaTitleBar.h | 7 +++- src/DockAreaWidget.cpp | 23 ++++++++---- src/DockManager.h | 3 ++ src/ads.qrc | 2 + src/ads_globals.h | 4 +- src/images/minimize-button-focused.svg | 2 + src/images/minimize-button.svg | 2 + src/stylesheets/default.css | 6 +++ src/stylesheets/default_linux.css | 6 +++ src/stylesheets/focus_highlighting.css | 6 +++ src/stylesheets/focus_highlighting_linux.css | 6 +++ 12 files changed, 89 insertions(+), 17 deletions(-) create mode 100644 src/images/minimize-button-focused.svg create mode 100644 src/images/minimize-button.svg diff --git a/src/DockAreaTitleBar.cpp b/src/DockAreaTitleBar.cpp index e8c3991..ee050f6 100644 --- a/src/DockAreaTitleBar.cpp +++ b/src/DockAreaTitleBar.cpp @@ -72,10 +72,11 @@ struct DockAreaTitleBarPrivate QPointer AutoHideButton; QPointer UndockButton; QPointer CloseButton; + QPointer MinimizeButton; QBoxLayout* Layout; CDockAreaWidget* DockArea; CDockAreaTabBar* TabBar; - CElidingLabel* AutoHideTitleLabel; + CElidingLabel* AutoHideTitleLabel = nullptr; bool MenuOutdated = true; QMenu* TabsMenu; QList DockWidgetActionsButtons; @@ -218,6 +219,17 @@ void DockAreaTitleBarPrivate::createButtons() Layout->addWidget(AutoHideButton, 0); _this->connect(AutoHideButton, SIGNAL(clicked()), SLOT(onAutoHideButtonClicked())); + // Minimize button + MinimizeButton = new CTitleBarButton(testAutoHideConfigFlag(CDockManager::AutoHideHasMinimizeButton)); + MinimizeButton->setObjectName("dockAreaMinimizeButton"); + MinimizeButton->setAutoRaise(true); + MinimizeButton->setVisible(false); + internal::setButtonIcon(MinimizeButton, QStyle::SP_TitleBarMinButton, ads::DockAreaMinimizeIcon); + internal::setToolTip(MinimizeButton, QObject::tr("Minimize")); + MinimizeButton->setSizePolicy(ButtonSizePolicy); + Layout->addWidget(MinimizeButton, 0); + _this->connect(MinimizeButton, SIGNAL(clicked()), SLOT(minimizeAutoHideContainer())); + // Close button CloseButton = new CTitleBarButton(testConfigFlag(CDockManager::DockAreaHasCloseButton)); CloseButton->setObjectName("dockAreaCloseButton"); @@ -236,7 +248,10 @@ void DockAreaTitleBarPrivate::createAutoHideTitleLabel() { AutoHideTitleLabel = new CElidingLabel(""); AutoHideTitleLabel->setObjectName("autoHideTitleLabel"); - Layout->addWidget(AutoHideTitleLabel); + // At position 0 is the tab bar - insert behind tab bar + Layout->insertWidget(1, AutoHideTitleLabel); + AutoHideTitleLabel->setVisible(false); // Default hidden + Layout->insertWidget(2 ,new CSpacerWidget(_this)); } @@ -324,10 +339,8 @@ CDockAreaTitleBar::CDockAreaTitleBar(CDockAreaWidget* parent) : setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); d->createTabBar(); - d->createAutoHideTitleLabel(); - d->AutoHideTitleLabel->setVisible(false); // Default hidden - d->Layout->addWidget(new CSpacerWidget(this)); d->createButtons(); + d->createAutoHideTitleLabel(); setFocusPolicy(Qt::NoFocus); } @@ -439,7 +452,7 @@ void CDockAreaTitleBar::onAutoHideCloseActionTriggered() //============================================================================ -void CDockAreaTitleBar::onAutoHideMinimizeActionTriggered() +void CDockAreaTitleBar::minimizeAutoHideContainer() { auto AutoHideContainer = d->DockArea->autoHideDockContainer(); if (AutoHideContainer) @@ -565,6 +578,7 @@ CTitleBarButton* CDockAreaTitleBar::button(TitleBarButton which) const case TitleBarButtonUndock: return d->UndockButton; case TitleBarButtonClose: return d->CloseButton; case TitleBarButtonAutoHide: return d->AutoHideButton; + case TitleBarButtonMinimize: return d->MinimizeButton; default: return nullptr; } @@ -756,7 +770,7 @@ void CDockAreaTitleBar::contextMenuEvent(QContextMenuEvent* ev) if (isAutoHide) { - Action = Menu.addAction(tr("Minimize"), this, SLOT(onAutoHideMinimizeActionTriggered())); + Action = Menu.addAction(tr("Minimize"), this, SLOT(minimizeAutoHideContainer())); Action = Menu.addAction(tr("Close"), this, SLOT(onAutoHideCloseActionTriggered())); } else @@ -831,6 +845,16 @@ QString CDockAreaTitleBar::titleBarButtonToolTip(TitleBarButton Button) const return QString(); } + +//============================================================================ +void CDockAreaTitleBar::showAutoHideControls(bool Show) +{ + d->TabBar->setVisible(!Show); // Auto hide toolbar never has tabs + d->MinimizeButton->setVisible(Show); + d->AutoHideTitleLabel->setVisible(Show); +} + + //============================================================================ CTitleBarButton::CTitleBarButton(bool showInTitleBar, QWidget* parent) : tTitleBarButton(parent), @@ -887,6 +911,7 @@ CSpacerWidget::CSpacerWidget(QWidget* Parent /*= 0*/) : Super(Parent) setStyleSheet("border: none; background: none;"); } + } // namespace ads //--------------------------------------------------------------------------- diff --git a/src/DockAreaTitleBar.h b/src/DockAreaTitleBar.h index 2de2ed6..77c8f94 100644 --- a/src/DockAreaTitleBar.h +++ b/src/DockAreaTitleBar.h @@ -98,7 +98,7 @@ private Q_SLOTS: void onTabsMenuAboutToShow(); void onCloseButtonClicked(); void onAutoHideCloseActionTriggered(); - void onAutoHideMinimizeActionTriggered(); + void minimizeAutoHideContainer(); void onUndockButtonClicked(); void onTabsMenuActionTriggered(QAction* Action); void onCurrentTabChanged(int Index); @@ -210,6 +210,11 @@ public: */ void setAreaFloating(); + /** + * Call this function, to create all the required auto hide controls + */ + void showAutoHideControls(bool Show); + Q_SIGNALS: /** * This signal is emitted if a tab in the tab bar is clicked by the user diff --git a/src/DockAreaWidget.cpp b/src/DockAreaWidget.cpp index 6a140bc..a47aa5b 100644 --- a/src/DockAreaWidget.cpp +++ b/src/DockAreaWidget.cpp @@ -390,20 +390,29 @@ void DockAreaWidgetPrivate::updateTitleBarButtonVisibility(bool IsTopLevel) return; } - if (IsTopLevel) + bool IsAutoHide = _this->isAutoHide(); + if (IsAutoHide) + { + bool ShowCloseButton = CDockManager::autoHideConfigFlags().testFlag(CDockManager::AutoHideHasCloseButton); + TitleBar->button(TitleBarButtonClose)->setVisible(ShowCloseButton); + TitleBar->button(TitleBarButtonAutoHide)->setVisible(true); + TitleBar->button(TitleBarButtonUndock)->setVisible(false); + TitleBar->button(TitleBarButtonTabsMenu)->setVisible(false); + } + else if (IsTopLevel) { TitleBar->button(TitleBarButtonClose)->setVisible(!container->isFloating()); TitleBar->button(TitleBarButtonAutoHide)->setVisible(!container->isFloating()); // Undock and tabs should never show when auto hidden - TitleBar->button(TitleBarButtonUndock)->setVisible(!container->isFloating() && !_this->isAutoHide()); - TitleBar->button(TitleBarButtonTabsMenu)->setVisible(!_this->isAutoHide()); + TitleBar->button(TitleBarButtonUndock)->setVisible(!container->isFloating()); + TitleBar->button(TitleBarButtonTabsMenu)->setVisible(true); } else { TitleBar->button(TitleBarButtonClose)->setVisible(true); TitleBar->button(TitleBarButtonAutoHide)->setVisible(true); - TitleBar->button(TitleBarButtonUndock)->setVisible(!_this->isAutoHide()); - TitleBar->button(TitleBarButtonTabsMenu)->setVisible(!_this->isAutoHide()); + TitleBar->button(TitleBarButtonUndock)->setVisible(true); + TitleBar->button(TitleBarButtonTabsMenu)->setVisible(true); } } @@ -847,9 +856,7 @@ void CDockAreaWidget::updateTitleBarVisibility() if (isAutoHideFeatureEnabled()) { - auto tabBar = d->TitleBar->tabBar(); - tabBar->setVisible(!IsAutoHide); // Never show tab bar when auto hidden - d->TitleBar->autoHideTitleLabel()->setVisible(IsAutoHide); // Always show when auto hidden, never otherwise + d->TitleBar->showAutoHideControls(IsAutoHide); updateTitleBarButtonVisibility(Container->topLevelDockArea() == this); } } diff --git a/src/DockManager.h b/src/DockManager.h index 85482d0..973c078 100644 --- a/src/DockManager.h +++ b/src/DockManager.h @@ -251,10 +251,13 @@ public: AutoHideSideBarsIconOnly = 0x10,///< show only icons in auto hide side tab - if a tab has no icon, then the text will be shown AutoHideShowOnMouseOver = 0x20, ///< show the auto hide window on mouse over tab and hide it if mouse leaves auto hide container AutoHideCloseButtonCollapsesDock = 0x40, ///< Close button of an auto hide container collapses the dock instead of hiding it completely + AutoHideHasCloseButton = 0x80, //< If the flag is set an auto hide title bar has a close button + AutoHideHasMinimizeButton = 0x100, ///< if this flag is set, the auto hide title bar has a minimize button to collapse the dock widget DefaultAutoHideConfig = AutoHideFeatureEnabled | DockAreaHasAutoHideButton | AutoHideCloseButtonCollapsesDock + | AutoHideHasCloseButton }; Q_DECLARE_FLAGS(AutoHideFlags, eAutoHideFlag) diff --git a/src/ads.qrc b/src/ads.qrc index fb68e40..b067f82 100644 --- a/src/ads.qrc +++ b/src/ads.qrc @@ -20,5 +20,7 @@ images/vs-pin-button-pinned-focused.svg images/vs-pin-button_45.svg images/pin-button-big.svg + images/minimize-button.svg + images/minimize-button-focused.svg diff --git a/src/ads_globals.h b/src/ads_globals.h index d2460f5..af8f078 100644 --- a/src/ads_globals.h +++ b/src/ads_globals.h @@ -107,7 +107,8 @@ enum TitleBarButton TitleBarButtonTabsMenu, TitleBarButtonUndock, TitleBarButtonClose, - TitleBarButtonAutoHide + TitleBarButtonAutoHide, + TitleBarButtonMinimize }; /** @@ -131,6 +132,7 @@ enum eIcon DockAreaMenuIcon, //!< DockAreaMenuIcon DockAreaUndockIcon,//!< DockAreaUndockIcon DockAreaCloseIcon, //!< DockAreaCloseIcon + DockAreaMinimizeIcon, IconCount, //!< just a delimiter for range checks }; diff --git a/src/images/minimize-button-focused.svg b/src/images/minimize-button-focused.svg new file mode 100644 index 0000000..c473a13 --- /dev/null +++ b/src/images/minimize-button-focused.svg @@ -0,0 +1,2 @@ + + diff --git a/src/images/minimize-button.svg b/src/images/minimize-button.svg new file mode 100644 index 0000000..78df69e --- /dev/null +++ b/src/images/minimize-button.svg @@ -0,0 +1,2 @@ + + diff --git a/src/stylesheets/default.css b/src/stylesheets/default.css index 83d1e32..cef3ad0 100644 --- a/src/stylesheets/default.css +++ b/src/stylesheets/default.css @@ -298,6 +298,12 @@ ads--CAutoHideDockContainer #dockAreaAutoHideButton { } +ads--CAutoHideDockContainer #dockAreaMinimizeButton { + qproperty-icon: url(:/ads/images/minimize-button-focused.svg); + qproperty-iconSize: 16px; +} + + ads--CAutoHideDockContainer #dockAreaCloseButton{ qproperty-icon: url(:/ads/images/close-button-focused.svg) } diff --git a/src/stylesheets/default_linux.css b/src/stylesheets/default_linux.css index 573d7df..d02d42d 100644 --- a/src/stylesheets/default_linux.css +++ b/src/stylesheets/default_linux.css @@ -334,6 +334,12 @@ ads--CAutoHideDockContainer #dockAreaAutoHideButton { } +ads--CAutoHideDockContainer #dockAreaMinimizeButton { + qproperty-icon: url(:/ads/images/minimize-button-focused.svg); + qproperty-iconSize: 16px; +} + + ads--CAutoHideDockContainer #dockAreaCloseButton{ qproperty-icon: url(:/ads/images/close-button-focused.svg) } diff --git a/src/stylesheets/focus_highlighting.css b/src/stylesheets/focus_highlighting.css index 0fd9f18..0855157 100644 --- a/src/stylesheets/focus_highlighting.css +++ b/src/stylesheets/focus_highlighting.css @@ -336,6 +336,12 @@ ads--CAutoHideDockContainer #dockAreaAutoHideButton { } +ads--CAutoHideDockContainer #dockAreaMinimizeButton { + qproperty-icon: url(:/ads/images/minimize-button-focused.svg); + qproperty-iconSize: 16px; +} + + ads--CAutoHideDockContainer #dockAreaCloseButton{ qproperty-icon: url(:/ads/images/close-button-focused.svg) } diff --git a/src/stylesheets/focus_highlighting_linux.css b/src/stylesheets/focus_highlighting_linux.css index f21b137..54d0b47 100644 --- a/src/stylesheets/focus_highlighting_linux.css +++ b/src/stylesheets/focus_highlighting_linux.css @@ -411,6 +411,12 @@ ads--CAutoHideDockContainer #dockAreaAutoHideButton { } +ads--CAutoHideDockContainer #dockAreaMinimizeButton { + qproperty-icon: url(:/ads/images/minimize-button-focused.svg); + qproperty-iconSize: 16px; +} + + ads--CAutoHideDockContainer #dockAreaCloseButton{ qproperty-icon: url(:/ads/images/close-button-focused.svg) }