Blame view

app/gui/oven_control/cooldownpopup.cpp 7.86 KB
cfc2fcc35   김태훈   쿨다운 팝업 추가
1
2
  #include "cooldownpopup.h"
  #include "ui_cooldownpopup.h"
271dda4ae   김태훈   엔코더 구현
3
  #include <QKeyEvent>
bbd7d8f29   김태훈   버튼 음향 추가
4
  #include "soundplayer.h"
2bfd3a050   김태훈   환경 설정 대응
5
  #include "stringer.h"
8d6b74605   김태훈   세척 시작 전 온도 검사 후 쿨다운
6
  CooldownPopup::CooldownPopup(QWidget *parent, int target) :
cfc2fcc35   김태훈   쿨다운 팝업 추가
7
8
      QWidget(parent),
      ui(new Ui::CooldownPopup),
6fbaea2a7   김태훈   수동 요리 동작 변경
9
10
      showingCurrentTemp(false),
      needCookStarting(false)
cfc2fcc35   김태훈   쿨다운 팝업 추가
11
12
13
14
  {
      ui->setupUi(this);
  
      setAttribute(Qt::WA_DeleteOnClose);
8d6b74605   김태훈   세척 시작 전 온도 검사 후 쿨다운
15
      oven = Oven::getInstance();
2bfd3a050   김태훈   환경 설정 대응
16
17
      lastDisplayedFanLevel = -1;
      lastDisplayedHumidification = !oven->humidification();
cfc2fcc35   김태훈   쿨다운 팝업 추가
18
19
20
21
22
23
24
25
26
27
      ui->openDoorAnimation->load(":/images/animation/door_big_01.png");
      ui->openDoorAnimation->load(":/images/animation/door_big_02.png");
      ui->openDoorAnimation->load(":/images/animation/door_big_03.png");
      ui->openDoorAnimation->load(":/images/animation/door_big_04.png");
      ui->openDoorAnimation->load(":/images/animation/door_big_05.png");
      ui->openDoorAnimation->load(":/images/animation/door_big_06.png");
      ui->openDoorAnimation->load(":/images/animation/door_big_07.png");
      ui->openDoorAnimation->load(":/images/animation/door_big_08.png");
      ui->openDoorAnimation->load(":/images/animation/door_big_09.png");
      ui->openDoorAnimation->start(300);
a2de3cbfc   김태훈   수동 요리에 새 슬라이더 적용
28
29
      ui->tempSlider->setSubPixmap(":/images/slider/sub_red.png");
      ui->tempSlider->setRange(30, 300);
8d6b74605   김태훈   세척 시작 전 온도 검사 후 쿨다운
30
      ui->tempSlider->setValue(target);
a2de3cbfc   김태훈   수동 요리에 새 슬라이더 적용
31
cfc2fcc35   김태훈   쿨다운 팝업 추가
32
33
34
35
      cookingFanLevel = oven->fan();
      expectingFanLevel = oven->maxFan();
      started = false;
      opened = false;
6fbaea2a7   김태훈   수동 요리 동작 변경
36
37
38
      needCookStarting = oven->cooking();
      if (needCookStarting)
          oven->stopCooking();
cfc2fcc35   김태훈   쿨다운 팝업 추가
39
0fbf1932c   김태훈   V1.5.0.2
40
      oven->setFan(expectingFanLevel);
cfc2fcc35   김태훈   쿨다운 팝업 추가
41
42
43
      connect(oven, SIGNAL(changed(Oven*)), SLOT(updateView()));
  
      cooldownStartTimer.setSingleShot(true);
5228da630   김태훈   딜레이 변경
44
      cooldownStartTimer.setInterval(3000);
cfc2fcc35   김태훈   쿨다운 팝업 추가
45
46
47
      connect(&cooldownStartTimer, SIGNAL(timeout()), SLOT(start()));
  
      showCurrentTempTimer.setSingleShot(true);
5228da630   김태훈   딜레이 변경
48
      showCurrentTempTimer.setInterval(1000);
cfc2fcc35   김태훈   쿨다운 팝업 추가
49
50
51
52
      connect(&showCurrentTempTimer, SIGNAL(timeout()), SLOT(showCurrentTemp()));
  
      checkOvenTimer.setInterval(100);
      connect(&checkOvenTimer, SIGNAL(timeout()), SLOT(checkOven()));
a2de3cbfc   김태훈   수동 요리에 새 슬라이더 적용
53
      connect(ui->tempSlider, SIGNAL(sliderMoved(int)), SLOT(updateView()));
cfc2fcc35   김태훈   쿨다운 팝업 추가
54
55
56
57
  
      updateView();
  
      cooldownStartTimer.start();
bbd7d8f29   김태훈   버튼 음향 추가
58
59
60
  
      foreach (QPushButton *button, findChildren<QPushButton *>())
          connect(button, &QPushButton::pressed, SoundPlayer::playClick);
271dda4ae   김태훈   엔코더 구현
61
62
63
64
65
66
67
68
  
      focusTempButtonTimer.setSingleShot(true);
      focusTempButtonTimer.setInterval(3000);
      connect(&focusTempButtonTimer, SIGNAL(timeout()), SLOT(focusTempButton()));
  
      connect(ui->tempSlider, SIGNAL(sliderMoved(int)), &focusTempButtonTimer, SLOT(start()));
  
      ui->background->setFocus();
cfc2fcc35   김태훈   쿨다운 팝업 추가
69
70
71
72
  }
  
  CooldownPopup::~CooldownPopup()
  {
6fbaea2a7   김태훈   수동 요리 동작 변경
73
74
      if (needCookStarting)
          oven->startCooking();
cfc2fcc35   김태훈   쿨다운 팝업 추가
75
76
      delete ui;
  }
