-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwidget.cpp
125 lines (93 loc) · 1.87 KB
/
widget.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
117
118
119
120
121
122
123
124
#include "widget.h"
#include "ui_widget.h"
#include <QMessageBox>
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
changeEnable();
}
Widget::~Widget()
{
delete ui;
}
void Widget::changeMoney(int diff) {
money += diff;
ui->lcdNumber->display(money);
changeEnable();
}
void Widget::changeEnable() {
ui->pbCoffee->setEnabled(money >= 100);
ui->pbTea->setEnabled(money >= 200);
ui->pbTang->setEnabled(money >= 300);
ui->pbReset->setEnabled(money > 0);
}
void Widget::on_pbCoin10_clicked()
{
changeMoney(10);
}
void Widget::on_pbCoin50_clicked()
{
changeMoney(50);
}
void Widget::on_pbCoin100_clicked()
{
changeMoney(100);
}
void Widget::on_pbCoin500_clicked()
{
changeMoney(500);
}
void Widget::on_pbCoffee_clicked()
{
changeMoney(-100);
}
void Widget::on_pbTea_clicked()
{
changeMoney(-200);
}
void Widget::on_pbTang_clicked()
{
changeMoney(-300);
}
void Widget::on_pbReset_clicked()
{
int rs500, rs100, rs50, rs10;
rs500 = money / 500;
money %= 500;
rs100 = money / 100;
money = money % 100;
rs50 = money / 50;
money = money % 50;
rs10 = money / 10;
money = money % 10;
QString msg = "";
if (rs500) {
msg += "500 : " + QString::number(rs500);
}
if (rs100) {
if (msg != "") {
msg = msg + "\n";
}
msg = msg + "100 : " + QString::number(rs100);
}
if (rs50) {
if (msg != "") {
msg = msg + "\n";
}
msg = msg + "50 : " + QString::number(rs50);
}
if (rs10) {
if (msg != "") {
msg = msg + "\n";
}
msg += "10 : " + QString::number(rs10);
}
if (msg == "") {
msg = "No money to return.";
}
QMessageBox mb;
mb.information(nullptr, "title", msg);
changeMoney(0);
}