Blame view

app/gui/oven_control/autocookwindow.cpp 28.8 KB
99b8066f4   김태훈   V0.1.1
1
2
3
4
5
6
7
8
9
  #include "autocookwindow.h"
  #include "ui_autocookwindow.h"
  
  AutoCookWindow::AutoCookWindow(QWidget *parent, Oven *oven, AbstractCook *cook) :
      QMainWindow(parent),
      ui(new Ui::AutoCookWindow),
      oven(oven),
      cook(cook),
      started(false),
6f96c947a   김태훈   GUI 0.1.4
10
      done(false),
99b8066f4   김태훈   V0.1.1
11
12
13
      selectedStepIndex(0)
  {
      ui->setupUi(this);
99b8066f4   김태훈   V0.1.1
14
      ui->clockContainer->setParent(ui->upperStack);
6f96c947a   김태훈   GUI 0.1.4
15
      setAttribute(Qt::WA_DeleteOnClose);
99b8066f4   김태훈   V0.1.1
16
17
18
19
20
21
  
      connect(oven, SIGNAL(changed(Oven*)), SLOT(onOvenUpdated()));
      oven->setDefault(Oven::CombinationMode);
  
      lastHumidity = oven->currentHumidity();
      lastTemp = oven->currentTemp();
6f96c947a   김태훈   GUI 0.1.4
22
      lastDoorView = Cook::Invalid;
99b8066f4   김태훈   V0.1.1
23
24
25
26
27
  
      QTimer *cookStartTimer = new QTimer(this);
      cookStartTimer->setSingleShot(true);
      cookStartTimer->setInterval(3000);
      connect(cookStartTimer, SIGNAL(timeout()), SLOT(start()));
99b8066f4   김태훈   V0.1.1
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
      connect(ui->configButton_1, SIGNAL(pressed()), SIGNAL(stopCookStartTimer()));
      connect(ui->configButton_2, SIGNAL(pressed()), SIGNAL(stopCookStartTimer()));
      connect(ui->configButton_3, SIGNAL(pressed()), SIGNAL(stopCookStartTimer()));
      connect(ui->configButton_4, SIGNAL(pressed()), SIGNAL(stopCookStartTimer()));
      connect(ui->configButton_5, SIGNAL(pressed()), SIGNAL(stopCookStartTimer()));
      connect(ui->configButton_1, SIGNAL(released()), SIGNAL(startCookStartTimer()));
      connect(ui->configButton_2, SIGNAL(released()), SIGNAL(startCookStartTimer()));
      connect(ui->configButton_3, SIGNAL(released()), SIGNAL(startCookStartTimer()));
      connect(ui->configButton_4, SIGNAL(released()), SIGNAL(startCookStartTimer()));
      connect(ui->configButton_5, SIGNAL(released()), SIGNAL(startCookStartTimer()));
  
      connect(ui->configSlider_1, SIGNAL(sliderPressed()), SIGNAL(stopCookStartTimer()));
      connect(ui->configSlider_2, SIGNAL(sliderPressed()), SIGNAL(stopCookStartTimer()));
      connect(ui->configSlider_3, SIGNAL(sliderPressed()), SIGNAL(stopCookStartTimer()));
      connect(ui->configSlider_4, SIGNAL(sliderPressed()), SIGNAL(stopCookStartTimer()));
      connect(ui->configSlider_5, SIGNAL(sliderPressed()), SIGNAL(stopCookStartTimer()));
      connect(ui->configSlider_1, SIGNAL(actionTriggered(int)), SIGNAL(startCookStartTimer()));
      connect(ui->configSlider_2, SIGNAL(actionTriggered(int)), SIGNAL(startCookStartTimer()));
      connect(ui->configSlider_3, SIGNAL(actionTriggered(int)), SIGNAL(startCookStartTimer()));
      connect(ui->configSlider_4, SIGNAL(actionTriggered(int)), SIGNAL(startCookStartTimer()));
      connect(ui->configSlider_5, SIGNAL(actionTriggered(int)), SIGNAL(startCookStartTimer()));
  
      connect(this, SIGNAL(stopCookStartTimer()), cookStartTimer, SLOT(stop()));
      connect(this, SIGNAL(startCookStartTimer()), cookStartTimer, SLOT(start()));
  
      connect(ui->configSlider_1, SIGNAL(valueChanged(int)), SLOT(onConfigChanged()));
      connect(ui->configSlider_2, SIGNAL(valueChanged(int)), SLOT(onConfigChanged()));
      connect(ui->configSlider_3, SIGNAL(valueChanged(int)), SLOT(onConfigChanged()));
      connect(ui->configSlider_4, SIGNAL(valueChanged(int)), SLOT(onConfigChanged()));
      connect(ui->configSlider_5, SIGNAL(valueChanged(int)), SLOT(onConfigChanged()));
  
      connect(ui->configSlider_1, SIGNAL(sliderMoved(int)), SLOT(updateView()));
      connect(ui->configSlider_2, SIGNAL(sliderMoved(int)), SLOT(updateView()));
      connect(ui->configSlider_3, SIGNAL(sliderMoved(int)), SLOT(updateView()));
      connect(ui->configSlider_4, SIGNAL(sliderMoved(int)), SLOT(updateView()));
      connect(ui->configSlider_5, SIGNAL(sliderMoved(int)), SLOT(updateView()));
      connect(ui->configSlider_1, SIGNAL(valueChanged(int)), SLOT(updateView()));
      connect(ui->configSlider_2, SIGNAL(valueChanged(int)), SLOT(updateView()));
      connect(ui->configSlider_3, SIGNAL(valueChanged(int)), SLOT(updateView()));
      connect(ui->configSlider_4, SIGNAL(valueChanged(int)), SLOT(updateView()));
      connect(ui->configSlider_5, SIGNAL(valueChanged(int)), SLOT(updateView()));
  
  
      checkCookTimer.setInterval(1000);
      connect(&checkCookTimer, SIGNAL(timeout()), SLOT(checkCook()));
  
  
      returnToCurrentStepTimer.setSingleShot(true);
      returnToCurrentStepTimer.setInterval(3000);
      connect(&returnToCurrentStepTimer, SIGNAL(timeout()), SLOT(returnToCurrentStep()));
  
  
      showingCurrentHumidity = false;
      showCurrentHumidityTimer.setSingleShot(true);
      showCurrentHumidityTimer.setInterval(3000);
      connect(&showCurrentHumidityTimer, SIGNAL(timeout()), SLOT(showCurrentHumidity()));
  
      showingCurrentTemp = false;
      showCurrentTempTimer.setSingleShot(true);
      showCurrentTempTimer.setInterval(3000);
      connect(&showCurrentTempTimer, SIGNAL(timeout()), SLOT(showCurrentTemp()));
  
      setupUi();
d66d7f5b4   김태훈   GUI 버전 0.1.2
91
92
  
      cookStartTimer->start();
99b8066f4   김태훈   V0.1.1
93
94
95
96
97
  }
  
  AutoCookWindow::~AutoCookWindow()
  {
      delete ui;
6f96c947a   김태훈   GUI 0.1.4
98
99
  
      delete cook;
99b8066f4   김태훈   V0.1.1
100
101
102
103
  }
  
  void AutoCookWindow::setupUi()
  {
6f96c947a   김태훈   GUI 0.1.4
104
105
106
107
108
      bulletPixmap.load(":/images/images/auto/window_arrow_pin_02.png");
      selectedBulletPixmap.load(":/images/images/auto/window_arrow_pin_01.png");
      steamModeIcon.load(":/images/images/auto/window_icon_04.png");
      dryModeIcon.load(":/images/images/auto/window_icon_06.png");
      combiModeIcon.load(":/images/images/auto/window_icon_05.png");
99b8066f4   김태훈   V0.1.1
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
      QString cookTypeIcon = Cook::icon(cook->type());
      ui->cookTypeIcon_1->setPixmap(cookTypeIcon);
      ui->cookTypeIcon_2->setPixmap(cookTypeIcon);
  
      QString name = cook->name();
      ui->selectCookButton_1->setText(name);
      ui->selectCookButton_2->setText(name);
  
      for (int idx = 0; idx < 5; idx++)
      {
          QPushButton *icon;
          QWidget *block;
          QLabel *minLabel;
          QLabel *maxLabel;
          QLabel *currentLabel;
          QSlider *slider;
  
          switch (idx)
          {
          case 0:
              icon = ui->configButton_1;
              block = ui->configBlock_1;
              minLabel = ui->configMinLabel_1;
              maxLabel = ui->configMaxLabel_1;
              currentLabel = ui->configCurrentLabel_1;
              slider = ui->configSlider_1;
              break;
          case 1:
              icon = ui->configButton_2;
              block = ui->configBlock_2;
              minLabel = ui->configMinLabel_2;
              maxLabel = ui->configMaxLabel_2;
              currentLabel = ui->configCurrentLabel_2;
              slider = ui->configSlider_2;
              break;
          case 2:
              icon = ui->configButton_3;
              block = ui->configBlock_3;
              minLabel = ui->configMinLabel_3;
              maxLabel = ui->configMaxLabel_3;
              currentLabel = ui->configCurrentLabel_3;
              slider = ui->configSlider_3;
              break;
          case 3:
              icon = ui->configButton_4;
              block = ui->configBlock_4;
              minLabel = ui->configMinLabel_4;
              maxLabel = ui->configMaxLabel_4;
              currentLabel = ui->configCurrentLabel_4;
              slider = ui->configSlider_4;
              break;
          case 4:
              icon = ui->configButton_5;
              block = ui->configBlock_5;
              minLabel = ui->configMinLabel_5;
              maxLabel = ui->configMaxLabel_5;
              currentLabel = ui->configCurrentLabel_5;
              slider = ui->configSlider_5;
              break;
          }
  
          AbstractCookConfig *config = cook->configurations[idx];
          if (config != NULL)
          {
              icon->show();
              icon->setStyleSheet("QPushButton { border-image: url("
                                  + config->icon()
                                  + ") } QPushButton::pressed { border-image: url("
                                  + config->overlayIcon()
                                  + ") }");
              block->show();
              minLabel->show();
              minLabel->setText(config->minLabel());
              maxLabel->show();
              maxLabel->setText(config->maxLabel());
  
              currentLabel->show();
  
              slider->show();
              slider->blockSignals(true);
              slider->setMinimum(1);
              slider->setMaximum(config->count());
              slider->setValue(config->current());
              slider->blockSignals(false);
6f96c947a   김태훈   GUI 0.1.4
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
              switch (config->type())
              {
              case Cook::Time:
                  slider->setProperty("sliderColor", QString("white"));
                  break;
              case Cook::BurnDegree:
                  slider->setProperty("sliderColor", QString("yellow"));
                  break;
              case Cook::Brightness:
                  slider->setProperty("sliderColor", QString("red"));
                  break;
              default:
                  slider->setProperty("sliderColor", QString("blue"));
                  break;
              }
  
              slider->style()->unpolish(slider);
              slider->style()->polish(slider);
              slider->update();
99b8066f4   김태훈   V0.1.1
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
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
253
254
255
256
257
258
259
260
261
          }
          else
          {
              icon->hide();
              block->hide();
              minLabel->hide();
              maxLabel->hide();
              currentLabel->hide();
              slider->hide();
          }
      }
  
      if (cook->interTempEnabled())
      {
          ui->configBlock_4->show();
          ui->configButton_4->show();
          ui->configButton_4->setStyleSheet(
                      QString("QPushButton { border-image: url(")
                      + ":/images/images/auto/011_icon_04_ov_01.png"
                      + ") } QPushButton::pressed { border-image: url("
                      + ":/images/images/auto/011_icon_04_ov.png"
                      + ") }"
                      );
          ui->configMinLabel_4->hide();
          ui->configMaxLabel_4->hide();
          ui->configCurrentLabel_4->hide();
          ui->configSlider_4->hide();
  
          interTempEnabled = true;
      }
  
      int offsetX = (900 - (cook->stepCount() * 19 * 2 - 19)) / 2;
      int offsetY = 1150;
      for (int idx = 0; idx < cook->stepCount(); idx++)
      {
          QLabel *bullet = new QLabel(ui->cookPage);
          bullet->setPixmap(bulletPixmap);
          bullet->setGeometry(offsetX + 19 * 2 * idx, offsetY, 19, 19);
          bullets.append(bullet);
      }
  
      ui->cookStepAnimation->start(300);
  
      ui->humidityGauge->setMinimum(0);
      ui->humidityGauge->setMaximum(100);
      ui->humidityGauge->setValue(0);
  
      ui->heatGauge->setMinimum(30);
      ui->heatGauge->setMaximum(300);
      ui->heatGauge->setValue(30);
6f96c947a   김태훈   GUI 0.1.4
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
      ui->openDoorAnimation->load(":/images/images/auto/ani_01.png");
      ui->openDoorAnimation->load(":/images/images/auto/ani_02.png");
      ui->openDoorAnimation->load(":/images/images/auto/ani_03.png");
      ui->openDoorAnimation->load(":/images/images/auto/ani_04.png");
      ui->openDoorAnimation->load(":/images/images/auto/ani_05.png");
      ui->openDoorAnimation->load(":/images/images/auto/ani_06.png");
      ui->openDoorAnimation->load(":/images/images/auto/ani_07.png");
      ui->openDoorAnimation->load(":/images/images/auto/ani_08.png");
      ui->openDoorAnimation->load(":/images/images/auto/ani_09.png");
      ui->openDoorAnimation->start(300);
      ui->openDoorAnimation->hide();
      ui->openDoorArrow->hide();
  
      ui->closeDoorAnimation->load(":/images/images/auto/ani_09.png");
      ui->closeDoorAnimation->load(":/images/images/auto/ani_08.png");
      ui->closeDoorAnimation->load(":/images/images/auto/ani_07.png");
      ui->closeDoorAnimation->load(":/images/images/auto/ani_06.png");
      ui->closeDoorAnimation->load(":/images/images/auto/ani_05.png");
      ui->closeDoorAnimation->load(":/images/images/auto/ani_04.png");
      ui->closeDoorAnimation->load(":/images/images/auto/ani_03.png");
      ui->closeDoorAnimation->load(":/images/images/auto/ani_02.png");
      ui->closeDoorAnimation->load(":/images/images/auto/ani_01.png");
      ui->closeDoorAnimation->start(300);
      ui->closeDoorAnimation->hide();
      ui->closeDoorArrow->hide();
99b8066f4   김태훈   V0.1.1
287
288
289
290
291
      updateView();
  }
  
  void AutoCookWindow::updateView()
  {
6f96c947a   김태훈   GUI 0.1.4
292
  //    qDebug() << "updateView";
99b8066f4   김태훈   V0.1.1
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
      if (started)
      {
          ui->stackedWidget->setCurrentIndex(1);
  
          for (int idx = 0; idx < bullets.length(); idx++)
          {
              QLabel *bullet = bullets.at(idx);
              if (idx == selectedStepIndex)
                  bullet->setPixmap(selectedBulletPixmap);
              else
                  bullet->setPixmap(bulletPixmap);
          }
  
          viewStep(cook->step(selectedStepIndex));
  
          int time = oven->time();
          if (time >= 3600)
6f96c947a   김태훈   GUI 0.1.4
310
              ui->timeLabel->setText(QString().sprintf("%d<span style=\"font-size:11pt;\">시간</span> %02d<span style=\"font-size:11pt;\">분</span>", time / 3600, (time % 3600) / 60));
99b8066f4   김태훈   V0.1.1
311
          else if (time >= 60)
6f96c947a   김태훈   GUI 0.1.4
312
              ui->timeLabel->setText(QString().sprintf("%d<span style=\"font-size:11pt;\">분</span> %02d<span style=\"font-size:11pt;\">초</span>", time / 60, time % 60));
99b8066f4   김태훈   V0.1.1
313
          else
6f96c947a   김태훈   GUI 0.1.4
314
              ui->timeLabel->setText(QString().sprintf("%d<span style=\"font-size:11pt;\">초</span>", time));
99b8066f4   김태훈   V0.1.1
315
316
  
          int curInterTemp = oven->currentInterTemp();
6f96c947a   김태훈   GUI 0.1.4
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
          if (interTempEnabled)
          {
              int interTemp = oven->interTemp();
              ui->interTempLabel->setText(QString().sprintf("%d<span style=\"font-size:11pt;\">℃ / %d</span><span style=\"font-size:9pt;\">℃</span>", curInterTemp, interTemp));
          }
          else
              ui->interTempLabel->setText(QString().sprintf("%d<span style=\"font-size:11pt;\">℃</span>", curInterTemp));
  
          if (!done)
          {
              if (oven->door())
              {
                  ui->closeDoorAnimation->show();
                  ui->closeDoorArrow->show();
                  ui->openDoorAnimation->hide();
                  ui->openDoorArrow->hide();
              }
              else
              {
                  ui->closeDoorAnimation->hide();
                  ui->closeDoorArrow->hide();
  
                  Cook::Step step = cook->currentStep();
                  if (Cook::classify(step.type) == Cook::DoorClass)
                  {
                      ui->openDoorAnimation->show();
                      ui->openDoorArrow->show();
                  }
                  else
                  {
                      ui->openDoorAnimation->hide();
                      ui->openDoorArrow->hide();
                  }
              }
          }
99b8066f4   김태훈   V0.1.1
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
      }
      else
      {
          ui->stackedWidget->setCurrentIndex(0);
  
          for (int idx = 0; idx < 5; idx++)
          {
              AbstractCookConfig *config = cook->configurations[idx];
              if (config == NULL)
                  continue;
  
              QLabel *l;
              QSlider *s;
              switch (idx)
              {
              case 0:
                  l = ui->configCurrentLabel_1;
                  s = ui->configSlider_1;
                  break;
              case 1:
                  l = ui->configCurrentLabel_2;
                  s = ui->configSlider_2;
                  break;
              case 2:
                  l = ui->configCurrentLabel_3;
                  s = ui->configSlider_3;
                  break;
              case 3:
                  l = ui->configCurrentLabel_4;
                  s = ui->configSlider_4;
                  break;
              case 4:
                  l = ui->configCurrentLabel_5;
                  s = ui->configSlider_5;
                  break;
              }
6f96c947a   김태훈   GUI 0.1.4
388
389
              int time = cook->time();
              int interTemp = cook->interTemp();
99b8066f4   김태훈   V0.1.1
390
391
              switch (config->type())
              {
6f96c947a   김태훈   GUI 0.1.4
392
393
394
395
396
397
398
399
400
401
402
              case Cook::Time:
                  if (time >= 3600)
                      l->setText(QString().sprintf("%d<span style=\"font-size:11pt;\">시간</span> %02d<span style=\"font-size:11pt;\">분</span>", time / 3600, (time % 3600) / 60));
                  else if (time >= 60)
                      l->setText(QString().sprintf("%d<span style=\"font-size:11pt;\">분</span> %02d<span style=\"font-size:11pt;\">초</span>", time / 60, time % 60));
                  else
                      l->setText(QString().sprintf("%d<span style=\"font-size:11pt;\">초</span>", time));
                  break;
              case Cook::BurnDegree:
                  l->setText(QString().sprintf("%d<span style=\"font-size:11pt;\">℃</span>", interTemp));
                  break;
99b8066f4   김태훈   V0.1.1
403
              default:
6f96c947a   김태훈   GUI 0.1.4
404
                  l->setText(QString().sprintf("%d<span style=\"font-size:11pt;\">/%d</span>", config->current(), config->count()));
99b8066f4   김태훈   V0.1.1
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
                  break;
              }
          }
  
          if (interTempEnabled)
          {
              ui->configButton_4->setStyleSheet(
                          QString("QPushButton { border-image: url(")
                          + ":/images/images/auto/011_icon_04_ov_01.png"
                          + ") } QPushButton::pressed { border-image: url("
                          + ":/images/images/auto/011_icon_04_ov.png"
                          + ") }");
          }
          else
          {
              ui->configButton_4->setStyleSheet(
                          QString("QPushButton { border-image: url(")
                          + ":/images/images/auto/011_icon_04.png"
                          + ") } QPushButton::pressed { border-image: url("
                          + ":/images/images/auto/011_icon_04_ov.png"
                          + ") }");
          }
      }
  }
  
  void AutoCookWindow::viewStep(Cook::Step step)
  {
6f96c947a   김태훈   GUI 0.1.4
432
  //    qDebug() << "viewStep" << step.type;
99b8066f4   김태훈   V0.1.1
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
      switch (Cook::classify(step.type))
      {
      case Cook::PreheatClass:
          viewPreheatStep(step);
          break;
      case Cook::DoorClass:
          viewDoorStep(step);
          break;
      case Cook::CookClass:
          viewCookStep(step);
          break;
      default:
          break;
      }
  }
  
  void AutoCookWindow::viewPreheatStep(Cook::Step step)
  {
      ui->cookStepIcon->show();
      ui->cookStepIcon->setPixmap(QPixmap(":/images/images/auto/sys_icon_05.png"));
      ui->cookStepLabel->show();
      ui->cookStepLabel->setText("예열");
      ui->doorStepLabel->hide();
      ui->cookStepAnimation->hide();
  
      ui->humidityGauge->show();
      ui->humidityGauge->setValue(step.humidity);
      ui->humidityLabel->show();
      if (showingCurrentHumidity)
          ui->humidityLabel->setText(QString().sprintf("%d%%", oven->currentHumidity()));
      else
          ui->humidityLabel->setText(QString().sprintf("%d%%", step.humidity));
  
      ui->heatGauge->show();
      ui->heatGauge->setValue(step.temp);
      ui->heatLabel->show();
      if (showingCurrentTemp)
          ui->heatLabel->setText(QString().sprintf("%d℃", oven->currentTemp()));
      else
          ui->heatLabel->setText(QString().sprintf("%d℃", step.temp));
  
      ui->cookModeIcon->show();
      switch (step.mode)
      {
      case Cook::SteamMode:
          ui->cookModeIcon->setPixmap(steamModeIcon);
          break;
      case Cook::DryMode:
          ui->cookModeIcon->setPixmap(dryModeIcon);
          break;
      case Cook::CombiMode:
          ui->cookModeIcon->setPixmap(combiModeIcon);
          break;
      }
  }
  
  void AutoCookWindow::viewDoorStep(Cook::Step step)
  {
6f96c947a   김태훈   GUI 0.1.4
491
  //    qDebug() << "viewDoorStep";
99b8066f4   김태훈   V0.1.1
492
493
494
495
      ui->cookStepLabel->hide();
      ui->cookStepIcon->hide();
      ui->doorStepLabel->show();
      ui->cookStepAnimation->show();
99b8066f4   김태훈   V0.1.1
496
497
498
499
500
501
  
      ui->humidityGauge->hide();
      ui->humidityLabel->hide();
      ui->heatGauge->hide();
      ui->heatLabel->hide();
      ui->cookModeIcon->hide();
6f96c947a   김태훈   GUI 0.1.4
502
      if (lastDoorView != step.type)
99b8066f4   김태훈   V0.1.1
503
      {
6f96c947a   김태훈   GUI 0.1.4
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
          lastDoorView = step.type;
          qDebug() << "clearStepAnimation";
  
          ui->cookStepAnimation->clear();
          switch (step.type)
          {
          case Cook::PutThermometer:
              ui->doorStepLabel->setText("중심 온도계 삽입");
              ui->cookStepAnimation->load(":/images/images/auto/ani_d_01.png");
              ui->cookStepAnimation->load(":/images/images/auto/ani_d_02.png");
              ui->cookStepAnimation->setGeometry((900-210)/2, 800, 210, 307);
              break;
          case Cook::Load:
              ui->doorStepLabel->setText("식재료 적재");
              ui->cookStepAnimation->load(":/images/images/auto/ani_frame_c_01.png");
              ui->cookStepAnimation->load(":/images/images/auto/ani_frame_c_02.png");
              ui->cookStepAnimation->load(":/images/images/auto/ani_frame_c_03.png");
              ui->cookStepAnimation->load(":/images/images/auto/ani_frame_c_04.png");
              ui->cookStepAnimation->load(":/images/images/auto/ani_frame_c_03.png");
              ui->cookStepAnimation->load(":/images/images/auto/ani_frame_c_02.png");
              ui->cookStepAnimation->load(":/images/images/auto/ani_frame_c_01.png");
              ui->cookStepAnimation->setGeometry((900-264)/2, 800, 264, 307);
              break;
          case Cook::Cut:
              ui->doorStepLabel->setText("자르기");
              ui->cookStepAnimation->load(":/images/images/auto/ani_frame_b_01.png");
              ui->cookStepAnimation->load(":/images/images/auto/ani_frame_b_02.png");
              ui->cookStepAnimation->load(":/images/images/auto/ani_frame_b_03.png");
              ui->cookStepAnimation->setGeometry((900-264)/2, 800, 264, 307);
              break;
          case Cook::Pour:
              ui->doorStepLabel->setText("물 붓기");
              ui->cookStepAnimation->load(":/images/images/auto/ani_frame_a_01.png");
              ui->cookStepAnimation->load(":/images/images/auto/ani_frame_a_02.png");
              ui->cookStepAnimation->load(":/images/images/auto/ani_frame_a_03.png");
              ui->cookStepAnimation->load(":/images/images/auto/ani_frame_a_04.png");
              ui->cookStepAnimation->setGeometry((900-264)/2, 800, 264, 307);
              break;
          default:
              ui->doorStepLabel->hide();
          }
99b8066f4   김태훈   V0.1.1
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
      }
  }
  
  void AutoCookWindow::viewCookStep(Cook::Step step)
  {
      ui->cookStepLabel->show();
      ui->cookStepIcon->show();
      ui->doorStepLabel->hide();
      ui->cookStepAnimation->hide();
  
      ui->humidityGauge->show();
      ui->humidityGauge->setValue(step.humidity);
      ui->humidityLabel->show();
      if (showingCurrentHumidity)
          ui->humidityLabel->setText(QString().sprintf("%d%%", oven->currentHumidity()));
      else
          ui->humidityLabel->setText(QString().sprintf("%d%%", step.humidity));
  
      ui->heatGauge->show();
      ui->heatGauge->setValue(step.temp);
      ui->heatLabel->show();
      if (showingCurrentTemp)
          ui->heatLabel->setText(QString().sprintf("%d℃", oven->currentTemp()));
      else
          ui->heatLabel->setText(QString().sprintf("%d℃", step.temp));
  
      ui->cookModeIcon->show();
      switch (step.mode)
      {
      case Cook::SteamMode:
          ui->cookModeIcon->setPixmap(steamModeIcon);
          break;
      case Cook::DryMode:
          ui->cookModeIcon->setPixmap(dryModeIcon);
          break;
      case Cook::CombiMode:
          ui->cookModeIcon->setPixmap(combiModeIcon);
          break;
      }
  
      ui->cookStepLabel->setText(Cook::name(step.type));
      ui->cookStepIcon->setPixmap(QPixmap(Cook::icon(step.type)));
  }
  
  void AutoCookWindow::doPreheatStep(Cook::Step step)
  {
  //    oven->setHumidity(step.humidity);
      oven->setHumidity(0);
      oven->setTemp(step.temp);
      oven->startPreheating();
  
      lastHumidity = oven->currentHumidity();
      lastTemp = oven->currentTemp();
6f96c947a   김태훈   GUI 0.1.4
598
599
600
601
602
603
604
  
      ui->preheatIcon->show();
      ui->preheatLabel->show();
      ui->preheatGauge->show();
      ui->preheatGauge->setMaximum(step.temp);
      ui->preheatGauge->setMinimum(lastTemp);
      ui->preheatGauge->setValue(lastTemp);
99b8066f4   김태훈   V0.1.1
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
  }
  
  void AutoCookWindow::doDoorStep(Cook::Step /*step*/)
  {
      opened = false;
  }
  
  void AutoCookWindow::doCookStep(Cook::Step step)
  {
  //    oven->setHumidity(step.humidity);
      oven->setHumidity(0);
      oven->setTemp(step.temp);
      oven->startCooking();
  
      lastHumidity = oven->currentHumidity();
      lastTemp = oven->currentTemp();
  }
  
  static bool checkReached(int target, int last, int current)
  {
d66d7f5b4   김태훈   GUI 버전 0.1.2
625
626
627
      qDebug() << "checkReached" << target << last << current;
      return ((target >= last) && (target <= current))
              || ((target <= last) && (target >= current));
99b8066f4   김태훈   V0.1.1
628
629
630
631
  }
  
  void AutoCookWindow::checkPreheatStep(Cook::Step step)
  {
6f96c947a   김태훈   GUI 0.1.4
632
633
634
      int curTemp = oven->currentTemp();
  
      ui->preheatGauge->setValue(curTemp);
99b8066f4   김태훈   V0.1.1
635
      if (/*checkReached(step.humidity, lastHumidity, oven->currentHumidity())
6f96c947a   김태훈   GUI 0.1.4
636
              && */checkReached(step.temp, lastTemp, curTemp))
99b8066f4   김태훈   V0.1.1
637
      {
d66d7f5b4   김태훈   GUI 버전 0.1.2
638
639
          if (selectedStepIndex == cook->currentStepIndex())
              selectedStepIndex = cook->currentStepIndex() + 1;
6f96c947a   김태훈   GUI 0.1.4
640
641
642
          ui->preheatIcon->hide();
          ui->preheatLabel->hide();
          ui->preheatGauge->hide();
99b8066f4   김태훈   V0.1.1
643
644
645
646
647
648
649
          cook->setCurrentStepIndex(cook->currentStepIndex() + 1);
          doStep();
      }
  }
  
  void AutoCookWindow::checkDoorStep(Cook::Step /*step*/)
  {
6f96c947a   김태훈   GUI 0.1.4
650
  //    qDebug() << "checkDoorStep" << opened << oven->door();
d66d7f5b4   김태훈   GUI 버전 0.1.2
651
      if (opened)
99b8066f4   김태훈   V0.1.1
652
      {
d66d7f5b4   김태훈   GUI 버전 0.1.2
653
654
655
656
657
658
659
660
661
662
663
664
665
          if (!oven->door())
          {
              if (selectedStepIndex == cook->currentStepIndex())
                  selectedStepIndex = cook->currentStepIndex() + 1;
  
              cook->setCurrentStepIndex(cook->currentStepIndex() + 1);
              doStep();
          }
      }
      else
      {
          if (oven->door())
              opened = true;
99b8066f4   김태훈   V0.1.1
666
      }
99b8066f4   김태훈   V0.1.1
667
668
669
670
671
672
673
674
675
  }
  
  void AutoCookWindow::checkCookStep(Cook::Step step)
  {
      if (cook->currentStepIndex() + 1 < cook->stepCount())
      {
          if (/*checkReached(step.humidity, lastHumidity, oven->currentHumidity())
                  && */checkReached(step.temp, lastTemp, oven->currentTemp()))
          {
d66d7f5b4   김태훈   GUI 버전 0.1.2
676
677
              if (selectedStepIndex == cook->currentStepIndex())
                  selectedStepIndex = cook->currentStepIndex() + 1;
99b8066f4   김태훈   V0.1.1
678
679
680
681
682
683
684
              cook->setCurrentStepIndex(cook->currentStepIndex() + 1);
              doStep();
          }
          else if (interTempEnabled)
          {
              if (cook->interTemp() == oven->currentInterTemp())
              {
d66d7f5b4   김태훈   GUI 버전 0.1.2
685
686
                  if (selectedStepIndex == cook->currentStepIndex())
                      selectedStepIndex = cook->stepCount() - 1;
99b8066f4   김태훈   V0.1.1
687
688
689
690
691
                  cook->setCurrentStepIndex(cook->stepCount() - 1);
                  doStep();
              }
          }
      }
6f96c947a   김태훈   GUI 0.1.4
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
      else /*if current step == last step*/
      {
          if (done)
          {
  
          }
          else
          {
              if ((interTempEnabled && cook->interTemp() == oven->currentInterTemp())
                      || oven->time() == 0)
              {
                  done = true;
                  ui->openDoorAnimation->show();
                  ui->openDoorArrow->show();
                  ui->closeDoorAnimation->hide();
                  ui->closeDoorArrow->hide();
  
                  oven->setTime(0);
              }
          }
      }
99b8066f4   김태훈   V0.1.1
713
714
715
716
  }
  
  void AutoCookWindow::start()
  {
d66d7f5b4   김태훈   GUI 버전 0.1.2
717
      qDebug() << "start";
99b8066f4   김태훈   V0.1.1
718
719
      started = true;
      oven->setTime(cook->time());
99b8066f4   김태훈   V0.1.1
720
      oven->setInterTemp(cook->interTemp());
6f96c947a   김태훈   GUI 0.1.4
721
      oven->setInterTempEnabled(interTempEnabled);
99b8066f4   김태훈   V0.1.1
722
723
724
725
726
727
728
729
730
  
      doStep();
      checkCookTimer.start();
  
      updateView();
  }
  
  void AutoCookWindow::stop()
  {
d66d7f5b4   김태훈   GUI 버전 0.1.2
731
      qDebug() << "stop";
99b8066f4   김태훈   V0.1.1
732
733
734
735
736
737
738
739
      oven->stop();
      checkCookTimer.stop();
  
      updateView();
  }
  
  void AutoCookWindow::doStep()
  {
d66d7f5b4   김태훈   GUI 버전 0.1.2
740
      qDebug() << "doStep";
99b8066f4   김태훈   V0.1.1
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
      Cook::Step step = cook->currentStep();
      switch (Cook::classify(step.type))
      {
      case Cook::PreheatClass:
          doPreheatStep(step);
          break;
      case Cook::DoorClass:
          doDoorStep(step);
          break;
      case Cook::CookClass:
          doCookStep(step);
          break;
      default:
          break;
      }
  }
  
  void AutoCookWindow::checkCook()
  {
6f96c947a   김태훈   GUI 0.1.4
760
  //    qDebug() << "checkCook";
99b8066f4   김태훈   V0.1.1
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
      Cook::Step step = cook->currentStep();
      switch (Cook::classify(step.type))
      {
      case Cook::PreheatClass:
          checkPreheatStep(step);
          break;
      case Cook::DoorClass:
          checkDoorStep(step);
          break;
      case Cook::CookClass:
          checkCookStep(step);
          break;
      default:
          qDebug() << "Checking Invalid Cook";
      }
  
      updateView();
  }
  
  void AutoCookWindow::onOvenUpdated()
  {
      updateView();
  
      qDebug() << "onOvenUpdated()";
  }
  
  void AutoCookWindow::on_showPrevStepButton_clicked()
  {
      if (selectedStepIndex > 0)
          selectedStepIndex--;
  
      updateView();
  
      returnToCurrentStepTimer.start();
  }
  
  void AutoCookWindow::on_showNextStepButton_clicked()
  {
      if (selectedStepIndex + 1 < cook->stepCount())
          selectedStepIndex++;
  
      updateView();
  
      returnToCurrentStepTimer.start();
  }
  
  void AutoCookWindow::returnToCurrentStep()
  {
      selectedStepIndex = cook->currentStepIndex();
  
      updateView();
  }
  
  void AutoCookWindow::onConfigChanged()
  {
      for (int idx = 0; idx < 5; idx++)
      {
          AbstractCookConfig *config = cook->configurations[idx];
          if (config == NULL)
              continue;
  
          QSlider *slider;
          switch (idx)
          {
          case 0:
              slider = ui->configSlider_1;
              break;
          case 1:
              slider = ui->configSlider_2;
              break;
          case 2:
              slider = ui->configSlider_3;
              break;
          case 3:
              slider = ui->configSlider_4;
              break;
          case 4:
              slider = ui->configSlider_5;
              break;
          }
  
          config->setCurrent(slider->value());
      }
  }
  
  void AutoCookWindow::on_backButton_clicked()
  {
      stop();
      close();
  }
  
  void AutoCookWindow::on_configButton_4_clicked()
  {
      if (cook->interTempEnabled())
      {
          interTempEnabled = !interTempEnabled;
  
          updateView();
      }
  }
  
  void AutoCookWindow::on_humidityGaugeButton_pressed()
  {
      showCurrentHumidityTimer.start();
  }
  
  void AutoCookWindow::on_humidityGaugeButton_released()
  {
      showCurrentHumidityTimer.stop();
      showingCurrentHumidity = false;
  
      updateView();
  }
  
  void AutoCookWindow::on_heatGaugeButton_pressed()
  {
      showCurrentTempTimer.start();
  }
  
  void AutoCookWindow::on_heatGaugeButton_released()
  {
      showCurrentTempTimer.stop();
      showingCurrentTemp = false;
  
      updateView();
  }
  
  void AutoCookWindow::showCurrentHumidity()
  {
      showingCurrentHumidity = true;
  
      updateView();
  }
  
  void AutoCookWindow::showCurrentTemp()
  {
      showingCurrentTemp = true;
  
      updateView();
  }