configmastervolumedlg.cpp 4.47 KB

#include "configmastervolumedlg.h"
#include "ui_configmastervolumedlg.h"

#include "soundplayer.h"

using namespace Define;

#define MAX_VOL  7

ConfigVolumeDlg::ConfigVolumeDlg(QWidget *parent, ConfigType type) :
    QDialog(parent),
    ui(new Ui::ConfigMasterVolumeDlg)
{
    Config* cfg = Config::getInstance();
    config_item item;
    ui->setupUi(this);
    this->setWindowFlags( Qt::FramelessWindowHint);
    this->setAttribute( Qt::WA_DeleteOnClose);
    qApp->setActiveWindow(this);
    this->setFocus();


    connect(ui->ctrBtnOk, &QPushButton::pressed, SoundPlayer::playClick);
    connect(ui->ctrBtnCancel, &QPushButton::pressed, SoundPlayer::playClick);


   if(type == config_keypad_sound2){
    ui->ctrLbTitle->setText(tr("키패드 볼륨"));
   }

    m_cfgType = type;

    item = cfg->getConfigValue(m_cfgType);
    m_nPrevVol = m_nCurVol = item.d32;
    ui->ctrProgressLight->setMaxProgress(m_nCurVol,MAX_VOL);

    m_vectorTabOrder.append(this);
    m_vectorTabOrder.append(ui->ctrBtnMinus);
    m_vectorTabOrder.append(ui->ctrBtnPlus);
    m_vectorTabOrder.append(ui->ctrBtnOk);
    m_vectorTabOrder.append(ui->ctrBtnCancel);
}

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

void ConfigVolumeDlg::on_ctrBtnOk_clicked()
{
    accept();
}

void ConfigVolumeDlg::on_ctrBtnCancel_clicked()
{
    Config* cfg = Config::getInstance();
    config_item item;
    item.d32 = m_nPrevVol;
    cfg->setConfigValue(m_cfgType,item);
    reject();
}

void ConfigVolumeDlg::on_ctrBtnMinus_clicked()
{
    Config* cfg = Config::getInstance();
    config_item item;
    m_nCurVol = m_nCurVol > 0?m_nCurVol-1:0;
    item.d32 = m_nCurVol;
    cfg->setConfigValue(m_cfgType,item);
    ui->ctrProgressLight->setCurrentProgress(m_nCurVol);

    SoundPlayer::playClick();
}

void ConfigVolumeDlg::on_ctrBtnPlus_clicked()
{
    Config* cfg = Config::getInstance();
    config_item item;
    m_nCurVol = m_nCurVol<MAX_VOL?m_nCurVol+1:MAX_VOL;
    item.d32 = m_nCurVol;
    cfg->setConfigValue(m_cfgType,item);
    ui->ctrProgressLight->setCurrentProgress(m_nCurVol);

    SoundPlayer::playClick();
}

void ConfigVolumeDlg::keyPressEvent(QKeyEvent *event){
    int i = 0;
    switch (event->key())
    {
    case 0x01000032:    // Turn left
        for(i = 0; i < m_vectorTabOrder.size();i++){
            if(focusWidget() == m_vectorTabOrder[i]) break;
        }

        if(i==0){
            i = m_vectorTabOrder.size()-1;
            m_vectorTabOrder[i]->setFocus();
        }
        else if(i < m_vectorTabOrder.size()) {
            i = i - 1;
            m_vectorTabOrder[i]->setFocus();
        }
        else{
            i=0;
            m_vectorTabOrder[i]->setFocus();
        }
        break;
    case 0x01000031:    // Push

        break;
    case 0x01000030:    // Turn right
        for(i = 0; i < m_vectorTabOrder.size();i++){
            if(focusWidget() == m_vectorTabOrder[i]) break;
        }

        if(i<m_vectorTabOrder.size()-1){
            i+=1;
            m_vectorTabOrder[i]->setFocus();
        }
        else if(i== (m_vectorTabOrder.size()-1)){
            i=0;
            m_vectorTabOrder[i]->setFocus();
        }
        else{
            i=0;
            m_vectorTabOrder[i]->setFocus();
        }
        break;
    }
}

void ConfigVolumeDlg::keyReleaseEvent(QKeyEvent *event){
    int i = 0;
    switch (event->key())
    {
    case 0x01000032:    // Turn left
        for(i = 0; i < m_vectorTabOrder.size();i++){
            if(focusWidget() == m_vectorTabOrder[i]) break;
        }

        if(i==0){
            i = m_vectorTabOrder.size()-1;
            m_vectorTabOrder[i]->setFocus();
        }
        else if(i < m_vectorTabOrder.size()) {
            i = i - 1;
            m_vectorTabOrder[i]->setFocus();
        }
        else{
            i=0;
            m_vectorTabOrder[i]->setFocus();
        }
        break;
    case 0x01000031:    // Push
    {
        QPushButton *btn = qobject_cast<QPushButton*>(focusWidget());
        if(btn != NULL){
            btn->click();
        }
        break;
    }
    case 0x01000030:    // Turn right
        for(i = 0; i < m_vectorTabOrder.size();i++){
            if(focusWidget() == m_vectorTabOrder[i]) break;
        }

        if(i<m_vectorTabOrder.size()-1){
            i+=1;
            m_vectorTabOrder[i]->setFocus();
        }
        else if(i== (m_vectorTabOrder.size()-1)){
            i=0;
            m_vectorTabOrder[i]->setFocus();
        }
        else{
            i=0;
            m_vectorTabOrder[i]->setFocus();
        }
        break;
    }
}