#include #include "config1digitsetandenablesetdlg.h" #include "ui_config1digitsetandenablesetdlg.h" #include "soundplayer.h" Config1DigitSetAndEnableSetDlg::Config1DigitSetAndEnableSetDlg(QWidget *parent, uint16_t val) : QDialog(parent), ui(new Ui::Config1DigitSetAndEnableSetDlg) { ui->setupUi(this); this->setWindowFlags(Qt::FramelessWindowHint); foreach (QPushButton *button, findChildren()) connect(button, &QPushButton::pressed, SoundPlayer::playClick); if(val < MIN_MONITORING_VALUE) val = MIN_MONITORING_VALUE; ui->ctrSpBxValue->setMaximum(MAX_MONITORING_VALUE); ui->ctrSpBxValue->setMinimum(MIN_MONITORING_VALUE); ui->ctrSpBxValue->setValue(val); ui->ctrSpBxValue->installEventFilter(this); connect(ui->keyboardwidget, SIGNAL(onOkKeyClicked()), this, SLOT(keyEnter_clicked())); connect(ui->keyboardwidget, SIGNAL(onCancelKeyClicked()), this, SLOT(keyCancel_clicked())); } Config1DigitSetAndEnableSetDlg::~Config1DigitSetAndEnableSetDlg() { delete ui; } void Config1DigitSetAndEnableSetDlg::on_ctrBtnOk_clicked() { m_nResult = result_ok; close(); } void Config1DigitSetAndEnableSetDlg::on_ctrBtnOk_2_clicked() { m_nResult = result_disable; close(); } void Config1DigitSetAndEnableSetDlg::on_ctrBtnCancel_clicked() { m_nResult = result_rejected; close(); } void Config1DigitSetAndEnableSetDlg::keyCancel_clicked() { if(focusWidget() == ui->ctrSpBxValue) ui->ctrSpBxValue->setValue(m_nPrevValue); ui->keyboardwidget->focusOutKeyboard(); } void Config1DigitSetAndEnableSetDlg::keyEnter_clicked() { ui->keyboardwidget->focusOutKeyboard(); } int Config1DigitSetAndEnableSetDlg::getValue(){ return ui->ctrSpBxValue->value(); } void Config1DigitSetAndEnableSetDlg::keyPressEvent(QKeyEvent *event){ switch (event->key()) { case 0x01000032: // Turn left if(focusWidget() == ui->ctrSpBxValue) ui->ctrBtnCancel->setFocus(); else focusPreviousChild(); break; case 0x01000031: // Push break; case 0x01000030: // Turn right if(focusWidget() == ui->ctrBtnCancel) ui->ctrSpBxValue->setFocus(); else focusNextChild(); break; } } void Config1DigitSetAndEnableSetDlg::keyReleaseEvent(QKeyEvent *event){ switch (event->key()) { case 0x01000032: // Turn left if(focusWidget() == ui->ctrSpBxValue) ui->ctrBtnCancel->setFocus(); else focusPreviousChild(); break; case 0x01000031: // Push { QPushButton *btn = qobject_cast(focusWidget()); if(btn != NULL){ btn->click(); } else{ QSpinBox *spbx = qobject_cast(focusWidget()); if(spbx != NULL) { m_nPrevValue = spbx->value(); ui->keyboardwidget->focusInKeyboard(); } } break; } case 0x01000030: // Turn right if(focusWidget() == ui->ctrBtnCancel) ui->ctrSpBxValue->setFocus(); else focusNextChild(); break; } }