From bc33f0470d4d6bcbf30475f85b36705e8a99528b Mon Sep 17 00:00:00 2001 From: Eike Hein Date: Fri, 24 Mar 2017 06:19:15 +0900 Subject: [PATCH] Set implicit size from source size for image/SVG URL sources. Summary: This allows users of IconItem to know the aspect ratio of the source document, which can be used to size the item or set applet size hints to accomodate non-square images better. This will be used in a patch to Kicker/Dashboard that ports a use of Image in its CompactRepresentation to IconItem to get the hover highlight effect even for a custom button image. Reviewers: #plasma, mart, davidedmundson Subscribers: plasma-devel, #frameworks Tags: #plasma, #frameworks Differential Revision: https://phabricator.kde.org/D5160 --- src/declarativeimports/core/iconitem.cpp | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/declarativeimports/core/iconitem.cpp b/src/declarativeimports/core/iconitem.cpp index 1fa13bb14..8ac9d6e3a 100644 --- a/src/declarativeimports/core/iconitem.cpp +++ b/src/declarativeimports/core/iconitem.cpp @@ -84,7 +84,25 @@ IconItem::~IconItem() void IconItem::updateImplicitSize() { - //initialize implicit size to the Dialog size + if (!m_imageIcon.isNull()) { + const QSize &s = m_imageIcon.size(); + + if (s.isValid()) { + setImplicitSize(s.width(), s.height()); + + return; + } + } else if (m_svgIcon) { // FIXME: Check Svg::isValid()? Considered expensive by apidox. + const QSize &s = m_svgIcon->size(); + + if (s.isValid()) { + setImplicitSize(s.width(), s.height()); + + return; + } + } + + // Fall back to initializing implicit size to the Dialog size. const int implicitSize = KIconLoader::global()->currentSize(KIconLoader::Dialog); setImplicitSize(implicitSize, implicitSize); } @@ -131,7 +149,6 @@ void IconItem::setSource(const QVariant &source) if (m_svgIcon->isValid() && m_svgIcon->hasElement(sourceString)) { m_icon = QIcon(); m_svgIconName = sourceString; - //ok, svg not available from the plasma theme } else { //try to load from iconloader an svg with Plasma::Svg @@ -176,7 +193,6 @@ void IconItem::setSource(const QVariant &source) m_svgIconName.clear(); delete m_svgIcon; m_svgIcon = 0; - } else { m_icon = QIcon(); m_imageIcon = QImage(); @@ -189,6 +205,8 @@ void IconItem::setSource(const QVariant &source) schedulePixmapUpdate(); } + updateImplicitSize(); + emit sourceChanged(); emit validChanged(); }