-
Notifications
You must be signed in to change notification settings - Fork 0
/
clockpage.cpp
100 lines (88 loc) · 2.01 KB
/
clockpage.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
#include "clockpage.h"
#include "ui_clock.h"
ClockPage::ClockPage(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::Clock)
{
ui->setupUi(this);
timeSet=ui->timeEdit->time();
ui->lineEdit->setText(timeSet.toString());
hasSetTime = false;
btnStartHasClicked = false;
isStop = false;
}
ClockPage::~ClockPage()
{
delete ui;
}
void ClockPage::on_TimeEdit_usetTimeChanged(const QTime &time)
{
ui->lineEdit->setText(time.toString());
setSecond = time.hour()*3600+time.minute()*60;
hasSetTime = true;
btnStartHasClicked = false;
}
void ClockPage::on_btnStart_clicked()
{
isStop = false;
if(btnStartHasClicked)
{
}
else
{
if(hasSetTime)
{
timerId = startTimer(1000);
btnStartHasClicked =true;
}
else
{
QMessageBox::information(this,"提示","请先设置时间");
}
}
}
void ClockPage::timerEvent(QTimerEvent *)
{
if(isStop)
{
}
else
{
setSecond -=1;
timeSet.setHMS(setSecond/3600,(setSecond - (setSecond-setSecond/3600*3600)/60),setSecond-setSecond/60*60);
ui->lineEdit->setText(timeSet.toString());
if (setSecond = 0)
{
QMessageBox::information(this,"提示","时间到");
killTimer(timerId);
}
}
}
void ClockPage::on_btnStop_clicked()
{
if(btnStartHasClicked)
{
isStop = true;
}
else
{
QMessageBox::information(this,"提示","未开始计时");
}
}
void ClockPage::on_btnReset_clicked()
{
if(btnStartHasClicked)
{
killTimer(timerId);
timeSet.setHMS(0,0,0);
ui->lineEdit->setText(timeSet.toString());
QTime time(0,0,0);
ui->timeEdit->setTime(time);
hasSetTime= false;
btnStartHasClicked = false;
}
else
{
QMessageBox::information(this,"提示","未开始计时");
}
}