Skip to content

Commit c57d14d

Browse files
author
Uwe Kindler
committed
Implemented restoring of hidden floating widgets
1 parent 52aedfe commit c57d14d

File tree

11 files changed

+279
-43
lines changed

11 files changed

+279
-43
lines changed

AdvancedDockingSystem/res/stylesheets/default-windows2.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ ads--CDockWidget
6060
QPushButton#closeButton,
6161
QPushButton#tabsMenuButton
6262
{
63-
padding: 1px;
63+
padding: 2px;
6464
}
6565

6666

AdvancedDockingSystem/src/v2/DockAreaWidget.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ void DockAreaWidgetPrivate::createTabBar()
314314
CloseButton->setToolTip(_this->tr("Close"));
315315
CloseButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
316316
TopLayout->addWidget(CloseButton, 0);
317-
//connect(_closeButton, SIGNAL(clicked(bool)), this, SLOT(onCloseButtonClicked()));
317+
_this->connect(CloseButton, SIGNAL(clicked()), SLOT(onCloseButtonClicked()));
318318

319319
TabsLayoutInitCount = TabsLayout->count();
320320
}
@@ -429,7 +429,6 @@ CDockContainerWidget* CDockAreaWidget::dockContainer() const
429429
void CDockAreaWidget::addDockWidget(CDockWidget* DockWidget)
430430
{
431431
insertDockWidget(d->ContentsLayout->count(), DockWidget);
432-
433432
}
434433

435434

@@ -441,13 +440,15 @@ void CDockAreaWidget::insertDockWidget(int index, CDockWidget* DockWidget,
441440
DockWidget->titleBar()->setDockAreaWidget(this);
442441
auto TitleBar = DockWidget->titleBar();
443442
d->TabsLayout->insertWidget(index, TitleBar);
443+
TitleBar->show();
444444
connect(TitleBar, SIGNAL(clicked()), this, SLOT(onDockWidgetTitleClicked()));
445445
DockWidget->setProperty(INDEX_PROPERTY, index);
446446
if (Activate)
447447
{
448448
setCurrentIndex(index);
449449
}
450450
d->addTabsMenuEntry(DockWidget, index);
451+
DockWidget->setDockArea(this);
451452
}
452453

453454

@@ -457,6 +458,7 @@ void CDockAreaWidget::removeDockWidget(CDockWidget* DockWidget)
457458
std::cout << "CDockAreaWidget::removeDockWidget" << std::endl;
458459
d->ContentsLayout->removeWidget(DockWidget);
459460
auto TitleBar = DockWidget->titleBar();
461+
TitleBar->hide();
460462
d->TabsLayout->removeWidget(TitleBar);
461463
disconnect(TitleBar, SIGNAL(clicked()), this, SLOT(onDockWidgetTitleClicked()));
462464
setCurrentIndex(d->ContentsLayout->currentIndex());
@@ -470,6 +472,7 @@ void CDockAreaWidget::removeDockWidget(CDockWidget* DockWidget)
470472
}
471473

472474
d->updateTabBar();
475+
DockWidget->setDockArea(nullptr);
473476
}
474477

475478

@@ -487,6 +490,20 @@ void CDockAreaWidget::onDockWidgetTitleClicked()
487490
}
488491

489492

493+
//============================================================================
494+
void CDockAreaWidget::onCloseButtonClicked()
495+
{
496+
currentDockWidget()->toggleView(false);
497+
}
498+
499+
500+
//============================================================================
501+
CDockWidget* CDockAreaWidget::currentDockWidget() const
502+
{
503+
return dockWidget(currentIndex());
504+
}
505+
506+
490507
//============================================================================
491508
void CDockAreaWidget::setCurrentIndex(int index)
492509
{
@@ -630,8 +647,6 @@ void CDockAreaWidget::reorderDockWidget(int fromIndex, int toIndex)
630647
liFrom = d->ContentsLayout->takeAt(fromIndex);
631648
d->ContentsLayout->insertWidget(toIndex, liFrom->widget());
632649
delete liFrom;
633-
634-
//Menu->removeAction()
635650
}
636651

637652

AdvancedDockingSystem/src/v2/DockAreaWidget.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class CDockAreaWidget : public QFrame
5454
private slots:
5555
void onDockWidgetTitleClicked();
5656
void onTabsMenuActionTriggered(QAction* Action);
57+
void onCloseButtonClicked();
5758

