preheatpopup.cpp
3.33 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#include "preheatpopup.h"
#include "ui_preheatpopup.h"
#include <QKeyEvent>
#include "stringer.h"
PreheatPopup::PreheatPopup(QWidget *parent, Oven *oven) :
QWidget(parent),
ui(new Ui::PreheatPopup),
oven(oven),
showingCurrentHumidity(false),
showingCurrentTemp(false)
{
ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
connect(oven, SIGNAL(changed(Oven*)), SLOT(onOvenChanged()));
showCurrentHumidityTimer.setSingleShot(true);
showCurrentHumidityTimer.setInterval(1000);
connect(&showCurrentHumidityTimer, SIGNAL(timeout()), SLOT(showCurrentHumidity()));
showCurrentTempTimer.setSingleShot(true);
showCurrentTempTimer.setInterval(1000);
connect(&showCurrentTempTimer, SIGNAL(timeout()), SLOT(showCurrentTemp()));
ui->preheatGauge->setMaximum(oven->temp());
ui->preheatGauge->setMinimum(oven->currentTemp());
ui->preheatGauge->setValue(oven->currentTemp());
ui->infoButton->hide();
updateView();
start();
ui->background->setFocus();
}
PreheatPopup::~PreheatPopup()
{
delete ui;
}
void PreheatPopup::keyReleaseEvent(QKeyEvent *event)
{
switch (event->key())
{
case 0x01000030: // Turn left
break;
case 0x01000031: // Push
stop();
close();
break;
case 0x01000032: // Turn right
break;
}
}
void PreheatPopup::updateView()
{
ui->timeLabel->setText(Stringer::remainingTime(oven->msecs(), Stringer::fontSize14));
int curInterTemp = oven->currentInterTemp();
if (oven->interTempEnabled())
ui->interTempLabel->setText(Stringer::temperature(curInterTemp, oven->interTemp(), Stringer::fontSize14));
else
ui->interTempLabel->setText(Stringer::temperature(curInterTemp, Stringer::fontSize14));
int humidity;
if (showingCurrentHumidity)
humidity = oven->currentHumidity();
else
humidity = oven->humidity();
int temp;
if (showingCurrentTemp)
temp = oven->currentTemp();
else
temp = oven->temp();
ui->humidityLabel->setText(QString().sprintf("%d%%", humidity));
ui->humidityGauge->setValue(humidity);
ui->heatLabel->setText(Stringer::temperature(temp));
ui->heatGauge->setValue(temp);
ui->preheatGauge->setValue(oven->currentTemp());
}
void PreheatPopup::start()
{
oven->startPreheating();
}
void PreheatPopup::stop()
{
oven->stopPreheating();
}
void PreheatPopup::showCurrentHumidity()
{
showingCurrentHumidity = true;
updateView();
}
void PreheatPopup::showCurrentTemp()
{
showingCurrentTemp = true;
updateView();
}
void PreheatPopup::onOvenChanged()
{
if (oven->currentTemp() >= oven->temp())
{
stop();
close();
}
else
updateView();
}
void PreheatPopup::on_closeButton_clicked()
{
stop();
close();
}
void PreheatPopup::on_closeButton_2_clicked()
{
stop();
close();
}
void PreheatPopup::on_humidityGaugeButton_pressed()
{
showCurrentHumidityTimer.start();
}
void PreheatPopup::on_humidityGaugeButton_released()
{
showCurrentHumidityTimer.stop();
showingCurrentHumidity = false;
updateView();
}
void PreheatPopup::on_heatGaugeButton_pressed()
{
showCurrentTempTimer.start();
}
void PreheatPopup::on_heatGaugeButton_released()
{
showCurrentTempTimer.stop();
showingCurrentTemp = false;
updateView();
}