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