Blame view

app/gui/oven_control/programmingautoconfigwindow.cpp 6.89 KB
382b586e9   김태훈   프로그래밍 모드 임시 구현
1
2
  #include "programmingautoconfigwindow.h"
  #include "ui_programmingautoconfigwindow.h"
9e1f8d093   김태훈   엔코더 구현 대비 선행 수정
3
  #include <QKeyEvent>
382b586e9   김태훈   프로그래밍 모드 임시 구현
4
5
6
  #include "soundplayer.h"
  #include "stringer.h"
  #include "cookprogram.h"
95a9aa99d   김태훈   기능 보충 구현
7
8
  #include "configwindow.h"
  #include "mainwindow.h"
382b586e9   김태훈   프로그래밍 모드 임시 구현
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
  
  ProgrammingAutoConfigWindow::ProgrammingAutoConfigWindow(QWidget *parent, Cook cook) :
      QMainWindow(parent),
      ui(new Ui::ProgrammingAutoConfigWindow),
      cook(cook)
  {
      ui->setupUi(this);
  
      ui->clockContainer->setParent(ui->upperStack);
      setAttribute(Qt::WA_DeleteOnClose);
  
      configWidgets.append(
                  ConfigWidget {
                      ui->configButton_1,
                      ui->configMinLabel_1,
                      ui->configMaxLabel_1,
                      ui->configCurrentLabel_1,
                      ui->configSlider_1
                  });
      configWidgets.append(
                  ConfigWidget {
                      ui->configButton_2,
                      ui->configMinLabel_2,
                      ui->configMaxLabel_2,
                      ui->configCurrentLabel_2,
                      ui->configSlider_2
                  });
      configWidgets.append(
                  ConfigWidget {
                      ui->configButton_3,
                      ui->configMinLabel_3,
                      ui->configMaxLabel_3,
                      ui->configCurrentLabel_3,
                      ui->configSlider_3
                  });
      configWidgets.append(
                  ConfigWidget {
                      ui->configButton_4,
                      ui->configMinLabel_4,
                      ui->configMaxLabel_4,
                      ui->configCurrentLabel_4,
                      ui->configSlider_4
                  });
      configWidgets.append(
                  ConfigWidget {
                      ui->configButton_5,
                      ui->configMinLabel_5,
                      ui->configMaxLabel_5,
                      ui->configCurrentLabel_5,
                      ui->configSlider_5
                  });
  
      setupUi();
  
      foreach (QPushButton *button, findChildren<QPushButton *>())
          connect(button, &QPushButton::pressed, SoundPlayer::playClick);
  }
  
  ProgrammingAutoConfigWindow::~ProgrammingAutoConfigWindow()
  {
      delete ui;
  }
9e1f8d093   김태훈   엔코더 구현 대비 선행 수정
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
  void ProgrammingAutoConfigWindow::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 ProgrammingAutoConfigWindow::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;
      }
  }
  
  void ProgrammingAutoConfigWindow::onEncoderLeft()
  {
  
  }
  
  void ProgrammingAutoConfigWindow::onEncoderRight()
  {
  
  }
  
  void ProgrammingAutoConfigWindow::onEncoderClicked(QWidget *clicked)
  {
  
  }
