FrameSvgItem: catch margin changes of FrameSvg also outside own methods

Summary:
FrameSvg updates the margins e.g. on a Theme change already in its
internal event handling before the methods of FrameSvgItem are invoked.
Due to that CheckMarginsChange guards before this change could not detect
any changes, and thus missed to trigger an update via the margin objects
to the QtQuick world.

So when changing the theme e.g. in a Plasma shell or in the Plasma Theme
Explorer, existing FrameSvg items are using outdated margins, resulting
in broken display.

By keeping a copy of the last seen margins as part of the item and not only
per method, changes outside the FrameSvgItem items can be properly detected.

Test Plan:
Switch Plasma themes between Air, Breeze & Oxygen, see how different margins
are reflected in the widgets sizes instantly.
Switch Plasma themes in the Plasma Theme Explorer, with "Show Margins"
enabled, see how margins are always correctly updated intead of taking the
value of the last theme used.

Reviewers: #plasma, mart

Reviewed By: #plasma, mart

Subscribers: kde-frameworks-devel

Tags: #frameworks

Differential Revision: https://phabricator.kde.org/D19743
This commit is contained in:
Friedrich W. H. Kossebau 2019-03-14 00:21:54 +01:00
parent fb1a332948
commit 5f4f88ad66
2 changed files with 24 additions and 16 deletions

View File

@ -281,18 +281,23 @@ FrameSvgItem::~FrameSvgItem()
class CheckMarginsChange
{
public:
CheckMarginsChange(FrameSvgItemMargins *margins)
: m_oldMargins(margins ? margins->margins() : QVector<qreal>()), m_margins(margins)
CheckMarginsChange(QVector<qreal>& oldMargins, FrameSvgItemMargins *marginsObject)
: m_oldMargins(oldMargins), m_marginsObject(marginsObject)
{}
~CheckMarginsChange() {
if (m_margins && m_margins->margins() != m_oldMargins) {
m_margins->update();
~CheckMarginsChange()
{
const QVector<qreal> oldMarginsBefore = m_oldMargins;
m_oldMargins = m_marginsObject ? m_marginsObject->margins() : QVector<qreal>();
if (oldMarginsBefore != m_oldMargins) {
m_marginsObject->update();
}
}
const QVector<qreal> m_oldMargins;
FrameSvgItemMargins *const m_margins;
private:
QVector<qreal>& m_oldMargins;
FrameSvgItemMargins *const m_marginsObject;
};
void FrameSvgItem::setImagePath(const QString &path)
@ -301,8 +306,8 @@ void FrameSvgItem::setImagePath(const QString &path)
return;
}
CheckMarginsChange checkMargins(m_margins);
CheckMarginsChange checkFixedMargins(m_fixedMargins);
CheckMarginsChange checkMargins(m_oldMargins, m_margins);
CheckMarginsChange checkFixedMargins(m_oldFixedMargins, m_fixedMargins);
updateDevicePixelRatio();
m_frameSvg->setImagePath(path);
@ -345,8 +350,8 @@ void FrameSvgItem::setPrefix(const QVariant &prefixes)
return;
}
CheckMarginsChange checkMargins(m_margins);
CheckMarginsChange checkFixedMargins(m_fixedMargins);
CheckMarginsChange checkMargins(m_oldMargins, m_margins);
CheckMarginsChange checkFixedMargins(m_oldFixedMargins, m_fixedMargins);
m_prefixes = prefixList;
applyPrefixes();
@ -432,7 +437,7 @@ void FrameSvgItem::setEnabledBorders(const Plasma::FrameSvg::EnabledBorders bord
return;
}
CheckMarginsChange checkMargins(m_margins);
CheckMarginsChange checkMargins(m_oldMargins, m_margins);
m_frameSvg->setEnabledBorders(borders);
emit enabledBordersChanged();
@ -466,8 +471,8 @@ void FrameSvgItem::doUpdate()
return;
}
CheckMarginsChange checkMargins(m_margins);
CheckMarginsChange checkFixedMargins(m_fixedMargins);
CheckMarginsChange checkMargins(m_oldMargins, m_margins);
CheckMarginsChange checkFixedMargins(m_oldFixedMargins, m_fixedMargins);
//if the theme changed, the available prefix may have changed as well
applyPrefixes();
@ -601,8 +606,8 @@ void FrameSvgItem::classBegin()
void FrameSvgItem::componentComplete()
{
CheckMarginsChange checkMargins(m_margins);
CheckMarginsChange checkFixedMargins(m_fixedMargins);
CheckMarginsChange checkMargins(m_oldMargins, m_margins);
CheckMarginsChange checkFixedMargins(m_oldFixedMargins, m_fixedMargins);
QQuickItem::componentComplete();
m_frameSvg->resizeFrame(QSize(width(), height()));

View File

@ -255,6 +255,9 @@ private:
Plasma::FrameSvg *m_frameSvg;
FrameSvgItemMargins *m_margins;
FrameSvgItemMargins *m_fixedMargins;
// logged margins to check for changes
QVector<qreal> m_oldMargins;
QVector<qreal> m_oldFixedMargins;
QStringList m_prefixes;
bool m_textureChanged;
bool m_sizeChanged;