diff --git a/src/AutoHideDockContainer.cpp b/src/AutoHideDockContainer.cpp index 079c3a3..aa183ca 100644 --- a/src/AutoHideDockContainer.cpp +++ b/src/AutoHideDockContainer.cpp @@ -107,6 +107,7 @@ struct AutoHideDockContainerPrivate QBoxLayout* Layout; CResizeHandle* ResizeHandle = nullptr; QSize Size; // creates invalid size + CDockWidgetSideTab* SideTab = nullptr; /** * Private data constructor diff --git a/src/AutoHideDockContainer.h b/src/AutoHideDockContainer.h index 047290f..b684bb4 100644 --- a/src/AutoHideDockContainer.h +++ b/src/AutoHideDockContainer.h @@ -70,12 +70,14 @@ public: /** * Create Auto Hide widget with a dock manager */ - CAutoHideDockContainer(CDockManager* DockManager, SideBarLocation area, CDockContainerWidget* parent); + CAutoHideDockContainer(CDockManager* DockManager, SideBarLocation area, + CDockContainerWidget* parent); /** * Create Auto Hide widget with the given dock widget */ - CAutoHideDockContainer(CDockWidget* DockWidget, SideBarLocation area, CDockContainerWidget* parent); + CAutoHideDockContainer(CDockWidget* DockWidget, SideBarLocation area, + CDockContainerWidget* parent); /** * Virtual Destructor diff --git a/src/DockWidget.cpp b/src/DockWidget.cpp index 745a6fe..9611f7c 100644 --- a/src/DockWidget.cpp +++ b/src/DockWidget.cpp @@ -79,7 +79,6 @@ struct DockWidgetPrivate QBoxLayout* Layout = nullptr; QWidget* Widget = nullptr; CDockWidgetTab* TabWidget = nullptr; - CDockWidgetSideTab* SideTabWidget = nullptr; CDockWidget::DockWidgetFeatures Features = CDockWidget::DefaultDockWidgetFeatures; CDockManager* DockManager = nullptr; CDockAreaWidget* DockArea = nullptr; @@ -97,6 +96,7 @@ struct DockWidgetPrivate WidgetFactory* Factory = nullptr; double DefaultAutoHideDockProportion = 0.25; CDockWidget::eAutoHideInsertOrder AutoHideInsertOrder = CDockWidget::Last; + QPointer SideTabWidget; /** * Private data constructor @@ -246,6 +246,8 @@ void DockWidgetPrivate::updateParentDockArea() } } + +//============================================================================ void DockWidgetPrivate::closeAutoHideDockWidgetsIfNeeded() { if (_this->dockContainer() && _this->dockContainer()->openedDockWidgets().isEmpty() && !_this->dockManager()->isRestoringState()) diff --git a/src/SideTabBar.cpp b/src/SideTabBar.cpp index 8f81a87..85718ca 100644 --- a/src/SideTabBar.cpp +++ b/src/SideTabBar.cpp @@ -113,6 +113,7 @@ CSideTabBar::CSideTabBar(CDockContainerWidget* parent, SideBarLocation area) : //============================================================================ CSideTabBar::~CSideTabBar() { + qDebug() << "~CSideTabBar() "; // The SideTabeBar is not the owner of the tabs and to prevent deletion // we set the parent here to nullptr to remove it from the children auto Tabs = findChildren(QString(), Qt::FindDirectChildrenOnly); @@ -127,6 +128,7 @@ CSideTabBar::~CSideTabBar() //============================================================================ void CSideTabBar::insertSideTab(int Index, CDockWidgetSideTab* SideTab) { + SideTab->installEventFilter(this); d->TabsLayout->insertWidget(Index, SideTab); SideTab->setSideTabBar(this); show(); @@ -166,6 +168,7 @@ void CSideTabBar::removeDockWidget(CDockWidget* DockWidget) void CSideTabBar::removeSideTab(CDockWidgetSideTab* SideTab) { qDebug() << "CSideTabBar::removeSideTab " << SideTab->text(); + SideTab->removeEventFilter(this); d->TabsLayout->removeWidget(SideTab); if (d->TabsLayout->isEmpty()) { @@ -174,6 +177,65 @@ void CSideTabBar::removeSideTab(CDockWidgetSideTab* SideTab) } +//============================================================================ +bool CSideTabBar::event(QEvent* e) +{ + qDebug() << e; + switch (e->type()) + { + case QEvent::ChildRemoved: + if (d->TabsLayout->isEmpty()) + { + hide(); + } + break; + + case QEvent::Resize: + if (d->TabsLayout->count()) + { + auto ev = static_cast(e); + auto Tab = tabAt(0); + int Size = d->isHorizontal() ? ev->size().height() : ev->size().width(); + int TabSize = d->isHorizontal() ? Tab->size().height() : Tab->size().width(); + // If the size of the side bar is less than the size of the first tab + // then there are no visible tabs in this side bar. This check will + // fail if someone will force a very big border via CSS!! + if (Size < TabSize) + { + hide(); + } + } + else + { + hide(); + } + break; + + default: + break; + } + return Super::event(e); +} + + +//============================================================================ +bool CSideTabBar::eventFilter(QObject *watched, QEvent *event) +{ + if (event->type() != QEvent::ShowToParent) + { + return false; + } + + // As soon as on tab is shhown, we need to show the side tab bar + auto Tab = qobject_cast(watched); + if (Tab) + { + show(); + } + return false; +} + + //============================================================================ void CSideTabBar::paintEvent(QPaintEvent* event) { @@ -212,4 +274,5 @@ SideBarLocation CSideTabBar::sideTabBarArea() const { return d->SideTabArea; } + } diff --git a/src/SideTabBar.h b/src/SideTabBar.h index ecafb6e..890a10d 100644 --- a/src/SideTabBar.h +++ b/src/SideTabBar.h @@ -55,7 +55,9 @@ private: friend class DockWidgetSideTab; protected: - void paintEvent(QPaintEvent* event) override; + virtual void paintEvent(QPaintEvent* event) override; + virtual bool event(QEvent* e) override; + virtual bool eventFilter(QObject *watched, QEvent *event) override; public: using Super = QFrame;