#include "loadingindicator.h"

#define WIDTH       260
#define HEIGHT      80

LoadingIndicator::LoadingIndicator(QWidget *parent)
    : QFrame(parent)
    , movie(":/loading.gif")
{    
    setObjectName("LoadingIndicator");
    setStyleSheet("#LoadingIndicator{border-radius:5px; background-color:rgba(90, 90, 90, 50); margin:15px;}");
    setLayout(&layout);
    setWindowFlags(Qt::Widget | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowStaysOnTopHint);
    setGeometry((parentWidget()->width() - WIDTH)/2, (parentWidget()->height() - HEIGHT)/2, WIDTH, HEIGHT);

    lblMovie.setMovie(&movie);
    lblMovie.setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);

    layout.addWidget(&lblMovie);
    layout.addWidget(&lblMessage);

	hide();
}

void LoadingIndicator::setMessage(const QString &msg)
{
	show();
    move((parentWidget()->width() - WIDTH)/2, (parentWidget()->height() - HEIGHT)/2);
    lblMessage.setText(msg);
    lblMovie.show();
    movie.start();
    show();
    raise();
}

void LoadingIndicator::setPause(bool paused)
{
	movie.setPaused(paused);
}