#include "mainbtn.h"
#include "ui_mainbtn.h"

#include <QMouseEvent>

#include <qDebug>

MainBtn::MainBtn(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::MainBtn)
{
    ui->setupUi(this);
    _checked = false;
}

MainBtn::~MainBtn()
{
    delete ui;
}

void MainBtn::setChecked(bool check)
{
    _checked = check;

    QString type =  this->property("type").toString();

    //qDebug() << "====" << type << ";" << check << _type;

    if(type.compare("order",Qt::CaseInsensitive) == 0)
    {
        if(check)
        {

            ui->mainbtnlabel_name->setStyleSheet("#mainbtnlabel_name{color:rgba(255,255,255,1)}");
            ui->mainbtnlabel_lg->setStyleSheet("#mainbtnlabel_lg{ border-image: url(:orders_on.png)}");
        }
        else
        {
            ui->mainbtnlabel_name->setStyleSheet("#mainbtnlabel_name{color:rgba(54,60,66,1)}");
            ui->mainbtnlabel_lg->setStyleSheet("#mainbtnlabel_lg{ border-image: url(:orders_off.png)}");
        }
        return ;
    }

    if(type.compare("refund",Qt::CaseInsensitive) == 0)
    {
        if(check)
        {
            ui->mainbtnlabel_name->setStyleSheet("#mainbtnlabel_name{color:rgba(255,255,255,1)}");
            ui->mainbtnlabel_lg->setStyleSheet("#mainbtnlabel_lg{ border-image: url(:refund_on.png)}");
        }
        else
        {
            ui->mainbtnlabel_name->setStyleSheet("#mainbtnlabel_name{color:rgba(54,60,66,1)}");
            ui->mainbtnlabel_lg->setStyleSheet("#mainbtnlabel_lg{ border-image: url(:refund_off.png)}");
        }
        return ;
    }

    if(type.compare("set",Qt::CaseInsensitive) == 0)
    {
        if(check)
        {
            ui->mainbtnlabel_name->setStyleSheet("#mainbtnlabel_name{color:rgba(255,255,255,1)}");
            ui->mainbtnlabel_lg->setStyleSheet("#mainbtnlabel_lg{ border-image: url(:setting_on.png)}");
        }
        else
        {
            ui->mainbtnlabel_name->setStyleSheet("#mainbtnlabel_name{color:rgba(54,60,66,1)}");
            ui->mainbtnlabel_lg->setStyleSheet("#mainbtnlabel_lg{ border-image: url(:setting_off.png)}");
        }
        return ;
    }
}

void MainBtn::mousePressEvent(QMouseEvent *e)
{
    if(e->buttons()&Qt::LeftButton)
    {
        emit clicked();
        return ;
    }
    return QWidget::mousePressEvent(e);
}

void MainBtn::SetText(QString data, QString type)
{
    _type = type;
    ui->mainbtnlabel_name->setText(data);

    ui->mainbtnlabel_name->setStyleSheet("#mainbtnlabel_name{color:rgba(255,255,255,1)}");

    if(type.compare("order",Qt::CaseInsensitive) == 0)
    {
        ui->mainbtnlabel_lg->setStyleSheet("#mainbtnlabel_lg{ border-image: url(:orders_off.png)}");
        return ;
    }

    if(type.compare("refund",Qt::CaseInsensitive) == 0)
    {
        ui->mainbtnlabel_lg->setStyleSheet("#mainbtnlabel_lg{ border-image: url(:refund_off.png)}");
        return ;
    }

    if(type.compare("set",Qt::CaseInsensitive) == 0)
    {
        ui->mainbtnlabel_lg->setStyleSheet("#mainbtnlabel_lg{ border-image: url(:setting_off.png)}");
        return ;
    }
}
