#include "awqn_item.h"
#include "ui_awqn_item.h"

#include "CAppInfo.h"
#include "logproc.h"

awqn_item::awqn_item(CSubQuestionStruct &sqs, QWidget *parent) :
    QWidget(parent),
    ui(new Ui::awqn_item), m_sqs(sqs)
{
    ui->setupUi(this);

    setStyleSheet(g_appInfoPtr->m_sQssStr);

	ui->btn_awqn_quesion->setText(QString::number(sqs.nShowNumber));
    refreshStatus();
}

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

void awqn_item::setUI(int nX, int nY, int nWidth, int nHeight)
{    
    setGeometry(nX, nY, nWidth, nHeight);
	ui->btn_awqn_quesion->setGeometry(0, 0, width(), height());

}

void awqn_item::on_btn_awqn_quesion_clicked()
{
    emit showSubQuestion(m_sqs.nOrder);
}

bool awqn_item::isMarked()
{
   return m_sqs.bMarked;
}

bool awqn_item::isAnswered()
{
    return m_sqs.bAnswered;
}


void awqn_item::refreshStatus()
{
    QString sNormalStyle = QString(R"(QPushButton
        {
            outline:none;
            font-size:%1px;
            font-family:"Microsoft YaHei";
            font-weight:400;
            color:rgba(136,146,146,1);
            background:rgba(239,240,245,1);
            border:0px;
            border-radius:%2px;
        })").arg((int)(g_appInfoPtr->m_fRate*12)).arg((int)(g_appInfoPtr->m_fRate*15));


    QString sMarkedStyle = QString(R"(QPushButton
        {
            outline:none;
            font-size:%1px;
            font-family:"Microsoft YaHei";
            font-weight:400;
            color:rgba(255,255,255,1);
            background:rgba(255,159,67,1);
            border:0px solid rgba(255,159,67,1);
            border-radius:%2px;
        })").arg((int)(g_appInfoPtr->m_fRate*12))
            //.arg((int)(g_appInfoPtr->m_fRate*1 < 1 ? 1 : g_appInfoPtr->m_fRate*1))
            .arg((int)(g_appInfoPtr->m_fRate*15));
    QString sAnsweredStyle = QString(R"(QPushButton
        {
            outline:none;
            font-size:%1px;
            font-family:"Microsoft YaHei";
            font-weight:400;
            color:rgba(255,255,255,1);
            background:rgba(131,172,247,1);
            border:0px solid rgba(131,172,247,1);
            border-radius:%2px;
        })").arg((int)(g_appInfoPtr->m_fRate*12))
         //   .arg((int)(g_appInfoPtr->m_fRate*1 < 1 ? 1 : g_appInfoPtr->m_fRate*1))
            .arg((int)(g_appInfoPtr->m_fRate*15));
    QString sCurrentStyle = QString(R"(QPushButton
        {
            outline:none;
            font-size:%1px;
            font-family:"Microsoft YaHei";
            font-weight:400;
            color:rgba(255,255,255,1);
            background:rgba(19,187,138,1);
            border:0px solid rgba(131,172,247,1);
            border-radius:%2px;
        })").arg((int)(g_appInfoPtr->m_fRate*12))
            .arg((int)(g_appInfoPtr->m_fRate*15));
    ui->btn_awqn_quesion->setStyleSheet(sNormalStyle);

    if(m_sqs.bAnswered)
    {
        ui->btn_awqn_quesion->setStyleSheet(sAnsweredStyle);
    }
    
	if(m_sqs.bMarked)
    {
        ui->btn_awqn_quesion->setStyleSheet(sMarkedStyle);
    }
    
	if(m_sqs.bCurrent)
    {
        ui->btn_awqn_quesion->setStyleSheet(sCurrentStyle);
    }
}
