#include "popMsgBox.h"
#include "ui_popMsgBox.h"

#include "CAppInfo.h"

#include <QDesktopWidget>

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

    setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint);
    setAttribute(Qt::WA_TranslucentBackground);       //小部件应该具有半透明的背景

    setStyleSheet(g_appInfoPtr->m_sQssStr);
}

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

void popMsgBox::setMsg(QString sMsg, QString sTitle)
{
    ui->label_pmb_content->setText(sMsg);
    ui->label_pmb_title->setText(sTitle);
}

void popMsgBox::initUI()
{
    int nCW = g_appInfoPtr->m_fRate*340;
    QDesktopWidget *dekwiget = QApplication::desktop();
    setGeometry((dekwiget->width() - nCW)/2, (dekwiget->height() - g_appInfoPtr->m_fRate*203)/2, nCW, g_appInfoPtr->m_fRate*203);
    ui->widget_pmb_bg->setGeometry(0, 0 , nCW, g_appInfoPtr->m_fRate*203);
    ui->label_pmb_icon->setGeometry(g_appInfoPtr->m_fRate*30, g_appInfoPtr->m_fRate*30,
                                   g_appInfoPtr->m_fRate*40, g_appInfoPtr->m_fRate*40);
    ui->label_pmb_title->adjustSize();
    ui->label_pmb_title->setGeometry(ui->label_pmb_icon->x() + ui->label_pmb_icon->width() + g_appInfoPtr->m_fRate*16, g_appInfoPtr->m_fRate*30,
                                     ui->label_pmb_title->width(), ui->label_pmb_title->height());
    ui->label_pmb_content->setGeometry(ui->label_pmb_icon->x() + ui->label_pmb_icon->width() + g_appInfoPtr->m_fRate*16,
                                       ui->label_pmb_title->y() + ui->label_pmb_title->height() + g_appInfoPtr->m_fRate*8,
                                   224, 80);
    ui->btn_yes->setGeometry(ui->widget_pmb_bg->width() - g_appInfoPtr->m_fRate*(20 + 80),
                             ui->widget_pmb_bg->height() - g_appInfoPtr->m_fRate*(20 + 30),
                             g_appInfoPtr->m_fRate*80, g_appInfoPtr->m_fRate*30);
    ui->btn_no->setGeometry(ui->btn_yes->x() - g_appInfoPtr->m_fRate*15 - ui->btn_yes->width(),
                            ui->btn_yes->y(), ui->btn_yes->width(), ui->btn_yes->height());
}

int popMsg(QString sMsg, QString sTitle, QWidget *parent)
{
    popMsgBox msgDlg(parent);

    msgDlg.setMsg(sMsg, sTitle);
    msgDlg.initUI();
    return msgDlg.exec();
}

void popMsgBox::on_btn_yes_clicked()
{
    accept();
}

void popMsgBox::on_btn_no_clicked()
{
    reject();
}
