servicepassinputdlg.cpp
4.62 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include "servicepassinputdlg.h"
#include "ui_servicepassinputdlg.h"
#include "engineermenuwindow.h"
#include <QDebug>
#include "soundplayer.h"
#include "udphandler.h"
#include "mainwindow.h"
ServicePassInputDlg::ServicePassInputDlg(QWidget *parent, service_pass_type mode, bool sendClrCmd) :
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<QPushButton *>())
// connect(button, &QPushButton::pressed, SoundPlayer::playClick);
connect(ui->ctrBtnOk, &QPushButton::pressed, SoundPlayer::playClick);
connect(ui->ctrBtnCancel, &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();
m_nMode = mode;
m_bSendClrCmd = sendClrCmd;
qDebug() << __func__;
}
ServicePassInputDlg::~ServicePassInputDlg()
{
qDebug() << __func__;
delete ui;
}
void ServicePassInputDlg::on_ctrBtnOk_clicked()
{
if( QString(m_strInputPass) == QString(NORMAL_PASS_WORD) && m_nMode == NORMAL_SERVICE_PASS_MODE){
qDebug() << this->parentWidget() <<this->parent();
if(m_bSendClrCmd) UdpHandler::getInstance()->set(TG_ERROR_CLEAR,0xCECE);
if(MainWindow::getEngineerMenuWindow()==NULL){
EngineerMenuWindow *w = new EngineerMenuWindow(this->parentWidget());
w->setWindowModality(Qt::WindowModal);
w->showFullScreen();
w->raise();
hide();
deleteLater();
}
else{
EngineerMenuWindow *w = MainWindow::getEngineerMenuWindow();
w->killChild();
w->raise();
hide();
deleteLater();
}
//connect(w,SIGNAL(destroyed(QObject*)),this,SLOT(close()));
}
else if(QString(m_strInputPass) == QString(DEMO_PASS_WORD) && m_nMode == DEMO_SERVICE_PASS_MODE){
accept();
}
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){
switch (event->key())
{
case 0x01000032: // Turn left
if(focusWidget() == ui->ctrProgressBar) ui->ctrBtnCancel->setFocus();
else focusPreviousChild();
break;
case 0x01000031: // Push
break;
case 0x01000030: // Turn right
if(focusWidget() == ui->ctrBtnCancel) ui->ctrProgressBar->setFocus();
else focusNextChild();
break;
}
}
void ServicePassInputDlg::keyReleaseEvent(QKeyEvent *event){
switch (event->key())
{
case 0x01000032: // Turn left
if(focusWidget() == ui->ctrProgressBar) ui->ctrBtnCancel->setFocus();
else focusPreviousChild();
break;
case 0x01000031: // Push
{
QPushButton *btn = qobject_cast<QPushButton*>(focusWidget());
if(btn != NULL){
btn->click();
}
else{
ui->keyboardwidget->focusInKeyboard();
}
break;
}
case 0x01000030: // 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();
}