autocookconfigwindow.cpp 7.02 KB
#include "autocookconfigwindow.h"
#include "ui_autocookconfigwindow.h"

AutoCookConfigWindow::AutoCookConfigWindow(QWidget *parent, Oven *oven, AbstractCook *cook) :
    QMainWindow(parent),
    ui(new Ui::AutoCookConfigWindow),
    oven(oven),
    cook(cook)
{
    ui->setupUi(this);

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

    ui->cookTypeIcon->setPixmap(Cook::icon(cook->type()));
    ui->selectCookButton->setText(cook->name());

    configWidgets.append(
                ConfigWidget {
                    ui->configButton_1,
                    ui->configBlock_1,
                    ui->configMinLabel_1,
                    ui->configMaxLabel_1,
                    ui->configCurrentLabel_1,
                    ui->configSlider_1
                });
    configWidgets.append(
                ConfigWidget {
                    ui->configButton_2,
                    ui->configBlock_2,
                    ui->configMinLabel_2,
                    ui->configMaxLabel_2,
                    ui->configCurrentLabel_2,
                    ui->configSlider_2
                });
    configWidgets.append(
                ConfigWidget {
                    ui->configButton_3,
                    ui->configBlock_3,
                    ui->configMinLabel_3,
                    ui->configMaxLabel_3,
                    ui->configCurrentLabel_3,
                    ui->configSlider_3
                });
    configWidgets.append(
                ConfigWidget {
                    ui->configButton_4,
                    ui->configBlock_4,
                    ui->configMinLabel_4,
                    ui->configMaxLabel_4,
                    ui->configCurrentLabel_4,
                    ui->configSlider_4
                });
    configWidgets.append(
                ConfigWidget {
                    ui->configButton_5,
                    ui->configBlock_5,
                    ui->configMinLabel_5,
                    ui->configMaxLabel_5,
                    ui->configCurrentLabel_5,
                    ui->configSlider_5
                });

    for (int idx = 0; idx < 5; idx++)
    {
        AbstractCookConfig *config = cook->configurations[idx];
        if (config == NULL)
        {
            ConfigWidget cw = configWidgets.at(idx);
            cw.button->hide();
            cw.block->hide();
            cw.minimum->hide();
            cw.maximum->hide();
            cw.current->hide();
            cw.slider->hide();
        }
        else
        {
            ConfigWidget cw = configWidgets.at(idx);
            cw.button->setStyleSheet(
                        "QPushButton { border-image: url("
                         + config->icon()
                         + ") } QPushButton::pressed { border-image: url("
                         + config->overlayIcon()
                         + ") }");

            cw.minimum->setText(config->minLabel());
            cw.maximum->setText(config->maxLabel());
            cw.slider->blockSignals(true);
            cw.slider->setMinimum(1);
            cw.slider->setMaximum(config->count());
            cw.slider->setValue(config->current());
            cw.slider->blockSignals(false);

            switch (config->type())
            {
            case Cook::Time:
                cw.slider->setProperty("sliderColor", "white");
                break;
            case Cook::BurnDegree:
                cw.slider->setProperty("sliderColor", "yellow");
                break;
            case Cook::Brightness:
                cw.slider->setProperty("sliderColor", "red");
                break;
            default:
                cw.slider->setProperty("sliderColor", "blue");
                break;
            }

            cw.slider->style()->unpolish(cw.slider);
            cw.slider->style()->polish(cw.slider);
            cw.slider->update();

            connect(cw.slider, SIGNAL(valueChanged(int)), SLOT(updateConfig()));
        }
    }

    if (cook->interTempEnabled())
    {
        interTempEnabled = true;

        ConfigWidget cw = configWidgets.at(3);
        cw.button->show();
        cw.button->setStyleSheet(
                    "QPushButton {"
                    "  border-image: url(:/images/images/auto/011_icon_04_ov_01.png)"
                    "} QPushButton::pressed {"
                    "  border-image: url(:/images/images/auto/011_icon_04_ov.png)"
                    "}");

        cw.block->show();
        cw.minimum->hide();
        cw.maximum->hide();
        cw.current->hide();
        cw.slider->hide();

        connect(cw.button, SIGNAL(clicked()), SLOT(changeInterTemp()));
    }

}

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

void AutoCookConfigWindow::updateView()
{
    for (int idx = 0; idx < 5; idx++)
    {
        if (interTempEnabled && idx == 3)
            continue;

        AbstractCookConfig *config = cook->configurations[idx];
        if (config == NULL)
            continue;

        ConfigWidget cw = configWidgets.at(idx);

        switch (config->type())
        {
        case Cook::Time:
        {
            int time = cook->time();
            if (time >= 3600)
                cw.current->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)
                cw.current->setText(QString().sprintf(
                        "%d"
                        "<span style=\"font-size:11pt;\">분</span>"
                        " %02d"
                        "<span style=\"font-size:11pt;\">초</span>",
                        time / 60,
                        time % 60));
            else
                cw.current->setText(QString().sprintf(
                        "%d"
                        "<span style=\"font-size:11pt;\">초</span>",
                        time));
            break;
        }
        case Cook::BurnDegree:
            cw.slider->setProperty("sliderColor", "yellow");
            break;
        case Cook::Brightness:
            cw.slider->setProperty("sliderColor", "red");
            break;
        default:
            cw.slider->setProperty("sliderColor", "blue");
            break;
        }
    }

    if (cook->interTempEnabled())
    {
        ConfigWidget cw = configWidgets.at(3);
        cw.button->show();
        cw.button->setStyleSheet(
                    "QPushButton {"
                    "  border-image: url(:/images/images/auto/011_icon_04_ov_01.png)"
                    "} QPushButton::pressed {"
                    "  border-image: url(:/images/images/auto/011_icon_04_ov.png)"
                    "}");

        cw.block->show();
        cw.minimum->hide();
        cw.maximum->hide();
        cw.current->hide();
        cw.slider->hide();
    }
}

void AutoCookConfigWindow::updateConfig()
{

}

void AutoCookConfigWindow::changeInterTemp()
{
    cook->setInterTempEnabled(!cook->interTempEnabled());
}