3737#include < QVariant>
3838#include < QDebug>
3939#include < QXmlStreamWriter>
40+ #include < QAbstractButton>
4041
4142#include " DockManager.h"
4243#include " DockAreaWidget.h"
@@ -105,6 +106,7 @@ class DockContainerWidgetPrivate
105106 bool isFloating = false ;
106107 CDockAreaWidget* LastAddedAreaCache[5 ]{0 , 0 , 0 , 0 , 0 };
107108 int VisibleDockAreaCount = -1 ;
109+ CDockAreaWidget* TopLevelDockArea = nullptr ;
108110
109111 /* *
110112 * Private data constructor
@@ -144,6 +146,12 @@ class DockContainerWidgetPrivate
144146 */
145147 void addDockAreasToList (const QList<CDockAreaWidget*> NewDockAreas);
146148
149+ /* *
150+ * Wrapper function for DockAreas append, that ensures that dock area signals
151+ * are properly connected to dock container slots
152+ */
153+ void appendDockAreas (const QList<CDockAreaWidget*> NewDockAreas);
154+
147155 /* *
148156 * Save state of child nodes
149157 */
@@ -208,11 +216,31 @@ class DockContainerWidgetPrivate
208216 return VisibleDockAreaCount;
209217 }
210218
219+ /* *
220+ * The visible dock area count changes, if dock areas are remove, added or
221+ * when its view is toggled
222+ */
223+ void onVisibleDockAreaCountChanged ();
224+
225+ void emitDockAreasRemoved ()
226+ {
227+ onVisibleDockAreaCountChanged ();
228+ emit _this->dockAreasRemoved ();
229+ }
230+
231+ void emitDockAreasAdded ()
232+ {
233+ onVisibleDockAreaCountChanged ();
234+ emit _this->dockAreasAdded ();
235+ }
236+
211237// private slots: ------------------------------------------------------------
212238 void onDockAreaViewToggled (bool Visible)
213239 {
214- std::cout << " onDockAreaViewToggled " << Visible << std::endl ;
240+ CDockAreaWidget* DockArea = qobject_cast<CDockAreaWidget*>(_this-> sender ()) ;
215241 VisibleDockAreaCount += Visible ? 1 : -1 ;
242+ onVisibleDockAreaCountChanged ();
243+ emit _this->dockAreaViewToggled (DockArea, Visible);
216244 }
217245}; // struct DockContainerWidgetPrivate
218246
@@ -225,6 +253,24 @@ DockContainerWidgetPrivate::DockContainerWidgetPrivate(CDockContainerWidget* _pu
225253}
226254
227255
256+ // ============================================================================
257+ void DockContainerWidgetPrivate::onVisibleDockAreaCountChanged ()
258+ {
259+ auto TopLevelDockArea = _this->topLevelDockArea ();
260+
261+ if (TopLevelDockArea)
262+ {
263+ this ->TopLevelDockArea = TopLevelDockArea;
264+ TopLevelDockArea->titleBarButton (TitleBarButtonUndock)->setVisible (false || !_this->isFloating ());
265+ }
266+ else if (this ->TopLevelDockArea )
267+ {
268+ this ->TopLevelDockArea ->titleBarButton (TitleBarButtonUndock)->setVisible (true );
269+ this ->TopLevelDockArea = nullptr ;
270+ }
271+ }
272+
273+
228274// ============================================================================
229275void DockContainerWidgetPrivate::dropIntoContainer (CFloatingDockContainer* FloatingWidget,
230276 DockWidgetArea area)
@@ -299,7 +345,7 @@ void DockContainerWidgetPrivate::dropIntoSection(CFloatingDockContainer* Floatin
299345 }
300346 TargetArea->setCurrentIndex (0 ); // make the topmost widget active
301347 FloatingWidget->deleteLater ();
302- TargetArea->updateTabBarVisibility ();
348+ TargetArea->updateTitleBarVisibility ();
303349 return ;
304350 }
305351
@@ -364,21 +410,39 @@ void DockContainerWidgetPrivate::addDockAreasToList(const QList<CDockAreaWidget*
364410{
365411 int CountBefore = DockAreas.count ();
366412 int NewAreaCount = NewDockAreas.count ();
367- DockAreas.append (NewDockAreas);
413+ appendDockAreas (NewDockAreas);
414+ // If the user dropped a floating widget that contains only one single
415+ // visible dock area, then its title bar button TitleBarButtonUndock is
416+ // likely hidden. We need to ensure, that it is visible
417+ for (auto DockArea : NewDockAreas)
418+ {
419+ DockArea->titleBarButton (TitleBarButtonUndock)->setVisible (true );
420+ }
368421
369422 // We need to ensure, that the dock area title bar is visible. The title bar
370423 // is invisible, if the dock are is a single dock area in a floating widget.
371424 if (1 == CountBefore)
372425 {
373- DockAreas.at (0 )->updateTabBarVisibility ();
426+ DockAreas.at (0 )->updateTitleBarVisibility ();
374427 }
375428
376429 if (1 == NewAreaCount)
377430 {
378- DockAreas.last ()->updateTabBarVisibility ();
431+ DockAreas.last ()->updateTitleBarVisibility ();
379432 }
380433
381- emit _this->dockAreasAdded ();
434+ emitDockAreasAdded ();
435+ }
436+
437+
438+ // ============================================================================
439+ void DockContainerWidgetPrivate::appendDockAreas (const QList<CDockAreaWidget*> NewDockAreas)
440+ {
441+ DockAreas.append (NewDockAreas);
442+ for (auto DockArea : NewDockAreas)
443+ {
444+ _this->connect (DockArea, SIGNAL (viewToggled (bool )), SLOT (onDockAreaViewToggled (bool )));
445+ }
382446}
383447
384448
@@ -588,7 +652,7 @@ bool DockContainerWidgetPrivate::restoreDockArea(QXmlStreamReader& s,
588652 else
589653 {
590654 DockArea->setProperty (" currentDockWidget" , CurrentDockWidget);
591- DockAreas. append ( DockArea);
655+ appendDockAreas ({ DockArea} );
592656 }
593657
594658 CreatedWidget = DockArea;
@@ -631,7 +695,7 @@ CDockAreaWidget* DockContainerWidgetPrivate::dockWidgetIntoContainer(DockWidgetA
631695 CDockAreaWidget* NewDockArea = new CDockAreaWidget (DockManager, _this);
632696 NewDockArea->addDockWidget (Dockwidget);
633697 addDockArea (NewDockArea, area);
634- NewDockArea->updateTabBarVisibility ();
698+ NewDockArea->updateTitleBarVisibility ();
635699 LastAddedAreaCache[areaIdToIndex (area)] = NewDockArea;
636700 return NewDockArea;
637701}
@@ -673,9 +737,9 @@ void DockContainerWidgetPrivate::addDockArea(CDockAreaWidget* NewDockArea, DockW
673737 RootSplitter = NewSplitter;
674738 }
675739
676- DockAreas. append ( NewDockArea);
677- NewDockArea->updateTabBarVisibility ();
678- emit _this-> dockAreasAdded ();
740+ appendDockAreas ({ NewDockArea} );
741+ NewDockArea->updateTitleBarVisibility ();
742+ emitDockAreasAdded ();
679743}
680744
681745
@@ -744,8 +808,8 @@ CDockAreaWidget* DockContainerWidgetPrivate::dockWidgetIntoDockArea(DockWidgetAr
744808 TargetAreaSplitter->insertWidget (index, NewSplitter);
745809 }
746810
747- DockAreas. append ( NewDockArea);
748- emit _this-> dockAreasAdded ();
811+ appendDockAreas ({ NewDockArea} );
812+ emitDockAreasAdded ();
749813 return NewDockArea;
750814}
751815
@@ -853,6 +917,7 @@ void CDockContainerWidget::addDockArea(CDockAreaWidget* DockAreaWidget,
853917void CDockContainerWidget::removeDockArea (CDockAreaWidget* area)
854918{
855919 qDebug () << " CDockContainerWidget::removeDockArea" ;
920+ area->disconnect (this );
856921 d->DockAreas .removeAll (area);
857922 CDockSplitter* Splitter = internal::findParent<CDockSplitter*>(area);
858923
@@ -913,7 +978,7 @@ void CDockContainerWidget::removeDockArea(CDockAreaWidget* area)
913978 // one single visible dock widget
914979 CDockWidget::emitTopLevelEventForWidget (TopLevelWidget, true );
915980 dumpLayout ();
916- emit dockAreasRemoved ();
981+ d-> emitDockAreasRemoved ();
917982}
918983
919984
0 commit comments