Make sure the FrameSvg and Svg instances have the right devicePixelRatio

Summary:
On wayland (at least) it's initialized when the window is assigned, so
we need to listen to the itemChanged to adopt it.

Test Plan: manual testing

Reviewers: #plasma, hein

Reviewed By: #plasma, hein

Subscribers: hein, plasma-devel, #frameworks

Tags: #plasma, #frameworks

Differential Revision: https://phabricator.kde.org/D10420
This commit is contained in:
Aleix Pol 2018-02-10 01:25:13 +01:00
parent 9bbba13099
commit 3e4b26452a
3 changed files with 18 additions and 7 deletions

View File

@ -612,15 +612,16 @@ void FrameSvgItem::componentComplete()
void FrameSvgItem::updateDevicePixelRatio()
{
m_frameSvg->setScaleFactor(qMax<qreal>(1.0, floor(Units::instance().devicePixelRatio())));
//devicepixelratio is always set integer in the svg, so needs at least 192dpi to double up.
//(it needs to be integer to have lines contained inside a svg piece to keep being pixel aligned)
if (window()) {
m_frameSvg->setDevicePixelRatio(qMax<qreal>(1.0, floor(window()->devicePixelRatio())));
} else {
m_frameSvg->setDevicePixelRatio(qMax<qreal>(1.0, floor(qApp->devicePixelRatio())));
}
m_frameSvg->setScaleFactor(qMax<qreal>(1.0, floor(Units::instance().devicePixelRatio())));
const auto newDevicePixelRation = qMax<qreal>(1.0, floor(window() ? window()->devicePixelRatio() : qApp->devicePixelRatio()));
if (newDevicePixelRation != m_frameSvg->devicePixelRatio()) {
m_frameSvg->setDevicePixelRatio(qMax<qreal>(1.0, newDevicePixelRation));
m_textureChanged = true;
}
}
void FrameSvgItem::applyPrefixes()
@ -657,5 +658,14 @@ void FrameSvgItem::applyPrefixes()
}
}
void FrameSvgItem::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData & value)
{
if (change == ItemSceneChange && value.window) {
updateDevicePixelRatio();
}
QQuickItem::itemChange(change, value);
}
} // Plasma namespace

View File

@ -227,7 +227,7 @@ public:
QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) Q_DECL_OVERRIDE;
void itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData & data) override;
protected:
void classBegin() Q_DECL_OVERRIDE;

View File

@ -563,6 +563,7 @@ void IconItem::loadPixmap()
update();
return;
} else if (m_svgIcon) {
m_svgIcon->setDevicePixelRatio(window() ? window()->devicePixelRatio() : qApp->devicePixelRatio());
m_svgIcon->resize(size, size);
if (!m_svgIconName.isEmpty() && m_svgIcon->hasElement(m_svgIconName)) {
result = m_svgIcon->pixmap(m_svgIconName);