Properly implemented handling of DockWidget flag DockWidgetIsMovable for NonOpaque undocking - creating the drag preview is allowed even if the DockWidget is not floatable

This commit is contained in:
Uwe Kindler 2020-02-16 14:37:14 +01:00
parent 2c15d5dacd
commit d4a18003d9
5 changed files with 36 additions and 17 deletions

View File

@ -331,6 +331,8 @@ void MainWindowPrivate::createContent()
auto ToolBar = FileSystemWidget->createDefaultToolBar(); auto ToolBar = FileSystemWidget->createDefaultToolBar();
ToolBar->addAction(ui.actionSaveState); ToolBar->addAction(ui.actionSaveState);
ToolBar->addAction(ui.actionRestoreState); ToolBar->addAction(ui.actionRestoreState);
FileSystemWidget->setFeature(ads::CDockWidget::DockWidgetFloatable, false);
appendFeaturStringToWindowTitle(FileSystemWidget);
DockManager->addDockWidget(ads::BottomDockWidgetArea, FileSystemWidget); DockManager->addDockWidget(ads::BottomDockWidgetArea, FileSystemWidget);
FileSystemWidget = createFileSystemTreeDockWidget(ViewMenu); FileSystemWidget = createFileSystemTreeDockWidget(ViewMenu);
@ -484,9 +486,9 @@ CMainWindow::CMainWindow(QWidget *parent) :
// a QToolButton instead of a QPushButton // a QToolButton instead of a QPushButton
// CDockManager::setConfigFlags(CDockManager::configFlags() | CDockManager::TabCloseButtonIsToolButton); // 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 // opaque splitter resizing
CDockManager::setConfigFlags(CDockManager::DefaultNonOpaqueConfig); // CDockManager::setConfigFlags(CDockManager::DefaultOpaqueConfig);
// uncomment the following line if you want a fixed tab width that does // uncomment the following line if you want a fixed tab width that does
// not change if the visibility of the close button changes // not change if the visibility of the close button changes

View File

@ -600,7 +600,11 @@ void CDockAreaTitleBar::mouseMoveEvent(QMouseEvent* ev)
// If one single dock widget in this area is not floatable then the whole // If one single dock widget in this area is not floatable then the whole
// area is not floatable // 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; return;
} }

View File

@ -58,7 +58,7 @@
namespace ads namespace ads
{ {
static CDockManager::ConfigFlags StaticConfigFlags = CDockManager::DefaultOpaqueConfig; static CDockManager::ConfigFlags StaticConfigFlags = CDockManager::DefaultNonOpaqueConfig;
/** /**
* Private data class of CDockManager class (pimpl) * Private data class of CDockManager class (pimpl)

View File

@ -368,8 +368,13 @@ void CDockWidgetTab::mouseMoveEvent(QMouseEvent* ev)
return; 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 // If we undock, we need to restore the initial position of this
// tab because it looks strange if it remains on its dragged position // tab because it looks strange if it remains on its dragged position

View File

@ -291,25 +291,33 @@ void CFloatingDragPreview::finishDragging()
else else
{ {
CDockWidget* DockWidget = qobject_cast<CDockWidget*>(d->Content); CDockWidget* DockWidget = qobject_cast<CDockWidget*>(d->Content);
CFloatingDockContainer* FloatingWidget; CFloatingDockContainer* FloatingWidget = nullptr;
if (DockWidget)
if (DockWidget && DockWidget->features().testFlag(CDockWidget::DockWidgetFloatable))
{ {
FloatingWidget = new CFloatingDockContainer(DockWidget); FloatingWidget = new CFloatingDockContainer(DockWidget);
} }
else else
{ {
CDockAreaWidget* DockArea = qobject_cast<CDockAreaWidget*>(d->Content); CDockAreaWidget* DockArea = qobject_cast<CDockAreaWidget*>(d->Content);
FloatingWidget = new CFloatingDockContainer(DockArea); if (DockArea->features().testFlag(CDockWidget::DockWidgetFloatable))
{
FloatingWidget = new CFloatingDockContainer(DockArea);
}
} }
FloatingWidget->setGeometry(this->geometry());
FloatingWidget->show(); if (FloatingWidget)
if (!CDockManager::configFlags().testFlag(CDockManager::DragPreviewHasWindowFrame))
{ {
QApplication::processEvents(); FloatingWidget->setGeometry(this->geometry());
int FrameHeight = FloatingWidget->frameGeometry().height() - FloatingWidget->geometry().height(); FloatingWidget->show();
QRect FixedGeometry = this->geometry(); if (!CDockManager::configFlags().testFlag(CDockManager::DragPreviewHasWindowFrame))
FixedGeometry.adjust(0, FrameHeight, 0, 0); {
FloatingWidget->setGeometry(FixedGeometry); QApplication::processEvents();
int FrameHeight = FloatingWidget->frameGeometry().height() - FloatingWidget->geometry().height();
QRect FixedGeometry = this->geometry();
FixedGeometry.adjust(0, FrameHeight, 0, 0);
FloatingWidget->setGeometry(FixedGeometry);
}
} }
} }