functiontestwindow.cpp 2.6 KB
#include "functiontestwindow.h"
#include "ui_functiontestwindow.h"

#include <QKeyEvent>

#include "burnertestwindow.h"
#include "componenttestwindow.h"
#include "valvetestwindow.h"
#include "washtestwindow.h"
#include "fantestwindow.h"
#include "gastestwindow.h"
#include "soundplayer.h"

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

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

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

    connect(ui->backButton, SIGNAL(clicked(bool)), SLOT(close()));
}

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

void FunctionTestWindow::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 FunctionTestWindow::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 FunctionTestWindow::on_burnerTestButton_clicked()
{
    BurnerTestWindow *w = new BurnerTestWindow(this);
    w->showFullScreen();
}

void FunctionTestWindow::on_componentTestButton_clicked()
{
    ComponentTestWindow *w = new ComponentTestWindow(this);
    w->showFullScreen();
}

void FunctionTestWindow::on_valveTestButton_clicked()
{
    ValveTestWindow *w = new ValveTestWindow(this);
    w->showFullScreen();
}

void FunctionTestWindow::on_washTestButton_clicked()
{
    WashTestWindow *w = new WashTestWindow(this);
    w->showFullScreen();
}

void FunctionTestWindow::on_fanTestButton_clicked()
{
    FanTestWindow *w = new FanTestWindow(this);
    w->showFullScreen();
}

void FunctionTestWindow::on_gasTestButton_clicked()
{
//    GasTestWindow *w = new GasTestWindow(this, udp);
    //    w->showFullScreen();
}

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

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

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