Properly consider pinnable flag of dock widget when painting the drop overlays - no auto hide overlay for non pinnable dock widgets

This commit is contained in:
Uwe Kindler 2023-07-11 10:28:17 +02:00
parent 364ee33f9c
commit 39bc7f1780
3 changed files with 49 additions and 17 deletions

View File

@ -472,19 +472,23 @@ DockWidgetArea CDockOverlay::dropAreaUnderCursor() const
{ {
auto Rect = rect(); auto Rect = rect();
const QPoint pos = mapFromGlobal(QCursor::pos()); const QPoint pos = mapFromGlobal(QCursor::pos());
if (pos.x() < d->sideBarMouseZone(SideBarLeft)) if ((pos.x() < d->sideBarMouseZone(SideBarLeft))
&& d->AllowedAreas.testFlag(LeftAutoHideArea))
{ {
return LeftAutoHideArea; return LeftAutoHideArea;
} }
else if (pos.x() > (Rect.width() - d->sideBarMouseZone(SideBarRight))) else if (pos.x() > (Rect.width() - d->sideBarMouseZone(SideBarRight))
&& d->AllowedAreas.testFlag(RightAutoHideArea))
{ {
return RightAutoHideArea; return RightAutoHideArea;
} }
else if (pos.y() < d->sideBarMouseZone(SideBarTop)) else if (pos.y() < d->sideBarMouseZone(SideBarTop)
&& d->AllowedAreas.testFlag(TopAutoHideArea))
{ {
return TopAutoHideArea; return TopAutoHideArea;
} }
else if (pos.y() > (Rect.height() - d->sideBarMouseZone(SideBarBottom))) else if (pos.y() > (Rect.height() - d->sideBarMouseZone(SideBarBottom))
&& d->AllowedAreas.testFlag(BottomAutoHideArea))
{ {
return BottomAutoHideArea; return BottomAutoHideArea;
} }

View File

@ -590,16 +590,22 @@ void FloatingDockContainerPrivate::updateDropOverlays(const QPoint &GlobalPos)
} }
int VisibleDockAreas = TopContainer->visibleDockAreaCount(); int VisibleDockAreas = TopContainer->visibleDockAreaCount();
DockWidgetAreas AllowedAreas = (VisibleDockAreas > 1) ? OuterDockAreas : AllDockAreas; DockWidgetAreas AllowedContainerAreas = (VisibleDockAreas > 1) ? OuterDockAreas : AllDockAreas;
auto DockArea = TopContainer->dockAreaAt(GlobalPos); auto DockArea = TopContainer->dockAreaAt(GlobalPos);
// If the dock container contains only one single DockArea, then we need // If the dock container contains only one single DockArea, then we need
// to respect the allowed areas - only the center area is relevant here because // to respect the allowed areas - only the center area is relevant here because
// all other allowed areas are from the container // all other allowed areas are from the container
if (VisibleDockAreas == 1 && DockArea) if (VisibleDockAreas == 1 && DockArea)
{ {
AllowedAreas.setFlag(CenterDockWidgetArea, DockArea->allowedAreas().testFlag(CenterDockWidgetArea)); AllowedContainerAreas.setFlag(CenterDockWidgetArea, DockArea->allowedAreas().testFlag(CenterDockWidgetArea));
} }
ContainerOverlay->setAllowedAreas(AllowedAreas);
if (DockContainer->features().testFlag(CDockWidget::DockWidgetPinnable))
{
AllowedContainerAreas |= AutoHideDockAreas;
}
ContainerOverlay->setAllowedAreas(AllowedContainerAreas);
DockWidgetArea ContainerArea = ContainerOverlay->showOverlay(TopContainer); DockWidgetArea ContainerArea = ContainerOverlay->showOverlay(TopContainer);
ContainerOverlay->enableDropPreview(ContainerArea != InvalidDockWidgetArea); ContainerOverlay->enableDropPreview(ContainerArea != InvalidDockWidgetArea);

View File

