From 0f8096e31493ce380c0f20190e2c4bea57cbb297 Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Thu, 19 Oct 2023 09:10:26 +0200 Subject: [PATCH] Added minimize and close action to Auto Hide context menu --- demo/MainWindow.cpp | 1 + src/DockAreaTitleBar.cpp | 33 +++++++++++++++++++++++++++++++-- src/DockAreaTitleBar.h | 2 ++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/demo/MainWindow.cpp b/demo/MainWindow.cpp index 2ebf052..3609461 100644 --- a/demo/MainWindow.cpp +++ b/demo/MainWindow.cpp @@ -527,6 +527,7 @@ void MainWindowPrivate::createContent() // Tests CustomCloseHandling without DeleteOnClose LabelDockWidget->setFeature(ads::CDockWidget::CustomCloseHandling, true); + LabelDockWidget->setWindowTitle(LabelDockWidget->windowTitle() + " [Custom Close]"); QObject::connect(LabelDockWidget, &ads::CDockWidget::closeRequested, [LabelDockWidget, this]() { int Result = QMessageBox::question(_this, "Custom Close Request", diff --git a/src/DockAreaTitleBar.cpp b/src/DockAreaTitleBar.cpp index 919b130..e8c3991 100644 --- a/src/DockAreaTitleBar.cpp +++ b/src/DockAreaTitleBar.cpp @@ -431,6 +431,24 @@ void CDockAreaTitleBar::onCloseButtonClicked() } +//============================================================================ +void CDockAreaTitleBar::onAutoHideCloseActionTriggered() +{ + d->DockArea->closeArea(); +} + + +//============================================================================ +void CDockAreaTitleBar::onAutoHideMinimizeActionTriggered() +{ + auto AutoHideContainer = d->DockArea->autoHideDockContainer(); + if (AutoHideContainer) + { + AutoHideContainer->collapseView(true); + } +} + + //============================================================================ void CDockAreaTitleBar::onUndockButtonClicked() { @@ -735,7 +753,17 @@ void CDockAreaTitleBar::contextMenuEvent(QContextMenuEvent* ev) } Menu.addSeparator(); } - Action = Menu.addAction(isAutoHide ? tr("Close") : tr("Close Group"), this, SLOT(onCloseButtonClicked())); + + if (isAutoHide) + { + Action = Menu.addAction(tr("Minimize"), this, SLOT(onAutoHideMinimizeActionTriggered())); + Action = Menu.addAction(tr("Close"), this, SLOT(onAutoHideCloseActionTriggered())); + } + else + { + Action = Menu.addAction(isAutoHide ? tr("Close") : tr("Close Group"), this, SLOT(onCloseButtonClicked())); + } + Action->setEnabled(d->DockArea->features().testFlag(CDockWidget::DockWidgetClosable)); if (!isAutoHide && !isTopLevelArea) { @@ -782,7 +810,8 @@ QString CDockAreaTitleBar::titleBarButtonToolTip(TitleBarButton Button) const case TitleBarButtonClose: if (d->DockArea->isAutoHide()) { - return tr("Close"); + bool Minimize = CDockManager::testAutoHideConfigFlag(CDockManager::AutoHideCloseButtonCollapsesDock); + return Minimize ? tr("Minimize") : tr("Close"); } if (CDockManager::testConfigFlag(CDockManager::DockAreaCloseButtonClosesTab)) diff --git a/src/DockAreaTitleBar.h b/src/DockAreaTitleBar.h index 46ac231..2de2ed6 100644 --- a/src/DockAreaTitleBar.h +++ b/src/DockAreaTitleBar.h @@ -97,6 +97,8 @@ private: private Q_SLOTS: void onTabsMenuAboutToShow(); void onCloseButtonClicked(); + void onAutoHideCloseActionTriggered(); + void onAutoHideMinimizeActionTriggered(); void onUndockButtonClicked(); void onTabsMenuActionTriggered(QAction* Action); void onCurrentTabChanged(int Index);