1
0
mirror of https://github.com/KDE/latte-dock.git synced 2025-01-15 03:24:49 +03:00

160 lines
4.4 KiB
C
Raw Normal View History

2016-12-30 16:22:28 -05:00
/*
2017-01-02 17:12:20 -05:00
* Copyright 2012 Marco Martin <mart@kde.org>
* Copyright 2014 David Edmundson <davidedmudnson@kde.org>
2017-01-02 17:05:30 -05:00
* Copyright 2016 Smith AR <audoban@openmailbox.org>
* Michail Vourlakos <mvourlakos@gmail.com>
2016-12-30 16:22:28 -05:00
*
2017-01-02 17:12:20 -05:00
* This file is part of Latte-Dock and is a Fork of PlasmaCore::IconItem
2016-12-30 16:22:28 -05:00
*
2017-01-02 17:05:30 -05:00
* Latte-Dock is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
2016-12-30 16:22:28 -05:00
*
2017-01-02 17:05:30 -05:00
* Latte-Dock 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 General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2016-12-30 16:22:28 -05:00
*/
#ifndef ICONITEM_H
#define ICONITEM_H
#include <memory>
#include <QQuickItem>
#include <QIcon>
#include <QImage>
#include <QPixmap>
#include <Plasma/Svg>
// this file is based on PlasmaCore::IconItem class, thanks to KDE
namespace Latte {
class IconItem : public QQuickItem {
Q_OBJECT
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05: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
*/
Q_PROPERTY(QVariant source READ source WRITE setSource NOTIFY sourceChanged)
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
/**
* Specifies the overlay(s) for this icon
*/
Q_PROPERTY(QStringList overlays READ overlays WRITE setOverlays NOTIFY overlaysChanged)
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
/**
* See QQuickItem::smooth
*/
Q_PROPERTY(bool smooth READ smooth WRITE setSmooth NOTIFY smoothChanged)
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
/**
* Apply a visual indication that this icon is active.
* Typically used to indicate that it is hovered
*/
Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged)
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
/**
* True if a valid icon is set. False otherwise.
*/
Q_PROPERTY(bool valid READ isValid NOTIFY validChanged)
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
/**
* The width of the icon that is actually painted
*/
Q_PROPERTY(int paintedWidth READ paintedWidth NOTIFY paintedSizeChanged)
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
/**
* The height of the icon actually being drawn.
*/
Q_PROPERTY(int paintedHeight READ paintedHeight NOTIFY paintedSizeChanged)
2017-01-16 14:07:49 -05:00
/**
* Contains the last valid icon name
*/
Q_PROPERTY(QString lastValidSourceName READ lastValidSourceName NOTIFY lastValidSourceNameChanged)
2016-12-30 16:22:28 -05:00
public:
IconItem(QQuickItem *parent = nullptr);
virtual ~IconItem();
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
void setSource(const QVariant &source);
QVariant source() const;
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
void setOverlays(const QStringList &overlays);
QStringList overlays() const;
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
bool isActive() const;
void setActive(bool active);
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
void setSmooth(const bool smooth);
bool smooth() const;
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
bool isValid() const;
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
int paintedWidth() const;
int paintedHeight() const;
2017-01-16 14:07:49 -05:00
QString lastValidSourceName();
2016-12-30 16:22:28 -05:00
void updatePolish() Q_DECL_OVERRIDE;
QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData) override;
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
void itemChange(ItemChange change, const ItemChangeData &value) override;
void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override;
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
void componentComplete() Q_DECL_OVERRIDE;
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
signals:
void overlaysChanged();
void activeChanged();
void lastValidSourceNameChanged();
2016-12-30 16:22:28 -05:00
void sourceChanged();
void smoothChanged();
void validChanged();
void paintedSizeChanged();
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
private slots:
void schedulePixmapUpdate();
void enabledChanged();
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
private:
void loadPixmap();
void setLastValidSourceName(QString name);
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
QIcon m_icon;
QPixmap m_iconPixmap;
QImage m_imageIcon;
std::unique_ptr<Plasma::Svg> m_svgIcon;
QString m_lastValidSourceName;
2016-12-30 16:22:28 -05:00
QString m_svgIconName;
QStringList m_overlays;
//this contains the raw variant it was passed
QVariant m_source;
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
QSizeF m_implicitSize;
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
bool m_smooth;
bool m_active;
2017-01-16 14:07:49 -05:00
2016-12-30 16:22:28 -05:00
bool m_textureChanged;
bool m_sizeChanged;
};
2016-12-30 16:32:48 -05:00
2016-12-30 16:22:28 -05:00
}
#endif // ICONITEM_H