37
37
#include < QVariant>
38
38
#include < QDebug>
39
39
#include < QXmlStreamWriter>
40
+ #include < QAbstractButton>
40
41
41
42
#include " DockManager.h"
42
43
#include " DockAreaWidget.h"
@@ -105,6 +106,7 @@ class DockContainerWidgetPrivate
105
106
bool isFloating = false ;
106
107
CDockAreaWidget* LastAddedAreaCache[5 ]{0 , 0 , 0 , 0 , 0 };
107
108
int VisibleDockAreaCount = -1 ;
109
+ CDockAreaWidget* TopLevelDockArea = nullptr ;
108
110
109
111
/* *
110
112
* Private data constructor
@@ -144,6 +146,12 @@ class DockContainerWidgetPrivate
144
146
*/
145
147
void addDockAreasToList (const QList<CDockAreaWidget*> NewDockAreas);
146
148
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
+
147
155
/* *
148
156
* Save state of child nodes
149
157
*/
@@ -208,11 +216,31 @@ class DockContainerWidgetPrivate
208
216
return VisibleDockAreaCount;
209
217
}
210
218
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
+
211
237
// private slots: ------------------------------------------------------------
212
238
void onDockAreaViewToggled (bool Visible)
213
239
{
214
- std::cout << " onDockAreaViewToggled " << Visible << std::endl ;
240
+ CDockAreaWidget* DockArea = qobject_cast<CDockAreaWidget*>(_this-> sender ()) ;
215
241
VisibleDockAreaCount += Visible ? 1 : -1 ;
242
+ onVisibleDockAreaCountChanged ();
243
+ emit _this->dockAreaViewToggled (DockArea, Visible);
216
244
}
217
245
}; // struct DockContainerWidgetPrivate
218
246
@@ -225,6 +253,24 @@ DockContainerWidgetPrivate::DockContainerWidgetPrivate(CDockContainerWidget* _pu
225
253
}
226
254
227
255
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
+
228
274
// ============================================================================
229
275
void DockContainerWidgetPrivate::dropIntoContainer (CFloatingDockContainer* FloatingWidget,
230
276
DockWidgetArea area)
@@ -299,7 +345,7 @@ void DockContainerWidgetPrivate::dropIntoSection(CFloatingDockContainer* Floatin
299
345
}
300
346
TargetArea->setCurrentIndex (0 ); // make the topmost widget active
301
347
FloatingWidget->deleteLater ();
302
- TargetArea->updateTabBarVisibility ();
348
+ TargetArea->updateTitleBarVisibility ();
303
349
return ;
304
350
}
305
351
@@ -364,21 +410,39 @@ void DockContainerWidgetPrivate::addDockAreasToList(const QList<CDockAreaWidget*
364
410
{
365
411
int CountBefore = DockAreas.count ();
366
412
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
+ }
368
421
369
422
// We need to ensure, that the dock area title bar is visible. The title bar
370
423
// is invisible, if the dock are is a single dock area in a floating widget.
371
424
if (1 == CountBefore)
372
425
{
373
- DockAreas.at (0 )->updateTabBarVisibility ();
426
+ DockAreas.at (0 )->updateTitleBarVisibility ();
374
427
}
375
428
376
429
if (1 == NewAreaCount)
377
430
{
378
- DockAreas.last ()->updateTabBarVisibility ();
431
+ DockAreas.last ()->updateTitleBarVisibility ();
379
432
}
380
433
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
+ }
382
446
}
383
447
384
448
@@ -588,7 +652,7 @@ bool DockContainerWidgetPrivate::restoreDockArea(QXmlStreamReader& s,
588
652
else
589
653
{
590
654
DockArea->setProperty (" currentDockWidget" , CurrentDockWidget);
591
- DockAreas. append ( DockArea);
655
+ appendDockAreas ({ DockArea} );
592
656
}
593
657
594
658
CreatedWidget = DockArea;
@@ -631,7 +695,7 @@ CDockAreaWidget* DockContainerWidgetPrivate::dockWidgetIntoContainer(DockWidgetA
631
695
CDockAreaWidget* NewDockArea = new CDockAreaWidget (DockManager, _this);
632
696
NewDockArea->addDockWidget (Dockwidget);
633
697
addDockArea (NewDockArea, area);
634
- NewDockArea->updateTabBarVisibility ();
698
+ NewDockArea->updateTitleBarVisibility ();
635
699
LastAddedAreaCache[areaIdToIndex (area)] = NewDockArea;
636
700
return NewDockArea;
637
701
}
@@ -673,9 +737,9 @@ void DockContainerWidgetPrivate::addDockArea(CDockAreaWidget* NewDockArea, DockW
673
737
RootSplitter = NewSplitter;
674
738
}
675
739
676
- DockAreas. append ( NewDockArea);
677
- NewDockArea->updateTabBarVisibility ();
678
- emit _this-> dockAreasAdded ();
740
+ appendDockAreas ({ NewDockArea} );
741
+ NewDockArea->updateTitleBarVisibility ();
742
+ emitDockAreasAdded ();
679
743
}
680
744
681
745
@@ -744,8 +808,8 @@ CDockAreaWidget* DockContainerWidgetPrivate::dockWidgetIntoDockArea(DockWidgetAr
744
808
TargetAreaSplitter->insertWidget (index, NewSplitter);
745
809
}
746
810
747
- DockAreas. append ( NewDockArea);
748
- emit _this-> dockAreasAdded ();
811
+ appendDockAreas ({ NewDockArea} );
812
+ emitDockAreasAdded ();
749
813
return NewDockArea;
750
814
}
751
815
@@ -853,6 +917,7 @@ void CDockContainerWidget::addDockArea(CDockAreaWidget* DockAreaWidget,
853
917
void CDockContainerWidget::removeDockArea (CDockAreaWidget* area)
854
918
{
855
919
qDebug () << " CDockContainerWidget::removeDockArea" ;
920
+ area->disconnect (this );
856
921
d->DockAreas .removeAll (area);
857
922
CDockSplitter* Splitter = internal::findParent<CDockSplitter*>(area);
858
923
@@ -913,7 +978,7 @@ void CDockContainerWidget::removeDockArea(CDockAreaWidget* area)
913
978
// one single visible dock widget
914
979
CDockWidget::emitTopLevelEventForWidget (TopLevelWidget, true );
915
980
dumpLayout ();
916
- emit dockAreasRemoved ();
981
+ d-> emitDockAreasRemoved ();
917
982
}
918
983
919
984
0 commit comments