Started implementing support for docking multiple sections into section

This commit is contained in:
Uwe Kindler 2017-02-20 07:36:27 +01:00
parent b93d2fbd48
commit 70a7a7b352
9 changed files with 99 additions and 74 deletions

View File

@ -46,7 +46,7 @@ public:
/**
* Returns the current zOrderIndex
*/
unsigned int zOrderIndex() const;
virtual unsigned int zOrderIndex() const;
void dropFloatingWidget(FloatingWidget* FloatingWidget,
const QPoint& TargetPos);

View File

@ -57,8 +57,6 @@ public:
FloatingWidget(MainContainerWidget* container, SectionWidget* sectionWidget);
virtual ~FloatingWidget();
SectionContent::RefPtr content() const { return _content; }
/**
* Returns the current zOrderIndex
*/
@ -87,9 +85,6 @@ private:
void setDraggingActive(bool Active);
MainContainerWidget* m_MainContainerWidget;
SectionContent::RefPtr _content;
//SectionTitleWidget* _titleWidget;
//SectionContentWidget* _contentWidget;
CContainerWidget* m_ContainerWidget;
CContainerWidget* m_DropContainer;
bool m_DraggingActive = false;

View File

@ -117,6 +117,8 @@ public:
static QSplitter* newSplitter(Qt::Orientation orientation = Qt::Horizontal, QWidget* parent = 0);
virtual unsigned int zOrderIndex() const {return 0;}
private:
// Serialization
QByteArray saveHierarchy() const;

View File

