servicepassinputdlg.cpp
2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "servicepassinputdlg.h"
#include "ui_servicepassinputdlg.h"
#include "engineermenuwindow.h"
#include <QDebug>
#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);
this->setResult(QDialog::Accepted);
foreach (QPushButton *button, findChildren<QPushButton *>())
connect(button, &QPushButton::pressed, SoundPlayer::playClick);
ui->ctrProgressBar->setMaxProgress(0,4);
m_nCurInputCount = 0;
this->setFocus();
memset(m_strInputPass, 0x00, MAX_PASSWORD+1);
}
ServicePassInputDlg::~ServicePassInputDlg()
{
delete ui;
}
void ServicePassInputDlg::on_ctrBtnOk_clicked()
{
if( QString(m_strInputPass) == QString(PASS_WORD)){
qDebug() << this->parentWidget() <<this->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::keyPressEvent(QKeyEvent *event){
if(event->key() == Qt::Key_Backspace){
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::inputMethodEvent(QInputMethodEvent *event){
if(m_nCurInputCount < MAX_PASSWORD){
if(!event->commitString().isEmpty()){
const QChar* in = event->commitString().constData();
m_strInputPass[m_nCurInputCount++] = in[0];
qDebug() <<"input event" << QString(m_strInputPass);
ui->ctrProgressBar->setCurrentProgress(m_nCurInputCount);
}
}
}