From dd1a7b72c7ee79145344ef5f24def3de5ebdecf8 Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Mon, 2 Mar 2020 18:44:40 +0200 Subject: [PATCH] validate top/bottom borders for vertical panels --make the top/bottom borders identification much smarter in order to identify in they must be drawn. There are many corner cases that these borders should be drawn, for example when a vertical top aligned panel is half shown its top border because of a top panel --- app/view/effects.cpp | 31 +++++++++++++++++-------- app/view/effects.h | 7 +++--- app/view/positioner.cpp | 51 ++++++++++++++++++++++++++++++++++++++++- app/view/positioner.h | 2 ++ 4 files changed, 77 insertions(+), 14 deletions(-) diff --git a/app/view/effects.cpp b/app/view/effects.cpp index 9cbfe1bcb..83645725d 100644 --- a/app/view/effects.cpp +++ b/app/view/effects.cpp @@ -135,18 +135,24 @@ void Effects::setDrawEffects(bool draw) emit drawEffectsChanged(); } -bool Effects::forceDrawCenteredBorders() const +void Effects::setForceBottomBorder(bool draw) { - return m_forceDrawCenteredBorders; + if (m_forceBottomBorder == draw) { + return; + } + + m_forceBottomBorder = draw; + updateEnabledBorders(); } -void Effects::setForceDrawCenteredBorders(bool draw) +void Effects::setForceTopBorder(bool draw) { - if (m_forceDrawCenteredBorders == draw) { + if (m_forceTopBorder == draw) { return; } - m_forceDrawCenteredBorders = draw; + m_forceTopBorder = draw; + updateEnabledBorders(); } int Effects::backgroundOpacity() const @@ -519,16 +525,21 @@ void Effects::updateEnabledBorders() } if ((m_view->location() == Plasma::Types::LeftEdge || m_view->location() == Plasma::Types::RightEdge)) { - if (m_view->maxLength() == 1 && m_view->alignment() == Latte::Types::Justify && !m_forceDrawCenteredBorders) { - borders &= ~Plasma::FrameSvg::TopBorder; - borders &= ~Plasma::FrameSvg::BottomBorder; + if (m_view->maxLength() == 1 && m_view->alignment() == Latte::Types::Justify) { + if (!m_forceTopBorder) { + borders &= ~Plasma::FrameSvg::TopBorder; + } + + if (!m_forceBottomBorder) { + borders &= ~Plasma::FrameSvg::BottomBorder; + } } - if (m_view->alignment() == Latte::Types::Top && !m_forceDrawCenteredBorders && m_view->offset() == 0) { + if (m_view->alignment() == Latte::Types::Top && !m_forceTopBorder && m_view->offset() == 0) { borders &= ~Plasma::FrameSvg::TopBorder; } - if (m_view->alignment() == Latte::Types::Bottom && !m_forceDrawCenteredBorders && m_view->offset() == 0) { + if (m_view->alignment() == Latte::Types::Bottom && !m_forceBottomBorder && m_view->offset() == 0) { borders &= ~Plasma::FrameSvg::BottomBorder; } } diff --git a/app/view/effects.h b/app/view/effects.h index 5b5422d47..4aa87a8b3 100644 --- a/app/view/effects.h +++ b/app/view/effects.h @@ -68,8 +68,8 @@ public: bool drawEffects() const; void setDrawEffects(bool draw); - bool forceDrawCenteredBorders() const; - void setForceDrawCenteredBorders(bool draw); + void setForceTopBorder(bool draw); + void setForceBottomBorder(bool draw); bool settingsMaskSubtracted() const; void setSettingsMaskSubtracted(bool enabled); @@ -127,7 +127,8 @@ private: bool m_animationsBlocked{false}; bool m_drawShadows{true}; bool m_drawEffects{false}; - bool m_forceDrawCenteredBorders{false}; + bool m_forceTopBorder{false}; + bool m_forceBottomBorder{false}; bool m_settingsMaskSubtracted{false}; int m_backgroundOpacity{100}; diff --git a/app/view/positioner.cpp b/app/view/positioner.cpp index 4d9160cbb..e2b81def7 100644 --- a/app/view/positioner.cpp +++ b/app/view/positioner.cpp @@ -158,6 +158,12 @@ void Positioner::init() } }); + connect(m_view, &Latte::View::screenEdgeMarginChanged, this, [&]() { + if (m_view->screenEdgeMarginEnabled() && m_view->inEditMode()) { + syncGeometry(); + } + }); + connect(m_view->effects(), &Latte::ViewPart::Effects::drawShadowsChanged, this, [&]() { if (!m_view->behaveAsPlasmaPanel()) { syncGeometry(); @@ -452,6 +458,11 @@ void Positioner::syncGeometry() area = tempArea; } } + + validateTopBottomBorders(availableScreenRect, freeRegion); + } else { + m_view->effects()->setForceTopBorder(false); + m_view->effects()->setForceBottomBorder(false); } m_view->effects()->updateEnabledBorders(); @@ -518,6 +529,44 @@ QRect Positioner::maximumNormalGeometry() return maxGeometry; } +void Positioner::validateTopBottomBorders(QRect availableScreenRect, QRegion availableScreenRegion) +{ + //! Check if the the top/bottom borders must be drawn also + int edgeMargin = qMax(1, m_view->screenEdgeMargin()); + + if (availableScreenRect.top() != m_view->screenGeometry().top()) { + //! check top border + QRegion fitInRegion = QRect(m_view->screenGeometry().x(), availableScreenRect.y()-1, edgeMargin, 1); + QRegion subtracted = fitInRegion.subtracted(availableScreenRegion); + + if (subtracted.isNull()) { + //!FitIn rectangle fits TOTALLY in the free screen region and as such + //!the top border should be drawn + m_view->effects()->setForceTopBorder(true); + } else { + m_view->effects()->setForceTopBorder(false); + } + } else { + m_view->effects()->setForceTopBorder(false); + } + + if (availableScreenRect.bottom() != m_view->screenGeometry().bottom()) { + //! check top border + QRegion fitInRegion = QRect(m_view->screenGeometry().x(), availableScreenRect.bottom()+1, edgeMargin, 1); + QRegion subtracted = fitInRegion.subtracted(availableScreenRegion); + + if (subtracted.isNull()) { + //!FitIn rectangle fits TOTALLY in the free screen region and as such + //!the BOTTOM border should be drawn + m_view->effects()->setForceBottomBorder(true); + } else { + m_view->effects()->setForceBottomBorder(false); + } + } else { + m_view->effects()->setForceBottomBorder(false); + } +} + void Positioner::updatePosition(QRect availableScreenRect) { QRect screenGeometry{availableScreenRect}; @@ -785,7 +834,7 @@ bool Positioner::isStickedOnTopEdge() const void Positioner::setIsStickedOnTopEdge(bool sticked) { if (m_isStickedOnTopEdge == sticked) { - return; + return; } m_isStickedOnTopEdge = sticked; diff --git a/app/view/positioner.h b/app/view/positioner.h index 2988ee61f..4fb50310e 100644 --- a/app/view/positioner.h +++ b/app/view/positioner.h @@ -134,6 +134,8 @@ private: void updateFormFactor(); void updatePosition(QRect availableScreenRect = QRect()); + void validateTopBottomBorders(QRect availableScreenRect, QRegion availableScreenRegion); + QRect maximumNormalGeometry(); private: