Commit 184bdebb42d1f19f7f35c830eab16f74d0d13eac

Authored by 김태훈
1 parent e9e5be516f
Exists in master and in 2 other branches fhd, fhd-demo

엔코더 구현

- 자동 요리 설정 화면
app/gui/oven_control/autocookconfigwindow.cpp
1 1 #include "autocookconfigwindow.h"
2 2 #include "ui_autocookconfigwindow.h"
3 3  
  4 +#include <QKeyEvent>
  5 +
4 6 #include "autocookwindow.h"
5 7 #include "confirmpopup.h"
6 8 #include "stringer.h"
... ... @@ -61,31 +63,143 @@ AutoCookConfigWindow::AutoCookConfigWindow(QWidget *parent, Cook cook) :
61 63 ui->configSlider_5
62 64 });
63 65  
64   - cookStartTimer.setSingleShot(true);
65   - cookStartTimer.setInterval(3000);
66   - connect(&cookStartTimer, SIGNAL(timeout()), SLOT(start()));
  66 + setupUi();
  67 +
  68 + afterThreeSecsTimer.setSingleShot(true);
  69 + afterThreeSecsTimer.setInterval(3000);
  70 + connect(&afterThreeSecsTimer, SIGNAL(timeout()), SLOT(afterThreeSecs()));
  71 +
  72 + foreach (QPushButton *button, findChildren<QPushButton *>())
  73 + connect(button, &QPushButton::pressed, SoundPlayer::playClick);
  74 +
  75 + foreach (QWidget *w, findChildren<QWidget *>())
  76 + w->installEventFilter(this);
  77 +
  78 + installEventFilter(this);
  79 +
  80 + setFocus();
67 81  
68   - foreach (ConfigWidget w, configWidgets)
  82 + afterThreeSecsTimer.start();
  83 +}
  84 +
  85 +AutoCookConfigWindow::~AutoCookConfigWindow()
  86 +{
  87 + delete ui;
  88 +}
  89 +
  90 +bool AutoCookConfigWindow::eventFilter(QObject */*watched*/, QEvent *event)
  91 +{
  92 + switch (event->type())
69 93 {
70   - connect(w.button, SIGNAL(pressed()), SLOT(stopTimer()));
71   - connect(w.button, SIGNAL(released()), SLOT(startTimer()));
72   - connect(w.slider, SIGNAL(sliderPressed()), SLOT(stopTimer()));
73   - connect(w.slider, SIGNAL(sliderReleased()), SLOT(startTimer()));
  94 + case QEvent::KeyPress:
  95 + case QEvent::KeyRelease:
  96 + case QEvent::MouseButtonPress:
  97 + case QEvent::MouseButtonRelease:
  98 + case QEvent::MouseMove:
  99 + afterThreeSecsTimer.start();
  100 + break;
  101 + default:
  102 + break;
74 103 }
75 104  
76   - setupUi();
  105 + return false;
  106 +}
77 107  
78   - foreach (QPushButton *button, findChildren<QPushButton *>())
  108 +void AutoCookConfigWindow::keyPressEvent(QKeyEvent *event)
  109 +{
  110 + switch (event->key())
79 111 {
80   - connect(button, &QPushButton::pressed, SoundPlayer::playClick);
  112 + case 0x01000030: // Turn left
  113 + onEncoderLeft();
  114 + break;
  115 + case 0x01000031: // Push
  116 + pushed = focusWidget();
  117 + break;
  118 + case 0x01000032: // Turn right
  119 + onEncoderRight();
  120 + break;
81 121 }
  122 +}
