experimental devicePixelRatio in Plasma::Svg
Conflicts: src/declarativeimports/core/framesvgitem.cpp
This commit is contained in:
parent
8c65f60de5
commit
17332257d7
@ -82,6 +82,7 @@ void FrameSvgItem::setImagePath(const QString &path)
|
|||||||
|
|
||||||
m_frameSvg->setImagePath(path);
|
m_frameSvg->setImagePath(path);
|
||||||
m_frameSvg->setElementPrefix(m_prefix);
|
m_frameSvg->setElementPrefix(m_prefix);
|
||||||
|
updateDevicePixelRatio();
|
||||||
|
|
||||||
if (implicitWidth() <= 0) {
|
if (implicitWidth() <= 0) {
|
||||||
setImplicitWidth(m_frameSvg->marginSize(Plasma::Types::LeftMargin) + m_frameSvg->marginSize(Plasma::Types::RightMargin));
|
setImplicitWidth(m_frameSvg->marginSize(Plasma::Types::LeftMargin) + m_frameSvg->marginSize(Plasma::Types::RightMargin));
|
||||||
@ -228,6 +229,12 @@ void FrameSvgItem::componentComplete()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void FrameSvgItem::updateDevicePixelRatio()
|
||||||
|
{
|
||||||
|
m_frameSvg->resize();
|
||||||
|
m_frameSvg->resize(m_frameSvg->size() * 5);
|
||||||
|
}
|
||||||
|
|
||||||
} // Plasma namespace
|
} // Plasma namespace
|
||||||
|
|
||||||
#include "framesvgitem.moc"
|
#include "framesvgitem.moc"
|
||||||
|
@ -23,6 +23,8 @@
|
|||||||
|
|
||||||
#include <Plasma/FrameSvg>
|
#include <Plasma/FrameSvg>
|
||||||
|
|
||||||
|
#include "units.h"
|
||||||
|
|
||||||
namespace Plasma {
|
namespace Plasma {
|
||||||
|
|
||||||
class FrameSvg;
|
class FrameSvg;
|
||||||
@ -155,11 +157,13 @@ Q_SIGNALS:
|
|||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void doUpdate();
|
void doUpdate();
|
||||||
|
void updateDevicePixelRatio();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Plasma::FrameSvg *m_frameSvg;
|
Plasma::FrameSvg *m_frameSvg;
|
||||||
FrameSvgItemMargins *m_margins;
|
FrameSvgItemMargins *m_margins;
|
||||||
QString m_prefix;
|
QString m_prefix;
|
||||||
|
Units m_units;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,8 @@
|
|||||||
|
|
||||||
#include "svgitem.h"
|
#include "svgitem.h"
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QDesktopWidget>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
#include "QDebug"
|
#include "QDebug"
|
||||||
@ -68,10 +70,10 @@ QSizeF SvgItem::naturalSize() const
|
|||||||
if (!m_svg) {
|
if (!m_svg) {
|
||||||
return QSizeF();
|
return QSizeF();
|
||||||
} else if (!m_elementID.isEmpty()) {
|
} else if (!m_elementID.isEmpty()) {
|
||||||
return m_svg.data()->elementSize(m_elementID);
|
return m_svg.data()->elementSize(m_elementID) * floor(m_units.devicePixelRatio());
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_svg.data()->size();
|
return m_svg.data()->size() * floor(m_units.devicePixelRatio());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
|
|
||||||
#include <QQuickPaintedItem>
|
#include <QQuickPaintedItem>
|
||||||
|
|
||||||
|
#include "units.h"
|
||||||
|
|
||||||
namespace Plasma {
|
namespace Plasma {
|
||||||
|
|
||||||
class Svg;
|
class Svg;
|
||||||
@ -104,6 +106,7 @@ private:
|
|||||||
QWeakPointer<Plasma::Svg> m_svg;
|
QWeakPointer<Plasma::Svg> m_svg;
|
||||||
QString m_elementID;
|
QString m_elementID;
|
||||||
bool m_smooth;
|
bool m_smooth;
|
||||||
|
Units m_units;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,6 +107,7 @@ public:
|
|||||||
QSizeF naturalSize;
|
QSizeF naturalSize;
|
||||||
QChar styleCrc;
|
QChar styleCrc;
|
||||||
unsigned int lastModified;
|
unsigned int lastModified;
|
||||||
|
qreal devicePixelRatio;
|
||||||
bool multipleImages : 1;
|
bool multipleImages : 1;
|
||||||
bool themed : 1;
|
bool themed : 1;
|
||||||
bool applyColors : 1;
|
bool applyColors : 1;
|
||||||
|
@ -129,14 +129,15 @@ bool SharedSvgRenderer::load(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define QLSEP QLatin1Char('_')
|
#define QLSEP QLatin1Char('_')
|
||||||
#define CACHE_ID_WITH_SIZE(size, id) QString::number(int(size.width())) % QLSEP % QString::number(int(size.height())) % QLSEP % id
|
#define CACHE_ID_WITH_SIZE(size, id, devicePixelRatio) QString::number(int(size.width())) % QLSEP % QString::number(int(size.height())) % QLSEP % id % QLSEP % QString::number(int(devicePixelRatio))
|
||||||
#define CACHE_ID_NATURAL_SIZE(id) QLatin1Literal("Natural") % QLSEP % id
|
#define CACHE_ID_NATURAL_SIZE(id, devicePixelRatio) QLatin1Literal("Natural") % QLSEP % id % QLSEP % QString::number(int(devicePixelRatio))
|
||||||
|
|
||||||
SvgPrivate::SvgPrivate(Svg *svg)
|
SvgPrivate::SvgPrivate(Svg *svg)
|
||||||
: q(svg),
|
: q(svg),
|
||||||
renderer(0),
|
renderer(0),
|
||||||
styleCrc(0),
|
styleCrc(0),
|
||||||
lastModified(0),
|
lastModified(0),
|
||||||
|
devicePixelRatio(2.0),
|
||||||
multipleImages(false),
|
multipleImages(false),
|
||||||
themed(false),
|
themed(false),
|
||||||
applyColors(false),
|
applyColors(false),
|
||||||
@ -155,16 +156,16 @@ SvgPrivate::~SvgPrivate()
|
|||||||
QString SvgPrivate::cacheId(const QString &elementId)
|
QString SvgPrivate::cacheId(const QString &elementId)
|
||||||
{
|
{
|
||||||
if (size.isValid() && size != naturalSize) {
|
if (size.isValid() && size != naturalSize) {
|
||||||
return CACHE_ID_WITH_SIZE(size, elementId);
|
return CACHE_ID_WITH_SIZE(size, elementId, devicePixelRatio);
|
||||||
} else {
|
} else {
|
||||||
return CACHE_ID_NATURAL_SIZE(elementId);
|
return CACHE_ID_NATURAL_SIZE(elementId, devicePixelRatio);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//This function is meant for the pixmap cache
|
//This function is meant for the pixmap cache
|
||||||
QString SvgPrivate::cachePath(const QString &path, const QSize &size)
|
QString SvgPrivate::cachePath(const QString &path, const QSize &size)
|
||||||
{
|
{
|
||||||
return CACHE_ID_WITH_SIZE(size, path);
|
return CACHE_ID_WITH_SIZE(size, path, devicePixelRatio);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SvgPrivate::setImagePath(const QString &imagePath)
|
bool SvgPrivate::setImagePath(const QString &imagePath)
|
||||||
@ -221,7 +222,7 @@ bool SvgPrivate::setImagePath(const QString &imagePath)
|
|||||||
naturalSize = rect.size();
|
naturalSize = rect.size();
|
||||||
} else {
|
} else {
|
||||||
createRenderer();
|
createRenderer();
|
||||||
naturalSize = renderer->defaultSize();
|
naturalSize = renderer->defaultSize() * devicePixelRatio;
|
||||||
//qDebug() << "natural size for" << path << "from renderer is" << naturalSize;
|
//qDebug() << "natural size for" << path << "from renderer is" << naturalSize;
|
||||||
cacheAndColorsTheme()->insertIntoRectsCache(path, "_Natural", QRectF(QPointF(0,0), naturalSize));
|
cacheAndColorsTheme()->insertIntoRectsCache(path, "_Natural", QRectF(QPointF(0,0), naturalSize));
|
||||||
//qDebug() << "natural size for" << path << "from cache is" << naturalSize;
|
//qDebug() << "natural size for" << path << "from cache is" << naturalSize;
|
||||||
@ -271,7 +272,7 @@ QPixmap SvgPrivate::findInCache(const QString &elementId, const QSizeF &s)
|
|||||||
if (elementsWithSizeHints.isEmpty()) {
|
if (elementsWithSizeHints.isEmpty()) {
|
||||||
// Fetch all size hinted element ids from the theme's rect cache
|
// Fetch all size hinted element ids from the theme's rect cache
|
||||||
// and store them locally.
|
// and store them locally.
|
||||||
QRegExp sizeHintedKeyExpr(CACHE_ID_NATURAL_SIZE("(\\d+)-(\\d+)-(.+)"));
|
QRegExp sizeHintedKeyExpr(CACHE_ID_NATURAL_SIZE("(\\d+)-(\\d+)-(.+)", devicePixelRatio));
|
||||||
|
|
||||||
foreach (const QString &key, cacheAndColorsTheme()->listCachedRectKeys(path)) {
|
foreach (const QString &key, cacheAndColorsTheme()->listCachedRectKeys(path)) {
|
||||||
if (sizeHintedKeyExpr.exactMatch(key)) {
|
if (sizeHintedKeyExpr.exactMatch(key)) {
|
||||||
@ -438,7 +439,7 @@ void SvgPrivate::createRenderer()
|
|||||||
const QString &elementId = i.key();
|
const QString &elementId = i.key();
|
||||||
const QRectF &elementRect = i.value();
|
const QRectF &elementRect = i.value();
|
||||||
|
|
||||||
const QString cacheId = CACHE_ID_NATURAL_SIZE(elementId);
|
const QString cacheId = CACHE_ID_NATURAL_SIZE(elementId, devicePixelRatio);
|
||||||
localRectCache.insert(cacheId, elementRect);
|
localRectCache.insert(cacheId, elementRect);
|
||||||
cacheAndColorsTheme()->insertIntoRectsCache(path, cacheId, elementRect);
|
cacheAndColorsTheme()->insertIntoRectsCache(path, cacheId, elementRect);
|
||||||
}
|
}
|
||||||
@ -513,12 +514,12 @@ QRectF SvgPrivate::findAndCacheElementRect(const QString &elementId)
|
|||||||
QRectF elementRect = renderer->elementExists(elementId) ?
|
QRectF elementRect = renderer->elementExists(elementId) ?
|
||||||
renderer->matrixForElement(elementId).map(renderer->boundsOnElement(elementId)).boundingRect() :
|
renderer->matrixForElement(elementId).map(renderer->boundsOnElement(elementId)).boundingRect() :
|
||||||
QRectF();
|
QRectF();
|
||||||
naturalSize = renderer->defaultSize();
|
naturalSize = renderer->defaultSize() * devicePixelRatio;
|
||||||
qreal dx = size.width() / naturalSize.width();
|
qreal dx = size.width() / naturalSize.width();
|
||||||
qreal dy = size.height() / naturalSize.height();
|
qreal dy = size.height() / naturalSize.height();
|
||||||
|
|
||||||
elementRect = QRectF(elementRect.x() * dx, elementRect.y() * dy,
|
elementRect = QRectF(elementRect.x() * dx, elementRect.y() * dy,
|
||||||
elementRect.width() * dx, elementRect.height() * dy);
|
elementRect.width() * dx * devicePixelRatio, elementRect.height() * dy * devicePixelRatio);
|
||||||
|
|
||||||
cacheAndColorsTheme()->insertIntoRectsCache(path, id, elementRect);
|
cacheAndColorsTheme()->insertIntoRectsCache(path, id, elementRect);
|
||||||
return elementRect;
|
return elementRect;
|
||||||
@ -659,6 +660,23 @@ Svg::~Svg()
|
|||||||
delete d;
|
delete d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Svg::setDevicePixelRatio(qreal ratio)
|
||||||
|
{
|
||||||
|
//be completely integer for now
|
||||||
|
if (floor(d->devicePixelRatio) == floor(ratio)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
d->devicePixelRatio = floor(ratio);
|
||||||
|
emit repaintNeeded();
|
||||||
|
emit sizeChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
qreal Svg::devicePixelRatio()
|
||||||
|
{
|
||||||
|
return d->devicePixelRatio;
|
||||||
|
}
|
||||||
|
|
||||||
QPixmap Svg::pixmap(const QString &elementID)
|
QPixmap Svg::pixmap(const QString &elementID)
|
||||||
{
|
{
|
||||||
if (elementID.isNull() || d->multipleImages) {
|
if (elementID.isNull() || d->multipleImages) {
|
||||||
|
@ -80,6 +80,19 @@ class PLASMA_EXPORT Svg : public QObject
|
|||||||
explicit Svg(QObject *parent = 0);
|
explicit Svg(QObject *parent = 0);
|
||||||
~Svg();
|
~Svg();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the device pixel ratio for the Svg. This is the ratio between
|
||||||
|
* image pixels and device-independent pixels.
|
||||||
|
* The default value is 1.0.
|
||||||
|
* Setting it to something more, will make all the elements of this svg appear bigger.
|
||||||
|
*/
|
||||||
|
void setDevicePixelRatio(qreal ratio);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the device pixel ratio for this Svg.
|
||||||
|
*/
|
||||||
|
qreal devicePixelRatio();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a pixmap of the SVG represented by this object.
|
* Returns a pixmap of the SVG represented by this object.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user