Added signals for dock area added and removed

This commit is contained in:
Uwe Kindler 2017-03-13 15:34:40 +01:00
parent 97571e4be8
commit 239bd4781b
5 changed files with 109 additions and 62 deletions

View File

@ -81,16 +81,6 @@ struct DockContainerWidgetPrivate
*/ */
DockContainerWidgetPrivate(CDockContainerWidget* _public); DockContainerWidgetPrivate(CDockContainerWidget* _public);
/**
* Create a new dock area widget and adds it to the list of doc areas
*/
CDockAreaWidget* newDockArea()
{
auto DockAreaWidget = new CDockAreaWidget(DockManager, _this);
DockAreas.append(DockAreaWidget);
return DockAreaWidget;
}
/** /**
* Adds dock widget to container and returns the dock area that contains * Adds dock widget to container and returns the dock area that contains
* the inserted dock widget * the inserted dock widget
@ -289,6 +279,8 @@ void DockContainerWidgetPrivate::addDockAreasToList(const QList<CDockAreaWidget*
{ {
DockAreas.last()->updateDockArea(); DockAreas.last()->updateDockArea();
} }
emit _this->dockAreasAdded();
} }
@ -348,6 +340,7 @@ void DockContainerWidgetPrivate::addDockArea(CDockAreaWidget* NewDockArea, DockW
DockAreas.append(NewDockArea); DockAreas.append(NewDockArea);
NewDockArea->updateDockArea(); NewDockArea->updateDockArea();
emit _this->dockAreasAdded();
} }
@ -392,6 +385,7 @@ CDockAreaWidget* DockContainerWidgetPrivate::dockWidgetIntoDockArea(DockWidgetAr
} }
DockAreas.append(NewDockArea); DockAreas.append(NewDockArea);
emit _this->dockAreasAdded();
return NewDockArea; return NewDockArea;
} }
@ -521,6 +515,7 @@ void CDockContainerWidget::removeDockArea(CDockAreaWidget* area)
d->Layout->replaceWidget(Splitter, widget); d->Layout->replaceWidget(Splitter, widget);
} }
delete Splitter; delete Splitter;
emit dockAreasRemoved();
} }

View File

@ -126,6 +126,19 @@ public:
* This function returns true, if this container is in a floating widget * This function returns true, if this container is in a floating widget
*/ */
bool isFloating() const; bool isFloating() const;
signals:
/**
* This signal is emitted if one or multiple dock areas has been added to
* the internal list of dock areas.
* If multiple dock areas are inserted, this signal is emitted only once
*/
void dockAreasAdded();
/**
* This signal is emitted if one or multiple dock areas has been removed
*/
void dockAreasRemoved();
}; // class DockContainerWidget }; // class DockContainerWidget
} // namespace ads } // namespace ads
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View File

