#include "awTimeLeftTips.h"
#include "ui_awTimeLeftTips.h"

#include "CAppInfo.h"

#include <QDesktopWidget>

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

    setStyleSheet(g_appInfoPtr->m_sQssStr);

    if(type == MASK_POP_WIDGET_TYPE::wt_timeLeft)
    {
        ui->label_awtlt_content->setText(QString::fromLocal8Bit(R"(<html>
                                                <style>
                                                    .normal
                                                    {
                                                        font-size:%1px;
                                                        font-family:"Microsoft YaHei";
                                                        font-weight:400;
                                                        color:rgba(102,102,102,1);
                                                    }
                                                    .hover
                                                    {
                                                        font-size:%2px;
                                                        font-family:"Microsoft YaHei";
                                                        font-weight:600;
                                                        color:rgba(255,0,0,1);
                                                    }
                                                </style>
                                                <body>
                                                    <span class="normal">还有</span><span class="hover">五</span><span class="normal">分钟即将结束本场考试，请合理分配时间！</span>
                                                </body>
                                            </html>)").arg((int)(g_appInfoPtr->m_fRate * 14)).arg((int)(g_appInfoPtr->m_fRate * 16)));
    }
    else
    {
        ui->label_awtlt_title->setText(QString::fromLocal8Bit("网络连接异常"));
        ui->label_awtlt_content->setText(QString::fromLocal8Bit("退出考试"));
    }

    initUI();
}

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

void awTimeLeftTips::setText(QString sTitle, QString sContent)
{	
    ui->label_awtlt_title->setText(sTitle);
    ui->label_awtlt_title->setFixedWidth(ui->widget_awtlt_bg->width() - g_appInfoPtr->m_fRate * 20*2);
	ui->label_awtlt_title->adjustSize();
	ui->label_awtlt_title->setGeometry(g_appInfoPtr->m_fRate * 20, g_appInfoPtr->m_fRate * 20,
		ui->label_awtlt_title->width(), ui->label_awtlt_title->height());
	
	ui->label_awtlt_content->setText(sContent);
	ui->label_awtlt_content->adjustSize();
	ui->label_awtlt_content->setGeometry(g_appInfoPtr->m_fRate * 40, ui->label_awtlt_title->y() + ui->label_awtlt_title->height() + g_appInfoPtr->m_fRate * 40,
		ui->label_awtlt_content->width(), ui->label_awtlt_content->height());
}

void awTimeLeftTips::initUI()
{
    QDesktopWidget *dekwiget = QApplication::desktop();
    setGeometry(0, 0, dekwiget->width(), dekwiget->height());
	ui->widget_mask->setGeometry(0, 0, width(), height());
	ui->widget_awtlt_bg->setGeometry((width() - g_appInfoPtr->m_fRate*420)/2,
		g_appInfoPtr->m_fRate * 190, g_appInfoPtr->m_fRate*420, g_appInfoPtr->m_fRate*190);
	ui->label_awtlt_title->adjustSize();
	ui->label_awtlt_title->setGeometry(g_appInfoPtr->m_fRate *20, g_appInfoPtr->m_fRate *20,
		ui->label_awtlt_title->width(), ui->label_awtlt_title->height());	
	ui->label_awtlt_content->adjustSize();
	ui->label_awtlt_content->setGeometry(g_appInfoPtr->m_fRate * 40, ui->label_awtlt_title->y() + ui->label_awtlt_title->height() +  g_appInfoPtr->m_fRate * 40,
		ui->label_awtlt_content->width(), ui->label_awtlt_content->height());
	ui->btn_awtlt_confirm->setGeometry(ui->widget_awtlt_bg->width() - g_appInfoPtr->m_fRate *(20 + 60),
		ui->widget_awtlt_bg->height() - g_appInfoPtr->m_fRate *(20 + 40), 60, 40);
}

void awTimeLeftTips::on_btn_awtlt_confirm_clicked()
{
    emit timeLeftConfirm();
}
