Blame view

app/gui/oven_control/programmingmanualwindow.cpp 8.95 KB
81b835e59   김태훈   한글 폰트 변경
1
2
  #include "programmingmanualwindow.h"
  #include "ui_programmingmanualwindow.h"
dcfd897f3   김태훈   수동 요리 만들기 추가
3
4
5
  #include "stringer.h"
  #include "programmingmanualcoretemppopup.h"
  #include "cookprogram.h"
382b586e9   김태훈   프로그래밍 모드 임시 구현
6
  #include "soundplayer.h"
95a9aa99d   김태훈   기능 보충 구현
7
8
  #include "configwindow.h"
  #include "mainwindow.h"
dcfd897f3   김태훈   수동 요리 만들기 추가
9
10
  
  ProgrammingManualWindow::ProgrammingManualWindow(QWidget *parent, Define::Mode mode) :
81b835e59   김태훈   한글 폰트 변경
11
12
13
14
      QMainWindow(parent),
      ui(new Ui::ProgrammingManualWindow)
  {
      ui->setupUi(this);
dcfd897f3   김태훈   수동 요리 만들기 추가
15
16
17
  
      ui->clockContainer->setParent(ui->upperStack);
      setAttribute(Qt::WA_DeleteOnClose);
935b853a4   김태훈   새 슬라이더 적용
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
      ui->humiditySlider->setSubPixmap(":/images/slider/humidity.png");
      ui->humiditySlider->setRange(0, 100);
      ui->humiditySlider->bigTickInterval = 50;
      ui->humiditySlider->tickInterval = 10;
  
      ui->tempSlider->setSubPixmap(":/images/slider/temp.png");
      ui->tempSlider->bigTickInterval = 50;
      ui->tempSlider->tickInterval = 10;
  
      ui->timeSlider->setSubPixmap(":/images/slider/time.png");
      ui->timeSlider->setRange(0, 342);
      ui->timeSlider->bigTicks.append(0);
      ui->timeSlider->bigTicks.append(180);
      ui->timeSlider->bigTicks.append(270);
      ui->timeSlider->bigTicks.append(342);
      ui->timeSlider->ticks.append(60);
      ui->timeSlider->ticks.append(120);
      ui->timeSlider->ticks.append(180 + 30);
      ui->timeSlider->ticks.append(180 + 60);
      ui->timeSlider->ticks.append(270 + 4 * 6);
      ui->timeSlider->ticks.append(270 + 4 * 12);
  
      ui->interTempSlider->setSubPixmap(":/images/slider/core.png");
      ui->interTempSlider->setRange(30, 99);
  
      Oven *oven = Oven::getInstance();
  
      QList<int> &bigTicks = ui->interTempSlider->bigTicks;
      bigTicks.append(oven->minInterTemp());
      bigTicks.append(oven->minInterTemp() + (oven->maxInterTemp() - oven->minInterTemp()) / 2);
      bigTicks.append(oven->maxInterTemp());
  
      QList<int> &ticks = ui->interTempSlider->ticks;
      for (int i = 1; i < 3; i++)
          ticks.append(bigTicks.at(0) + i * (bigTicks.at(1) - bigTicks.at(0)) / 3);
      for (int i = 1; i < 3; i++)
          ticks.append(bigTicks.at(1) + i * (bigTicks.at(2) - bigTicks.at(1)) / 3);
  
      connect(ui->humiditySlider, SIGNAL(sliderMoved(int)), SLOT(updateHumidityLabel()));
      connect(ui->tempSlider, SIGNAL(sliderMoved(int)), SLOT(updateTempLabel()));
      connect(ui->timeSlider, SIGNAL(sliderMoved(int)), SLOT(updateTimeLabel()));
      connect(ui->interTempSlider, SIGNAL(sliderMoved(int)), SLOT(updateCoreTempLabel()));
dcfd897f3   김태훈   수동 요리 만들기 추가
60
61
  
      setDefault(mode);
382b586e9   김태훈   프로그래밍 모드 임시 구현
62
63
64
  
      foreach (QPushButton *button, findChildren<QPushButton *>())
          connect(button, &QPushButton::pressed, SoundPlayer::playClick);
81b835e59   김태훈   한글 폰트 변경
65
66
67
68
69
70
  }
  
  ProgrammingManualWindow::~ProgrammingManualWindow()
  {
      delete ui;
  }
