From d4a18003d940c8bc80ef6edf0e0d773da8616c3c Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Sun, 16 Feb 2020 14:37:14 +0100 Subject: [PATCH] Properly implemented handling of DockWidget flag DockWidgetIsMovable for NonOpaque undocking - creating the drag preview is allowed even if the DockWidget is not floatable --- demo/MainWindow.cpp | 6 ++++-- src/DockAreaTitleBar.cpp | 6 +++++- src/DockManager.cpp | 2 +- src/DockWidgetTab.cpp | 9 +++++++-- src/FloatingDragPreview.cpp | 30 +++++++++++++++++++----------- 5 files changed, 36 insertions(+), 17 deletions(-) diff --git a/demo/MainWindow.cpp b/demo/MainWindow.cpp index bc40a6a..300fd1c 100644 --- a/demo/MainWindow.cpp +++ b/demo/MainWindow.cpp @@ -331,6 +331,8 @@ void MainWindowPrivate::createContent() auto ToolBar = FileSystemWidget->createDefaultToolBar(); ToolBar->addAction(ui.actionSaveState); ToolBar->addAction(ui.actionRestoreState); + FileSystemWidget->setFeature(ads::CDockWidget::DockWidgetFloatable, false); + appendFeaturStringToWindowTitle(FileSystemWidget); DockManager->addDockWidget(ads::BottomDockWidgetArea, FileSystemWidget); FileSystemWidget = createFileSystemTreeDockWidget(ViewMenu); @@ -484,9 +486,9 @@ CMainWindow::CMainWindow(QWidget *parent) : // a QToolButton instead of a QPushButton // CDockManager::setConfigFlags(CDockManager::configFlags() | CDockManager::TabCloseButtonIsToolButton); - // comment the following line if you want to use opaque undocking and + // uncomment the following line if you want to use opaque undocking and // opaque splitter resizing - CDockManager::setConfigFlags(CDockManager::DefaultNonOpaqueConfig); + // CDockManager::setConfigFlags(CDockManager::DefaultOpaqueConfig); // uncomment the following line if you want a fixed tab width that does // not change if the visibility of the close button changes diff --git a/src/DockAreaTitleBar.cpp b/src/DockAreaTitleBar.cpp index 3beae3e..53d5396 100644 --- a/src/DockAreaTitleBar.cpp +++ b/src/DockAreaTitleBar.cpp @@ -600,7 +600,11 @@ void CDockAreaTitleBar::mouseMoveEvent(QMouseEvent* ev) // If one single dock widget in this area is not floatable then the whole // area is not floatable - if (!d->DockArea->features().testFlag(CDockWidget::DockWidgetFloatable)) + // If we do non opaque undocking, then we can create the floating drag + // preview if the dock widget is movable + auto Features = d->DockArea->features(); + if (!Features.testFlag(CDockWidget::DockWidgetFloatable) + && !(Features.testFlag(CDockWidget::DockWidgetMovable) && !CDockManager::testConfigFlag(CDockManager::OpaqueUndocking))) { return; } diff --git a/src/DockManager.cpp b/src/DockManager.cpp index b5a7d11..1ac5a91 100644 --- a/src/DockManager.cpp +++ b/src/DockManager.cpp @@ -58,7 +58,7 @@ namespace ads { -static CDockManager::ConfigFlags StaticConfigFlags = CDockManager::DefaultOpaqueConfig; +static CDockManager::ConfigFlags StaticConfigFlags = CDockManager::DefaultNonOpaqueConfig; /** * Private data class of CDockManager class (pimpl) diff --git a/src/DockWidgetTab.cpp b/src/DockWidgetTab.cpp index 4e8323f..c721cbd 100644 --- a/src/DockWidgetTab.cpp +++ b/src/DockWidgetTab.cpp @@ -368,8 +368,13 @@ void CDockWidgetTab::mouseMoveEvent(QMouseEvent* ev) return; } - // Floating is only allowed for widgets that are movable - if (d->DockWidget->features().testFlag(CDockWidget::DockWidgetFloatable)) + + // Floating is only allowed for widgets that are floatable + // If we do non opaque undocking, then can create the drag preview + // if the widget is movable. + auto Features = d->DockWidget->features(); + if (Features.testFlag(CDockWidget::DockWidgetFloatable) + || (Features.testFlag(CDockWidget::DockWidgetMovable) && !CDockManager::testConfigFlag(CDockManager::OpaqueUndocking))) { // If we undock, we need to restore the initial position of this // tab because it looks strange if it remains on its dragged position diff --git a/src/FloatingDragPreview.cpp b/src/FloatingDragPreview.cpp index 14346df..47904a8 100644 --- a/src/FloatingDragPreview.cpp +++ b/src/FloatingDragPreview.cpp @@ -291,25 +291,33 @@ void CFloatingDragPreview::finishDragging() else { CDockWidget* DockWidget = qobject_cast(d->Content); - CFloatingDockContainer* FloatingWidget; - if (DockWidget) + CFloatingDockContainer* FloatingWidget = nullptr; + + if (DockWidget && DockWidget->features().testFlag(CDockWidget::DockWidgetFloatable)) { FloatingWidget = new CFloatingDockContainer(DockWidget); } else { CDockAreaWidget* DockArea = qobject_cast(d->Content); - FloatingWidget = new CFloatingDockContainer(DockArea); + if (DockArea->features().testFlag(CDockWidget::DockWidgetFloatable)) + { + FloatingWidget = new CFloatingDockContainer(DockArea); + } } - FloatingWidget->setGeometry(this->geometry()); - FloatingWidget->show(); - if (!CDockManager::configFlags().testFlag(CDockManager::DragPreviewHasWindowFrame)) + + if (FloatingWidget) { - QApplication::processEvents(); - int FrameHeight = FloatingWidget->frameGeometry().height() - FloatingWidget->geometry().height(); - QRect FixedGeometry = this->geometry(); - FixedGeometry.adjust(0, FrameHeight, 0, 0); - FloatingWidget->setGeometry(FixedGeometry); + FloatingWidget->setGeometry(this->geometry()); + FloatingWidget->show(); + if (!CDockManager::configFlags().testFlag(CDockManager::DragPreviewHasWindowFrame)) + { + QApplication::processEvents(); + int FrameHeight = FloatingWidget->frameGeometry().height() - FloatingWidget->geometry().height(); + QRect FixedGeometry = this->geometry(); + FixedGeometry.adjust(0, FrameHeight, 0, 0); + FloatingWidget->setGeometry(FixedGeometry); + } } }