271dda4ae   김태훈   엔코더 구현
77
78
79
80
  void CooldownPopup::keyPressEvent(QKeyEvent *event)
  {
      switch (event->key())
      {
01249f413   김태훈   엔코더 방향 반전. 하드웨어가 변경됨
81
      case 0x01000032:    // Turn left
271dda4ae   김태훈   엔코더 구현
82
83
84
85
86
          onEncoderLeft();
          break;
      case 0x01000031:    // Push
          pushed = focusWidget();
          break;
01249f413   김태훈   엔코더 방향 반전. 하드웨어가 변경됨
87
      case 0x01000030:    // Turn right
271dda4ae   김태훈   엔코더 구현
88
89
90
91
92
93
94
95
96
          onEncoderRight();
          break;
      }
  }
  
  void CooldownPopup::keyReleaseEvent(QKeyEvent *event)
  {
      switch (event->key())
      {
01249f413   김태훈   엔코더 방향 반전. 하드웨어가 변경됨
97
      case 0x01000032:    // Turn left
271dda4ae   김태훈   엔코더 구현
98
99
100
101
102
103
104
105
          onEncoderLeft();
          break;
      case 0x01000031:    // Push
          if (focusWidget() == pushed)
              onEncoderClicked(pushed);
  
          pushed = NULL;
          break;
01249f413   김태훈   엔코더 방향 반전. 하드웨어가 변경됨
106
      case 0x01000030:    // Turn right
271dda4ae   김태훈   엔코더 구현
107
108
109
110
          onEncoderRight();
          break;
      }
  }