382b586e9   김태훈   프로그래밍 모드 임시 구현
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
  void ProgrammingAutoConfigWindow::setupUi()
  {
      ui->cookTypeIcon->setPixmap(Define::icon(cook.type));
      ui->selectCookButton->setText(cook.name);
  
      for (int idx = 0; idx < 5; idx++)
      {
          CookConfig config = cook.configs[idx];
          if (config.type == Define::ConfigNotUsed)
          {
              ConfigWidget cw = configWidgets.at(idx);
              cw.button->hide();
              cw.minimum->hide();
              cw.maximum->hide();
              cw.current->hide();
              cw.slider->hide();
          }
          else
          {
              ConfigWidget cw = configWidgets.at(idx);
              cw.button->setStyleSheet(
                          "QPushButton { image: url("
                           + Define::icon(config.type)
                           + ") } QPushButton::pressed { image: url("
                           + Define::iconOverlay(config.type)
                           + ") }");
  
              cw.minimum->setText(Define::minimum(config.type));
              cw.maximum->setText(Define::maximum(config.type));
382b586e9   김태훈   프로그래밍 모드 임시 구현
149
150
151
152
  
              switch (config.type)
              {
              case Define::Time:
935b853a4   김태훈   새 슬라이더 적용
153
                  cw.slider->setSubPixmap(":/images/slider/sub_white.png");
382b586e9   김태훈   프로그래밍 모드 임시 구현
154
155
                  break;
              case Define::BurnDegree:
935b853a4   김태훈   새 슬라이더 적용
156
                  cw.slider->setSubPixmap(":/images/slider/sub_yellow.png");
382b586e9   김태훈   프로그래밍 모드 임시 구현
157
158
                  break;
              case Define::Brightness:
935b853a4   김태훈   새 슬라이더 적용
159
                  cw.slider->setSubPixmap(":/images/slider/sub_red.png");
382b586e9   김태훈   프로그래밍 모드 임시 구현
160
161
                  break;
              default:
935b853a4   김태훈   새 슬라이더 적용
162
                  cw.slider->setSubPixmap(":/images/slider/sub_blue.png");
382b586e9   김태훈   프로그래밍 모드 임시 구현
163
164
                  break;
              }
935b853a4   김태훈   새 슬라이더 적용
165
166
167
168
169
170
171
172
              cw.slider->blockSignals(true);
              cw.slider->setMinimum(1);
              cw.slider->setMaximum(config.maximum);
              cw.slider->setValue(config.current);
              cw.slider->blockSignals(false);
              cw.slider->bigTickInterval = 1;
  
              connect(cw.slider, SIGNAL(sliderMoved(int)), SLOT(updateConfig()));
382b586e9   김태훈   프로그래밍 모드 임시 구현
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
          }
      }
  
      updateView();
  }
  
  void ProgrammingAutoConfigWindow::updateView()
  {
      for (int idx = 0; idx < 5; idx++)
      {
          CookConfig config = cook.configs[idx];
          if (config.type == Define::ConfigNotUsed)
              continue;
  
          ConfigWidget cw = configWidgets.at(idx);
  
          switch (config.type)
          {
          case Define::Time:
              cw.current->setText(Stringer::remainingTime(cook.time() * 1000, Stringer::fontSize14));
              break;
          case Define::BurnDegree:
              cw.current->setText(Stringer::temperature(cook.coreTemp(), Stringer::fontSize14));
              break;
          default:
              cw.current->setText(QString().sprintf(
                      "%d"
                      "<span style=\"font-size:11pt;\">/%d</span>",
                      config.current, config.maximum));
              break;
          }
      }
  }
  
  void ProgrammingAutoConfigWindow::updateConfig()
  {
935b853a4   김태훈   새 슬라이더 적용
209
210
211
212
213
      cook.setConfig(ui->configSlider_1->sliderPosition(),
                     ui->configSlider_2->sliderPosition(),
                     ui->configSlider_3->sliderPosition(),
                     ui->configSlider_4->sliderPosition(),
                     ui->configSlider_5->sliderPosition());
382b586e9   김태훈   프로그래밍 모드 임시 구현
214
215
216
217
218
219
220
221
222
223
224
  
      updateView();
  }
  
  void ProgrammingAutoConfigWindow::on_backButton_clicked()
  {
      close();
  }
  
  void ProgrammingAutoConfigWindow::on_configButton_clicked()
  {
95a9aa99d   김태훈   기능 보충 구현
225
226
227
228
      ConfigWindow *w = new ConfigWindow(MainWindow::getInstance());
      w->setWindowModality(Qt::WindowModal);
      w->showFullScreen();
      w->raise();
382b586e9   김태훈   프로그래밍 모드 임시 구현
229
95a9aa99d   김태훈   기능 보충 구현
230
      MainWindow::jump(w);
382b586e9   김태훈   프로그래밍 모드 임시 구현
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
  }
  
  void ProgrammingAutoConfigWindow::on_helpButton_clicked()
  {
  
  }
  
  void ProgrammingAutoConfigWindow::on_okButton_clicked()
  {
      if (!cook.isLoaded())
          cook.load();
  
      AutoCookSetting s;
      s.type = cook.type;
      s.name = cook.name;
      s.root = cook.root;
      for (int i = 0; i < 5; i++)
          s.configs[i] = cook.configs[i].current;
  
      CookProgram::add(s);
  
      emit added();
      close();
  }