From 6b80b7a1995016c8e175edc326d753113d8e00ae Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Mon, 6 Dec 2010 18:37:31 +0000 Subject: [PATCH] a new property: naturalWidth/height is needed when painting compositions of various elements svn path=/trunk/KDE/kdebase/runtime/; revision=1204315 --- declarativeimports/core/svgitem.cpp | 26 +++++++++++++++++++++++++- declarativeimports/core/svgitem_p.h | 8 ++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/declarativeimports/core/svgitem.cpp b/declarativeimports/core/svgitem.cpp index e9d236db8..1b19d4673 100644 --- a/declarativeimports/core/svgitem.cpp +++ b/declarativeimports/core/svgitem.cpp @@ -31,7 +31,6 @@ SvgItem::SvgItem(QDeclarativeItem *parent) : QDeclarativeItem(parent) { setFlag(QGraphicsItem::ItemHasNoContents, false); - } @@ -42,6 +41,7 @@ SvgItem::~SvgItem() void SvgItem::setElementId(const QString &elementID) { m_elementID = elementID; + emit sizeChanged(); update(); } @@ -50,6 +50,28 @@ QString SvgItem::elementId() const return m_elementID; } +qreal SvgItem::naturalWidth() const +{ + if (!m_svg) { + return 0; + } else if (!m_elementID.isEmpty()) { + return m_svg.data()->elementSize(m_elementID).height(); + } else { + return m_svg.data()->size().height(); + } +} + +qreal SvgItem::naturalHeight() const +{ + if (!m_svg) { + return 0; + } else if (!m_elementID.isEmpty()) { + return m_svg.data()->elementSize(m_elementID).width(); + } else { + return m_svg.data()->size().width(); + } +} + void SvgItem::setSvg(Plasma::Svg *svg) { if (m_svg) { @@ -57,6 +79,8 @@ void SvgItem::setSvg(Plasma::Svg *svg) } m_svg = svg; connect(svg, SIGNAL(repaintNeeded()), this, SLOT(update())); + connect(svg, SIGNAL(repaintNeeded()), this, SLOT(sizeChanged())); + emit sizeChanged(); } Plasma::Svg *SvgItem::svg() const diff --git a/declarativeimports/core/svgitem_p.h b/declarativeimports/core/svgitem_p.h index e26ae61ed..11695bca7 100644 --- a/declarativeimports/core/svgitem_p.h +++ b/declarativeimports/core/svgitem_p.h @@ -31,6 +31,8 @@ class SvgItem : public QDeclarativeItem Q_PROPERTY(QString elementId READ elementId WRITE setElementId) Q_PROPERTY(Plasma::Svg * svg READ svg WRITE setSvg) + Q_PROPERTY(qreal naturalWidth READ naturalWidth NOTIFY sizeChanged) + Q_PROPERTY(qreal naturalHeight READ naturalHeight NOTIFY sizeChanged) public: SvgItem(QDeclarativeItem *parent=0); @@ -42,8 +44,14 @@ public: void setSvg(Plasma::Svg *svg); Plasma::Svg *svg() const; + qreal naturalWidth() const; + qreal naturalHeight() const; + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); +Q_SIGNALS: + void sizeChanged(); + private: QWeakPointer m_svg; QString m_elementID;