Added setFloating function to CDockWidget to support making a dock widget floating with from code

This commit is contained in:
Uwe Kindler 2019-11-25 15:59:08 +01:00
parent aee9fb1c95
commit f497944d2c
5 changed files with 26 additions and 5 deletions

View File

@ -229,9 +229,14 @@ void MainWindowPrivate::createContent()
DockManager->addDockWidget(ads::CenterDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), BottomDockArea); DockManager->addDockWidget(ads::CenterDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), BottomDockArea);
// Test creation of floating dock widgets // 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)); 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()) for (auto DockWidget : DockManager->dockWidgetsMap())
{ {

View File

@ -726,6 +726,17 @@ QSize CDockWidget::minimumSizeHint() const
} }
//============================================================================
void CDockWidget::setFloating()
{
if (isClosed())
{
return;
}
d->TabWidget->detachDockWidget();
}
} // namespace ads } // namespace ads
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View File

@ -414,6 +414,11 @@ public slots:
*/ */
void toggleView(bool Open = true); void toggleView(bool Open = true);
/**
* This function will make a docked widget floating
*/
void setFloating();
signals: signals:
/** /**
* This signal is emitted if the dock widget is opened or closed * This signal is emitted if the dock widget is opened or closed

View File

@ -371,7 +371,7 @@ void CDockWidgetTab::contextMenuEvent(QContextMenuEvent* ev)
d->DragStartMousePosition = ev->pos(); d->DragStartMousePosition = ev->pos();
QMenu Menu(this); 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)); Action->setEnabled(d->DockWidget->features().testFlag(CDockWidget::DockWidgetFloatable));
Menu.addSeparator(); Menu.addSeparator();
Action = Menu.addAction(tr("Close"), this, SIGNAL(closeRequested())); 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)) if (!d->DockWidget->features().testFlag(CDockWidget::DockWidgetFloatable))
{ {

View File

@ -57,7 +57,7 @@ private:
void onDockWidgetFeaturesChanged(); void onDockWidgetFeaturesChanged();
private slots: private slots:
void onDetachActionTriggered(); void detachDockWidget();
protected: protected:
virtual void mousePressEvent(QMouseEvent* ev) override; virtual void mousePressEvent(QMouseEvent* ev) override;