#include "configbacklightdlg.h" #include "ui_configbacklightdlg.h" #include "config.h" #include "soundplayer.h" #include "backlight.h" using namespace Define; #define MAX_LIGHT 7 #define MIN_LIGHT 0 ConfigBackLightDlg::ConfigBackLightDlg(QWidget *parent) : QDialog(parent), ui(new Ui::ConfigBackLightDlg) { Config* cfg = Config::getInstance(); Define::config_item item; ui->setupUi(this); this->setWindowFlags( Qt::FramelessWindowHint); this->setAttribute( Qt::WA_DeleteOnClose); qApp->setActiveWindow(this); this->setFocus(); foreach (QPushButton *button, findChildren()) connect(button, &QPushButton::pressed, SoundPlayer::playClick); showFullScreen(); item = cfg->getConfigValue(config_backlight); m_nSelBackLight = item.d32; ui->ctrProgressLight->setMaxProgress(0,MAX_LIGHT); ui->ctrProgressLight->setCurrentProgress(m_nSelBackLight); m_vectorTabOrder.append(this); m_vectorTabOrder.append(ui->ctrBtnPlus); m_vectorTabOrder.append(ui->ctrBtnMinus); m_vectorTabOrder.append(ui->ctrBtnOk); m_vectorTabOrder.append(ui->ctrBtnCancel); } ConfigBackLightDlg::~ConfigBackLightDlg() { delete ui; } void ConfigBackLightDlg::on_ctrBtnOk_clicked() { Config* cfg = Config::getInstance(); config_item item; item.d32 = m_nSelBackLight; cfg->setConfigValue(config_backlight,item); accept(); } void ConfigBackLightDlg::on_ctrBtnCancel_clicked() { Config* cfg = Config::getInstance(); config_item item; item = cfg->getConfigValue(config_backlight); Backlight::set(item.d32); reject(); } void ConfigBackLightDlg::on_pushButton_clicked() { } void ConfigBackLightDlg::on_ctrBtnPlus_clicked() { //minus button; m_nSelBackLight = m_nSelBackLight>0?m_nSelBackLight-1:0; ui->ctrProgressLight->setCurrentProgress(m_nSelBackLight); Backlight::set(m_nSelBackLight); } void ConfigBackLightDlg::on_ctrBtnMinus_clicked() { m_nSelBackLight = m_nSelBackLight<7?m_nSelBackLight+1:7; ui->ctrProgressLight->setCurrentProgress(m_nSelBackLight); Backlight::set(m_nSelBackLight); } void ConfigBackLightDlg::keyPressEvent(QKeyEvent *event){ int i = 0; switch (event->key()) { case 0x01000030: // 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 0x01000032: // Turn right for(i = 0; i < m_vectorTabOrder.size();i++){ if(focusWidget() == m_vectorTabOrder[i]) break; } if(isetFocus(); } else if(i== (m_vectorTabOrder.size()-1)){ i=0; m_vectorTabOrder[i]->setFocus(); } else{ i=0; m_vectorTabOrder[i]->setFocus(); } break; } } void ConfigBackLightDlg::keyReleaseEvent(QKeyEvent *event){ int i = 0; switch (event->key()) { case 0x01000030: // 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(focusWidget()); if(btn != NULL){ btn->click(); } break; } case 0x01000032: // Turn right for(i = 0; i < m_vectorTabOrder.size();i++){ if(focusWidget() == m_vectorTabOrder[i]) break; } if(isetFocus(); } else if(i== (m_vectorTabOrder.size()-1)){ i=0; m_vectorTabOrder[i]->setFocus(); } else{ i=0; m_vectorTabOrder[i]->setFocus(); } break; } }