mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-11-15 13:15:43 +08:00
Some cleanup and support for dropping floating window with multiple setcion into section
This commit is contained in:
parent
635b96a2ae
commit
b93d2fbd48
@ -73,6 +73,10 @@ public:
|
||||
|
||||
MainContainerWidget* mainContainerWidget() const {return m_MainContainerWidget;}
|
||||
|
||||
void addSectionWidget(SectionWidget* section);
|
||||
|
||||
void takeSection(SectionWidget* Widget);
|
||||
|
||||
signals:
|
||||
/*!
|
||||
* Emits whenever the "isActiveTab" state of a SectionContent changes.
|
||||
@ -86,7 +90,6 @@ protected:
|
||||
void dropIntoSection(FloatingWidget* FloatingWidget, SectionWidget* targetSection, DropArea area);
|
||||
virtual bool event(QEvent *e) override;
|
||||
SectionWidget* newSectionWidget();
|
||||
void addSectionWidget(SectionWidget* section);
|
||||
SectionWidget* dropContentOuterHelper(QLayout* l, const InternalContentData& data, Qt::Orientation orientation, bool append);
|
||||
SectionWidget* insertNewSectionWidget(const InternalContentData& data,
|
||||
SectionWidget* targetSection, SectionWidget* ret, Qt::Orientation Orientation, int InsertIndexOffset);
|
||||
|
@ -54,7 +54,7 @@ class FloatingWidget : public QWidget
|
||||
|
||||
public:
|
||||
FloatingWidget(MainContainerWidget* container, SectionContent::RefPtr sc, SectionTitleWidget* titleWidget, SectionContentWidget* contentWidget, QWidget* parent = NULL);
|
||||
FloatingWidget(SectionWidget* sectionWidget);
|
||||
FloatingWidget(MainContainerWidget* container, SectionWidget* sectionWidget);
|
||||
virtual ~FloatingWidget();
|
||||
|
||||
SectionContent::RefPtr content() const { return _content; }
|
||||
@ -88,8 +88,8 @@ private:
|
||||
|
||||
MainContainerWidget* m_MainContainerWidget;
|
||||
SectionContent::RefPtr _content;
|
||||
SectionTitleWidget* _titleWidget;
|
||||
SectionContentWidget* _contentWidget;
|
||||
//SectionTitleWidget* _titleWidget;
|
||||
//SectionContentWidget* _contentWidget;
|
||||
CContainerWidget* m_ContainerWidget;
|
||||
CContainerWidget* m_DropContainer;
|
||||
bool m_DraggingActive = false;
|
||||
|
@ -50,7 +50,6 @@ protected:
|
||||
virtual void mouseMoveEvent(QMouseEvent* ev);
|
||||
|
||||
private:
|
||||
void moveFloatingWidget(QMouseEvent* ev, MainContainerWidget* cw);
|
||||
void startFloating(QMouseEvent* ev, MainContainerWidget* cw, SectionWidget* sectionwidget);
|
||||
void moveTab(QMouseEvent* ev);
|
||||
|
||||
|
@ -45,6 +45,7 @@ public:
|
||||
void addContent(const SectionContent::RefPtr& c);
|
||||
void addContent(const InternalContentData& data, bool autoActivate);
|
||||
bool takeContent(int uid, InternalContentData& data);
|
||||
bool takeContentAt(int Index, InternalContentData& data);
|
||||
int indexOfContent(const SectionContent::RefPtr& c) const;
|
||||
int indexOfContentByUid(int uid) const;
|
||||
int indexOfContentByTitlePos(const QPoint& pos, QWidget* exclude = NULL) const;
|
||||
@ -71,8 +72,6 @@ private slots:
|
||||
|
||||
private:
|
||||
const int _uid;
|
||||
|
||||
QPointer<CContainerWidget> m_ContainerWidget;
|
||||
QPointer<MainContainerWidget> m_MainContainerWidget;
|
||||
QList<SectionContent::RefPtr> m_Contents;
|
||||
QList<SectionTitleWidget*> m_TitleWidgets;
|
||||
|
@ -226,6 +226,7 @@ void CContainerWidget::dropIntoContainer(FloatingWidget* FloatingWidget, DropAre
|
||||
}
|
||||
}
|
||||
|
||||
m_Sections.append(SectionWidgets);
|
||||
FloatingWidget->deleteLater();
|
||||
}
|
||||
|
||||
@ -249,11 +250,23 @@ void CContainerWidget::dropIntoSection(FloatingWidget* FloatingWidget,
|
||||
case BottomDropArea: return insertNewSectionWidget(data, targetSectionWidget, section_widget, Qt::Vertical, 1);
|
||||
case LeftDropArea: return insertNewSectionWidget(data, targetSectionWidget, section_widget, Qt::Horizontal, 0);*/
|
||||
case CenterDropArea:
|
||||
{
|
||||
QList<SectionWidget*> SectionWidgets = FloatingContainer->findChildren<SectionWidget*>(QString(), Qt::FindChildrenRecursively);
|
||||
for (auto SectionWidget : SectionWidgets)
|
||||
{
|
||||
//sp->insertWidget(0, SectionWidget);
|
||||
//targetSectionWidget->addContent(data, autoActive);
|
||||
// targetSection->add
|
||||
std::cout << "dropping into section CenterDropArea " << SectionWidget->contentCount() << std::endl;
|
||||
while (SectionWidget->contentCount())
|
||||
{
|
||||
InternalContentData data;
|
||||
if (!SectionWidget->takeContentAt(0, data))
|
||||
{
|
||||
qWarning() << "THIS SHOULD NOT HAPPEN!! " << 0;
|
||||
return;
|
||||
}
|
||||
targetSection->addContent(data, false);
|
||||
}
|
||||
}
|
||||
FloatingWidget->deleteLater();
|
||||
}
|
||||
return;
|
||||
|
||||
@ -261,6 +274,27 @@ void CContainerWidget::dropIntoSection(FloatingWidget* FloatingWidget,
|
||||
break;
|
||||
}
|
||||
|
||||
/* 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);
|
||||
@ -285,6 +319,8 @@ void CContainerWidget::dropIntoSection(FloatingWidget* FloatingWidget,
|
||||
|
||||
SectionWidget* CContainerWidget::sectionWidgetAt(const QPoint& pos) const
|
||||
{
|
||||
std::cout << "CContainerWidget::sectionWidgetAt m_Sections count "
|
||||
<< m_Sections.count() << std::endl;
|
||||
for (const auto& SectionWidget : m_Sections)
|
||||
{
|
||||
if (SectionWidget->rect().contains(SectionWidget->mapFromGlobal(pos)))
|
||||
@ -360,6 +396,10 @@ SectionWidget* CContainerWidget::newSectionWidget()
|
||||
void CContainerWidget::addSectionWidget(SectionWidget* section)
|
||||
{
|
||||
ADS_Expects(section != NULL);
|
||||
if (section->containerWidget())
|
||||
{
|
||||
section->containerWidget()->takeSection(section);
|
||||
}
|
||||
|
||||
// Create default splitter.
|
||||
if (!m_Splitter)
|
||||
@ -373,6 +413,13 @@ void CContainerWidget::addSectionWidget(SectionWidget* section)
|
||||
return;
|
||||
}
|
||||
m_Splitter->addWidget(section);
|
||||
m_Sections.append(section);
|
||||
}
|
||||
|
||||
|
||||
void CContainerWidget::takeSection(SectionWidget* Widget)
|
||||
{
|
||||
m_Sections.removeAll(Widget);
|
||||
}
|
||||
|
||||
SectionWidget* CContainerWidget::dropContentOuterHelper(QLayout* l, const InternalContentData& data, Qt::Orientation orientation, bool append)
|
||||
|
@ -136,47 +136,48 @@ void CFloatingTitleWidget::onMaximizeButtonClicked()
|
||||
|
||||
|
||||
|
||||
FloatingWidget::FloatingWidget(MainContainerWidget* container, SectionContent::RefPtr sc, SectionTitleWidget* titleWidget, SectionContentWidget* contentWidget, QWidget* parent) :
|
||||
QWidget(0),
|
||||
m_MainContainerWidget(container),
|
||||
_content(sc),
|
||||
_titleWidget(titleWidget),
|
||||
_contentWidget(contentWidget)
|
||||
FloatingWidget::FloatingWidget(MainContainerWidget* MainContainer, SectionContent::RefPtr sc, SectionTitleWidget* titleWidget, SectionContentWidget* contentWidget, QWidget* parent) :
|
||||
QWidget(MainContainer, Qt::Window),
|
||||
m_MainContainerWidget(MainContainer),
|
||||
_content(sc)
|
||||
{
|
||||
QBoxLayout* l = new QBoxLayout(QBoxLayout::TopToBottom);
|
||||
l->setContentsMargins(0, 0, 0, 0);
|
||||
l->setSpacing(0);
|
||||
setLayout(l);
|
||||
|
||||
// Title + Controls
|
||||
/*CFloatingTitleWidget* TitleBar = new CFloatingTitleWidget(sc->flags(), this);
|
||||
l->insertWidget(0, TitleBar);
|
||||
connect(TitleBar, SIGNAL(closeButtonClicked()), this, SLOT(onCloseButtonClicked()));*/
|
||||
|
||||
m_ContainerWidget = new CContainerWidget(m_MainContainerWidget, this);
|
||||
m_MainContainerWidget->m_Containers.append(m_ContainerWidget);
|
||||
l->addWidget(m_ContainerWidget, 1);
|
||||
|
||||
InternalContentData data;
|
||||
data.content = sc;
|
||||
data.contentWidget = contentWidget;
|
||||
data.titleWidget = titleWidget;
|
||||
|
||||
m_ContainerWidget->dropContent(data, nullptr, CenterDropArea);
|
||||
m_ContainerWidget->show();
|
||||
|
||||
m_zOrderIndex = ++zOrderCounter;
|
||||
container->m_Floatings.append(this);
|
||||
m_MainContainerWidget->m_Floatings.append(this);
|
||||
}
|
||||
|
||||
|
||||
FloatingWidget::FloatingWidget(SectionWidget* sectionWidget)
|
||||
FloatingWidget::FloatingWidget(MainContainerWidget* MainContainer, SectionWidget* sectionWidget)
|
||||
: QWidget(MainContainer, Qt::Window),
|
||||
m_MainContainerWidget(MainContainer)
|
||||
{
|
||||
QBoxLayout* l = new QBoxLayout(QBoxLayout::TopToBottom);
|
||||
l->setContentsMargins(0, 0, 0, 0);
|
||||
l->setSpacing(0);
|
||||
setLayout(l);
|
||||
|
||||
l->addWidget(sectionWidget);
|
||||
m_ContainerWidget = new CContainerWidget(m_MainContainerWidget, this);
|
||||
m_MainContainerWidget->m_Containers.append(m_ContainerWidget);
|
||||
l->addWidget(m_ContainerWidget, 1);
|
||||
|
||||
m_ContainerWidget->addSectionWidget(sectionWidget);
|
||||
m_ContainerWidget->show();
|
||||
m_zOrderIndex = ++zOrderCounter;
|
||||
m_MainContainerWidget->m_Floatings.append(this);
|
||||
}
|
||||
|
||||
|
||||
@ -188,7 +189,8 @@ FloatingWidget::~FloatingWidget()
|
||||
|
||||
bool FloatingWidget::takeContent(InternalContentData& data)
|
||||
{
|
||||
data.content = _content;
|
||||
// TODO remove takeContent function
|
||||
/*data.content = _content;
|
||||
data.titleWidget = _titleWidget;
|
||||
data.contentWidget = _contentWidget;
|
||||
|
||||
@ -198,7 +200,7 @@ bool FloatingWidget::takeContent(InternalContentData& data)
|
||||
|
||||
layout()->removeWidget(_contentWidget);
|
||||
_contentWidget->setParent(m_MainContainerWidget);
|
||||
_contentWidget = NULL;
|
||||
_contentWidget = NULL;*/
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -146,31 +146,26 @@ void SectionTitleWidget::mouseReleaseEvent(QMouseEvent* ev)
|
||||
}
|
||||
|
||||
|
||||
void SectionTitleWidget::moveFloatingWidget(QMouseEvent* ev, MainContainerWidget* cw)
|
||||
{
|
||||
std::cout << "SectionTitleWidget::moveFloatingWidget" << std::endl;
|
||||
/*const QPoint DragDistance = ev->globalPos() - m_DragStartGlobalMousePosition;
|
||||
const QPoint moveToGlobalPos = m_DragStartPosition + DragDistance;
|
||||
m_FloatingWidget->move(moveToGlobalPos);*/
|
||||
|
||||
const QPoint moveToPos = ev->globalPos() - m_DragStartMousePosition;
|
||||
//m_FloatingWidget->move(moveToPos);
|
||||
}
|
||||
|
||||
|
||||
void SectionTitleWidget::startFloating(QMouseEvent* ev, MainContainerWidget* cw, SectionWidget* sectionwidget)
|
||||
{
|
||||
std::cout << "SectionTitleWidget::startFloating" << std::endl;
|
||||
QPoint moveToPos = ev->globalPos() - m_DragStartMousePosition;
|
||||
|
||||
FloatingWidget* fw;
|
||||
if (sectionwidget->contentCount() > 1)
|
||||
{
|
||||
InternalContentData data;
|
||||
if (!sectionwidget->takeContent(m_Content->uid(), data))
|
||||
{
|
||||
qWarning() << "THIS SHOULD NOT HAPPEN!!" << m_Content->uid();
|
||||
return;
|
||||
}
|
||||
fw = new FloatingWidget(cw, data.content, data.titleWidget, data.contentWidget, cw);
|
||||
}
|
||||
else
|
||||
{
|
||||
fw = new FloatingWidget(cw, sectionwidget);
|
||||
}
|
||||
|
||||
FloatingWidget* fw = new FloatingWidget(cw, data.content, data.titleWidget, data.contentWidget, cw);
|
||||
fw->resize(sectionwidget->size());
|
||||
fw->setObjectName("FloatingWidget");
|
||||
fw->startFloating(m_DragStartMousePosition);
|
||||
|
@ -35,7 +35,6 @@ ADS_NAMESPACE_BEGIN
|
||||
SectionWidget::SectionWidget(MainContainerWidget* MainContainer, CContainerWidget* parent) :
|
||||
QFrame(parent),
|
||||
_uid(GetNextUid()),
|
||||
m_ContainerWidget(parent),
|
||||
m_MainContainerWidget(MainContainer),
|
||||
_tabsLayout(NULL),
|
||||
_tabsLayoutInitCount(0),
|
||||
@ -124,7 +123,7 @@ int SectionWidget::uid() const
|
||||
|
||||
CContainerWidget* SectionWidget::containerWidget() const
|
||||
{
|
||||
return m_ContainerWidget;
|
||||
return dynamic_cast<CContainerWidget*>(parent());
|
||||
}
|
||||
|
||||
QRect SectionWidget::titleAreaGeometry() const
|
||||
@ -191,17 +190,21 @@ void SectionWidget::addContent(const InternalContentData& data, bool autoActivat
|
||||
|
||||
bool SectionWidget::takeContent(int uid, InternalContentData& data)
|
||||
{
|
||||
// Find SectionContent.
|
||||
SectionContent::RefPtr sc;
|
||||
int index = -1;
|
||||
for (int i = 0; i < m_Contents.count(); i++)
|
||||
{
|
||||
if (m_Contents[i]->uid() != uid)
|
||||
{
|
||||
continue;
|
||||
index = i;
|
||||
sc = m_Contents.takeAt(i);
|
||||
break;
|
||||
}
|
||||
return takeContentAt(i, data);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SectionWidget::takeContentAt(int index, InternalContentData& data)
|
||||
{
|
||||
SectionContent::RefPtr sc = m_Contents.takeAt(index);
|
||||
if (!sc)
|
||||
return false;
|
||||
|
||||
@ -240,6 +243,7 @@ bool SectionWidget::takeContent(int uid, InternalContentData& data)
|
||||
return !data.content.isNull();
|
||||
}
|
||||
|
||||
|
||||
int SectionWidget::indexOfContent(const SectionContent::RefPtr& c) const
|
||||
{
|
||||
return m_Contents.indexOf(c);
|
||||
@ -289,14 +293,7 @@ void SectionWidget::moveContent(int from, int to)
|
||||
|
||||
QLayoutItem* liFrom = NULL;
|
||||
liFrom = _tabsLayout->takeAt(from);
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
||||
_tabsLayout->insertItem(to, liFrom);
|
||||
#else
|
||||
_tabsLayout->insertWidget(to, liFrom->widget());
|
||||
delete liFrom;
|
||||
liFrom = NULL;
|
||||
#endif
|
||||
|
||||
liFrom = _contentsLayout->takeAt(from);
|
||||
_contentsLayout->insertWidget(to, liFrom->widget());
|
||||
delete liFrom;
|
||||
|
Loading…
Reference in New Issue
Block a user