Blame view

app/gui/oven_control/programmingmanualwindow.cpp 9.87 KB
81b835e59   김태훈   한글 폰트 변경
1
2
  #include "programmingmanualwindow.h"
  #include "ui_programmingmanualwindow.h"
9e1f8d093   김태훈   엔코더 구현 대비 선행 수정
3
  #include <QKeyEvent>
dcfd897f3   김태훈   수동 요리 만들기 추가
4
5
6
  #include "stringer.h"
  #include "programmingmanualcoretemppopup.h"
  #include "cookprogram.h"
382b586e9   김태훈   프로그래밍 모드 임시 구현
7
  #include "soundplayer.h"
95a9aa99d   김태훈   기능 보충 구현
8
9
  #include "configwindow.h"
  #include "mainwindow.h"
dcfd897f3   김태훈   수동 요리 만들기 추가
10
11
  
  ProgrammingManualWindow::ProgrammingManualWindow(QWidget *parent, Define::Mode mode) :
81b835e59   김태훈   한글 폰트 변경
12
13
14
15
      QMainWindow(parent),
      ui(new Ui::ProgrammingManualWindow)
  {
      ui->setupUi(this);
dcfd897f3   김태훈   수동 요리 만들기 추가
16
17
18
  
      ui->clockContainer->setParent(ui->upperStack);
      setAttribute(Qt::WA_DeleteOnClose);
935b853a4   김태훈   새 슬라이더 적용
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
      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   김태훈   수동 요리 만들기 추가
61
62
  
      setDefault(mode);
382b586e9   김태훈   프로그래밍 모드 임시 구현
63
64
65
  
      foreach (QPushButton *button, findChildren<QPushButton *>())
          connect(button, &QPushButton::pressed, SoundPlayer::playClick);
81b835e59   김태훈   한글 폰트 변경
66
67
68
69
70
71
  }
  
  ProgrammingManualWindow::~ProgrammingManualWindow()
  {
      delete ui;
  }
dcfd897f3   김태훈   수동 요리 만들기 추가
72
9e1f8d093   김태훈   엔코더 구현 대비 선행 수정
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
  void ProgrammingManualWindow::keyPressEvent(QKeyEvent *event)
  {
      switch (event->key())
      {
      case 0x01000030:    // Turn left
          onEncoderLeft();
          break;
      case 0x01000031:    // Push
          pushed = focusWidget();
          break;
      case 0x01000032:    // Turn right
          onEncoderRight();
          break;
      }
  }
  
  void ProgrammingManualWindow::keyReleaseEvent(QKeyEvent *event)
  {
      switch (event->key())
      {
      case 0x01000030:    // Turn left
          onEncoderLeft();
          break;
      case 0x01000031:    // Push
          if (focusWidget() == pushed)
              onEncoderClicked(pushed);
  
          pushed = NULL;
          break;
      case 0x01000032:    // Turn right
          onEncoderRight();
          break;
      }
  }
935b853a4   김태훈   새 슬라이더 적용
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
  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;
  }
9e1f8d093   김태훈   엔코더 구현 대비 선행 수정
124
125
126
127
128
129
130
131
132
133
134
135
136
137
  void ProgrammingManualWindow::onEncoderLeft()
  {
  
  }
  
  void ProgrammingManualWindow::onEncoderRight()
  {
  
  }
  
  void ProgrammingManualWindow::onEncoderClicked(QWidget *clicked)
  {
  
  }
dcfd897f3   김태훈   수동 요리 만들기 추가
138
139
140
141
142
143
144
145
146
147
148
149
  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   김태훈   새 슬라이더 적용
150
          ui->interTempSlider->setSubVisible(false);
dcfd897f3   김태훈   수동 요리 만들기 추가
151
152
153
154
155
156
157
158
159
160
161
162
163
164
          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   김태훈   새 슬라이더 적용
165
          ui->interTempSlider->setSubVisible(false);
dcfd897f3   김태훈   수동 요리 만들기 추가
166
167
168
169
170
171
172
173
174
175
176
177
178
179
          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   김태훈   새 슬라이더 적용
180
          ui->interTempSlider->setSubVisible(false);
dcfd897f3   김태훈   수동 요리 만들기 추가
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
          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   김태훈   새 슬라이더 적용
201
      ui->humidityLabel->setText(QString("%1%").arg(ui->humiditySlider->sliderPosition()));
dcfd897f3   김태훈   수동 요리 만들기 추가
202
203
204
205
  }
  
  void ProgrammingManualWindow::updateTempLabel()
  {
935b853a4   김태훈   새 슬라이더 적용
206
      ui->tempLabel->setText(Stringer::temperature(ui->tempSlider->sliderPosition(), Stringer::fontSize14));
dcfd897f3   김태훈   수동 요리 만들기 추가
207
208
209
210
  }
  
  void ProgrammingManualWindow::updateTimeLabel()
  {
935b853a4   김태훈   새 슬라이더 적용
211
      ui->timeLabel->setText(Stringer::remainingTime(sliderToTime(ui->timeSlider->sliderPosition()) * 1000, Stringer::fontSize14));
dcfd897f3   김태훈   수동 요리 만들기 추가
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
  }
  
  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   김태훈   새 슬라이더 적용
237
          ui->interTempLabel->setText(Stringer::temperature(ui->interTempSlider->sliderPosition(), Stringer::fontSize14));
dcfd897f3   김태훈   수동 요리 만들기 추가
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
      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   김태훈   새 슬라이더 적용
276
      ui->interTempSlider->setSubVisible(true);
dcfd897f3   김태훈   수동 요리 만들기 추가
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
      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   김태훈   새 슬라이더 적용
302
          ui->interTempSlider->setSubVisible(false);
dcfd897f3   김태훈   수동 요리 만들기 추가
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
          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   김태훈   기능 보충 구현
330
331
332
333
      ConfigWindow *w = new ConfigWindow(MainWindow::getInstance());
      w->setWindowModality(Qt::WindowModal);
      w->showFullScreen();
      w->raise();
dcfd897f3   김태훈   수동 요리 만들기 추가
334
95a9aa99d   김태훈   기능 보충 구현
335
      MainWindow::jump(w);
dcfd897f3   김태훈   수동 요리 만들기 추가
336
337
338
339
340
341
342
343
344
345
346
347
348
  }
  
  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   김태훈   새 슬라이더 적용
349
      s.time = sliderToTime(ui->timeSlider->value());
dcfd897f3   김태훈   수동 요리 만들기 추가
350
351
352
353
354
355
356
357
358
      s.coreTempEnabled = ui->interTempSlider->isEnabled();
      s.coreTemp = ui->interTempSlider->value();
      s.fan = fan;
  
      CookProgram::add(s);
  
      emit added();
      close();
  }