Commit 6f1aa03f6b62890a8e8bc6178ecdb0fa9deb0e04
1 parent
f2921ceb9a
Exists in
master
and in
2 other branches
엔코더 구현
- 자동 요리 선택 화면
Showing
3 changed files
with
83 additions
and
5 deletions
Show diff stats
app/gui/oven_control/autocookselectionwindow.cpp
... | ... | @@ -3,6 +3,7 @@ |
3 | 3 | |
4 | 4 | #include <QSignalMapper> |
5 | 5 | #include <QtDebug> |
6 | +#include <QKeyEvent> | |
6 | 7 | |
7 | 8 | #include "autocookconfigwindow.h" |
8 | 9 | #include "soundplayer.h" |
... | ... | @@ -36,7 +37,7 @@ AutoCookSelectionWindow::AutoCookSelectionWindow(QWidget *parent, Define::CookTy |
36 | 37 | QLatin1String stylesheet("QPushButton {\n" |
37 | 38 | "border-image: url(:/images/button/288.png);\n" |
38 | 39 | "}\n" |
39 | - "QPushButton::pressed {\n" | |
40 | + "QPushButton::pressed, QPushButton:focus {\n" | |
40 | 41 | "border-image: url(:/images/button/288_ov.png);\n" |
41 | 42 | "}"); |
42 | 43 | |
... | ... | @@ -53,10 +54,15 @@ AutoCookSelectionWindow::AutoCookSelectionWindow(QWidget *parent, Define::CookTy |
53 | 54 | |
54 | 55 | sm->setMapping(pb, idx); |
55 | 56 | connect(pb, SIGNAL(clicked()), sm, SLOT(map())); |
57 | + | |
58 | + if (idx == 0) | |
59 | + firstEntry = pb; | |
56 | 60 | } |
57 | 61 | |
58 | 62 | foreach (QPushButton *button, findChildren<QPushButton *>()) |
59 | 63 | connect(button, &QPushButton::pressed, SoundPlayer::playClick); |
64 | + | |
65 | + setFocus(); | |
60 | 66 | } |
61 | 67 | |
62 | 68 | AutoCookSelectionWindow::~AutoCookSelectionWindow() |
... | ... | @@ -64,6 +70,41 @@ AutoCookSelectionWindow::~AutoCookSelectionWindow() |
64 | 70 | delete ui; |
65 | 71 | } |
66 | 72 | |
73 | +void AutoCookSelectionWindow::keyPressEvent(QKeyEvent *event) | |
74 | +{ | |
75 | + switch (event->key()) | |
76 | + { | |
77 | + case 0x01000030: // Turn left | |
78 | + onEncoderLeft(); | |
79 | + break; | |
80 | + case 0x01000031: // Push | |
81 | + pushed = focusWidget(); | |
82 | + break; | |
83 | + case 0x01000032: // Turn right | |
84 | + onEncoderRight(); | |
85 | + break; | |
86 | + } | |
87 | +} | |
88 | + | |
89 | +void AutoCookSelectionWindow::keyReleaseEvent(QKeyEvent *event) | |
90 | +{ | |
91 | + switch (event->key()) | |
92 | + { | |
93 | + case 0x01000030: // Turn left | |
94 | + onEncoderLeft(); | |
95 | + break; | |
96 | + case 0x01000031: // Push | |
97 | + if (focusWidget() == pushed) | |
98 | + onEncoderClicked(pushed); | |
99 | + | |
100 | + pushed = NULL; | |
101 | + break; | |
102 | + case 0x01000032: // Turn right | |
103 | + onEncoderRight(); | |
104 | + break; | |
105 | + } | |
106 | +} | |
107 | + | |
67 | 108 | void AutoCookSelectionWindow::onCookSelected(int idx) |
68 | 109 | { |
69 | 110 | AutoCookConfigWindow *w = new AutoCookConfigWindow(this, book.get(idx)); |
... | ... | @@ -101,3 +142,28 @@ void AutoCookSelectionWindow::on_helpButton_clicked() |
101 | 142 | { |
102 | 143 | |
103 | 144 | } |
145 | + | |
146 | +void AutoCookSelectionWindow::onEncoderLeft() | |
147 | +{ | |
148 | + QWidget *focused = focusWidget(); | |
149 | + if (focused == this || focused == firstEntry) | |
150 | + ui->helpButton->setFocus(); | |
151 | + else | |
152 | + focusPreviousChild(); | |
153 | +} | |
154 | + | |
155 | +void AutoCookSelectionWindow::onEncoderRight() | |
156 | +{ | |
157 | + QWidget *focused = focusWidget(); | |
158 | + if (focused == this || focused == ui->helpButton) | |
159 | + firstEntry->setFocus(); | |
160 | + else | |
161 | + focusNextChild(); | |
162 | +} | |
163 | + | |
164 | +void AutoCookSelectionWindow::onEncoderClicked(QWidget *clicked) | |
165 | +{ | |
166 | + QPushButton *b = qobject_cast<QPushButton *>(clicked); | |
167 | + if (b) | |
168 | + b->click(); | |
169 | +} | ... | ... |
app/gui/oven_control/autocookselectionwindow.h
... | ... | @@ -2,6 +2,7 @@ |
2 | 2 | #define AUTOCOOKSELECTIONWINDOW_H |
3 | 3 | |
4 | 4 | #include <QMainWindow> |
5 | +#include <QPushButton> | |
5 | 6 | |
6 | 7 | #include "oven.h" |
7 | 8 | #include "cookbook.h" |
... | ... | @@ -18,6 +19,10 @@ public: |
18 | 19 | explicit AutoCookSelectionWindow(QWidget *parent, Define::CookType type); |
19 | 20 | ~AutoCookSelectionWindow(); |
20 | 21 | |
22 | +protected: | |
23 | + void keyPressEvent(QKeyEvent *event); | |
24 | + void keyReleaseEvent(QKeyEvent *event); | |
25 | + | |
21 | 26 | private slots: |
22 | 27 | void onCookSelected(int idx); |
23 | 28 | |
... | ... | @@ -35,6 +40,13 @@ private: |
35 | 40 | CookBook book; |
36 | 41 | |
37 | 42 | bool autoCookWindowOpened; |
43 | + | |
44 | + QPushButton *firstEntry = NULL; | |
45 | + QWidget *pushed = NULL; | |
46 | + | |
47 | + void onEncoderLeft(); | |
48 | + void onEncoderRight(); | |
49 | + void onEncoderClicked(QWidget *clicked); | |
38 | 50 | }; |
39 | 51 | |
40 | 52 | #endif // AUTOCOOKSELECTIONWINDOW_H | ... | ... |
app/gui/oven_control/autocookselectionwindow.ui
... | ... | @@ -77,7 +77,7 @@ |
77 | 77 | </property> |
78 | 78 | <property name="styleSheet"> |
79 | 79 | <string notr="true">QPushButton { border-image: url(:/images/bottom_bar/back.png); } |
80 | -QPushButton:pressed { border-image: url(:/images/bottom_bar/back_ov.png); }</string> | |
80 | +QPushButton:pressed, QPushButton:focus { border-image: url(:/images/bottom_bar/back_ov.png); }</string> | |
81 | 81 | </property> |
82 | 82 | <property name="text"> |
83 | 83 | <string/> |
... | ... | @@ -100,7 +100,7 @@ QPushButton:pressed { border-image: url(:/images/bottom_bar/back_ov.png); }</str |
100 | 100 | </property> |
101 | 101 | <property name="styleSheet"> |
102 | 102 | <string notr="true">QPushButton { border-image: url(:/images/bottom_bar/config.png); } |
103 | -QPushButton:pressed { border-image: url(:/images/bottom_bar/config_ov.png); }</string> | |
103 | +QPushButton:pressed, QPushButton:focus { border-image: url(:/images/bottom_bar/config_ov.png); }</string> | |
104 | 104 | </property> |
105 | 105 | <property name="text"> |
106 | 106 | <string/> |
... | ... | @@ -123,7 +123,7 @@ QPushButton:pressed { border-image: url(:/images/bottom_bar/config_ov.png); }</s |
123 | 123 | </property> |
124 | 124 | <property name="styleSheet"> |
125 | 125 | <string notr="true">QPushButton { border-image: url(:/images/bottom_bar/wash.png); } |
126 | -QPushButton:pressed { border-image: url(:/images/bottom_bar/wash_ov.png); }</string> | |
126 | +QPushButton:pressed, QPushButton:focus { border-image: url(:/images/bottom_bar/wash_ov.png); }</string> | |
127 | 127 | </property> |
128 | 128 | <property name="text"> |
129 | 129 | <string/> |
... | ... | @@ -146,7 +146,7 @@ QPushButton:pressed { border-image: url(:/images/bottom_bar/wash_ov.png); }</str |
146 | 146 | </property> |
147 | 147 | <property name="styleSheet"> |
148 | 148 | <string notr="true">QPushButton { border-image: url(:/images/bottom_bar/help.png); } |
149 | -QPushButton:pressed { border-image: url(:/images/bottom_bar/help_ov.png); }</string> | |
149 | +QPushButton:pressed, QPushButton:focus { border-image: url(:/images/bottom_bar/help_ov.png); }</string> | |
150 | 150 | </property> |
151 | 151 | <property name="text"> |
152 | 152 | <string/> | ... | ... |