diff --git a/app/gui/oven_control/autocookselectionwindow.cpp b/app/gui/oven_control/autocookselectionwindow.cpp index 289c0ce..9145ce0 100644 --- a/app/gui/oven_control/autocookselectionwindow.cpp +++ b/app/gui/oven_control/autocookselectionwindow.cpp @@ -3,6 +3,7 @@ #include #include +#include #include "autocookconfigwindow.h" #include "soundplayer.h" @@ -36,7 +37,7 @@ AutoCookSelectionWindow::AutoCookSelectionWindow(QWidget *parent, Define::CookTy QLatin1String stylesheet("QPushButton {\n" "border-image: url(:/images/button/288.png);\n" "}\n" - "QPushButton::pressed {\n" + "QPushButton::pressed, QPushButton:focus {\n" "border-image: url(:/images/button/288_ov.png);\n" "}"); @@ -53,10 +54,15 @@ AutoCookSelectionWindow::AutoCookSelectionWindow(QWidget *parent, Define::CookTy sm->setMapping(pb, idx); connect(pb, SIGNAL(clicked()), sm, SLOT(map())); + + if (idx == 0) + firstEntry = pb; } foreach (QPushButton *button, findChildren()) connect(button, &QPushButton::pressed, SoundPlayer::playClick); + + setFocus(); } AutoCookSelectionWindow::~AutoCookSelectionWindow() @@ -64,6 +70,41 @@ AutoCookSelectionWindow::~AutoCookSelectionWindow() delete ui; } +void AutoCookSelectionWindow::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 AutoCookSelectionWindow::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 AutoCookSelectionWindow::onCookSelected(int idx) { AutoCookConfigWindow *w = new AutoCookConfigWindow(this, book.get(idx)); @@ -101,3 +142,28 @@ void AutoCookSelectionWindow::on_helpButton_clicked() { } + +void AutoCookSelectionWindow::onEncoderLeft() +{ + QWidget *focused = focusWidget(); + if (focused == this || focused == firstEntry) + ui->helpButton->setFocus(); + else + focusPreviousChild(); +} + +void AutoCookSelectionWindow::onEncoderRight() +{ + QWidget *focused = focusWidget(); + if (focused == this || focused == ui->helpButton) + firstEntry->setFocus(); + else + focusNextChild(); +} + +void AutoCookSelectionWindow::onEncoderClicked(QWidget *clicked) +{ + QPushButton *b = qobject_cast(clicked); + if (b) + b->click(); +} diff --git a/app/gui/oven_control/autocookselectionwindow.h b/app/gui/oven_control/autocookselectionwindow.h index 3e5f507..14eb416 100644 --- a/app/gui/oven_control/autocookselectionwindow.h +++ b/app/gui/oven_control/autocookselectionwindow.h @@ -2,6 +2,7 @@ #define AUTOCOOKSELECTIONWINDOW_H #include +#include #include "oven.h" #include "cookbook.h" @@ -18,6 +19,10 @@ public: explicit AutoCookSelectionWindow(QWidget *parent, Define::CookType type); ~AutoCookSelectionWindow(); +protected: + void keyPressEvent(QKeyEvent *event); + void keyReleaseEvent(QKeyEvent *event); + private slots: void onCookSelected(int idx); @@ -35,6 +40,13 @@ private: CookBook book; bool autoCookWindowOpened; + + QPushButton *firstEntry = NULL; + QWidget *pushed = NULL; + + void onEncoderLeft(); + void onEncoderRight(); + void onEncoderClicked(QWidget *clicked); }; #endif // AUTOCOOKSELECTIONWINDOW_H diff --git a/app/gui/oven_control/autocookselectionwindow.ui b/app/gui/oven_control/autocookselectionwindow.ui index 9e45a28..c710bab 100644 --- a/app/gui/oven_control/autocookselectionwindow.ui +++ b/app/gui/oven_control/autocookselectionwindow.ui @@ -77,7 +77,7 @@ QPushButton { border-image: url(:/images/bottom_bar/back.png); } -QPushButton:pressed { border-image: url(:/images/bottom_bar/back_ov.png); } +QPushButton:pressed, QPushButton:focus { border-image: url(:/images/bottom_bar/back_ov.png); } @@ -100,7 +100,7 @@ QPushButton:pressed { border-image: url(:/images/bottom_bar/back_ov.png); } QPushButton { border-image: url(:/images/bottom_bar/config.png); } -QPushButton:pressed { border-image: url(:/images/bottom_bar/config_ov.png); } +QPushButton:pressed, QPushButton:focus { border-image: url(:/images/bottom_bar/config_ov.png); } @@ -123,7 +123,7 @@ QPushButton:pressed { border-image: url(:/images/bottom_bar/config_ov.png); } QPushButton { border-image: url(:/images/bottom_bar/wash.png); } -QPushButton:pressed { border-image: url(:/images/bottom_bar/wash_ov.png); } +QPushButton:pressed, QPushButton:focus { border-image: url(:/images/bottom_bar/wash_ov.png); } @@ -146,7 +146,7 @@ QPushButton:pressed { border-image: url(:/images/bottom_bar/wash_ov.png); } QPushButton { border-image: url(:/images/bottom_bar/help.png); } -QPushButton:pressed { border-image: url(:/images/bottom_bar/help_ov.png); } +QPushButton:pressed, QPushButton:focus { border-image: url(:/images/bottom_bar/help_ov.png); }