configlanguagedlg.cpp 2.05 KB
#include "config.h"
#include "configlanguagedlg.h"
#include "ui_configlanguagedlg.h"
#include "soundplayer.h"

using namespace Define;

ConfigLanguageDlg::ConfigLanguageDlg(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::ConfigLanguageDlg)
{
    ui->setupUi(this);
    this->setWindowFlags( Qt::FramelessWindowHint);
    this->setAttribute( Qt::WA_DeleteOnClose);

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



    ui->pushButton_1->setText(tr(language_menu[0]));
    ui->pushButton_2->setText(tr(language_menu[1]));
    ui->pushButton_3->setText(tr(language_menu[2]));

    Config *cfg = Config::getInstance();
    config_item item;
    cfg->getConfigValue(config_language);
    m_nCurSelLang = item.d32;

    m_pSignalMapper = new QSignalMapper(this);
    m_pSignalMapper->setMapping(ui->pushButton_1,0);
    m_pSignalMapper->setMapping(ui->pushButton_2,1);
    m_pSignalMapper->setMapping(ui->pushButton_3,2);

    connect(ui->pushButton_1,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
    connect(ui->pushButton_2,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));
    connect(ui->pushButton_3,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map()));

    connect(m_pSignalMapper,SIGNAL(mapped(int)),this,SLOT(onConfigBtnClicked(int)));

}

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

void ConfigLanguageDlg::on_ctrBtnOk_clicked()
{
    Config* cfg = Config::getInstance();
    config_item item;
    item.d32 = m_nCurSelLang;
    cfg->setConfigValue(config_language, item);
    this->accept();
}

void ConfigLanguageDlg::on_ctrBtnCancel_clicked()
{
    this->reject();
}

void ConfigLanguageDlg::onConfigBtnClicked(const int sel){
          m_nCurSelLang = sel;
}

void ConfigLanguageDlg::reloadUi(){
    switch(m_nCurSelLang){
    case 0:
        ui->pushButton_1->setChecked(true);
        break;
   case 1:
        ui->pushButton_2->setChecked(true);
        break;
    case 2:
        ui->pushButton_3->setChecked(true);
        break;
    default:
        break;
    }
}