From 329ba8b6ff1193efc715484b0d550d81c246d4d4 Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Tue, 7 Mar 2017 18:29:37 +0200 Subject: [PATCH] fix #126, improve behavior for auto positioning --support also an edge case where a top and left dock overlap each other but there is also a free space in them. This case hasnt been taken into account into the previous implementation --- app/dockview.cpp | 33 ++++++++++++++++++++++++++++++--- app/dockview.h | 1 + 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/app/dockview.cpp b/app/dockview.cpp index 15e16f4bd..96a84e852 100644 --- a/app/dockview.cpp +++ b/app/dockview.cpp @@ -592,9 +592,35 @@ inline void DockView::syncGeometry() if (formFactor() == Plasma::Types::Vertical) { freeRegion = corona()->availableScreenRegion(this->containment()->screen()); maximumRect = maximumNormalGeometry(); + QRegion availableRegion = freeRegion.intersected(maximumRect); availableScreenRect = freeRegion.intersected(maximumRect).boundingRect(); + + float area = 0; + + //! it is used to choose which or the availableRegion rectangles will + //! be the one representing dock geometry + for (int i = 0; i < availableRegion.rectCount(); ++i) { + QRect rect = availableRegion.rects().at(i); + + //! the area of each rectangle in calculated in squares of 50x50 + //! this is a way to avoid enourmous numbers for area value + float tempArea = (float)(rect.width() * rect.height()) / 2500; + + if (tempArea > area) { + availableScreenRect = rect; + area = tempArea; + } + } + + if (availableRegion.rectCount() > 1 && m_drawShadows) + m_forceDrawCenteredBorders = true; + else + m_forceDrawCenteredBorders = false; + } else { + m_forceDrawCenteredBorders = false; } + updateEnabledBorders(); resizeWindow(availableScreenRect); updatePosition(availableScreenRect); @@ -699,6 +725,7 @@ void DockView::setDrawShadows(bool draw) } else { PanelShadows::self()->removeWindow(this); m_enabledBorders = Plasma::FrameSvg::AllBorders; + emit enabledBordersChanged(); } @@ -1298,16 +1325,16 @@ void DockView::updateEnabledBorders() } if ((location() == Plasma::Types::LeftEdge || location() == Plasma::Types::RightEdge)) { - if (maxLength() == 1 && m_alignment == Dock::Justify) { + if (maxLength() == 1 && m_alignment == Dock::Justify && !m_forceDrawCenteredBorders) { borders &= ~Plasma::FrameSvg::TopBorder; borders &= ~Plasma::FrameSvg::BottomBorder; } - if (m_alignment == Dock::Top) { + if (m_alignment == Dock::Top && !m_forceDrawCenteredBorders) { borders &= ~Plasma::FrameSvg::TopBorder; } - if (m_alignment == Dock::Bottom) { + if (m_alignment == Dock::Bottom && !m_forceDrawCenteredBorders) { borders &= ~Plasma::FrameSvg::BottomBorder; } diff --git a/app/dockview.h b/app/dockview.h index 2139300ba..8fe7987a6 100644 --- a/app/dockview.h +++ b/app/dockview.h @@ -193,6 +193,7 @@ private: private: Plasma::Containment *containmentById(uint id); + bool m_forceDrawCenteredBorders{false}; bool m_drawShadows{false}; bool m_onPrimary{true}; int m_maxThickness{24};