mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-12-26 08:01:32 +08:00
Implemented RootSplitter
This commit is contained in:
parent
a652deba71
commit
5dcd15e2b9
@ -75,7 +75,7 @@ struct DockContainerWidgetPrivate
|
|||||||
unsigned int zOrderIndex = 0;
|
unsigned int zOrderIndex = 0;
|
||||||
QList<CDockAreaWidget*> DockAreas;
|
QList<CDockAreaWidget*> DockAreas;
|
||||||
QGridLayout* Layout = nullptr;
|
QGridLayout* Layout = nullptr;
|
||||||
CDockSplitter* RootSplitter;
|
QSplitter* RootSplitter;
|
||||||
bool isFloating = false;
|
bool isFloating = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -143,30 +143,18 @@ void DockContainerWidgetPrivate::dropIntoContainer(CFloatingDockContainer* Float
|
|||||||
auto InsertParam = internal::dockAreaInsertParameters(area);
|
auto InsertParam = internal::dockAreaInsertParameters(area);
|
||||||
auto NewDockAreas = FloatingWidget->dockContainer()->findChildren<CDockAreaWidget*>(
|
auto NewDockAreas = FloatingWidget->dockContainer()->findChildren<CDockAreaWidget*>(
|
||||||
QString(), Qt::FindChildrenRecursively);
|
QString(), Qt::FindChildrenRecursively);
|
||||||
QSplitter* OldSplitter = nullptr;
|
QSplitter* Splitter = RootSplitter;
|
||||||
|
|
||||||
// If the container already contains dock areas, then we need to ensure that
|
if (DockAreas.count() <= 1)
|
||||||
// we have a splitter with an orientation that matches the orientation of
|
|
||||||
// the current drop action
|
|
||||||
if (!DockAreas.isEmpty())
|
|
||||||
{
|
{
|
||||||
OldSplitter = _this->findChild<QSplitter*>(QString(), Qt::FindDirectChildrenOnly);
|
Splitter->setOrientation(InsertParam.orientation());
|
||||||
// First replace the dock widget with a splitter
|
|
||||||
if (DockAreas.count() == 1)
|
|
||||||
{
|
|
||||||
auto DockArea = dynamic_cast<CDockAreaWidget*>(Layout->itemAtPosition(0, 0)->widget());
|
|
||||||
QSplitter* NewSplitter = internal::newSplitter(InsertParam.orientation());
|
|
||||||
Layout->replaceWidget(DockArea, NewSplitter);
|
|
||||||
NewSplitter->addWidget(DockArea);
|
|
||||||
OldSplitter = NewSplitter;
|
|
||||||
}
|
}
|
||||||
else if (OldSplitter->orientation() != InsertParam.orientation())
|
else
|
||||||
{
|
{
|
||||||
QSplitter* NewSplitter = internal::newSplitter(InsertParam.orientation());
|
QSplitter* NewSplitter = internal::newSplitter(InsertParam.orientation());
|
||||||
QLayoutItem* li = Layout->replaceWidget(OldSplitter, NewSplitter);
|
QLayoutItem* li = Layout->replaceWidget(Splitter, NewSplitter);
|
||||||
NewSplitter->addWidget(OldSplitter);
|
NewSplitter->addWidget(Splitter);
|
||||||
OldSplitter = NewSplitter;
|
Splitter = NewSplitter;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now we can insert the floating widget content into this container
|
// Now we can insert the floating widget content into this container
|
||||||
@ -174,25 +162,25 @@ void DockContainerWidgetPrivate::dropIntoContainer(CFloatingDockContainer* Float
|
|||||||
auto FloatingSplitter = dynamic_cast<QSplitter*>(Widget);
|
auto FloatingSplitter = dynamic_cast<QSplitter*>(Widget);
|
||||||
if (DockAreas.isEmpty())
|
if (DockAreas.isEmpty())
|
||||||
{
|
{
|
||||||
auto Widget = FloatingWidget->dockContainer()->findChild<QWidget*>(QString(), Qt::FindDirectChildrenOnly);
|
Splitter->addWidget(Widget);
|
||||||
Layout->addWidget(Widget, 0, 0);
|
|
||||||
}
|
}
|
||||||
else if (!FloatingSplitter)
|
else if (FloatingSplitter->count() == 1)
|
||||||
{
|
{
|
||||||
insertWidgetIntoSplitter(OldSplitter, Widget, InsertParam.append());
|
insertWidgetIntoSplitter(Splitter, FloatingSplitter->widget(0), InsertParam.append());
|
||||||
}
|
}
|
||||||
else if (FloatingSplitter->orientation() == InsertParam.orientation())
|
else if (FloatingSplitter->orientation() == InsertParam.orientation())
|
||||||
{
|
{
|
||||||
while (FloatingSplitter->count())
|
while (FloatingSplitter->count())
|
||||||
{
|
{
|
||||||
insertWidgetIntoSplitter(OldSplitter, FloatingSplitter->widget(0), InsertParam.append());
|
insertWidgetIntoSplitter(Splitter, FloatingSplitter->widget(0), InsertParam.append());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
insertWidgetIntoSplitter(OldSplitter, FloatingSplitter, InsertParam.append());
|
insertWidgetIntoSplitter(Splitter, FloatingSplitter, InsertParam.append());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RootSplitter = Splitter;
|
||||||
addDockAreasToList(NewDockAreas);
|
addDockAreasToList(NewDockAreas);
|
||||||
FloatingWidget->deleteLater();
|
FloatingWidget->deleteLater();
|
||||||
}
|
}
|
||||||
@ -236,7 +224,7 @@ void DockContainerWidgetPrivate::dropIntoSection(CFloatingDockContainer* Floatin
|
|||||||
|
|
||||||
if (TargetAreaSplitter->orientation() == InsertParam.orientation())
|
if (TargetAreaSplitter->orientation() == InsertParam.orientation())
|
||||||
{
|
{
|
||||||
if (!FloatingSplitter || FloatingSplitter->orientation() != InsertParam.orientation())
|
if ((FloatingSplitter->orientation() != InsertParam.orientation()) && FloatingSplitter->count() > 1)
|
||||||
{
|
{
|
||||||
TargetAreaSplitter->insertWidget(AreaIndex + InsertParam.insertOffset(), Widget);
|
TargetAreaSplitter->insertWidget(AreaIndex + InsertParam.insertOffset(), Widget);
|
||||||
}
|
}
|
||||||
@ -252,7 +240,7 @@ void DockContainerWidgetPrivate::dropIntoSection(CFloatingDockContainer* Floatin
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
QSplitter* NewSplitter = internal::newSplitter(InsertParam.orientation());
|
QSplitter* NewSplitter = internal::newSplitter(InsertParam.orientation());
|
||||||
if (!FloatingSplitter || FloatingSplitter->orientation() != InsertParam.orientation())
|
if ((FloatingSplitter->orientation() != InsertParam.orientation()) && FloatingSplitter->count() > 1)
|
||||||
{
|
{
|
||||||
NewSplitter->addWidget(Widget);
|
NewSplitter->addWidget(Widget);
|
||||||
}
|
}
|
||||||
@ -405,24 +393,14 @@ CDockAreaWidget* DockContainerWidgetPrivate::dockWidgetIntoContainer(DockWidgetA
|
|||||||
void DockContainerWidgetPrivate::addDockArea(CDockAreaWidget* NewDockArea, DockWidgetArea area)
|
void DockContainerWidgetPrivate::addDockArea(CDockAreaWidget* NewDockArea, DockWidgetArea area)
|
||||||
{
|
{
|
||||||
auto InsertParam = internal::dockAreaInsertParameters(area);
|
auto InsertParam = internal::dockAreaInsertParameters(area);
|
||||||
if (DockAreas.isEmpty())
|
// As long as we have only one dock area in the splitter we can adjust
|
||||||
|
// its orientation
|
||||||
|
if (DockAreas.count() <= 1)
|
||||||
{
|
{
|
||||||
QSplitter* Splitter = internal::newSplitter(Qt::Horizontal);
|
RootSplitter->setOrientation(InsertParam.orientation());
|
||||||
Splitter->addWidget(NewDockArea);
|
|
||||||
insertWidgetIntoSplitter(Splitter, NewDockArea, InsertParam.append());
|
|
||||||
_this->layout()->addWidget(Splitter);
|
|
||||||
}
|
}
|
||||||
else if (DockAreas.count() == 1)
|
|
||||||
{
|
QSplitter* Splitter = RootSplitter;
|
||||||
QSplitter* Splitter = internal::newSplitter(InsertParam.orientation());
|
|
||||||
auto DockArea = dynamic_cast<CDockAreaWidget*>(Layout->itemAtPosition(0, 0)->widget());
|
|
||||||
Layout->replaceWidget(DockArea, Splitter);
|
|
||||||
Splitter->addWidget(DockArea);
|
|
||||||
insertWidgetIntoSplitter(Splitter, NewDockArea, InsertParam.append());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
QSplitter* Splitter = _this->findChild<QSplitter*>(QString(), Qt::FindDirectChildrenOnly);
|
|
||||||
if (Splitter->orientation() == InsertParam.orientation())
|
if (Splitter->orientation() == InsertParam.orientation())
|
||||||
{
|
{
|
||||||
insertWidgetIntoSplitter(Splitter, NewDockArea, InsertParam.append());
|
insertWidgetIntoSplitter(Splitter, NewDockArea, InsertParam.append());
|
||||||
@ -444,7 +422,7 @@ void DockContainerWidgetPrivate::addDockArea(CDockAreaWidget* NewDockArea, DockW
|
|||||||
NewSplitter->addWidget(Splitter);
|
NewSplitter->addWidget(Splitter);
|
||||||
delete li;
|
delete li;
|
||||||
}
|
}
|
||||||
}
|
RootSplitter = NewSplitter;
|
||||||
}
|
}
|
||||||
|
|
||||||
DockAreas.append(NewDockArea);
|
DockAreas.append(NewDockArea);
|
||||||
@ -466,16 +444,7 @@ CDockAreaWidget* DockContainerWidgetPrivate::dockWidgetIntoDockArea(DockWidgetAr
|
|||||||
CDockAreaWidget* NewDockArea = new CDockAreaWidget(DockManager, _this);
|
CDockAreaWidget* NewDockArea = new CDockAreaWidget(DockManager, _this);
|
||||||
NewDockArea->addDockWidget(Dockwidget);
|
NewDockArea->addDockWidget(Dockwidget);
|
||||||
auto InsertParam = internal::dockAreaInsertParameters(area);
|
auto InsertParam = internal::dockAreaInsertParameters(area);
|
||||||
if (DockAreas.count() == 1)
|
|
||||||
{
|
|
||||||
QSplitter* Splitter = internal::newSplitter(InsertParam.orientation());
|
|
||||||
auto DockArea = dynamic_cast<CDockAreaWidget*>(Layout->itemAtPosition(0, 0)->widget());
|
|
||||||
Layout->replaceWidget(DockArea, Splitter);
|
|
||||||
Splitter->addWidget(DockArea);
|
|
||||||
insertWidgetIntoSplitter(Splitter, NewDockArea, InsertParam.append());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
QSplitter* TargetAreaSplitter = internal::findParent<QSplitter*>(TargetDockArea);
|
QSplitter* TargetAreaSplitter = internal::findParent<QSplitter*>(TargetDockArea);
|
||||||
int index = TargetAreaSplitter ->indexOf(TargetDockArea);
|
int index = TargetAreaSplitter ->indexOf(TargetDockArea);
|
||||||
if (TargetAreaSplitter->orientation() == InsertParam.orientation())
|
if (TargetAreaSplitter->orientation() == InsertParam.orientation())
|
||||||
@ -491,7 +460,6 @@ CDockAreaWidget* DockContainerWidgetPrivate::dockWidgetIntoDockArea(DockWidgetAr
|
|||||||
insertWidgetIntoSplitter(NewSplitter, NewDockArea, InsertParam.append());
|
insertWidgetIntoSplitter(NewSplitter, NewDockArea, InsertParam.append());
|
||||||
TargetAreaSplitter->insertWidget(index, NewSplitter);
|
TargetAreaSplitter->insertWidget(index, NewSplitter);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
DockAreas.append(NewDockArea);
|
DockAreas.append(NewDockArea);
|
||||||
emit _this->dockAreasAdded();
|
emit _this->dockAreasAdded();
|
||||||
@ -517,6 +485,9 @@ CDockContainerWidget::CDockContainerWidget(CDockManager* DockManager, QWidget *p
|
|||||||
d->Layout->setContentsMargins(0, 1, 0, 1);
|
d->Layout->setContentsMargins(0, 1, 0, 1);
|
||||||
d->Layout->setSpacing(0);
|
d->Layout->setSpacing(0);
|
||||||
setLayout(d->Layout);
|
setLayout(d->Layout);
|
||||||
|
|
||||||
|
d->RootSplitter = internal::newSplitter(Qt::Horizontal);
|
||||||
|
d->Layout->addWidget(d->RootSplitter);
|
||||||
}
|
}
|
||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
@ -604,7 +575,7 @@ void CDockContainerWidget::removeDockArea(CDockAreaWidget* area)
|
|||||||
d->DockAreas.removeAll(area);
|
d->DockAreas.removeAll(area);
|
||||||
QSplitter* Splitter = internal::findParent<QSplitter*>(area);
|
QSplitter* Splitter = internal::findParent<QSplitter*>(area);
|
||||||
area->setParent(0);
|
area->setParent(0);
|
||||||
if (!(Splitter && Splitter->count() == 1))
|
if (Splitter == d->RootSplitter || Splitter->count() != 1)
|
||||||
{
|
{
|
||||||
emit dockAreasRemoved();
|
emit dockAreasRemoved();
|
||||||
return;
|
return;
|
||||||
@ -616,14 +587,7 @@ void CDockContainerWidget::removeDockArea(CDockAreaWidget* area)
|
|||||||
QWidget* widget = Splitter->widget(0);
|
QWidget* widget = Splitter->widget(0);
|
||||||
widget->setParent(this);
|
widget->setParent(this);
|
||||||
QSplitter* ParentSplitter = internal::findParent<QSplitter*>(Splitter);
|
QSplitter* ParentSplitter = internal::findParent<QSplitter*>(Splitter);
|
||||||
if (ParentSplitter)
|
|
||||||
{
|
|
||||||
internal::replaceSplitterWidget(ParentSplitter, Splitter, widget);
|
internal::replaceSplitterWidget(ParentSplitter, Splitter, widget);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
d->Layout->replaceWidget(Splitter, widget);
|
|
||||||
}
|
|
||||||
delete Splitter;
|
delete Splitter;
|
||||||
emit dockAreasRemoved();
|
emit dockAreasRemoved();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user