From 3d21d43182064ed72378960bb9ee50eb0cb09f12 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Tue, 27 Nov 2012 13:33:50 +0100 Subject: [PATCH] set default meaningful implicitWidth/height svgItem has naturalSize as implicit size framesvgitem has the sum of their borders --- declarativeimports/core/framesvgitem.cpp | 56 ++++++++++++++++++++++++ declarativeimports/core/framesvgitem.h | 18 ++++++++ declarativeimports/core/iconitem.h | 1 + declarativeimports/core/svgitem.cpp | 53 ++++++++++++++++++++++ declarativeimports/core/svgitem.h | 18 ++++++++ 5 files changed, 146 insertions(+) diff --git a/declarativeimports/core/framesvgitem.cpp b/declarativeimports/core/framesvgitem.cpp index 24c4b0a37..b313da1bc 100644 --- a/declarativeimports/core/framesvgitem.cpp +++ b/declarativeimports/core/framesvgitem.cpp @@ -83,6 +83,14 @@ void FrameSvgItem::setImagePath(const QString &path) m_frameSvg->setImagePath(path); m_frameSvg->setElementPrefix(m_prefix); + if (implicitWidth() <= 0) { + setImplicitWidth(m_frameSvg->marginSize(Plasma::LeftMargin) + m_frameSvg->marginSize(Plasma::RightMargin)); + } + + if (implicitHeight() <= 0) { + setImplicitHeight(m_frameSvg->marginSize(Plasma::TopMargin) + m_frameSvg->marginSize(Plasma::BottomMargin)); + } + emit imagePathChanged(); update(); } @@ -102,6 +110,14 @@ void FrameSvgItem::setPrefix(const QString &prefix) m_frameSvg->setElementPrefix(prefix); m_prefix = prefix; + if (implicitWidth() <= 0) { + setImplicitWidth(m_frameSvg->marginSize(Plasma::LeftMargin) + m_frameSvg->marginSize(Plasma::RightMargin)); + } + + if (implicitHeight() <= 0) { + setImplicitHeight(m_frameSvg->marginSize(Plasma::TopMargin) + m_frameSvg->marginSize(Plasma::BottomMargin)); + } + emit prefixChanged(); m_margins->update(); update(); @@ -148,9 +164,49 @@ void FrameSvgItem::geometryChanged(const QRectF &newGeometry, void FrameSvgItem::doUpdate() { + if (implicitWidth() <= 0) { + setImplicitWidth(m_frameSvg->marginSize(Plasma::LeftMargin) + m_frameSvg->marginSize(Plasma::RightMargin)); + } + + if (implicitHeight() <= 0) { + setImplicitHeight(m_frameSvg->marginSize(Plasma::TopMargin) + m_frameSvg->marginSize(Plasma::BottomMargin)); + } + update(); } +void FrameSvgItem::setImplicitWidth(qreal width) +{ + if (implicitWidth() == width) { + return; + } + + QDeclarativeItem::setImplicitWidth(width); + + emit implicitWidthChanged(); +} + +qreal FrameSvgItem::implicitWidth() const +{ + return QDeclarativeItem::implicitWidth(); +} + +void FrameSvgItem::setImplicitHeight(qreal height) +{ + if (implicitHeight() == height) { + return; + } + + QDeclarativeItem::setImplicitHeight(height); + + emit implicitHeightChanged(); +} + +qreal FrameSvgItem::implicitHeight() const +{ + return QDeclarativeItem::implicitHeight(); +} + } // Plasma namespace #include "framesvgitem.moc" diff --git a/declarativeimports/core/framesvgitem.h b/declarativeimports/core/framesvgitem.h index f313f1072..6d8b7a1de 100644 --- a/declarativeimports/core/framesvgitem.h +++ b/declarativeimports/core/framesvgitem.h @@ -102,6 +102,16 @@ class FrameSvgItem : public QDeclarativeItem */ Q_PROPERTY(Plasma::FrameSvg::EnabledBorders enabledBorders READ enabledBorders WRITE setEnabledBorders NOTIFY enabledBordersChanged) + /** + * suggested default size hint for width + */ + Q_PROPERTY(qreal implicitWidth READ implicitWidth WRITE setImplicitWidth NOTIFY implicitWidthChanged) + + /** + * suggested default size hint for height + */ + Q_PROPERTY(qreal implicitHeight READ implicitHeight WRITE setImplicitHeight NOTIFY implicitHeightChanged) + public: FrameSvgItem(QDeclarativeItem *parent=0); ~FrameSvgItem(); @@ -122,10 +132,18 @@ public: void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); + void setImplicitWidth(qreal width); + qreal implicitWidth() const; + + void setImplicitHeight(qreal height); + qreal implicitHeight() const; + signals: void imagePathChanged(); void prefixChanged(); void enabledBordersChanged(); + void implicitWidthChanged(); + void implicitHeightChanged(); private Q_SLOTS: void doUpdate(); diff --git a/declarativeimports/core/iconitem.h b/declarativeimports/core/iconitem.h index b5c14b078..9f0677918 100644 --- a/declarativeimports/core/iconitem.h +++ b/declarativeimports/core/iconitem.h @@ -54,6 +54,7 @@ public: void setImplicitWidth(qreal width); qreal implicitWidth() const; + void setImplicitHeight(qreal height); qreal implicitHeight() const; diff --git a/declarativeimports/core/svgitem.cpp b/declarativeimports/core/svgitem.cpp index 787342353..cfa4a0902 100644 --- a/declarativeimports/core/svgitem.cpp +++ b/declarativeimports/core/svgitem.cpp @@ -45,6 +45,13 @@ void SvgItem::setElementId(const QString &elementID) return; } + if (implicitWidth() <= 0) { + setImplicitWidth(naturalSize().width()); + } + if (implicitHeight() <= 0) { + setImplicitHeight(naturalSize().height()); + } + m_elementID = elementID; emit elementIdChanged(); emit naturalSizeChanged(); @@ -79,6 +86,14 @@ void SvgItem::setSvg(Plasma::Svg *svg) connect(svg, SIGNAL(repaintNeeded()), this, SIGNAL(naturalSizeChanged())); connect(svg, SIGNAL(sizeChanged()), this, SIGNAL(naturalSizeChanged())); } + + if (implicitWidth() <= 0) { + setImplicitWidth(naturalSize().width()); + } + if (implicitHeight() <= 0) { + setImplicitHeight(naturalSize().height()); + } + emit svgChanged(); emit naturalSizeChanged(); } @@ -126,9 +141,47 @@ void SvgItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, Q void SvgItem::updateNeeded() { + if (implicitWidth() <= 0) { + setImplicitWidth(naturalSize().width()); + } + if (implicitHeight() <= 0) { + setImplicitHeight(naturalSize().height()); + } update(); } +void SvgItem::setImplicitWidth(qreal width) +{ + if (implicitWidth() == width) { + return; + } + + QDeclarativeItem::setImplicitWidth(width); + + emit implicitWidthChanged(); +} + +qreal SvgItem::implicitWidth() const +{ + return QDeclarativeItem::implicitWidth(); +} + +void SvgItem::setImplicitHeight(qreal height) +{ + if (implicitHeight() == height) { + return; + } + + QDeclarativeItem::setImplicitHeight(height); + + emit implicitHeightChanged(); +} + +qreal SvgItem::implicitHeight() const +{ + return QDeclarativeItem::implicitHeight(); +} + } // Plasma namespace #include "svgitem.moc" diff --git a/declarativeimports/core/svgitem.h b/declarativeimports/core/svgitem.h index a6d4a5a5d..cca0545a7 100644 --- a/declarativeimports/core/svgitem.h +++ b/declarativeimports/core/svgitem.h @@ -56,6 +56,16 @@ class SvgItem : public QDeclarativeItem */ Q_PROPERTY(bool smooth READ smooth WRITE setSmooth NOTIFY smoothChanged) + /** + * suggested default size hint for width (default to naturalSize.width) + */ + Q_PROPERTY(qreal implicitWidth READ implicitWidth WRITE setImplicitWidth NOTIFY implicitWidthChanged) + + /** + * suggested default size hint for height (default to naturalSize.height) + */ + Q_PROPERTY(qreal implicitHeight READ implicitHeight WRITE setImplicitHeight NOTIFY implicitHeightChanged) + public: SvgItem(QDeclarativeItem *parent=0); ~SvgItem(); @@ -73,11 +83,19 @@ public: void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); + void setImplicitWidth(qreal width); + qreal implicitWidth() const; + + void setImplicitHeight(qreal height); + qreal implicitHeight() const; + Q_SIGNALS: void elementIdChanged(); void svgChanged(); void naturalSizeChanged(); void smoothChanged(); + void implicitWidthChanged(); + void implicitHeightChanged(); protected Q_SLOTS: void updateNeeded();