#include "servicepassinputdlg.h" #include "ui_servicepassinputdlg.h" #include "engineermenuwindow.h" #include #include "soundplayer.h" ServicePassInputDlg::ServicePassInputDlg(QWidget *parent) : QDialog(parent), ui(new Ui::ServicePassInputDlg) { ui->setupUi(this); setWindowFlags(Qt::FramelessWindowHint); setAttribute(Qt::WA_NoSystemBackground); setAttribute(Qt::WA_TranslucentBackground); setAttribute(Qt::WA_DeleteOnClose); qApp->setActiveWindow(this); ui->ctrProgressBar->setFocus(); this->setResult(QDialog::Accepted); foreach (QPushButton *button, findChildren()) connect(button, &QPushButton::pressed, SoundPlayer::playClick); ui->ctrProgressBar->setMaxProgress(0,MAX_PASSWORD); m_nCurInputCount = 0; memset(m_strInputPass, 0x00, MAX_PASSWORD+1); connect(ui->keyboardwidget,SIGNAL(onBackspaceKeyClicked()), SLOT(backspaceKeyPressEvent())); connect(ui->keyboardwidget, SIGNAL(onOkKeyClicked()), SLOT(keyEnter_clicked())); connect(ui->keyboardwidget, SIGNAL(onCancelKeyClicked()),SLOT(keyCancel_clicked())); connect(ui->keyboardwidget,SIGNAL(onKeyboardClickSignal(QString)),SLOT(keyboardInputEvent(QString))); ui->keyboardwidget->focusInKeyboard(); } ServicePassInputDlg::~ServicePassInputDlg() { delete ui; } void ServicePassInputDlg::on_ctrBtnOk_clicked() { if( QString(m_strInputPass) == QString(PASS_WORD)){ qDebug() << this->parentWidget() <parent(); EngineerMenuWindow *w = new EngineerMenuWindow(this->parentWidget()); connect(w,SIGNAL(destroyed(QObject*)),this,SLOT(close())); w->setWindowModality(Qt::WindowModal); w->show(); this->hide(); } else { reject(); } } void ServicePassInputDlg::on_ctrBtnCancel_clicked() { reject(); } void ServicePassInputDlg::backspaceKeyPressEvent(){ if(m_nCurInputCount>0) m_nCurInputCount--; m_strInputPass[m_nCurInputCount] = 0; qDebug() <<"back space input" << QString(m_strInputPass); ui->ctrProgressBar->setCurrentProgress(m_nCurInputCount); } void ServicePassInputDlg::keyboardInputEvent(QString strIn){ if(m_nCurInputCount < MAX_PASSWORD){ const QChar* in = strIn.constData(); m_strInputPass[m_nCurInputCount++] = in[0]; qDebug() <<"input event" << QString(m_strInputPass); ui->ctrProgressBar->setCurrentProgress(m_nCurInputCount); } } void ServicePassInputDlg::keyPressEvent(QKeyEvent *event){ int i = 0; switch (event->key()) { case 0x01000030: // Turn left if(focusWidget() == ui->ctrProgressBar) ui->ctrBtnCancel->setFocus(); else focusPreviousChild(); break; case 0x01000031: // Push break; case 0x01000032: // Turn right if(focusWidget() == ui->ctrBtnCancel) ui->ctrProgressBar->setFocus(); else focusNextChild(); break; } } void ServicePassInputDlg::keyReleaseEvent(QKeyEvent *event){ int i = 0; switch (event->key()) { case 0x01000030: // Turn left if(focusWidget() == ui->ctrProgressBar) ui->ctrBtnCancel->setFocus(); else focusPreviousChild(); break; case 0x01000031: // Push { QPushButton *btn = qobject_cast(focusWidget()); if(btn != NULL){ btn->click(); } else{ ui->keyboardwidget->focusInKeyboard(); } break; } case 0x01000032: // Turn right if(focusWidget() == ui->ctrBtnCancel) ui->ctrProgressBar->setFocus(); else focusNextChild(); break; } } void ServicePassInputDlg::keyCancel_clicked(){ ui->ctrBtnCancel->click(); } void ServicePassInputDlg::keyEnter_clicked(){ ui->ctrBtnOk->click(); }