#include "config.h" #include "confighalfenergydlg.h" #include "ui_confighalfenergydlg.h" #include "soundplayer.h" using namespace Define; ConfigHalfEnergyDlg::ConfigHalfEnergyDlg(QWidget *parent) : QDialog(parent), ui(new Ui::ConfigHalfEnergyDlg) { Config* cfg = Config::getInstance(); config_item item; item = cfg->getConfigValue(config_set_half_energy); m_nCurSel = item.d32; ui->setupUi(this); this->setWindowFlags( Qt::FramelessWindowHint); this->setAttribute( Qt::WA_DeleteOnClose); foreach (QPushButton *button, findChildren()) connect(button, &QPushButton::pressed, SoundPlayer::playClick); ui->pushButton_1->setText(tr(on_off_menu[0])); ui->pushButton_2->setText(tr(on_off_menu[1])); reloadUi(); m_pSignalMapper = new QSignalMapper(this); m_pSignalMapper->setMapping(ui->pushButton_1,0); m_pSignalMapper->setMapping(ui->pushButton_2,1); connect(ui->pushButton_1,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map())); connect(ui->pushButton_2,SIGNAL(clicked(bool)),m_pSignalMapper,SLOT(map())); connect(m_pSignalMapper,SIGNAL(mapped(int)),this,SLOT(onConfigBtnClicked(int))); } ConfigHalfEnergyDlg::~ConfigHalfEnergyDlg() { delete ui; } void ConfigHalfEnergyDlg::on_ctrBtnOk_clicked() { Config* cfg = Config::getInstance(); config_item item; item.d32 = m_nCurSel; cfg->setConfigValue(config_set_half_energy,item); accept(); } void ConfigHalfEnergyDlg::onConfigBtnClicked(const int sel){ m_nCurSel = sel; } void ConfigHalfEnergyDlg::on_ctrBtnCancel_clicked() { reject(); } void ConfigHalfEnergyDlg::reloadUi(){ switch(m_nCurSel){ case 0: ui->pushButton_1->setChecked(true); break; case 1: ui->pushButton_2->setChecked(true); break; default: break; } }