From 540961b8dd7f486575bd9946c23b5179b2df7f5d Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Tue, 1 Nov 2022 21:31:27 +0100 Subject: [PATCH] Renamed toggleAutoHide to setAutoHide and added toggleAutoHide function --- src/DockAreaTitleBar.cpp | 2 +- src/DockAreaWidget.cpp | 40 ++++++++++++++++++++++++++++++++++--- src/DockAreaWidget.h | 18 ++++++++++++++--- src/DockContainerWidget.cpp | 2 +- src/DockContainerWidget.h | 2 +- 5 files changed, 55 insertions(+), 9 deletions(-) diff --git a/src/DockAreaTitleBar.cpp b/src/DockAreaTitleBar.cpp index fdaacd3..efa93fd 100644 --- a/src/DockAreaTitleBar.cpp +++ b/src/DockAreaTitleBar.cpp @@ -493,7 +493,7 @@ void CDockAreaTitleBar::onCurrentTabChanged(int Index) //============================================================================ void CDockAreaTitleBar::onAutoHideButtonClicked() { - d->DockArea->toggleAutoHide(!d->DockArea->isAutoHide()); + d->DockArea->setAutoHide(!d->DockArea->isAutoHide()); } diff --git a/src/DockAreaWidget.cpp b/src/DockAreaWidget.cpp index fc2f70f..ae7c159 100644 --- a/src/DockAreaWidget.cpp +++ b/src/DockAreaWidget.cpp @@ -61,6 +61,15 @@ namespace ads static const char* const INDEX_PROPERTY = "index"; static const char* const ACTION_PROPERTY = "action"; +/** + * Check, if auto hide is enabled + */ +static bool isAutoHideFeatureEnabled() +{ + return CDockManager::testAutoHideConfigFlag(CDockManager::AutoHideFeatureEnabled); +} + + /** * Internal dock area layout mimics stack layout but only inserts the current * widget into the internal QLayout object. @@ -826,7 +835,7 @@ void CDockAreaWidget::updateTitleBarVisibility() Hidden &= !IsAutoHide; // Titlebar must always be visible when auto hidden so it can be dragged d->TitleBar->setVisible(!Hidden); - if (CDockManager::testAutoHideConfigFlag(CDockManager::AutoHideFeatureEnabled)) + if (isAutoHideFeatureEnabled()) { auto tabBar = d->TitleBar->tabBar(); tabBar->setVisible(!IsAutoHide); // Never show tab bar when auto hidden @@ -1176,16 +1185,29 @@ void CDockAreaWidget::closeArea() } } + //============================================================================ -void CDockAreaWidget::toggleAutoHide(bool Enable) +SideBarLocation CDockAreaWidget::calculateSideTabBarArea() const { + return dockContainer()->calculateSideTabBarArea(this); +} + + +//============================================================================ +void CDockAreaWidget::setAutoHide(bool Enable) +{ + if (!isAutoHideFeatureEnabled()) + { + return; + } + if (!Enable) { autoHideDockContainer()->moveContentsToParent(); return; } - const auto area = dockContainer()->calculateSideTabBarArea(this); + const auto area = calculateSideTabBarArea(); if (CDockManager::testAutoHideConfigFlag(CDockManager::AutoHideButtonTogglesArea) && features().testFlag(CDockWidget::DockWidgetPinnable)) @@ -1212,6 +1234,18 @@ void CDockAreaWidget::toggleAutoHide(bool Enable) } +//============================================================================ +void CDockAreaWidget::toggleAutoHide() +{ + if (!isAutoHideFeatureEnabled()) + { + return; + } + + setAutoHide(!isAutoHide()); +} + + //============================================================================ void CDockAreaWidget::closeOtherAreas() { diff --git a/src/DockAreaWidget.h b/src/DockAreaWidget.h index eb9179a..65d73de 100644 --- a/src/DockAreaWidget.h +++ b/src/DockAreaWidget.h @@ -89,6 +89,12 @@ private Q_SLOTS: */ void updateTitleBarButtonToolTip(); + /** + * Calculate the auto hide side bar location depending on the dock area + * widget position in the container + */ + SideBarLocation calculateSideTabBarArea() const; + protected: #ifdef Q_OS_WIN @@ -211,7 +217,7 @@ public: CAutoHideDockContainer* autoHideDockContainer() const; /** - * Returns true if the dock area exists in an auto hide dock container + * Returns true if the dock area is in an auto hide container */ bool isAutoHide() const; @@ -385,9 +391,15 @@ public Q_SLOTS: void closeArea(); /** - * Toggles the Auto hides behaviour of the dock area and all dock widgets in this area + * Sets the dock area into auto hide mode or into normal mode */ - void toggleAutoHide(bool Enable); + void setAutoHide(bool Enable); + + /** + * Switches the dock area to auto hide mode or vice versa depending on its + * current state. + */ + void toggleAutoHide(); /** * This function closes all other areas except of this area diff --git a/src/DockContainerWidget.cpp b/src/DockContainerWidget.cpp index af31f2f..6bd0df6 100644 --- a/src/DockContainerWidget.cpp +++ b/src/DockContainerWidget.cpp @@ -1411,7 +1411,7 @@ enum eBorderLocation //============================================================================ -SideBarLocation CDockContainerWidget::calculateSideTabBarArea(CDockAreaWidget* DockAreaWidget) +SideBarLocation CDockContainerWidget::calculateSideTabBarArea(const CDockAreaWidget* DockAreaWidget) const { auto ContentRect = this->contentRect(); diff --git a/src/DockContainerWidget.h b/src/DockContainerWidget.h index 0f3d3ea..b37494b 100644 --- a/src/DockContainerWidget.h +++ b/src/DockContainerWidget.h @@ -220,7 +220,7 @@ public: /** * Get's the auto hide dock side tab bar area based on the dock area widget position */ - SideBarLocation calculateSideTabBarArea(CDockAreaWidget* DockAreaWidget); + SideBarLocation calculateSideTabBarArea(const CDockAreaWidget* DockAreaWidget) const; /** * Removes dockwidget