/*
 * Copyright (C) 2022, KylinSoft Co., Ltd.
 *
 * 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 ICONTHEME_H
#define ICONTHEME_H

#include <QQuickPaintedItem>
#include <QIcon>

/*!
 * \brief 封装QIcon，并导出为QML类型
 * \details 在QML中不能直接使用QIcon类，常见的比如在Button中设置icon属性为QIcon类会提示Unable to assign QIcon to QQuickIcon。
 *          子类化QQuickImageProvider来实现在QML中访问C++提供的图片感觉即繁琐又复杂。
 *          通过继承QQuickPaintedItem，封装一层QIcon直接导出为QML可以使用的类，使用QIcon无疑会方便许多。
 */
class IconTheme : public QQuickPaintedItem
{
    Q_OBJECT
    Q_PROPERTY(QString iconName WRITE setIconName)
    Q_PROPERTY(QIcon icon READ icon WRITE setIcon)
public:
    IconTheme(QQuickPaintedItem *parent = nullptr);

    QIcon icon() { return m_icon; }
    void setIcon(const QIcon &icon);

    void setIconName(const QString &iconName);
    void paint(QPainter *painter);

private:
    QIcon m_icon;
};

#endif // ICONTHEME_H
