#include "changeQuestion.h"
#include "ui_changeQuestion.h"

#include <QFile>

#include "CAppInfo.h"

changeQuestion::changeQuestion(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::changeQuestion)
{
    ui->setupUi(this);

    setAttribute(Qt::WA_DeleteOnClose);

//    QFile qssFile(":/qss/main.qss");
//    qssFile.open(QFile::ReadOnly);
//    QString qss;
//    qss = qssFile.readAll();
//    setStyleSheet(qss);
    setStyleSheet(g_appInfoPtr->m_sQssStr);


}

void changeQuestion::showBtn(int nType)
{
    sStyle = QString(R"(QPushButton
                            {
                                outline:none;
                                background:rgba(19,187,138,1);
                                border-radius:%1px;
                                font-size:%2px;
                                font-family:"Microsoft YaHei";
                                font-weight:600;
                                color:rgba(255,255,255,1);
                            })").arg((int)(g_appInfoPtr->m_fRate*10))
                            .arg((int)(g_appInfoPtr->m_fRate*12));
    sDisableStyle = QString(R"(QPushButton
                            {
                                outline:none;
                                background:rgba(239,240,245,1);
                                border-radius:%1px;
                                font-size:%2px;
                                font-family:"Microsoft YaHei";
                                font-weight:600;
                                color:rgba(153,153,153,1);
                            })").arg((int)(g_appInfoPtr->m_fRate*10))
                            .arg((int)(g_appInfoPtr->m_fRate*12));
    ui->btn_cq_previous->setStyleSheet(sStyle);
    ui->btn_cq_next->setStyleSheet(sStyle);
    ui->btn_cq_previous->setEnabled(true);
    ui->btn_cq_next->setEnabled(true);
    if(nType == 1)
    {
        ui->btn_cq_previous->setStyleSheet(sDisableStyle);
        ui->btn_cq_previous->setEnabled(false);
    }
    else if(nType == 2)
    {
        ui->btn_cq_next->setStyleSheet(sDisableStyle);
        ui->btn_cq_next->setEnabled(false);
    }
}


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

void changeQuestion::setUI(const int nLeft, const int nTop, const int nWidth, const int nHeight)
{
    setGeometry(nLeft, nTop, nWidth, nHeight);
    QIcon icon(QPixmap(":/images/btn-icon-previous.png"));
    ui->btn_cq_previous->setIcon(icon);
    ui->btn_cq_previous->setGeometry(g_appInfoPtr->m_fRate*80, nHeight - g_appInfoPtr->m_fRate*32, g_appInfoPtr->m_fRate*100, g_appInfoPtr->m_fRate*32);


    QIcon icon1(QPixmap(":/images/btn-icon-next.png"));
    ui->btn_cq_next->setIcon(icon1);

    ui->btn_cq_next->setGeometry(ui->btn_cq_previous->x() + ui->btn_cq_previous->width() + g_appInfoPtr->m_fRate*20,
                                 ui->btn_cq_previous->y(), ui->btn_cq_previous->width(), ui->btn_cq_previous->height());

}

void changeQuestion::on_btn_cq_previous_clicked()
{
    ui->btn_cq_previous->setStyleSheet(sDisableStyle);
    ui->btn_cq_next->setStyleSheet(sDisableStyle);
    ui->btn_cq_previous->setEnabled(false);
    ui->btn_cq_next->setEnabled(false);
    emit previousQuestion();
}

void changeQuestion::on_btn_cq_next_clicked()
{
    ui->btn_cq_previous->setStyleSheet(sDisableStyle);
    ui->btn_cq_next->setStyleSheet(sDisableStyle);
    ui->btn_cq_previous->setEnabled(false);
    ui->btn_cq_next->setEnabled(false);
    emit nextQuestion();
}
