@@ -62,6 +62,7 @@ struct DockWidgetPrivate
6262 CDockManager* DockManager = nullptr ;
6363 CDockAreaWidget* DockArea = nullptr ;
6464 QAction* ToggleViewAction;
65+ bool Closed = false ;
6566 struct CapturedState
6667 {
6768 QString DockTreePosition;
@@ -83,6 +84,16 @@ struct DockWidgetPrivate
8384 * Show dock widget
8485 */
8586 void showDockWidget ();
87+
88+ /* *
89+ * Hides a parent splitter if all dock widgets in the splitter are closed
90+ */
91+ void hideEmptyParentSplitter ();
92+
93+ /* *
94+ * Hides a dock area if all dock widgets in the area are closed
95+ */
96+ void hideEmptyParentDockArea ();
8697};
8798// struct DockWidgetPrivate
8899
@@ -131,36 +142,59 @@ void DockWidgetPrivate::capturedState()
131142// ============================================================================
132143void DockWidgetPrivate::showDockWidget ()
133144{
134- /* if (!CapturedState.DockContainer)
145+ DockArea->show ();
146+ DockArea->setCurrentIndex (DockArea->tabIndex (_this));
147+ QSplitter* Splitter = internal::findParent<QSplitter*>(_this);
148+ if (Splitter)
135149 {
136- auto FloatingWidget = new CFloatingDockContainer(_this);
137- FloatingWidget->setGeometry(CapturedState.GlobalGeometry);
138- FloatingWidget->show();
139- return;
150+ Splitter->show ();
140151 }
152+ }
141153
142- CDockContainerWidget* DockContainer = CapturedState.DockContainer.data();
143- QStringList DockTree = this->CapturedState.DockTreePosition.split(' ');
144- QSplitter* splitter = DockContainer->findChild<QSplitter*>(QString(), Qt::FindDirectChildrenOnly);
145154
146- while (splitter)
155+ // ============================================================================
156+ void DockWidgetPrivate::hideEmptyParentSplitter ()
157+ {
158+ QSplitter* Splitter = internal::findParent<QSplitter*>(_this);
159+ if (!Splitter)
147160 {
148-
161+ return ;
149162 }
150163
151- for (const auto& TreeItem : DockTree )
164+ for (int i = 0 ; i < Splitter-> count (); ++i )
152165 {
166+ if (Splitter->widget (i)->isVisible ())
167+ {
168+ return ;
169+ }
170+ }
153171
154- }*/
172+ Splitter->hide ();
173+ }
155174
156- std::cout << " DockWidgetPrivate::showDockWidget()" << std::endl;
157- _this->show ();
158- DockArea->show ();
159175
160- QSplitter* Splitter = internal::findParent<QSplitter*>(_this);
161- if (Splitter)
176+ // ============================================================================
177+ void DockWidgetPrivate::hideEmptyParentDockArea ()
178+ {
179+ auto OpenDockWidgets = DockArea->openDockWidgets ();
180+ if (OpenDockWidgets.count () > 1 )
162181 {
163- Splitter->show ();
182+ CDockWidget* NextDockWidget;
183+ if (OpenDockWidgets.last () == _this)
184+ {
185+ NextDockWidget = OpenDockWidgets[OpenDockWidgets.count () - 2 ];
186+ }
187+ else
188+ {
189+ int NextIndex = OpenDockWidgets.indexOf (_this) + 1 ;
190+ NextDockWidget = OpenDockWidgets[NextIndex];
191+ }
192+
193+ DockArea->setCurrentDockWidget (NextDockWidget);
194+ }
195+ else
196+ {
197+ DockArea->hide ();
164198 }
165199}
166200
@@ -270,6 +304,13 @@ bool CDockWidget::isFloating() const
270304}
271305
272306
307+ // ============================================================================
308+ bool CDockWidget::isClosed () const
309+ {
310+ return d->Closed ;
311+ }
312+
313+
273314// ============================================================================
274315QAction* CDockWidget::toggleViewAction () const
275316{
@@ -280,28 +321,15 @@ QAction* CDockWidget::toggleViewAction() const
280321// ============================================================================
281322void CDockWidget::toggleView (bool Open)
282323{
283- /* if ((d->DockArea != nullptr) == Open)
284- {
285- return;
286- }
287-
288- if (!Open && d->DockArea)
289- {
290- hideDockWidget(true);
291- }
292- else if (Open && !d->DockArea)
293- {
294- d->showDockWidget();
295- }*/
296-
297324 if (Open)
298325 {
299326 d->showDockWidget ();
300327 }
301328 else
302329 {
303- hideDockWidget (true );
330+ hideDockWidget ();
304331 }
332+ d->Closed = !Open;
305333}
306334
307335
@@ -315,59 +343,13 @@ void CDockWidget::setDockArea(CDockAreaWidget* DockArea)
315343
316344
317345// ============================================================================
318- void CDockWidget::hideDockWidget (bool RemoveFromDockArea )
346+ void CDockWidget::hideDockWidget ()
319347{
320- /* d->capturedState();
321- if (d->DockArea && RemoveFromDockArea)
322- {
323- d->DockArea->removeDockWidget(this);
324- }
325- this->setParent(d->DockManager);
326- this->setDockArea(nullptr);
327- // Remove title from dock area widget to prevent its deletion if dock
328- // area is deleted
329- d->TitleWidget->setParent(this);*/
330-
331- std::cout << " CDockWidget::hideDockWidget" << std::endl;
332- this ->hide ();
348+ CDockAreaWidget* DockArea = d->DockArea ;
333349 d->ToggleViewAction ->setChecked (false );
334350 d->TitleWidget ->hide ();
335- CDockAreaWidget* DockArea = d->DockArea ;
336- for (int i = 0 ; i < DockArea->count (); ++i)
337- {
338- if (DockArea->dockWidget (i)->isVisible ())
339- {
340- return ;
341- }
342- }
343-
344- if (DockArea->count () > 1 )
345- {
346- if (DockArea->currentIndex () == (DockArea->count () - 1 ))
347- {
348- DockArea->setCurrentIndex (DockArea->currentIndex () - 1 );
349- }
350- else
351- {
352- DockArea->setCurrentIndex (DockArea->currentIndex () + 1 );
353- }
354- }
355- QSplitter* Splitter = internal::findParent<QSplitter*>(this );
356- if (!Splitter)
357- {
358- return ;
359- }
360-
361- std::cout << " DockWidgets " << Splitter->count () << std::endl;
362- for (int i = 0 ; i < Splitter->count (); ++i)
363- {
364- if (Splitter->widget (i)->isVisible ())
365- {
366- return ;
367- }
368- }
369-
370- Splitter->hide ();
351+ d->hideEmptyParentDockArea ();
352+ d->hideEmptyParentSplitter ();
371353}
372354
373355} // namespace ads
0 commit comments