@ -186,7 +186,7 @@ void CContainerWidget::dropIntoContainer(FloatingWidget* FloatingWidget, DropAre
sp->addWidget(SectionWidget);
}
}
else if ((FloatingMainSplitter->orientation() == orientation) &&
else if ((FloatingMainSplitter->orientation() == orientation || FloatingMainSplitter->count() == 1) &&
(OldSplitter->count() == 1 || OldSplitter->orientation() == orientation))
{
OldSplitter->setOrientation(orientation);
@ -236,19 +236,22 @@ void CContainerWidget::dropIntoSection(FloatingWidget* FloatingWidget,
{
CContainerWidget* FloatingContainer = FloatingWidget->containerWidget();
QSplitter* FloatingMainSplitter = FloatingContainer->findChild<QSplitter*>(QString(),
Qt::FindDirectChildrenOnly); QSplitter* OldSplitter = this->findChild<QSplitter*>(QString(), Qt::FindDirectChildrenOnly);
Qt::FindDirectChildrenOnly);
QList<SectionWidget*> SectionWidgets;
for (int i = 0; i < FloatingMainSplitter->count(); ++i)
{
SectionWidgets.append(static_cast<SectionWidget*>(FloatingMainSplitter->widget(i)));
}
Qt::Orientation Orientation;
int InsertIndexOffset;
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 TopDropArea: Orientation = Qt::Vertical; InsertIndexOffset = 0;break;
case RightDropArea: Orientation = Qt::Horizontal; InsertIndexOffset = 1;break;
case BottomDropArea: Orientation = Qt::Vertical; InsertIndexOffset = 1;break;
case LeftDropArea: Orientation = Qt::Horizontal; InsertIndexOffset = 0;break;
case CenterDropArea:
{
QList<SectionWidget*> SectionWidgets = FloatingContainer->findChildren<SectionWidget*>(QString(), Qt::FindChildrenRecursively);
@ -274,6 +277,48 @@ void CContainerWidget::dropIntoSection(FloatingWidget* FloatingWidget,
break;
}
QSplitter* targetSectionSplitter = findParentSplitter(targetSection);
std::cout << "target->orientaton " << targetSectionSplitter->orientation()
<< " orien " << Orientation << std::endl;
int index = targetSectionSplitter->indexOf(targetSection);
if (targetSectionSplitter->orientation() == Orientation)
{
std::cout << "targetSectionSplitter->orientation() == Orientation" << std::endl;
if (FloatingMainSplitter->orientation() == Orientation || FloatingMainSplitter->count() == 1)
{
std::cout << "FloatingMainSplitter->orientation() == Orientation || FloatingMainSplitter->count() == 1" << std::endl;
for (int i = 0; i < SectionWidgets.count(); ++i)
{
targetSectionSplitter->insertWidget(index + InsertIndexOffset, SectionWidgets[i]);
}
}
else
{
targetSectionSplitter->insertWidget(index + InsertIndexOffset, FloatingMainSplitter);
}
}
else
{
std::cout << "targetSectionSplitter->orientation() != Orientation" << std::endl;
QSplitter* s = MainContainerWidget::newSplitter(Orientation);
if (FloatingMainSplitter->orientation() == Orientation || FloatingMainSplitter->count() == 1)
{
std::cout << "FloatingMainSplitter->orientation() == Orientation || FloatingMainSplitter->count() == 1" << std::endl;
for (int i = 0; i < SectionWidgets.count(); ++i)
{
s->addWidget(SectionWidgets[i]);
}
}
else
{
s->addWidget(FloatingMainSplitter);
}
s->addWidget(targetSection);
targetSectionSplitter->insertWidget(index, s);
}
FloatingWidget->deleteLater();
/* InternalContentData data;
if (!sectionwidget->takeContent(m_Content->uid(), data))
{
@ -335,7 +380,7 @@ SectionWidget* CContainerWidget::sectionWidgetAt(const QPoint& pos) const
bool CContainerWidget::isInFrontOf(CContainerWidget* Other) const
{
return this->m_zOrderIndex > Other->m_zOrderIndex;
return this->zOrderIndex() > Other->zOrderIndex();
}
SectionWidget* CContainerWidget::dropContent(const InternalContentData& data, SectionWidget* targetSectionWidget, DropArea area, bool autoActive)
@ -396,6 +441,7 @@ SectionWidget* CContainerWidget::newSectionWidget()
void CContainerWidget::addSectionWidget(SectionWidget* section)
{
ADS_Expects(section != NULL);
if (section->containerWidget())
{
section->containerWidget()->takeSection(section);

View File

@ -171,8 +171,6 @@ DropArea DropOverlay::showDropOverlay(QWidget* target)
return da;
}
//hideDropOverlay();
//std::cout << "_target != target, hideDropOverlay(), _fullAreaDrop = false" << std::endl;
_target = target;
_targetRect = QRect();
_lastLocation = InvalidDropArea;

View File

@ -138,8 +138,7 @@ void CFloatingTitleWidget::onMaximizeButtonClicked()
FloatingWidget::FloatingWidget(MainContainerWidget* MainContainer, SectionContent::RefPtr sc, SectionTitleWidget* titleWidget, SectionContentWidget* contentWidget, QWidget* parent) :
QWidget(MainContainer, Qt::Window),
m_MainContainerWidget(MainContainer),
_content(sc)
m_MainContainerWidget(MainContainer)
{
QBoxLayout* l = new QBoxLayout(QBoxLayout::TopToBottom);
l->setContentsMargins(0, 0, 0, 0);
@ -207,7 +206,7 @@ bool FloatingWidget::takeContent(InternalContentData& data)
void FloatingWidget::onCloseButtonClicked()
{
m_MainContainerWidget->hideSectionContent(_content);
//m_MainContainerWidget->hideSectionContent(_content);
}
@ -336,6 +335,10 @@ unsigned int FloatingWidget::zOrderIndex() const
void FloatingWidget::updateDropOverlays(const QPoint& GlobalPos)
{
if (!isVisible())
{
return;
}
MainContainerWidget* MainContainerWidget = mainContainerWidget();
auto Containers = MainContainerWidget->m_Containers;
CContainerWidget* TopContainer = nullptr;
@ -390,12 +393,12 @@ void FloatingWidget::updateDropOverlays(const QPoint& GlobalPos)
if (TopContainer)
{
MainContainerWidget->dropOverlay()->showDropOverlay(TopContainer);
MainContainerWidget->dropOverlay()->raise();
ContainerDropOverlay->showDropOverlay(TopContainer);
ContainerDropOverlay->raise();
}
else
{
MainContainerWidget->dropOverlay()->hideDropOverlay();
ContainerDropOverlay->hideDropOverlay();
}
}

View File

@ -36,8 +36,8 @@ QSplitter* MainContainerWidget::newSplitter(Qt::Orientation orientation, QWidget
MainContainerWidget::MainContainerWidget(QWidget *parent) :
CContainerWidget(this, parent)
{
m_SectionDropOverlay = new DropOverlay(0, DropOverlay::ModeSectionOverlay);
m_ContainerDropOverlay = new DropOverlay(0, DropOverlay::ModeContainerOverlay);
m_SectionDropOverlay = new DropOverlay(this, DropOverlay::ModeSectionOverlay);
m_ContainerDropOverlay = new DropOverlay(this, DropOverlay::ModeContainerOverlay);
m_ContainerDropOverlay->setAttribute(Qt::WA_TransparentForMouseEvents);
m_ContainerDropOverlay->setWindowFlags(m_ContainerDropOverlay->windowFlags() | Qt::WindowTransparentForInput);
m_Containers.append(this);
@ -118,12 +118,12 @@ bool MainContainerWidget::showSectionContent(const SectionContent::RefPtr& sc)
for (int i = 0; i < m_Floatings.count(); ++i)
{
FloatingWidget* fw = m_Floatings.at(i);
const bool found = fw->content()->uid() == sc->uid();
/*const bool found = fw->content()->uid() == sc->uid();
if (!found)
continue;
continue;*/
fw->setVisible(true);
fw->_titleWidget->setVisible(true);
fw->_contentWidget->setVisible(true);
//fw->_titleWidget->setVisible(true);
//fw->_contentWidget->setVisible(true);
emit sectionContentVisibilityChanged(sc, true);
return true;
}
@ -173,9 +173,9 @@ bool MainContainerWidget::hideSectionContent(const SectionContent::RefPtr& sc)
// We can simply hide floatings, nothing else required.
for (int i = 0; i < m_Floatings.count(); ++i)
{
const bool found = m_Floatings.at(i)->content()->uid() == sc->uid();
/*const bool found = m_Floatings.at(i)->content()->uid() == sc->uid();
if (!found)
continue;
continue;*/
m_Floatings.at(i)->setVisible(false);
emit sectionContentVisibilityChanged(sc, false);
return true;
@ -240,8 +240,8 @@ bool MainContainerWidget::raiseSectionContent(const SectionContent::RefPtr& sc)
for (int i = 0; i < m_Floatings.size(); ++i)
{
FloatingWidget* fw = m_Floatings.at(i);
if (fw->content()->uid() != sc->uid())
continue;
/*if (fw->content()->uid() != sc->uid())
continue;*/
fw->setVisible(true);
fw->raise();
return true;
@ -262,9 +262,9 @@ bool MainContainerWidget::isSectionContentVisible(const SectionContent::RefPtr&
// Search SC in floatings
for (int i = 0; i < m_Floatings.count(); ++i)
{
const bool found = m_Floatings.at(i)->content()->uid() == sc->uid();
/*const bool found = m_Floatings.at(i)->content()->uid() == sc->uid();
if (!found)
continue;
continue;*/
return m_Floatings.at(i)->isVisible();
}
@ -330,7 +330,7 @@ QMenu* MainContainerWidget::createContextMenu() const
// Floating contents
for (int i = 0; i < m_Floatings.size(); ++i)
{
const FloatingWidget* fw = m_Floatings.at(i);
/*const FloatingWidget* fw = m_Floatings.at(i);
const SectionContent::RefPtr sc = fw->content();
QAction* a = new QAction(QIcon(), sc->visibleTitle(), NULL);
@ -340,7 +340,7 @@ QMenu* MainContainerWidget::createContextMenu() const
a->setCheckable(true);
a->setChecked(fw->isVisible());
connect(a, SIGNAL(toggled(bool)), this, SLOT(onActionToggleSectionContentVisibility(bool)));
actions.insert(a->text(), a);
actions.insert(a->text(), a);*/
}
// Create menu from "actions"
@ -512,7 +512,7 @@ void MainContainerWidget::saveFloatingWidgets(QDataStream& out) const
for (int i = 0; i < m_Floatings.count(); ++i)
{
FloatingWidget* fw = m_Floatings.at(i);
out << fw->content()->uniqueName();
/*out << fw->content()->uniqueName();*/
out << fw->saveGeometry();
out << fw->isVisible();
}
@ -714,8 +714,8 @@ bool MainContainerWidget::restoreHierarchy(const QByteArray& data)
// Collect all contents which has been restored
QList<SectionContent::RefPtr> contents;
for (int i = 0; i < floatings.count(); ++i)
contents.append(floatings.at(i)->content());
/*for (int i = 0; i < floatings.count(); ++i)
contents.append(floatings.at(i)->content());*/
for (int i = 0; i < sections.count(); ++i)
for (int j = 0; j < sections.at(i)->contents().count(); ++j)
contents.append(sections.at(i)->contents().at(j));
@ -811,8 +811,8 @@ bool MainContainerWidget::restoreFloatingWidgets(QDataStream& in, int version, Q
fw->setVisible(visible);
if (visible)
{
fw->_titleWidget->setVisible(visible);
fw->_contentWidget->setVisible(visible);
//fw->_titleWidget->setVisible(visible);
//fw->_contentWidget->setVisible(visible);
}
floatings.append(fw);
//data.titleWidget->m_FloatingWidget = fw; // $mfreiholz: Don't look at it :-< It's more than ugly...
@ -932,9 +932,9 @@ bool MainContainerWidget::takeContent(const SectionContent::RefPtr& sc, Internal
// Search in floating widgets
for (int i = 0; i < m_Floatings.count() && !found; ++i)
{
found = m_Floatings.at(i)->content()->uid() == sc->uid();
/*found = m_Floatings.at(i)->content()->uid() == sc->uid();
if (found)
m_Floatings.at(i)->takeContent(data);
m_Floatings.at(i)->takeContent(data);*/
}
// Search in hidden items

View File

@ -184,36 +184,6 @@ void SectionTitleWidget::startFloating(QMouseEvent* ev, MainContainerWidget* cw,
ContainerDropOverlay->raise();
}
/*
FloatingWidget* MainContainerWidget::startFloating(SectionWidget* sectionwidget, int ContentUid, const QPoint& TargetPos)
{
// Create floating widget.
InternalContentData data;
if (!sectionwidget->takeContent(ContentUid, data))
{
qWarning() << "THIS SHOULD NOT HAPPEN!!" << ContentUid;
return 0;
}
FloatingWidget* fw = new FloatingWidget(this, data.content, data.titleWidget, data.contentWidget, this);
fw->resize(sectionwidget->size());
fw->setObjectName("FloatingWidget");
fw->startFloating(TargetPos);
// Delete old section, if it is empty now.
if (sectionwidget->contents().isEmpty())
{
delete sectionwidget;
sectionwidget = NULL;
}
deleteEmptySplitter(this);
m_ContainerDropOverlay->setAllowedAreas(OuterAreas);
m_ContainerDropOverlay->showDropOverlay(this);
m_ContainerDropOverlay->raise();
return fw;
}*/
void SectionTitleWidget::moveTab(QMouseEvent* ev)
{
@ -272,7 +242,7 @@ void SectionTitleWidget::mouseMoveEvent(QMouseEvent* ev)
&& sectionwidget->titleAreaGeometry().contains(sectionwidget->mapFromGlobal(ev->globalPos())))
{
m_TabMoving = true;
raise(); // Raise current title-widget above other tabs
//raise(); // Raise current title-widget above other tabs
return;
}
QFrame::mouseMoveEvent(ev);

View File

@ -123,7 +123,18 @@ int SectionWidget::uid() const
CContainerWidget* SectionWidget::containerWidget() const
{
return dynamic_cast<CContainerWidget*>(parent());
QWidget* Parent = parentWidget();
while (Parent)
{
CContainerWidget* Container = dynamic_cast<CContainerWidget*>(Parent);
if (Container)
{
return Container;
}
Parent = Parent->parentWidget();
}
return 0;
}
QRect SectionWidget::titleAreaGeometry() const