Fixed dropping of FloatingDragPreview into center of dock container with only one single visible dock area

If this happens the dropped dock widget needs to get tabified
This commit is contained in:
Uwe Kindler 2020-04-27 14:00:37 +02:00
parent ef855e3843
commit cdc863e962
2 changed files with 54 additions and 31 deletions

View File

@ -169,14 +169,14 @@ void FloatingDockContainerPrivate::titleMouseReleaseEvent()
|| DockManager->containerOverlay()->dropAreaUnderCursor()
!= InvalidDockWidgetArea)
{
// Resize the floating widget to the size of the highlighted drop area
// rectangle
CDockOverlay *Overlay = DockManager->containerOverlay();
if (!Overlay->dropOverlayRect().isValid())
{
Overlay = DockManager->dockAreaOverlay();
}
// Resize the floating widget to the size of the highlighted drop area
// rectangle
QRect Rect = Overlay->dropOverlayRect();
int FrameWidth = (_this->frameSize().width() - _this->rect().width())
/ 2;

View File

@ -66,6 +66,12 @@ struct FloatingDragPreviewPrivate
DockManager->dockAreaOverlay()->hideOverlay();
_this->close();
}
/**
* Creates the real floating widget in case the mouse is released outside
* outside of any drop area
*/
void createFloatingWidget();
};
// struct LedArrayPanelPrivate
@ -173,6 +179,40 @@ FloatingDragPreviewPrivate::FloatingDragPreviewPrivate(CFloatingDragPreview *_pu
}
//============================================================================
void FloatingDragPreviewPrivate::createFloatingWidget()
{
CDockWidget* DockWidget = qobject_cast<CDockWidget*>(Content);
CDockAreaWidget* DockArea = qobject_cast<CDockAreaWidget*>(Content);
CFloatingDockContainer* FloatingWidget = nullptr;
if (DockWidget && DockWidget->features().testFlag(CDockWidget::DockWidgetFloatable))
{
FloatingWidget = new CFloatingDockContainer(DockWidget);
}
else if (DockArea && DockArea->features().testFlag(CDockWidget::DockWidgetFloatable))
{
FloatingWidget = new CFloatingDockContainer(DockArea);
}
if (FloatingWidget)
{
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);
}
}
}
//============================================================================
CFloatingDragPreview::CFloatingDragPreview(QWidget* Content, QWidget* parent) :
QWidget(parent),
@ -288,42 +328,25 @@ void CFloatingDragPreview::finishDragging()
ADS_PRINT("CFloatingDragPreview::finishDragging");
auto DockDropArea = d->DockManager->dockAreaOverlay()->visibleDropAreaUnderCursor();
auto ContainerDropArea = d->DockManager->containerOverlay()->visibleDropAreaUnderCursor();
if (d->DropContainer && (DockDropArea != InvalidDockWidgetArea))
if (!d->DropContainer)
{
d->createFloatingWidget();
}
else if (DockDropArea != InvalidDockWidgetArea)
{
d->DropContainer->dropWidget(d->Content, DockDropArea, d->DropContainer->dockAreaAt(QCursor::pos()));
}
else if (d->DropContainer && (ContainerDropArea != InvalidDockWidgetArea))
else if (ContainerDropArea != InvalidDockWidgetArea)
{
d->DropContainer->dropWidget(d->Content, ContainerDropArea, nullptr);
}
else
{
CDockWidget* DockWidget = qobject_cast<CDockWidget*>(d->Content);
CDockAreaWidget* DockArea = qobject_cast<CDockAreaWidget*>(d->Content);
CFloatingDockContainer* FloatingWidget = nullptr;
if (DockWidget && DockWidget->features().testFlag(CDockWidget::DockWidgetFloatable))
// If there is only one single dock area, and we drop into the center
// then we tabify the dropped widget into the only visible dock area
if (d->DropContainer->visibleDockAreaCount() <= 1 && CenterDockWidgetArea == ContainerDropArea)
{
FloatingWidget = new CFloatingDockContainer(DockWidget);
d->DropContainer->dropWidget(d->Content, ContainerDropArea, d->DropContainer->dockAreaAt(QCursor::pos()));
}
else if (DockArea && DockArea->features().testFlag(CDockWidget::DockWidgetFloatable))
else
{
FloatingWidget = new CFloatingDockContainer(DockArea);
}
if (FloatingWidget)
{
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);
}
d->DropContainer->dropWidget(d->Content, ContainerDropArea, nullptr);
}
}