82 123  
83   - startTimer();
  124 +void AutoCookConfigWindow::keyReleaseEvent(QKeyEvent *event)
  125 +{
  126 + switch (event->key())
  127 + {
  128 + case 0x01000030: // Turn left
  129 + onEncoderLeft();
  130 + break;
  131 + case 0x01000031: // Push
  132 + if (focusWidget() == pushed)
  133 + onEncoderClicked(pushed);
  134 +
  135 + pushed = NULL;
  136 + break;
  137 + case 0x01000032: // Turn right
  138 + onEncoderRight();
  139 + break;
  140 + }
84 141 }
85 142  
86   -AutoCookConfigWindow::~AutoCookConfigWindow()
  143 +void AutoCookConfigWindow::afterThreeSecs()
87 144 {
88   - delete ui;
  145 + Slider *slider = qobject_cast<Slider *>(focusWidget());
  146 + if (slider)
  147 + {
  148 + if (slider == ui->configSlider_1)
  149 + ui->configButton_1->setFocus();
  150 + else if (slider == ui->configSlider_2)
  151 + ui->configButton_2->setFocus();
  152 + else if (slider == ui->configSlider_3)
  153 + ui->configButton_3->setFocus();
  154 + else if (slider == ui->configSlider_4)
  155 + ui->configButton_4->setFocus();
  156 + else if (slider == ui->configSlider_5)
  157 + ui->configButton_5->setFocus();
  158 +
  159 + afterThreeSecsTimer.start();
  160 + }
  161 + else
  162 + start();
  163 +}
  164 +
  165 +void AutoCookConfigWindow::onEncoderLeft()
  166 +{
  167 + focusPreviousChild();
  168 +}
  169 +
  170 +void AutoCookConfigWindow::onEncoderRight()
  171 +{
  172 + focusNextChild();
  173 +}
  174 +
  175 +void AutoCookConfigWindow::onEncoderClicked(QWidget *clicked)
  176 +{
  177 + if (clicked == NULL)
  178 + return;
  179 +
  180 + if (clicked->inherits("QPushButton"))
  181 + {
  182 + QPushButton *pb = qobject_cast<QPushButton *>(clicked);
  183 + if (pb)
  184 + pb->click();
  185 + }
  186 + else if (clicked->inherits("Slider"))
  187 + {
  188 + Slider *slider = qobject_cast<Slider *>(clicked);
  189 + if (slider)
  190 + {
  191 + if (slider == ui->configSlider_1)
  192 + ui->configButton_1->setFocus();
  193 + else if (slider == ui->configSlider_2)
  194 + ui->configButton_2->setFocus();
  195 + else if (slider == ui->configSlider_3)
  196 + ui->configButton_3->setFocus();
  197 + else if (slider == ui->configSlider_4)
  198 + ui->configButton_4->setFocus();
  199 + else if (slider == ui->configSlider_5)
  200 + ui->configButton_5->setFocus();
  201 + }
  202 + }
89 203 }
90 204  
91 205 void AutoCookConfigWindow::setupUi()
... ... @@ -111,7 +225,7 @@ void AutoCookConfigWindow::setupUi()
111 225 cw.button->setStyleSheet(
112 226 "QPushButton { image: url("
113 227 + Define::icon(config.type)
114   - + ") } QPushButton::pressed { image: url("
  228 + + ") } QPushButton:pressed, QPushButton:focus { image: url("
115 229 + Define::iconOverlay(config.type)
116 230 + ") }");
117 231  
... ... @@ -187,16 +301,6 @@ void AutoCookConfigWindow::updateConfig()
187 301 updateView();
188 302 }
189 303  
190   -void AutoCookConfigWindow::startTimer()
191   -{
192   - cookStartTimer.start();
193   -}
194   -
195   -void AutoCookConfigWindow::stopTimer()
196   -{
197   - cookStartTimer.stop();
198   -}
199   -
200 304 void AutoCookConfigWindow::start()
201 305 {
202 306 AutoCookWindow *w = new AutoCookWindow(parentWidget(), cook);
... ... @@ -204,7 +308,7 @@ void AutoCookConfigWindow::start()
204 308 w->showFullScreen();
205 309 w->raise();
206 310  
207   - connect(w, SIGNAL(back()), SLOT(startTimer()));
  311 + connect(w, SIGNAL(back()), &afterThreeSecsTimer, SLOT(start()));
208 312 }
209 313  
210 314 void AutoCookConfigWindow::addFavorite()
... ... @@ -241,10 +345,10 @@ void AutoCookConfigWindow::on_favoritesButton_clicked()
241 345  
242 346 connect(p, SIGNAL(accepted()), SLOT(addFavorite()));
243 347  
244   - if (cookStartTimer.isActive())
  348 + if (afterThreeSecsTimer.isActive())
