From 0b5840309fc83f0f4eed6a970ca47f24be82aef8 Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Tue, 15 Nov 2022 15:08:52 +0100 Subject: [PATCH] Added support for runtime switching of CAutoHideDockContainer sidebar location --- src/AutoHideDockContainer.cpp | 18 ++++++++++++++++++ src/AutoHideDockContainer.h | 8 +++++++- src/AutoHideSideBar.cpp | 6 ++++++ src/ResizeHandle.cpp | 22 +++++++++++----------- 4 files changed, 42 insertions(+), 12 deletions(-) diff --git a/src/AutoHideDockContainer.cpp b/src/AutoHideDockContainer.cpp index a9d6a28..b5d404b 100644 --- a/src/AutoHideDockContainer.cpp +++ b/src/AutoHideDockContainer.cpp @@ -353,6 +353,24 @@ SideBarLocation CAutoHideDockContainer::sideBarLocation() const return d->SideTabBarArea; } + +//============================================================================ +void CAutoHideDockContainer::setSideBarLocation(SideBarLocation SideBarLocation) +{ + if (d->SideTabBarArea == SideBarLocation) + { + return; + } + + d->SideTabBarArea = SideBarLocation; + d->Layout->removeWidget(d->ResizeHandle); + d->Layout->setDirection(isHorizontalArea(SideBarLocation) ? QBoxLayout::TopToBottom : QBoxLayout::LeftToRight); + d->Layout->insertWidget(resizeHandleLayoutPosition(SideBarLocation), d->ResizeHandle); + d->ResizeHandle->setHandlePosition(edgeFromSideTabBarArea(SideBarLocation)); + internal::repolishStyle(this, internal::RepolishDirectChildren); +} + + //============================================================================ CDockAreaWidget* CAutoHideDockContainer::dockAreaWidget() const { diff --git a/src/AutoHideDockContainer.h b/src/AutoHideDockContainer.h index 42cd7cd..d042b40 100644 --- a/src/AutoHideDockContainer.h +++ b/src/AutoHideDockContainer.h @@ -66,7 +66,6 @@ protected: virtual void leaveEvent(QEvent *event) override; virtual bool event(QEvent* event) override; - /** * Updates the size considering the size limits and the resize margins */ @@ -116,6 +115,13 @@ public: */ SideBarLocation sideBarLocation() const; + /** + * Sets a new SideBarLocation. + * If a new side bar location is set, the auto hide dock container needs + * to update its resize handle position + */ + void setSideBarLocation(SideBarLocation SideBarLocation); + /** * Returns the dock area widget of this Auto Hide dock container */ diff --git a/src/AutoHideSideBar.cpp b/src/AutoHideSideBar.cpp index b16eb58..6a1ebe2 100644 --- a/src/AutoHideSideBar.cpp +++ b/src/AutoHideSideBar.cpp @@ -257,11 +257,17 @@ void CAutoHideSideBar::removeAutoHideWidget(CAutoHideDockContainer* AutoHideWidg void CAutoHideSideBar::addAutoHideWidget(CAutoHideDockContainer* AutoHideWidget) { auto SideBar = AutoHideWidget->autoHideTab()->sideBar(); + if (SideBar == this) + { + return; + } + if (SideBar) { SideBar->removeAutoHideWidget(AutoHideWidget); } AutoHideWidget->setParent(d->ContainerWidget); + AutoHideWidget->setSideBarLocation(d->SideTabArea); d->ContainerWidget->registerAutoHideWidget(AutoHideWidget); insertTab(-1, AutoHideWidget->autoHideTab()); } diff --git a/src/ResizeHandle.cpp b/src/ResizeHandle.cpp index 84f02d2..ae97984 100644 --- a/src/ResizeHandle.cpp +++ b/src/ResizeHandle.cpp @@ -167,18 +167,8 @@ CResizeHandle::CResizeHandle(Qt::Edge HandlePosition, QWidget* parent) : d(new ResizeHandlePrivate(this)) { d->Target = parent; - setHandlePosition(HandlePosition); setMinResizeSize(48); - setMaxResizeSize(d->isHorizontal() ? parent->height() : parent->width()); - - if (!d->isHorizontal()) - { - setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); - } - else - { - setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); - } + setHandlePosition(HandlePosition); } @@ -244,6 +234,16 @@ void CResizeHandle::setHandlePosition(Qt::Edge HandlePosition) case Qt::TopEdge: // fall through case Qt::BottomEdge: setCursor(Qt::SizeVerCursor); break; } + + setMaxResizeSize(d->isHorizontal() ? parentWidget()->height() : parentWidget()->width()); + if (!d->isHorizontal()) + { + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + } + else + { + setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); + } }