diff --git a/src/DockAreaWidget.cpp b/src/DockAreaWidget.cpp index 2d69865..056f37e 100644 --- a/src/DockAreaWidget.cpp +++ b/src/DockAreaWidget.cpp @@ -216,14 +216,7 @@ void DockAreaWidgetPrivate::updateTabBar() return; } - if (Container->isFloating() && (Container->dockAreaCount() == 1) && (_this->dockWidgetsCount() == 1)) - { - TitleBar->setVisible(false); - } - else - { - TitleBar->setVisible(true); - } + TitleBar->setVisible(!Container->isFloating() || !Container->hasSingleVisibleDockWidget()); } @@ -360,27 +353,25 @@ void CDockAreaWidget::insertDockWidget(int index, CDockWidget* DockWidget, void CDockAreaWidget::removeDockWidget(CDockWidget* DockWidget) { qDebug() << "CDockAreaWidget::removeDockWidget"; - auto NextDockWidget = nextOpenDockWidget(DockWidget); + auto NextOpenDockWidget = nextOpenDockWidget(DockWidget); d->ContentsLayout->removeWidget(DockWidget); - auto TitleBar = DockWidget->tabWidget(); - TitleBar->hide(); - d->TabsLayout->removeWidget(TitleBar); - disconnect(TitleBar, SIGNAL(clicked()), this, SLOT(onDockWidgetTitleClicked())); - if (NextDockWidget) + auto TabWidget = DockWidget->tabWidget(); + TabWidget->hide(); + d->TabsLayout->removeWidget(TabWidget); + disconnect(TabWidget, SIGNAL(clicked()), this, SLOT(onDockWidgetTitleClicked())); + if (NextOpenDockWidget) { - setCurrentDockWidget(NextDockWidget); + setCurrentDockWidget(NextOpenDockWidget); d->markTabsMenuOutdated(); } - - CDockContainerWidget* DockContainer = dockContainer(); - if (d->ContentsLayout->isEmpty()) + else if (d->ContentsLayout->isEmpty()) { qDebug() << "Dock Area empty"; dockContainer()->removeDockArea(this); - this->deleteLater();; + this->deleteLater(); } - else if (!NextDockWidget) + else { // if contents layout is not empty but there are no more open dock // widgets, then we need to hide the dock area because it does not @@ -390,7 +381,11 @@ void CDockAreaWidget::removeDockWidget(CDockWidget* DockWidget) d->updateTabBar(); DockWidget->setDockArea(nullptr); + +#if (ADS_DEBUG_LEVEL > 0) + CDockContainerWidget* DockContainer = dockContainer(); DockContainer->dumpLayout(); +#endif } @@ -656,6 +651,7 @@ void CDockAreaWidget::toggleDockWidgetView(CDockWidget* DockWidget, bool Open) { Q_UNUSED(DockWidget); Q_UNUSED(Open); + updateDockArea(); d->markTabsMenuOutdated(); } diff --git a/src/DockContainerWidget.cpp b/src/DockContainerWidget.cpp index 2dd67b7..b2c7b54 100644 --- a/src/DockContainerWidget.cpp +++ b/src/DockContainerWidget.cpp @@ -189,8 +189,11 @@ void DockContainerWidgetPrivate::dropIntoContainer(CFloatingDockContainer* Float DockWidgetArea area) { auto InsertParam = internal::dockAreaInsertParameters(area); - auto NewDockAreas = FloatingWidget->dockContainer()->findChildren( + CDockContainerWidget* FloatingDockContainer = FloatingWidget->dockContainer(); + auto NewDockAreas = FloatingDockContainer->findChildren( QString(), Qt::FindChildrenRecursively); + CDockWidget* SingleDoppedDockWidget = FloatingDockContainer->singleVisibleDockWidget(); + CDockWidget* SingleDockWidget = _this->singleVisibleDockWidget(); QSplitter* Splitter = RootSplitter; if (DockAreas.count() <= 1) @@ -207,7 +210,7 @@ void DockContainerWidgetPrivate::dropIntoContainer(CFloatingDockContainer* Float } // Now we can insert the floating widget content into this container - auto FloatingSplitter = FloatingWidget->dockContainer()->rootSplitter(); + auto FloatingSplitter = FloatingDockContainer->rootSplitter(); if (FloatingSplitter->count() == 1) { insertWidgetIntoSplitter(Splitter, FloatingSplitter->widget(0), InsertParam.append()); @@ -227,6 +230,15 @@ void DockContainerWidgetPrivate::dropIntoContainer(CFloatingDockContainer* Float RootSplitter = Splitter; addDockAreasToList(NewDockAreas); FloatingWidget->deleteLater(); + if (SingleDoppedDockWidget) + { + SingleDoppedDockWidget->dockAreaWidget()->updateDockArea(); + } + + if (SingleDockWidget) + { + SingleDockWidget->dockAreaWidget()->updateDockArea(); + } // If we dropped the floating widget into the main dock container that does // not contain any dock widgets, then splitter is invisible and we need to // show it to display the docked widgets @@ -588,6 +600,7 @@ CDockAreaWidget* DockContainerWidgetPrivate::dockWidgetIntoContainer(DockWidgetA CDockAreaWidget* NewDockArea = new CDockAreaWidget(DockManager, _this); NewDockArea->addDockWidget(Dockwidget); addDockArea(NewDockArea, area); + NewDockArea->updateDockArea(); LastAddedAreaCache[areaIdToIndex(area)] = NewDockArea; return NewDockArea; } @@ -864,6 +877,12 @@ void CDockContainerWidget::removeDockArea(CDockAreaWidget* area) delete Splitter; emitAndExit: + // Updated the title bar visibility of the dock widget if there is only + // one single visible dock widget + if (hasSingleVisibleDockWidget()) + { + openedDockAreas()[0]->updateDockArea(); + } dumpLayout(); emit dockAreasRemoved(); } @@ -974,7 +993,7 @@ QList CDockContainerWidget::openedDockAreas() const QList Result; for (auto DockArea : d->DockAreas) { - if (DockArea->isVisible()) + if (DockArea->isVisibleTo(this)) { Result.append(DockArea); } @@ -1088,6 +1107,45 @@ CDockAreaWidget* CDockContainerWidget::lastAddedDockAreaWidget(DockWidgetArea ar } +//============================================================================ +bool CDockContainerWidget::hasSingleVisibleDockWidget() const +{ + auto DockAreas = openedDockAreas(); + if (DockAreas.count() != 1) + { + return false; + } + + return DockAreas[0]->openDockWidgetsCount() == 1; +} + + +//============================================================================ +CDockWidget* CDockContainerWidget::firstVisibleDockWidget() const +{ + return openedDockAreas()[0]->openedDockWidgets()[0]; +} + + +//============================================================================ +CDockWidget* CDockContainerWidget::singleVisibleDockWidget() const +{ + auto DockAreas = openedDockAreas(); + if (DockAreas.count() != 1) + { + return nullptr; + } + + auto DockWidgets = DockAreas[0]->openedDockWidgets(); + if (DockWidgets.count() != 1) + { + return nullptr; + } + + return DockWidgets[0]; +} + + } // namespace ads //--------------------------------------------------------------------------- diff --git a/src/DockContainerWidget.h b/src/DockContainerWidget.h index 40ff2c1..1ac3915 100644 --- a/src/DockContainerWidget.h +++ b/src/DockContainerWidget.h @@ -61,8 +61,10 @@ private: friend class CDockManager; friend struct DockManagerPrivate; friend class CDockAreaWidget; + friend struct DockAreaWidgetPrivate; friend class CFloatingDockContainer; friend struct FloatingDockContainerPrivate; + friend class CDockWidget; protected: /** @@ -110,6 +112,25 @@ protected: */ CDockAreaWidget* lastAddedDockAreaWidget(DockWidgetArea area) const; + /** + * This function returns true if this dock area has only one single + * visible dock widget. + */ + bool hasSingleVisibleDockWidget() const; + + /** + * If hasSingleVisibleDockWidget() returns true, this function returns the + * one and only visible dock widget. Otherwise it returns a nullptr. + */ + CDockWidget* singleVisibleDockWidget() const; + + /** + * Returns the first visible dock widget. + * If the function hasSingleVisibleDockWidget() returns true, then this + * function returns the one and only visible dock widget + */ + CDockWidget* firstVisibleDockWidget() const; + public: /** * Default Constructor diff --git a/src/DockWidget.cpp b/src/DockWidget.cpp index 8e9d5e0..55110cf 100644 --- a/src/DockWidget.cpp +++ b/src/DockWidget.cpp @@ -328,7 +328,7 @@ CDockContainerWidget* CDockWidget::dockContainer() const //============================================================================ CDockAreaWidget* CDockWidget::dockAreaWidget() const { - return internal::findParent(this); + return d->DockArea; } @@ -345,7 +345,7 @@ bool CDockWidget::isFloating() const return false; } - if (dockContainer()->dockArea(0)->dockWidgetsCount() != 1) + if (d->DockArea->openDockWidgetsCount() != 1) { return false; } @@ -357,12 +357,13 @@ bool CDockWidget::isFloating() const //============================================================================ bool CDockWidget::isInFloatingContainer() const { - if (!dockContainer()) + auto Container = dockContainer(); + if (!Container) { return false; } - if (!dockContainer()->isFloating()) + if (!Container->isFloating()) { return false; } @@ -405,6 +406,13 @@ void CDockWidget::setToggleViewActionMode(eToggleViewActionMode Mode) void CDockWidget::toggleView(bool Open) { QAction* Sender = qobject_cast(sender()); + CDockContainerWidget* DockContainer = dockContainer(); + CDockWidget* SingleDockWidget = nullptr;; + if (Open) + { + SingleDockWidget = DockContainer->singleVisibleDockWidget(); + } + if (Sender == d->ToggleViewAction && !d->ToggleViewAction->isCheckable()) { Open = true; @@ -424,6 +432,16 @@ void CDockWidget::toggleView(bool Open) d->ToggleViewAction->blockSignals(false); d->DockArea->toggleDockWidgetView(this, Open); + if (!Open) + { + SingleDockWidget = DockContainer->singleVisibleDockWidget(); + } + + if (SingleDockWidget) + { + SingleDockWidget->dockAreaWidget()->updateDockArea(); + } + if (!Open) { emit closed(); diff --git a/src/DockWidgetTab.cpp b/src/DockWidgetTab.cpp index c253ab6..62dbfa9 100644 --- a/src/DockWidgetTab.cpp +++ b/src/DockWidgetTab.cpp @@ -162,14 +162,15 @@ void DockWidgetTabPrivate::moveTab(QMouseEvent* ev) //============================================================================ bool DockWidgetTabPrivate::startFloating() { - qDebug() << "isFloating " << DockWidget->dockContainer()->isFloating(); - qDebug() << "areaCount " << DockWidget->dockContainer()->dockAreaCount(); + auto dockContainer = DockWidget->dockContainer(); + qDebug() << "isFloating " << dockContainer->isFloating(); + qDebug() << "areaCount " << dockContainer->dockAreaCount(); qDebug() << "widgetCount " << DockWidget->dockAreaWidget()->dockWidgetsCount(); // if this is the last dock widget inside of this floating widget, // then it does not make any sense, to make it floating because // it is already floating - if (DockWidget->dockContainer()->isFloating() - && (DockWidget->dockContainer()->visibleDockAreaCount() == 1) + if (dockContainer->isFloating() + && (dockContainer->visibleDockAreaCount() == 1) && (DockWidget->dockAreaWidget()->dockWidgetsCount() == 1)) { return false; @@ -399,6 +400,17 @@ void CDockWidgetTab::mouseDoubleClickEvent(QMouseEvent *event) Super::mouseDoubleClickEvent(event); } + +//============================================================================ +void CDockWidgetTab::setVisible(bool visible) +{ + if (!visible) + { + qDebug() << "CDockWidgetTab::setVisible " << visible; + } + Super::setVisible(visible); +} + } // namespace ads //--------------------------------------------------------------------------- diff --git a/src/DockWidgetTab.h b/src/DockWidgetTab.h index dd2c07e..a300db3 100644 --- a/src/DockWidgetTab.h +++ b/src/DockWidgetTab.h @@ -116,6 +116,9 @@ public: */ const QIcon& icon() const; +public slots: + virtual void setVisible(bool visible); + signals: void activeTabChanged(); void clicked();