245 349 {
246   - cookStartTimer.stop();
247   - connect(p, SIGNAL(rejected()), &cookStartTimer, SLOT(start()));
  350 + afterThreeSecsTimer.stop();
  351 + connect(p, SIGNAL(rejected()), &afterThreeSecsTimer, SLOT(start()));
248 352 }
249 353 }
250 354  
... ... @@ -257,3 +361,28 @@ void AutoCookConfigWindow::on_washButton_clicked()
257 361  
258 362 MainWindow::jump(w);
259 363 }
  364 +
  365 +void AutoCookConfigWindow::on_configButton_1_clicked()
  366 +{
  367 + ui->configSlider_1->setFocus();
  368 +}
  369 +
  370 +void AutoCookConfigWindow::on_configButton_2_clicked()
  371 +{
  372 + ui->configSlider_2->setFocus();
  373 +}
  374 +
  375 +void AutoCookConfigWindow::on_configButton_3_clicked()
  376 +{
  377 + ui->configSlider_3->setFocus();
  378 +}
  379 +
  380 +void AutoCookConfigWindow::on_configButton_4_clicked()
  381 +{
  382 + ui->configSlider_4->setFocus();
  383 +}
  384 +
  385 +void AutoCookConfigWindow::on_configButton_5_clicked()
  386 +{
  387 + ui->configSlider_5->setFocus();
  388 +}
... ...
app/gui/oven_control/autocookconfigwindow.h
... ... @@ -24,13 +24,17 @@ public:
24 24 explicit AutoCookConfigWindow(QWidget *parent, Cook cook);
25 25 ~AutoCookConfigWindow();
26 26  
  27 + bool eventFilter(QObject *watched, QEvent *event);
  28 +
  29 +protected:
  30 + void keyPressEvent(QKeyEvent *event);
  31 + void keyReleaseEvent(QKeyEvent *event);
  32 +
27 33 private:
28 34 Ui::AutoCookConfigWindow *ui;
29 35 Oven *oven;
30 36 Cook cook;
31 37  
32   - QTimer cookStartTimer;
33   -
34 38 struct ConfigWidget {
35 39 QPushButton *button;
36 40 QLabel *minimum;
... ... @@ -41,19 +45,31 @@ private:
41 45  
42 46 QList<ConfigWidget> configWidgets;
43 47  
  48 + QTimer afterThreeSecsTimer;
  49 +
  50 + QWidget *pushed = NULL;
  51 +
  52 + void onEncoderLeft();
  53 + void onEncoderRight();
  54 + void onEncoderClicked(QWidget *clicked);
  55 +
44 56 private slots:
45 57 void setupUi();
46 58 void updateView();
47 59 void updateConfig();
48   - void startTimer();
49   - void stopTimer();
50 60 void start();
51 61 void addFavorite();
  62 + void afterThreeSecs();
52 63  
53 64 void on_backButton_clicked();
54 65 void on_configButton_clicked();
55 66 void on_favoritesButton_clicked();
56 67 void on_washButton_clicked();
  68 + void on_configButton_1_clicked();
  69 + void on_configButton_2_clicked();
  70 + void on_configButton_3_clicked();
  71 + void on_configButton_4_clicked();
  72 + void on_configButton_5_clicked();
57 73 };
58 74  
59 75 #endif // AUTOCOOKCONFIGWINDOW_H
... ...
app/gui/oven_control/autocookconfigwindow.ui
... ... @@ -124,7 +124,7 @@ border: none;
124 124 </property>
125 125 <property name="styleSheet">
126 126 <string notr="true">QPushButton { border-image: url(:/images/bottom_bar/back.png); }
127   -QPushButton:pressed { border-image: url(:/images/bottom_bar/back_ov.png); }</string>
  127 +QPushButton:pressed, QPushButton:focus { border-image: url(:/images/bottom_bar/back_ov.png); }</string>
