-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
125 lines (109 loc) · 2.67 KB
/
mainwindow.cpp
File metadata and controls
125 lines (109 loc) · 2.67 KB
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
117
118
119
120
121
122
123
124
125
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QThread>
#include <QTime>
#include <QString>
#include <QMessageBox>
void mkhelp ()
{
QMessageBox *msgBox;
msgBox = new QMessageBox(
"Help",
"<b>Set clocks</b><br>Input min and sec in input boxes and click <code>Start</code> to start clock<br><b>Stop clock</b><br>Press 'P' or click menu 'Clock->Stop'",
QMessageBox::Information,
QMessageBox::Cancel | QMessageBox::Escape,
0,
0);
msgBox->show();
}
void mkabout ()
{
QMessageBox *msgBox;
msgBox = new QMessageBox(
"About",
"LanGong Clock is made by <a href=\"https://langong-dev.github.io\">LanGong Dev Team</a> and undered MIT-License. Published at GitHub, <a href=\"https://github.com/langong-dev/langong-clock\">Repo langong-dev/langong-clock</a>. And made with QT5.<br>© 2020 LanGong.",
QMessageBox::Information,
QMessageBox::Cancel | QMessageBox::Escape,
0,
0);
msgBox->show();
}
int nsec, nmin;
QString ch (int a, int b)
{
QString s;
if (a < 10)
{
s += "0";
}
s += QString::number(a);
s += ":";
if (b < 10)
{
s += "0";
}
s += QString::number(b);
return s;
}
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_lcdNumber_overflow()
{
ui->lcdNumber->display("Error");
}
void MainWindow::on_pushButton_clicked()
{
nsec = ui->spinBox->value();
nmin = ui->spinBoxm->value();
if (nmin < 0 || nsec < 0)
{
ui->lcdNumber->display("Error");
}
ui->lcdNumber->display(ch(nmin,nsec));
if (!(nmin <= 0 && nsec <= 0))
{
while (true)
{
nsec--;
QTime _Timer = QTime::currentTime().addMSecs(1000);
while( QTime::currentTime() < _Timer )
QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
if (nsec < 0)
{
nsec += 60;
nmin --;
}
if (nmin <=0 && nsec <= 0)
{
break;
}
ui->lcdNumber->display(ch(nmin,nsec));
}
}
ui->lcdNumber->display("00:00");
QApplication::beep();
}
void MainWindow::crt()
{
ui->lcdNumber->display("00:00");
}
void MainWindow::on_actionStop_clock_triggered()
{
nsec = nmin = 0;
}
void MainWindow::on_actionHelp_triggered()
{
mkhelp();
}
void MainWindow::on_actionAbout_triggered()
{
mkabout();
}