Skip to content

Commit d4a1800

Browse files
Properly implemented handling of DockWidget flag DockWidgetIsMovable for NonOpaque undocking - creating the drag preview is allowed even if the DockWidget is not floatable
1 parent 2c15d5d commit d4a1800

File tree

5 files changed

+36
-17
lines changed

5 files changed

+36
-17
lines changed

demo/MainWindow.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,8 @@ void MainWindowPrivate::createContent()
331331
auto ToolBar = FileSystemWidget->createDefaultToolBar();
332332
ToolBar->addAction(ui.actionSaveState);
333333
ToolBar->addAction(ui.actionRestoreState);
334+
FileSystemWidget->setFeature(ads::CDockWidget::DockWidgetFloatable, false);
335+
appendFeaturStringToWindowTitle(FileSystemWidget);
334336
DockManager->addDockWidget(ads::BottomDockWidgetArea, FileSystemWidget);
335337

336338
FileSystemWidget = createFileSystemTreeDockWidget(ViewMenu);
@@ -484,9 +486,9 @@ CMainWindow::CMainWindow(QWidget *parent) :
484486
// a QToolButton instead of a QPushButton
485487
// CDockManager::setConfigFlags(CDockManager::configFlags() | CDockManager::TabCloseButtonIsToolButton);
486488

487-
// comment the following line if you want to use opaque undocking and
489+
// uncomment the following line if you want to use opaque undocking and
488490
// opaque splitter resizing
489-
CDockManager::setConfigFlags(CDockManager::DefaultNonOpaqueConfig);
491+
// CDockManager::setConfigFlags(CDockManager::DefaultOpaqueConfig);
490492

491493
// uncomment the following line if you want a fixed tab width that does
492494
// not change if the visibility of the close button changes

src/DockAreaTitleBar.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,11 @@ void CDockAreaTitleBar::mouseMoveEvent(QMouseEvent* ev)
600600

601601
// If one single dock widget in this area is not floatable then the whole
602602
// area is not floatable
603-
if (!d->DockArea->features().testFlag(CDockWidget::DockWidgetFloatable))
603+
// If we do non opaque undocking, then we can create the floating drag
604+
// preview if the dock widget is movable
605+
auto Features = d->DockArea->features();
606+
if (!Features.testFlag(CDockWidget::DockWidgetFloatable)
607+
&& !(Features.testFlag(CDockWidget::DockWidgetMovable) && !CDockManager::testConfigFlag(CDockManager::OpaqueUndocking)))
604608
{
605609
return;
606610
}

src/DockManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858

5959
namespace ads
6060
{
61-
static CDockManager::ConfigFlags StaticConfigFlags = CDockManager::DefaultOpaqueConfig;
61+
static CDockManager::ConfigFlags StaticConfigFlags = CDockManager::DefaultNonOpaqueConfig;
6262

6363
/**
6464
* Private data class of CDockManager class (pimpl)

src/DockWidgetTab.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,13 @@ void CDockWidgetTab::mouseMoveEvent(QMouseEvent* ev)
368368
return;
369369
}
370370

371-
// Floating is only allowed for widgets that are movable
372-
if (d->DockWidget->features().testFlag(CDockWidget::DockWidgetFloatable))
371+
372+
// Floating is only allowed for widgets that are floatable
373+
// If we do non opaque undocking, then can create the drag preview
374+
// if the widget is movable.
375+
auto Features = d->DockWidget->features();
376+
if (Features.testFlag(CDockWidget::DockWidgetFloatable)
377+
|| (Features.testFlag(CDockWidget::DockWidgetMovable) && !CDockManager::testConfigFlag(CDockManager::OpaqueUndocking)))
373378
{
374379
// If we undock, we need to restore the initial position of this
375380
// tab because it looks strange if it remains on its dragged position

src/FloatingDragPreview.cpp

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -291,25 +291,33 @@ void CFloatingDragPreview::finishDragging()
291291
else
292292
{
293293
CDockWidget* DockWidget = qobject_cast<CDockWidget*>(d->Content);
294-
CFloatingDockContainer* FloatingWidget;
295-
if (DockWidget)
294+
CFloatingDockContainer* FloatingWidget = nullptr;
295+
296+
if (DockWidget && DockWidget->features().testFlag(CDockWidget::DockWidgetFloatable))
296297
{
297298
FloatingWidget = new CFloatingDockContainer(DockWidget);
298299
}
299300
else
300301
{
301302
CDockAreaWidget* DockArea = qobject_cast<CDockAreaWidget*>(d->Content);
302-
FloatingWidget = new CFloatingDockContainer(DockArea);
303+
if (DockArea->features().testFlag(CDockWidget::DockWidgetFloatable))
304+
{
305+
FloatingWidget = new CFloatingDockContainer(DockArea);
306+
}
303307
}
304-
FloatingWidget->setGeometry(this->geometry());
305-
FloatingWidget->show();
306-
if (!CDockManager::configFlags().testFlag(CDockManager::DragPreviewHasWindowFrame))
308+
309+
if (FloatingWidget)
307310
{
308-
QApplication::processEvents();
309-
int FrameHeight = FloatingWidget->frameGeometry().height() - FloatingWidget->geometry().height();
310-
QRect FixedGeometry = this->geometry();
311-
FixedGeometry.adjust(0, FrameHeight, 0, 0);
312-
FloatingWidget->setGeometry(FixedGeometry);
311+
FloatingWidget->setGeometry(this->geometry());
312+
FloatingWidget->show();
313+
if (!CDockManager::configFlags().testFlag(CDockManager::DragPreviewHasWindowFrame))
314+
{
315+
QApplication::processEvents();
316+
int FrameHeight = FloatingWidget->frameGeometry().height() - FloatingWidget->geometry().height();
317+
QRect FixedGeometry = this->geometry();
318+
FixedGeometry.adjust(0, FrameHeight, 0, 0);
319+
FloatingWidget->setGeometry(FixedGeometry);
320+
}
313321
}
314322
}
315323

0 commit comments

Comments
 (0)