From 239bd4781baf5b6dc26bf9ab7e291e3e40702f25 Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Mon, 13 Mar 2017 15:34:40 +0100 Subject: [PATCH] Added signals for dock area added and removed --- src/DockContainerWidget.cpp | 15 ++--- src/DockContainerWidget.h | 13 +++++ src/DockWidget.cpp | 103 +++++++++++++++++----------------- src/FloatingDockContainer.cpp | 35 ++++++++++++ src/FloatingDockContainer.h | 5 ++ 5 files changed, 109 insertions(+), 62 deletions(-) diff --git a/src/DockContainerWidget.cpp b/src/DockContainerWidget.cpp index cad855a..74dca12 100644 --- a/src/DockContainerWidget.cpp +++ b/src/DockContainerWidget.cpp @@ -81,16 +81,6 @@ struct DockContainerWidgetPrivate */ DockContainerWidgetPrivate(CDockContainerWidget* _public); - /** - * Create a new dock area widget and adds it to the list of doc areas - */ - CDockAreaWidget* newDockArea() - { - auto DockAreaWidget = new CDockAreaWidget(DockManager, _this); - DockAreas.append(DockAreaWidget); - return DockAreaWidget; - } - /** * Adds dock widget to container and returns the dock area that contains * the inserted dock widget @@ -289,6 +279,8 @@ void DockContainerWidgetPrivate::addDockAreasToList(const QListupdateDockArea(); } + + emit _this->dockAreasAdded(); } @@ -348,6 +340,7 @@ void DockContainerWidgetPrivate::addDockArea(CDockAreaWidget* NewDockArea, DockW DockAreas.append(NewDockArea); NewDockArea->updateDockArea(); + emit _this->dockAreasAdded(); } @@ -392,6 +385,7 @@ CDockAreaWidget* DockContainerWidgetPrivate::dockWidgetIntoDockArea(DockWidgetAr } DockAreas.append(NewDockArea); + emit _this->dockAreasAdded(); return NewDockArea; } @@ -521,6 +515,7 @@ void CDockContainerWidget::removeDockArea(CDockAreaWidget* area) d->Layout->replaceWidget(Splitter, widget); } delete Splitter; + emit dockAreasRemoved(); } diff --git a/src/DockContainerWidget.h b/src/DockContainerWidget.h index 6b6a410..0943fda 100644 --- a/src/DockContainerWidget.h +++ b/src/DockContainerWidget.h @@ -126,6 +126,19 @@ public: * This function returns true, if this container is in a floating widget */ bool isFloating() const; + +signals: + /** + * This signal is emitted if one or multiple dock areas has been added to + * the internal list of dock areas. + * If multiple dock areas are inserted, this signal is emitted only once + */ + void dockAreasAdded(); + + /** + * This signal is emitted if one or multiple dock areas has been removed + */ + void dockAreasRemoved(); }; // class DockContainerWidget } // namespace ads //----------------------------------------------------------------------------- diff --git a/src/DockWidget.cpp b/src/DockWidget.cpp index acc9afc..6b4f951 100644 --- a/src/DockWidget.cpp +++ b/src/DockWidget.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include @@ -61,7 +62,12 @@ struct DockWidgetPrivate CDockManager* DockManager = nullptr; CDockAreaWidget* DockArea = nullptr; QAction* ToggleViewAction; - QString CapturedState; + struct CapturedState + { + QString DockTreePosition; + QRect GlobalGeometry; + QPointer DockContainer; + } CapturedState; /** * Private data constructor @@ -91,67 +97,60 @@ DockWidgetPrivate::DockWidgetPrivate(CDockWidget* _public) : //============================================================================ void DockWidgetPrivate::capturedState() { - QString CapturedState; - QTextStream stream(&CapturedState); - stream << (_this->isFloating() ? "F " : "D "); - if (_this->isFloating()) - { - CFloatingDockContainer* FloatingWidget = internal::findParent(_this); - QRect Rect = FloatingWidget->geometry(); - stream << Rect.left() << " " << Rect.top() << " " << Rect.width() - << " " << Rect.height(); - } - else - { - QWidget* Widget = DockArea; - QSplitter* splitter = internal::findParent(Widget); - QStack SplitterData; - while (splitter) - { - SplitterData.push(QString("%1%2") - .arg((splitter->orientation() == Qt::Horizontal) ? "H" : "V") - .arg(splitter->indexOf(Widget))); - Widget = splitter; - splitter = internal::findParent(Widget); - } + QString DockTreePosition; + QTextStream stream(&DockTreePosition); - QString Separator; - while (!SplitterData.isEmpty()) - { - stream << Separator << SplitterData.pop(); - Separator = " "; - } + QPoint GlobalTopLeft = _this->mapToGlobal(_this->geometry().topLeft()); + QRect Rect(GlobalTopLeft, _this->geometry().size()); + CapturedState.GlobalGeometry = Rect; + CapturedState.DockContainer = _this->dockContainer(); + + QWidget* Widget = DockArea; + QSplitter* splitter = internal::findParent(Widget); + QStack SplitterData; + while (splitter) + { + SplitterData.push(QString("%1%2") + .arg((splitter->orientation() == Qt::Horizontal) ? "H" : "V") + .arg(splitter->indexOf(Widget))); + Widget = splitter; + splitter = internal::findParent(Widget); } - this->CapturedState = CapturedState; - std::cout << "SerializedPosition: " << CapturedState.toStdString() << std::endl; + + QString Separator; + while (!SplitterData.isEmpty()) + { + stream << Separator << SplitterData.pop(); + Separator = " "; + } + this->CapturedState.DockTreePosition = DockTreePosition; + std::cout << "SerializedPosition: " << DockTreePosition.toStdString() << std::endl; } //============================================================================ void DockWidgetPrivate::showDockWidget() { - QTextStream stream(&CapturedState); - QString DockedState; - stream >> DockedState; - if (DockedState == "F") + if (!CapturedState.DockContainer) + { + auto FloatingWidget = new CFloatingDockContainer(_this); + FloatingWidget->setGeometry(CapturedState.GlobalGeometry); + FloatingWidget->show(); + return; + } + + CDockContainerWidget* DockContainer = CapturedState.DockContainer.data(); + QStringList DockTree = this->CapturedState.DockTreePosition.split(' '); + QSplitter* splitter = DockContainer->findChild(QString(), Qt::FindDirectChildrenOnly); + + while (splitter) + { + + } + + for (const auto& TreeItem : DockTree) { - std::cout << "Restoring Floating Dock Widget" << std::endl; - QVector v; - while (!stream.atEnd()) - { - int Value; - stream >> Value; - v.append(Value); - } - if (v.count() == 4) - { - std::cout << "Rectangle Loaded" << std::endl; - QRect Rect(v[0], v[1], v[2], v[3]); - auto FloatingWidget = new CFloatingDockContainer(_this); - FloatingWidget->setGeometry(Rect); - FloatingWidget->show(); - } } } diff --git a/src/FloatingDockContainer.cpp b/src/FloatingDockContainer.cpp index 0810465..2828180 100644 --- a/src/FloatingDockContainer.cpp +++ b/src/FloatingDockContainer.cpp @@ -60,6 +60,7 @@ struct FloatingDockContainerPrivate bool DraggingActive = false; QPoint DragStartMousePosition; CDockContainerWidget* DropContainer = nullptr; + CDockAreaWidget* SingleDockArea = nullptr; /** * Private data constructor @@ -179,6 +180,8 @@ CFloatingDockContainer::CFloatingDockContainer(CDockManager* DockManager) : setLayout(l); d->DockContainer = new CDockContainerWidget(DockManager, this); + connect(d->DockContainer, SIGNAL(dockAreasAdded()), this, SLOT(onDockAreasAddedOrRemoved())); + connect(d->DockContainer, SIGNAL(dockAreasRemoved()), this, SLOT(onDockAreasAddedOrRemoved())); l->addWidget(d->DockContainer); DockManager->registerFloatingWidget(this); @@ -339,6 +342,38 @@ void CFloatingDockContainer::moveFloating() const QPoint moveToPos = QCursor::pos() - d->DragStartMousePosition - QPoint(BorderSize, 0); move(moveToPos); } + + +//============================================================================ +void CFloatingDockContainer::onDockAreasAddedOrRemoved() +{ + if (d->DockContainer->dockAreaCount() == 1) + { + d->SingleDockArea = d->DockContainer->dockArea(0); + this->setWindowTitle(d->SingleDockArea->currentDockWidget()->windowTitle()); + connect(d->SingleDockArea, SIGNAL(currentChanged(int)), this, + SLOT(onDockAreaCurrentChanged(int))); + } + else + { + if (d->SingleDockArea) + { + disconnect(d->SingleDockArea, SIGNAL(currentChanged(int)), this, + SLOT(onDockAreaCurrentChanged(int))); + d->SingleDockArea = nullptr; + } + this->setWindowTitle(qApp->applicationDisplayName()); + } +} + + +//============================================================================ +void CFloatingDockContainer::onDockAreaCurrentChanged(int Index) +{ + this->setWindowTitle(d->SingleDockArea->currentDockWidget()->windowTitle()); +} + + } // namespace ads //--------------------------------------------------------------------------- diff --git a/src/FloatingDockContainer.h b/src/FloatingDockContainer.h index 0fd0157..503aa08 100644 --- a/src/FloatingDockContainer.h +++ b/src/FloatingDockContainer.h @@ -50,6 +50,11 @@ class CFloatingDockContainer : public QWidget private: FloatingDockContainerPrivate* d; ///< private data (pimpl) friend class FloatingDockContainerPrivate; + +private slots: + void onDockAreasAddedOrRemoved(); + void onDockAreaCurrentChanged(int Index); + protected: /** * Private constructor that is called from public constructors