#include "loadinglabel.h"

LoadingLabel::LoadingLabel(QObject *parent)
{
    m_timer = new QTimer(this);
    m_timer->setInterval(100);
    connect(m_timer,&QTimer::timeout,this,&LoadingLabel::refreshIconNum);
}

LoadingLabel::~LoadingLabel()
{
//    delete m_timer;
}

void LoadingLabel::setTimerStop()
{  
    m_timer->stop();
}

void LoadingLabel::setTimerStart()
{
    m_timer->start();
}

void LoadingLabel::setTimeReresh(int m)
{
    m_timer->setInterval(m);
}

void LoadingLabel::paintEvent(QPaintEvent *e)
{
    QPainter painter(this);
    painter.setRenderHint(QPainter::SmoothPixmapTransform);
    painter.setPen(Qt::transparent);

    painter.drawPixmap(0,0,this->width(),this->height(),QIcon::fromTheme("ukui-loading-"+QString("%1").arg(i)+"-symbolic").pixmap(this->width(),this->height()));
}

void LoadingLabel::refreshIconNum()
{
//    qDebug() << Q_FUNC_INFO << QString::number(i,10);
    this->update();
    if(i == 0)
        i = 8;
    i--;
}
