Qt-Advanced-Docking-System/src/DockContainerWidget.cpp

923 lines
25 KiB
C++
Raw Normal View History

/*******************************************************************************
2017-06-10 04:04:02 +08:00
** Qt Advanced Docking System
** Copyright (C) 2017 Uwe Kindler
2017-06-10 04:04:02 +08:00
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License as published by the Free Software Foundation; either
** version 2.1 of the License, or (at your option) any later version.
**
** This library is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
2017-06-10 04:04:02 +08:00
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public
** License along with this library; If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
//============================================================================
/// \file DockContainerWidget.cpp
/// \author Uwe Kindler
/// \date 24.02.2017
/// \brief Implementation of CDockContainerWidget class
//============================================================================
//============================================================================
// INCLUDES
//============================================================================
#include "DockContainerWidget.h"
#include <QEvent>
#include <QList>
#include <QGridLayout>
#include <QPointer>
#include <QVariant>
#include <QDebug>
#include "DockManager.h"
#include "DockAreaWidget.h"
#include "DockWidget.h"
#include "FloatingDockContainer.h"
#include "DockOverlay.h"
#include "DockStateSerialization.h"
#include "ads_globals.h"
2017-03-24 17:18:25 +08:00
#include "DockSplitter.h"
namespace ads
{
static unsigned int zOrderCounter = 0;
/**
* Helper function to ease insertion of dock area into splitter
*/
static void insertWidgetIntoSplitter(QSplitter* Splitter, QWidget* widget, bool Append)
{
if (Append)
{
Splitter->addWidget(widget);
}
else
{
Splitter->insertWidget(0, widget);
}
}
/**
* Private data class of CDockContainerWidget class (pimpl)
*/
struct DockContainerWidgetPrivate
{
CDockContainerWidget* _this;
QPointer<CDockManager> DockManager;
unsigned int zOrderIndex = 0;
QList<CDockAreaWidget*> DockAreas;
QGridLayout* Layout = nullptr;
2017-03-24 19:54:43 +08:00
QSplitter* RootSplitter;
bool isFloating = false;
/**
* Private data constructor
*/
DockContainerWidgetPrivate(CDockContainerWidget* _public);
/**
* Adds dock widget to container and returns the dock area that contains
* the inserted dock widget
*/
CDockAreaWidget* dockWidgetIntoContainer(DockWidgetArea area, CDockWidget* Dockwidget);
/**
* Adds dock widget to a existing DockWidgetArea
*/
CDockAreaWidget* dockWidgetIntoDockArea(DockWidgetArea area, CDockWidget* Dockwidget,
CDockAreaWidget* TargetDockArea);
/**
* Add dock area to this container
*/
void addDockArea(CDockAreaWidget* NewDockWidget, DockWidgetArea area = CenterDockWidgetArea);
/**
* Drop floating widget into container
*/
void dropIntoContainer(CFloatingDockContainer* FloatingWidget, DockWidgetArea area);
/**
* Drop floating widget into dock area
*/
void dropIntoSection(CFloatingDockContainer* FloatingWidget,
CDockAreaWidget* TargetArea, DockWidgetArea area);
/**
* Adds new dock areas to the internal dock area list
*/
void addDockAreasToList(const QList<CDockAreaWidget*> NewDockAreas);
/**
* Save state of child nodes
*/
void saveChildNodesState(QDataStream& Stream, QWidget* Widget);
/**
2017-03-27 16:41:27 +08:00
* Restore state of child nodes.
* \param[in] Stream The data stream that contains the serialized state
2017-03-27 19:18:16 +08:00
* \param[out] CreatedWidget The widget created from parsed data or 0 if
* the parsed widget was an empty splitter
2017-03-27 16:41:27 +08:00
* \param[in] Testing If Testing is true, only the stream data is
* parsed without modifiying anything.
*/
2017-03-27 16:41:27 +08:00
bool restoreChildNodes(QDataStream& Stream, QWidget*& CreatedWidget,
bool Testing);
/**
* Restores a splitter.
* \see restoreChildNodes() for details
*/
bool restoreSplitter(QDataStream& Stream, QWidget*& CreatedWidget,
bool Testing);
/**
* Restores a dock area.
* \see restoreChildNodes() for details
*/
bool restoreDockArea(QDataStream& Stream, QWidget*& CreatedWidget,
bool Testing);
/**
* Helper function for recursive dumping of layout
*/
void dumpRecursive(int level, QWidget* widget);
}; // struct DockContainerWidgetPrivate
//============================================================================
DockContainerWidgetPrivate::DockContainerWidgetPrivate(CDockContainerWidget* _public) :
_this(_public)
{
}
//============================================================================
void DockContainerWidgetPrivate::dropIntoContainer(CFloatingDockContainer* FloatingWidget,
DockWidgetArea area)
{
auto InsertParam = internal::dockAreaInsertParameters(area);
auto NewDockAreas = FloatingWidget->dockContainer()->findChildren<CDockAreaWidget*>(
QString(), Qt::FindChildrenRecursively);
2017-03-24 19:54:43 +08:00
QSplitter* Splitter = RootSplitter;
2017-03-24 19:54:43 +08:00
if (DockAreas.count() <= 1)
{
2017-03-24 19:54:43 +08:00
Splitter->setOrientation(InsertParam.orientation());
}
else if (Splitter->orientation() != InsertParam.orientation())
2017-03-24 19:54:43 +08:00
{
QSplitter* NewSplitter = internal::newSplitter(InsertParam.orientation());
QLayoutItem* li = Layout->replaceWidget(Splitter, NewSplitter);
NewSplitter->addWidget(Splitter);
Splitter = NewSplitter;
delete li;
}
// Now we can insert the floating widget content into this container
auto FloatingSplitter = FloatingWidget->dockContainer()->rootSplitter();
if (FloatingSplitter->count() == 1)
{
2017-03-24 19:54:43 +08:00
insertWidgetIntoSplitter(Splitter, FloatingSplitter->widget(0), InsertParam.append());
}
else if (FloatingSplitter->orientation() == InsertParam.orientation())
{
while (FloatingSplitter->count())
{
2017-03-24 19:54:43 +08:00
insertWidgetIntoSplitter(Splitter, FloatingSplitter->widget(0), InsertParam.append());
}
}
else
{
2017-03-24 19:54:43 +08:00
insertWidgetIntoSplitter(Splitter, FloatingSplitter, InsertParam.append());
}
2017-03-24 19:54:43 +08:00
RootSplitter = Splitter;
addDockAreasToList(NewDockAreas);
FloatingWidget->deleteLater();
_this->dumpLayout();
}
//============================================================================
void DockContainerWidgetPrivate::dropIntoSection(CFloatingDockContainer* FloatingWidget,
CDockAreaWidget* TargetArea, DockWidgetArea area)
{
CDockContainerWidget* FloatingContainer = FloatingWidget->dockContainer();
if (area == CenterDockWidgetArea)
{
auto NewDockWidgets = FloatingContainer->findChildren<CDockWidget*>(
QString(), Qt::FindChildrenRecursively);
for (auto DockWidget : NewDockWidgets)
{
TargetArea->insertDockWidget(0, DockWidget, false);
}
TargetArea->setCurrentIndex(0); // make the topmost widget active
FloatingWidget->deleteLater();
TargetArea->updateDockArea();
return;
}
auto InsertParam = internal::dockAreaInsertParameters(area);
auto NewDockAreas = FloatingWidget->dockContainer()->findChildren<CDockAreaWidget*>(
QString(), Qt::FindChildrenRecursively);
QSplitter* TargetAreaSplitter = internal::findParent<QSplitter*>(TargetArea);
if (!TargetAreaSplitter)
{
QSplitter* Splitter = internal::newSplitter(InsertParam.orientation());
Layout->replaceWidget(TargetArea, Splitter);
Splitter->addWidget(TargetArea);
TargetAreaSplitter = Splitter;
}
int AreaIndex = TargetAreaSplitter->indexOf(TargetArea);
auto Widget = FloatingWidget->dockContainer()->findChild<QWidget*>(QString(), Qt::FindDirectChildrenOnly);
auto FloatingSplitter = dynamic_cast<QSplitter*>(Widget);
if (TargetAreaSplitter->orientation() == InsertParam.orientation())
{
2017-03-24 19:54:43 +08:00
if ((FloatingSplitter->orientation() != InsertParam.orientation()) && FloatingSplitter->count() > 1)
{
TargetAreaSplitter->insertWidget(AreaIndex + InsertParam.insertOffset(), Widget);
}
else
{
int InsertIndex = AreaIndex + InsertParam.insertOffset();
while (FloatingSplitter->count())
{
TargetAreaSplitter->insertWidget(InsertIndex++, FloatingSplitter->widget(0));
}
}
}
else
{
QSplitter* NewSplitter = internal::newSplitter(InsertParam.orientation());
2017-03-24 19:54:43 +08:00
if ((FloatingSplitter->orientation() != InsertParam.orientation()) && FloatingSplitter->count() > 1)
{
NewSplitter->addWidget(Widget);
}
else
{
while (FloatingSplitter->count())
{
NewSplitter->addWidget(FloatingSplitter->widget(0));
}
}
insertWidgetIntoSplitter(NewSplitter, TargetArea, !InsertParam.append());
TargetAreaSplitter->insertWidget(AreaIndex, NewSplitter);
}
FloatingWidget->deleteLater();
addDockAreasToList(NewDockAreas);
_this->dumpLayout();
}
//============================================================================
void DockContainerWidgetPrivate::addDockAreasToList(const QList<CDockAreaWidget*> NewDockAreas)
{
int CountBefore = DockAreas.count();
int NewAreaCount = NewDockAreas.count();
DockAreas.append(NewDockAreas);
// We need to ensure, that the dock area title bar is visible. The title bar
// is invisible, if the dock are is a single dock area in a floating widget.
if (1 == CountBefore)
{
DockAreas.at(0)->updateDockArea();
}
if (1 == NewAreaCount)
{
DockAreas.last()->updateDockArea();
}
emit _this->dockAreasAdded();
}
//============================================================================
void DockContainerWidgetPrivate::saveChildNodesState(QDataStream& stream, QWidget* Widget)
{
QSplitter* Splitter = dynamic_cast<QSplitter*>(Widget);
if (Splitter)
{
2017-03-27 16:41:27 +08:00
stream << internal::SplitterMarker << Splitter->orientation() << Splitter->count();
qDebug() << "NodeSplitter orient: " << Splitter->orientation()
<< " WidgetCont: " << Splitter->count();
for (int i = 0; i < Splitter->count(); ++i)
{
saveChildNodesState(stream, Splitter->widget(i));
}
stream << Splitter->sizes();
}
else
{
2017-03-27 16:41:27 +08:00
stream << internal::DockAreaMarker;
CDockAreaWidget* DockArea = dynamic_cast<CDockAreaWidget*>(Widget);
if (DockArea)
{
DockArea->saveState(stream);
}
}
}
//============================================================================
2017-03-27 16:41:27 +08:00
bool DockContainerWidgetPrivate::restoreSplitter(QDataStream& stream,
QWidget*& CreatedWidget, bool Testing)
{
2017-03-27 16:41:27 +08:00
int Orientation;
int WidgetCount;
stream >> Orientation >> WidgetCount;
qDebug() << "Restore NodeSplitter Orientation: " << Orientation <<
" WidgetCount: " << WidgetCount;
2017-03-27 16:41:27 +08:00
QSplitter* Splitter = nullptr;
if (!Testing)
{
Splitter = internal::newSplitter((Qt::Orientation)Orientation);
}
bool Visible = false;
for (int i = 0; i < WidgetCount; ++i)
{
QWidget* ChildNode;
if (!restoreChildNodes(stream, ChildNode, Testing))
2017-03-24 17:18:25 +08:00
{
2017-03-27 16:41:27 +08:00
return false;
}
if (Testing)
{
continue;
2017-03-24 17:18:25 +08:00
}
qDebug() << "ChildNode isVisible " << ChildNode->isVisible()
<< " isVisibleTo " << ChildNode->isVisibleTo(Splitter);
2017-03-27 16:41:27 +08:00
Splitter->addWidget(ChildNode);
Visible |= ChildNode->isVisibleTo(Splitter);
}
QList<int> Sizes;
stream >> Sizes;
if (!Testing)
{
if (!Splitter->count())
{
delete Splitter;
Splitter = nullptr;
}
else
{
Splitter->setSizes(Sizes);
Splitter->setVisible(Visible);
}
CreatedWidget = Splitter;
}
else
{
2017-03-27 16:41:27 +08:00
CreatedWidget = nullptr;
}
return true;
}
2017-03-27 16:41:27 +08:00
//============================================================================
bool DockContainerWidgetPrivate::restoreDockArea(QDataStream& stream,
QWidget*& CreatedWidget, bool Testing)
{
int Tabs;
int CurrentIndex;
stream >> Tabs >> CurrentIndex;
qDebug() << "Restore NodeDockArea Tabs: " << Tabs << " CurrentIndex: "
<< CurrentIndex;
2017-03-27 16:41:27 +08:00
CDockAreaWidget* DockArea = nullptr;
if (!Testing)
{
DockArea = new CDockAreaWidget(DockManager, _this);
}
for (int i = 0; i < Tabs; ++i)
{
int Marker;
stream >> Marker;
if (Marker != internal::DockWidgetMarker)
{
2017-03-27 16:41:27 +08:00
return false;
}
2017-03-24 17:18:25 +08:00
2017-03-27 16:41:27 +08:00
QString ObjectName;
bool Closed;
stream >> ObjectName >> Closed;
qDebug() << "Restore DockWidget " << ObjectName << " Closed: " << Closed;
2017-03-27 16:41:27 +08:00
CDockWidget* DockWidget = DockManager->findDockWidget(ObjectName);
if (!DockWidget || Testing)
{
2017-03-27 16:41:27 +08:00
continue;
}
2017-03-27 16:41:27 +08:00
qDebug() << "Dock Widget found - parent " << DockWidget->parent();
2017-03-27 16:41:27 +08:00
DockArea->addDockWidget(DockWidget);
DockArea->hide();
DockWidget->setToggleViewActionChecked(!Closed);
DockWidget->setProperty("closed", Closed);
DockWidget->setProperty("dirty", false);
2017-03-27 16:41:27 +08:00
}
if (Testing)
{
return true;
}
if (!DockArea->count())
{
delete DockArea;
DockArea = nullptr;
}
else
{
DockArea->setProperty("currentIndex", CurrentIndex);
}
2017-03-27 16:41:27 +08:00
CreatedWidget = DockArea;
DockAreas.append(DockArea);
return true;
}
//============================================================================
bool DockContainerWidgetPrivate::restoreChildNodes(QDataStream& stream,
QWidget*& CreatedWidget, bool Testing)
{
int Marker;
stream >> Marker;
if (internal::SplitterMarker == Marker)
{
return restoreSplitter(stream, CreatedWidget, Testing);
}
else if (internal::DockAreaMarker == Marker)
{
return restoreDockArea(stream, CreatedWidget, Testing);
}
else
{
return false;
}
}
//============================================================================
CDockAreaWidget* DockContainerWidgetPrivate::dockWidgetIntoContainer(DockWidgetArea area,
CDockWidget* Dockwidget)
{
CDockAreaWidget* NewDockArea = new CDockAreaWidget(DockManager, _this);
NewDockArea->addDockWidget(Dockwidget);
addDockArea(NewDockArea, area);
return NewDockArea;
}
//============================================================================
void DockContainerWidgetPrivate::addDockArea(CDockAreaWidget* NewDockArea, DockWidgetArea area)
{
auto InsertParam = internal::dockAreaInsertParameters(area);
2017-03-24 19:54:43 +08:00
// As long as we have only one dock area in the splitter we can adjust
// its orientation
if (DockAreas.count() <= 1)
{
2017-03-24 19:54:43 +08:00
RootSplitter->setOrientation(InsertParam.orientation());
}
2017-03-24 19:54:43 +08:00
QSplitter* Splitter = RootSplitter;
if (Splitter->orientation() == InsertParam.orientation())
{
insertWidgetIntoSplitter(Splitter, NewDockArea, InsertParam.append());
}
else
{
2017-03-24 19:54:43 +08:00
QSplitter* NewSplitter = internal::newSplitter(InsertParam.orientation());
if (InsertParam.append())
{
2017-03-24 19:54:43 +08:00
QLayoutItem* li = Layout->replaceWidget(Splitter, NewSplitter);
NewSplitter->addWidget(Splitter);
NewSplitter->addWidget(NewDockArea);
delete li;
}
else
{
2017-03-24 19:54:43 +08:00
NewSplitter->addWidget(NewDockArea);
QLayoutItem* li = Layout->replaceWidget(Splitter, NewSplitter);
NewSplitter->addWidget(Splitter);
delete li;
}
2017-03-24 19:54:43 +08:00
RootSplitter = NewSplitter;
}
DockAreas.append(NewDockArea);
NewDockArea->updateDockArea();
emit _this->dockAreasAdded();
}
//============================================================================
void DockContainerWidgetPrivate::dumpRecursive(int level, QWidget* widget)
{
#if defined(QT_DEBUG)
QSplitter* Splitter = dynamic_cast<QSplitter*>(widget);
QByteArray buf;
buf.fill(' ', level * 4);
if (Splitter)
{
qDebug("%sSplitter %s", (const char*)buf, (Splitter->orientation() == Qt::Vertical)
? "-" : "|");
for (int i = 0; i < Splitter->count(); ++i)
{
dumpRecursive(level + 1, Splitter->widget(i));
}
}
else
{
CDockAreaWidget* DockArea = dynamic_cast<CDockAreaWidget*>(widget);
if (!DockArea)
{
return;
}
qDebug("%sDockArea", (const char*)buf);
}
#else
Q_UNUSED(level);
Q_UNUSED(widget);
#endif
}
//============================================================================
CDockAreaWidget* DockContainerWidgetPrivate::dockWidgetIntoDockArea(DockWidgetArea area,
CDockWidget* Dockwidget, CDockAreaWidget* TargetDockArea)
{
if (CenterDockWidgetArea == area)
{
TargetDockArea->addDockWidget(Dockwidget);
return TargetDockArea;
}
CDockAreaWidget* NewDockArea = new CDockAreaWidget(DockManager, _this);
NewDockArea->addDockWidget(Dockwidget);
auto InsertParam = internal::dockAreaInsertParameters(area);
2017-03-24 19:54:43 +08:00
QSplitter* TargetAreaSplitter = internal::findParent<QSplitter*>(TargetDockArea);
int index = TargetAreaSplitter ->indexOf(TargetDockArea);
if (TargetAreaSplitter->orientation() == InsertParam.orientation())
{
qDebug() << "TargetAreaSplitter->orientation() == InsertParam.orientation()";
2017-03-24 19:54:43 +08:00
TargetAreaSplitter->insertWidget(index + InsertParam.insertOffset(), NewDockArea);
}
else
{
qDebug() << "TargetAreaSplitter->orientation() != InsertParam.orientation()";
2017-03-24 19:54:43 +08:00
QSplitter* NewSplitter = internal::newSplitter(InsertParam.orientation());
NewSplitter->addWidget(TargetDockArea);
insertWidgetIntoSplitter(NewSplitter, NewDockArea, InsertParam.append());
TargetAreaSplitter->insertWidget(index, NewSplitter);
}
DockAreas.append(NewDockArea);
emit _this->dockAreasAdded();
return NewDockArea;
}
//============================================================================
CDockContainerWidget::CDockContainerWidget(CDockManager* DockManager, QWidget *parent) :
QFrame(parent),
d(new DockContainerWidgetPrivate(this))
{
d->isFloating = dynamic_cast<CFloatingDockContainer*>(parent) != 0;
//setStyleSheet("background: green;");
d->DockManager = DockManager;
if (DockManager != this)
{
d->DockManager->registerDockContainer(this);
}
d->Layout = new QGridLayout();
d->Layout->setContentsMargins(0, 1, 0, 1);
d->Layout->setSpacing(0);
setLayout(d->Layout);
2017-03-24 19:54:43 +08:00
d->RootSplitter = internal::newSplitter(Qt::Horizontal);
d->Layout->addWidget(d->RootSplitter);
}
//============================================================================
CDockContainerWidget::~CDockContainerWidget()
{
if (d->DockManager)
{
d->DockManager->removeDockContainer(this);
}
delete d;
}
//============================================================================
CDockAreaWidget* CDockContainerWidget::addDockWidget(DockWidgetArea area, CDockWidget* Dockwidget,
CDockAreaWidget* DockAreaWidget)
{
CDockAreaWidget* OldDockArea = Dockwidget->dockAreaWidget();
if (OldDockArea)
{
OldDockArea->removeDockWidget(Dockwidget);
}
Dockwidget->setDockManager(d->DockManager);
if (DockAreaWidget)
{
return d->dockWidgetIntoDockArea(area, Dockwidget, DockAreaWidget);
}
else
{
return d->dockWidgetIntoContainer(area, Dockwidget);
}
}
//============================================================================
unsigned int CDockContainerWidget::zOrderIndex() const
{
return d->zOrderIndex;
}
//============================================================================
bool CDockContainerWidget::isInFrontOf(CDockContainerWidget* Other) const
{
return this->zOrderIndex() > Other->zOrderIndex();
}
//============================================================================
bool CDockContainerWidget::event(QEvent *e)
{
bool Result = QWidget::event(e);
if (e->type() == QEvent::WindowActivate)
{
d->zOrderIndex = ++zOrderCounter;
}
else if (e->type() == QEvent::Show && !d->zOrderIndex)
{
d->zOrderIndex = ++zOrderCounter;
}
return Result;
}
//============================================================================
void CDockContainerWidget::addDockArea(CDockAreaWidget* DockAreaWidget,
DockWidgetArea area)
{
CDockContainerWidget* Container = DockAreaWidget->dockContainer();
if (Container && Container != this)
{
Container->removeDockArea(DockAreaWidget);
}
d->addDockArea(DockAreaWidget, area);
}
//============================================================================
void CDockContainerWidget::removeDockArea(CDockAreaWidget* area)
{
qDebug() << "CDockContainerWidget::removeDockArea";
d->DockAreas.removeAll(area);
QSplitter* Splitter = internal::findParent<QSplitter*>(area);
area->setParent(0);
2017-03-24 19:54:43 +08:00
if (Splitter == d->RootSplitter || Splitter->count() != 1)
{
emit dockAreasRemoved();
return;
}
// It the splitter contains only one single widget, then we do not need
// it anymore and can replace it with its content
qDebug() << "Replacing splitter with content";
QWidget* widget = Splitter->widget(0);
widget->setParent(this);
QSplitter* ParentSplitter = internal::findParent<QSplitter*>(Splitter);
2017-03-24 19:54:43 +08:00
internal::replaceSplitterWidget(ParentSplitter, Splitter, widget);
delete Splitter;
dumpLayout();
emit dockAreasRemoved();
}
//============================================================================
CDockAreaWidget* CDockContainerWidget::dockAreaAt(const QPoint& GlobalPos) const
{
for (const auto& DockArea : d->DockAreas)
{
if (DockArea->rect().contains(DockArea->mapFromGlobal(GlobalPos)))
{
return DockArea;
}
}
return 0;
}
//============================================================================
CDockAreaWidget* CDockContainerWidget::dockArea(int Index) const
{
return (Index < dockAreaCount()) ? d->DockAreas[Index] : 0;
}
//============================================================================
bool CDockContainerWidget::isFloating() const
{
return d->isFloating;
}
//============================================================================
int CDockContainerWidget::dockAreaCount() const
{
return d->DockAreas.count();
}
//============================================================================
int CDockContainerWidget::visibleDockAreaCount() const
{
// TODO Cache or precalculate this to speed it up because it is used during
// movement of floating widget
int Result = 0;
for (auto DockArea : d->DockAreas)
{
Result += DockArea->isVisible() ? 1 : 0;
}
return Result;
}
//============================================================================
void CDockContainerWidget::dropFloatingWidget(CFloatingDockContainer* FloatingWidget,
const QPoint& TargetPos)
{
qDebug() << "CDockContainerWidget::dropFloatingWidget";
CDockAreaWidget* DockArea = dockAreaAt(TargetPos);
auto dropArea = InvalidDockWidgetArea;
if (DockArea)
{
auto dropOverlay = d->DockManager->dockAreaOverlay();
dropOverlay->setAllowedAreas(AllDockAreas);
dropArea = dropOverlay->showOverlay(DockArea);
if (dropArea != InvalidDockWidgetArea)
{
qDebug() << "Dock Area Drop Content: " << dropArea;
d->dropIntoSection(FloatingWidget, DockArea, dropArea);
}
}
// mouse is over container
if (InvalidDockWidgetArea == dropArea)
{
dropArea = d->DockManager->containerOverlay()->dropAreaUnderCursor();
qDebug() << "Container Drop Content: " << dropArea;
if (dropArea != InvalidDockWidgetArea)
{
d->dropIntoContainer(FloatingWidget, dropArea);
}
}
}
//============================================================================
QList<CDockAreaWidget*> CDockContainerWidget::openedDockAreas() const
{
QList<CDockAreaWidget*> Result;
for (auto DockArea : d->DockAreas)
{
if (DockArea->isVisible())
{
Result.append(DockArea);
}
}
return Result;
}
//============================================================================
void CDockContainerWidget::saveState(QDataStream& stream) const
{
qDebug() << "CDockContainerWidget::saveState isFloating "
<< isFloating();
2017-03-27 16:41:27 +08:00
stream << internal::ContainerMarker;
stream << isFloating();
if (isFloating())
{
CFloatingDockContainer* FloatingWidget = internal::findParent<CFloatingDockContainer*>(this);
stream << FloatingWidget->saveGeometry();
}
d->saveChildNodesState(stream, d->RootSplitter);
}
//============================================================================
2017-03-27 16:41:27 +08:00
bool CDockContainerWidget::restoreState(QDataStream& stream, bool Testing)
{
bool IsFloating;
2017-03-27 16:41:27 +08:00
int Marker;
stream >> Marker;
if (Marker != internal::ContainerMarker)
{
return false;
}
stream >> IsFloating;
qDebug() << "Restore CDockContainerWidget Floating" << IsFloating;
2017-03-24 17:18:25 +08:00
QWidget* NewRootSplitter;
2017-03-27 16:41:27 +08:00
if (!Testing)
{
d->DockAreas.clear();
}
if (IsFloating)
{
qDebug() << "Restore floating widget";
QByteArray Geometry;
stream >> Geometry;
2017-03-27 16:41:27 +08:00
if (!Testing)
{
CFloatingDockContainer* FloatingWidget = internal::findParent<CFloatingDockContainer*>(this);
FloatingWidget->restoreGeometry(Geometry);
FloatingWidget->show();
}
}
if (!d->restoreChildNodes(stream, NewRootSplitter, Testing))
{
return false;
}
2017-03-27 16:41:27 +08:00
if (Testing)
{
return true;
}
2017-03-27 19:18:16 +08:00
// If the root splitter is empty, rostoreChildNodes returns a 0 pointer
// and we need to create a new empty root splitter
if (!NewRootSplitter)
{
NewRootSplitter = internal::newSplitter(Qt::Horizontal);
}
d->Layout->replaceWidget(d->RootSplitter, NewRootSplitter);
QSplitter* OldRoot = d->RootSplitter;
d->RootSplitter = dynamic_cast<QSplitter*>(NewRootSplitter);
2017-03-27 16:41:27 +08:00
OldRoot->deleteLater();
2017-03-27 19:18:16 +08:00
return true;
}
//============================================================================
QSplitter* CDockContainerWidget::rootSplitter() const
{
return d->RootSplitter;
}
//============================================================================
void CDockContainerWidget::dumpLayout()
{
d->dumpRecursive(0, d->RootSplitter);
}
} // namespace ads
//---------------------------------------------------------------------------
// EOF DockContainerWidget.cpp