preheatpopup.cpp 3.55 KB
#include "preheatpopup.h"
#include "ui_preheatpopup.h"

PreheatPopup::PreheatPopup(QWidget *parent, Oven *oven) :
    QWidget(parent),
    ui(new Ui::PreheatPopup),
    oven(oven),
    showingCurrentHumidity(false),
    showingCurrentTemp(false)
{
    ui->setupUi(this);

    setAttribute(Qt::WA_DeleteOnClose);

    connect(oven, SIGNAL(changed(Oven*)), SLOT(onOvenChanged()));

    showCurrentHumidityTimer.setSingleShot(true);
    showCurrentHumidityTimer.setInterval(3000);
    connect(&showCurrentHumidityTimer, SIGNAL(timeout()), SLOT(showCurrentHumidity()));

    showCurrentTempTimer.setSingleShot(true);
    showCurrentTempTimer.setInterval(3000);
    connect(&showCurrentTempTimer, SIGNAL(timeout()), SLOT(showCurrentTemp()));

    ui->preheatGauge->setMaximum(oven->temp());
    ui->preheatGauge->setMinimum(oven->currentTemp());
    ui->preheatGauge->setValue(oven->currentTemp());

    start();
}

PreheatPopup::~PreheatPopup()
{
    delete ui;
}

void PreheatPopup::updateView()
{
    int time = oven->time();
    if (time >= 3600)
        ui->timeLabel->setText(QString().sprintf("%d<span style=\"font-size:11pt;\">시간</span> %02d<span style=\"font-size:11pt;\">분</span>", time / 3600, (time % 3600) / 60));
    else if (time >= 60)
        ui->timeLabel->setText(QString().sprintf("%d<span style=\"font-size:11pt;\">분</span> %02d<span style=\"font-size:11pt;\">초</span>", time / 60, time % 60));
    else
        ui->timeLabel->setText(QString().sprintf("%d<span style=\"font-size:11pt;\">초</span>", time));

    int curInterTemp = oven->currentInterTemp();
    if (oven->interTempEnabled())
    {
        int interTemp = oven->interTemp();
        ui->interTempLabel->setText(QString().sprintf("%d<span style=\"font-size:11pt;\">℃ / %d</span><span style=\"font-size:9pt;\">℃</span>", curInterTemp, interTemp));
    }
    else
        ui->interTempLabel->setText(QString().sprintf("%d<span style=\"font-size:11pt;\">℃</span>", curInterTemp));

    int humidity;
    if (showingCurrentHumidity)
        humidity = oven->currentHumidity();
    else
        humidity = oven->humidity();

    int temp;
    if (showingCurrentTemp)
        temp = oven->currentTemp();
    else
        temp = oven->temp();

    ui->humidityLabel->setText(QString().sprintf("%d%%", humidity));
    ui->humidityGauge->setValue(humidity);
    ui->heatLabel->setText(QString().sprintf("%d℃", temp));
    ui->heatGauge->setValue(temp);

    ui->preheatGauge->setValue(oven->currentTemp());
}

void PreheatPopup::start()
{
    oven->startPreheating();
}

void PreheatPopup::stop()
{
    oven->stopPreheating();
}

void PreheatPopup::showCurrentHumidity()
{
    showingCurrentHumidity = true;

    updateView();
}

void PreheatPopup::showCurrentTemp()
{
    showingCurrentTemp = true;

    updateView();
}

void PreheatPopup::onOvenChanged()
{
    if (oven->currentHumidity() >= oven->humidity() && oven->currentTemp() >= oven->temp())
    {
        stop();
        close();
    }
    else
        updateView();
}

void PreheatPopup::on_closeButton_clicked()
{
    stop();
    close();
}

void PreheatPopup::on_closeButton_2_clicked()
{
    stop();
    close();
}

void PreheatPopup::on_humidityGaugeButton_pressed()
{
    showCurrentHumidityTimer.start();
}

void PreheatPopup::on_humidityGaugeButton_released()
{
    showCurrentHumidityTimer.stop();
    showingCurrentHumidity = false;

    updateView();
}

void PreheatPopup::on_heatGaugeButton_pressed()
{
    showCurrentTempTimer.start();
}

void PreheatPopup::on_heatGaugeButton_released()
{
    showCurrentTempTimer.stop();
    showingCurrentTemp = false;

    updateView();
}