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
pull/11/head
Michail Vourlakos 5 years ago
parent 5efa757146
commit dd1a7b72c7

@ -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;
}
}

@ -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};

@ -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;

@ -134,6 +134,8 @@ private:
void updateFormFactor();
void updatePosition(QRect availableScreenRect = QRect());
void validateTopBottomBorders(QRect availableScreenRect, QRegion availableScreenRegion);
QRect maximumNormalGeometry();
private:

Loading…
Cancel
Save