diff --git a/demo/MainWindow.cpp b/demo/MainWindow.cpp index ca19964..76d3c52 100644 --- a/demo/MainWindow.cpp +++ b/demo/MainWindow.cpp @@ -57,6 +57,7 @@ #include "DockManager.h" #include "DockWidget.h" #include "DockAreaWidget.h" +#include "FloatingDockContainer.h" //============================================================================ @@ -226,8 +227,11 @@ void MainWindowPrivate::createContent() auto BottomDockArea = DockManager->addDockWidget(ads::BottomDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea); DockManager->addDockWidget(ads::RightDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea); DockManager->addDockWidget(ads::CenterDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), BottomDockArea); - //DockManager->addDockWidget(ads::CenterDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), BottomDockArea); - //DockManager->addDockWidget(ads::CenterDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), BottomDockArea); + + // Test creation of floating dock widgets + auto FloatingWidget = DockManager->addDockWidgetFloating(createFileSystemTreeDockWidget(ViewMenu)); + FloatingWidget->move(QPoint(0,0)); + DockManager->addDockWidgetFloating(createLongTextLabelDockWidget(ViewMenu)); for (auto DockWidget : DockManager->dockWidgetsMap()) { @@ -309,6 +313,10 @@ CMainWindow::CMainWindow(QWidget *parent) : // uncomment the following line if the tab close button should be // a QToolButton instead of a QPushButton // CDockManager::setConfigFlags(CDockManager::configFlags() | CDockManager::TabCloseButtonIsToolButton); + auto Flags = CDockManager::configFlags(); + Flags.setFlag(CDockManager::XmlAutoFormattingEnabled, true); + Flags.setFlag(CDockManager::XmlCompressionEnabled, false); + CDockManager::setConfigFlags(Flags); // uncomment the following line if you wand a fixed tab width that does // not change if the visibility of the close button changes @@ -328,7 +336,7 @@ CMainWindow::CMainWindow(QWidget *parent) : // Default window geometry resize(1280, 720); - d->restoreState(); + //d->restoreState(); d->restorePerspectives(); } diff --git a/src/DockAreaWidget.h b/src/DockAreaWidget.h index 91e8605..f3fa649 100644 --- a/src/DockAreaWidget.h +++ b/src/DockAreaWidget.h @@ -63,6 +63,7 @@ private: friend struct DockWidgetPrivate; friend class CDockWidget; friend struct DockManagerPrivate; + friend class CDockManager; private slots: void onTabCloseRequested(int Index); diff --git a/src/DockManager.cpp b/src/DockManager.cpp index 59e68ad..6b32aec 100644 --- a/src/DockManager.cpp +++ b/src/DockManager.cpp @@ -76,6 +76,7 @@ struct DockManagerPrivate QMenu* ViewMenu; CDockManager::eViewMenuInsertionOrder MenuInsertionOrder = CDockManager::MenuAlphabeticallySorted; bool RestoringState = false; + QVector UninitializedFloatingWidgets; /** * Private data constructor @@ -560,6 +561,48 @@ bool CDockManager::restoreState(const QByteArray &state, int version) } +//============================================================================ +CFloatingDockContainer* CDockManager::addDockWidgetFloating(CDockWidget* Dockwidget) +{ + d->DockWidgetsMap.insert(Dockwidget->objectName(), Dockwidget); + CDockAreaWidget* OldDockArea = Dockwidget->dockAreaWidget(); + if (OldDockArea) + { + OldDockArea->removeDockWidget(Dockwidget); + } + + Dockwidget->setDockManager(this); + CFloatingDockContainer* FloatingWidget = new CFloatingDockContainer(Dockwidget); + FloatingWidget->resize(Dockwidget->size()); + if (isVisible()) + { + FloatingWidget->show(); + } + else + { + d->UninitializedFloatingWidgets.append(FloatingWidget); + } + return FloatingWidget; +} + + +//============================================================================ +void CDockManager::showEvent(QShowEvent *event) +{ + Super::showEvent(event); + if (d->UninitializedFloatingWidgets.empty()) + { + return; + } + + for (auto FloatingWidget : d->UninitializedFloatingWidgets) + { + FloatingWidget->show(); + } + d->UninitializedFloatingWidgets.clear(); +} + + //============================================================================ CDockAreaWidget* CDockManager::addDockWidget(DockWidgetArea area, CDockWidget* Dockwidget, CDockAreaWidget* DockAreaWidget) diff --git a/src/DockManager.h b/src/DockManager.h index fd59278..7ba9dfa 100644 --- a/src/DockManager.h +++ b/src/DockManager.h @@ -111,7 +111,14 @@ protected: */ CDockOverlay* dockAreaOverlay() const; + /** + * Show the floating widgets that has been created floating + */ + virtual void showEvent(QShowEvent *event) override; + public: + using Super = CDockContainerWidget; + enum eViewMenuInsertionOrder { MenuSortedByInsertion, @@ -206,6 +213,12 @@ public: CDockAreaWidget* addDockWidgetTabToArea(CDockWidget* Dockwidget, CDockAreaWidget* DockAreaWidget); + /** + * Adds the given DockWidget floating and returns the created + * CFloatingDockContainer instance. + */ + CFloatingDockContainer* addDockWidgetFloating(CDockWidget* Dockwidget); + /** * Searches for a registered doc widget with the given ObjectName * \return Return the found dock widget or nullptr if a dock widget with the