dcfd897f3   김태훈   수동 요리 만들기 추가
71
935b853a4   김태훈   새 슬라이더 적용
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
  int ProgrammingManualWindow::sliderToTime(int value)
  {
      if (value <= 180)
          return value * 60;
      if (value <= 270)
          return 180 * 60 + (value - 180) * 2 * 60;
      return 360 * 60 + (value - 270) * 15 * 60;
  }
  
  int ProgrammingManualWindow::timeToSlider(int secs)
  {
      if (secs <= 180 * 60)
          return secs / 60;
      if (secs <= 360 * 60)
          return 180 + (secs - 180 * 60) / 2 / 60;
      return 270 + (secs - 360 * 60) / 15 / 60;
  }
dcfd897f3   김태훈   수동 요리 만들기 추가
89
90
91
92
93
94
95
96
97
98
99
100
  void ProgrammingManualWindow::setDefault(Define::Mode mode)
  {
      switch (mode)
      {
      case Define::SteamMode:
          ui->steamButton->setChecked(true);
          ui->humiditySlider->setEnabled(false);
          ui->humiditySlider->setValue(100);
          ui->tempSlider->setRange(30, 130);
          ui->tempSlider->setValue(100);
          ui->timeSlider->setValue(0);
          ui->interTempSlider->setEnabled(false);
935b853a4   김태훈   새 슬라이더 적용
101
          ui->interTempSlider->setSubVisible(false);
dcfd897f3   김태훈   수동 요리 만들기 추가
102
103
104
105
106
107
108
109
110
111
112
113
114
115
          ui->interTempSlider->setValue(30);
          setFan(4);
          updateCoreTempButton();
          updateCoreTempLabel();
          this->mode = mode;
          break;
      case Define::CombiMode:
          ui->combiButton->setChecked(true);
          ui->humiditySlider->setEnabled(true);
          ui->humiditySlider->setValue(50);
          ui->tempSlider->setRange(30, 300);
          ui->tempSlider->setValue(100);
          ui->timeSlider->setValue(0);
          ui->interTempSlider->setEnabled(false);
935b853a4   김태훈   새 슬라이더 적용
116
          ui->interTempSlider->setSubVisible(false);
dcfd897f3   김태훈   수동 요리 만들기 추가
117
118
119
120
121
122
123
124
125
126
127
128
129
130
          ui->interTempSlider->setValue(30);
          setFan(4);
          updateCoreTempButton();
          updateCoreTempLabel();
          this->mode = mode;
          break;
      case Define::DryMode:
          ui->dryheatButton->setChecked(true);
          ui->humiditySlider->setEnabled(false);
          ui->humiditySlider->setValue(0);
          ui->tempSlider->setRange(30, 300);
          ui->tempSlider->setValue(160);
          ui->timeSlider->setValue(0);
          ui->interTempSlider->setEnabled(false);
935b853a4   김태훈   새 슬라이더 적용
131
          ui->interTempSlider->setSubVisible(false);
dcfd897f3   김태훈   수동 요리 만들기 추가
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
          ui->interTempSlider->setValue(30);
          setFan(4);
          updateCoreTempButton();
          updateCoreTempLabel();
          this->mode = mode;
          break;
      default:
          return;
      }
  }
  
  void ProgrammingManualWindow::setFan(int level)
  {
      fan = level;
  
      updateFanButton();
  }
  
  void ProgrammingManualWindow::updateHumidityLabel()
  {
935b853a4   김태훈   새 슬라이더 적용
152
      ui->humidityLabel->setText(QString("%1%").arg(ui->humiditySlider->sliderPosition()));
dcfd897f3   김태훈   수동 요리 만들기 추가
153
154
155
156
  }
  
  void ProgrammingManualWindow::updateTempLabel()
  {
935b853a4   김태훈   새 슬라이더 적용
157
      ui->tempLabel->setText(Stringer::temperature(ui->tempSlider->sliderPosition(), Stringer::fontSize14));
dcfd897f3   김태훈   수동 요리 만들기 추가
158
159
160
161
  }
  
  void ProgrammingManualWindow::updateTimeLabel()
  {
935b853a4   김태훈   새 슬라이더 적용
162
      ui->timeLabel->setText(Stringer::remainingTime(sliderToTime(ui->timeSlider->sliderPosition()) * 1000, Stringer::fontSize14));
dcfd897f3   김태훈   수동 요리 만들기 추가
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
  }
  
  void ProgrammingManualWindow::updateCoreTempButton()
  {
      if (ui->interTempSlider->isEnabled())
          ui->interTempButton->setStyleSheet("\
  QPushButton {\
      image: url(:/images/slider_icon/core_temp_enabled.png);\
  }\
  QPushButton:pressed {\
      image: url(:/images/slider_icon/core_temp_ov.png);\
  }");
      else
         ui->interTempButton->setStyleSheet("\
  QPushButton {\
     image: url(:/images/slider_icon/core_temp.png);\
  }\
  QPushButton:pressed {\
     image: url(:/images/slider_icon/core_temp_ov.png);\
  }");
  }
  
  void ProgrammingManualWindow::updateCoreTempLabel()
  {
      if (ui->interTempSlider->isEnabled())
935b853a4   김태훈   새 슬라이더 적용
188
          ui->interTempLabel->setText(Stringer::temperature(ui->interTempSlider->sliderPosition(), Stringer::fontSize14));
dcfd897f3   김태훈   수동 요리 만들기 추가
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
      else
          ui->interTempLabel->setText(Stringer::unusedTemperature(Stringer::fontSize14));
  }
  
  void ProgrammingManualWindow::updateFanButton()
  {
      switch (fan)
      {
      case 1:
          ui->fanButton->setStyleSheet(
                      "background-image: url(:/images/manual_button/fan_1.png)");
          break;
      case 2:
          ui->fanButton->setStyleSheet(
                      "background-image: url(:/images/manual_button/fan_2.png)");
          break;
      case 3:
          ui->fanButton->setStyleSheet(
                      "background-image: url(:/images/manual_button/fan_3.png)");
          break;
      case 4:
          ui->fanButton->setStyleSheet(
                      "background-image: url(:/images/manual_button/fan_4.png)");
          break;
      case 5:
          ui->fanButton->setStyleSheet(
                      "background-image: url(:/images/manual_button/fan_5.png)");
          break;
      default:
          ui->fanButton->setStyleSheet(
                      "background-image: url(:/images/manual_button/fan_1.png)");
          break;
      }
  }
  
  void ProgrammingManualWindow::onCoreTempEnabled(int celsius)
  {
      ui->interTempSlider->setEnabled(true);
935b853a4   김태훈   새 슬라이더 적용
227
      ui->interTempSlider->setSubVisible(true);
dcfd897f3   김태훈   수동 요리 만들기 추가
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
      ui->interTempSlider->setValue(celsius);
      updateCoreTempButton();
      updateCoreTempLabel();
  }
  
  void ProgrammingManualWindow::on_steamButton_clicked()
  {
      setDefault(Define::SteamMode);
  }
  
  void ProgrammingManualWindow::on_combiButton_clicked()
  {
      setDefault(Define::CombiMode);
  }
  
  void ProgrammingManualWindow::on_dryheatButton_clicked()
  {
      setDefault(Define::DryMode);
  }
  
  void ProgrammingManualWindow::on_interTempButton_clicked()
  {
      if (ui->interTempSlider->isEnabled())
      {
          ui->interTempSlider->setEnabled(false);
935b853a4   김태훈   새 슬라이더 적용
253
          ui->interTempSlider->setSubVisible(false);
dcfd897f3   김태훈   수동 요리 만들기 추가
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
          updateCoreTempButton();
          updateCoreTempLabel();
      }
      else
      {
          ProgrammingManualCoreTempPopup *p = new ProgrammingManualCoreTempPopup(this);
          connect(p, SIGNAL(coreTempEnabled(int)), SLOT(onCoreTempEnabled(int)));
          p->showFullScreen();
      }
  }
  
  void ProgrammingManualWindow::on_fanButton_clicked()
  {
      fan++;
      if (fan > 5)
          fan = 1;
  
      updateFanButton();
  }
  
  void ProgrammingManualWindow::on_backButton_clicked()
  {
      close();
  }
  
  void ProgrammingManualWindow::on_configButton_clicked()
  {
95a9aa99d   김태훈   기능 보충 구현
281
282
283
284
      ConfigWindow *w = new ConfigWindow(MainWindow::getInstance());
      w->setWindowModality(Qt::WindowModal);
      w->showFullScreen();
      w->raise();
dcfd897f3   김태훈   수동 요리 만들기 추가
285
95a9aa99d   김태훈   기능 보충 구현
286
      MainWindow::jump(w);
dcfd897f3   김태훈   수동 요리 만들기 추가
287
288
289
290
291
292
293
294
295
296
297
298
299
  }
  
  void ProgrammingManualWindow::on_helpButton_clicked()
  {
  
  }
  
  void ProgrammingManualWindow::on_okButton_clicked()
  {
      ManualCookSetting s;
      s.mode = mode;
      s.humidity = ui->humiditySlider->value();
      s.temp = ui->tempSlider->value();
935b853a4   김태훈   새 슬라이더 적용
300
      s.time = sliderToTime(ui->timeSlider->value());
dcfd897f3   김태훈   수동 요리 만들기 추가
301
302
303
304
305
306
307
308
309
      s.coreTempEnabled = ui->interTempSlider->isEnabled();
      s.coreTemp = ui->interTempSlider->value();
      s.fan = fan;
  
      CookProgram::add(s);
  
      emit added();
      close();
  }