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,6 +3,7 @@ | ||
| 3 | 3 | ||
| 4 | #include <QSignalMapper> | 4 | #include <QSignalMapper> |
| 5 | #include <QtDebug> | 5 | #include <QtDebug> |
| 6 | +#include <QKeyEvent> | ||
| 6 | 7 | ||
| 7 | #include "autocookconfigwindow.h" | 8 | #include "autocookconfigwindow.h" |
| 8 | #include "soundplayer.h" | 9 | #include "soundplayer.h" |
| @@ -36,7 +37,7 @@ AutoCookSelectionWindow::AutoCookSelectionWindow(QWidget *parent, Define::CookTy | @@ -36,7 +37,7 @@ AutoCookSelectionWindow::AutoCookSelectionWindow(QWidget *parent, Define::CookTy | ||
| 36 | QLatin1String stylesheet("QPushButton {\n" | 37 | QLatin1String stylesheet("QPushButton {\n" |
| 37 | "border-image: url(:/images/button/288.png);\n" | 38 | "border-image: url(:/images/button/288.png);\n" |
| 38 | "}\n" | 39 | "}\n" |
| 39 | - "QPushButton::pressed {\n" | 40 | + "QPushButton::pressed, QPushButton:focus {\n" |
| 40 | "border-image: url(:/images/button/288_ov.png);\n" | 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,10 +54,15 @@ AutoCookSelectionWindow::AutoCookSelectionWindow(QWidget *parent, Define::CookTy | ||
| 53 | 54 | ||
| 54 | sm->setMapping(pb, idx); | 55 | sm->setMapping(pb, idx); |
| 55 | connect(pb, SIGNAL(clicked()), sm, SLOT(map())); | 56 | connect(pb, SIGNAL(clicked()), sm, SLOT(map())); |
| 57 | + | ||
| 58 | + if (idx == 0) | ||
| 59 | + firstEntry = pb; | ||
| 56 | } | 60 | } |
| 57 | 61 | ||
| 58 | foreach (QPushButton *button, findChildren<QPushButton *>()) | 62 | foreach (QPushButton *button, findChildren<QPushButton *>()) |
| 59 | connect(button, &QPushButton::pressed, SoundPlayer::playClick); | 63 | connect(button, &QPushButton::pressed, SoundPlayer::playClick); |
| 64 | + | ||
| 65 | + setFocus(); | ||
| 60 | } | 66 | } |
| 61 | 67 | ||
| 62 | AutoCookSelectionWindow::~AutoCookSelectionWindow() | 68 | AutoCookSelectionWindow::~AutoCookSelectionWindow() |
| @@ -64,6 +70,41 @@ AutoCookSelectionWindow::~AutoCookSelectionWindow() | @@ -64,6 +70,41 @@ AutoCookSelectionWindow::~AutoCookSelectionWindow() | ||
| 64 | delete ui; | 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 | void AutoCookSelectionWindow::onCookSelected(int idx) | 108 | void AutoCookSelectionWindow::onCookSelected(int idx) |
| 68 | { | 109 | { |
| 69 | AutoCookConfigWindow *w = new AutoCookConfigWindow(this, book.get(idx)); | 110 | AutoCookConfigWindow *w = new AutoCookConfigWindow(this, book.get(idx)); |
| @@ -101,3 +142,28 @@ void AutoCookSelectionWindow::on_helpButton_clicked() | @@ -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,6 +2,7 @@ | ||
| 2 | #define AUTOCOOKSELECTIONWINDOW_H | 2 | #define AUTOCOOKSELECTIONWINDOW_H |
| 3 | 3 | ||
| 4 | #include <QMainWindow> | 4 | #include <QMainWindow> |
| 5 | +#include <QPushButton> | ||
| 5 | 6 | ||
| 6 | #include "oven.h" | 7 | #include "oven.h" |
| 7 | #include "cookbook.h" | 8 | #include "cookbook.h" |
| @@ -18,6 +19,10 @@ public: | @@ -18,6 +19,10 @@ public: | ||
| 18 | explicit AutoCookSelectionWindow(QWidget *parent, Define::CookType type); | 19 | explicit AutoCookSelectionWindow(QWidget *parent, Define::CookType type); |
| 19 | ~AutoCookSelectionWindow(); | 20 | ~AutoCookSelectionWindow(); |
| 20 | 21 | ||
| 22 | +protected: | ||
| 23 | + void keyPressEvent(QKeyEvent *event); | ||
| 24 | + void keyReleaseEvent(QKeyEvent *event); | ||
| 25 | + | ||
| 21 | private slots: | 26 | private slots: |
| 22 | void onCookSelected(int idx); | 27 | void onCookSelected(int idx); |
| 23 | 28 | ||
| @@ -35,6 +40,13 @@ private: | @@ -35,6 +40,13 @@ private: | ||
| 35 | CookBook book; | 40 | CookBook book; |
| 36 | 41 | ||
| 37 | bool autoCookWindowOpened; | 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 | #endif // AUTOCOOKSELECTIONWINDOW_H | 52 | #endif // AUTOCOOKSELECTIONWINDOW_H |
app/gui/oven_control/autocookselectionwindow.ui
| @@ -77,7 +77,7 @@ | @@ -77,7 +77,7 @@ | ||
| 77 | </property> | 77 | </property> |
| 78 | <property name="styleSheet"> | 78 | <property name="styleSheet"> |
| 79 | <string notr="true">QPushButton { border-image: url(:/images/bottom_bar/back.png); } | 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 | </property> | 81 | </property> |
| 82 | <property name="text"> | 82 | <property name="text"> |
| 83 | <string/> | 83 | <string/> |
| @@ -100,7 +100,7 @@ QPushButton:pressed { border-image: url(:/images/bottom_bar/back_ov.png); }</str | @@ -100,7 +100,7 @@ QPushButton:pressed { border-image: url(:/images/bottom_bar/back_ov.png); }</str | ||
| 100 | </property> | 100 | </property> |
| 101 | <property name="styleSheet"> | 101 | <property name="styleSheet"> |
| 102 | <string notr="true">QPushButton { border-image: url(:/images/bottom_bar/config.png); } | 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 | </property> | 104 | </property> |
| 105 | <property name="text"> | 105 | <property name="text"> |
| 106 | <string/> | 106 | <string/> |
| @@ -123,7 +123,7 @@ QPushButton:pressed { border-image: url(:/images/bottom_bar/config_ov.png); }</s | @@ -123,7 +123,7 @@ QPushButton:pressed { border-image: url(:/images/bottom_bar/config_ov.png); }</s | ||
| 123 | </property> | 123 | </property> |
| 124 | <property name="styleSheet"> | 124 | <property name="styleSheet"> |
| 125 | <string notr="true">QPushButton { border-image: url(:/images/bottom_bar/wash.png); } | 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 | </property> | 127 | </property> |
| 128 | <property name="text"> | 128 | <property name="text"> |
| 129 | <string/> | 129 | <string/> |
| @@ -146,7 +146,7 @@ QPushButton:pressed { border-image: url(:/images/bottom_bar/wash_ov.png); }</str | @@ -146,7 +146,7 @@ QPushButton:pressed { border-image: url(:/images/bottom_bar/wash_ov.png); }</str | ||
| 146 | </property> | 146 | </property> |
| 147 | <property name="styleSheet"> | 147 | <property name="styleSheet"> |
| 148 | <string notr="true">QPushButton { border-image: url(:/images/bottom_bar/help.png); } | 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 | </property> | 150 | </property> |
| 151 | <property name="text"> | 151 | <property name="text"> |
| 152 | <string/> | 152 | <string/> |