From 20e4b7ca355cdd74ba0cf7baea8d173acac40c36 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Mon, 6 Dec 2010 22:19:33 +0000 Subject: [PATCH] smooth property (default off) svn path=/trunk/KDE/kdebase/runtime/; revision=1204366 --- declarativeimports/core/svgitem.cpp | 25 ++++++++++++++++++++++++- declarativeimports/core/svgitem_p.h | 5 +++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/declarativeimports/core/svgitem.cpp b/declarativeimports/core/svgitem.cpp index 961149376..0cb30ef99 100644 --- a/declarativeimports/core/svgitem.cpp +++ b/declarativeimports/core/svgitem.cpp @@ -28,7 +28,8 @@ namespace Plasma { SvgItem::SvgItem(QDeclarativeItem *parent) - : QDeclarativeItem(parent) + : QDeclarativeItem(parent), + m_smooth(false) { setFlag(QGraphicsItem::ItemHasNoContents, false); } @@ -79,6 +80,20 @@ Plasma::Svg *SvgItem::svg() const return m_svg.data(); } +void SvgItem::setSmooth(const bool smooth) +{ + if (smooth == m_smooth) { + return; + } + m_smooth = smooth; + update(); +} + +bool SvgItem::smooth() const +{ + return m_smooth; +} + void SvgItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_UNUSED(option); @@ -87,9 +102,17 @@ void SvgItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, Q if (!m_svg) { return; } + //do without painter save, faster and the support can be compiled out + const bool wasAntiAlias = painter->testRenderHint(QPainter::Antialiasing); + const bool wasSmoothTransform = painter->testRenderHint(QPainter::SmoothPixmapTransform); + painter->setRenderHint(QPainter::Antialiasing, m_smooth); + painter->setRenderHint(QPainter::SmoothPixmapTransform, m_smooth); + //setContainsMultipleImages has to be done there since m_frameSvg can be shared with somebody else m_svg.data()->setContainsMultipleImages(!m_elementID.isEmpty()); m_svg.data()->paint(painter, boundingRect(), m_elementID); + painter->setRenderHint(QPainter::Antialiasing, wasAntiAlias); + painter->setRenderHint(QPainter::SmoothPixmapTransform, wasSmoothTransform); } } // Plasma namespace diff --git a/declarativeimports/core/svgitem_p.h b/declarativeimports/core/svgitem_p.h index 52c6a9d18..25cd4be91 100644 --- a/declarativeimports/core/svgitem_p.h +++ b/declarativeimports/core/svgitem_p.h @@ -32,6 +32,7 @@ class SvgItem : public QDeclarativeItem Q_PROPERTY(QString elementId READ elementId WRITE setElementId) Q_PROPERTY(Plasma::Svg * svg READ svg WRITE setSvg) Q_PROPERTY(QSizeF naturalSize READ naturalSize NOTIFY naturalSizeChanged) + Q_PROPERTY(bool smooth READ smooth WRITE setSmooth) public: SvgItem(QDeclarativeItem *parent=0); @@ -43,6 +44,9 @@ public: void setSvg(Plasma::Svg *svg); Plasma::Svg *svg() const; + void setSmooth(const bool smooth); + bool smooth() const; + QSizeF naturalSize() const; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); @@ -53,6 +57,7 @@ Q_SIGNALS: private: QWeakPointer m_svg; QString m_elementID; + bool m_smooth; }; }