/**
 * 弹框提示
 */

#include "message_dialog.h"
#include "ui_message_dialog.h"


MessageDialog::MessageDialog(
    QString message,
    QString detail,
    MessageLevel level,
    bool ok_button,
    bool cancel_button,
    QWidget* parent) :
    QDialog(parent),
    ui_(new Ui::messageDialog)
{
    ui_->setupUi(this);
    setWindowFlags(Qt::WindowCloseButtonHint);

    ui_->message_label->setText(message);
    ui_->detail_label->setText(detail);

    if(level == MESSAGE_LEVEL_INFO) {
        ui_->icon_label->setPixmap(QPixmap(
            ":/message/images/message/information_2x.png"));
        setWindowTitle("提示");
    }
    else if(level == MESSAGE_LEVEL_SUCCEESS) {
        ui_->icon_label->setPixmap(QPixmap(
            ":/message/images/message/success_2x.png"));
        setWindowTitle("提示");
    }
    else if(level == MESSAGE_LEVEL_WARNING) {
        ui_->icon_label->setPixmap(QPixmap(
            ":/message/images/message/warning_2x.png"));
        setWindowTitle("警告");
    }
    else if(level == MESSAGE_LEVEL_ERROR) {
        ui_->icon_label->setPixmap(QPixmap(
            ":/message/images/message/error_2x.png"));
        setWindowTitle("错误");
    }

    if(!ok_button) {
        ui_->ok_button->setVisible(false);
    }
    if(!cancel_button) {
        ui_->cancel_button->setVisible(false);
        if(ok_button) {
            ui_->ok_button->setGeometry(
                ui_->cancel_button->geometry());
        }
    }

    connect(ui_->ok_button, SIGNAL(clicked()),
        this, SLOT(__okButtonClicked()));
    connect(ui_->cancel_button, SIGNAL(clicked()),
        this, SLOT(__cancelButtonClicked()));
}

MessageDialog::~MessageDialog()
{
    delete ui_;
}

void MessageDialog::__cancelButtonClicked()
{
    reject();
}

void MessageDialog::__okButtonClicked()
{
    accept();
}
