programmingmanualwindow.cpp 6.55 KB
#include "programmingmanualwindow.h"
#include "ui_programmingmanualwindow.h"

#include "stringer.h"
#include "programmingmanualcoretemppopup.h"
#include "cookprogram.h"
#include "soundplayer.h"

ProgrammingManualWindow::ProgrammingManualWindow(QWidget *parent, Define::Mode mode) :
    QMainWindow(parent),
    ui(new Ui::ProgrammingManualWindow)
{
    ui->setupUi(this);

    ui->clockContainer->setParent(ui->upperStack);
    setAttribute(Qt::WA_DeleteOnClose);

    connect(ui->humiditySlider, SIGNAL(valueChanged(int)), SLOT(updateHumidityLabel()));
    connect(ui->tempSlider, SIGNAL(valueChanged(int)), SLOT(updateTempLabel()));
    connect(ui->timeSlider, SIGNAL(valueChanged(int)), SLOT(updateTimeLabel()));
    connect(ui->interTempSlider, SIGNAL(valueChanged(int)), SLOT(updateCoreTempLabel()));

    setDefault(mode);

    foreach (QPushButton *button, findChildren<QPushButton *>())
        connect(button, &QPushButton::pressed, SoundPlayer::playClick);
}

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

void ProgrammingManualWindow::setDefault(Define::Mode mode)
{
    switch (mode)
    {
    case Define::SteamMode:
        ui->steamButton->setChecked(true);
        ui->humiditySlider->setEnabled(false);
        ui->humiditySlider->setValue(100);
        ui->tempSlider->setRange(30, 130);
        ui->tempSlider->setValue(100);
        ui->timeSlider->setValue(0);
        ui->interTempSlider->setEnabled(false);
        ui->interTempSlider->setValue(30);
        setFan(4);
        updateCoreTempButton();
        updateCoreTempLabel();
        this->mode = mode;
        break;
    case Define::CombiMode:
        ui->combiButton->setChecked(true);
        ui->humiditySlider->setEnabled(true);
        ui->humiditySlider->setValue(50);
        ui->tempSlider->setRange(30, 300);
        ui->tempSlider->setValue(100);
        ui->timeSlider->setValue(0);
        ui->interTempSlider->setEnabled(false);
        ui->interTempSlider->setValue(30);
        setFan(4);
        updateCoreTempButton();
        updateCoreTempLabel();
        this->mode = mode;
        break;
    case Define::DryMode:
        ui->dryheatButton->setChecked(true);
        ui->humiditySlider->setEnabled(false);
        ui->humiditySlider->setValue(0);
        ui->tempSlider->setRange(30, 300);
        ui->tempSlider->setValue(160);
        ui->timeSlider->setValue(0);
        ui->interTempSlider->setEnabled(false);
        ui->interTempSlider->setValue(30);
        setFan(4);
        updateCoreTempButton();
        updateCoreTempLabel();
        this->mode = mode;
        break;
    default:
        return;
    }
}

void ProgrammingManualWindow::setFan(int level)
{
    fan = level;

    updateFanButton();
}

void ProgrammingManualWindow::updateHumidityLabel()
{
//    ui->humidityLabel->setText(QString::number(ui->humiditySlider->value()));
    ui->humidityLabel->setText(QString("%1%").arg(ui->humiditySlider->value()));
}

void ProgrammingManualWindow::updateTempLabel()
{
    ui->tempLabel->setText(Stringer::temperature(ui->tempSlider->value(), Stringer::fontSize14));
}

void ProgrammingManualWindow::updateTimeLabel()
{
    ui->timeLabel->setText(Stringer::remainingTime(ui->timeSlider->value() * 1000, Stringer::fontSize14));
}

void ProgrammingManualWindow::updateCoreTempButton()
{
    if (ui->interTempSlider->isEnabled())
        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);\
}");
}

void ProgrammingManualWindow::updateCoreTempLabel()
{
    if (ui->interTempSlider->isEnabled())
        ui->interTempLabel->setText(Stringer::temperature(ui->interTempSlider->value(), Stringer::fontSize14));
    else
        ui->interTempLabel->setText(Stringer::unusedTemperature(Stringer::fontSize14));
}

void ProgrammingManualWindow::updateFanButton()
{
    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;
    }
}

void ProgrammingManualWindow::onCoreTempEnabled(int celsius)
{
    ui->interTempSlider->setEnabled(true);
    ui->interTempSlider->setValue(celsius);
    updateCoreTempButton();
    updateCoreTempLabel();
}

void ProgrammingManualWindow::on_steamButton_clicked()
{
    setDefault(Define::SteamMode);
}

void ProgrammingManualWindow::on_combiButton_clicked()
{
    setDefault(Define::CombiMode);
}

void ProgrammingManualWindow::on_dryheatButton_clicked()
{
    setDefault(Define::DryMode);
}

void ProgrammingManualWindow::on_interTempButton_clicked()
{
    if (ui->interTempSlider->isEnabled())
    {
        ui->interTempSlider->setEnabled(false);
        updateCoreTempButton();
        updateCoreTempLabel();
    }
    else
    {
        ProgrammingManualCoreTempPopup *p = new ProgrammingManualCoreTempPopup(this);
        connect(p, SIGNAL(coreTempEnabled(int)), SLOT(onCoreTempEnabled(int)));
        p->showFullScreen();
    }
}

void ProgrammingManualWindow::on_fanButton_clicked()
{
    fan++;
    if (fan > 5)
        fan = 1;

    updateFanButton();
}

void ProgrammingManualWindow::on_backButton_clicked()
{
    close();
}

void ProgrammingManualWindow::on_configButton_clicked()
{

}

void ProgrammingManualWindow::on_helpButton_clicked()
{

}

void ProgrammingManualWindow::on_okButton_clicked()
{
    ManualCookSetting s;
    s.mode = mode;
    s.humidity = ui->humiditySlider->value();
    s.temp = ui->tempSlider->value();
    s.time = ui->timeSlider->value();
    s.coreTempEnabled = ui->interTempSlider->isEnabled();
    s.coreTemp = ui->interTempSlider->value();
    s.fan = fan;

    CookProgram::add(s);

    emit added();
    close();
}