Skip to content

Commit 239bd47

Browse files
author
Uwe Kindler
committed
Added signals for dock area added and removed
1 parent 97571e4 commit 239bd47

File tree

5 files changed

+108
-61
lines changed

5 files changed

+108
-61
lines changed

src/DockContainerWidget.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,6 @@ struct DockContainerWidgetPrivate
8181
*/
8282
DockContainerWidgetPrivate(CDockContainerWidget* _public);
8383

84-
/**
85-
* Create a new dock area widget and adds it to the list of doc areas
86-
*/
87-
CDockAreaWidget* newDockArea()
88-
{
89-
auto DockAreaWidget = new CDockAreaWidget(DockManager, _this);
90-
DockAreas.append(DockAreaWidget);
91-
return DockAreaWidget;
92-
}
93-
9484
/**
9585
* Adds dock widget to container and returns the dock area that contains
9686
* the inserted dock widget
@@ -289,6 +279,8 @@ void DockContainerWidgetPrivate::addDockAreasToList(const QList<CDockAreaWidget*
289279
{
290280
DockAreas.last()->updateDockArea();
291281
}
282+
283+
emit _this->dockAreasAdded();
292284
}
293285

294286

@@ -348,6 +340,7 @@ void DockContainerWidgetPrivate::addDockArea(CDockAreaWidget* NewDockArea, DockW
348340

349341
DockAreas.append(NewDockArea);
350342
NewDockArea->updateDockArea();
343+
emit _this->dockAreasAdded();
351344
}
352345

353346

@@ -392,6 +385,7 @@ CDockAreaWidget* DockContainerWidgetPrivate::dockWidgetIntoDockArea(DockWidgetAr
392385
}
393386

394387
DockAreas.append(NewDockArea);
388+
emit _this->dockAreasAdded();
395389
return NewDockArea;
396390
}
397391

@@ -521,6 +515,7 @@ void CDockContainerWidget::removeDockArea(CDockAreaWidget* area)
521515
d->Layout->replaceWidget(Splitter, widget);
522516
}
523517
delete Splitter;
518+
emit dockAreasRemoved();
524519
}
525520

526521

src/DockContainerWidget.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,19 @@ class CDockContainerWidget : public QFrame
126126
* This function returns true, if this container is in a floating widget
127127
*/
128128
bool isFloating() const;
129+
130+
signals:
131+
/**
132+
* This signal is emitted if one or multiple dock areas has been added to
133+
* the internal list of dock areas.
134+
* If multiple dock areas are inserted, this signal is emitted only once
135+
*/
136+
void dockAreasAdded();
137+
138+
/**
139+
* This signal is emitted if one or multiple dock areas has been removed
140+
*/
141+
void dockAreasRemoved();
129142
}; // class DockContainerWidget
130143
} // namespace ads
131144
//-----------------------------------------------------------------------------

src/DockWidget.cpp

Lines changed: 50 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <QSplitter>
3636
#include <QStack>
3737
#include <QTextStream>
38+
#include <QPointer>
3839

3940
#include <iostream>
4041

@@ -61,7 +62,12 @@ struct DockWidgetPrivate
6162
CDockManager* DockManager = nullptr;
6263
CDockAreaWidget* DockArea = nullptr;
6364
QAction* ToggleViewAction;
64-
QString CapturedState;
65+
struct CapturedState
66+
{
67+
QString DockTreePosition;
68+
QRect GlobalGeometry;
69+
QPointer<CDockContainerWidget> DockContainer;
70+
} CapturedState;
6571

