#include "autocookconfigwindow.h" #include "ui_autocookconfigwindow.h" #include #include "autocookwindow.h" #include "confirmpopup.h" #include "stringer.h" #include "favoritenamepopup.h" #include "soundplayer.h" #include "configwindow.h" #include "washwindow.h" #include "mainwindow.h" #include "autocookselectionpopup.h" #include "autocookcheckwindow.h" AutoCookConfigWindow::AutoCookConfigWindow(QWidget *parent, Cook cook) : QMainWindow(parent), ui(new Ui::AutoCookConfigWindow), 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 }); foreach (Slider *s, findChildren()) { connect(s, SIGNAL(sliderPressed()), SLOT(updateView())); connect(s, SIGNAL(sliderMoved(int)), SLOT(updateConfig())); } setupUi(); 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(); afterThreeSecsTimer.start(); } AutoCookConfigWindow::~AutoCookConfigWindow() { delete ui; } bool AutoCookConfigWindow::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 AutoCookConfigWindow::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 AutoCookConfigWindow::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 AutoCookConfigWindow::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(); afterThreeSecsTimer.start(); } else start(); updateView(); } void AutoCookConfigWindow::changeCook(Cook cook) { if (this->cook.root == cook.root) return; this->cook = cook; setupUi(); } void AutoCookConfigWindow::connectNewWindow(AutoCookWindow *w) { connect(w, SIGNAL(back()), &afterThreeSecsTimer, SLOT(start())); connect(w, SIGNAL(newWindow(AutoCookWindow*)), SLOT(connectNewWindow(AutoCookWindow*))); } void AutoCookConfigWindow::onEncoderLeft() { focusPreviousChild(); } void AutoCookConfigWindow::onEncoderRight() { focusNextChild(); } void AutoCookConfigWindow::onEncoderClicked(QWidget *clicked) { if (clicked == NULL) return; if (clicked->inherits("QPushButton")) { QPushButton *pb = qobject_cast(clicked); if (pb) pb->click(); } else if (clicked->inherits("Slider")) { 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 AutoCookConfigWindow::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; } } updateView(); } void AutoCookConfigWindow::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 AutoCookConfigWindow::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 AutoCookConfigWindow::start() { setFocus(); AutoCookWindow *w = new AutoCookWindow(parentWidget(), cook); w->setWindowModality(Qt::WindowModal); w->showFullScreen(); w->raise(); connect(w, SIGNAL(back()), &afterThreeSecsTimer, SLOT(start())); connect(w, SIGNAL(newWindow(AutoCookWindow*)), SLOT(connectNewWindow(AutoCookWindow*))); } void AutoCookConfigWindow::addFavorite() { AutoCookSetting s; s.type = cook.type; s.root = cook.root; for (int i = 0; i < 5; i++) s.configs[i] = cook.configs[i].current; FavoriteNamePopup *p = new FavoriteNamePopup(this, s); p->showFullScreen(); } void AutoCookConfigWindow::on_backButton_clicked() { close(); } void AutoCookConfigWindow::on_configButton_clicked() { ConfigWindow *w = new ConfigWindow(MainWindow::getInstance()); w->setWindowModality(Qt::WindowModal); w->showFullScreen(); w->raise(); MainWindow::jump(w); } void AutoCookConfigWindow::on_favoritesButton_clicked() { ConfirmPopup *p = new ConfirmPopup(this, tr("즐겨찾기 항목에 추가하시겠습니까?")); p->showFullScreen(); connect(p, SIGNAL(accepted()), SLOT(addFavorite())); if (afterThreeSecsTimer.isActive()) { afterThreeSecsTimer.stop(); connect(p, SIGNAL(rejected()), &afterThreeSecsTimer, SLOT(start())); } } void AutoCookConfigWindow::on_washButton_clicked() { WashWindow *w = new WashWindow(MainWindow::getInstance()); w->setWindowModality(Qt::WindowModal); w->showFullScreen(); w->raise(); MainWindow::jump(w); } void AutoCookConfigWindow::on_configButton_1_clicked() { ui->configSlider_1->setFocus(); updateView(); } void AutoCookConfigWindow::on_configButton_2_clicked() { ui->configSlider_2->setFocus(); updateView(); } void AutoCookConfigWindow::on_configButton_3_clicked() { ui->configSlider_3->setFocus(); updateView(); } void AutoCookConfigWindow::on_configButton_4_clicked() { ui->configSlider_4->setFocus(); updateView(); } void AutoCookConfigWindow::on_configButton_5_clicked() { ui->configSlider_5->setFocus(); updateView(); } void AutoCookConfigWindow::on_selectCookButton_clicked() { setFocus(); 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())); if (afterThreeSecsTimer.isActive()) { afterThreeSecsTimer.stop(); connect(p, SIGNAL(selected(Cook)), &afterThreeSecsTimer, SLOT(start())); connect(p, SIGNAL(canceled()), &afterThreeSecsTimer, SLOT(start())); } } void AutoCookConfigWindow::on_checkCookButton_clicked() { setFocus(); AutoCookCheckWindow *w = new AutoCookCheckWindow(this, cook); w->setWindowModality(Qt::WindowModal); w->showFullScreen(); w->raise(); if (afterThreeSecsTimer.isActive()) { afterThreeSecsTimer.stop(); connect(w, SIGNAL(back()), &afterThreeSecsTimer, SLOT(start())); } }