manualcooksettingwidget.cpp 4.04 KB
#include "manualcooksettingwidget.h"
#include "ui_manualcooksettingwidget.h"

#include <QKeyEvent>

#include "stringer.h"

ManualCookSettingWidget::ManualCookSettingWidget(ManualCookSetting setting, QWidget *parent) :
    QWidget(parent),
    ui(new Ui::ManualCookSettingWidget)
{
    ui->setupUi(this);

    setMode(setting.mode);
    setHumidity(setting.humidity);
    setTemp(setting.temp);
    setTime(setting.time);
    setCoreTempEnabled(setting.coreTempEnabled);
    setCoreTemp(setting.coreTemp);
    setFan(setting.fan);
}

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

void ManualCookSettingWidget::setMode(Define::Mode mode)
{
    switch (mode)
    {
    case Define::SteamMode:
        ui->steamButton->setChecked(true);
        ui->tempSlider->setRange(30, 130);
        break;
    case Define::CombiMode:
        ui->combiButton->setChecked(true);
        ui->tempSlider->setRange(30, 300);
        break;
    case Define::DryMode:
        ui->dryheatButton->setChecked(true);
        ui->tempSlider->setRange(30, 300);
        break;
    default:
        return;
    }
}

void ManualCookSettingWidget::setHumidity(int percentage)
{
    ui->humiditySlider->setValue(percentage);
    ui->humidityLabel->setText(QString("%1%").arg(percentage));
}

void ManualCookSettingWidget::setTemp(int celsius)
{
    ui->tempSlider->setValue(celsius);
    ui->tempLabel->setText(Stringer::temperature(celsius, Stringer::fontSize14));
}

void ManualCookSettingWidget::setTime(int secs)
{
    ui->timeSlider->setValue(secs);
    ui->timeLabel->setText(Stringer::remainingTime(secs * 1000, Stringer::fontSize14));
}

void ManualCookSettingWidget::setCoreTempEnabled(bool enabled)
{
    ui->coreTempButton->setEnabled(enabled);
    ui->coreTempSlider->setEnabled(enabled);

    if (enabled)
        ui->coreTempLabel->setText(Stringer::temperature(ui->coreTempSlider->value(), Stringer::fontSize14));
    else
        ui->coreTempLabel->setText(Stringer::unusedTemperature(Stringer::fontSize14));
}

void ManualCookSettingWidget::setCoreTemp(int celsius)
{
    ui->coreTempSlider->setValue(celsius);
    if (ui->coreTempSlider->isEnabled())
        ui->coreTempLabel->setText(Stringer::temperature(celsius, Stringer::fontSize14));
}

void ManualCookSettingWidget::setFan(int level)
{
    switch (level)
    {
    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 ManualCookSettingWidget::keyPressEvent(QKeyEvent *event)
{
    switch (event->key())
    {
    case 0x01000030:    // Turn left
        onEncoderLeft();
        break;
    case 0x01000031:    // Push
        pushed = focusWidget();
        break;
    case 0x01000032:    // Turn right
        onEncoderRight();
        break;
    }
}

void ManualCookSettingWidget::keyReleaseEvent(QKeyEvent *event)
{
    switch (event->key())
    {
    case 0x01000030:    // Turn left
        onEncoderLeft();
        break;
    case 0x01000031:    // Push
        if (focusWidget() == pushed)
            onEncoderClicked(pushed);

        pushed = NULL;
        break;
    case 0x01000032:    // Turn right
        onEncoderRight();
        break;
    }
}

void ManualCookSettingWidget::onEncoderLeft()
{

}

void ManualCookSettingWidget::onEncoderRight()
{

}

void ManualCookSettingWidget::onEncoderClicked(QWidget *clicked)
{

}