diff --git a/demo/MainWindow.cpp b/demo/MainWindow.cpp index 76d3c52..74df077 100644 --- a/demo/MainWindow.cpp +++ b/demo/MainWindow.cpp @@ -229,9 +229,14 @@ void MainWindowPrivate::createContent() DockManager->addDockWidget(ads::CenterDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), BottomDockArea); // Test creation of floating dock widgets - auto FloatingWidget = DockManager->addDockWidgetFloating(createFileSystemTreeDockWidget(ViewMenu)); + DockWidget = createFileSystemTreeDockWidget(ViewMenu); + auto FloatingWidget = DockManager->addDockWidgetFloating(DockWidget); FloatingWidget->move(QPoint(0,0)); - DockManager->addDockWidgetFloating(createLongTextLabelDockWidget(ViewMenu)); + FloatingWidget = DockManager->addDockWidgetFloating(createLongTextLabelDockWidget(ViewMenu)); + + auto Action = ui.menuView->addAction(QString("Set %1 floating").arg(DockWidget->windowTitle())); + DockWidget->connect(Action, SIGNAL(triggered()), SLOT(setFloating())); + for (auto DockWidget : DockManager->dockWidgetsMap()) { diff --git a/src/DockWidget.cpp b/src/DockWidget.cpp index c9356db..dcc7ee0 100644 --- a/src/DockWidget.cpp +++ b/src/DockWidget.cpp @@ -726,6 +726,17 @@ QSize CDockWidget::minimumSizeHint() const } +//============================================================================ +void CDockWidget::setFloating() +{ + if (isClosed()) + { + return; + } + d->TabWidget->detachDockWidget(); +} + + } // namespace ads //--------------------------------------------------------------------------- diff --git a/src/DockWidget.h b/src/DockWidget.h index c276f6f..c9422c0 100644 --- a/src/DockWidget.h +++ b/src/DockWidget.h @@ -414,6 +414,11 @@ public slots: */ void toggleView(bool Open = true); + /** + * This function will make a docked widget floating + */ + void setFloating(); + signals: /** * This signal is emitted if the dock widget is opened or closed diff --git a/src/DockWidgetTab.cpp b/src/DockWidgetTab.cpp index 005bcf5..bca93b5 100644 --- a/src/DockWidgetTab.cpp +++ b/src/DockWidgetTab.cpp @@ -371,7 +371,7 @@ void CDockWidgetTab::contextMenuEvent(QContextMenuEvent* ev) d->DragStartMousePosition = ev->pos(); QMenu Menu(this); - auto Action = Menu.addAction(tr("Detach"), this, SLOT(onDetachActionTriggered())); + auto Action = Menu.addAction(tr("Detach"), this, SLOT(detachDockWidget())); Action->setEnabled(d->DockWidget->features().testFlag(CDockWidget::DockWidgetFloatable)); Menu.addSeparator(); Action = Menu.addAction(tr("Close"), this, SIGNAL(closeRequested())); @@ -526,7 +526,7 @@ bool CDockWidgetTab::isClosable() const //=========================================================================== -void CDockWidgetTab::onDetachActionTriggered() +void CDockWidgetTab::detachDockWidget() { if (!d->DockWidget->features().testFlag(CDockWidget::DockWidgetFloatable)) { diff --git a/src/DockWidgetTab.h b/src/DockWidgetTab.h index 894b57a..1d37e1d 100644 --- a/src/DockWidgetTab.h +++ b/src/DockWidgetTab.h @@ -57,7 +57,7 @@ private: void onDockWidgetFeaturesChanged(); private slots: - void onDetachActionTriggered(); + void detachDockWidget(); protected: virtual void mousePressEvent(QMouseEvent* ev) override;