From e2929ade142785c629022eebcfd40766574cc392 Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Wed, 28 Jun 2023 15:59:26 +0200 Subject: [PATCH] Fixed DockContainerWidget.cpp contentRect() function to work properly even if no dock widget is visible in container --- src/AutoHideDockContainer.cpp | 2 ++ src/DockContainerWidget.cpp | 30 ++++++++++++++++++++++-------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/AutoHideDockContainer.cpp b/src/AutoHideDockContainer.cpp index 3762eec..56c1541 100644 --- a/src/AutoHideDockContainer.cpp +++ b/src/AutoHideDockContainer.cpp @@ -230,6 +230,7 @@ CAutoHideDockContainer::CAutoHideDockContainer(CDockWidget* DockWidget, SideBarL //============================================================================ void CAutoHideDockContainer::updateSize() { + std::cout << "CAutoHideDockContainer::updateSize()" << std::endl; auto dockContainerParent = dockContainer(); if (!dockContainerParent) { @@ -237,6 +238,7 @@ void CAutoHideDockContainer::updateSize() } auto rect = dockContainerParent->contentRect(); + qDebug() << "dockContainerParent->contentRect() " << rect; switch (sideBarLocation()) { diff --git a/src/DockContainerWidget.cpp b/src/DockContainerWidget.cpp index 95aeeb6..daa1231 100644 --- a/src/DockContainerWidget.cpp +++ b/src/DockContainerWidget.cpp @@ -145,7 +145,7 @@ public: QList AutoHideWidgets; QMap SideTabBarWidgets; QGridLayout* Layout = nullptr; - QSplitter* RootSplitter = nullptr; + CDockSplitter* RootSplitter = nullptr; bool isFloating = false; CDockAreaWidget* LastAddedAreaCache[5]; int VisibleDockAreaCount = -1; @@ -465,7 +465,7 @@ void DockContainerWidgetPrivate::dropIntoContainer(CFloatingDockContainer* Float CDockContainerWidget* FloatingDockContainer = FloatingWidget->dockContainer(); auto NewDockAreas = FloatingDockContainer->findChildren( QString(), Qt::FindChildrenRecursively); - QSplitter* Splitter = RootSplitter; + auto Splitter = RootSplitter; if (DockAreas.count() <= 1) { @@ -473,7 +473,7 @@ void DockContainerWidgetPrivate::dropIntoContainer(CFloatingDockContainer* Float } else if (Splitter->orientation() != InsertParam.orientation()) { - QSplitter* NewSplitter = newSplitter(InsertParam.orientation()); + auto NewSplitter = newSplitter(InsertParam.orientation()); QLayoutItem* li = Layout->replaceWidget(Splitter, NewSplitter); NewSplitter->addWidget(Splitter); updateSplitterHandles(NewSplitter); @@ -1248,7 +1248,7 @@ void DockContainerWidgetPrivate::addDockArea(CDockAreaWidget* NewDockArea, DockW } else { - QSplitter* NewSplitter = newSplitter(InsertParam.orientation()); + auto NewSplitter = newSplitter(InsertParam.orientation()); if (InsertParam.append()) { QLayoutItem* li = Layout->replaceWidget(Splitter, NewSplitter); @@ -1583,7 +1583,7 @@ void CDockContainerWidget::removeDockArea(CDockAreaWidget* area) } QWidget* widget = Splitter->widget(0); - QSplitter* ChildSplitter = qobject_cast(widget); + auto ChildSplitter = qobject_cast(widget); // If the one and only content widget of the splitter is not a splitter // then we are finished if (!ChildSplitter) @@ -1913,8 +1913,8 @@ bool CDockContainerWidget::restoreState(CDockingStateReader& s, bool Testing) } d->Layout->replaceWidget(d->RootSplitter, NewRootSplitter); - QSplitter* OldRoot = d->RootSplitter; - d->RootSplitter = qobject_cast(NewRootSplitter); + auto OldRoot = d->RootSplitter; + d->RootSplitter = qobject_cast(NewRootSplitter); OldRoot->deleteLater(); return true; @@ -2132,7 +2132,21 @@ QRect CDockContainerWidget::contentRect() const return QRect(); } - return d->RootSplitter->geometry(); + if (d->RootSplitter->hasVisibleContent()) + { + return d->RootSplitter->geometry(); + } + else + { + auto ContentRect = this->rect(); + ContentRect.adjust( + sideTabBar(SideBarLeft)->sizeHint().width(), + sideTabBar(SideBarTop)->sizeHint().height(), + -sideTabBar(SideBarRight)->sizeHint().width(), + -sideTabBar(SideBarBottom)->sizeHint().height()); + + return ContentRect; + } }