-
Notifications
You must be signed in to change notification settings - Fork 83
/
Copy pathfrmmessagebox.cpp
116 lines (99 loc) · 2.76 KB
/
frmmessagebox.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#if _MSC_VER >= 1600
#pragma execution_character_set("utf-8")
#endif
#include "frmmessagebox.h"
#include "ui_frmmessagebox.h"
#include "api/myhelper.h"
frmMessageBox *frmMessageBox::_instance = 0;
frmMessageBox::frmMessageBox(QWidget *parent) :
QDialog(parent),
ui(new Ui::frmMessageBox)
{
ui->setupUi(this);
this->InitStyle();
this->InitForm();
myHelper::FormInCenter(this);
}
frmMessageBox::~frmMessageBox()
{
delete ui;
}
void frmMessageBox::InitStyle()
{
if (App::UseStyle) {
this->setProperty("Form", true);
this->setProperty("CanMove", true);
this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint |
Qt::WindowMinMaxButtonsHint | Qt::WindowStaysOnTopHint);
IconHelper::Instance()->SetIcoMain(ui->lab_Ico, App::FontSize + 2);
IconHelper::Instance()->SetIcoClose(ui->btnMenu_Close);
connect(ui->btnMenu_Close, SIGNAL(clicked()), this, SLOT(close()));
} else {
this->setWindowFlags(Qt::WindowCloseButtonHint | Qt::WindowStaysOnTopHint);
this->resize(size().width(), size().height() - ui->widget_title->size().height());
ui->widget_title->setVisible(false);
}
#ifdef __arm__
this->setFixedSize(300, 160);
#endif
this->setWindowTitle(ui->lab_Title->text());
connect(ui->btnCancel, SIGNAL(clicked()), this, SLOT(close()));
}
void frmMessageBox::InitForm()
{
closeSec = 0;
currentSec = 0;
QTimer *timer = new QTimer(this);
timer->setInterval(1000);
connect(timer, SIGNAL(timeout()), this, SLOT(CheckSec()));
timer->start();
}
void frmMessageBox::CheckSec()
{
if (closeSec == 0) {
return;
}
if (currentSec < closeSec) {
currentSec++;
} else {
this->close();
}
if (App::UseStyle) {
QString str = QString("关闭倒计时 %1 s").arg(closeSec - currentSec + 1);
ui->labTime->setText(str);
} else {
QString str = QString("%1 关闭倒计时 %2 s").arg(ui->lab_Title->text()).arg(closeSec - currentSec + 1);
this->setWindowTitle(str);
}
}
void frmMessageBox::SetMessage(QString msg, int type, int closeSec)
{
this->closeSec = closeSec;
this->currentSec = 0;
ui->labTime->clear();
this->setWindowTitle(ui->lab_Title->text());
CheckSec();
if (type == 0) {
ui->labIcoMain->setStyleSheet("border-image: url(:/image/msg_info.png);");
ui->btnCancel->setVisible(false);
ui->lab_Title->setText("提示");
} else if (type == 1) {
ui->labIcoMain->setStyleSheet("border-image: url(:/image/msg_question.png);");
ui->lab_Title->setText("询问");
} else if (type == 2) {
ui->labIcoMain->setStyleSheet("border-image: url(:/image/msg_error.png);");
ui->btnCancel->setVisible(false);
ui->lab_Title->setText("错误");
}
ui->labInfo->setText(msg);
}
void frmMessageBox::closeEvent(QCloseEvent *)
{
closeSec = 0;
currentSec = 0;
}
void frmMessageBox::on_btnOk_clicked()
{
done(1);
this->close();
}