@ -35,6 +35,7 @@
#include <QSplitter> #include <QSplitter>
#include <QStack> #include <QStack>
#include <QTextStream> #include <QTextStream>
#include <QPointer>
#include <iostream> #include <iostream>
@ -61,7 +62,12 @@ struct DockWidgetPrivate
CDockManager* DockManager = nullptr; CDockManager* DockManager = nullptr;
CDockAreaWidget* DockArea = nullptr; CDockAreaWidget* DockArea = nullptr;
QAction* ToggleViewAction; QAction* ToggleViewAction;
QString CapturedState; struct CapturedState
{
QString DockTreePosition;
QRect GlobalGeometry;
QPointer<CDockContainerWidget> DockContainer;
} CapturedState;
/** /**
* Private data constructor * Private data constructor
@ -91,67 +97,60 @@ DockWidgetPrivate::DockWidgetPrivate(CDockWidget* _public) :
//============================================================================ //============================================================================
void DockWidgetPrivate::capturedState() void DockWidgetPrivate::capturedState()
{ {
QString CapturedState; QString DockTreePosition;
QTextStream stream(&CapturedState); QTextStream stream(&DockTreePosition);
stream << (_this->isFloating() ? "F " : "D ");
if (_this->isFloating())
{
CFloatingDockContainer* FloatingWidget = internal::findParent<CFloatingDockContainer*>(_this);
QRect Rect = FloatingWidget->geometry();
stream << Rect.left() << " " << Rect.top() << " " << Rect.width()
<< " " << Rect.height();
}
else
{
QWidget* Widget = DockArea;
QSplitter* splitter = internal::findParent<QSplitter*>(Widget);
QStack<QString> SplitterData;
while (splitter)
{
SplitterData.push(QString("%1%2")
.arg((splitter->orientation() == Qt::Horizontal) ? "H" : "V")
.arg(splitter->indexOf(Widget)));
Widget = splitter;
splitter = internal::findParent<QSplitter*>(Widget);
}
QString Separator; QPoint GlobalTopLeft = _this->mapToGlobal(_this->geometry().topLeft());
while (!SplitterData.isEmpty()) QRect Rect(GlobalTopLeft, _this->geometry().size());
{ CapturedState.GlobalGeometry = Rect;
stream << Separator << SplitterData.pop(); CapturedState.DockContainer = _this->dockContainer();
Separator = " ";
} QWidget* Widget = DockArea;
QSplitter* splitter = internal::findParent<QSplitter*>(Widget);
QStack<QString> SplitterData;
while (splitter)
{
SplitterData.push(QString("%1%2")
.arg((splitter->orientation() == Qt::Horizontal) ? "H" : "V")
.arg(splitter->indexOf(Widget)));
Widget = splitter;
splitter = internal::findParent<QSplitter*>(Widget);
} }
this->CapturedState = CapturedState;
std::cout << "SerializedPosition: " << CapturedState.toStdString() << std::endl; QString Separator;
while (!SplitterData.isEmpty())
{
stream << Separator << SplitterData.pop();
Separator = " ";
}
this->CapturedState.DockTreePosition = DockTreePosition;
std::cout << "SerializedPosition: " << DockTreePosition.toStdString() << std::endl;
} }
//============================================================================ //============================================================================
void DockWidgetPrivate::showDockWidget() void DockWidgetPrivate::showDockWidget()
{ {
QTextStream stream(&CapturedState); if (!CapturedState.DockContainer)
QString DockedState; {
stream >> DockedState; auto FloatingWidget = new CFloatingDockContainer(_this);
if (DockedState == "F") FloatingWidget->setGeometry(CapturedState.GlobalGeometry);
FloatingWidget->show();
return;
}
CDockContainerWidget* DockContainer = CapturedState.DockContainer.data();
QStringList DockTree = this->CapturedState.DockTreePosition.split(' ');
QSplitter* splitter = DockContainer->findChild<QSplitter*>(QString(), Qt::FindDirectChildrenOnly);
while (splitter)
{
}
for (const auto& TreeItem : DockTree)
{ {
std::cout << "Restoring Floating Dock Widget" << std::endl;
QVector<int> v;
while (!stream.atEnd())
{
int Value;
stream >> Value;
v.append(Value);
}
if (v.count() == 4)
{
std::cout << "Rectangle Loaded" << std::endl;
QRect Rect(v[0], v[1], v[2], v[3]);
auto FloatingWidget = new CFloatingDockContainer(_this);
FloatingWidget->setGeometry(Rect);
FloatingWidget->show();
}
} }
} }

View File

@ -60,6 +60,7 @@ struct FloatingDockContainerPrivate
bool DraggingActive = false; bool DraggingActive = false;
QPoint DragStartMousePosition; QPoint DragStartMousePosition;
CDockContainerWidget* DropContainer = nullptr; CDockContainerWidget* DropContainer = nullptr;
CDockAreaWidget* SingleDockArea = nullptr;
/** /**
* Private data constructor * Private data constructor
@ -179,6 +180,8 @@ CFloatingDockContainer::CFloatingDockContainer(CDockManager* DockManager) :
setLayout(l); setLayout(l);
d->DockContainer = new CDockContainerWidget(DockManager, this); d->DockContainer = new CDockContainerWidget(DockManager, this);
connect(d->DockContainer, SIGNAL(dockAreasAdded()), this, SLOT(onDockAreasAddedOrRemoved()));
connect(d->DockContainer, SIGNAL(dockAreasRemoved()), this, SLOT(onDockAreasAddedOrRemoved()));
l->addWidget(d->DockContainer); l->addWidget(d->DockContainer);
DockManager->registerFloatingWidget(this); DockManager->registerFloatingWidget(this);
@ -339,6 +342,38 @@ void CFloatingDockContainer::moveFloating()
const QPoint moveToPos = QCursor::pos() - d->DragStartMousePosition - QPoint(BorderSize, 0); const QPoint moveToPos = QCursor::pos() - d->DragStartMousePosition - QPoint(BorderSize, 0);
move(moveToPos); move(moveToPos);
} }
//============================================================================
void CFloatingDockContainer::onDockAreasAddedOrRemoved()
{
if (d->DockContainer->dockAreaCount() == 1)
{
d->SingleDockArea = d->DockContainer->dockArea(0);
this->setWindowTitle(d->SingleDockArea->currentDockWidget()->windowTitle());
connect(d->SingleDockArea, SIGNAL(currentChanged(int)), this,
SLOT(onDockAreaCurrentChanged(int)));
}
else
{
if (d->SingleDockArea)
{
disconnect(d->SingleDockArea, SIGNAL(currentChanged(int)), this,
SLOT(onDockAreaCurrentChanged(int)));
d->SingleDockArea = nullptr;
}
this->setWindowTitle(qApp->applicationDisplayName());
}
}
//============================================================================
void CFloatingDockContainer::onDockAreaCurrentChanged(int Index)
{
this->setWindowTitle(d->SingleDockArea->currentDockWidget()->windowTitle());
}
} // namespace ads } // namespace ads
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View File

@ -50,6 +50,11 @@ class CFloatingDockContainer : public QWidget
private: private:
FloatingDockContainerPrivate* d; ///< private data (pimpl) FloatingDockContainerPrivate* d; ///< private data (pimpl)
friend class FloatingDockContainerPrivate; friend class FloatingDockContainerPrivate;
private slots:
void onDockAreasAddedOrRemoved();
void onDockAreaCurrentChanged(int Index);
protected: protected:
/** /**
* Private constructor that is called from public constructors * Private constructor that is called from public constructors