From 06bcf2cd48eb918ee2d04001c5b8659957438ffe Mon Sep 17 00:00:00 2001 From: Syarif Fakhri Date: Wed, 14 Sep 2022 15:52:34 +0800 Subject: [PATCH] Add insert order for overlayed widget to the side tab bar - Set the default insert order to append --- src/DockAreaWidget.cpp | 2 +- src/DockContainerWidget.cpp | 6 +++--- src/DockContainerWidget.h | 4 +--- src/DockManager.cpp | 8 ++++---- src/DockManager.h | 4 ++-- src/DockWidget.cpp | 13 +++++++++++++ src/DockWidget.h | 21 +++++++++++++++++++++ src/SideTabBar.cpp | 9 +++++++-- 8 files changed, 52 insertions(+), 15 deletions(-) diff --git a/src/DockAreaWidget.cpp b/src/DockAreaWidget.cpp index 127d9ca..e8243b6 100644 --- a/src/DockAreaWidget.cpp +++ b/src/DockAreaWidget.cpp @@ -1097,7 +1097,7 @@ void CDockAreaWidget::onAutoHideToggleRequested(CDockWidget* DockWidget, bool En { if (Enable) { - dockContainer()->createAndInitializeDockWidgetOverlayContainer(area, DockWidget); + dockContainer()->createAndInitializeDockWidgetOverlayContainer(area, DockWidget, DockWidget->overlayInsertOrder()); } else { diff --git a/src/DockContainerWidget.cpp b/src/DockContainerWidget.cpp index bcf53bd..dbb9a66 100644 --- a/src/DockContainerWidget.cpp +++ b/src/DockContainerWidget.cpp @@ -1485,7 +1485,7 @@ CDockAreaWidget* CDockContainerWidget::addDockWidget(DockWidgetArea area, CDockW //============================================================================ -COverlayDockContainer* CDockContainerWidget::createAndInitializeDockWidgetOverlayContainer(CDockWidgetSideTab::SideTabBarArea area, CDockWidget* DockWidget) +COverlayDockContainer* CDockContainerWidget::createAndInitializeDockWidgetOverlayContainer(CDockWidgetSideTab::SideTabBarArea area, CDockWidget* DockWidget, CDockWidget::eOverlayInsertOrder insertOrder) { if (d->DockManager != DockWidget->dockManager()) { @@ -1498,7 +1498,7 @@ COverlayDockContainer* CDockContainerWidget::createAndInitializeDockWidgetOverla return nullptr; } - sideTabBar(area)->insertSideTab(0, DockWidget->sideTabWidget()); + sideTabBar(area)->insertSideTab(insertOrder == CDockWidget::First ? 0 : -1, DockWidget->sideTabWidget()); DockWidget->sideTabWidget()->show(); const auto dockContainer = new COverlayDockContainer(DockWidget, area, this); @@ -1800,7 +1800,7 @@ void CDockContainerWidget::dropFloatingWidget(CFloatingDockContainer* FloatingWi auto overlayWidgets = FloatingWidget->dockContainer()->overlayWidgets(); for (const auto overlayWidget : overlayWidgets) { - createAndInitializeDockWidgetOverlayContainer(overlayWidget->sideTabBarArea(), overlayWidget->dockWidget()); + createAndInitializeDockWidgetOverlayContainer(overlayWidget->sideTabBarArea(), overlayWidget->dockWidget(), overlayWidget->dockWidget()->overlayInsertOrder()); } if (DockArea) diff --git a/src/DockContainerWidget.h b/src/DockContainerWidget.h index ea3d55a..269f784 100644 --- a/src/DockContainerWidget.h +++ b/src/DockContainerWidget.h @@ -95,13 +95,12 @@ protected: */ QSplitter* rootSplitter() const; - /** * Creates and initializes a dockwidget overlay container into the given area. * Initializing inserts the tabs into the side tab widget and hides it * Returns nullptr if you try and insert into an area where the configuration is not enabled */ - COverlayDockContainer* createAndInitializeDockWidgetOverlayContainer(CDockWidgetSideTab::SideTabBarArea area, CDockWidget* DockWidget); + COverlayDockContainer* createAndInitializeDockWidgetOverlayContainer(CDockWidgetSideTab::SideTabBarArea area, CDockWidget* DockWidget, CDockWidget::eOverlayInsertOrder insertOrder); /** * Helper function for creation of the root splitter @@ -198,7 +197,6 @@ protected: public: - /** * Default Constructor */ diff --git a/src/DockManager.cpp b/src/DockManager.cpp index 843402b..b29f1a6 100644 --- a/src/DockManager.cpp +++ b/src/DockManager.cpp @@ -864,16 +864,16 @@ CDockAreaWidget* CDockManager::addDockWidgetToContainer(DockWidgetArea area, } //============================================================================ -COverlayDockContainer* CDockManager::addOverlayDockWidget(CDockWidgetSideTab::SideTabBarArea area, CDockWidget* Dockwidget) +COverlayDockContainer* CDockManager::addOverlayDockWidget(CDockWidgetSideTab::SideTabBarArea area, CDockWidget* Dockwidget, CDockWidget::eOverlayInsertOrder insertOrder) { - return addOverlayDockWidgetToContainer(area, Dockwidget, this); + return addOverlayDockWidgetToContainer(area, Dockwidget, this, insertOrder); } //============================================================================ -COverlayDockContainer* CDockManager::addOverlayDockWidgetToContainer(CDockWidgetSideTab::SideTabBarArea area, CDockWidget* Dockwidget, CDockContainerWidget* DockContainerWidget) +COverlayDockContainer* CDockManager::addOverlayDockWidgetToContainer(CDockWidgetSideTab::SideTabBarArea area, CDockWidget* Dockwidget, CDockContainerWidget* DockContainerWidget, CDockWidget::eOverlayInsertOrder insertOrder) { d->DockWidgetsMap.insert(Dockwidget->objectName(), Dockwidget); - auto container = DockContainerWidget->createAndInitializeDockWidgetOverlayContainer(area, Dockwidget); + auto container = DockContainerWidget->createAndInitializeDockWidgetOverlayContainer(area, Dockwidget, insertOrder); container->collapseView(true); Q_EMIT dockWidgetAdded(Dockwidget); diff --git a/src/DockManager.h b/src/DockManager.h index 3a8d740..7f42d87 100644 --- a/src/DockManager.h +++ b/src/DockManager.h @@ -341,14 +341,14 @@ public: * An overlay widget is used for auto hide functionality * \return Returns the COverlayDockContainer that contains the new DockWidget */ - COverlayDockContainer* addOverlayDockWidget(CDockWidgetSideTab::SideTabBarArea area, CDockWidget* Dockwidget); + COverlayDockContainer* addOverlayDockWidget(CDockWidgetSideTab::SideTabBarArea area, CDockWidget* Dockwidget, CDockWidget::eOverlayInsertOrder insertOrder = CDockWidget::Last); /** * Adds dock widget overlayed into the given container based on the CDockWidgetSideTab::SideTabBarArea. * An overlay widget is used for auto hide functionality * \return Returns the COverlayDockContainer that contains the new DockWidget */ - COverlayDockContainer* addOverlayDockWidgetToContainer(CDockWidgetSideTab::SideTabBarArea area, CDockWidget* Dockwidget, CDockContainerWidget* DockContainerWidget); + COverlayDockContainer* addOverlayDockWidgetToContainer(CDockWidgetSideTab::SideTabBarArea area, CDockWidget* Dockwidget, CDockContainerWidget* DockContainerWidget, CDockWidget::eOverlayInsertOrder = CDockWidget::Last); /** * This function will add the given Dockwidget to the given dock area as diff --git a/src/DockWidget.cpp b/src/DockWidget.cpp index c990209..05d0335 100644 --- a/src/DockWidget.cpp +++ b/src/DockWidget.cpp @@ -96,6 +96,7 @@ struct DockWidgetPrivate CDockWidget::eMinimumSizeHintMode MinimumSizeHintMode = CDockWidget::MinimumSizeHintFromDockWidget; WidgetFactory* Factory = nullptr; double DefaultOverlayDockProportion = 0.25; + CDockWidget::eOverlayInsertOrder OverlayInsertOrder = CDockWidget::Last; /** * Private data constructor @@ -1149,6 +1150,18 @@ double CDockWidget::DefaultOverlayDockProportion() const } +//============================================================================ +void CDockWidget::setOverlayInsertOrder(eOverlayInsertOrder insertOrder) +{ + d->OverlayInsertOrder = insertOrder; +} + +CDockWidget::eOverlayInsertOrder CDockWidget::overlayInsertOrder() const +{ + return d->OverlayInsertOrder; +} + + //============================================================================ void CDockWidget::raise() { diff --git a/src/DockWidget.h b/src/DockWidget.h index da0000c..f63cf3c 100644 --- a/src/DockWidget.h +++ b/src/DockWidget.h @@ -229,6 +229,17 @@ public: ActionModeShow //!< ActionModeShow }; + /** + * This mode configures the order of pinning and unpinning overlayed widgets + * First will add it to the top of the SideTabBar, while last will append it to the end + */ + enum eOverlayInsertOrder + { + First, + Last + }; + + /** * This constructor creates a dock widget with the given title. @@ -524,6 +535,16 @@ public: */ double DefaultOverlayDockProportion() const; + /* + * Set overlay insertion mode + */ + void setOverlayInsertOrder(eOverlayInsertOrder insertOrder); + + /* + * Get overlay insertion mode + */ + eOverlayInsertOrder overlayInsertOrder() const; + public: // reimplements QFrame ----------------------------------------------- /** * Emits titleChanged signal if title change event occurs diff --git a/src/SideTabBar.cpp b/src/SideTabBar.cpp index 08cb111..bbc1b5b 100644 --- a/src/SideTabBar.cpp +++ b/src/SideTabBar.cpp @@ -71,12 +71,17 @@ CSideTabBar::CSideTabBar(CDockContainerWidget* parent, Qt::Orientation orientati d->ContainerWidget = parent; d->Orientation = orientation; + auto mainLayout = new QBoxLayout(d->Orientation == Qt::Vertical ? QBoxLayout::TopToBottom : QBoxLayout::LeftToRight); + d->TabsLayout = new QBoxLayout(d->Orientation == Qt::Vertical ? QBoxLayout::TopToBottom : QBoxLayout::LeftToRight); d->TabsLayout->setContentsMargins(0, 0, 0, 0); d->TabsLayout->setSpacing(0); - d->TabsLayout->addStretch(1); - setLayout(d->TabsLayout); + mainLayout->addLayout(d->TabsLayout); + mainLayout->setContentsMargins(0, 0, 0, 0); + mainLayout->setSpacing(0); + mainLayout->addStretch(1); + setLayout(mainLayout); setFocusPolicy(Qt::NoFocus); }