Added optional Minimize button to AutoHide dock widget title bar

This commit is contained in:
Uwe Kindler 2023-11-06 11:06:12 +01:00
parent 420baeedfe
commit fa94da00d4
12 changed files with 89 additions and 17 deletions

View File

@ -72,10 +72,11 @@ struct DockAreaTitleBarPrivate
QPointer<CTitleBarButton> AutoHideButton; QPointer<CTitleBarButton> AutoHideButton;
QPointer<CTitleBarButton> UndockButton; QPointer<CTitleBarButton> UndockButton;
QPointer<CTitleBarButton> CloseButton; QPointer<CTitleBarButton> CloseButton;
QPointer<CTitleBarButton> MinimizeButton;
QBoxLayout* Layout; QBoxLayout* Layout;
CDockAreaWidget* DockArea; CDockAreaWidget* DockArea;
CDockAreaTabBar* TabBar; CDockAreaTabBar* TabBar;
CElidingLabel* AutoHideTitleLabel; CElidingLabel* AutoHideTitleLabel = nullptr;
bool MenuOutdated = true; bool MenuOutdated = true;
QMenu* TabsMenu; QMenu* TabsMenu;
QList<tTitleBarButton*> DockWidgetActionsButtons; QList<tTitleBarButton*> DockWidgetActionsButtons;
@ -218,6 +219,17 @@ void DockAreaTitleBarPrivate::createButtons()
Layout->addWidget(AutoHideButton, 0); Layout->addWidget(AutoHideButton, 0);
_this->connect(AutoHideButton, SIGNAL(clicked()), SLOT(onAutoHideButtonClicked())); _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 // Close button
CloseButton = new CTitleBarButton(testConfigFlag(CDockManager::DockAreaHasCloseButton)); CloseButton = new CTitleBarButton(testConfigFlag(CDockManager::DockAreaHasCloseButton));
CloseButton->setObjectName("dockAreaCloseButton"); CloseButton->setObjectName("dockAreaCloseButton");
@ -236,7 +248,10 @@ void DockAreaTitleBarPrivate::createAutoHideTitleLabel()
{ {
AutoHideTitleLabel = new CElidingLabel(""); AutoHideTitleLabel = new CElidingLabel("");
AutoHideTitleLabel->setObjectName("autoHideTitleLabel"); 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); setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
d->createTabBar(); d->createTabBar();
d->createAutoHideTitleLabel();
d->AutoHideTitleLabel->setVisible(false); // Default hidden
d->Layout->addWidget(new CSpacerWidget(this));
d->createButtons(); d->createButtons();
d->createAutoHideTitleLabel();
setFocusPolicy(Qt::NoFocus); setFocusPolicy(Qt::NoFocus);
} }
@ -439,7 +452,7 @@ void CDockAreaTitleBar::onAutoHideCloseActionTriggered()
//============================================================================ //============================================================================
void CDockAreaTitleBar::onAutoHideMinimizeActionTriggered() void CDockAreaTitleBar::minimizeAutoHideContainer()
{ {
auto AutoHideContainer = d->DockArea->autoHideDockContainer(); auto AutoHideContainer = d->DockArea->autoHideDockContainer();
if (AutoHideContainer) if (AutoHideContainer)
@ -565,6 +578,7 @@ CTitleBarButton* CDockAreaTitleBar::button(TitleBarButton which) const
case TitleBarButtonUndock: return d->UndockButton; case TitleBarButtonUndock: return d->UndockButton;
case TitleBarButtonClose: return d->CloseButton; case TitleBarButtonClose: return d->CloseButton;
case TitleBarButtonAutoHide: return d->AutoHideButton; case TitleBarButtonAutoHide: return d->AutoHideButton;
case TitleBarButtonMinimize: return d->MinimizeButton;
default: default:
return nullptr; return nullptr;
} }
@ -756,7 +770,7 @@ void CDockAreaTitleBar::contextMenuEvent(QContextMenuEvent* ev)
if (isAutoHide) 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())); Action = Menu.addAction(tr("Close"), this, SLOT(onAutoHideCloseActionTriggered()));
} }
else else
@ -831,6 +845,16 @@ QString CDockAreaTitleBar::titleBarButtonToolTip(TitleBarButton Button) const
return QString(); 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) CTitleBarButton::CTitleBarButton(bool showInTitleBar, QWidget* parent)
: tTitleBarButton(parent), : tTitleBarButton(parent),
@ -887,6 +911,7 @@ CSpacerWidget::CSpacerWidget(QWidget* Parent /*= 0*/) : Super(Parent)
setStyleSheet("border: none; background: none;"); setStyleSheet("border: none; background: none;");
} }
} // namespace ads } // namespace ads
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View File

