From a04a87bcec53cea3607272c0c30576b254bae7c2 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Mon, 24 Feb 2014 16:55:19 +0100 Subject: [PATCH] use units to understand the devicePixelRatio --- src/declarativeimports/core/framesvgitem.cpp | 4 ++-- src/declarativeimports/core/svgitem.cpp | 10 ++++++++++ src/declarativeimports/core/svgitem.h | 1 + src/plasma/svg.cpp | 2 +- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/declarativeimports/core/framesvgitem.cpp b/src/declarativeimports/core/framesvgitem.cpp index f51c9732b..8c0800755 100644 --- a/src/declarativeimports/core/framesvgitem.cpp +++ b/src/declarativeimports/core/framesvgitem.cpp @@ -101,6 +101,7 @@ FrameSvgItem::FrameSvgItem(QQuickItem *parent) m_fixedMargins->setFixed(true); setFlag(ItemHasContents, true); 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() { - m_frameSvg->resize(); - m_frameSvg->resize(m_frameSvg->size() * 5); + m_frameSvg->setDevicePixelRatio(qMax((qreal)1.0, floor(m_units.devicePixelRatio()))); } } // Plasma namespace diff --git a/src/declarativeimports/core/svgitem.cpp b/src/declarativeimports/core/svgitem.cpp index 4ad761a17..6669ada86 100644 --- a/src/declarativeimports/core/svgitem.cpp +++ b/src/declarativeimports/core/svgitem.cpp @@ -34,6 +34,7 @@ SvgItem::SvgItem(QQuickItem *parent) m_smooth(false) { 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); } m_svg = svg; + updateDevicePixelRatio(); + if (svg) { connect(svg, SIGNAL(repaintNeeded()), this, SLOT(updateNeeded())); connect(svg, SIGNAL(repaintNeeded()), this, SIGNAL(naturalSizeChanged())); @@ -181,6 +184,13 @@ qreal SvgItem::implicitHeight() const return QQuickItem::implicitHeight(); } +void SvgItem::updateDevicePixelRatio() +{ + if (m_svg) { + m_svg.data()->setDevicePixelRatio(qMax((qreal)1.0, floor(m_units.devicePixelRatio()))); + } +} + } // Plasma namespace #include "svgitem.moc" diff --git a/src/declarativeimports/core/svgitem.h b/src/declarativeimports/core/svgitem.h index 14c50f60c..05072eb99 100644 --- a/src/declarativeimports/core/svgitem.h +++ b/src/declarativeimports/core/svgitem.h @@ -101,6 +101,7 @@ Q_SIGNALS: protected Q_SLOTS: void updateNeeded(); + void updateDevicePixelRatio(); private: QWeakPointer m_svg; diff --git a/src/plasma/svg.cpp b/src/plasma/svg.cpp index 6d55dc460..5b48f36a3 100644 --- a/src/plasma/svg.cpp +++ b/src/plasma/svg.cpp @@ -137,7 +137,7 @@ SvgPrivate::SvgPrivate(Svg *svg) renderer(0), styleCrc(0), lastModified(0), - devicePixelRatio(2.0), + devicePixelRatio(1.0), multipleImages(false), themed(false), applyColors(false),