programmingselectionwindow.cpp 4.68 KB
#include "programmingselectionwindow.h"
#include "ui_programmingselectionwindow.h"

#include <QKeyEvent>

#include "programmingmanualwindow.h"
#include "programmingautoselectionwindow.h"
#include "soundplayer.h"
#include "configwindow.h"
#include "mainwindow.h"
#include "manualviewerdlg.h"

ProgrammingSelectionWindow::ProgrammingSelectionWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::ProgrammingSelectionWindow)
{
    ui->setupUi(this);

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

    setFocus();

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

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

void ProgrammingSelectionWindow::setModeEnabled(bool enabled)
{
    ui->steamButton->setEnabled(enabled);
    ui->combiButton->setEnabled(enabled);
    ui->dryheatButton->setEnabled(enabled);
}

void ProgrammingSelectionWindow::setCookTypeEnabled(bool enabled)
{
    ui->poultryButton->setEnabled(enabled);
    ui->meatButton->setEnabled(enabled);
    ui->fishButton->setEnabled(enabled);
    ui->dessertButton->setEnabled(enabled);
    ui->grainButton->setEnabled(enabled);
    ui->breadButton->setEnabled(enabled);
    ui->etcButton->setEnabled(enabled);
}

void ProgrammingSelectionWindow::keyPressEvent(QKeyEvent *event)
{
    switch (event->key())
    {
    case 0x01000032:    // Turn left
        onEncoderLeft();
        break;
    case 0x01000031:    // Push
        pushed = focusWidget();
        break;
    case 0x01000030:    // Turn right
        onEncoderRight();
        break;
    }
}

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

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

void ProgrammingSelectionWindow::onEncoderLeft()
{
    focusPreviousChild();
}

void ProgrammingSelectionWindow::onEncoderRight()
{
    focusNextChild();
}

void ProgrammingSelectionWindow::onEncoderClicked(QWidget *clicked)
{
    QPushButton *b = qobject_cast<QPushButton *>(clicked);
    if (b)
        b->click();
}

void ProgrammingSelectionWindow::onModeClicked(Define::Mode mode)
{
    setFocus();

    ProgrammingManualWindow *w = new ProgrammingManualWindow(this, mode);
    connect(w, SIGNAL(added()), SIGNAL(added()));
    connect(w, SIGNAL(added()), SLOT(hide()));
    connect(w, SIGNAL(added()), SLOT(close()));
    w->setWindowModality(Qt::WindowModal);
    w->showFullScreen();
    w->raise();
}

void ProgrammingSelectionWindow::onCookTypeClicked(Define::CookType type)
{
    setFocus();

    ProgrammingAutoSelectionWindow *w = new ProgrammingAutoSelectionWindow(this, type);
    connect(w, SIGNAL(added()), SIGNAL(added()));
    connect(w, SIGNAL(added()), SLOT(hide()));
    connect(w, SIGNAL(added()), SLOT(close()));
    w->setWindowModality(Qt::WindowModal);
    w->showFullScreen();
    w->raise();
}

void ProgrammingSelectionWindow::on_steamButton_clicked()
{
    onModeClicked(Define::SteamMode);
}

void ProgrammingSelectionWindow::on_combiButton_clicked()
{
    onModeClicked(Define::CombiMode);
}

void ProgrammingSelectionWindow::on_dryheatButton_clicked()
{
    onModeClicked(Define::DryMode);
}

void ProgrammingSelectionWindow::on_poultryButton_clicked()
{
    onCookTypeClicked(Define::Poultry);
}

void ProgrammingSelectionWindow::on_meatButton_clicked()
{
    onCookTypeClicked(Define::Meat);
}

void ProgrammingSelectionWindow::on_fishButton_clicked()
{
    onCookTypeClicked(Define::Fish);
}

void ProgrammingSelectionWindow::on_dessertButton_clicked()
{
    onCookTypeClicked(Define::Desert);
}

void ProgrammingSelectionWindow::on_grainButton_clicked()
{
    onCookTypeClicked(Define::Vegetable);
}

void ProgrammingSelectionWindow::on_breadButton_clicked()
{
    onCookTypeClicked(Define::Bread);
}

void ProgrammingSelectionWindow::on_etcButton_clicked()
{
    onCookTypeClicked(Define::Etc);
}

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

void ProgrammingSelectionWindow::on_configButton_clicked()
{
    ConfigWindow *w = new ConfigWindow(MainWindow::getInstance());
    w->setWindowModality(Qt::WindowModal);
    w->showFullScreen();
    w->raise();

    MainWindow::jump(w);
}

void ProgrammingSelectionWindow::on_helpButton_clicked()
{
    ManualViewerDlg* dlg = new ManualViewerDlg(this);
    dlg->showFullScreen();
    dlg->raise();
}

void ProgrammingSelectionWindow::on_okButton_clicked()
{
    close();
}