#include #include "configipdlg.h" #include "ui_configipdlg.h" #include "config.h" #include "soundplayer.h" using namespace Define; ConfigIpDlg::ConfigIpDlg(QWidget *parent) : QDialog(parent), ui(new Ui::ConfigIpDlg) { ui->setupUi(this); setWindowFlags(Qt::FramelessWindowHint); setAttribute(Qt::WA_NoSystemBackground); setAttribute(Qt::WA_TranslucentBackground); qApp->setActiveWindow(this); this->setFocus(); foreach (QPushButton *button, findChildren()) connect(button, &QPushButton::pressed, SoundPlayer::playClick); ui->ctrGw_0->setFormatterWidth(3); ui->ctrGw_1->setFormatterWidth(3); ui->ctrGw_2->setFormatterWidth(3); ui->ctrGw_3->setFormatterWidth(3); ui->ctrIp_0->setFormatterWidth(3); ui->ctrIp_1->setFormatterWidth(3); ui->ctrIp_2->setFormatterWidth(3); ui->ctrIp_3->setFormatterWidth(3); ui->ctrNetmask_0->setFormatterWidth(3); ui->ctrNetmask_1->setFormatterWidth(3); ui->ctrNetmask_2->setFormatterWidth(3); ui->ctrNetmask_3->setFormatterWidth(3); Config* cfg = Config::getInstance(); config_item temp; temp = cfg->getConfigValue(config_ip); ui->ctrIp_0->setValue(temp.d8.d8_0); ui->ctrIp_1->setValue(temp.d8.d8_1); ui->ctrIp_2->setValue(temp.d8.d8_2); ui->ctrIp_3->setValue(temp.d8.d8_3); temp = cfg->getConfigValue(config_gateway); ui->ctrGw_0->setValue(temp.d8.d8_0); ui->ctrGw_1->setValue(temp.d8.d8_1); ui->ctrGw_2->setValue(temp.d8.d8_2); ui->ctrGw_3->setValue(temp.d8.d8_3); temp = cfg->getConfigValue(config_netmask); ui->ctrNetmask_0->setValue(temp.d8.d8_0); ui->ctrNetmask_1->setValue(temp.d8.d8_1); ui->ctrNetmask_2->setValue(temp.d8.d8_2); ui->ctrNetmask_3->setValue(temp.d8.d8_3); connect(ui->keyboardwidget, SIGNAL(onOkKeyClicked()), this, SLOT(keyEnter_clicked())); connect(ui->keyboardwidget, SIGNAL(onCancelKeyClicked()), this, SLOT(keyCancel_clicked())); m_pSignalMapper = new QSignalMapper(this); m_pSignalMapper->setMapping(ui->ctrIp_0,ui->ctrIp_0); m_pSignalMapper->setMapping(ui->ctrIp_1,ui->ctrIp_1); m_pSignalMapper->setMapping(ui->ctrIp_2,ui->ctrIp_2); m_pSignalMapper->setMapping(ui->ctrIp_3,ui->ctrIp_3); m_pSignalMapper->setMapping(ui->ctrGw_0,ui->ctrGw_0); m_pSignalMapper->setMapping(ui->ctrGw_1,ui->ctrGw_1); m_pSignalMapper->setMapping(ui->ctrGw_2,ui->ctrGw_2); m_pSignalMapper->setMapping(ui->ctrGw_3,ui->ctrGw_3); m_pSignalMapper->setMapping(ui->ctrNetmask_0,ui->ctrNetmask_0); m_pSignalMapper->setMapping(ui->ctrNetmask_1,ui->ctrNetmask_1); m_pSignalMapper->setMapping(ui->ctrNetmask_2,ui->ctrNetmask_2); m_pSignalMapper->setMapping(ui->ctrNetmask_3,ui->ctrNetmask_3); connect(ui->ctrGw_0,SIGNAL(focusInEdit()),m_pSignalMapper, SLOT(map())); connect(ui->ctrGw_1,SIGNAL(focusInEdit()),m_pSignalMapper, SLOT(map())); connect(ui->ctrGw_2,SIGNAL(focusInEdit()),m_pSignalMapper, SLOT(map())); connect(ui->ctrGw_3,SIGNAL(focusInEdit()),m_pSignalMapper, SLOT(map())); connect(ui->ctrIp_0,SIGNAL(focusInEdit()),m_pSignalMapper, SLOT(map())); connect(ui->ctrIp_1,SIGNAL(focusInEdit()),m_pSignalMapper, SLOT(map())); connect(ui->ctrIp_2,SIGNAL(focusInEdit()),m_pSignalMapper, SLOT(map())); connect(ui->ctrIp_3,SIGNAL(focusInEdit()),m_pSignalMapper, SLOT(map())); connect(ui->ctrNetmask_0,SIGNAL(focusInEdit()),m_pSignalMapper, SLOT(map())); connect(ui->ctrNetmask_1,SIGNAL(focusInEdit()),m_pSignalMapper, SLOT(map())); connect(ui->ctrNetmask_2,SIGNAL(focusInEdit()),m_pSignalMapper, SLOT(map())); connect(ui->ctrNetmask_3,SIGNAL(focusInEdit()),m_pSignalMapper, SLOT(map())); connect(m_pSignalMapper, SIGNAL(mapped(QWidget*)), this, SLOT(focusInSpinBox(QWidget*))); } ConfigIpDlg::~ConfigIpDlg() { delete ui; } void ConfigIpDlg::on_ctrBtnOk_clicked() { Config* cfg = Config::getInstance(); config_item temp; temp.d8.d8_0 = (uint8_t)ui->ctrIp_0->value(); temp.d8.d8_1 = (uint8_t)ui->ctrIp_1->value(); temp.d8.d8_2 = (uint8_t)ui->ctrIp_2->value(); temp.d8.d8_3 = (uint8_t)ui->ctrIp_3->value(); cfg->setConfigValue(config_ip, temp); temp.d8.d8_0 = (uint8_t)ui->ctrGw_0->value(); temp.d8.d8_1 = (uint8_t)ui->ctrGw_1->value(); temp.d8.d8_2 = (uint8_t)ui->ctrGw_2->value(); temp.d8.d8_3 = (uint8_t)ui->ctrGw_3->value(); cfg->setConfigValue(config_gateway, temp); temp.d8.d8_0 = (uint8_t)ui->ctrNetmask_0->value(); temp.d8.d8_1 = (uint8_t)ui->ctrNetmask_1->value(); temp.d8.d8_2 = (uint8_t)ui->ctrNetmask_2->value(); temp.d8.d8_3 = (uint8_t)ui->ctrNetmask_3->value(); cfg->setConfigValue(config_netmask, temp); accept(); } void ConfigIpDlg::on_ctrBtnCancel_clicked() { reject(); } void ConfigIpDlg::focusInSpinBox(QWidget *widget){ QSpinBox *spbx = qobject_cast(widget); if(spbx != NULL){ m_nFocusValue = spbx->value(); } } void ConfigIpDlg::keyPressEvent(QKeyEvent *event){ switch (event->key()) { case 0x01000032: // Turn left if(focusWidget() == ui->ctrIp_0) ui->ctrBtnCancel->setFocus(); else focusPreviousChild(); break; case 0x01000031: // Push break; case 0x01000030: // Turn right if(focusWidget() == ui->ctrBtnCancel) ui->ctrIp_0->setFocus(); else focusNextChild(); break; } } void ConfigIpDlg::keyReleaseEvent(QKeyEvent *event){ switch (event->key()) { case 0x01000032: // Turn left if(focusWidget() == ui->ctrIp_0) 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) ui->keyboardwidget->focusInKeyboard(); } break; } case 0x01000030: // Turn right if(focusWidget() == ui->ctrBtnCancel) ui->ctrIp_0->setFocus(); else focusNextChild(); break; } } void ConfigIpDlg::keyCancel_clicked(){ QSpinBox *spbx = qobject_cast(focusWidget()); if(spbx != NULL){ spbx->setValue(m_nFocusValue); } ui->keyboardwidget->focusOutKeyboard(); } void ConfigIpDlg::keyEnter_clicked(){ ui->keyboardwidget->focusOutKeyboard(); }