2012-11-26 20:49:16 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Marco Martin <mart@kde.org>
|
2014-05-12 18:47:49 +02:00
|
|
|
* Copyright 2014 David Edmundson <davidedmudnson@kde.org>
|
2012-11-26 20:49:16 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "iconitem.h"
|
|
|
|
|
2013-03-13 12:05:06 +01:00
|
|
|
#include <QDebug>
|
|
|
|
#include <QPaintEngine>
|
2012-11-26 20:49:16 +01:00
|
|
|
#include <QPainter>
|
|
|
|
#include <QPropertyAnimation>
|
2014-05-12 18:47:49 +02:00
|
|
|
#include <QPixmap>
|
|
|
|
#include <QSGSimpleTextureNode>
|
|
|
|
#include <QQuickWindow>
|
|
|
|
#include <QPixmap>
|
2012-11-26 20:49:16 +01:00
|
|
|
|
2013-10-05 01:38:31 +02:00
|
|
|
#include <kiconloader.h>
|
|
|
|
#include <kiconeffect.h>
|
2015-10-20 11:44:52 +02:00
|
|
|
#include <KIconTheme>
|
2013-03-13 12:05:06 +01:00
|
|
|
|
2014-05-12 18:47:49 +02:00
|
|
|
#include "fadingnode_p.h"
|
2014-10-15 13:22:27 +02:00
|
|
|
#include <QuickAddons/ManagedTextureNode>
|
2014-09-25 14:33:39 +02:00
|
|
|
#include "units.h"
|
2013-02-02 04:43:20 +01:00
|
|
|
|
2013-02-01 17:26:26 +01:00
|
|
|
IconItem::IconItem(QQuickItem *parent)
|
2014-05-12 18:47:49 +02:00
|
|
|
: QQuickItem(parent),
|
2012-11-26 20:49:16 +01:00
|
|
|
m_svgIcon(0),
|
|
|
|
m_smooth(false),
|
|
|
|
m_active(false),
|
2016-01-06 20:21:15 +01:00
|
|
|
m_animated(true),
|
2016-01-20 11:28:56 +01:00
|
|
|
m_usesPlasmaTheme(true),
|
2015-03-24 11:50:28 +01:00
|
|
|
m_textureChanged(false),
|
|
|
|
m_sizeChanged(false),
|
2014-06-18 19:22:02 +02:00
|
|
|
m_colorGroup(Plasma::Theme::NormalColorGroup),
|
2012-11-26 20:49:16 +01:00
|
|
|
m_animValue(0)
|
|
|
|
{
|
|
|
|
m_animation = new QPropertyAnimation(this);
|
|
|
|
connect(m_animation, SIGNAL(valueChanged(QVariant)),
|
|
|
|
this, SLOT(valueChanged(QVariant)));
|
|
|
|
connect(m_animation, SIGNAL(finished()),
|
|
|
|
this, SLOT(animationFinished()));
|
|
|
|
m_animation->setTargetObject(this);
|
|
|
|
m_animation->setEasingCurve(QEasingCurve::InOutQuad);
|
2014-05-12 18:47:49 +02:00
|
|
|
m_animation->setDuration(250); //FIXME from theme
|
2012-11-26 20:49:16 +01:00
|
|
|
|
2013-02-01 18:18:52 +01:00
|
|
|
setFlag(ItemHasContents, true);
|
2012-11-26 20:49:16 +01:00
|
|
|
|
|
|
|
connect(KIconLoader::global(), SIGNAL(iconLoaderSettingsChanged()),
|
2012-12-03 18:10:25 +01:00
|
|
|
this, SIGNAL(implicitWidthChanged()));
|
2012-11-26 20:49:16 +01:00
|
|
|
connect(KIconLoader::global(), SIGNAL(iconLoaderSettingsChanged()),
|
2012-12-03 18:10:25 +01:00
|
|
|
this, SIGNAL(implicitHeightChanged()));
|
2012-11-26 20:49:16 +01:00
|
|
|
|
2012-11-27 14:02:34 +01:00
|
|
|
connect(this, SIGNAL(enabledChanged()),
|
2015-12-22 18:36:23 +01:00
|
|
|
this, SLOT(schedulePixmapUpdate()));
|
2012-11-27 14:02:34 +01:00
|
|
|
|
2012-11-26 20:49:16 +01:00
|
|
|
//initialize implicit size to the Dialog size
|
|
|
|
setImplicitWidth(KIconLoader::global()->currentSize(KIconLoader::Dialog));
|
|
|
|
setImplicitHeight(KIconLoader::global()->currentSize(KIconLoader::Dialog));
|
|
|
|
}
|
|
|
|
|
|
|
|
IconItem::~IconItem()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void IconItem::setSource(const QVariant &source)
|
|
|
|
{
|
|
|
|
if (source == m_source) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_source = source;
|
2016-03-04 23:44:57 +01:00
|
|
|
QString sourceString = source.toString();
|
2012-11-26 20:49:16 +01:00
|
|
|
|
2016-01-19 10:14:49 +01:00
|
|
|
// If the QIcon was created with QIcon::fromTheme(), try to load it as svg
|
2016-03-04 23:44:57 +01:00
|
|
|
if (source.canConvert<QIcon>() && !source.value<QIcon>().name().isEmpty()) {
|
|
|
|
sourceString = source.value<QIcon>().name();
|
2016-01-19 10:14:49 +01:00
|
|
|
}
|
2012-11-26 20:49:16 +01:00
|
|
|
|
2016-03-04 23:44:57 +01:00
|
|
|
if (!sourceString.isEmpty()) {
|
2014-11-26 15:13:33 +01:00
|
|
|
//If a url in the form file:// is passed, take the image pointed by that from disk
|
2016-01-19 10:14:49 +01:00
|
|
|
QUrl url(sourceString);
|
2014-11-26 15:13:33 +01:00
|
|
|
if (url.isLocalFile()) {
|
2012-11-26 20:49:16 +01:00
|
|
|
m_icon = QIcon();
|
2014-11-26 15:13:33 +01:00
|
|
|
m_imageIcon = QImage(url.path());
|
2016-03-04 23:44:57 +01:00
|
|
|
m_svgIconName.clear();
|
2012-11-26 20:49:16 +01:00
|
|
|
delete m_svgIcon;
|
|
|
|
m_svgIcon = 0;
|
2014-11-26 15:13:33 +01:00
|
|
|
} else {
|
|
|
|
if (!m_svgIcon) {
|
|
|
|
m_svgIcon = new Plasma::Svg(this);
|
|
|
|
m_svgIcon->setColorGroup(m_colorGroup);
|
2015-03-10 18:02:15 +01:00
|
|
|
m_svgIcon->setDevicePixelRatio((window() ? window()->devicePixelRatio() : qApp->devicePixelRatio()));
|
2016-02-29 22:28:58 +01:00
|
|
|
connect(m_svgIcon, &Plasma::Svg::repaintNeeded, this, &IconItem::schedulePixmapUpdate);
|
2014-11-26 15:13:33 +01:00
|
|
|
}
|
|
|
|
|
2016-01-20 11:28:56 +01:00
|
|
|
if (m_usesPlasmaTheme) {
|
|
|
|
//try as a svg icon from plasma theme
|
|
|
|
m_svgIcon->setImagePath(QLatin1String("icons/") + sourceString.split('-').first());
|
|
|
|
m_svgIcon->setContainsMultipleImages(true);
|
|
|
|
}
|
2014-11-26 15:13:33 +01:00
|
|
|
|
|
|
|
//success?
|
2016-01-19 10:14:49 +01:00
|
|
|
if (m_svgIcon->isValid() && m_svgIcon->hasElement(sourceString)) {
|
2014-11-26 15:13:33 +01:00
|
|
|
m_icon = QIcon();
|
2016-03-04 23:44:57 +01:00
|
|
|
m_svgIconName = sourceString;
|
2014-11-26 15:13:33 +01:00
|
|
|
|
2015-10-20 11:44:52 +02:00
|
|
|
//ok, svg not available from the plasma theme
|
2014-11-26 15:13:33 +01:00
|
|
|
} else {
|
2015-10-20 11:44:52 +02:00
|
|
|
//try to load from iconloader an svg with Plasma::Svg
|
2015-11-25 18:17:57 +01:00
|
|
|
const auto *iconTheme = KIconLoader::global()->theme();
|
|
|
|
QString iconPath;
|
|
|
|
if (iconTheme) {
|
2016-02-27 10:40:54 -08:00
|
|
|
iconPath = iconTheme->iconPath(sourceString + QLatin1String(".svg"), qMin(width(), height()), KIconLoader::MatchBest);
|
2015-11-25 18:17:57 +01:00
|
|
|
if (iconPath.isEmpty()) {
|
2016-02-27 10:40:54 -08:00
|
|
|
iconPath = iconTheme->iconPath(sourceString + QLatin1String(".svgz"), qMin(width(), height()), KIconLoader::MatchBest);
|
2015-11-25 18:17:57 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
qWarning() << "KIconLoader has no theme set";
|
2015-10-20 11:44:52 +02:00
|
|
|
}
|
|
|
|
|
2016-03-04 23:44:57 +01:00
|
|
|
if (!iconPath.isEmpty()) {
|
2015-10-20 11:44:52 +02:00
|
|
|
m_svgIcon->setImagePath(iconPath);
|
2016-03-04 23:44:57 +01:00
|
|
|
m_svgIconName = sourceString;
|
2015-10-20 11:44:52 +02:00
|
|
|
//fail, use QIcon
|
|
|
|
} else {
|
2016-01-19 10:14:49 +01:00
|
|
|
m_icon = QIcon::fromTheme(sourceString);
|
2016-02-16 17:59:32 +01:00
|
|
|
if (m_icon.isNull()) {
|
|
|
|
// fallback for non-theme icons
|
|
|
|
m_icon = source.value<QIcon>();
|
|
|
|
}
|
2016-03-04 23:44:57 +01:00
|
|
|
m_svgIconName.clear();
|
2015-10-20 11:44:52 +02:00
|
|
|
delete m_svgIcon;
|
|
|
|
m_svgIcon = 0;
|
|
|
|
m_imageIcon = QImage();
|
|
|
|
}
|
2014-11-26 15:13:33 +01:00
|
|
|
}
|
2012-11-26 20:49:16 +01:00
|
|
|
}
|
|
|
|
|
2016-01-19 10:14:49 +01:00
|
|
|
} else if (source.canConvert<QIcon>()) {
|
|
|
|
m_icon = source.value<QIcon>();
|
|
|
|
m_imageIcon = QImage();
|
2016-03-04 23:44:57 +01:00
|
|
|
m_svgIconName.clear();
|
2016-01-19 10:14:49 +01:00
|
|
|
delete m_svgIcon;
|
|
|
|
m_svgIcon = 0;
|
2012-11-26 20:49:16 +01:00
|
|
|
} else if (source.canConvert<QImage>()) {
|
|
|
|
m_icon = QIcon();
|
|
|
|
m_imageIcon = source.value<QImage>();
|
2016-03-04 23:44:57 +01:00
|
|
|
m_svgIconName.clear();
|
2012-11-26 20:49:16 +01:00
|
|
|
delete m_svgIcon;
|
|
|
|
m_svgIcon = 0;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
m_icon = QIcon();
|
|
|
|
m_imageIcon = QImage();
|
2016-03-04 23:44:57 +01:00
|
|
|
m_svgIconName.clear();
|
2012-11-26 20:49:16 +01:00
|
|
|
delete m_svgIcon;
|
|
|
|
m_svgIcon = 0;
|
|
|
|
}
|
|
|
|
|
2013-02-14 04:33:26 +01:00
|
|
|
if (width() > 0 && height() > 0) {
|
2015-12-22 18:36:23 +01:00
|
|
|
schedulePixmapUpdate();
|
2013-02-14 04:33:26 +01:00
|
|
|
}
|
2012-11-26 20:49:16 +01:00
|
|
|
|
|
|
|
emit sourceChanged();
|
|
|
|
emit validChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant IconItem::source() const
|
|
|
|
{
|
|
|
|
return m_source;
|
|
|
|
}
|
|
|
|
|
2014-06-18 19:22:02 +02:00
|
|
|
void IconItem::setColorGroup(Plasma::Theme::ColorGroup group)
|
2014-06-09 19:35:58 +02:00
|
|
|
{
|
2014-06-13 15:40:16 +02:00
|
|
|
if (m_colorGroup == group) {
|
2014-06-09 19:35:58 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-13 15:40:16 +02:00
|
|
|
m_colorGroup = group;
|
2014-06-09 19:35:58 +02:00
|
|
|
|
|
|
|
if (m_svgIcon) {
|
|
|
|
m_svgIcon->setColorGroup(group);
|
|
|
|
}
|
|
|
|
|
2014-06-13 15:40:16 +02:00
|
|
|
emit colorGroupChanged();
|
2014-06-09 19:35:58 +02:00
|
|
|
}
|
|
|
|
|
2014-06-18 19:22:02 +02:00
|
|
|
Plasma::Theme::ColorGroup IconItem::colorGroup() const
|
2014-06-09 19:35:58 +02:00
|
|
|
{
|
2014-06-13 15:40:16 +02:00
|
|
|
return m_colorGroup;
|
2014-06-09 19:35:58 +02:00
|
|
|
}
|
|
|
|
|
2012-11-26 20:49:16 +01:00
|
|
|
bool IconItem::isActive() const
|
|
|
|
{
|
|
|
|
return m_active;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IconItem::setActive(bool active)
|
|
|
|
{
|
|
|
|
if (m_active == active) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_active = active;
|
2014-12-15 20:21:06 +01:00
|
|
|
if (isComponentComplete()) {
|
2015-12-22 18:36:23 +01:00
|
|
|
schedulePixmapUpdate();
|
2014-12-15 20:21:06 +01:00
|
|
|
}
|
2012-11-26 20:49:16 +01:00
|
|
|
emit activeChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void IconItem::setSmooth(const bool smooth)
|
|
|
|
{
|
|
|
|
if (smooth == m_smooth) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_smooth = smooth;
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IconItem::smooth() const
|
|
|
|
{
|
|
|
|
return m_smooth;
|
|
|
|
}
|
|
|
|
|
2016-01-06 20:21:15 +01:00
|
|
|
bool IconItem::isAnimated() const
|
|
|
|
{
|
|
|
|
return m_animated;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IconItem::setAnimated(bool animated)
|
|
|
|
{
|
|
|
|
if (m_animated == animated) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_animated = animated;
|
|
|
|
emit animatedChanged();
|
|
|
|
}
|
|
|
|
|
2016-01-20 11:28:56 +01:00
|
|
|
bool IconItem::usesPlasmaTheme() const
|
|
|
|
{
|
|
|
|
return m_usesPlasmaTheme;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IconItem::setUsesPlasmaTheme(bool usesPlasmaTheme)
|
|
|
|
{
|
|
|
|
if (m_usesPlasmaTheme == usesPlasmaTheme) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_usesPlasmaTheme = usesPlasmaTheme;
|
|
|
|
|
|
|
|
// Reload icon with new settings
|
|
|
|
if (m_svgIcon && m_svgIcon->hasElement(m_source.toString())) {
|
|
|
|
const QVariant src = m_source;
|
|
|
|
m_source.clear();
|
|
|
|
setSource(src);
|
|
|
|
}
|
|
|
|
|
|
|
|
emit usesPlasmaThemeChanged();
|
|
|
|
}
|
|
|
|
|
2012-11-26 20:49:16 +01:00
|
|
|
bool IconItem::isValid() const
|
|
|
|
{
|
2016-03-04 00:20:46 +00:00
|
|
|
return !m_icon.isNull() || m_svgIcon || !m_imageIcon.isNull();
|
2012-11-26 20:49:16 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 18:17:33 +01:00
|
|
|
int IconItem::paintedWidth() const
|
|
|
|
{
|
|
|
|
return Units::roundToIconSize(qMin(boundingRect().size().width(), boundingRect().size().height()));
|
|
|
|
}
|
|
|
|
|
|
|
|
int IconItem::paintedHeight() const
|
|
|
|
{
|
|
|
|
return Units::roundToIconSize(qMin(boundingRect().size().width(), boundingRect().size().height()));
|
|
|
|
}
|
|
|
|
|
2015-12-22 18:36:23 +01:00
|
|
|
void IconItem::updatePolish()
|
|
|
|
{
|
|
|
|
QQuickItem::updatePolish();
|
|
|
|
loadPixmap();
|
|
|
|
}
|
|
|
|
|
2014-05-12 18:47:49 +02:00
|
|
|
QSGNode* IconItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData)
|
2012-11-26 20:49:16 +01:00
|
|
|
{
|
2014-05-12 18:47:49 +02:00
|
|
|
Q_UNUSED(updatePaintNodeData)
|
|
|
|
|
2014-05-16 15:43:43 +02:00
|
|
|
if (m_iconPixmap.isNull() || width() == 0 || height() == 0) {
|
2014-05-12 18:47:49 +02:00
|
|
|
delete oldNode;
|
|
|
|
return Q_NULLPTR;
|
2012-11-26 20:49:16 +01:00
|
|
|
}
|
2013-02-02 04:43:20 +01:00
|
|
|
|
2014-05-12 18:47:49 +02:00
|
|
|
if (m_animation->state() == QAbstractAnimation::Running) {
|
2014-05-22 07:53:55 +02:00
|
|
|
FadingNode *animatingNode = dynamic_cast<FadingNode*>(oldNode);
|
2012-11-26 20:49:16 +01:00
|
|
|
|
2014-05-12 18:47:49 +02:00
|
|
|
if (!animatingNode || m_textureChanged) {
|
|
|
|
delete oldNode;
|
2014-02-17 15:39:01 +01:00
|
|
|
|
2014-05-12 18:47:49 +02:00
|
|
|
QSGTexture *source = window()->createTextureFromImage(m_iconPixmap.toImage());
|
|
|
|
QSGTexture *target = window()->createTextureFromImage(m_oldIconPixmap.toImage());
|
|
|
|
animatingNode = new FadingNode(source, target);
|
|
|
|
m_sizeChanged = true;
|
|
|
|
m_textureChanged = false;
|
|
|
|
}
|
2012-11-26 20:49:16 +01:00
|
|
|
|
2014-05-12 18:47:49 +02:00
|
|
|
animatingNode->setProgress(m_animValue);
|
|
|
|
|
|
|
|
if (m_sizeChanged) {
|
2014-09-25 14:33:39 +02:00
|
|
|
const int iconSize = Units::roundToIconSize(qMin(boundingRect().size().width(), boundingRect().size().height()));
|
2014-05-12 18:47:49 +02:00
|
|
|
const QRect destRect(QPointF(boundingRect().center() - QPointF(iconSize/2, iconSize/2)).toPoint(),
|
|
|
|
QSize(iconSize, iconSize));
|
|
|
|
|
|
|
|
animatingNode->setRect(destRect);
|
|
|
|
m_sizeChanged = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return animatingNode;
|
2012-11-26 20:49:16 +01:00
|
|
|
} else {
|
2014-10-15 13:22:27 +02:00
|
|
|
ManagedTextureNode *textureNode = dynamic_cast<ManagedTextureNode*>(oldNode);
|
2014-05-12 18:47:49 +02:00
|
|
|
|
|
|
|
if (!textureNode || m_textureChanged) {
|
|
|
|
delete oldNode;
|
2014-10-15 13:22:27 +02:00
|
|
|
textureNode = new ManagedTextureNode;
|
2014-07-25 12:41:53 +02:00
|
|
|
textureNode->setTexture(QSharedPointer<QSGTexture>(window()->createTextureFromImage(m_iconPixmap.toImage())));
|
2014-05-12 18:47:49 +02:00
|
|
|
m_sizeChanged = true;
|
|
|
|
m_textureChanged = false;
|
|
|
|
}
|
2012-11-26 20:49:16 +01:00
|
|
|
|
2014-05-12 18:47:49 +02:00
|
|
|
if (m_sizeChanged) {
|
2014-09-25 14:33:39 +02:00
|
|
|
const int iconSize = Units::roundToIconSize(qMin(boundingRect().size().width(), boundingRect().size().height()));
|
2014-05-12 18:47:49 +02:00
|
|
|
const QRect destRect(QPointF(boundingRect().center() - QPointF(iconSize/2, iconSize/2)).toPoint(),
|
|
|
|
QSize(iconSize, iconSize));
|
2012-11-26 20:49:16 +01:00
|
|
|
|
2014-05-12 18:47:49 +02:00
|
|
|
textureNode->setRect(destRect);
|
|
|
|
m_sizeChanged = false;
|
|
|
|
}
|
|
|
|
return textureNode;
|
2012-11-26 20:49:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void IconItem::valueChanged(const QVariant &value)
|
|
|
|
{
|
|
|
|
m_animValue = value.toReal();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2014-05-12 18:47:49 +02:00
|
|
|
void IconItem::animationFinished()
|
|
|
|
{
|
|
|
|
m_oldIconPixmap = QPixmap();
|
|
|
|
m_textureChanged = true;
|
2014-05-22 07:53:55 +02:00
|
|
|
update();
|
2014-05-12 18:47:49 +02:00
|
|
|
}
|
|
|
|
|
2015-12-22 18:36:23 +01:00
|
|
|
void IconItem::schedulePixmapUpdate()
|
|
|
|
{
|
|
|
|
polish();
|
|
|
|
}
|
|
|
|
|
2014-02-17 15:39:01 +01:00
|
|
|
void IconItem::loadPixmap()
|
|
|
|
{
|
2014-12-15 20:21:06 +01:00
|
|
|
if (!isComponentComplete()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-25 14:33:39 +02:00
|
|
|
const int size = Units::roundToIconSize(qMin(width(), height()));
|
2014-02-17 15:39:01 +01:00
|
|
|
|
2012-11-26 20:49:16 +01:00
|
|
|
//final pixmap to paint
|
|
|
|
QPixmap result;
|
2014-04-26 01:45:47 +02:00
|
|
|
if (size <= 0) {
|
2015-02-12 16:35:28 +01:00
|
|
|
m_iconPixmap = QPixmap();
|
2013-02-14 04:33:26 +01:00
|
|
|
m_animation->stop();
|
|
|
|
update();
|
2013-02-07 12:11:51 +01:00
|
|
|
return;
|
|
|
|
} else if (m_svgIcon) {
|
2012-11-26 20:49:16 +01:00
|
|
|
m_svgIcon->resize(size, size);
|
2016-03-04 23:44:57 +01:00
|
|
|
if (m_svgIcon->hasElement(m_svgIconName)) {
|
|
|
|
result = m_svgIcon->pixmap(m_svgIconName);
|
|
|
|
} else if (!m_svgIconName.isEmpty()) {
|
2015-11-25 18:17:57 +01:00
|
|
|
const auto *iconTheme = KIconLoader::global()->theme();
|
|
|
|
QString iconPath;
|
|
|
|
if (iconTheme) {
|
2016-03-04 23:44:57 +01:00
|
|
|
iconPath = iconTheme->iconPath(m_svgIconName + QLatin1String(".svg"), qMin(width(), height()), KIconLoader::MatchBest);
|
2015-11-25 18:17:57 +01:00
|
|
|
if (iconPath.isEmpty()) {
|
2016-03-04 23:44:57 +01:00
|
|
|
iconPath = iconTheme->iconPath(m_svgIconName + QLatin1String(".svgz"), qMin(width(), height()), KIconLoader::MatchBest);
|
2015-11-25 18:17:57 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
qWarning() << "KIconLoader has no theme set";
|
2015-10-20 11:44:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!iconPath.isEmpty()) {
|
|
|
|
m_svgIcon->setImagePath(iconPath);
|
|
|
|
}
|
|
|
|
result = m_svgIcon->pixmap();
|
|
|
|
}
|
2014-05-06 16:32:55 +02:00
|
|
|
} else if (!m_icon.isNull()) {
|
2015-03-10 18:02:15 +01:00
|
|
|
result = m_icon.pixmap(QSize(size, size) * (window() ? window()->devicePixelRatio() : qApp->devicePixelRatio()));
|
2012-11-26 20:49:16 +01:00
|
|
|
} else if (!m_imageIcon.isNull()) {
|
|
|
|
result = QPixmap::fromImage(m_imageIcon);
|
|
|
|
} else {
|
2014-05-12 18:47:49 +02:00
|
|
|
m_iconPixmap = QPixmap();
|
2013-02-14 04:33:26 +01:00
|
|
|
m_animation->stop();
|
|
|
|
update();
|
2012-11-26 20:49:16 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isEnabled()) {
|
|
|
|
result = KIconLoader::global()->iconEffect()->apply(result, KIconLoader::Desktop, KIconLoader::DisabledState);
|
|
|
|
} else if (m_active) {
|
|
|
|
result = KIconLoader::global()->iconEffect()->apply(result, KIconLoader::Desktop, KIconLoader::ActiveState);
|
|
|
|
}
|
|
|
|
|
2014-05-12 18:47:49 +02:00
|
|
|
m_oldIconPixmap = m_iconPixmap;
|
|
|
|
m_iconPixmap = result;
|
|
|
|
m_textureChanged = true;
|
2014-02-17 15:39:01 +01:00
|
|
|
|
2014-05-12 18:47:49 +02:00
|
|
|
//don't animate initial setting
|
2016-01-06 20:21:15 +01:00
|
|
|
if (m_animated && !m_oldIconPixmap.isNull() && !m_sizeChanged) {
|
2016-02-27 21:24:45 +01:00
|
|
|
m_animValue = 0.0;
|
2012-11-26 20:49:16 +01:00
|
|
|
m_animation->setStartValue((qreal)0);
|
|
|
|
m_animation->setEndValue((qreal)1);
|
|
|
|
m_animation->start();
|
2014-05-12 18:47:49 +02:00
|
|
|
} else {
|
|
|
|
m_animValue = 1.0;
|
2014-12-11 14:48:42 -05:00
|
|
|
m_animation->stop();
|
2012-11-26 20:49:16 +01:00
|
|
|
}
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2016-03-10 13:01:29 +01:00
|
|
|
void IconItem::itemChange(ItemChange change, const ItemChangeData &value)
|
|
|
|
{
|
|
|
|
if (change == ItemVisibleHasChanged && value.boolValue) {
|
|
|
|
// Clear pixmap to disable animation
|
|
|
|
m_iconPixmap = QPixmap();
|
|
|
|
}
|
|
|
|
|
|
|
|
QQuickItem::itemChange(change, value);
|
|
|
|
}
|
|
|
|
|
2012-11-26 20:49:16 +01:00
|
|
|
void IconItem::geometryChanged(const QRectF &newGeometry,
|
|
|
|
const QRectF &oldGeometry)
|
|
|
|
{
|
|
|
|
if (newGeometry.size() != oldGeometry.size()) {
|
2014-05-21 16:54:05 +02:00
|
|
|
m_sizeChanged = true;
|
2013-02-14 04:33:26 +01:00
|
|
|
if (newGeometry.width() > 0 && newGeometry.height() > 0) {
|
2015-12-22 18:36:23 +01:00
|
|
|
schedulePixmapUpdate();
|
|
|
|
} else {
|
|
|
|
update();
|
2013-02-14 04:33:26 +01:00
|
|
|
}
|
2016-01-04 18:17:33 +01:00
|
|
|
|
|
|
|
if (Units::roundToIconSize(qMin(oldGeometry.size().width(), oldGeometry.size().height())) !=
|
|
|
|
Units::roundToIconSize(qMin(newGeometry.size().width(), newGeometry.size().height()))) {
|
|
|
|
emit paintedSizeChanged();
|
|
|
|
}
|
2013-02-14 04:33:26 +01:00
|
|
|
}
|
2014-02-17 14:32:35 +01:00
|
|
|
|
|
|
|
QQuickItem::geometryChanged(newGeometry, oldGeometry);
|
2012-11-26 20:49:16 +01:00
|
|
|
}
|
|
|
|
|
2014-12-15 20:21:06 +01:00
|
|
|
void IconItem::componentComplete()
|
|
|
|
{
|
|
|
|
QQuickItem::componentComplete();
|
2015-12-22 18:36:23 +01:00
|
|
|
schedulePixmapUpdate();
|
2014-12-15 20:21:06 +01:00
|
|
|
}
|