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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ICONITEM_H
|
|
|
|
#define ICONITEM_H
|
|
|
|
|
2013-02-01 18:18:52 +01:00
|
|
|
#include <QIcon>
|
2014-05-12 18:47:49 +02:00
|
|
|
#include <QQuickItem>
|
2012-11-26 20:49:16 +01:00
|
|
|
#include <QPixmap>
|
|
|
|
#include <QVariant>
|
2014-02-17 15:39:01 +01:00
|
|
|
#include <QTimer>
|
2012-11-26 20:49:16 +01:00
|
|
|
|
2014-06-09 19:35:58 +02:00
|
|
|
#include <plasma/svg.h>
|
2012-11-26 20:49:16 +01:00
|
|
|
|
2014-06-09 19:35:58 +02:00
|
|
|
class QPropertyAnimation;
|
2012-11-26 20:49:16 +01:00
|
|
|
|
2014-08-12 23:12:15 +02:00
|
|
|
/**
|
|
|
|
* @class IconItem
|
|
|
|
* @short Displays an icon, either from the standard QIcon system or where applicable from the theme SVG files
|
|
|
|
*/
|
2014-05-12 18:47:49 +02:00
|
|
|
class IconItem : public QQuickItem
|
2012-11-26 20:49:16 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
2016-03-04 00:17:11 +00:00
|
|
|
/**
|
|
|
|
* Sets the icon to be displayed. Source can be one of:
|
|
|
|
* - iconName (as a string)
|
|
|
|
* - URL
|
|
|
|
* - QImage
|
|
|
|
* - QPixmap
|
|
|
|
* - QIcon
|
|
|
|
*
|
|
|
|
* When passing an icon name (or a QIcon with an icon name set) it will:
|
|
|
|
* - load the plasma variant if usesPlasmaTheme is set and exists
|
|
|
|
* - otherwise try to load the icon as an SVG so colorscopes apply
|
|
|
|
* - load the icon as normal
|
|
|
|
*/
|
2012-11-26 20:49:16 +01:00
|
|
|
Q_PROPERTY(QVariant source READ source WRITE setSource NOTIFY sourceChanged)
|
2016-03-04 00:17:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Specifies the color group to use for this icon
|
|
|
|
* This only applies to icons loaded from the plasma theme
|
|
|
|
*/
|
2014-06-18 19:22:02 +02:00
|
|
|
Q_PROPERTY(Plasma::Theme::ColorGroup colorGroup READ colorGroup WRITE setColorGroup NOTIFY colorGroupChanged)
|
2016-03-04 00:17:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* See QQuickItem::smooth
|
|
|
|
*/
|
2012-11-26 20:49:16 +01:00
|
|
|
Q_PROPERTY(bool smooth READ smooth WRITE setSmooth NOTIFY smoothChanged)
|
2016-03-04 00:17:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Apply a visual indication that this icon is active.
|
|
|
|
* Typically used to indicate that it is hovered
|
|
|
|
*/
|
2012-11-26 20:49:16 +01:00
|
|
|
Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged)
|
2016-03-04 00:17:11 +00:00
|
|
|
|
2016-05-31 11:10:47 +02:00
|
|
|
/**
|
2016-06-01 14:47:56 +02:00
|
|
|
* Sets the image in a selected status.
|
|
|
|
* Svgs can be colored with system color themes, if the status is selected,
|
2016-05-31 11:10:47 +02:00
|
|
|
* the TextColor will become HighlightedText color and BackgroundColor
|
|
|
|
* will become HighlightColor, making the svg graphics (for instance an icon)
|
|
|
|
* will look correct together selected text
|
2016-06-01 14:47:56 +02:00
|
|
|
* @see Plasma::Svg::status
|
2016-05-31 11:10:47 +02:00
|
|
|
* @since 5.23
|
|
|
|
*/
|
2016-06-01 14:47:56 +02:00
|
|
|
Q_PROPERTY(Plasma::Svg::Status status READ status WRITE setStatus NOTIFY statusChanged)
|
2016-05-31 11:10:47 +02:00
|
|
|
|
2016-03-04 00:17:11 +00:00
|
|
|
/**
|
2016-03-11 14:07:44 +01:00
|
|
|
* If set, icon will blend when the source is changed
|
2016-03-04 00:17:11 +00:00
|
|
|
*/
|
2016-01-06 20:21:15 +01:00
|
|
|
Q_PROPERTY(bool animated READ isAnimated WRITE setAnimated NOTIFY animatedChanged)
|
2016-03-04 00:17:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If set, icon will try and use icons from the Plasma theme if possible
|
|
|
|
*/
|
2016-01-20 11:28:56 +01:00
|
|
|
Q_PROPERTY(bool usesPlasmaTheme READ usesPlasmaTheme WRITE setUsesPlasmaTheme NOTIFY usesPlasmaThemeChanged)
|
2016-03-04 00:17:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* True if a valid icon is set. False otherwise.
|
|
|
|
*/
|
2012-11-26 20:49:16 +01:00
|
|
|
Q_PROPERTY(bool valid READ isValid NOTIFY validChanged)
|
2016-03-04 00:17:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The width of the icon that is actually painted
|
|
|
|
* Icons are drawn at standard icon sizes (eg. 16,32,64) centered within the item
|
|
|
|
*/
|
2016-01-04 18:17:33 +01:00
|
|
|
Q_PROPERTY(int paintedWidth READ paintedWidth NOTIFY paintedSizeChanged)
|
2016-03-04 00:17:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The height of the icon actually being drawn.
|
|
|
|
* Icons are drawn at standard icon sizes (eg. 16,32,64) centered within the item
|
|
|
|
*/
|
2016-01-04 18:17:33 +01:00
|
|
|
Q_PROPERTY(int paintedHeight READ paintedHeight NOTIFY paintedSizeChanged)
|
2012-11-26 20:49:16 +01:00
|
|
|
|
|
|
|
public:
|
2014-04-26 01:45:47 +02:00
|
|
|
IconItem(QQuickItem *parent = 0);
|
2012-11-26 20:49:16 +01:00
|
|
|
~IconItem();
|
|
|
|
|
|
|
|
void setSource(const QVariant &source);
|
|
|
|
QVariant source() const;
|
|
|
|
|
2014-06-18 19:22:02 +02:00
|
|
|
void setColorGroup(Plasma::Theme::ColorGroup group);
|
|
|
|
Plasma::Theme::ColorGroup colorGroup() const;
|
2014-06-09 19:35:58 +02:00
|
|
|
|
2012-11-26 20:49:16 +01:00
|
|
|
bool isActive() const;
|
|
|
|
void setActive(bool active);
|
|
|
|
|
|
|
|
void setSmooth(const bool smooth);
|
|
|
|
bool smooth() const;
|
|
|
|
|
2016-01-06 20:21:15 +01:00
|
|
|
bool isAnimated() const;
|
|
|
|
void setAnimated(bool animated);
|
|
|
|
|
2016-01-20 11:28:56 +01:00
|
|
|
bool usesPlasmaTheme() const;
|
|
|
|
void setUsesPlasmaTheme(bool usesPlasmaTheme);
|
|
|
|
|
2012-11-26 20:49:16 +01:00
|
|
|
bool isValid() const;
|
|
|
|
|
2016-01-04 18:17:33 +01:00
|
|
|
int paintedWidth() const;
|
|
|
|
int paintedHeight() const;
|
|
|
|
|
2016-06-01 14:47:56 +02:00
|
|
|
void setStatus(Plasma::Svg::Status status);
|
|
|
|
Plasma::Svg::Status status() const;
|
2016-05-31 11:10:47 +02:00
|
|
|
|
2015-12-22 18:36:23 +01:00
|
|
|
void updatePolish() Q_DECL_OVERRIDE;
|
2015-02-13 13:31:30 +01:00
|
|
|
QSGNode* updatePaintNode(QSGNode * oldNode, UpdatePaintNodeData * updatePaintNodeData) Q_DECL_OVERRIDE;
|
2012-11-26 20:49:16 +01:00
|
|
|
|
2016-03-10 13:01:29 +01:00
|
|
|
void itemChange(ItemChange change, const ItemChangeData &value) Q_DECL_OVERRIDE;
|
2012-11-26 20:49:16 +01:00
|
|
|
void geometryChanged(const QRectF &newGeometry,
|
2015-02-13 13:31:30 +01:00
|
|
|
const QRectF &oldGeometry) Q_DECL_OVERRIDE;
|
2012-11-26 20:49:16 +01:00
|
|
|
|
2014-12-15 20:21:06 +01:00
|
|
|
void componentComplete() Q_DECL_OVERRIDE;
|
|
|
|
|
2012-11-26 20:49:16 +01:00
|
|
|
Q_SIGNALS:
|
|
|
|
void activeChanged();
|
|
|
|
void sourceChanged();
|
|
|
|
void smoothChanged();
|
2016-01-06 20:21:15 +01:00
|
|
|
void animatedChanged();
|
2016-01-20 11:28:56 +01:00
|
|
|
void usesPlasmaThemeChanged();
|
2012-11-26 20:49:16 +01:00
|
|
|
void validChanged();
|
2014-06-13 15:40:16 +02:00
|
|
|
void colorGroupChanged();
|
2016-01-04 18:17:33 +01:00
|
|
|
void paintedSizeChanged();
|
2016-06-01 14:47:56 +02:00
|
|
|
void statusChanged();
|
2012-11-26 20:49:16 +01:00
|
|
|
|
|
|
|
private Q_SLOTS:
|
2015-12-22 18:36:23 +01:00
|
|
|
void schedulePixmapUpdate();
|
2012-11-26 20:49:16 +01:00
|
|
|
void animationFinished();
|
|
|
|
void valueChanged(const QVariant &value);
|
2016-03-11 14:07:44 +01:00
|
|
|
void enabledChanged();
|
2012-11-26 20:49:16 +01:00
|
|
|
|
|
|
|
private:
|
2015-12-22 18:36:23 +01:00
|
|
|
void loadPixmap();
|
|
|
|
|
2012-11-26 20:49:16 +01:00
|
|
|
//all the ways we can set an source. Only one of them will be valid
|
|
|
|
QIcon m_icon;
|
|
|
|
Plasma::Svg *m_svgIcon;
|
2016-03-04 23:44:57 +01:00
|
|
|
QString m_svgIconName;
|
2012-11-26 20:49:16 +01:00
|
|
|
QPixmap m_pixmapIcon;
|
|
|
|
QImage m_imageIcon;
|
|
|
|
//this contains the raw variant it was passed
|
|
|
|
QVariant m_source;
|
2016-06-01 14:47:56 +02:00
|
|
|
Plasma::Svg::Status m_status;
|
2012-11-26 20:49:16 +01:00
|
|
|
|
|
|
|
QSizeF m_implicitSize;
|
|
|
|
|
|
|
|
bool m_smooth;
|
|
|
|
bool m_active;
|
2016-01-06 20:21:15 +01:00
|
|
|
bool m_animated;
|
2016-01-20 11:28:56 +01:00
|
|
|
bool m_usesPlasmaTheme;
|
2012-11-26 20:49:16 +01:00
|
|
|
|
2014-05-12 18:47:49 +02:00
|
|
|
bool m_textureChanged;
|
|
|
|
bool m_sizeChanged;
|
2016-03-11 14:07:44 +01:00
|
|
|
bool m_allowNextAnimation;
|
2016-07-12 10:02:47 +02:00
|
|
|
bool m_blockNextAnimation;
|
2014-05-12 18:47:49 +02:00
|
|
|
|
|
|
|
QPixmap m_iconPixmap;
|
|
|
|
QPixmap m_oldIconPixmap;
|
|
|
|
|
2014-06-18 19:22:02 +02:00
|
|
|
Plasma::Theme::ColorGroup m_colorGroup;
|
2012-11-26 20:49:16 +01:00
|
|
|
|
|
|
|
//animation on pixmap change
|
|
|
|
QPropertyAnimation *m_animation;
|
|
|
|
qreal m_animValue;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|