128 128 </property>
129 129 <property name="text">
130 130 <string/>
... ... @@ -147,7 +147,7 @@ QPushButton:pressed { border-image: url(:/images/bottom_bar/back_ov.png); }&lt;/str
147 147 </property>
148 148 <property name="styleSheet">
149 149 <string notr="true">QPushButton { border-image: url(:/images/bottom_bar/wash.png); }
150   -QPushButton:pressed { border-image: url(:/images/bottom_bar/wash_ov.png); }</string>
  150 +QPushButton:pressed, QPushButton:focus { border-image: url(:/images/bottom_bar/wash_ov.png); }</string>
151 151 </property>
152 152 <property name="text">
153 153 <string/>
... ... @@ -170,7 +170,7 @@ QPushButton:pressed { border-image: url(:/images/bottom_bar/wash_ov.png); }&lt;/str
170 170 </property>
171 171 <property name="styleSheet">
172 172 <string notr="true">QPushButton { border-image: url(:/images/bottom_bar/config.png); }
173   -QPushButton:pressed { border-image: url(:/images/bottom_bar/config_ov.png); }</string>
  173 +QPushButton:pressed, QPushButton:focus { border-image: url(:/images/bottom_bar/config_ov.png); }</string>
174 174 </property>
175 175 <property name="text">
176 176 <string/>
... ... @@ -193,7 +193,7 @@ QPushButton:pressed { border-image: url(:/images/bottom_bar/config_ov.png); }&lt;/s
193 193 </property>
194 194 <property name="styleSheet">
195 195 <string notr="true">QPushButton { border-image: url(:/images/bottom_bar/help.png); }
196   -QPushButton:pressed { border-image: url(:/images/bottom_bar/help_ov.png); }</string>
  196 +QPushButton:pressed, QPushButton:focus { border-image: url(:/images/bottom_bar/help_ov.png); }</string>
197 197 </property>
198 198 <property name="text">
199 199 <string/>
... ... @@ -216,7 +216,7 @@ QPushButton:pressed { border-image: url(:/images/bottom_bar/help_ov.png); }&lt;/str
216 216 </property>
217 217 <property name="styleSheet">
218 218 <string notr="true">QPushButton { border-image: url(:/images/bottom_bar/favorites.png); }
219   -QPushButton:pressed { border-image: url(:/images/bottom_bar/favorites_ov.png); }</string>
  219 +QPushButton:pressed, QPushButton:focus { border-image: url(:/images/bottom_bar/favorites_ov.png); }</string>