5859
public:
5960
/**
@@ -143,6 +144,11 @@ private slots:
143144
*/
144145
int currentIndex() const;
145146

147+
/**
148+
* Returns the current active dock widget
149+
*/
150+
CDockWidget* currentDockWidget() const;
151+
146152
public slots:
147153
/**
148154
* This sets the index position of the current tab page.

AdvancedDockingSystem/src/v2/DockContainerWidget.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ CDockContainerWidget::CDockContainerWidget(CDockManager* DockManager, QWidget *p
411411
}
412412

413413
d->Layout = new QGridLayout();
414-
d->Layout->setContentsMargins(0, 1, 0, 0);
414+
d->Layout->setContentsMargins(0, 1, 0, 1);
415415
d->Layout->setSpacing(0);
416416
setLayout(d->Layout);
417417
}
@@ -539,6 +539,13 @@ CDockAreaWidget* CDockContainerWidget::dockAreaAt(const QPoint& GlobalPos) const
539539
}
540540

541541

542+
//============================================================================
543+
CDockAreaWidget* CDockContainerWidget::dockArea(int Index) const
544+
{
545+
return (Index < dockAreaCount()) ? d->DockAreas[Index] : 0;
546+
}
547+
548+
542549
//============================================================================
543550
bool CDockContainerWidget::isFloating() const
544551
{

AdvancedDockingSystem/src/v2/DockContainerWidget.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ class CDockContainerWidget : public QFrame
111111
*/
112112
CDockAreaWidget* dockAreaAt(const QPoint& GlobalPos) const;
113113

114+
/**
115+
* Returns the dock area at the given Index or 0 if the index is out of
116+
* range
117+
*/
118+
CDockAreaWidget* dockArea(int Index) const;
119+
114120
/**
115121
* Returns the number of dock areas in this container
116122
*/

AdvancedDockingSystem/src/v2/DockWidget.cpp

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,19 @@
3131
#include "DockWidget.h"
3232

3333
#include <QBoxLayout>
34+
#include <QAction>
35+
#include <QSplitter>
36+
#include <QStack>
37+
#include <QTextStream>
38+
39+
#include <iostream>
3440

3541
#include "DockWidgetTitleBar.h"
3642
#include "DockContainerWidget.h"
3743
#include "DockAreaWidget.h"
44+
#include "DockManager.h"
45+
#include "FloatingDockContainer.h"
46+
3847
#include "ads_globals.h"
3948

4049
namespace ads
@@ -50,11 +59,24 @@ struct DockWidgetPrivate
5059
CDockWidgetTitleBar* TitleWidget;
5160
CDockWidget::DockWidgetFeatures Features = CDockWidget::AllDockWidgetFeatures;
5261
CDockManager* DockManager = nullptr;
62+
CDockAreaWidget* DockArea = nullptr;
63+
QAction* ToggleViewAction;
64+
QString CapturedState;
5365

5466
/**
5567
* Private data constructor
5668
*/
5769
DockWidgetPrivate(CDockWidget* _public);
70+
71+
/**
72+
* Saves the current state into CapturedState variable
73+
*/
74+
void capturedState();
75+
76+
/**
77+
* Show dock widget
78+
*/
79+
void showDockWidget();
5880
};
5981
// struct DockWidgetPrivate
6082

@@ -65,6 +87,75 @@ DockWidgetPrivate::DockWidgetPrivate(CDockWidget* _public) :
6587

6688
}
6789

