From 938afb7357c968d9ff1d2f592fc98c15b982b80b Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Mon, 20 Feb 2017 23:57:32 +0100 Subject: [PATCH] Implemented support for dropping mutiple sections into sections --- AdvancedDockingSystem/src/API.cpp | 17 ++++--- AdvancedDockingSystem/src/ContainerWidget.cpp | 51 ++++--------------- .../src/SectionTitleWidget.cpp | 21 ++++++++ 3 files changed, 40 insertions(+), 49 deletions(-) diff --git a/AdvancedDockingSystem/src/API.cpp b/AdvancedDockingSystem/src/API.cpp index b804ab0..2b0593a 100644 --- a/AdvancedDockingSystem/src/API.cpp +++ b/AdvancedDockingSystem/src/API.cpp @@ -67,23 +67,24 @@ void deleteEmptySplitter(MainContainerWidget* container) } -QSplitter* findParentSplitter(class QWidget* w) +QSplitter* findParentSplitter(QWidget* w) { - QSplitter* cw = 0; - QWidget* next = w; + QSplitter* splitter = 0; + QWidget* parentWidget = w; do { - if ((cw = dynamic_cast(next)) != 0) + if ((splitter = dynamic_cast(parentWidget)) != 0) { break; } - next = next->parentWidget(); + parentWidget = parentWidget->parentWidget(); } - while (next); - return cw; + while (parentWidget); + return splitter; } -QSplitter* findImmediateSplitter(class QWidget* w) + +QSplitter* findImmediateSplitter(QWidget* w) { QLayout* l = w->layout(); if (!l || l->count() <= 0) diff --git a/AdvancedDockingSystem/src/ContainerWidget.cpp b/AdvancedDockingSystem/src/ContainerWidget.cpp index 70e0b1a..c5d11ba 100644 --- a/AdvancedDockingSystem/src/ContainerWidget.cpp +++ b/AdvancedDockingSystem/src/ContainerWidget.cpp @@ -293,6 +293,7 @@ void CContainerWidget::dropIntoSection(FloatingWidget* FloatingWidget, std::cout << "target->orientaton " << targetSectionSplitter->orientation() << " orien " << Orientation << std::endl; int index = targetSectionSplitter->indexOf(targetSection); + std::cout << "targetSectionSplitter->indexOf(targetSection) " << index << std::endl; if (targetSectionSplitter->orientation() == Orientation) { std::cout << "targetSectionSplitter->orientation() == Orientation" << std::endl; @@ -326,50 +327,18 @@ void CContainerWidget::dropIntoSection(FloatingWidget* FloatingWidget, s->addWidget(FloatingMainSplitter); } - s->addWidget(targetSection); + if (!InsertIndexOffset) + { + s->addWidget(targetSection); + } + else + { + s->insertWidget(0, targetSection); + } targetSectionSplitter->insertWidget(index, s); } FloatingWidget->deleteLater(); - - /* InternalContentData data; - if (!sectionwidget->takeContent(m_Content->uid(), data)) - { - qWarning() << "THIS SHOULD NOT HAPPEN!!" << m_Content->uid(); - return; - } - - FloatingWidget* fw = new FloatingWidget(cw, data.content, data.titleWidget, data.contentWidget, cw); - fw->resize(sectionwidget->size()); - fw->setObjectName("FloatingWidget"); - fw->startFloating(m_DragStartMousePosition); - - // Delete old section, if it is empty now. - if (sectionwidget->contents().isEmpty()) - { - delete sectionwidget; - sectionwidget = NULL; - } - deleteEmptySplitter(cw);*/ - - - /*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;*/ + m_Sections.append(SectionWidgets); } diff --git a/AdvancedDockingSystem/src/SectionTitleWidget.cpp b/AdvancedDockingSystem/src/SectionTitleWidget.cpp index 8af6f6c..d29f7e3 100644 --- a/AdvancedDockingSystem/src/SectionTitleWidget.cpp +++ b/AdvancedDockingSystem/src/SectionTitleWidget.cpp @@ -171,6 +171,7 @@ void SectionTitleWidget::startFloating(QMouseEvent* ev, MainContainerWidget* cw, FloatingWidget* fw; if (sectionwidget->contentCount() > 1) { + // If section widget has multiple tabs, we take only one tab InternalContentData data; if (!sectionwidget->takeContent(m_Content->uid(), data)) { @@ -181,7 +182,27 @@ void SectionTitleWidget::startFloating(QMouseEvent* ev, MainContainerWidget* cw, } else { + // If section widget has only one content widget, we can move the complete + // section widget into floating widget + QSplitter* splitter = findParentSplitter(sectionwidget); fw = new FloatingWidget(cw, sectionwidget); + if (splitter && splitter->count() == 1) + { + // if splitter contains only one section widget, then we can + // remove the splitter and replace it with the section widget + std::cout << "splitter->count() == 1" << std::endl; + SectionWidget* sectionwidget = dynamic_cast(splitter->widget(0)); + QSplitter* parentSplitter = dynamic_cast(splitter->parentWidget()); + if (parentSplitter) + { + sectionwidget->setParent(0); + int index = parentSplitter->indexOf(splitter); + splitter->setParent(0); + parentSplitter->insertWidget(index, sectionwidget); + delete splitter; + std::cout << "Index of splitter " << index << std::endl; + } + } } fw->resize(sectionwidget->size());