a new property: naturalWidth/height

is needed when painting compositions of various elements

svn path=/trunk/KDE/kdebase/runtime/; revision=1204315
This commit is contained in:
Marco Martin 2010-12-06 18:37:31 +00:00
parent 1dcc19c800
commit 6b80b7a199
2 changed files with 33 additions and 1 deletions

View File

@ -31,7 +31,6 @@ SvgItem::SvgItem(QDeclarativeItem *parent)
: QDeclarativeItem(parent) : QDeclarativeItem(parent)
{ {
setFlag(QGraphicsItem::ItemHasNoContents, false); setFlag(QGraphicsItem::ItemHasNoContents, false);
} }
@ -42,6 +41,7 @@ SvgItem::~SvgItem()
void SvgItem::setElementId(const QString &elementID) void SvgItem::setElementId(const QString &elementID)
{ {
m_elementID = elementID; m_elementID = elementID;
emit sizeChanged();
update(); update();
} }
@ -50,6 +50,28 @@ QString SvgItem::elementId() const
return m_elementID; 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) void SvgItem::setSvg(Plasma::Svg *svg)
{ {
if (m_svg) { if (m_svg) {
@ -57,6 +79,8 @@ void SvgItem::setSvg(Plasma::Svg *svg)
} }
m_svg = svg; m_svg = svg;
connect(svg, SIGNAL(repaintNeeded()), this, SLOT(update())); connect(svg, SIGNAL(repaintNeeded()), this, SLOT(update()));
connect(svg, SIGNAL(repaintNeeded()), this, SLOT(sizeChanged()));
emit sizeChanged();
} }
Plasma::Svg *SvgItem::svg() const Plasma::Svg *SvgItem::svg() const

View File

@ -31,6 +31,8 @@ class SvgItem : public QDeclarativeItem
Q_PROPERTY(QString elementId READ elementId WRITE setElementId) Q_PROPERTY(QString elementId READ elementId WRITE setElementId)
Q_PROPERTY(Plasma::Svg * svg READ svg WRITE setSvg) 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: public:
SvgItem(QDeclarativeItem *parent=0); SvgItem(QDeclarativeItem *parent=0);
@ -42,8 +44,14 @@ public:
void setSvg(Plasma::Svg *svg); void setSvg(Plasma::Svg *svg);
Plasma::Svg *svg() const; Plasma::Svg *svg() const;
qreal naturalWidth() const;
qreal naturalHeight() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
Q_SIGNALS:
void sizeChanged();
private: private:
QWeakPointer<Plasma::Svg> m_svg; QWeakPointer<Plasma::Svg> m_svg;
QString m_elementID; QString m_elementID;