#include "programmingautoconfigwindow.h" #include "ui_programmingautoconfigwindow.h" #include #include "soundplayer.h" #include "stringer.h" #include "cookprogram.h" #include "configwindow.h" #include "mainwindow.h" #include "autocookselectionpopup.h" #include "autocookcheckwindow.h" 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 (Slider *s, findChildren()) connect(s, SIGNAL(sliderPressed()), SLOT(updateView())); afterThreeSecsTimer.setSingleShot(true); afterThreeSecsTimer.setInterval(3000); connect(&afterThreeSecsTimer, SIGNAL(timeout()), SLOT(afterThreeSecs())); foreach (QPushButton *button, findChildren()) connect(button, &QPushButton::pressed, SoundPlayer::playClick); foreach (QWidget *w, findChildren()) w->installEventFilter(this); setFocus(); } ProgrammingAutoConfigWindow::~ProgrammingAutoConfigWindow() { delete ui; } bool ProgrammingAutoConfigWindow::eventFilter(QObject */*watched*/, QEvent *event) { switch (event->type()) { case QEvent::KeyPress: case QEvent::KeyRelease: case QEvent::MouseButtonPress: case QEvent::MouseButtonRelease: case QEvent::MouseMove: afterThreeSecsTimer.start(); break; default: break; } return false; } void ProgrammingAutoConfigWindow::keyPressEvent(QKeyEvent *event) { switch (event->key()) { case 0x01000032: // Turn left onEncoderLeft(); break; case 0x01000031: // Push pushed = focusWidget(); break; case 0x01000030: // Turn right onEncoderRight(); break; } } void ProgrammingAutoConfigWindow::keyReleaseEvent(QKeyEvent *event) { switch (event->key()) { case 0x01000032: // Turn left onEncoderLeft(); break; case 0x01000031: // Push if (focusWidget() == pushed) onEncoderClicked(pushed); pushed = NULL; break; case 0x01000030: // Turn right onEncoderRight(); break; } } void ProgrammingAutoConfigWindow::onEncoderLeft() { focusPreviousChild(); } void ProgrammingAutoConfigWindow::onEncoderRight() { focusNextChild(); } void ProgrammingAutoConfigWindow::onEncoderClicked(QWidget *clicked) { QPushButton *pb = qobject_cast(clicked); if (pb) { pb->click(); return; } Slider *slider = qobject_cast(clicked); if (slider) { if (slider == ui->configSlider_1) ui->configButton_1->setFocus(); else if (slider == ui->configSlider_2) ui->configButton_2->setFocus(); else if (slider == ui->configSlider_3) ui->configButton_3->setFocus(); else if (slider == ui->configSlider_4) ui->configButton_4->setFocus(); else if (slider == ui->configSlider_5) ui->configButton_5->setFocus(); updateView(); } } void ProgrammingAutoConfigWindow::setupUi() { ui->cookTypeIcon->setPixmap(Define::icon(cook.type)); ui->selectCookButton->setText(cook.name); QString styleSheet("\ QPushButton { image: url(%1); }\ QPushButton:pressed,\ QPushButton:focus { image: url(%2); }\ QPushButton:checked { image: url(%3); }"); for (int idx = 0; idx < 5; idx++) { ConfigWidget cw = configWidgets.at(idx); CookConfig config = cook.configs[idx]; if (config.type == Define::ConfigNotUsed) { cw.button->hide(); cw.minimum->hide(); cw.maximum->hide(); cw.current->hide(); cw.slider->hide(); } else { cw.button->show(); cw.minimum->show(); cw.maximum->show(); cw.current->show(); cw.slider->show(); cw.button->setStyleSheet(styleSheet .arg(Define::icon(config.type)) .arg(Define::iconOverlay(config.type)) .arg(Define::iconActiveted(config.type))); cw.minimum->setText(Define::minimum(config.type)); cw.maximum->setText(Define::maximum(config.type)); switch (config.type) { case Define::Time: cw.slider->setSubPixmap(":/images/slider/sub_white.png"); break; case Define::BurnDegree: cw.slider->setSubPixmap(":/images/slider/sub_yellow.png"); break; case Define::Brightness: cw.slider->setSubPixmap(":/images/slider/sub_red.png"); break; default: cw.slider->setSubPixmap(":/images/slider/sub_blue.png"); break; } 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())); } } 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" "/%d", config.current, config.maximum)); break; } } QWidget *focused = focusWidget(); ui->configButton_1->setChecked(focused == ui->configSlider_1); ui->configButton_2->setChecked(focused == ui->configSlider_2); ui->configButton_3->setChecked(focused == ui->configSlider_3); ui->configButton_4->setChecked(focused == ui->configSlider_4); ui->configButton_5->setChecked(focused == ui->configSlider_5); } void ProgrammingAutoConfigWindow::updateConfig() { cook.setConfig(ui->configSlider_1->sliderPosition(), ui->configSlider_2->sliderPosition(), ui->configSlider_3->sliderPosition(), ui->configSlider_4->sliderPosition(), ui->configSlider_5->sliderPosition()); updateView(); } void ProgrammingAutoConfigWindow::afterThreeSecs() { Slider *slider = qobject_cast(focusWidget()); if (slider) { if (slider == ui->configSlider_1) ui->configButton_1->setFocus(); else if (slider == ui->configSlider_2) ui->configButton_2->setFocus(); else if (slider == ui->configSlider_3) ui->configButton_3->setFocus(); else if (slider == ui->configSlider_4) ui->configButton_4->setFocus(); else if (slider == ui->configSlider_5) ui->configButton_5->setFocus(); updateView(); } } void ProgrammingAutoConfigWindow::changeCook(Cook cook) { if (this->cook.root == cook.root) return; this->cook = cook; setupUi(); } void ProgrammingAutoConfigWindow::on_selectCookButton_clicked() { AutoCookSelectionPopup *p = new AutoCookSelectionPopup(this, cook.type); p->showFullScreen(); p->raise(); connect(p, SIGNAL(selected(Cook)), SLOT(changeCook(Cook))); connect(p, SIGNAL(selected(Cook)), SLOT(setFocus())); connect(p, SIGNAL(canceled()), SLOT(setFocus())); } void ProgrammingAutoConfigWindow::on_checkCookButton_clicked() { setFocus(); AutoCookCheckWindow *w = new AutoCookCheckWindow(this, cook); w->setWindowModality(Qt::WindowModal); w->showFullScreen(); w->raise(); } void ProgrammingAutoConfigWindow::on_backButton_clicked() { close(); } void ProgrammingAutoConfigWindow::on_configButton_1_clicked() { ui->configSlider_1->setFocus(); updateView(); } void ProgrammingAutoConfigWindow::on_configButton_2_clicked() { ui->configSlider_2->setFocus(); updateView(); } void ProgrammingAutoConfigWindow::on_configButton_3_clicked() { ui->configSlider_3->setFocus(); updateView(); } void ProgrammingAutoConfigWindow::on_configButton_4_clicked() { ui->configSlider_4->setFocus(); updateView(); } void ProgrammingAutoConfigWindow::on_configButton_5_clicked() { ui->configSlider_5->setFocus(); updateView(); } void ProgrammingAutoConfigWindow::on_configButton_clicked() { ConfigWindow *w = new ConfigWindow(MainWindow::getInstance()); w->setWindowModality(Qt::WindowModal); w->showFullScreen(); w->raise(); MainWindow::jump(w); } 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(); }