configwindow.cpp 7.11 KB
#include <QList>
#include "configwindow.h"
#include "ui_configwindow.h"
#include "configfavoritebutton.h"
#include "functiontestwindow.h"
#include "engineermenuwindow.h"
#include "config.h"
#include "configinfodlg.h"
#include "yesnopopupdlg.h"
#include "configdatetimedlg.h"
#include "servicepassinputdlg.h"
#include "fileprocessor.h"
#include "soundplayer.h"

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

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

    ui->scrollAreaMenuLayout->setAlignment(Qt::AlignTop);

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

    Config* cfg = Config::getInstance();

    QSetIterator<uint32_t> itr = cfg->getConstBeginFavorite();
    while(itr.hasNext()) itr.next();

    while(itr.hasPrevious()){
        idx = itr.previous();
        //configbtn = new ConfigPanelButton(this,idx);
    }

    m_nCurConfigPos = config_menu_favorite;

    reloadUi();

}

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

void ConfigWindow::on_pushButton_clicked()
{
    if(m_nCurConfigPos != config_menu_favorite){
        m_nCurConfigPos = config_menu_favorite;
        reloadUi();
    }
}

void ConfigWindow::on_backButton_clicked()
{
    Config* cfg = Config::getInstance();
    QDialog* dlg = new YesNoPopupDlg(this,tr("현재 설정을 적용하시겠습니까?"));
    dlg->setModal(true);
    dlg->exec();
    if(dlg->result() == QDialog::Accepted){
        cfg->saveConfig();
        cfg->saveFavorite();
    }
    else{
        cfg->loadConfig();
        cfg->loadFavorite();
    }
    cfg->applyConfig();
    close();
}

void ConfigWindow::on_pushButton_3_clicked()
{
    /*EngineerMenuWindow *w = new EngineerMenuWindow(this);
    w->setWindowModality(Qt::WindowModal);
    w->showFullScreen();*/
    if(m_nCurConfigPos != config_menu_service){
        m_nCurConfigPos = config_menu_service;
        reloadUi();
    }

}

void ConfigWindow::on_pushButton_8_clicked() //설정 버튼
{
    if(m_nCurConfigPos != config_menu_setting){
        m_nCurConfigPos = config_menu_setting;
        reloadUi();
    }
}

void ConfigWindow::reloadValue(){
    Config* cfg = Config::getInstance();
    QString strtemp="";
    for(int i=0;i<m_vectorMenuList.count();i++){
        strtemp = cfg->getValueString(m_arrConfigListInfos[m_nCurConfigPos][i]);
        m_vectorMenuList[i]->setValue(strtemp);
    }
}

void ConfigWindow::onConfigBtnClicked(uint16_t id){
    Config *cfg = Config::getInstance();
    QDialog* dlg;
    switch(id){
    case config_datetime:
        dlg = new ConfigDateTimeDlg(this);
        dlg->exec();
        if(m_nCurConfigPos != config_menu_favorite) reloadValue();
        break;
    case config_enter_engineer_mode:
        {
            dlg = new ServicePassInputDlg(this);
            dlg->exec();
            break;
        }
    case config_software_info:
    case config_hotline_chef:
    case config_hotline_service:
        dlg = new ConfigInfoDlg(this,(ConfigType)id);
        dlg->exec();
        break;
    default:
        cfg->execConfigWindow(this,(Define::ConfigType)id);
        if(m_nCurConfigPos != config_menu_favorite) reloadValue();
        break;

    }
}


void ConfigWindow::onConfigCheckBtnClicked(uint16_t id, bool checked){
    Config* cfg = Config::getInstance();
    qDebug()<<"favorite pressed " << id;
    if(checked){
        cfg->insertFavorite((ConfigType)id);
    }
    else{
        cfg->removeFavorite((ConfigType)id);
    }
}

