#include "autocookcheckwindow.h" #include "ui_autocookcheckwindow.h" #include #include "mainwindow.h" #include "configwindow.h" #include "washwindow.h" #include "confirmpopup.h" #include "favoritenamepopup.h" #include "stringer.h" #include "soundplayer.h" AutoCookCheckWindow::AutoCookCheckWindow(QWidget *parent, Cook cook) : QMainWindow(parent), ui(new Ui::AutoCookCheckWindow), cook(cook) { ui->setupUi(this); ui->clockContainer->setParent(ui->upperStack); setAttribute(Qt::WA_DeleteOnClose); if (!this->cook.isLoaded()) this->cook.load(); setupUi(); foreach (QPushButton *button, findChildren()) connect(button, &QPushButton::pressed, SoundPlayer::playClick); foreach (QWidget *w, findChildren()) w->installEventFilter(this); afterThreeSecsTimer.setSingleShot(true); afterThreeSecsTimer.setInterval(3000); afterThreeSecsTimer.start(); connect(&afterThreeSecsTimer, SIGNAL(timeout()), SLOT(afterThreeSecs())); setFocus(); } AutoCookCheckWindow::~AutoCookCheckWindow() { delete ui; } bool AutoCookCheckWindow::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 AutoCookCheckWindow::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 AutoCookCheckWindow::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 AutoCookCheckWindow::setupUi() { steamModeIcon.load(":/images/cook_mode/small_steam.png"); dryModeIcon.load(":/images/cook_mode/small_dryheat.png"); combiModeIcon.load(":/images/cook_mode/small_combi.png"); ui->cookTypeIcon->setPixmap(Define::icon(cook.type)); ui->selectCookButton->setText(cook.name); int msecs = 0; for (int i = 0; i < cook.steps.size(); i++) msecs += cook.steps[i].time * 1000; ui->timeLabel->setText(Stringer::remainingTime(msecs)); if (cook.isCoreTempValid()) ui->interTempLabel->setText(Stringer::temperature(cook.coreTemp())); else { ui->interTempIcon->hide(); ui->interTempLabel->hide(); } ui->stepIndicator->setMaximum(cook.steps.size() - 1); ui->cookStepAnimation->start(300); ui->humidityGauge->setMinimum(0); ui->humidityGauge->setMaximum(100); ui->humidityGauge->setValue(0); ui->heatGauge->setMinimum(30); ui->heatGauge->setMaximum(300); ui->heatGauge->setValue(30); ui->doorStepLabel->hide(); selectedStepIndex = 0; lastViewCookMode = Define::InvalidMode; lastViewCookType = Define::Invalid; lastViewDoorType = Define::Invalid; updateView(); } void AutoCookCheckWindow::onEncoderLeft() { focusPreviousChild(); } void AutoCookCheckWindow::onEncoderRight() { focusNextChild(); } void AutoCookCheckWindow::onEncoderClicked(QWidget *clicked) { QPushButton *b = qobject_cast(clicked); if (b) b->click(); } void AutoCookCheckWindow::updateView() { ui->stepIndicator->setCurrentIndex(selectedStepIndex); CookStep showingStep = cook.steps[selectedStepIndex]; if (Define::classify(showingStep.type) == Define::DoorClass) { ui->cookStepIcon->hide(); ui->cookStepLabel->hide(); ui->cookModeIcon->hide(); ui->humidityGauge->hide(); ui->humidityLabel->hide(); ui->heatGauge->hide(); ui->heatLabel->hide(); ui->doorStepLabel->show(); ui->cookStepAnimation->show(); if (showingStep.type != lastViewDoorType) { lastViewDoorType = showingStep.type; ui->doorStepLabel->setText(Define::name(showingStep.type)); ui->cookStepAnimation->clear(); switch (showingStep.type) { case Define::PutThermometer: ui->doorStepLabel->setText(tr("중심 온도계 삽입")); ui->cookStepAnimation->load(":/images/animation/thermometer_01.png"); ui->cookStepAnimation->load(":/images/animation/thermometer_02.png"); ui->cookStepAnimation->setGeometry((900-210)/2, 800, 210, 307); ui->cookStepAnimation->start(300); break; case Define::Load: ui->doorStepLabel->setText(tr("식재료 적재")); ui->cookStepAnimation->load(":/images/animation/load_01.png"); ui->cookStepAnimation->load(":/images/animation/load_02.png"); ui->cookStepAnimation->load(":/images/animation/load_03.png"); ui->cookStepAnimation->load(":/images/animation/load_04.png"); ui->cookStepAnimation->load(":/images/animation/load_03.png"); ui->cookStepAnimation->load(":/images/animation/load_02.png"); ui->cookStepAnimation->load(":/images/animation/load_01.png"); ui->cookStepAnimation->setGeometry((900-264)/2, 800, 264, 307); ui->cookStepAnimation->start(300); break; case Define::Cut: ui->doorStepLabel->setText(tr("자르기")); ui->cookStepAnimation->load(":/images/animation/cut_01.png"); ui->cookStepAnimation->load(":/images/animation/cut_02.png"); ui->cookStepAnimation->load(":/images/animation/cut_03.png"); ui->cookStepAnimation->setGeometry((900-264)/2, 800, 264, 307); ui->cookStepAnimation->start(300); break; case Define::Pour: ui->doorStepLabel->setText(tr("물 붓기")); ui->cookStepAnimation->load(":/images/animation/pour_01.png"); ui->cookStepAnimation->load(":/images/animation/pour_02.png"); ui->cookStepAnimation->load(":/images/animation/pour_03.png"); ui->cookStepAnimation->load(":/images/animation/pour_04.png"); ui->cookStepAnimation->setGeometry((900-264)/2, 800, 264, 307); ui->cookStepAnimation->start(300); break; default: ui->doorStepLabel->hide(); ui->cookStepAnimation->hide(); } } } else { ui->doorStepLabel->hide(); ui->cookStepAnimation->hide(); ui->cookStepIcon->show(); ui->cookStepLabel->show(); ui->cookModeIcon->show(); ui->humidityGauge->show(); ui->humidityLabel->show(); ui->heatGauge->show(); ui->heatLabel->show(); if (showingStep.type != lastViewCookType) { lastViewCookType = showingStep.type; ui->cookStepIcon->setPixmap(Define::icon(showingStep.type)); ui->cookStepLabel->setText(Define::name(showingStep.type)); } if (showingStep.mode != lastViewCookMode) { lastViewCookMode = showingStep.mode; switch (showingStep.mode) { case Define::SteamMode: ui->cookModeIcon->setPixmap(steamModeIcon); break; case Define::CombiMode: ui->cookModeIcon->setPixmap(combiModeIcon); break; case Define::DryMode: ui->cookModeIcon->setPixmap(dryModeIcon); break; case Define::InvalidClass: ui->cookModeIcon->hide(); break; } } ui->humidityLabel->setText(QString("%1%").arg(showingStep.humidity)); ui->humidityGauge->setValue(showingStep.humidity); ui->heatLabel->setText(Stringer::temperature(showingStep.temp)); ui->heatGauge->setValue(showingStep.temp); } } void AutoCookCheckWindow::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 AutoCookCheckWindow::afterThreeSecs() { emit back(); close(); } void AutoCookCheckWindow::on_selectCookButton_clicked() { } void AutoCookCheckWindow::on_showPrevStepButton_clicked() { if (selectedStepIndex > 0) { selectedStepIndex--; updateView(); } } void AutoCookCheckWindow::on_showNextStepButton_clicked() { if (selectedStepIndex + 1 < cook.steps.size()) { selectedStepIndex++; updateView(); } } void AutoCookCheckWindow::on_backButton_clicked() { emit back(); close(); }