diff --git a/AdvancedDockingSystem/include/ads/ContainerWidget.h b/AdvancedDockingSystem/include/ads/ContainerWidget.h index 00ddde9..65e2413 100644 --- a/AdvancedDockingSystem/include/ads/ContainerWidget.h +++ b/AdvancedDockingSystem/include/ads/ContainerWidget.h @@ -43,7 +43,6 @@ public: explicit CContainerWidget(MainContainerWidget* MainContainerWidget, QWidget *parent = nullptr); virtual ~CContainerWidget(); - void moveFloatingWidget(const QPoint& TargetPos); /** * Returns the current zOrderIndex */ @@ -52,7 +51,7 @@ public: void dropFloatingWidget(FloatingWidget* FloatingWidget, const QPoint& TargetPos); - SectionWidget* sectionWidgetAt(const QPoint& pos) const; + SectionWidget* sectionWidgetAt(const QPoint& GlobalPos) const; /** * This function returns true if this container widgets z order index is @@ -70,7 +69,18 @@ public: */ SectionWidget* addSectionContent(const SectionContent::RefPtr& sc, SectionWidget* sw = NULL, DropArea area = CenterDropArea); + void dumpLayout(); + +signals: + /*! + * Emits whenever the "isActiveTab" state of a SectionContent changes. + * Whenever the users sets another tab as active, this signal gets invoked + * for the old tab and the new active tab (the order is unspecified). + */ + void activeTabChanged(const SectionContent::RefPtr& sc, bool active); + protected: + void dropIntoContainer(FloatingWidget* FloatingWidget, DropArea area); virtual bool event(QEvent *e) override; SectionWidget* newSectionWidget(); void addSectionWidget(SectionWidget* section); @@ -88,6 +98,9 @@ protected: MainContainerWidget* m_MainContainerWidget = 0; unsigned int m_zOrderIndex = 0; static unsigned int zOrderCounter; + +private slots: + void onActiveTabChanged(); }; } // namespace ads diff --git a/AdvancedDockingSystem/include/ads/FloatingWidget.h b/AdvancedDockingSystem/include/ads/FloatingWidget.h index 0dc7a6e..b23a433 100644 --- a/AdvancedDockingSystem/include/ads/FloatingWidget.h +++ b/AdvancedDockingSystem/include/ads/FloatingWidget.h @@ -76,6 +76,8 @@ public: public://private: bool takeContent(InternalContentData& data); + void startFloating(const QPoint& Pos); + protected: virtual void changeEvent(QEvent *event) override; virtual void moveEvent(QMoveEvent *event) override; @@ -95,7 +97,10 @@ private: CContainerWidget* m_ContainerWidget; CContainerWidget* m_DropContainer; bool m_DraggingActive = false; + bool m_NonCLientDraggingActive = false; unsigned int m_zOrderIndex = 0; + QPoint m_DragStartPosition; + QPoint m_DragStartMousePosition; static unsigned int zOrderCounter; }; diff --git a/AdvancedDockingSystem/include/ads/MainContainerWidget.h b/AdvancedDockingSystem/include/ads/MainContainerWidget.h index c50e057..d51f54d 100644 --- a/AdvancedDockingSystem/include/ads/MainContainerWidget.h +++ b/AdvancedDockingSystem/include/ads/MainContainerWidget.h @@ -125,18 +125,7 @@ public: static QSplitter* newSplitter(Qt::Orientation orientation = Qt::Horizontal, QWidget* parent = 0); - /** - * Filters the events of the floating widgets - */ - virtual bool event(QEvent *e) override; - private: - // - // Internal Stuff Begins Here - // - SectionWidget* dropContent(const InternalContentData& data, SectionWidget* targetSection, DropArea area, bool autoActive = true); - SectionWidget* sectionWidgetAt(const QPoint& pos) const; - // Serialization QByteArray saveHierarchy() const; void saveFloatingWidgets(QDataStream& out) const; @@ -149,24 +138,15 @@ private: bool restoreSectionWidgets(QDataStream& in, int version, QSplitter* currentSplitter, QList& sections, QList& contentsToHide); bool takeContent(const SectionContent::RefPtr& sc, InternalContentData& data); - FloatingWidget* startFloating(SectionWidget* sectionwidget, int ContentUid, const QPoint& TargetPos); void hideContainerOverlay(); void moveFloatingWidget(const QPoint& TargetPos); private slots: - void onActiveTabChanged(); void onActionToggleSectionContentVisibility(bool visible); signals: void orientationChanged(); - /*! - * Emits whenever the "isActiveTab" state of a SectionContent changes. - * Whenever the users sets another tab as active, this signal gets invoked - * for the old tab and the new active tab (the order is unspecified). - */ - void activeTabChanged(const SectionContent::RefPtr& sc, bool active); - /*! * Emits whenever the visibility of a SectionContent changes. * \see showSectionContent(), hideSectionContent() diff --git a/AdvancedDockingSystem/include/ads/SectionTitleWidget.h b/AdvancedDockingSystem/include/ads/SectionTitleWidget.h index 08b7861..f37d2b7 100644 --- a/AdvancedDockingSystem/include/ads/SectionTitleWidget.h +++ b/AdvancedDockingSystem/include/ads/SectionTitleWidget.h @@ -22,11 +22,14 @@ class SectionTitleWidget : public QFrame friend class MainContainerWidget; friend class SectionWidget; + friend class CContainerWidget; SectionContent::RefPtr m_Content; // Drag & Drop (Floating) QPointer m_FloatingWidget; + QPoint m_DragStartMousePosition; + QPoint m_DragStartGlobalMousePosition; QPoint m_DragStartPosition; // Drag & Drop (Title/Tabs) @@ -48,6 +51,8 @@ public: */ bool isDraggingFloatingWidget() const; + virtual bool event(QEvent *e); + protected: virtual void mousePressEvent(QMouseEvent* ev); virtual void mouseReleaseEvent(QMouseEvent* ev); diff --git a/AdvancedDockingSystem/src/ContainerWidget.cpp b/AdvancedDockingSystem/src/ContainerWidget.cpp index b802eba..c4a705e 100644 --- a/AdvancedDockingSystem/src/ContainerWidget.cpp +++ b/AdvancedDockingSystem/src/ContainerWidget.cpp @@ -80,8 +80,7 @@ unsigned int CContainerWidget::zOrderIndex() const void CContainerWidget::dropFloatingWidget(FloatingWidget* FloatingWidget, const QPoint& TargetPos) { - QPoint MousePos = mapFromGlobal(TargetPos); - SectionWidget* sectionWidget = sectionWidgetAt(MousePos); + SectionWidget* sectionWidget = sectionWidgetAt(TargetPos); DropArea dropArea = InvalidDropArea; if (sectionWidget) { @@ -90,6 +89,7 @@ void CContainerWidget::dropFloatingWidget(FloatingWidget* FloatingWidget, dropArea = dropOverlay->showDropOverlay(sectionWidget); if (dropArea != InvalidDropArea) { + std::cout << "Section Drop Content: " << dropArea << std::endl; InternalContentData data; FloatingWidget->takeContent(data); FloatingWidget->deleteLater(); @@ -101,29 +101,34 @@ void CContainerWidget::dropFloatingWidget(FloatingWidget* FloatingWidget, if (InvalidDropArea == dropArea) { dropArea = m_MainContainerWidget->dropOverlay()->dropAreaUnderCursor(); - std::cout << "Drop Content: " << dropArea << std::endl; + std::cout << "Container Drop Content: " << dropArea << std::endl; if (dropArea != InvalidDropArea) { - InternalContentData data; - FloatingWidget->takeContent(data); - FloatingWidget->deleteLater(); - dropContent(data, nullptr, dropArea, true); + dropIntoContainer(FloatingWidget, dropArea); } } } +void CContainerWidget::dropIntoContainer(FloatingWidget* FloatingWidget, DropArea area) +{ + InternalContentData data; + FloatingWidget->takeContent(data); + FloatingWidget->deleteLater(); + dropContent(data, nullptr, area, true); +} + + SectionWidget* CContainerWidget::sectionWidgetAt(const QPoint& pos) const { - const QPoint gpos = mapToGlobal(pos); - for (int i = 0; i < m_Sections.size(); ++i) + for (const auto& SectionWidget : m_Sections) { - SectionWidget* sw = m_Sections[i]; - if (sw->rect().contains(sw->mapFromGlobal(gpos))) + if (SectionWidget->rect().contains(SectionWidget->mapFromGlobal(pos))) { - return sw; + return SectionWidget; } } + return 0; } @@ -290,9 +295,49 @@ SectionWidget* CContainerWidget::addSectionContent(const SectionContent::RefPtr& data.titleWidget = new SectionTitleWidget(sc, NULL); data.contentWidget = new SectionContentWidget(sc, NULL); - //connect(data.titleWidget, SIGNAL(activeTabChanged()), this, SLOT(onActiveTabChanged())); + connect(data.titleWidget, SIGNAL(activeTabChanged()), this, SLOT(onActiveTabChanged())); return dropContent(data, sw, area, false); } + + +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::onActiveTabChanged() +{ + SectionTitleWidget* stw = qobject_cast(sender()); + if (stw) + { + emit activeTabChanged(stw->m_Content, stw->isActiveTab()); + } +} } // namespace ads //--------------------------------------------------------------------------- diff --git a/AdvancedDockingSystem/src/FloatingWidget.cpp b/AdvancedDockingSystem/src/FloatingWidget.cpp index e2bce0d..3c3eab6 100644 --- a/AdvancedDockingSystem/src/FloatingWidget.cpp +++ b/AdvancedDockingSystem/src/FloatingWidget.cpp @@ -219,6 +219,7 @@ void FloatingWidget::changeEvent(QEvent *event) QWidget::changeEvent(event); if (event->type() != QEvent::ActivationChange) { + std::cout << "FloatingWidget::changeEvent QEvent::ActivationChange " << std::endl; return; } @@ -242,25 +243,21 @@ void FloatingWidget::moveEvent(QMoveEvent *event) bool FloatingWidget::event(QEvent *e) { - //std::cout << "FloatingWidget::event " << e->type() << std::endl; if ((e->type() == QEvent::NonClientAreaMouseButtonPress)) { if (QGuiApplication::mouseButtons() == Qt::LeftButton) { + std::cout << "FloatingWidget::event Event::NonClientAreaMouseButtonPress" << e->type() << std::endl; m_DraggingActive = true; - qApp->installEventFilter(this); + 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) { + std::cout << "FloatingWidget::event QEvent::NonClientAreaMouseButtonRelease" << e->type() << 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); } @@ -271,10 +268,33 @@ bool FloatingWidget::eventFilter(QObject *watched, QEvent *event) { titleMouseReleaseEvent(); } + else if (event->type() == QEvent::MouseMove) + { + if (m_DraggingActive) + { + QMouseEvent* MouseEvent = dynamic_cast(event); + int BorderSize = (frameSize().width() - size().width()) / 2; + const QPoint moveToPos = QCursor::pos() - m_DragStartMousePosition - QPoint(BorderSize, 0); + move(moveToPos); + return true; + } + } return false; } +void FloatingWidget::startFloating(const QPoint& Pos) +{ + qApp->installEventFilter(this); + QPoint TargetPos = QCursor::pos() - Pos; + move(TargetPos); + show(); + m_DraggingActive = true; + m_DragStartMousePosition = Pos; + m_DragStartPosition = this->pos(); +} + + void FloatingWidget::titleMouseReleaseEvent() { qApp->removeEventFilter(this); @@ -286,7 +306,6 @@ void FloatingWidget::titleMouseReleaseEvent() 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(); @@ -328,6 +347,31 @@ void FloatingWidget::updateDropOverlays(const QPoint& GlobalPos) } m_DropContainer = TopContainer; + DropOverlay* ContainerDropOverlay = MainContainerWidget->dropOverlay(); + DropOverlay* SectionDropOverlay = MainContainerWidget->sectionDropOverlay(); + + if (!TopContainer) + { + ContainerDropOverlay->hideDropOverlay(); + SectionDropOverlay->hideDropOverlay(); + return; + } + + ContainerDropOverlay->showDropOverlay(TopContainer); + ContainerDropOverlay->raise(); + + SectionWidget* sectionwidget = TopContainer->sectionWidgetAt(GlobalPos); + if (sectionwidget) + { + SectionDropOverlay->setAllowedAreas(ADS_NS::AllAreas); + SectionDropOverlay->showDropOverlay(sectionwidget); + } + else + { + SectionDropOverlay->hideDropOverlay(); + } + + if (TopContainer) { MainContainerWidget->dropOverlay()->showDropOverlay(TopContainer); diff --git a/AdvancedDockingSystem/src/MainContainerWidget.cpp b/AdvancedDockingSystem/src/MainContainerWidget.cpp index 27c99e3..96ea1c8 100644 --- a/AdvancedDockingSystem/src/MainContainerWidget.cpp +++ b/AdvancedDockingSystem/src/MainContainerWidget.cpp @@ -435,70 +435,6 @@ QPointer MainContainerWidget::dropOverlay() const // PRIVATE API BEGINS HERE /////////////////////////////////////////////////////////////////////// -SectionWidget* MainContainerWidget::dropContent(const InternalContentData& data, SectionWidget* targetSectionWidget, DropArea area, bool autoActive) -{ - ADS_Expects(targetSection != NULL); - - SectionWidget* section_widget = nullptr; - - // If no sections exists yet, create a default one and always drop into it. - if (m_Sections.isEmpty()) - { - targetSectionWidget = newSectionWidget(); - addSectionWidget(targetSectionWidget); - area = CenterDropArea; - } - - // Drop on outer area - if (!targetSectionWidget) - { - switch (area) - { - case TopDropArea:return dropContentOuterHelper(m_MainLayout, data, Qt::Vertical, false); - case RightDropArea: return dropContentOuterHelper(m_MainLayout, data, Qt::Horizontal, true); - case CenterDropArea: - case BottomDropArea:return dropContentOuterHelper(m_MainLayout, data, Qt::Vertical, true); - case LeftDropArea: return dropContentOuterHelper(m_MainLayout, data, Qt::Horizontal, false); - default: - return nullptr; - } - return section_widget; - } - - // Drop logic based on area. - 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 CenterDropArea: - targetSectionWidget->addContent(data, autoActive); - return targetSectionWidget; - - default: - break; - } - return section_widget; -} - - -SectionWidget* MainContainerWidget::sectionWidgetAt(const QPoint& pos) const -{ - const QPoint gpos = mapToGlobal(pos); - for (int i = 0; i < m_Sections.size(); ++i) - { - SectionWidget* sw = m_Sections[i]; - if (sw->rect().contains(sw->mapFromGlobal(gpos))) - { - return sw; - } - } - return 0; -} - - - QByteArray MainContainerWidget::saveHierarchy() const { /* @@ -1028,14 +964,6 @@ bool MainContainerWidget::takeContent(const SectionContent::RefPtr& sc, Internal return found; } -void MainContainerWidget::onActiveTabChanged() -{ - SectionTitleWidget* stw = qobject_cast(sender()); - if (stw) - { - emit activeTabChanged(stw->m_Content, stw->isActiveTab()); - } -} void MainContainerWidget::onActionToggleSectionContentVisibility(bool visible) { @@ -1062,43 +990,6 @@ void MainContainerWidget::hideContainerOverlay() } -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->move(TargetPos); - fw->show(); - fw->setObjectName("FloatingWidget"); - - // 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; -} - - -bool MainContainerWidget::event(QEvent *e) -{ - //std::cout << "ContainerWidget::event " << e->type() << std::endl; - return QFrame::event(e); -} - void MainContainerWidget::moveFloatingWidget(const QPoint& TargetPos) { QPoint MousePos = mapFromGlobal(QCursor::pos()); diff --git a/AdvancedDockingSystem/src/SectionTitleWidget.cpp b/AdvancedDockingSystem/src/SectionTitleWidget.cpp index 75b1c91..a93015c 100644 --- a/AdvancedDockingSystem/src/SectionTitleWidget.cpp +++ b/AdvancedDockingSystem/src/SectionTitleWidget.cpp @@ -11,6 +11,8 @@ #include #include +#include + #ifdef ADS_ANIMATIONS_ENABLED #include #include @@ -70,7 +72,9 @@ void SectionTitleWidget::mousePressEvent(QMouseEvent* ev) if (ev->button() == Qt::LeftButton) { ev->accept(); - m_DragStartPosition = ev->pos(); + m_DragStartMousePosition = ev->pos(); + m_DragStartGlobalMousePosition = ev->globalPos(); + m_DragStartPosition = mapToGlobal(this->pos()); return; } QFrame::mousePressEvent(ev); @@ -80,13 +84,11 @@ void SectionTitleWidget::mouseReleaseEvent(QMouseEvent* ev) { SectionWidget* section = nullptr; MainContainerWidget* cw = findParentContainerWidget(this); + std::cout << "SectionTitleWidget::mouseReleaseEvent" << std::endl; - if (isDraggingFloatingWidget() && cw->rect().contains(cw->mapFromGlobal(ev->globalPos()))) - { - cw->dropFloatingWidget(m_FloatingWidget, ev->globalPos()); - } + m_FloatingWidget.clear(); // End of tab moving, change order now - else if (m_TabMoving && (section = findParentSectionWidget(this)) != nullptr) + if (m_TabMoving && (section = findParentSectionWidget(this)) != nullptr) { // Find tab under mouse QPoint pos = ev->globalPos(); @@ -101,13 +103,13 @@ void SectionTitleWidget::mouseReleaseEvent(QMouseEvent* ev) section->moveContent(fromIndex, toIndex); } - if (!m_DragStartPosition.isNull()) + if (!m_DragStartMousePosition.isNull()) { emit clicked(); } // Reset - m_DragStartPosition = QPoint(); + m_DragStartMousePosition = QPoint(); m_TabMoving = false; cw->m_SectionDropOverlay->hideDropOverlay(); cw->hideContainerOverlay(); @@ -117,26 +119,84 @@ void SectionTitleWidget::mouseReleaseEvent(QMouseEvent* ev) void SectionTitleWidget::moveFloatingWidget(QMouseEvent* ev, MainContainerWidget* cw) { - const QPoint moveToPos = ev->globalPos() - (m_DragStartPosition + QPoint(ADS_WINDOW_FRAME_BORDER_WIDTH, ADS_WINDOW_FRAME_BORDER_WIDTH)); - m_FloatingWidget->move(moveToPos); - // cw->moveFloatingWidget(moveToPos); + 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) { - QPoint moveToPos = ev->globalPos() - (m_DragStartPosition + QPoint(ADS_WINDOW_FRAME_BORDER_WIDTH, ADS_WINDOW_FRAME_BORDER_WIDTH)); - m_FloatingWidget = cw->startFloating(sectionwidget, m_Content->uid(), moveToPos); + std::cout << "SectionTitleWidget::startFloating" << std::endl; + QPoint moveToPos = ev->globalPos() - m_DragStartMousePosition; + + 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); + + DropOverlay* ContainerDropOverlay = cw->dropOverlay(); + ContainerDropOverlay->setAllowedAreas(OuterAreas); + ContainerDropOverlay->showDropOverlay(this); + 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) { ev->accept(); int left, top, right, bottom; getContentsMargins(&left, &top, &right, &bottom); - QPoint moveToPos = mapToParent(ev->pos()) - m_DragStartPosition; + QPoint moveToPos = mapToParent(ev->pos()) - m_DragStartMousePosition; moveToPos.setY(0/* + top*/); move(moveToPos); } @@ -144,62 +204,28 @@ void SectionTitleWidget::moveTab(QMouseEvent* ev) bool SectionTitleWidget::isDraggingFloatingWidget() const { - return m_FloatingWidget != nullptr; + return !m_FloatingWidget.isNull(); } void SectionTitleWidget::mouseMoveEvent(QMouseEvent* ev) { + std::cout << "SectionTitleWidget::mouseMoveEvent" << std::endl; if (!(ev->buttons() & Qt::LeftButton)) { QFrame::mouseMoveEvent(ev); return; } - QPoint Pos = QCursor::pos(); // TODO make a member with the main container widget and assign it on // creation MainContainerWidget* MainContainerWidget = findParentContainerWidget(this); - auto Containers = MainContainerWidget->m_Containers; - CContainerWidget* TopContainer = nullptr; - for (auto ContainerWidget : Containers) - { - if (!ContainerWidget->isVisible()) - { - continue; - } - - if (!m_FloatingWidget || (m_FloatingWidget->containerWidget() == ContainerWidget)) - { - continue; - } - - QPoint MappedPos = ContainerWidget->mapFromGlobal(Pos); - if (ContainerWidget->rect().contains(MappedPos)) - { - std::cout << "Container " << ContainerWidget << " contains maousepos" << std::endl; - if (!TopContainer || ContainerWidget->isInFrontOf(TopContainer)) - { - TopContainer = ContainerWidget; - } - } - } - - if (TopContainer) - { - MainContainerWidget->dropOverlay()->showDropOverlay(TopContainer); - MainContainerWidget->dropOverlay()->raise(); - } - else - { - MainContainerWidget->dropOverlay()->hideDropOverlay(); - } - ev->accept(); // Move already existing FloatingWidget if (isDraggingFloatingWidget()) { - moveFloatingWidget(ev, MainContainerWidget); + std::cout << "SectionTitleWidget isDraggingFloatingWidget()" << std::endl; + //moveFloatingWidget(ev, MainContainerWidget); return; } @@ -218,7 +244,7 @@ void SectionTitleWidget::mouseMoveEvent(QMouseEvent* ev) } // leave if dragging is not active - if (m_DragStartPosition.isNull()) + if (m_DragStartMousePosition.isNull()) { QFrame::mouseMoveEvent(ev); return; @@ -231,7 +257,7 @@ void SectionTitleWidget::mouseMoveEvent(QMouseEvent* ev) return; } // Begin to drag title inside the title area to switch its position inside the SectionWidget. - else if ((ev->pos() - m_DragStartPosition).manhattanLength() >= QApplication::startDragDistance() // Wait a few pixels before start moving + else if ((ev->pos() - m_DragStartMousePosition).manhattanLength() >= QApplication::startDragDistance() // Wait a few pixels before start moving && sectionwidget->titleAreaGeometry().contains(sectionwidget->mapFromGlobal(ev->globalPos()))) { m_TabMoving = true; @@ -241,4 +267,10 @@ void SectionTitleWidget::mouseMoveEvent(QMouseEvent* ev) QFrame::mouseMoveEvent(ev); } + +bool SectionTitleWidget::event(QEvent *e) +{ + return QFrame::event(e); +} + ADS_NAMESPACE_END diff --git a/AdvancedDockingSystem/src/SectionWidget.cpp b/AdvancedDockingSystem/src/SectionWidget.cpp index 216a291..a65b76a 100644 --- a/AdvancedDockingSystem/src/SectionWidget.cpp +++ b/AdvancedDockingSystem/src/SectionWidget.cpp @@ -206,14 +206,8 @@ bool SectionWidget::takeContent(int uid, InternalContentData& data) if (title) { _tabsLayout->removeWidget(title); -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - title->setAttribute(Qt::WA_WState_Created, false); /* fix: floating rubberband #16 */ -#endif title->disconnect(this); title->setParent(m_MainContainerWidget); -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - title->setAttribute(Qt::WA_WState_Created, true); /* fix: floating rubberband #16 */ -#endif } // Content wrapper widget (CONTENT) @@ -388,11 +382,7 @@ void SectionWidget::updateTabsMenu() const SectionContent::RefPtr& sc = _contents.at(i); QAction* a = m->addAction(QIcon(), sc->visibleTitle()); a->setData(sc->uid()); -#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) - QObject::connect(a, &QAction::triggered, this, &SectionWidget::onTabsMenuActionTriggered); -#else QObject::connect(a, SIGNAL(triggered(bool)), this, SLOT(onTabsMenuActionTriggered(bool))); -#endif } QMenu* old = _tabsMenuButton->menu(); _tabsMenuButton->setMenu(m); diff --git a/AdvancedDockingSystemDemo/src/mainwindow.cpp b/AdvancedDockingSystemDemo/src/mainwindow.cpp index 3b99ef4..ac9801d 100644 --- a/AdvancedDockingSystemDemo/src/mainwindow.cpp +++ b/AdvancedDockingSystemDemo/src/mainwindow.cpp @@ -104,6 +104,7 @@ MainWindow::MainWindow(QWidget *parent) : // ADS - Restore geometries and states of contents. //_container->restoreState(loadDataHelper("ContainerWidget")); + _container->dumpLayout(); } MainWindow::~MainWindow()