@ -98,7 +98,7 @@ private Q_SLOTS:
void onTabsMenuAboutToShow(); void onTabsMenuAboutToShow();
void onCloseButtonClicked(); void onCloseButtonClicked();
void onAutoHideCloseActionTriggered(); void onAutoHideCloseActionTriggered();
void onAutoHideMinimizeActionTriggered(); void minimizeAutoHideContainer();
void onUndockButtonClicked(); void onUndockButtonClicked();
void onTabsMenuActionTriggered(QAction* Action); void onTabsMenuActionTriggered(QAction* Action);
void onCurrentTabChanged(int Index); void onCurrentTabChanged(int Index);
@ -210,6 +210,11 @@ public:
*/ */
void setAreaFloating(); void setAreaFloating();
/**
* Call this function, to create all the required auto hide controls
*/
void showAutoHideControls(bool Show);
Q_SIGNALS: Q_SIGNALS:
/** /**
* This signal is emitted if a tab in the tab bar is clicked by the user * This signal is emitted if a tab in the tab bar is clicked by the user

View File

@ -390,20 +390,29 @@ void DockAreaWidgetPrivate::updateTitleBarButtonVisibility(bool IsTopLevel)
return; 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(TitleBarButtonClose)->setVisible(!container->isFloating());
TitleBar->button(TitleBarButtonAutoHide)->setVisible(!container->isFloating()); TitleBar->button(TitleBarButtonAutoHide)->setVisible(!container->isFloating());
// Undock and tabs should never show when auto hidden // Undock and tabs should never show when auto hidden
TitleBar->button(TitleBarButtonUndock)->setVisible(!container->isFloating() && !_this->isAutoHide()); TitleBar->button(TitleBarButtonUndock)->setVisible(!container->isFloating());
TitleBar->button(TitleBarButtonTabsMenu)->setVisible(!_this->isAutoHide()); TitleBar->button(TitleBarButtonTabsMenu)->setVisible(true);
} }
else else
{ {
TitleBar->button(TitleBarButtonClose)->setVisible(true); TitleBar->button(TitleBarButtonClose)->setVisible(true);
TitleBar->button(TitleBarButtonAutoHide)->setVisible(true); TitleBar->button(TitleBarButtonAutoHide)->setVisible(true);
TitleBar->button(TitleBarButtonUndock)->setVisible(!_this->isAutoHide()); TitleBar->button(TitleBarButtonUndock)->setVisible(true);
TitleBar->button(TitleBarButtonTabsMenu)->setVisible(!_this->isAutoHide()); TitleBar->button(TitleBarButtonTabsMenu)->setVisible(true);
} }
} }
@ -847,9 +856,7 @@ void CDockAreaWidget::updateTitleBarVisibility()
if (isAutoHideFeatureEnabled()) if (isAutoHideFeatureEnabled())
{ {
auto tabBar = d->TitleBar->tabBar(); d->TitleBar->showAutoHideControls(IsAutoHide);
tabBar->setVisible(!IsAutoHide); // Never show tab bar when auto hidden
d->TitleBar->autoHideTitleLabel()->setVisible(IsAutoHide); // Always show when auto hidden, never otherwise
updateTitleBarButtonVisibility(Container->topLevelDockArea() == this); updateTitleBarButtonVisibility(Container->topLevelDockArea() == this);
} }
} }

View File

@ -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 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 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 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 DefaultAutoHideConfig = AutoHideFeatureEnabled
| DockAreaHasAutoHideButton | DockAreaHasAutoHideButton
| AutoHideCloseButtonCollapsesDock | AutoHideCloseButtonCollapsesDock
| AutoHideHasCloseButton
}; };
Q_DECLARE_FLAGS(AutoHideFlags, eAutoHideFlag) Q_DECLARE_FLAGS(AutoHideFlags, eAutoHideFlag)

View File

@ -20,5 +20,7 @@
<file>images/vs-pin-button-pinned-focused.svg</file> <file>images/vs-pin-button-pinned-focused.svg</file>
<file>images/vs-pin-button_45.svg</file> <file>images/vs-pin-button_45.svg</file>
<file>images/pin-button-big.svg</file> <file>images/pin-button-big.svg</file>
<file>images/minimize-button.svg</file>
<file>images/minimize-button-focused.svg</file>
</qresource> </qresource>
</RCC> </RCC>

View File

@ -107,7 +107,8 @@ enum TitleBarButton
TitleBarButtonTabsMenu, TitleBarButtonTabsMenu,
TitleBarButtonUndock, TitleBarButtonUndock,
TitleBarButtonClose, TitleBarButtonClose,
TitleBarButtonAutoHide TitleBarButtonAutoHide,
TitleBarButtonMinimize
}; };
/** /**
@ -131,6 +132,7 @@ enum eIcon
DockAreaMenuIcon, //!< DockAreaMenuIcon DockAreaMenuIcon, //!< DockAreaMenuIcon
DockAreaUndockIcon,//!< DockAreaUndockIcon DockAreaUndockIcon,//!< DockAreaUndockIcon
DockAreaCloseIcon, //!< DockAreaCloseIcon DockAreaCloseIcon, //!< DockAreaCloseIcon
DockAreaMinimizeIcon,
IconCount, //!< just a delimiter for range checks IconCount, //!< just a delimiter for range checks
}; };

View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="16" height="16" enable-background="new 0 0 122.879 122.867" version="1.1" viewBox="0 0 16 16" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"><rect x="4" y="10" width="7" height="2" fill="#fff"/><style/><style/><style/><style/></svg>

After

Width:  |  Height:  |  Size: 293 B

View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="16" height="16" enable-background="new 0 0 122.879 122.867" version="1.1" viewBox="0 0 16 16" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"><rect x="4" y="10" width="7" height="2"/></svg>

After

Width:  |  Height:  |  Size: 249 B

View File

@ -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{ ads--CAutoHideDockContainer #dockAreaCloseButton{
qproperty-icon: url(:/ads/images/close-button-focused.svg) qproperty-icon: url(:/ads/images/close-button-focused.svg)
} }

View File

@ -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{ ads--CAutoHideDockContainer #dockAreaCloseButton{
qproperty-icon: url(:/ads/images/close-button-focused.svg) qproperty-icon: url(:/ads/images/close-button-focused.svg)
} }

View File

@ -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{ ads--CAutoHideDockContainer #dockAreaCloseButton{
qproperty-icon: url(:/ads/images/close-button-focused.svg) qproperty-icon: url(:/ads/images/close-button-focused.svg)
} }

View File

@ -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{ ads--CAutoHideDockContainer #dockAreaCloseButton{
qproperty-icon: url(:/ads/images/close-button-focused.svg) qproperty-icon: url(:/ads/images/close-button-focused.svg)
} }