void ConfigWindow::reloadUi(void){
    ConfigPanelButton** pws = m_vectorMenuList.data();
    ConfigFavoriteButton** fpws = m_vectorFavorMenuList.data();

    ConfigPanelButton* pw;
    ConfigPanelButton *pcb;

    ConfigFavoriteButton* fpw;
    ConfigFavoriteButton* fpcb;

    uint32_t idx;

    int i = 0;

    Config* cfg = Config::getInstance();
    QString strtemp="";
    for(i = 0; i < m_vectorMenuList.count();i++){
        pw = pws[i];
        ui->scrollAreaMenuLayout->removeWidget(pw);
        delete pw;
    }
    m_vectorMenuList.clear();

    for(i=0;i<m_vectorFavorMenuList.count();i++){
        fpw = fpws[i];
        ui->scrollAreaMenuLayout->removeWidget(fpw);
        delete fpw;
    }
    m_vectorFavorMenuList.clear();

    if(m_nCurConfigPos != config_menu_favorite){
        for(i=0 ; i < m_arrMaxMenuCount[m_nCurConfigPos] ;i++){
            pcb = new ConfigPanelButton(this,m_arrConfigListInfos[m_nCurConfigPos][i]);
            qDebug() <<m_arrConfigListInfos[m_nCurConfigPos][i] << cfg->getTitleString(m_arrConfigListInfos[m_nCurConfigPos][i]);
            strtemp = cfg->getTitleString(m_arrConfigListInfos[m_nCurConfigPos][i]);
            pcb->setText(strtemp);
            strtemp = cfg->getValueString(m_arrConfigListInfos[m_nCurConfigPos][i]);
            pcb->setValue(strtemp);
            pcb->showFavoriteButton();
            pcb->setFavoriteCheck(cfg->isFavorite(m_arrConfigListInfos[m_nCurConfigPos][i]));
            ui->scrollAreaMenuLayout->addWidget(pcb);
            m_vectorMenuList.append(pcb);
            connect(pcb ,SIGNAL(clicked(uint16_t)),SLOT(onConfigBtnClicked(uint16_t)));
            connect(pcb,SIGNAL(checkButtonClicked(uint16_t,bool)),SLOT(onConfigCheckBtnClicked(uint16_t,bool)));
        }
    }
    else{
        QList<uint32_t> list = cfg->getConstSortedFavorite();
        for(i=0;i <  list.count();i++){
            idx = list[i];
            fpcb = new ConfigFavoriteButton(this,idx);
            strtemp = cfg->getTitleString((ConfigType)idx);
            fpcb->setText(strtemp);
            ui->scrollAreaMenuLayout->addWidget(fpcb);
            m_vectorFavorMenuList.append(fpcb);
            connect(fpcb,SIGNAL(clicked(uint16_t)),SLOT(onConfigBtnClicked(uint16_t)));
            connect(fpcb,SIGNAL(delBtnClicked(uint16_t)),SLOT(onDeleteFavoriteBtnClicked(uint16_t)));
        }
    }

    ui->scrollAreaMenu->adjustSize(); //Display 전 Contents 사이즈 수정 깜빡임 제거함.

}

void ConfigWindow::on_pushButton_7_clicked() //음향 관리
{
    if(m_nCurConfigPos != config_menu_sound){
        m_nCurConfigPos = config_menu_sound;
        reloadUi();
    }
}

void ConfigWindow::on_pushButton_2_clicked()
{
    if(m_nCurConfigPos != config_menu_system){
        m_nCurConfigPos = config_menu_system;
        reloadUi();
    }
}

void ConfigWindow::on_pushButton_4_clicked()
{
    if(m_nCurConfigPos != config_menu_energy){
        m_nCurConfigPos = config_menu_energy;
        reloadUi();
    }
}

void ConfigWindow::on_pushButton_5_clicked()
{
    if(m_nCurConfigPos != config_menu_expert){
        m_nCurConfigPos = config_menu_expert;
        reloadUi();
    }
}

void ConfigWindow::onDeleteFavoriteBtnClicked(uint16_t id){
    Config* cfg = Config::getInstance();
    ConfigFavoriteButton* btn;
    for(int i = 0;i<m_vectorFavorMenuList.count();i++){
        if(m_vectorFavorMenuList[i]->getBtnId() == id){
            btn = m_vectorFavorMenuList[i];
            ui->scrollAreaMenuLayout->removeWidget(btn);
            m_vectorFavorMenuList.remove(i);
            delete btn;
            cfg->removeFavorite((ConfigType)id);
        }
    }
}