Implemented support for dropping mutiple sections into sections

This commit is contained in:
Uwe Kindler 2017-02-20 23:57:32 +01:00
parent 0edc1b4499
commit 938afb7357
3 changed files with 40 additions and 49 deletions

View File

@ -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<QSplitter*>(next)) != 0)
if ((splitter = dynamic_cast<QSplitter*>(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)

View File

@ -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);
}

View File

@ -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<SectionWidget*>(splitter->widget(0));
QSplitter* parentSplitter = dynamic_cast<QSplitter*>(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());