mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2025-01-24 05:22:06 +08:00
Implemented initial support for dropping multiple sections at the same time
This commit is contained in:
parent
268c49af3b
commit
72fc9cd79a
@ -81,6 +81,7 @@ signals:
|
||||
|
||||
protected:
|
||||
void dropIntoContainer(FloatingWidget* FloatingWidget, DropArea area);
|
||||
void dropIntoSection(FloatingWidget* FloatingWidget, SectionWidget* targetSection, DropArea area);
|
||||
virtual bool event(QEvent *e) override;
|
||||
SectionWidget* newSectionWidget();
|
||||
void addSectionWidget(SectionWidget* section);
|
||||
|
@ -50,14 +50,6 @@ public:
|
||||
// Public API
|
||||
//
|
||||
|
||||
/*!
|
||||
* Adds the section-content <em>sc</em> to this container-widget into the section-widget <em>sw</em>.
|
||||
* If <em>sw</em> is not NULL, the <em>area</em> is used to indicate how the content should be arranged.
|
||||
* Returns a pointer to the SectionWidget of the added SectionContent. Do not use it for anything else than adding more
|
||||
* SectionContent elements with this method.
|
||||
*/
|
||||
SectionWidget* addSectionContent(const SectionContent::RefPtr& sc, SectionWidget* sw = NULL, DropArea area = CenterDropArea);
|
||||
|
||||
/*!
|
||||
* Completely removes the <em>sc</em> from this ContainerWidget.
|
||||
* This container will no longer hold a reference to the content.
|
||||
|
@ -97,17 +97,24 @@ QSplitter* findParentSplitter(class QWidget* w)
|
||||
|
||||
QSplitter* findImmediateSplitter(class QWidget* w)
|
||||
{
|
||||
QSplitter* sp = NULL;
|
||||
QLayout* l = w->layout();
|
||||
if (!l || l->count() <= 0)
|
||||
return sp;
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QSplitter* sp = nullptr;
|
||||
for (int i = 0; i < l->count(); ++i)
|
||||
{
|
||||
QLayoutItem* li = l->itemAt(0);
|
||||
if (!li->widget())
|
||||
{
|
||||
continue;
|
||||
if ((sp = dynamic_cast<QSplitter*>(li->widget())) != NULL)
|
||||
}
|
||||
if ((sp = dynamic_cast<QSplitter*>(li->widget())) != nullptr)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
return sp;
|
||||
}
|
||||
|
@ -90,10 +90,11 @@ void CContainerWidget::dropFloatingWidget(FloatingWidget* FloatingWidget,
|
||||
if (dropArea != InvalidDropArea)
|
||||
{
|
||||
std::cout << "Section Drop Content: " << dropArea << std::endl;
|
||||
InternalContentData data;
|
||||
/*InternalContentData data;
|
||||
FloatingWidget->takeContent(data);
|
||||
FloatingWidget->deleteLater();
|
||||
dropContent(data, sectionWidget, dropArea, true);
|
||||
dropContent(data, sectionWidget, dropArea, true);*/
|
||||
dropIntoSection(FloatingWidget, sectionWidget, dropArea);
|
||||
}
|
||||
}
|
||||
|
||||
@ -104,40 +105,12 @@ void CContainerWidget::dropFloatingWidget(FloatingWidget* FloatingWidget,
|
||||
std::cout << "Container Drop Content: " << dropArea << std::endl;
|
||||
if (dropArea != InvalidDropArea)
|
||||
{
|
||||
// drop content
|
||||
dropIntoContainer(FloatingWidget, dropArea);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*void dumpChildSplitters(QWidget* Widget)
|
||||
{
|
||||
QSplitter* ParentSplitter = dynamic_cast<QSplitter*>(Widget);
|
||||
auto Sections = Widget->findChildren<SectionWidget*>(QString(), Qt::FindDirectChildrenOnly);
|
||||
auto Splitters = Widget->findChildren<QSplitter*>(QString(), Qt::FindDirectChildrenOnly);
|
||||
|
||||
std::cout << "-----------------------" << std::endl;
|
||||
std::cout << "Sections " << Sections.size() << std::endl;
|
||||
std::cout << "Splitters " << Splitters.size() << std::endl;
|
||||
for (const auto& Splitter : Splitters)
|
||||
{
|
||||
if (ParentSplitter)
|
||||
{
|
||||
std::cout << "Orientation " << Splitter->orientation() << " index " << ParentSplitter->indexOf(Splitter) << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Orientation " << Splitter->orientation() << std::endl;
|
||||
}
|
||||
dumpChildSplitters(Splitter);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void CContainerWidget::dumpLayout()
|
||||
{
|
||||
dumpChildSplitters(this);
|
||||
}*/
|
||||
|
||||
void CContainerWidget::dropChildSections(QWidget* Parent)
|
||||
{
|
||||
@ -163,13 +136,153 @@ void CContainerWidget::dropChildSections(QWidget* Parent)
|
||||
void CContainerWidget::dropIntoContainer(FloatingWidget* FloatingWidget, DropArea area)
|
||||
{
|
||||
dropChildSections(FloatingWidget->containerWidget());
|
||||
InternalContentData data;
|
||||
FloatingWidget->takeContent(data);
|
||||
|
||||
CContainerWidget* FloatingContainer = FloatingWidget->containerWidget();
|
||||
QSplitter* FloatingMainSplitter = FloatingContainer->findChild<QSplitter*>(QString(), Qt::FindDirectChildrenOnly);
|
||||
|
||||
//QSplitter* oldsp = findImmediateSplitter(this);
|
||||
// We use findChild here instead of findImmediateSplitter because I do not
|
||||
// know what the advantage of the findImmediateSplitter function is
|
||||
QSplitter* OldSplitter = this->findChild<QSplitter*>(QString(), Qt::FindDirectChildrenOnly);
|
||||
//auto SectionWidgets = FloatingMainSplitter->findChildren<SectionWidget*>(QString(), Qt::FindDirectChildrenOnly);
|
||||
QList<SectionWidget*> SectionWidgets;
|
||||
for (int i = 0; i < FloatingMainSplitter->count(); ++i)
|
||||
{
|
||||
SectionWidgets.append(static_cast<SectionWidget*>(FloatingMainSplitter->widget(i)));
|
||||
}
|
||||
|
||||
std::cout << "SectionWIdget[0] " << SectionWidgets[0] << " FloatingSplitter index 0"
|
||||
<< FloatingMainSplitter->widget(0) << std::endl;
|
||||
//std::cout<< "oldsp " << oldsp << " oldsp2 " << oldsp2 << std::endl;
|
||||
|
||||
Qt::Orientation orientation;
|
||||
bool append;
|
||||
|
||||
switch (area)
|
||||
{
|
||||
case TopDropArea: orientation = Qt::Vertical; append = false; break;
|
||||
case RightDropArea: orientation = Qt::Horizontal; append = true; break;
|
||||
case CenterDropArea:
|
||||
case BottomDropArea: orientation = Qt::Vertical; append = true; break;
|
||||
case LeftDropArea: orientation = Qt::Horizontal; append = false; break;
|
||||
}
|
||||
|
||||
auto l = m_MainLayout;
|
||||
|
||||
if (!OldSplitter)
|
||||
{
|
||||
std::cout << "Create new splitter" << std::endl;
|
||||
// we have no splitter yet - let us create one
|
||||
QSplitter* sp = MainContainerWidget::newSplitter(FloatingMainSplitter->orientation());
|
||||
if (l->count() > 0)
|
||||
{
|
||||
qWarning() << "Still items in layout. This should never happen.";
|
||||
QLayoutItem* li = l->takeAt(0);
|
||||
delete li;
|
||||
}
|
||||
l->addWidget(sp);
|
||||
for (auto SectionWidget : SectionWidgets)
|
||||
{
|
||||
sp->insertWidget(0, SectionWidget);
|
||||
}
|
||||
}
|
||||
else if ((FloatingMainSplitter->orientation() == orientation) &&
|
||||
(OldSplitter->count() == 1 || OldSplitter->orientation() == orientation))
|
||||
{
|
||||
OldSplitter->setOrientation(orientation);
|
||||
std::cout << "Splitter with right orientation" << std::endl;
|
||||
// we have a splitter with only one item or with the right orientation so
|
||||
// we can make it match the orientation of the floating splitter
|
||||
for (int i = 0; i < SectionWidgets.count(); ++i)
|
||||
{
|
||||
if (append)
|
||||
{
|
||||
OldSplitter->addWidget(SectionWidgets[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
OldSplitter->insertWidget(i, SectionWidgets[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Splitter with wrong orientation" << std::endl;
|
||||
// we have a splitter but with the wrong orientation
|
||||
QSplitter* sp = MainContainerWidget::newSplitter(orientation);
|
||||
if (append)
|
||||
{
|
||||
QLayoutItem* li = l->replaceWidget(OldSplitter, sp);
|
||||
sp->addWidget(OldSplitter);
|
||||
sp->addWidget(FloatingMainSplitter);
|
||||
delete li;
|
||||
}
|
||||
else
|
||||
{
|
||||
sp->addWidget(FloatingMainSplitter);
|
||||
QLayoutItem* li = l->replaceWidget(OldSplitter, sp);
|
||||
sp->addWidget(OldSplitter);
|
||||
delete li;
|
||||
}
|
||||
}
|
||||
|
||||
FloatingWidget->deleteLater();
|
||||
dropContent(data, nullptr, area, true);
|
||||
}
|
||||
|
||||
|
||||
void CContainerWidget::dropIntoSection(FloatingWidget* FloatingWidget,
|
||||
SectionWidget* targetSection, DropArea area)
|
||||
{
|
||||
CContainerWidget* FloatingContainer = FloatingWidget->containerWidget();
|
||||
QSplitter* FloatingMainSplitter = FloatingContainer->findChild<QSplitter*>(QString(),
|
||||
Qt::FindDirectChildrenOnly); QSplitter* OldSplitter = this->findChild<QSplitter*>(QString(), Qt::FindDirectChildrenOnly);
|
||||
QList<SectionWidget*> SectionWidgets;
|
||||
for (int i = 0; i < FloatingMainSplitter->count(); ++i)
|
||||
{
|
||||
SectionWidgets.append(static_cast<SectionWidget*>(FloatingMainSplitter->widget(i)));
|
||||
}
|
||||
|
||||
switch (area)
|
||||
{
|
||||
/*case TopDropArea:return insertNewSectionWidget(data, targetSectionWidget, section_widget, Qt::Vertical, 0);
|
||||
case RightDropArea: return insertNewSectionWidget(data, targetSectionWidget, section_widget, Qt::Horizontal, 1);
|
||||
case BottomDropArea: return insertNewSectionWidget(data, targetSectionWidget, section_widget, Qt::Vertical, 1);
|
||||
case LeftDropArea: return insertNewSectionWidget(data, targetSectionWidget, section_widget, Qt::Horizontal, 0);*/
|
||||
case CenterDropArea:
|
||||
for (auto SectionWidget : SectionWidgets)
|
||||
{
|
||||
//sp->insertWidget(0, SectionWidget);
|
||||
//targetSectionWidget->addContent(data, autoActive);
|
||||
// targetSection->add
|
||||
}
|
||||
return;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
/*QSplitter* targetSectionSplitter = findParentSplitter(targetSection);
|
||||
SectionWidget* sw = newSectionWidget();
|
||||
sw->addContent(data, true);
|
||||
if (targetSectionSplitter->orientation() == Orientation)
|
||||
{
|
||||
const int index = targetSectionSplitter->indexOf(targetSection);
|
||||
targetSectionSplitter->insertWidget(index + InsertIndexOffset, sw);
|
||||
}
|
||||
else
|
||||
{
|
||||
const int index = targetSectionSplitter->indexOf(targetSection);
|
||||
QSplitter* s = MainContainerWidget::newSplitter(Orientation);
|
||||
s->addWidget(sw);
|
||||
s->addWidget(targetSection);
|
||||
targetSectionSplitter->insertWidget(index, s);
|
||||
}
|
||||
ret = sw;
|
||||
return ret;*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
SectionWidget* CContainerWidget::sectionWidgetAt(const QPoint& pos) const
|
||||
{
|
||||
for (const auto& SectionWidget : m_Sections)
|
||||
|
@ -67,20 +67,6 @@ MainContainerWidget::~MainContainerWidget()
|
||||
}
|
||||
|
||||
|
||||
SectionWidget* MainContainerWidget::addSectionContent(const SectionContent::RefPtr& sc, SectionWidget* sw, DropArea area)
|
||||
{
|
||||
ADS_Expects(!sc.isNull());
|
||||
|
||||
// Drop it based on "area"
|
||||
InternalContentData data;
|
||||
data.content = sc;
|
||||
data.titleWidget = new SectionTitleWidget(sc, NULL);
|
||||
data.contentWidget = new SectionContentWidget(sc, NULL);
|
||||
|
||||
connect(data.titleWidget, SIGNAL(activeTabChanged()), this, SLOT(onActiveTabChanged()));
|
||||
return dropContent(data, sw, area, false);
|
||||
}
|
||||
|
||||
bool MainContainerWidget::removeSectionContent(const SectionContent::RefPtr& sc)
|
||||
{
|
||||
ADS_Expects(!sc.isNull());
|
||||
|
@ -16,6 +16,8 @@
|
||||
#include <QtGlobal>
|
||||
#include <QTabBar>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#if defined(ADS_ANIMATIONS_ENABLED)
|
||||
#include <QGraphicsDropShadowEffect>
|
||||
#endif
|
||||
@ -111,6 +113,8 @@ SectionWidget::~SectionWidget()
|
||||
{
|
||||
splitter->deleteLater();
|
||||
}
|
||||
|
||||
std::cout << "SectionWidget::~SectionWidget()" << std::endl;
|
||||
}
|
||||
|
||||
int SectionWidget::uid() const
|
||||
@ -422,11 +426,7 @@ SectionWidgetTabsScrollArea::~SectionWidgetTabsScrollArea()
|
||||
void SectionWidgetTabsScrollArea::wheelEvent(QWheelEvent* e)
|
||||
{
|
||||
e->accept();
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
||||
const int direction = e->angleDelta().y();
|
||||
#else
|
||||
const int direction = e->delta();
|
||||
#endif
|
||||
if (direction < 0)
|
||||
horizontalScrollBar()->setValue(horizontalScrollBar()->value() + 20);
|
||||
else
|
||||
|
@ -123,6 +123,7 @@ void MainWindow::createContent()
|
||||
sw = _container->addSectionContent(createLongTextLabelSC(cw), nullptr, ADS_NS::CenterDropArea);
|
||||
sw = _container->addSectionContent(createCalendarSC(cw), nullptr, ADS_NS::LeftDropArea);
|
||||
sw = _container->addSectionContent(createFileSystemTreeSC(cw), nullptr, ADS_NS::BottomDropArea);
|
||||
sw = _container->addSectionContent(createCalendarSC(cw), nullptr, ADS_NS::BottomDropArea);
|
||||
|
||||
/*_container->addSectionContent(createCalendarSC(_container));
|
||||
_container->addSectionContent(createLongTextLabelSC(_container));
|
||||
|
Loading…
Reference in New Issue
Block a user