-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtime2restdlg.cpp
88 lines (67 loc) · 1.85 KB
/
time2restdlg.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
#include "time2restdlg.h"
#include "ui_time2restdlg.h"
#include <QVBoxLayout>
time2restDlg::time2restDlg(QWidget *parent) :
QDialog(parent),
ui(new Ui::time2restDlg)
{
ui->setupUi(this);
ui->pushButton->raise();
ui->lcdNumber->raise();
int bkIndex = rand() % 6;
if (bkIndex == 0){
bkIndex = 1;
}
QString css = QString("background-image: url(:/icon/main/res/bk%1.jpg)").arg(bkIndex);
setStyleSheet(css);
ui->pushButton->setStyleSheet("border:0px groove gray;border-radius:10px;padding:2px 4px;");
QVBoxLayout *pLayout = new QVBoxLayout(this);
pLayout->addWidget(ui->lcdNumber);
pLayout->addWidget(ui->pushButton);
pLayout->setAlignment(ui->lcdNumber,Qt::AlignCenter);
pLayout->setAlignment(ui->pushButton,Qt::AlignCenter);
this->setLayout(pLayout);
m_iCounter = EP_MAX_REST_TIME;
m_timerPerSec = new QTimer(this);
connect(m_timerPerSec,SIGNAL(timeout()),this,SLOT(onTimerCounterEvent()));
m_timerPerSec->start(1000);
//ui->pushButton->setEnabled(false);
onTimerCounterEvent();
}
time2restDlg::~time2restDlg()
{
delete ui;
}
void time2restDlg::on_pushButton_clicked()
{
m_timerPerSec->stop();
emit restDlgClosed();
close();
}
void time2restDlg::keyPressEvent(QKeyEvent* /*event*/){
}
void time2restDlg::onTimerCounterEvent()
{
--m_iCounter;
if (m_iCounter < 0)
{
m_timerPerSec->stop();
emit restDlgClosed();
close();
return;
}
if (m_iCounter < EP_MAX_REST_TIME/2)
{
ui->pushButton->setEnabled(true);
}
QString info = "";
if (m_iCounter > 3600)
{
info.sprintf("%02d:%02d:%02d",m_iCounter / 3600,(m_iCounter % 3600)/ 60,m_iCounter % 60);
}
else
{
info.sprintf("%02d:%02d",m_iCounter / 60, m_iCounter % 60);
}
ui->lcdNumber->display(info);
}