@ -35,6 +35,7 @@ struct FloatingDragPreviewPrivate
{ {
CFloatingDragPreview *_this; CFloatingDragPreview *_this;
QWidget* Content; QWidget* Content;
CDockWidget::DockWidgetFeatures ContentFeatures;
CDockAreaWidget* ContentSourceArea = nullptr; CDockAreaWidget* ContentSourceArea = nullptr;
QPoint DragStartMousePosition; QPoint DragStartMousePosition;
CDockManager* DockManager; CDockManager* DockManager;
@ -80,19 +81,35 @@ struct FloatingDragPreviewPrivate
*/ */
bool isContentFloatable() const bool isContentFloatable() const
{ {
CDockWidget* DockWidget = qobject_cast<CDockWidget*>(Content); return this->ContentFeatures.testFlag(CDockWidget::DockWidgetFloatable);
if (DockWidget && DockWidget->features().testFlag(CDockWidget::DockWidgetFloatable)) }
/**
* Returns true, if the content is pinnable
*/
bool isContentPinnable() const
{ {
return true; return this->ContentFeatures.testFlag(CDockWidget::DockWidgetPinnable);
}
/**
* Returns the content features
*/
CDockWidget::DockWidgetFeatures contentFeatures() const
{
CDockWidget* DockWidget = qobject_cast<CDockWidget*>(Content);
if (DockWidget)
{
return DockWidget->features();
} }
CDockAreaWidget* DockArea = qobject_cast<CDockAreaWidget*>(Content); CDockAreaWidget* DockArea = qobject_cast<CDockAreaWidget*>(Content);
if (DockArea && DockArea->features().testFlag(CDockWidget::DockWidgetFloatable)) if (DockArea)
{ {
return true; return DockArea->features();
} }
return false; return CDockWidget::DockWidgetFeatures();
} }
}; };
// struct LedArrayPanelPrivate // struct LedArrayPanelPrivate
@ -152,7 +169,7 @@ void FloatingDragPreviewPrivate::updateDropOverlays(const QPoint &GlobalPos)
VisibleDockAreas++; VisibleDockAreas++;
} }
DockWidgetAreas AllowedAreas = (VisibleDockAreas > 1) ? OuterDockAreas : AllDockAreas; DockWidgetAreas AllowedContainerAreas = (VisibleDockAreas > 1) ? OuterDockAreas : AllDockAreas;
//ContainerOverlay->enableDropPreview(ContainerDropArea != InvalidDockWidgetArea); //ContainerOverlay->enableDropPreview(ContainerDropArea != InvalidDockWidgetArea);
auto DockArea = TopContainer->dockAreaAt(GlobalPos); auto DockArea = TopContainer->dockAreaAt(GlobalPos);
// If the dock container contains only one single DockArea, then we need // If the dock container contains only one single DockArea, then we need
@ -160,9 +177,14 @@ void FloatingDragPreviewPrivate::updateDropOverlays(const QPoint &GlobalPos)
// all other allowed areas are from the container // all other allowed areas are from the container
if (VisibleDockAreas == 1 && DockArea) if (VisibleDockAreas == 1 && DockArea)
{ {
AllowedAreas.setFlag(CenterDockWidgetArea, DockArea->allowedAreas().testFlag(CenterDockWidgetArea)); AllowedContainerAreas.setFlag(CenterDockWidgetArea, DockArea->allowedAreas().testFlag(CenterDockWidgetArea));
} }
ContainerOverlay->setAllowedAreas(AllowedAreas);
if (isContentPinnable())
{
AllowedContainerAreas |= AutoHideDockAreas;
}
ContainerOverlay->setAllowedAreas(AllowedContainerAreas);
ContainerOverlay->enableDropPreview(ContainerDropArea != InvalidDockWidgetArea); ContainerOverlay->enableDropPreview(ContainerDropArea != InvalidDockWidgetArea);
if (DockArea && DockArea->isVisible() && VisibleDockAreas >= 0 && DockArea != ContentSourceArea) if (DockArea && DockArea->isVisible() && VisibleDockAreas >= 0 && DockArea != ContentSourceArea)
{ {
@ -259,6 +281,7 @@ CFloatingDragPreview::CFloatingDragPreview(QWidget* Content, QWidget* parent) :
d(new FloatingDragPreviewPrivate(this)) d(new FloatingDragPreviewPrivate(this))
{ {
d->Content = Content; d->Content = Content;
d->ContentFeatures = d->contentFeatures();
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
if (CDockManager::testConfigFlag(CDockManager::DragPreviewHasWindowFrame)) if (CDockManager::testConfigFlag(CDockManager::DragPreviewHasWindowFrame))
{ {
@ -278,8 +301,6 @@ CFloatingDragPreview::CFloatingDragPreview(QWidget* Content, QWidget* parent) :
setWindowFlags(Flags); setWindowFlags(Flags);
#endif #endif
setWindowOpacity(0.6);
// Create a static image of the widget that should get undocked // Create a static image of the widget that should get undocked
// This is like some kind preview image like it is uses in drag and drop // This is like some kind preview image like it is uses in drag and drop
// operations // operations
@ -437,6 +458,7 @@ void CFloatingDragPreview::paintEvent(QPaintEvent* event)
} }
QPainter painter(this); QPainter painter(this);
painter.setOpacity(0.6);
if (CDockManager::testConfigFlag(CDockManager::DragPreviewShowsContentPixmap)) if (CDockManager::testConfigFlag(CDockManager::DragPreviewShowsContentPixmap))
{ {
painter.drawPixmap(QPoint(0, 0), d->ContentPreviewPixmap); painter.drawPixmap(QPoint(0, 0), d->ContentPreviewPixmap);