use units to understand the devicePixelRatio

This commit is contained in:
Marco Martin 2014-02-24 16:55:19 +01:00
parent c009c7f0cd
commit a04a87bcec
4 changed files with 14 additions and 3 deletions

View File

@ -101,6 +101,7 @@ FrameSvgItem::FrameSvgItem(QQuickItem *parent)
m_fixedMargins->setFixed(true); m_fixedMargins->setFixed(true);
setFlag(ItemHasContents, true); setFlag(ItemHasContents, true);
connect(m_frameSvg, SIGNAL(repaintNeeded()), this, SLOT(doUpdate())); connect(m_frameSvg, SIGNAL(repaintNeeded()), this, SLOT(doUpdate()));
connect(&m_units, &Units::devicePixelRatioChanged, this, &FrameSvgItem::updateDevicePixelRatio);
} }
@ -270,8 +271,7 @@ void FrameSvgItem::componentComplete()
void FrameSvgItem::updateDevicePixelRatio() void FrameSvgItem::updateDevicePixelRatio()
{ {
m_frameSvg->resize(); m_frameSvg->setDevicePixelRatio(qMax((qreal)1.0, floor(m_units.devicePixelRatio())));
m_frameSvg->resize(m_frameSvg->size() * 5);
} }
} // Plasma namespace } // Plasma namespace

View File

@ -34,6 +34,7 @@ SvgItem::SvgItem(QQuickItem *parent)
m_smooth(false) m_smooth(false)
{ {
setFlag(QQuickItem::ItemHasContents, true); setFlag(QQuickItem::ItemHasContents, true);
connect(&m_units, &Units::devicePixelRatioChanged, this, &SvgItem::updateDevicePixelRatio);
} }
@ -83,6 +84,8 @@ void SvgItem::setSvg(Plasma::Svg *svg)
disconnect(m_svg.data(), 0, this, 0); disconnect(m_svg.data(), 0, this, 0);
} }
m_svg = svg; m_svg = svg;
updateDevicePixelRatio();
if (svg) { if (svg) {
connect(svg, SIGNAL(repaintNeeded()), this, SLOT(updateNeeded())); connect(svg, SIGNAL(repaintNeeded()), this, SLOT(updateNeeded()));
connect(svg, SIGNAL(repaintNeeded()), this, SIGNAL(naturalSizeChanged())); connect(svg, SIGNAL(repaintNeeded()), this, SIGNAL(naturalSizeChanged()));
@ -181,6 +184,13 @@ qreal SvgItem::implicitHeight() const
return QQuickItem::implicitHeight(); return QQuickItem::implicitHeight();
} }
void SvgItem::updateDevicePixelRatio()
{
if (m_svg) {
m_svg.data()->setDevicePixelRatio(qMax((qreal)1.0, floor(m_units.devicePixelRatio())));
}
}
} // Plasma namespace } // Plasma namespace
#include "svgitem.moc" #include "svgitem.moc"

View File

@ -101,6 +101,7 @@ Q_SIGNALS:
protected Q_SLOTS: protected Q_SLOTS:
void updateNeeded(); void updateNeeded();
void updateDevicePixelRatio();
private: private:
QWeakPointer<Plasma::Svg> m_svg; QWeakPointer<Plasma::Svg> m_svg;

View File

@ -137,7 +137,7 @@ SvgPrivate::SvgPrivate(Svg *svg)
renderer(0), renderer(0),
styleCrc(0), styleCrc(0),
lastModified(0), lastModified(0),
devicePixelRatio(2.0), devicePixelRatio(1.0),
multipleImages(false), multipleImages(false),
themed(false), themed(false),
applyColors(false), applyColors(false),