configdoormonitoring.cpp 5.03 KB
#include <QDebug>
#include "configdoormonitoring.h"
#include "ui_configdoormonitoring.h"
#include "config1digitsetandenablesetdlg.h"



ConfigDoorMonitoring::ConfigDoorMonitoring(QWidget *parent, ConfigType idx) :
    QMainWindow(parent),
    ui(new Ui::ConfigDoorMonitoring)
{
    ui->setupUi(this);
    ui->clockContainer->setParent(ui->upperStack);
    setAttribute(Qt::WA_DeleteOnClose);
    m_nCfgType = idx;

    if(m_nCfgType == config_cooking_door_monitoring){
        ui->ctrLbTitle->setText(tr("전문가설정 > 조리중 문열림 시간 모니터링"));
    }

    Config *cfg = Config::getInstance();
    config_item item;
    item = cfg->getConfigValue(m_nCfgType);
    m_nSetStage = item.d8.d8_0;
    m_n1Stage = item.d8.d8_1;
    m_n2Stage = item.d8.d8_2;
    m_n3Stage = item.d8.d8_3;

    m_pSignalMapper = new QSignalMapper(this);
    m_pSignalMapper->setMapping(ui->ctrBtn_1,1);
    m_pSignalMapper->setMapping(ui->ctrBtn_2,2);
    m_pSignalMapper->setMapping(ui->ctrBtn_3,3);

    connect(ui->ctrBtn_1,  SIGNAL(clicked(bool)),m_pSignalMapper, SLOT(map()));
    connect(ui->ctrBtn_2,  SIGNAL(clicked(bool)),m_pSignalMapper, SLOT(map()));
    connect(ui->ctrBtn_3,  SIGNAL(clicked(bool)),m_pSignalMapper, SLOT(map()));
    connect(m_pSignalMapper, SIGNAL(mapped(int)), this, SLOT(onBtnClicked(int)));

    reloadUi();
}

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

void ConfigDoorMonitoring::on_backButton_clicked()
{
    Config* cfg = Config::getInstance();
    config_item item;
    item.d8.d8_0 = m_nSetStage;
    item.d8.d8_1 = m_n1Stage;
    item.d8.d8_2 = m_n2Stage;
    item.d8.d8_3 = m_n3Stage;
    cfg->setConfigValue(m_nCfgType, item);
    close();
}


void ConfigDoorMonitoring::reloadUi(){
    switch(m_nSetStage){
        case 0:
            m_n1Stage = 0;
            m_n2Stage = 0;
            m_n3Stage = 0;
            ui->ctrBtn_1->setEnabled(true);
            ui->ctrBtn_2->setEnabled(false);
            ui->ctrBtn_3->setEnabled(false);
            ui->ctrLbSet_1->setText("-");
            ui->ctrLbSet_2->setText("-");
            ui->ctrLbSet_3->setText("-");
            qDebug() << "0 stage";
        break;
    case 1:
            m_n2Stage = 0;
            m_n3Stage = 0;
            ui->ctrBtn_1->setEnabled(true);
            ui->ctrBtn_2->setEnabled(true);
            ui->ctrBtn_3->setEnabled(false);
            ui->ctrLbSet_1->setText(QString("%1 s").arg(m_n1Stage));
            ui->ctrLbSet_2->setText("-");
            ui->ctrLbSet_3->setText("-");
        break;
    case 2:
        m_n3Stage = 0;
        ui->ctrBtn_1->setEnabled(true);
        ui->ctrBtn_2->setEnabled(true);
        ui->ctrBtn_3->setEnabled(true);
        ui->ctrLbSet_1->setText(QString("%1 s").arg(m_n1Stage));
        ui->ctrLbSet_2->setText(QString("%1 s").arg(m_n2Stage));
        ui->ctrLbSet_3->setText("-");
        break;
    case 3:
        ui->ctrBtn_1->setEnabled(true);
        ui->ctrBtn_2->setEnabled(true);
        ui->ctrBtn_3->setEnabled(true);
        ui->ctrLbSet_1->setText(QString("%1 s").arg(m_n1Stage));
        ui->ctrLbSet_2->setText(QString("%1 s").arg(m_n2Stage));
        ui->ctrLbSet_3->setText(QString("%1 s").arg(m_n3Stage));
        break;
    }
}


void ConfigDoorMonitoring::onBtnClicked(const int sel){
    Config1DigitSetAndEnableSetDlg* dlg;
    switch(sel){
        case 1:
            dlg = new Config1DigitSetAndEnableSetDlg(this, m_n1Stage);
            dlg->exec();
            if(dlg->getResult() == result_disable){
                m_nSetStage = 0;
                m_n1Stage = 0;
            }
            else if(dlg->getResult() == result_ok){
                m_nSetStage = 1;
                m_n1Stage = dlg->getValue();
            }
            dlg->deleteLater();
            reloadUi();
            break;
        case 2:
            dlg = new Config1DigitSetAndEnableSetDlg(this, m_n2Stage);
            dlg->exec();
            if(dlg->getResult() == result_disable){
                m_nSetStage = 1;
                m_n2Stage = 0;
            }
            else if(dlg->getResult() == result_ok){
                m_nSetStage = 2;
                m_n2Stage = dlg->getValue();
            }
            dlg->deleteLater();
            reloadUi();
            break;
        case 3:
            dlg = new Config1DigitSetAndEnableSetDlg(this, m_n3Stage);
            dlg->exec();
            if(dlg->getResult() == result_disable){
                m_nSetStage = 2;
                m_n3Stage = 0;
            }
            else if(dlg->getResult() == result_ok){
                m_nSetStage = 3;
                m_n3Stage = dlg->getValue();
            }
            dlg->deleteLater();
            reloadUi();
            break;
        default:
            break;
    }
}

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

        break;
    case 0x01000032:    // Turn right
        focusNextChild();
        break;
    }
}

void ConfigDoorMonitoring::keyReleaseEvent(QKeyEvent *event){

}