@@ -258,7 +258,7 @@ struct DockAreaWidgetPrivate
258258 * Updates the tab bar visibility depending on the number of dock widgets
259259 * in this area
260260 */
261- void updateTabBar ();
261+ void updateTitleBarVisibility ();
262262
263263 /* *
264264 * Convenience function for tabbar access
@@ -294,7 +294,7 @@ void DockAreaWidgetPrivate::createTitleBar()
294294
295295
296296// ============================================================================
297- void DockAreaWidgetPrivate::updateTabBar ()
297+ void DockAreaWidgetPrivate::updateTitleBarVisibility ()
298298{
299299 CDockContainerWidget* Container = _this->dockContainer ();
300300 if (!Container)
@@ -358,7 +358,11 @@ void CDockAreaWidget::insertDockWidget(int index, CDockWidget* DockWidget,
358358 d->ContentsLayout ->insertWidget (index, DockWidget);
359359 DockWidget->tabWidget ()->setDockAreaWidget (this );
360360 auto TabWidget = DockWidget->tabWidget ();
361+ // Inserting the tab will change the current index which in turn will
362+ // make the tab widget visible in the slot
363+ d->tabBar ()->blockSignals (true );
361364 d->tabBar ()->insertTab (index, TabWidget);
365+ d->tabBar ()->blockSignals (false );
362366 TabWidget->setVisible (!DockWidget->isClosed ());
363367 DockWidget->setProperty (INDEX_PROPERTY, index);
364368 if (Activate)
@@ -398,7 +402,7 @@ void CDockAreaWidget::removeDockWidget(CDockWidget* DockWidget)
398402 hideAreaWithNoVisibleContent ();
399403 }
400404
401- d->updateTabBar ();
405+ d->updateTitleBarVisibility ();
402406 auto TopLevelDockWidget = dockContainer ()->topLevelDockWidget ();
403407 if (TopLevelDockWidget)
404408 {
@@ -415,6 +419,7 @@ void CDockAreaWidget::removeDockWidget(CDockWidget* DockWidget)
415419// ============================================================================
416420void CDockAreaWidget::hideAreaWithNoVisibleContent ()
417421{
422+ std::cout << " CDockAreaWidget::hideAreaWithNoVisibleContent()" << std::endl;
418423 this ->toggleView (false );
419424
420425 // Hide empty parent splitter
@@ -430,9 +435,21 @@ void CDockAreaWidget::hideAreaWithNoVisibleContent()
430435
431436 // Hide empty floating widget
432437 CDockContainerWidget* Container = this ->dockContainer ();
433- if (Container->isFloating () && Container->openedDockAreas ().isEmpty ())
438+ if (!Container->isFloating ())
439+ {
440+ return ;
441+ }
442+
443+ d->updateTitleBarVisibility ();
444+ auto TopLevelWidget = Container->topLevelDockWidget ();
445+ auto FloatingWidget = Container->floatingWidget ();
446+ if (TopLevelWidget)
447+ {
448+ FloatingWidget->updateWindowTitle ();
449+ CDockWidget::emitTopLevelEventForWidget (TopLevelWidget, true );
450+ }
451+ else if (Container->openedDockAreas ().isEmpty ())
434452 {
435- CFloatingDockContainer* FloatingWidget = internal::findParent<CFloatingDockContainer*>(Container);
436453 FloatingWidget->hide ();
437454 }
438455}
@@ -449,7 +466,13 @@ void CDockAreaWidget::onTabCloseRequested(int Index)
449466// ============================================================================
450467CDockWidget* CDockAreaWidget::currentDockWidget () const
451468{
452- return dockWidget (currentIndex ());
469+ int CurrentIndex = currentIndex ();
470+ if (CurrentIndex < 0 )
471+ {
472+ return nullptr ;
473+ }
474+
475+ return dockWidget (CurrentIndex);
453476}
454477
455478
@@ -576,7 +599,7 @@ int CDockAreaWidget::dockWidgetsCount() const
576599// ============================================================================
577600CDockWidget* CDockAreaWidget::dockWidget (int Index) const
578601{
579- return dynamic_cast <CDockWidget*>(d->ContentsLayout ->widget (Index));
602+ return qobject_cast <CDockWidget*>(d->ContentsLayout ->widget (Index));
580603}
581604
582605
@@ -610,7 +633,7 @@ void CDockAreaWidget::toggleDockWidgetView(CDockWidget* DockWidget, bool Open)
610633// ============================================================================
611634void CDockAreaWidget::updateTabBarVisibility ()
612635{
613- d->updateTabBar ();
636+ d->updateTitleBarVisibility ();
614637}
615638
616639
@@ -619,9 +642,11 @@ void CDockAreaWidget::saveState(QXmlStreamWriter& s) const
619642{
620643 s.writeStartElement (" DockAreaWidget" );
621644 s.writeAttribute (" Tabs" , QString::number (d->ContentsLayout ->count ()));
622- s.writeAttribute (" CurrentDockWidget" , currentDockWidget ()->objectName ());
645+ auto CurrentDockWidget = currentDockWidget ();
646+ QString Name = CurrentDockWidget ? CurrentDockWidget->objectName () : " " ;
647+ s.writeAttribute (" CurrentDockWidget" , Name);
623648 qDebug () << " CDockAreaWidget::saveState TabCount: " << d->ContentsLayout ->count ()
624- << " CurrentDockWidge: " << currentDockWidget ()-> objectName () ;
649+ << " CurrentDockWidge: " << Name ;
625650 for (int i = 0 ; i < d->ContentsLayout ->count (); ++i)
626651 {
627652 dockWidget (i)->saveState (s);
@@ -675,6 +700,13 @@ void CDockAreaWidget::toggleView(bool Open)
675700 setVisible (Open);
676701 emit viewToggled (Open);
677702}
703+
704+
705+ // ============================================================================
706+ QAbstractButton* CDockAreaWidget::titleBarButton (TitleBarButton which) const
707+ {
708+ return d->TitleBar ->button (which);
709+ }
678710} // namespace ads
679711
680712// ---------------------------------------------------------------------------
0 commit comments