diff --git a/AdvancedDockingSystem/include/ads/ContainerWidget.h b/AdvancedDockingSystem/include/ads/ContainerWidget.h index 65e2413..e17af94 100644 --- a/AdvancedDockingSystem/include/ads/ContainerWidget.h +++ b/AdvancedDockingSystem/include/ads/ContainerWidget.h @@ -99,6 +99,9 @@ protected: unsigned int m_zOrderIndex = 0; static unsigned int zOrderCounter; +private: + void dropChildSections(QWidget* Parent); + private slots: void onActiveTabChanged(); }; diff --git a/AdvancedDockingSystem/include/ads/FloatingWidget.h b/AdvancedDockingSystem/include/ads/FloatingWidget.h index b23a433..d4196e3 100644 --- a/AdvancedDockingSystem/include/ads/FloatingWidget.h +++ b/AdvancedDockingSystem/include/ads/FloatingWidget.h @@ -90,6 +90,8 @@ private slots: void onCloseButtonClicked(); private: + void setDraggingActive(bool Active); + MainContainerWidget* m_MainContainerWidget; SectionContent::RefPtr _content; SectionTitleWidget* _titleWidget; diff --git a/AdvancedDockingSystem/include/ads/SectionWidget.h b/AdvancedDockingSystem/include/ads/SectionWidget.h index 1dc0330..e13ecc0 100644 --- a/AdvancedDockingSystem/include/ads/SectionWidget.h +++ b/AdvancedDockingSystem/include/ads/SectionWidget.h @@ -41,7 +41,7 @@ public: QRect titleAreaGeometry() const; QRect contentAreaGeometry() const; - const QList& contents() const { return _contents; } + const QList& contents() const { return m_Contents; } void addContent(const SectionContent::RefPtr& c); void addContent(const InternalContentData& data, bool autoActivate); bool takeContent(int uid, InternalContentData& data); @@ -54,6 +54,8 @@ public: virtual bool eventFilter(QObject *watched, QEvent *event); + inline int contentCount() const {return m_ContentWidgets.size();} + protected: virtual void showEvent(QShowEvent*); @@ -72,9 +74,9 @@ private: QPointer m_ContainerWidget; QPointer m_MainContainerWidget; - QList _contents; - QList _sectionTitles; - QList _sectionContents; + QList m_Contents; + QList m_TitleWidgets; + QList m_ContentWidgets; QBoxLayout* _topLayout; QScrollArea* _tabsScrollArea; diff --git a/AdvancedDockingSystem/src/ContainerWidget.cpp b/AdvancedDockingSystem/src/ContainerWidget.cpp index c4a705e..f17887c 100644 --- a/AdvancedDockingSystem/src/ContainerWidget.cpp +++ b/AdvancedDockingSystem/src/ContainerWidget.cpp @@ -109,9 +109,60 @@ void CContainerWidget::dropFloatingWidget(FloatingWidget* FloatingWidget, } } +/*void dumpChildSplitters(QWidget* Widget) +{ + QSplitter* ParentSplitter = dynamic_cast(Widget); + auto Sections = Widget->findChildren(QString(), Qt::FindDirectChildrenOnly); + auto Splitters = Widget->findChildren(QString(), Qt::FindDirectChildrenOnly); + + std::cout << "-----------------------" << std::endl; + std::cout << "Sections " << Sections.size() << std::endl; + std::cout << "Splitters " << Splitters.size() << std::endl; + for (const auto& Splitter : Splitters) + { + if (ParentSplitter) + { + std::cout << "Orientation " << Splitter->orientation() << " index " << ParentSplitter->indexOf(Splitter) << std::endl; + } + else + { + std::cout << "Orientation " << Splitter->orientation() << std::endl; + } + dumpChildSplitters(Splitter); + } +} + + + +void CContainerWidget::dumpLayout() +{ + dumpChildSplitters(this); +}*/ + +void CContainerWidget::dropChildSections(QWidget* Parent) +{ + auto Sections = Parent->findChildren(QString(), Qt::FindDirectChildrenOnly); + auto Splitters = Parent->findChildren(QString(), Qt::FindDirectChildrenOnly); + + std::cout << "-----------------------" << std::endl; + std::cout << "Sections " << Sections.size() << std::endl; + std::cout << "Splitters " << Splitters.size() << std::endl; + + for (auto Section : Sections) + { + // drop section + } + + for (auto Splitter : Splitters) + { + dropChildSections(Splitter); + } +} + void CContainerWidget::dropIntoContainer(FloatingWidget* FloatingWidget, DropArea area) { + dropChildSections(FloatingWidget->containerWidget()); InternalContentData data; FloatingWidget->takeContent(data); FloatingWidget->deleteLater(); diff --git a/AdvancedDockingSystem/src/FloatingWidget.cpp b/AdvancedDockingSystem/src/FloatingWidget.cpp index 3c3eab6..a349e07 100644 --- a/AdvancedDockingSystem/src/FloatingWidget.cpp +++ b/AdvancedDockingSystem/src/FloatingWidget.cpp @@ -241,6 +241,27 @@ void FloatingWidget::moveEvent(QMoveEvent *event) } +void FloatingWidget::setDraggingActive(bool Active) +{ + if (m_DraggingActive == Active) + { + return; + } + + m_DraggingActive = Active; + if (Active) + { + std::cout << "FloatingWidget:: InstallEventFilter" << std::endl; + qApp->installEventFilter(this); + } + else + { + std::cout << "FloatingWidget:: RemoveEventFilter" << std::endl; + qApp->removeEventFilter(this); + } +} + + bool FloatingWidget::event(QEvent *e) { if ((e->type() == QEvent::NonClientAreaMouseButtonPress)) @@ -248,9 +269,8 @@ bool FloatingWidget::event(QEvent *e) if (QGuiApplication::mouseButtons() == Qt::LeftButton) { std::cout << "FloatingWidget::event Event::NonClientAreaMouseButtonPress" << e->type() << std::endl; - m_DraggingActive = true; + setDraggingActive(true); m_NonCLientDraggingActive = true; - qApp->installEventFilter(this); // install to remove mouse events if widget is behind drop overlay } } else if ((e->type() == QEvent::NonClientAreaMouseButtonRelease) && m_DraggingActive) @@ -285,11 +305,10 @@ bool FloatingWidget::eventFilter(QObject *watched, QEvent *event) void FloatingWidget::startFloating(const QPoint& Pos) { - qApp->installEventFilter(this); + setDraggingActive(true); QPoint TargetPos = QCursor::pos() - Pos; move(TargetPos); show(); - m_DraggingActive = true; m_DragStartMousePosition = Pos; m_DragStartPosition = this->pos(); } @@ -297,8 +316,8 @@ void FloatingWidget::startFloating(const QPoint& Pos) void FloatingWidget::titleMouseReleaseEvent() { - qApp->removeEventFilter(this); - m_DraggingActive = false; + setDraggingActive(false); + m_NonCLientDraggingActive = false; if (!m_DropContainer) { return; diff --git a/AdvancedDockingSystem/src/SectionWidget.cpp b/AdvancedDockingSystem/src/SectionWidget.cpp index a65b76a..931120e 100644 --- a/AdvancedDockingSystem/src/SectionWidget.cpp +++ b/AdvancedDockingSystem/src/SectionWidget.cpp @@ -135,19 +135,19 @@ QRect SectionWidget::contentAreaGeometry() const void SectionWidget::addContent(const SectionContent::RefPtr& c) { - _contents.append(c); + m_Contents.append(c); SectionTitleWidget* title = new SectionTitleWidget(c, NULL); - _sectionTitles.append(title); + m_TitleWidgets.append(title); _tabsLayout->insertWidget(_tabsLayout->count() - _tabsLayoutInitCount, title); QObject::connect(title, SIGNAL(clicked()), this, SLOT(onSectionTitleClicked())); SectionContentWidget* content = new SectionContentWidget(c, NULL); - _sectionContents.append(content); + m_ContentWidgets.append(content); _contentsLayout->addWidget(content); // Active first TAB. - if (_contents.size() == 1) + if (m_Contents.size() == 1) setCurrentIndex(0); // Switch to newest. // else @@ -158,26 +158,26 @@ void SectionWidget::addContent(const SectionContent::RefPtr& c) void SectionWidget::addContent(const InternalContentData& data, bool autoActivate) { - _contents.append(data.content); + m_Contents.append(data.content); // Add title-widget to tab-bar // #FIX: Make it visible, since it is possible that it was hidden previously. - _sectionTitles.append(data.titleWidget); + m_TitleWidgets.append(data.titleWidget); _tabsLayout->insertWidget(_tabsLayout->count() - _tabsLayoutInitCount, data.titleWidget); data.titleWidget->setVisible(true); QObject::connect(data.titleWidget, SIGNAL(clicked()), this, SLOT(onSectionTitleClicked())); // Add content-widget to stack. // Visibility is managed by QStackedWidget. - _sectionContents.append(data.contentWidget); + m_ContentWidgets.append(data.contentWidget); _contentsLayout->addWidget(data.contentWidget); // Activate first TAB. - if (_contents.size() == 1) + if (m_Contents.size() == 1) setCurrentIndex(0); // Switch to just added TAB. else if (autoActivate) - setCurrentIndex(_contents.count() - 1); + setCurrentIndex(m_Contents.count() - 1); // Mark it as inactive tab. else data.titleWidget->setActiveTab(false); // or: setCurrentIndex(currentIndex()) @@ -190,19 +190,19 @@ bool SectionWidget::takeContent(int uid, InternalContentData& data) // Find SectionContent. SectionContent::RefPtr sc; int index = -1; - for (int i = 0; i < _contents.count(); i++) + for (int i = 0; i < m_Contents.count(); i++) { - if (_contents[i]->uid() != uid) + if (m_Contents[i]->uid() != uid) continue; index = i; - sc = _contents.takeAt(i); + sc = m_Contents.takeAt(i); break; } if (!sc) return false; // Title wrapper widget (TAB) - SectionTitleWidget* title = _sectionTitles.takeAt(index); + SectionTitleWidget* title = m_TitleWidgets.takeAt(index); if (title) { _tabsLayout->removeWidget(title); @@ -211,7 +211,7 @@ bool SectionWidget::takeContent(int uid, InternalContentData& data) } // Content wrapper widget (CONTENT) - SectionContentWidget* content = _sectionContents.takeAt(index); + SectionContentWidget* content = m_ContentWidgets.takeAt(index); if (content) { _contentsLayout->removeWidget(content); @@ -220,7 +220,7 @@ bool SectionWidget::takeContent(int uid, InternalContentData& data) } // Select the previous tab as activeTab. - if (_contents.size() > 0 && title->isActiveTab()) + if (m_Contents.size() > 0 && title->isActiveTab()) { if (index > 0) setCurrentIndex(index - 1); @@ -238,14 +238,14 @@ bool SectionWidget::takeContent(int uid, InternalContentData& data) int SectionWidget::indexOfContent(const SectionContent::RefPtr& c) const { - return _contents.indexOf(c); + return m_Contents.indexOf(c); } int SectionWidget::indexOfContentByUid(int uid) const { - for (int i = 0; i < _contents.count(); ++i) + for (int i = 0; i < m_Contents.count(); ++i) { - if (_contents[i]->uid() == uid) + if (m_Contents[i]->uid() == uid) return i; } return -1; @@ -254,9 +254,9 @@ int SectionWidget::indexOfContentByUid(int uid) const int SectionWidget::indexOfContentByTitlePos(const QPoint& p, QWidget* exclude) const { int index = -1; - for (int i = 0; i < _sectionTitles.size(); ++i) + for (int i = 0; i < m_TitleWidgets.size(); ++i) { - if (_sectionTitles[i]->geometry().contains(p) && (exclude == NULL || _sectionTitles[i] != exclude)) + if (m_TitleWidgets[i]->geometry().contains(p) && (exclude == NULL || m_TitleWidgets[i] != exclude)) { index = i; break; @@ -272,16 +272,16 @@ int SectionWidget::currentIndex() const void SectionWidget::moveContent(int from, int to) { - if (from >= _contents.size() || from < 0 || to >= _contents.size() || to < 0 || from == to) + if (from >= m_Contents.size() || from < 0 || to >= m_Contents.size() || to < 0 || from == to) { qDebug() << "Invalid index for tab movement" << from << to; _tabsLayout->update(); return; } - _contents.move(from, to); - _sectionTitles.move(from, to); - _sectionContents.move(from, to); + m_Contents.move(from, to); + m_TitleWidgets.move(from, to); + m_ContentWidgets.move(from, to); QLayoutItem* liFrom = NULL; liFrom = _tabsLayout->takeAt(from); @@ -302,12 +302,12 @@ void SectionWidget::moveContent(int from, int to) void SectionWidget::showEvent(QShowEvent*) { - _tabsScrollArea->ensureWidgetVisible(_sectionTitles.at(currentIndex())); + _tabsScrollArea->ensureWidgetVisible(m_TitleWidgets.at(currentIndex())); } void SectionWidget::setCurrentIndex(int index) { - if (index < 0 || index > _contents.count() - 1) + if (index < 0 || index > m_Contents.count() - 1) { qWarning() << Q_FUNC_INFO << "Invalid index" << index; return; @@ -354,9 +354,9 @@ void SectionWidget::onSectionTitleClicked() void SectionWidget::onCloseButtonClicked() { const int index = currentIndex(); - if (index < 0 || index > _contents.size() - 1) + if (index < 0 || index > m_Contents.size() - 1) return; - SectionContent::RefPtr sc = _contents.at(index); + SectionContent::RefPtr sc = m_Contents.at(index); if (sc.isNull()) return; m_MainContainerWidget->hideSectionContent(sc); @@ -377,9 +377,9 @@ void SectionWidget::onTabsMenuActionTriggered(bool) void SectionWidget::updateTabsMenu() { QMenu* m = new QMenu(); - for (int i = 0; i < _contents.count(); ++i) + for (int i = 0; i < m_Contents.count(); ++i) { - const SectionContent::RefPtr& sc = _contents.at(i); + const SectionContent::RefPtr& sc = m_Contents.at(i); QAction* a = m->addAction(QIcon(), sc->visibleTitle()); a->setData(sc->uid()); QObject::connect(a, SIGNAL(triggered(bool)), this, SLOT(onTabsMenuActionTriggered(bool)));