#include "manualcookwindow.h" #include "ui_manualcookwindow.h" #include #include #include #include "soundplayer.h" #include "preheatpopup.h" #include "cooldownpopup.h" #include "cookhistory.h" #include "favoritenamepopup.h" #include "confirmpopup.h" #include "stringer.h" #include "config.h" #include "coretempsettingpopup.h" #include "reservetimepopup.h" #include "reservedtimepopup.h" #include "mainwindow.h" #include "configwindow.h" #include "primewindow.h" #include "washwindow.h" #include "errorpopupdlg.h" #include ManualCookWindow::ManualCookWindow(QWidget *parent, Define::Mode mode) : QMainWindow(parent), ui(new Ui::ManualCookWindow), repeat(false) { ui->setupUi(this); ui->clockContainer->setParent(ui->upperStack); ui->closeDoorWidget->setParent(ui->upperStack); setAttribute(Qt::WA_DeleteOnClose); oven = Oven::getInstance(); lastViewHumidity = -1; lastViewTemp = -1; lastViewTime = -1; lastViewInterTemp = -1; lastViewInterTempEnabled = !oven->interTempEnabled(); lastViewCooking = false; lastViewDamper = false; lastViewHumidification = false; lastViewFan = -1; Config *config = Config::getInstance(); config_item item = config->getConfigValue(Define::config_cooking_door_monitoring); monitorLevel = item.d8.d8_0; if (monitorLevel > 0 && monitorLevel < 4) { monitor1.setSingleShot(true); monitor2.setSingleShot(true); monitor3.setSingleShot(true); monitor1.setInterval(item.d8.d8_1 * 1000); monitor2.setInterval(item.d8.d8_2 * 1000); monitor3.setInterval(item.d8.d8_3 * 1000); connect(&monitor1, SIGNAL(timeout()), SLOT(onMonitor1Timeout())); connect(&monitor2, SIGNAL(timeout()), SLOT(onMonitor2Timeout())); connect(&monitor3, SIGNAL(timeout()), SLOT(onMonitor3Timeout())); } else monitorLevel = 0; connect(oven, SIGNAL(changed(Oven*)), this, SLOT(onOvenUpdated(Oven*))); connect(ui->humiditySlider, SIGNAL(valueChanged(int)), oven, SLOT(setHumidity(int))); connect(ui->tempSlider, SIGNAL(valueChanged(int)), oven, SLOT(setTemp(int))); connect(ui->timeSlider, SIGNAL(valueChanged(int)), oven, SLOT(setTime(int))); connect(ui->timeSlider, SIGNAL(valueChanged(int)), &startCookingTimer, SLOT(start())); connect(ui->timeSlider, SIGNAL(valueChanged(int)), this, SLOT(updateView())); connect(ui->interTempSlider, SIGNAL(valueChanged(int)), oven, SLOT(setInterTemp(int))); connect(ui->humiditySlider, SIGNAL(sliderMoved(int)), this, SLOT(updateView())); connect(ui->tempSlider, SIGNAL(sliderMoved(int)), this, SLOT(updateView())); connect(ui->timeSlider, SIGNAL(sliderMoved(int)), this, SLOT(updateView())); connect(ui->interTempSlider, SIGNAL(sliderMoved(int)), this, SLOT(updateView())); startCookingTimer.setSingleShot(true); startCookingTimer.setInterval(2000); connect(&startCookingTimer, SIGNAL(timeout()), SLOT(start())); showCurrentHumidityTimer.setSingleShot(true); showCurrentHumidityTimer.setInterval(2000); connect(&showCurrentHumidityTimer, SIGNAL(timeout()), SLOT(showCurrentHumidity())); showCurrentTempTimer.setSingleShot(true); showCurrentTempTimer.setInterval(2000); connect(&showCurrentTempTimer, SIGNAL(timeout()), SLOT(showCurrentTemp())); oven->setDefault(mode); connect(&updateViewTimer, SIGNAL(timeout()), SLOT(updateView())); updateViewTimer.start(100); foreach (QPushButton *button, findChildren()) connect(button, &QPushButton::pressed, SoundPlayer::playClick); QTimer::singleShot(0, this, SLOT(setupAnimation())); } ManualCookWindow::ManualCookWindow(QWidget *parent, ManualCookSetting setting) : ManualCookWindow(parent, setting.mode) { oven->setHumidity(setting.humidity); oven->setTemp(setting.temp); oven->setTime(setting.time); oven->setFan(setting.fan); oven->setInterTempEnabled(setting.coreTempEnabled); oven->setInterTemp(setting.coreTemp); startCookingTimer.start(); onOvenUpdated(oven); } ManualCookWindow::~ManualCookWindow() { stop(); delete ui; } void ManualCookWindow::setupAnimation() { ui->openDoorAnimation->load(":/images/animation/door_big_09.png"); ui->openDoorAnimation->load(":/images/animation/door_big_08.png"); ui->openDoorAnimation->load(":/images/animation/door_big_07.png"); ui->openDoorAnimation->load(":/images/animation/door_big_06.png"); ui->openDoorAnimation->load(":/images/animation/door_big_05.png"); ui->openDoorAnimation->load(":/images/animation/door_big_04.png"); ui->openDoorAnimation->load(":/images/animation/door_big_03.png"); ui->openDoorAnimation->load(":/images/animation/door_big_02.png"); ui->openDoorAnimation->load(":/images/animation/door_big_01.png"); ui->openDoorAnimation->start(300); } void ManualCookWindow::updateView() { switch (oven->mode()) { case Define::DryMode: if (!ui->dryheatButton->isChecked()) ui->dryheatButton->setChecked(true); break; case Define::SteamMode: if (!ui->steamButton->isChecked()) ui->steamButton->setChecked(true); break; case Define::CombiMode: if (!ui->combiButton->isChecked()) ui->combiButton->setChecked(true); break; default: break; } int humidity; if (showCurrentHumidity_) humidity = oven->currentHumidity(); else if (ui->humiditySlider->isSliderDown()) humidity = ui->humiditySlider->sliderPosition(); else humidity = oven->humidity(); if (humidity != lastViewHumidity) { lastViewHumidity = humidity; bool old = ui->humiditySlider->blockSignals(true); if (ui->humiditySlider->sliderPosition() != humidity) ui->humiditySlider->setValue(humidity); ui->humiditySlider->setEnabled(oven->mode() == Define::CombiMode); ui->humiditySlider->blockSignals(old); ui->humidityLabel->setText(QString("%1%").arg(humidity)); } int temp; if (showCurrentTemp_) temp = oven->currentTemp(); else if (ui->tempSlider->isSliderDown()) temp = ui->tempSlider->sliderPosition(); else temp = oven->temp(); if (temp != lastViewTemp) { lastViewTemp = temp; bool old = ui->tempSlider->blockSignals(true); ui->tempSlider->setRange(oven->minTemp(), oven->maxTemp()); if (ui->tempSlider->sliderPosition() != temp) ui->tempSlider->setValue(temp); ui->tempSlider->blockSignals(old); ui->tempLabel->setText(Stringer::temperature(temp, Stringer::fontSize14)); } int msecs; if (ui->timeSlider->isSliderDown()) msecs = ui->timeSlider->sliderPosition() * 1000; else msecs = oven->msecs(); if (msecs != lastViewTime) { lastViewTime = msecs; bool old = ui->timeSlider->blockSignals(true); ui->timeSlider->setSliderPosition(msecs / 1000); ui->timeSlider->blockSignals(old); ui->timeLabel->setText(Stringer::remainingTime(msecs, Stringer::fontSize14)); } int interTemp; if (ui->interTempSlider->isSliderDown()) interTemp = ui->interTempSlider->sliderPosition(); else interTemp = oven->interTemp(); bool interTempEnabled = oven->interTempEnabled(); if (interTempEnabled != lastViewInterTempEnabled || interTemp != lastViewInterTemp) { if (interTempEnabled != lastViewInterTempEnabled) { lastViewInterTempEnabled = oven->interTempEnabled(); if (interTempEnabled) ui->interTempButton->setStyleSheet("\ QPushButton {\ image: url(:/images/slider_icon/core_temp_enabled.png);\ }\ QPushButton:pressed {\ image: url(:/images/slider_icon/core_temp_ov.png);\ }"); else ui->interTempButton->setStyleSheet("\ QPushButton {\ image: url(:/images/slider_icon/core_temp.png);\ }\ QPushButton:pressed {\ image: url(:/images/slider_icon/core_temp_ov.png);\ }"); } lastViewInterTemp = interTemp; bool old = ui->interTempSlider->blockSignals(true); ui->interTempSlider->setEnabled(interTempEnabled); ui->interTempSlider->setRange(oven->minInterTemp(), oven->maxInterTemp()); ui->interTempSlider->setValue(interTemp); ui->interTempSlider->blockSignals(old); if (interTempEnabled) ui->interTempLabel->setText(Stringer::temperature(interTemp, Stringer::fontSize14)); else ui->interTempLabel->setText(Stringer::unusedTemperature(Stringer::fontSize14)); } bool cooking = oven->cooking(); if (cooking != lastViewCooking) { lastViewCooking = cooking; if (cooking) ui->runStopButton->setStyleSheet( "border-image: url(:/images/manual_button/stop.png)"); else ui->runStopButton->setStyleSheet( "border-image: url(:/images/manual_button/run.png)"); } bool damper = oven->damper(); if (damper != lastViewDamper) { lastViewDamper = damper; if (damper) ui->damperButton->setStyleSheet( "background-image: url(:/images/manual_button/damper_open.png)"); else ui->damperButton->setStyleSheet( "background-image: url(:/images/manual_button/damper_close.png)"); } bool humidification = oven->humidification(); if (humidification != lastViewHumidification) { lastViewHumidification = humidification; if (humidification) ui->humidificationButton->setStyleSheet( "background-image: url(:/images/manual_button/side_nozzle_open.png)"); else ui->humidificationButton->setStyleSheet( "background-image: url(:/images/manual_button/side_nozzle_close.png)"); } int fan = oven->fan(); if (fan != lastViewFan) { lastViewFan = fan; switch (fan) { case 1: ui->fanButton->setStyleSheet( "background-image: url(:/images/manual_button/fan_1.png)"); break; case 2: ui->fanButton->setStyleSheet( "background-image: url(:/images/manual_button/fan_2.png)"); break; case 3: ui->fanButton->setStyleSheet( "background-image: url(:/images/manual_button/fan_3.png)"); break; case 4: ui->fanButton->setStyleSheet( "background-image: url(:/images/manual_button/fan_4.png)"); break; case 5: ui->fanButton->setStyleSheet( "background-image: url(:/images/manual_button/fan_5.png)"); break; default: ui->fanButton->setStyleSheet( "background-image: url(:/images/manual_button/fan_1.png)"); break; } } if (oven->paused() && !oven->cooldown() && oven->door()) ui->upperStack->setCurrentIndex(1); else ui->upperStack->setCurrentIndex(0); if (oven->cooking()) { ui->reserveButton->hide(); ui->favoriteButton->hide(); ui->repeatButton->show(); } else { ui->reserveButton->show(); ui->favoriteButton->show(); ui->repeatButton->hide(); } } void ManualCookWindow::showCurrentHumidity() { showCurrentHumidity_ = true; updateView(); } void ManualCookWindow::hideCurrentHumidity() { showCurrentHumidity_ = false; updateView(); } void ManualCookWindow::showCurrentTemp() { showCurrentTemp_ = true; updateView(); } void ManualCookWindow::hideCurrentTemp() { showCurrentTemp_ = false; updateView(); } void ManualCookWindow::onOvenUpdated(Oven *oven) { updateView(); if (oven->interTempEnabled() && oven->currentInterTemp() >= oven->interTemp()) stop(); if (repeat && !oven->cooking()) { repeat = false; ui->repeatButton->setStyleSheet("\ QPushButton { background-image: url(:/images/manual_button/repeat.png); }\ QPushButton:pressed { background-image: url(:/images/manual_button/repeat_ov.png); }"); oven->setMode(repeatSetting.mode); oven->setHumidity(repeatSetting.humidity); oven->setTemp(repeatSetting.temp); oven->setTime(repeatSetting.time); oven->setInterTempEnabled(repeatSetting.coreTempEnabled); oven->setInterTemp(repeatSetting.coreTemp); } if (oven->paused() && oven->door()) { if (monitorLevel > 0 && !monitorTriggered) { monitorTriggered = true; monitor1.start(); } } if (monitorTriggered && !oven->door()) { monitorTriggered = false; monitor1.stop(); monitor2.stop(); monitor3.stop(); } } void ManualCookWindow::setOvenDefault(Define::Mode mode) { stop(); oven->setDefault(mode); } void ManualCookWindow::start() { if (oven->cooking()) return; if (oven->time() > 0) { SoundPlayer::playStart(); if (startCookingTimer.isActive()) startCookingTimer.stop(); oven->startCooking(); ManualCookSetting s; s.mode = oven->mode(); s.humidity = oven->humidity(); s.temp = oven->temp(); s.time = oven->time(); s.fan = oven->fan(); s.coreTempEnabled = oven->interTempEnabled(); s.coreTemp = oven->interTemp(); CookHistory::record(s); if (monitorLevel > 0 && oven->door()) { monitorTriggered = true; monitor1.start(); } else monitorTriggered = false; } } void ManualCookWindow::stop() { if (oven->cooking()) SoundPlayer::playStop(); oven->stop(); startCookingTimer.stop(); } void ManualCookWindow::addFavorite() { ManualCookSetting s; s.mode = oven->mode(); s.humidity = oven->humidity(); s.temp = oven->temp(); s.time = oven->time(); s.fan = oven->fan(); s.coreTempEnabled = oven->interTempEnabled(); s.coreTemp = oven->interTemp(); FavoriteNamePopup *p = new FavoriteNamePopup(this, s); p->showFullScreen(); } void ManualCookWindow::jumpConfig() { stop(); ConfigWindow *w = new ConfigWindow(MainWindow::getInstance()); w->setWindowModality(Qt::WindowModal); w->showFullScreen(); w->raise(); MainWindow::jump(w); } void ManualCookWindow::jumpFavorites() { stop(); PrimeWindow *w = new PrimeWindow(MainWindow::getInstance()); w->setWindowModality(Qt::WindowModal); w->listFavorites(); w->showFullScreen(); w->raise(); MainWindow::jump(w); } void ManualCookWindow::jumpWash() { stop(); WashWindow *w = new WashWindow(MainWindow::getInstance()); w->setWindowModality(Qt::WindowModal); w->showFullScreen(); w->raise(); MainWindow::jump(w); } void ManualCookWindow::onMonitor1Timeout() { SoundPlayer::playError1(); ErrorPopupDlg *d = new ErrorPopupDlg(this, tr("문을 닫아주세요"), tr("조리 중 문 열림 시간 모니터링 1단계")); d->showFullScreen(); if (monitorLevel > 1) monitor2.start(); } void ManualCookWindow::onMonitor2Timeout() { SoundPlayer::playError1(); ErrorPopupDlg *d = new ErrorPopupDlg(this, tr("문을 닫아주세요"), tr("조리 중 문 열림 시간 모니터링 2단계")); d->showFullScreen(); if (monitorLevel > 2) monitor3.start(); } void ManualCookWindow::onMonitor3Timeout() { SoundPlayer::playError1(); ErrorPopupDlg *d = new ErrorPopupDlg(MainWindow::getInstance(), tr("문이 오래 열려있어 조리가 취소되었습니다"), tr("조리 중 문 열림 시간 모니터링 3단계")); d->showFullScreen(); close(); } void ManualCookWindow::on_steamButton_clicked() { setOvenDefault(Define::SteamMode); } void ManualCookWindow::on_combiButton_clicked() { setOvenDefault(Define::CombiMode); } void ManualCookWindow::on_dryheatButton_clicked() { setOvenDefault(Define::DryMode); } void ManualCookWindow::on_humidityButton_pressed() { showCurrentHumidityTimer.start(); } void ManualCookWindow::on_humidityButton_released() { if (showCurrentHumidityTimer.isActive()) showCurrentHumidityTimer.stop(); else hideCurrentHumidity(); } void ManualCookWindow::on_tempButton_pressed() { showCurrentTempTimer.start(); } void ManualCookWindow::on_tempButton_released() { if (showCurrentTempTimer.isActive()) showCurrentTempTimer.stop(); else hideCurrentTemp(); } void ManualCookWindow::on_interTempButton_clicked() { if (oven->interTempEnabled()) oven->setInterTempEnabled(false); else { CoreTempSettingPopup *p = new CoreTempSettingPopup(this); p->show(); } } void ManualCookWindow::on_runStopButton_clicked() { if (oven->cooking()) stop(); else start(); } void ManualCookWindow::on_fanButton_clicked() { int fan = oven->fan() + 1; if (fan > oven->maxFan()) fan = oven->minFan(); oven->setFan(fan); } void ManualCookWindow::on_preheatButton_clicked() { startCookingTimer.stop(); PreheatPopup *p = new PreheatPopup(this, oven); p->setWindowModality(Qt::WindowModal); p->showFullScreen(); } void ManualCookWindow::on_damperButton_clicked() { if (oven->damper()) oven->closeDamper(); else oven->openDamper(); } void ManualCookWindow::on_humidificationButton_clicked() { if (oven->humidification()) oven->stopHumidification(); else oven->startHumidification(); } void ManualCookWindow::on_repeatButton_clicked() { if (repeat) { repeat = false; ui->repeatButton->setStyleSheet("\ QPushButton { background-image: url(:/images/manual_button/repeat.png); }\ QPushButton:pressed { background-image: url(:/images/manual_button/repeat_ov.png); }"); } else { repeat = true; ui->repeatButton->setStyleSheet("\ QPushButton { background-image: url(:/images/manual_button/repeat_ov.png); }\ QPushButton:pressed { background-image: url(:/images/manual_button/repeat.png); }"); repeatSetting.mode = oven->mode(); repeatSetting.humidity = oven->humidity(); repeatSetting.temp= oven->temp(); repeatSetting.time = oven->time(); repeatSetting.coreTempEnabled = oven->interTempEnabled(); repeatSetting.coreTemp = oven->interTemp(); } } void ManualCookWindow::on_cooldownButton_clicked() { startCookingTimer.stop(); CooldownPopup *p = new CooldownPopup(this, oven); p->setWindowModality(Qt::WindowModal); p->showFullScreen(); } void ManualCookWindow::on_reserveButton_clicked() { if (oven->time() > 0) { startCookingTimer.stop(); ReserveTimePopup *p = new ReserveTimePopup(this); connect(p, SIGNAL(timeout()), SLOT(start())); connect(p, SIGNAL(canceled()), &startCookingTimer, SLOT(start())); p->showFullScreen(); } } void ManualCookWindow::on_favoriteButton_clicked() { if (oven->cooking()) return; ConfirmPopup *p = new ConfirmPopup(this, tr("즐겨찾기 항목에 추가하시겠습니까?")); p->showFullScreen(); connect(p, SIGNAL(accepted()), SLOT(addFavorite())); if (startCookingTimer.isActive()) { startCookingTimer.stop(); connect(p, SIGNAL(rejected()), &startCookingTimer, SLOT(start())); } } void ManualCookWindow::on_goBackStackButton_clicked() { ui->buttonStack->setCurrentIndex(1); } void ManualCookWindow::on_goFrontStackButton_clicked() { ui->buttonStack->setCurrentIndex(0); } void ManualCookWindow::on_backButton_clicked() { stop(); close(); } void ManualCookWindow::on_configButton_clicked() { if (oven->cooking()) { ConfirmPopup *p = new ConfirmPopup(this, tr("요리가 중단되고 환경 설정 모드로 들어갑니다. 진행할까요?")); p->showFullScreen(); connect(p, SIGNAL(accepted()), SLOT(jumpConfig())); } else { ConfigWindow *w = new ConfigWindow(MainWindow::getInstance()); w->setWindowModality(Qt::WindowModal); w->showFullScreen(); w->raise(); MainWindow::jump(w); } } void ManualCookWindow::on_favoritesButton_clicked() { if (oven->cooking()) { ConfirmPopup *p = new ConfirmPopup(this, tr("요리가 중단되고 즐겨찾기 모드로 들어갑니다. 진행할까요?")); p->showFullScreen(); connect(p, SIGNAL(accepted()), SLOT(jumpFavorites())); } else { PrimeWindow *w = new PrimeWindow(MainWindow::getInstance()); w->setWindowModality(Qt::WindowModal); w->listFavorites(); w->showFullScreen(); w->raise(); MainWindow::jump(w); } } void ManualCookWindow::on_washButton_clicked() { if (oven->cooking()) { ConfirmPopup *p = new ConfirmPopup(this, tr("요리가 중단되고 자동 세척 모드로 들어갑니다. 진행할까요?")); p->showFullScreen(); connect(p, SIGNAL(accepted()), SLOT(jumpWash())); } else { WashWindow *w = new WashWindow(MainWindow::getInstance()); w->setWindowModality(Qt::WindowModal); w->showFullScreen(); w->raise(); MainWindow::jump(w); } } void ManualCookWindow::on_helpButton_clicked() { }