89 lines
2.5 KiB
C++
89 lines
2.5 KiB
C++
#include "messageDialog.h"
|
||
#include "ui_messageDialog.h"
|
||
|
||
MessageDialogBtn g_msgDlgBtn = btn_Null;
|
||
|
||
MessageDialog::MessageDialog(QWidget *parent)
|
||
: QDialog(parent)
|
||
, ui(new Ui::messageDialog)
|
||
{
|
||
ui->setupUi(this);
|
||
|
||
if(QSysInfo::kernelType() == "linux")
|
||
{
|
||
//Linux下默认的Qt::Dialog即使有父窗口也无法按照子窗口的行为进行展示,并且最大、最小按钮不好关闭,因此需要去掉Dialog属性,随之而来的问题是,模态无法起作用
|
||
setWindowFlags(windowFlags() & ~Qt::Dialog);
|
||
setStyleSheet("QDialog{border: 1px solid rgb(110,110,110);border-radius:5px;background-color:rgb(30,30,30);}");
|
||
}
|
||
else
|
||
{
|
||
setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint);//去掉关闭按钮和图标
|
||
setFixedSize(width(), height()); //不可缩放
|
||
}
|
||
|
||
connect(ui->btnConfrim, SIGNAL(clicked()), this, SLOT(onBtnClicked_confirm()));
|
||
connect(ui->btnYes, SIGNAL(clicked()), this, SLOT(onBtnClicked_yes()));
|
||
connect(ui->btnNo, SIGNAL(clicked()), this, SLOT(onBtnClicked_no()));
|
||
}
|
||
|
||
MessageDialog::~MessageDialog()
|
||
{
|
||
delete ui;
|
||
}
|
||
|
||
void MessageDialog::setType(MessageDialogType type)
|
||
{
|
||
if(type == type_information)
|
||
{
|
||
ui->typeLabel->setStyleSheet("border-image: url(:/img/images/icon_information.png);");
|
||
ui->stackedWidget->setCurrentIndex(0);
|
||
}
|
||
else if(type == type_question)
|
||
{
|
||
ui->typeLabel->setStyleSheet("border-image: url(:/img/images/icon_question.png);");
|
||
ui->stackedWidget->setCurrentIndex(1);
|
||
}
|
||
else if(type == type_warning)
|
||
{
|
||
ui->typeLabel->setStyleSheet("border-image: url(:/img/images/icon_no.png);");
|
||
ui->stackedWidget->setCurrentIndex(0);
|
||
}
|
||
}
|
||
|
||
void MessageDialog::setMessage(MessageDialogType type, const QString& strTitle, const QString& strContent)
|
||
{
|
||
setType(type);
|
||
ui->labelTitle->setText(strTitle);
|
||
setWindowTitle(strTitle);
|
||
if(strContent.length() > 19)
|
||
{
|
||
//QString& strText = const_cast<QString&>(strContent);
|
||
QString strText(strContent);
|
||
strText.insert(19, "\n"); //实现简单自动换行
|
||
ui->labelContent->setText(strText);
|
||
}
|
||
else
|
||
ui->labelContent->setText(strContent);
|
||
}
|
||
|
||
void MessageDialog::onBtnClicked_confirm()
|
||
{
|
||
close();
|
||
//emit sgl_hide();
|
||
}
|
||
|
||
void MessageDialog::onBtnClicked_yes()
|
||
{
|
||
g_msgDlgBtn = btn_Yes;
|
||
close();
|
||
//emit sgl_hide();
|
||
}
|
||
|
||
void MessageDialog::onBtnClicked_no()
|
||
{
|
||
g_msgDlgBtn = btn_No;
|
||
close();
|
||
//emit sgl_hide();
|
||
}
|
||
|