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
This commit is contained in:
Eike Hein 2017-03-24 06:19:15 +09:00
parent 244baaf928
commit bc33f0470d

View File

@ -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();
}