cfc2fcc35   김태훈   쿨다운 팝업 추가
111
112
113
114
  void CooldownPopup::start()
  {
      started = true;
      opened = false;
6fbaea2a7   김태훈   수동 요리 동작 변경
115
116
      oven->setFan(expectingFanLevel);
      oven->startCooldown();
cfc2fcc35   김태훈   쿨다운 팝업 추가
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
      checkOvenTimer.start();
  
      updateView();
  }
  
  void CooldownPopup::stop()
  {
      started = false;
  
      oven->stopCooldown();
      oven->setFan(cookingFanLevel);
  
      close();
  }
  
  void CooldownPopup::showCurrentTemp()
  {
      showingCurrentTemp = true;
      updateView();
  }
  
  void CooldownPopup::updateView()
  {
f9c67430c   김태훈   현재 온도를 표시할 때 슬라이더...
140
141
      QWidget *focused = focusWidget();
      ui->tempButton->setChecked(focused == ui->tempSlider);
cfc2fcc35   김태훈   쿨다운 팝업 추가
142
143
144
      int temp;
      if (showingCurrentTemp)
          temp = oven->currentTemp();
f9c67430c   김태훈   현재 온도를 표시할 때 슬라이더...
145
      else if (ui->tempSlider->isSliderDown() || focusWidget() == ui->tempSlider)
271dda4ae   김태훈   엔코더 구현
146
          temp = ui->tempSlider->sliderPosition();
f9c67430c   김태훈   현재 온도를 표시할 때 슬라이더...
147
148
149
150
151
152
153
154
155
      else
          temp = ui->tempSlider->value();
  
      if (ui->tempSlider->sliderPosition() != temp)
      {
          ui->tempSlider->blockSignals(true);
          ui->tempSlider->setSliderPosition(temp);
          ui->tempSlider->blockSignals(false);
      }
cfc2fcc35   김태훈   쿨다운 팝업 추가
156
2bfd3a050   김태훈   환경 설정 대응
157
      ui->tempCurrentLabel->setText(Stringer::temperature(temp, Stringer::fontSize14));
cfc2fcc35   김태훈   쿨다운 팝업 추가
158
2bfd3a050   김태훈   환경 설정 대응
159
      if (lastDisplayedFanLevel != expectingFanLevel)
cfc2fcc35   김태훈   쿨다운 팝업 추가
160
      {
2bfd3a050   김태훈   환경 설정 대응
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
          lastDisplayedFanLevel = expectingFanLevel;
  
          switch (expectingFanLevel)
          {
          case 1:
              ui->fanButton->setStyleSheet("background-image: url(:/images/cooldown/fan1.png);");
              break;
          case 2:
              ui->fanButton->setStyleSheet("background-image: url(:/images/cooldown/fan2.png);");
              break;
          case 3:
              ui->fanButton->setStyleSheet("background-image: url(:/images/cooldown/fan3.png);");
              break;
          case 4:
              ui->fanButton->setStyleSheet("background-image: url(:/images/cooldown/fan4.png);");
              break;
          case 5:
              ui->fanButton->setStyleSheet("background-image: url(:/images/cooldown/fan5.png);");
              break;
          }
cfc2fcc35   김태훈   쿨다운 팝업 추가
181
      }
2bfd3a050   김태훈   환경 설정 대응
182
183
184
      if (lastDisplayedHumidification != oven->humidification())
      {
          lastDisplayedHumidification = oven->humidification();
271dda4ae   김태훈   엔코더 구현
185
          ui->humidificationButton->setChecked(oven->humidification());
2bfd3a050   김태훈   환경 설정 대응
186
      }
cfc2fcc35   김태훈   쿨다운 팝업 추가
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
  
      if (started && !oven->door())
          ui->openDoorWidget->show();
      else
          ui->openDoorWidget->hide();
  }
  
  void CooldownPopup::checkOven()
  {
      updateView();
  
      if (!started)
          return;
  
      if (!opened)
      {
          if (oven->door())
          {
              opened = true;
cfc2fcc35   김태훈   쿨다운 팝업 추가
206
207
208
209
210
211
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
          }
      }
      else
      {
          if (oven->currentTemp() <= ui->tempSlider->value())
          {
              stop();
          }
      }
  }
  
  void CooldownPopup::on_closeButton_clicked()
  {
      stop();
      close();
  }
  
  void CooldownPopup::on_closeButton_2_clicked()
  {
      stop();
      close();
  }
  
  void CooldownPopup::on_tempButton_pressed()
  {
      showCurrentTempTimer.start();
  }
  
  void CooldownPopup::on_tempButton_released()
  {
      if (showCurrentTempTimer.isActive())
          showCurrentTempTimer.stop();
  
      if (showingCurrentTemp)
      {
          showingCurrentTemp = false;
          updateView();
      }
  }
  
  void CooldownPopup::on_runButton_clicked()
  {
      if (cooldownStartTimer.isActive())
      {
          cooldownStartTimer.stop();
          start();
      }
  }
  
  void CooldownPopup::on_fanButton_clicked()
  {
      expectingFanLevel--;
      if (expectingFanLevel < oven->minFan())
          expectingFanLevel = oven->maxFan();
0fbf1932c   김태훈   V1.5.0.2
260
      oven->setFan(expectingFanLevel);
cfc2fcc35   김태훈   쿨다운 팝업 추가
261
262
263
264
265
266
267
268
269
270
271
272
  
      if (cooldownStartTimer.isActive())
          cooldownStartTimer.start();
  }
  
  void CooldownPopup::on_humidificationButton_clicked()
  {
      if (oven->humidification())
          oven->stopHumidification();
      else
          oven->startHumidification();
  }
271dda4ae   김태훈   엔코더 구현
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
  
  void CooldownPopup::on_tempButton_clicked()
  {
      ui->tempSlider->setFocus();
      focusTempButtonTimer.start();
  }
  
  void CooldownPopup::focusTempButton()
  {
      if (focusWidget() == ui->tempSlider)
          ui->tempButton->setFocus();
  }
  
  void CooldownPopup::onEncoderLeft()
  {
      QWidget *focused = focusWidget();
      if (focused == ui->background)
          ui->humidificationButton->setFocus();
      else
          focusPreviousChild();
  }
  
  void CooldownPopup::onEncoderRight()
  {
      if (focusWidget() == ui->humidificationButton)
          ui->background->setFocus();
      else
          focusNextChild();
  }
  
  void CooldownPopup::onEncoderClicked(QWidget *clicked)
  {
      if (clicked == ui->background)
f9c67430c   김태훈   현재 온도를 표시할 때 슬라이더...
306
      {
271dda4ae   김태훈   엔코더 구현
307
          close();
f9c67430c   김태훈   현재 온도를 표시할 때 슬라이더...
308
309
310
311
312
          return;
      }
  
      QPushButton *b = qobject_cast<QPushButton *>(clicked);
      if (b)
271dda4ae   김태훈   엔코더 구현
313
      {
f9c67430c   김태훈   현재 온도를 표시할 때 슬라이더...
314
315
          b->click();
          return;
271dda4ae   김태훈   엔코더 구현
316
      }
f9c67430c   김태훈   현재 온도를 표시할 때 슬라이더...
317
318
319
  
      Slider *slider = qobject_cast<Slider *>(clicked);
      if (slider)
271dda4ae   김태훈   엔코더 구현
320
      {
f9c67430c   김태훈   현재 온도를 표시할 때 슬라이더...
321
          ui->tempButton->setFocus();
271dda4ae   김태훈   엔코더 구현
322
323
      }
  }