operationtimemain.cpp 1.94 KB
#include <QKeyEvent>
#include "operationtimemain.h"
#include "ui_operationtimemain.h"
#include "operationtimeheat.h"
#include "operationtimemode.h"
#include "operationtimeparts.h"
#include "soundplayer.h"

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

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

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

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

void OperationTimeMain::on_btnHeatPartTime_clicked()
{
    OperationTimeHeat* w = new OperationTimeHeat();
    w->setWindowModality(Qt::WindowModal);
    w->showFullScreen();
}

void OperationTimeMain::on_btnModeTime_clicked()
{
    OperationTimeMode* w = new OperationTimeMode();
    w->setWindowModality(Qt::WindowModal);
    w->showFullScreen();
}

void OperationTimeMain::on_btnPartsTime_clicked()
{
    OperationTimeParts*w = new OperationTimeParts();
    w->setWindowModality(Qt::WindowModal);
    w->showFullScreen();
}

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

void OperationTimeMain::keyPressEvent(QKeyEvent *event)
{
    switch (event->key())
    {
    case 0x01000030:    // Turn left
        focusPreviousChild();
        break;
    case 0x01000031:    // Push
        break;
    case 0x01000032:    // Turn right
        focusNextChild();
        break;
    }
}

void OperationTimeMain::keyReleaseEvent(QKeyEvent *event)
{
    switch (event->key())
    {
    case 0x01000030:    // Turn left
        focusPreviousChild();
        break;
    case 0x01000031:    // Push
    {
        QPushButton *btn = qobject_cast<QPushButton*>(focusWidget());
        if(btn != NULL){
            btn->click();
        }
        break;
    }
    case 0x01000032:    // Turn right
        focusNextChild();
        break;
    }
}