6672
/**
6773
* Private data constructor
@@ -91,67 +97,60 @@ DockWidgetPrivate::DockWidgetPrivate(CDockWidget* _public) :
9197
//============================================================================
9298
void DockWidgetPrivate::capturedState()
9399
{
94-
QString CapturedState;
95-
QTextStream stream(&CapturedState);
96-
stream << (_this->isFloating() ? "F " : "D ");
97-
if (_this->isFloating())
100+
QString DockTreePosition;
101+
QTextStream stream(&DockTreePosition);
102+
103+
QPoint GlobalTopLeft = _this->mapToGlobal(_this->geometry().topLeft());
104+
QRect Rect(GlobalTopLeft, _this->geometry().size());
105+
CapturedState.GlobalGeometry = Rect;
106+
CapturedState.DockContainer = _this->dockContainer();
107+
108+
QWidget* Widget = DockArea;
109+
QSplitter* splitter = internal::findParent<QSplitter*>(Widget);
110+
QStack<QString> SplitterData;
111+
while (splitter)
98112
{
99-
CFloatingDockContainer* FloatingWidget = internal::findParent<CFloatingDockContainer*>(_this);
100-
QRect Rect = FloatingWidget->geometry();
101-
stream << Rect.left() << " " << Rect.top() << " " << Rect.width()
102-
<< " " << Rect.height();
113+
SplitterData.push(QString("%1%2")
114+
.arg((splitter->orientation() == Qt::Horizontal) ? "H" : "V")
115+
.arg(splitter->indexOf(Widget)));
116+
Widget = splitter;
117+
splitter = internal::findParent<QSplitter*>(Widget);
103118
}
104-
else
119+
120+
QString Separator;
121+
while (!SplitterData.isEmpty())
105122
{
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-
}
123+
stream << Separator << SplitterData.pop();
124+
Separator = " ";
124125
}
125-
this->CapturedState = CapturedState;
126-
std::cout << "SerializedPosition: " << CapturedState.toStdString() << std::endl;
126+
this->CapturedState.DockTreePosition = DockTreePosition;
127+
std::cout << "SerializedPosition: " << DockTreePosition.toStdString() << std::endl;
127128
}
128129

129130

130131
//============================================================================
131132
void DockWidgetPrivate::showDockWidget()
132133
{
133-
QTextStream stream(&CapturedState);
134-
QString DockedState;
135-
stream >> DockedState;
136-
if (DockedState == "F")
134+
if (!CapturedState.DockContainer)
137135
{
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-
}
136+
auto FloatingWidget = new CFloatingDockContainer(_this);
137+
FloatingWidget->setGeometry(CapturedState.GlobalGeometry);
138+
FloatingWidget->show();
139+
return;
140+
}
141+
142+
CDockContainerWidget* DockContainer = CapturedState.DockContainer.data();
143+
QStringList DockTree = this->CapturedState.DockTreePosition.split(' ');
144+
QSplitter* splitter = DockContainer->findChild<QSplitter*>(QString(), Qt::FindDirectChildrenOnly);
145+
146+
while (splitter)
147+
{
148+
149+
}
150+
151+
for (const auto& TreeItem : DockTree)
152+
{
153+
155154
}
156155
}
157156

src/FloatingDockContainer.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ struct FloatingDockContainerPrivate
6060
bool DraggingActive = false;
6161
QPoint DragStartMousePosition;
6262
CDockContainerWidget* DropContainer = nullptr;
63+
CDockAreaWidget* SingleDockArea = nullptr;
6364

6465
/**
6566
* Private data constructor
@@ -179,6 +180,8 @@ CFloatingDockContainer::CFloatingDockContainer(CDockManager* DockManager) :
179180
setLayout(l);
180181

181182
d->DockContainer = new CDockContainerWidget(DockManager, this);
183+
connect(d->DockContainer, SIGNAL(dockAreasAdded()), this, SLOT(onDockAreasAddedOrRemoved()));
184+
connect(d->DockContainer, SIGNAL(dockAreasRemoved()), this, SLOT(onDockAreasAddedOrRemoved()));
182185
l->addWidget(d->DockContainer);
183186
DockManager->registerFloatingWidget(this);
184187

@@ -339,6 +342,38 @@ void CFloatingDockContainer::moveFloating()
339342
const QPoint moveToPos = QCursor::pos() - d->DragStartMousePosition - QPoint(BorderSize, 0);
340343
move(moveToPos);
341344
}
345+
346+
347+
//============================================================================
348+
void CFloatingDockContainer::onDockAreasAddedOrRemoved()
349+
{
350+
if (d->DockContainer->dockAreaCount() == 1)
351+
{
352+
d->SingleDockArea = d->DockContainer->dockArea(0);
353+
this->setWindowTitle(d->SingleDockArea->currentDockWidget()->windowTitle());
354+
connect(d->SingleDockArea, SIGNAL(currentChanged(int)), this,
355+
SLOT(onDockAreaCurrentChanged(int)));
356+
}
357+
else
358+
{
359+
if (d->SingleDockArea)
360+
{
361+
disconnect(d->SingleDockArea, SIGNAL(currentChanged(int)), this,
362+
SLOT(onDockAreaCurrentChanged(int)));
363+
d->SingleDockArea = nullptr;
364+
}
365+
this->setWindowTitle(qApp->applicationDisplayName());
366+
}
367+
}
368+
369+
370+
//============================================================================
371+
void CFloatingDockContainer::onDockAreaCurrentChanged(int Index)
372+
{
373+
this->setWindowTitle(d->SingleDockArea->currentDockWidget()->windowTitle());
374+
}
375+
376+
342377
} // namespace ads
343378

344379
//---------------------------------------------------------------------------

src/FloatingDockContainer.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ class CFloatingDockContainer : public QWidget
5050
private:
5151
FloatingDockContainerPrivate* d; ///< private data (pimpl)
5252
friend class FloatingDockContainerPrivate;
53+
54+
private slots:
55+
void onDockAreasAddedOrRemoved();
56+
void onDockAreaCurrentChanged(int Index);
57+
5358
protected:
5459
/**
5560
* Private constructor that is called from public constructors

0 commit comments

Comments
 (0)