220 220 </property>
221 221 <property name="text">
222 222 <string/>
... ... @@ -368,7 +368,7 @@ QPushButton:pressed { border-image: url(:/images/bottom_bar/favorites_ov.png); }
368 368 <string notr="true">QPushButton {
369 369 border-image: url(:/images/button/288.png);
370 370 }
371   -QPushButton::pressed {
  371 +QPushButton::pressed, QPushButton:focus {
372 372 border-image: url(:/images/button/288_ov.png);
373 373 }</string>
374 374 </property>
... ... @@ -639,7 +639,7 @@ border-image: url(:/images/button/288_ov.png);
639 639 <string notr="true">QPushButton {
640 640 border-image: url(:/images/button/152.png);
641 641 }
642   -QPushButton::pressed {
  642 +QPushButton::pressed, QPushButton:focus {
643 643 border-image: url(:/images/button/152_ov.png);
644 644 }</string>
645 645 </property>
... ... @@ -1326,51 +1326,66 @@ border-image: url(:/images/button/152_ov.png);
1326 1326 <property name="geometry">
1327 1327 <rect>
1328 1328 <x>185</x>
1329   - <y>605</y>
  1329 + <y>645</y>
1330 1330 <width>666</width>
1331   - <height>140</height>
  1331 + <height>60</height>
1332 1332 </rect>
1333 1333 </property>
  1334 + <property name="focusPolicy">
  1335 + <enum>Qt::ClickFocus</enum>
  1336 + </property>
1334 1337 </widget>
1335 1338 <widget class="Slider" name="configSlider_2" native="true">
1336 1339 <property name="geometry">
1337 1340 <rect>
1338 1341 <x>185</x>
1339   - <y>765</y>
  1342 + <y>805</y>
1340 1343 <width>666</width>
1341   - <height>140</height>
  1344 + <height>60</height>
1342 1345 </rect>
1343 1346 </property>
  1347 + <property name="focusPolicy">
  1348 + <enum>Qt::ClickFocus</enum>
  1349 + </property>
1344 1350 </widget>
1345 1351 <widget class="Slider" name="configSlider_3" native="true">
1346 1352 <property name="geometry">
1347 1353 <rect>
1348 1354 <x>185</x>
1349   - <y>935</y>
  1355 + <y>975</y>
1350 1356 <width>666</width>
1351   - <height>140</height>
  1357 + <height>60</height>
1352 1358 </rect>
1353 1359 </property>
  1360 + <property name="focusPolicy">
  1361 + <enum>Qt::ClickFocus</enum>
  1362 + </property>
1354 1363 </widget>
1355 1364 <widget class="Slider" name="configSlider_4" native="true">
1356 1365 <property name="geometry">
1357 1366 <rect>
1358 1367 <x>185</x>
1359   - <y>1115</y>
  1368 + <y>1155</y>
1360 1369 <width>666</width>
1361   - <height>140</height>
  1370 + <height>60</height>
1362 1371 </rect>
1363 1372 </property>
  1373 + <property name="focusPolicy">
  1374 + <enum>Qt::ClickFocus</enum>
  1375 + </property>
1364 1376 </widget>
1365 1377 <widget class="Slider" name="configSlider_5" native="true">
1366 1378 <property name="geometry">
1367 1379 <rect>
1368 1380 <x>185</x>
1369   - <y>1285</y>
  1381 + <y>1325</y>
1370 1382 <width>666</width>
1371   - <height>140</height>
  1383 + <height>60</height>
1372 1384 </rect>
1373 1385 </property>
  1386 + <property name="focusPolicy">
  1387 + <enum>Qt::ClickFocus</enum>
  1388 + </property>
1374 1389 </widget>
1375 1390 </widget>
1376 1391 </widget>
... ... @@ -1393,6 +1408,20 @@ border-image: url(:/images/button/152_ov.png);
1393 1408 <container>1</container>
1394 1409 </customwidget>
1395 1410 </customwidgets>
  1411 + <tabstops>
  1412 + <tabstop>selectCookButton</tabstop>
  1413 + <tabstop>pushButton_4</tabstop>
  1414 + <tabstop>configButton_1</tabstop>
  1415 + <tabstop>configButton_2</tabstop>
  1416 + <tabstop>configButton_3</tabstop>
  1417 + <tabstop>configButton_4</tabstop>
  1418 + <tabstop>configButton_5</tabstop>
  1419 + <tabstop>backButton</tabstop>
  1420 + <tabstop>configButton</tabstop>
  1421 + <tabstop>favoritesButton</tabstop>
  1422 + <tabstop>washButton</tabstop>
  1423 + <tabstop>helpButton</tabstop>
  1424 + </tabstops>
1396 1425 <resources>
1397 1426 <include location="resources.qrc"/>
1398 1427 </resources>
... ...