mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-12-24 23:31:32 +08:00
Added initial support for docking into dock areas
This commit is contained in:
parent
c14352e7c1
commit
b31c5f1f3d
@ -39,6 +39,8 @@
|
|||||||
#include "DockAreaWidget.h"
|
#include "DockAreaWidget.h"
|
||||||
#include "ads_globals.h"
|
#include "ads_globals.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
namespace ads
|
namespace ads
|
||||||
{
|
{
|
||||||
static unsigned int zOrderCounter = 0;
|
static unsigned int zOrderCounter = 0;
|
||||||
@ -46,7 +48,7 @@ static unsigned int zOrderCounter = 0;
|
|||||||
/**
|
/**
|
||||||
* Helper function to ease insertion of dock area into splitter
|
* Helper function to ease insertion of dock area into splitter
|
||||||
*/
|
*/
|
||||||
static void inserDockAreaIntoSplitter(QSplitter* Splitter, QWidget* widget, bool Append)
|
static void insertDockAreaIntoSplitter(QSplitter* Splitter, QWidget* widget, bool Append)
|
||||||
{
|
{
|
||||||
if (Append)
|
if (Append)
|
||||||
{
|
{
|
||||||
@ -94,7 +96,7 @@ struct DockContainerWidgetPrivate
|
|||||||
* Adds dock widget to a existing DockWidgetArea
|
* Adds dock widget to a existing DockWidgetArea
|
||||||
*/
|
*/
|
||||||
CDockAreaWidget* dockWidgetIntoDockArea(DockWidgetArea area, CDockWidget* Dockwidget,
|
CDockAreaWidget* dockWidgetIntoDockArea(DockWidgetArea area, CDockWidget* Dockwidget,
|
||||||
CDockAreaWidget* DockAreaWidget);
|
CDockAreaWidget* TargetDockArea);
|
||||||
}; // struct DockContainerWidgetPrivate
|
}; // struct DockContainerWidgetPrivate
|
||||||
|
|
||||||
|
|
||||||
@ -120,23 +122,23 @@ CDockAreaWidget* DockContainerWidgetPrivate::dockWidgetIntoContainer(DockWidgetA
|
|||||||
}
|
}
|
||||||
else if (DockAreas.count() == 1)
|
else if (DockAreas.count() == 1)
|
||||||
{
|
{
|
||||||
QSplitter* Splitter = internal::newSplitter(InsertParam.first);
|
QSplitter* Splitter = internal::newSplitter(InsertParam.orientation());
|
||||||
auto DockArea = dynamic_cast<CDockAreaWidget*>(Layout->itemAtPosition(0, 0)->widget());
|
auto DockArea = dynamic_cast<CDockAreaWidget*>(Layout->itemAtPosition(0, 0)->widget());
|
||||||
Layout->replaceWidget(DockArea, Splitter);
|
Layout->replaceWidget(DockArea, Splitter);
|
||||||
Splitter->addWidget(DockArea);
|
Splitter->addWidget(DockArea);
|
||||||
inserDockAreaIntoSplitter(Splitter, NewDockArea, InsertParam.second);
|
insertDockAreaIntoSplitter(Splitter, NewDockArea, InsertParam.append());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QSplitter* Splitter = _this->findChild<QSplitter*>(QString(), Qt::FindDirectChildrenOnly);
|
QSplitter* Splitter = _this->findChild<QSplitter*>(QString(), Qt::FindDirectChildrenOnly);
|
||||||
if (Splitter->orientation() == InsertParam.first)
|
if (Splitter->orientation() == InsertParam.orientation())
|
||||||
{
|
{
|
||||||
inserDockAreaIntoSplitter(Splitter, NewDockArea, InsertParam.second);
|
insertDockAreaIntoSplitter(Splitter, NewDockArea, InsertParam.append());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QSplitter* NewSplitter = internal::newSplitter(InsertParam.first);
|
QSplitter* NewSplitter = internal::newSplitter(InsertParam.orientation());
|
||||||
if (InsertParam.second)
|
if (InsertParam.append())
|
||||||
{
|
{
|
||||||
QLayoutItem* li = Layout->replaceWidget(Splitter, NewSplitter);
|
QLayoutItem* li = Layout->replaceWidget(Splitter, NewSplitter);
|
||||||
NewSplitter->addWidget(Splitter);
|
NewSplitter->addWidget(Splitter);
|
||||||
@ -160,16 +162,35 @@ CDockAreaWidget* DockContainerWidgetPrivate::dockWidgetIntoContainer(DockWidgetA
|
|||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
CDockAreaWidget* DockContainerWidgetPrivate::dockWidgetIntoDockArea(DockWidgetArea area,
|
CDockAreaWidget* DockContainerWidgetPrivate::dockWidgetIntoDockArea(DockWidgetArea area,
|
||||||
CDockWidget* Dockwidget, CDockAreaWidget* DockAreaWidget)
|
CDockWidget* Dockwidget, CDockAreaWidget* TargetDockArea)
|
||||||
{
|
{
|
||||||
if (CenterDockWidgetArea == area)
|
if (CenterDockWidgetArea == area)
|
||||||
{
|
{
|
||||||
DockAreaWidget->addDockWidget(Dockwidget);
|
TargetDockArea->addDockWidget(Dockwidget);
|
||||||
return DockAreaWidget;
|
return TargetDockArea;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CDockAreaWidget* NewDockArea = new CDockAreaWidget(DockManager, _this);
|
||||||
|
NewDockArea->addDockWidget(Dockwidget);
|
||||||
auto InsertParam = internal::dockAreaInsertParameters(area);
|
auto InsertParam = internal::dockAreaInsertParameters(area);
|
||||||
return 0;
|
QSplitter* TargetAreaSplitter = internal::findParentSplitter(TargetDockArea);
|
||||||
|
int index = TargetAreaSplitter ->indexOf(TargetDockArea);
|
||||||
|
if (TargetAreaSplitter->orientation() == InsertParam.orientation())
|
||||||
|
{
|
||||||
|
std::cout << "TargetAreaSplitter->orientation() == InsertParam.orientation()" << std::endl;
|
||||||
|
TargetAreaSplitter->insertWidget(index + InsertParam.insertOffset(), NewDockArea);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cout << "TargetAreaSplitter->orientation() != InsertParam.orientation()" << std::endl;
|
||||||
|
QSplitter* NewSplitter = internal::newSplitter(InsertParam.orientation());
|
||||||
|
NewSplitter->addWidget(TargetDockArea);
|
||||||
|
insertDockAreaIntoSplitter(NewSplitter, NewDockArea, InsertParam.append());
|
||||||
|
TargetAreaSplitter->insertWidget(index, NewSplitter);
|
||||||
|
}
|
||||||
|
|
||||||
|
DockAreas.append(NewDockArea);
|
||||||
|
return NewDockArea;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ QSplitter* newSplitter(Qt::Orientation orientation, QWidget* parent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
QPair<Qt::Orientation, bool> dockAreaInsertParameters(DockWidgetArea Area)
|
CDockInsertParam dockAreaInsertParameters(DockWidgetArea Area)
|
||||||
{
|
{
|
||||||
switch (Area)
|
switch (Area)
|
||||||
{
|
{
|
||||||
@ -61,10 +61,27 @@ QPair<Qt::Orientation, bool> dockAreaInsertParameters(DockWidgetArea Area)
|
|||||||
default: QPair<Qt::Orientation, bool>(Qt::Vertical, false);
|
default: QPair<Qt::Orientation, bool>(Qt::Vertical, false);
|
||||||
} // switch (Area)
|
} // switch (Area)
|
||||||
|
|
||||||
return QPair<Qt::Orientation, bool>(Qt::Vertical, false);
|
return CDockInsertParam(Qt::Vertical, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//============================================================================
|
||||||
|
QSplitter* findParentSplitter(QWidget* w)
|
||||||
|
{
|
||||||
|
QWidget* parentWidget = w;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
QSplitter* splitter = dynamic_cast<QSplitter*>(parentWidget);
|
||||||
|
if (splitter)
|
||||||
|
{
|
||||||
|
return splitter;
|
||||||
|
}
|
||||||
|
parentWidget = parentWidget->parentWidget();
|
||||||
|
}
|
||||||
|
while (parentWidget);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
} // namespace ads
|
} // namespace ads
|
||||||
|
|
||||||
|
@ -57,10 +57,29 @@ namespace internal
|
|||||||
*/
|
*/
|
||||||
QSplitter* newSplitter(Qt::Orientation orientation, QWidget* parent = 0);
|
QSplitter* newSplitter(Qt::Orientation orientation, QWidget* parent = 0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenience class for QPair to provide better naming than first and
|
||||||
|
* second
|
||||||
|
*/
|
||||||
|
class CDockInsertParam : public QPair<Qt::Orientation, bool>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
using QPair::QPair;
|
||||||
|
Qt::Orientation orientation() const {return this->first;}
|
||||||
|
bool append() const {return this->second;}
|
||||||
|
int insertOffset() const {return append() ? 1 : 0;}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the insertion parameters for the given dock area
|
* Returns the insertion parameters for the given dock area
|
||||||
*/
|
*/
|
||||||
QPair<Qt::Orientation, bool> dockAreaInsertParameters(DockWidgetArea Area);
|
CDockInsertParam dockAreaInsertParameters(DockWidgetArea Area);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the parent splitter of the given widget or 0 if the widget is not
|
||||||
|
* child of any splitter
|
||||||
|
*/
|
||||||
|
QSplitter* findParentSplitter(QWidget* w);
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
} // namespace ads
|
} // namespace ads
|
||||||
|
|
||||||
|
@ -86,15 +86,23 @@ MainWindow::~MainWindow()
|
|||||||
|
|
||||||
void MainWindow::createContent()
|
void MainWindow::createContent()
|
||||||
{
|
{
|
||||||
|
// Test container docking
|
||||||
auto DockWidget = createCalendarDockWidget(m_DockManager);
|
auto DockWidget = createCalendarDockWidget(m_DockManager);
|
||||||
DockWidget->setFeatures(DockWidget->features().setFlag(ads::CDockWidget::DockWidgetClosable, false));
|
DockWidget->setFeatures(DockWidget->features().setFlag(ads::CDockWidget::DockWidgetClosable, false));
|
||||||
m_DockManager->addDockWidget(ads::LeftDockWidgetArea, DockWidget);
|
m_DockManager->addDockWidget(ads::LeftDockWidgetArea, DockWidget);
|
||||||
m_DockManager->addDockWidget(ads::LeftDockWidgetArea, createLongTextLabelDockWidget(m_DockManager));
|
m_DockManager->addDockWidget(ads::LeftDockWidgetArea, createLongTextLabelDockWidget(m_DockManager));
|
||||||
m_DockManager->addDockWidget(ads::BottomDockWidgetArea, createFileSystemTreeDockWidget(m_DockManager));
|
m_DockManager->addDockWidget(ads::BottomDockWidgetArea, createFileSystemTreeDockWidget(m_DockManager));
|
||||||
auto DockArea = m_DockManager->addDockWidget(ads::TopDockWidgetArea, createFileSystemTreeDockWidget(m_DockManager));
|
auto TopDockArea = m_DockManager->addDockWidget(ads::TopDockWidgetArea, createFileSystemTreeDockWidget(m_DockManager));
|
||||||
DockWidget = createCalendarDockWidget(m_DockManager);
|
DockWidget = createCalendarDockWidget(m_DockManager);
|
||||||
DockWidget->setFeatures(DockWidget->features().setFlag(ads::CDockWidget::DockWidgetClosable, false));
|
DockWidget->setFeatures(DockWidget->features().setFlag(ads::CDockWidget::DockWidgetClosable, false));
|
||||||
m_DockManager->addDockWidget(ads::CenterDockWidgetArea, DockWidget, DockArea);
|
m_DockManager->addDockWidget(ads::CenterDockWidgetArea, DockWidget, TopDockArea);
|
||||||
|
|
||||||
|
// Test dock area docking
|
||||||
|
auto RighDockArea = m_DockManager->addDockWidget(ads::RightDockWidgetArea, createLongTextLabelDockWidget(m_DockManager), TopDockArea);
|
||||||
|
m_DockManager->addDockWidget(ads::TopDockWidgetArea, createLongTextLabelDockWidget(m_DockManager), RighDockArea);
|
||||||
|
auto BottomDockArea = m_DockManager->addDockWidget(ads::BottomDockWidgetArea, createLongTextLabelDockWidget(m_DockManager), RighDockArea);
|
||||||
|
m_DockManager->addDockWidget(ads::RightDockWidgetArea, createLongTextLabelDockWidget(m_DockManager), RighDockArea);
|
||||||
|
m_DockManager->addDockWidget(ads::CenterDockWidgetArea, createLongTextLabelDockWidget(m_DockManager), BottomDockArea);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user