mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2025-01-26 14:29:02 +08:00
Fixed container removal from MainCOntainerWidget
This commit is contained in:
parent
a4de5c5560
commit
2bf1a51627
@ -80,6 +80,8 @@ protected:
|
|||||||
virtual void changeEvent(QEvent *event) override;
|
virtual void changeEvent(QEvent *event) override;
|
||||||
virtual void moveEvent(QMoveEvent *event) override;
|
virtual void moveEvent(QMoveEvent *event) override;
|
||||||
virtual bool event(QEvent *e);
|
virtual bool event(QEvent *e);
|
||||||
|
void titleMouseReleaseEvent();
|
||||||
|
virtual bool eventFilter(QObject *watched, QEvent *event) override;
|
||||||
void updateDropOverlays(const QPoint& GlobalPos);
|
void updateDropOverlays(const QPoint& GlobalPos);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
@ -91,6 +93,7 @@ private:
|
|||||||
SectionTitleWidget* _titleWidget;
|
SectionTitleWidget* _titleWidget;
|
||||||
SectionContentWidget* _contentWidget;
|
SectionContentWidget* _contentWidget;
|
||||||
CContainerWidget* m_ContainerWidget;
|
CContainerWidget* m_ContainerWidget;
|
||||||
|
CContainerWidget* m_DropContainer;
|
||||||
bool m_DraggingActive = false;
|
bool m_DraggingActive = false;
|
||||||
unsigned int m_zOrderIndex = 0;
|
unsigned int m_zOrderIndex = 0;
|
||||||
static unsigned int zOrderCounter;
|
static unsigned int zOrderCounter;
|
||||||
|
@ -40,6 +40,7 @@ class ADS_EXPORT_API MainContainerWidget : public CContainerWidget
|
|||||||
friend class SectionTitleWidget;
|
friend class SectionTitleWidget;
|
||||||
friend class ContainerWidgetPrivate;
|
friend class ContainerWidgetPrivate;
|
||||||
friend class CFloatingTitleWidget;
|
friend class CFloatingTitleWidget;
|
||||||
|
friend class CContainerWidget;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MainContainerWidget(QWidget *parent = nullptr);
|
explicit MainContainerWidget(QWidget *parent = nullptr);
|
||||||
@ -151,7 +152,6 @@ private:
|
|||||||
FloatingWidget* startFloating(SectionWidget* sectionwidget, int ContentUid, const QPoint& TargetPos);
|
FloatingWidget* startFloating(SectionWidget* sectionwidget, int ContentUid, const QPoint& TargetPos);
|
||||||
void hideContainerOverlay();
|
void hideContainerOverlay();
|
||||||
void moveFloatingWidget(const QPoint& TargetPos);
|
void moveFloatingWidget(const QPoint& TargetPos);
|
||||||
void dropFloatingWidget(FloatingWidget* FloatingWidget, const QPoint& TargetPos);
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onActiveTabChanged();
|
void onActiveTabChanged();
|
||||||
@ -175,7 +175,6 @@ signals:
|
|||||||
void sectionContentVisibilityChanged(const SectionContent::RefPtr& sc, bool visible);
|
void sectionContentVisibilityChanged(const SectionContent::RefPtr& sc, bool visible);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<SectionWidget*> m_Sections;
|
|
||||||
QList<FloatingWidget*> m_Floatings;
|
QList<FloatingWidget*> m_Floatings;
|
||||||
QList<CContainerWidget*> m_Containers;
|
QList<CContainerWidget*> m_Containers;
|
||||||
QHash<int, HiddenSectionItem> m_HiddenSectionContents;
|
QHash<int, HiddenSectionItem> m_HiddenSectionContents;
|
||||||
@ -189,5 +188,6 @@ private:
|
|||||||
QPointer<DropOverlay> m_SectionDropOverlay;
|
QPointer<DropOverlay> m_SectionDropOverlay;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
ADS_NAMESPACE_END
|
ADS_NAMESPACE_END
|
||||||
#endif
|
#endif
|
||||||
|
@ -52,6 +52,7 @@ CContainerWidget::CContainerWidget(MainContainerWidget* MainContainer, QWidget *
|
|||||||
CContainerWidget::~CContainerWidget()
|
CContainerWidget::~CContainerWidget()
|
||||||
{
|
{
|
||||||
std::cout << "CContainerWidget::~CContainerWidget()" << std::endl;
|
std::cout << "CContainerWidget::~CContainerWidget()" << std::endl;
|
||||||
|
m_MainContainerWidget->m_Containers.removeAll(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -79,38 +80,34 @@ unsigned int CContainerWidget::zOrderIndex() const
|
|||||||
void CContainerWidget::dropFloatingWidget(FloatingWidget* FloatingWidget,
|
void CContainerWidget::dropFloatingWidget(FloatingWidget* FloatingWidget,
|
||||||
const QPoint& TargetPos)
|
const QPoint& TargetPos)
|
||||||
{
|
{
|
||||||
if (!FloatingWidget->isDraggingActive())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QPoint MousePos = mapFromGlobal(TargetPos);
|
QPoint MousePos = mapFromGlobal(TargetPos);
|
||||||
SectionWidget* sectionWidget = sectionWidgetAt(MousePos);
|
SectionWidget* sectionWidget = sectionWidgetAt(MousePos);
|
||||||
DropArea dropArea = InvalidDropArea;
|
DropArea dropArea = InvalidDropArea;
|
||||||
if (sectionWidget)
|
if (sectionWidget)
|
||||||
{
|
{
|
||||||
//m_SectionDropOverlay->setAllowedAreas(ADS_NS::AllAreas);
|
auto dropOverlay = m_MainContainerWidget->sectionDropOverlay();
|
||||||
//dropArea = m_SectionDropOverlay->showDropOverlay(sectionWidget);
|
dropOverlay->setAllowedAreas(ADS_NS::AllAreas);
|
||||||
|
dropArea = dropOverlay->showDropOverlay(sectionWidget);
|
||||||
if (dropArea != InvalidDropArea)
|
if (dropArea != InvalidDropArea)
|
||||||
{
|
{
|
||||||
InternalContentData data;
|
InternalContentData data;
|
||||||
FloatingWidget->takeContent(data);
|
FloatingWidget->takeContent(data);
|
||||||
FloatingWidget->deleteLater();
|
FloatingWidget->deleteLater();
|
||||||
//dropContent(data, sectionWidget, dropArea, true);
|
dropContent(data, sectionWidget, dropArea, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// mouse is over container
|
// mouse is over container
|
||||||
if (InvalidDropArea == dropArea)
|
if (InvalidDropArea == dropArea)
|
||||||
{
|
{
|
||||||
//dropArea = m_ContainerDropOverlay->dropAreaUnderCursor();
|
dropArea = m_MainContainerWidget->dropOverlay()->dropAreaUnderCursor();
|
||||||
std::cout << "Cursor location: " << dropArea << std::endl;
|
std::cout << "Drop Content: " << dropArea << std::endl;
|
||||||
if (dropArea != InvalidDropArea)
|
if (dropArea != InvalidDropArea)
|
||||||
{
|
{
|
||||||
InternalContentData data;
|
InternalContentData data;
|
||||||
FloatingWidget->takeContent(data);
|
FloatingWidget->takeContent(data);
|
||||||
FloatingWidget->deleteLater();
|
FloatingWidget->deleteLater();
|
||||||
//dropContent(data, nullptr, dropArea, true);
|
dropContent(data, nullptr, dropArea, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -154,6 +154,7 @@ FloatingWidget::FloatingWidget(MainContainerWidget* container, SectionContent::R
|
|||||||
connect(TitleBar, SIGNAL(closeButtonClicked()), this, SLOT(onCloseButtonClicked()));*/
|
connect(TitleBar, SIGNAL(closeButtonClicked()), this, SLOT(onCloseButtonClicked()));*/
|
||||||
|
|
||||||
m_ContainerWidget = new CContainerWidget(m_MainContainerWidget, this);
|
m_ContainerWidget = new CContainerWidget(m_MainContainerWidget, this);
|
||||||
|
m_MainContainerWidget->m_Containers.append(m_ContainerWidget);
|
||||||
l->addWidget(m_ContainerWidget, 1);
|
l->addWidget(m_ContainerWidget, 1);
|
||||||
InternalContentData data;
|
InternalContentData data;
|
||||||
data.content = sc;
|
data.content = sc;
|
||||||
@ -163,6 +164,7 @@ FloatingWidget::FloatingWidget(MainContainerWidget* container, SectionContent::R
|
|||||||
m_ContainerWidget->show();
|
m_ContainerWidget->show();
|
||||||
|
|
||||||
m_zOrderIndex = ++zOrderCounter;
|
m_zOrderIndex = ++zOrderCounter;
|
||||||
|
container->m_Floatings.append(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -180,8 +182,8 @@ FloatingWidget::FloatingWidget(SectionWidget* sectionWidget)
|
|||||||
|
|
||||||
FloatingWidget::~FloatingWidget()
|
FloatingWidget::~FloatingWidget()
|
||||||
{
|
{
|
||||||
// maybe we can implement this this via connection to destroyed signal
|
std::cout << "FloatingWidget::~FloatingWidget" << std::endl;
|
||||||
m_MainContainerWidget->m_Floatings.removeAll(this); // Note: I don't like this here, but we have to remove it from list...
|
m_MainContainerWidget->m_Floatings.removeAll(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FloatingWidget::takeContent(InternalContentData& data)
|
bool FloatingWidget::takeContent(InternalContentData& data)
|
||||||
@ -246,22 +248,51 @@ bool FloatingWidget::event(QEvent *e)
|
|||||||
if (QGuiApplication::mouseButtons() == Qt::LeftButton)
|
if (QGuiApplication::mouseButtons() == Qt::LeftButton)
|
||||||
{
|
{
|
||||||
m_DraggingActive = true;
|
m_DraggingActive = true;
|
||||||
|
qApp->installEventFilter(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ((e->type() == QEvent::NonClientAreaMouseButtonRelease) && m_DraggingActive)
|
else if ((e->type() == QEvent::NonClientAreaMouseButtonRelease) && m_DraggingActive)
|
||||||
{
|
{
|
||||||
m_DraggingActive = false;
|
titleMouseReleaseEvent();
|
||||||
std::cout << "Dropped" << std::endl;
|
|
||||||
}
|
}
|
||||||
else if (e->type() == QEvent::WindowActivate)
|
else if (e->type() == QEvent::WindowActivate)
|
||||||
{
|
{
|
||||||
m_DraggingActive = true;
|
m_DraggingActive = true;
|
||||||
|
qApp->installEventFilter(this);
|
||||||
std::cout << "QEvent::WindowActivate MouseButtons " << QGuiApplication::mouseButtons() << std::endl;
|
std::cout << "QEvent::WindowActivate MouseButtons " << QGuiApplication::mouseButtons() << std::endl;
|
||||||
}
|
}
|
||||||
return QWidget::event(e);
|
return QWidget::event(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool FloatingWidget::eventFilter(QObject *watched, QEvent *event)
|
||||||
|
{
|
||||||
|
if (event->type() == QEvent::MouseButtonRelease)
|
||||||
|
{
|
||||||
|
titleMouseReleaseEvent();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void FloatingWidget::titleMouseReleaseEvent()
|
||||||
|
{
|
||||||
|
qApp->removeEventFilter(this);
|
||||||
|
m_DraggingActive = false;
|
||||||
|
if (!m_DropContainer)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "Dropped" << std::endl;
|
||||||
|
MainContainerWidget* MainContainerWidget = mainContainerWidget();
|
||||||
|
//MainContainerWidget->dropFloatingWidget(this, QCursor::pos());
|
||||||
|
m_DropContainer->dropFloatingWidget(this, QCursor::pos());
|
||||||
|
MainContainerWidget->dropOverlay()->hideDropOverlay();
|
||||||
|
MainContainerWidget->sectionDropOverlay()->hideDropOverlay();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned int FloatingWidget::zOrderIndex() const
|
unsigned int FloatingWidget::zOrderIndex() const
|
||||||
{
|
{
|
||||||
return m_zOrderIndex;
|
return m_zOrderIndex;
|
||||||
@ -270,8 +301,6 @@ unsigned int FloatingWidget::zOrderIndex() const
|
|||||||
|
|
||||||
void FloatingWidget::updateDropOverlays(const QPoint& GlobalPos)
|
void FloatingWidget::updateDropOverlays(const QPoint& GlobalPos)
|
||||||
{
|
{
|
||||||
// TODO make a member with the main container widget and assign it on
|
|
||||||
// creation
|
|
||||||
MainContainerWidget* MainContainerWidget = mainContainerWidget();
|
MainContainerWidget* MainContainerWidget = mainContainerWidget();
|
||||||
auto Containers = MainContainerWidget->m_Containers;
|
auto Containers = MainContainerWidget->m_Containers;
|
||||||
CContainerWidget* TopContainer = nullptr;
|
CContainerWidget* TopContainer = nullptr;
|
||||||
@ -298,6 +327,7 @@ void FloatingWidget::updateDropOverlays(const QPoint& GlobalPos)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_DropContainer = TopContainer;
|
||||||
if (TopContainer)
|
if (TopContainer)
|
||||||
{
|
{
|
||||||
MainContainerWidget->dropOverlay()->showDropOverlay(TopContainer);
|
MainContainerWidget->dropOverlay()->showDropOverlay(TopContainer);
|
||||||
|
@ -1074,8 +1074,6 @@ FloatingWidget* MainContainerWidget::startFloating(SectionWidget* sectionwidget,
|
|||||||
|
|
||||||
FloatingWidget* fw = new FloatingWidget(this, data.content, data.titleWidget, data.contentWidget, this);
|
FloatingWidget* fw = new FloatingWidget(this, data.content, data.titleWidget, data.contentWidget, this);
|
||||||
fw->resize(sectionwidget->size());
|
fw->resize(sectionwidget->size());
|
||||||
m_Floatings.append(fw);
|
|
||||||
m_Containers.append(fw->containerWidget());
|
|
||||||
fw->move(TargetPos);
|
fw->move(TargetPos);
|
||||||
fw->show();
|
fw->show();
|
||||||
fw->setObjectName("FloatingWidget");
|
fw->setObjectName("FloatingWidget");
|
||||||
@ -1133,44 +1131,4 @@ void MainContainerWidget::moveFloatingWidget(const QPoint& TargetPos)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MainContainerWidget::dropFloatingWidget(FloatingWidget* FloatingWidget,
|
|
||||||
const QPoint& TargetPos)
|
|
||||||
{
|
|
||||||
if (!FloatingWidget->isDraggingActive())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QPoint MousePos = mapFromGlobal(TargetPos);
|
|
||||||
SectionWidget* sectionWidget = sectionWidgetAt(MousePos);
|
|
||||||
DropArea dropArea = InvalidDropArea;
|
|
||||||
if (sectionWidget)
|
|
||||||
{
|
|
||||||
m_SectionDropOverlay->setAllowedAreas(ADS_NS::AllAreas);
|
|
||||||
dropArea = m_SectionDropOverlay->showDropOverlay(sectionWidget);
|
|
||||||
if (dropArea != InvalidDropArea)
|
|
||||||
{
|
|
||||||
InternalContentData data;
|
|
||||||
FloatingWidget->takeContent(data);
|
|
||||||
FloatingWidget->deleteLater();
|
|
||||||
dropContent(data, sectionWidget, dropArea, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// mouse is over container
|
|
||||||
if (InvalidDropArea == dropArea)
|
|
||||||
{
|
|
||||||
dropArea = m_ContainerDropOverlay->dropAreaUnderCursor();
|
|
||||||
std::cout << "Cursor location: " << dropArea << std::endl;
|
|
||||||
if (dropArea != InvalidDropArea)
|
|
||||||
{
|
|
||||||
InternalContentData data;
|
|
||||||
FloatingWidget->takeContent(data);
|
|
||||||
FloatingWidget->deleteLater();
|
|
||||||
dropContent(data, nullptr, dropArea, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ADS_NAMESPACE_END
|
ADS_NAMESPACE_END
|
||||||
|
Loading…
Reference in New Issue
Block a user