90+
91+
//============================================================================
92+
void DockWidgetPrivate::capturedState()
93+
{
94+
QString CapturedState;
95+
QTextStream stream(&CapturedState);
96+
stream << (_this->isFloating() ? "F " : "D ");
97+
if (_this->isFloating())
98+
{
99+
CFloatingDockContainer* FloatingWidget = internal::findParent<CFloatingDockContainer*>(_this);
100+
QRect Rect = FloatingWidget->geometry();
101+
stream << Rect.left() << " " << Rect.top() << " " << Rect.width()
102+
<< " " << Rect.height();
103+
}
104+
else
105+
{
106+
QWidget* Widget = DockArea;
107+
QSplitter* splitter = internal::findParent<QSplitter*>(Widget);
108+
QStack<QString> SplitterData;
109+
while (splitter)
110+
{
111+
SplitterData.push(QString("%1%2")
112+
.arg((splitter->orientation() == Qt::Horizontal) ? "H" : "V")
113+
.arg(splitter->indexOf(Widget)));
114+
Widget = splitter;
115+
splitter = internal::findParent<QSplitter*>(Widget);
116+
}
117+
118+
QString Separator;
119+
while (!SplitterData.isEmpty())
120+
{
121+
stream << Separator << SplitterData.pop();
122+
Separator = " ";
123+
}
124+
}
125+
this->CapturedState = CapturedState;
126+
std::cout << "SerializedPosition: " << CapturedState.toStdString() << std::endl;
127+
}
128+
129+
130+
//============================================================================
131+
void DockWidgetPrivate::showDockWidget()
132+
{
133+
QTextStream stream(&CapturedState);
134+
QString DockedState;
135+
stream >> DockedState;
136+
if (DockedState == "F")
137+
{
138+
std::cout << "Restoring Floating Dock Widget" << std::endl;
139+
QVector<int> v;
140+
while (!stream.atEnd())
141+
{
142+
int Value;
143+
stream >> Value;
144+
v.append(Value);
145+
}
146+
147+
if (v.count() == 4)
148+
{
149+
std::cout << "Rectangle Loaded" << std::endl;
150+
QRect Rect(v[0], v[1], v[2], v[3]);
151+
auto FloatingWidget = new CFloatingDockContainer(_this);
152+
FloatingWidget->setGeometry(Rect);
153+
FloatingWidget->show();
154+
}
155+
}
156+
}
157+
158+
68159
//============================================================================
69160
CDockWidget::CDockWidget(const QString &title, QWidget *parent) :
70161
QFrame(parent),
@@ -77,11 +168,16 @@ CDockWidget::CDockWidget(const QString &title, QWidget *parent) :
77168
setWindowTitle(title);
78169

79170
d->TitleWidget = new CDockWidgetTitleBar(this);
171+
d->ToggleViewAction = new QAction(title);
172+
d->ToggleViewAction->setCheckable(true);
173+
connect(d->ToggleViewAction, SIGNAL(triggered(bool)), this,
174+
SLOT(toggleView(bool)));
80175
}
81176

82177
//============================================================================
83178
CDockWidget::~CDockWidget()
84179
{
180+
std::cout << "~CDockWidget()" << std::endl;
85181
delete d;
86182
}
87183

@@ -157,6 +253,64 @@ CDockAreaWidget* CDockWidget::dockAreaWidget() const
157253
return internal::findParent<CDockAreaWidget*>(this);
158254
}
159255

256+
257+
//============================================================================
258+
bool CDockWidget::isFloating() const
259+
{
260+
return dockContainer() ? dockContainer()->isFloating() : false;
261+
}
262+
263+
264+
//============================================================================
265+
QAction* CDockWidget::toggleViewAction() const
266+
{
267+
return d->ToggleViewAction;
268+
}
269+
270+
271+
//============================================================================
272+
void CDockWidget::toggleView(bool Open)
273+
{
274+
if ((d->DockArea != nullptr) == Open)
275+
{
276+
return;
277+
}
278+
279+
if (!Open && d->DockArea)
280+
{
281+
hideDockWidget(true);
282+
}
283+
else if (Open && !d->DockArea)
284+
{
285+
d->showDockWidget();
286+
}
287+
}
288+
289+
290+
//============================================================================
291+
void CDockWidget::setDockArea(CDockAreaWidget* DockArea)
292+
{
293+
d->DockArea = DockArea;
294+
d->ToggleViewAction->setChecked(DockArea != nullptr);
295+
}
296+
297+
298+
299+
//============================================================================
300+
void CDockWidget::hideDockWidget(bool RemoveFromDockArea)
301+
{
302+
d->capturedState();
303+
if (d->DockArea && RemoveFromDockArea)
304+
{
305+
d->DockArea->removeDockWidget(this);
306+
}
307+
this->setParent(d->DockManager);
308+
this->setDockArea(nullptr);
309+
// Remove title from dock area widget to prevent its deletion if dock
310+
// area is deleted
311+
d->TitleWidget->setParent(this);
312+
}
313+
160314
} // namespace ads
161315

162316
//---------------------------------------------------------------------------

0 commit comments

Comments
 (0)