#include "icontheme.h"

IconTheme::IconTheme(QQuickPaintedItem *parent)
    : QQuickPaintedItem(parent)
{

}

void IconTheme::setIcon(const QIcon &icon)
{
    m_icon = icon;
}

void IconTheme::setIconName(const QString &iconName)
{
    if(!QIcon::hasThemeIcon(iconName))
    {
        qWarning() << "未找到名为 " << iconName << " 的图标!";
        return;
    }
    m_icon = QIcon::fromTheme(iconName, m_icon);
}

void IconTheme::paint(QPainter *painter)
{
    if(m_icon.isNull()) return;
    m_icon.paint(painter, boundingRect().toRect());
}
