#include "recoUiPassword.h" #include #include const int recoUiPassword::PERSON_NAME_FONT_SIZE[UiConfig::SUPPORT_SCREEN_SIZE_QUANTITY][UiConfig::SUPPORT_LANGUAGE_QUANTITY] = { {24, 20, 14, 15, 12, 15, 14, 13, 9, 12, 10, 13, 13, 9}, {48, 40, 28, 30, 24, 30, 28, 26, 19, 26, 22, 26, 26, 19}, {48, 40, 28, 30, 24, 30, 28, 26, 19, 26, 22, 26, 26, 19}, {16, 16, 10, 12, 10, 12, 11, 10, 8, 10, 9, 10, 10, 8}, {16, 16, 10, 12, 10, 12, 11, 10, 8, 10, 9, 10, 10, 8} }; const int recoUiPassword::WEL_MSG_FONT_SIZE[UiConfig::SUPPORT_SCREEN_SIZE_QUANTITY][UiConfig::SUPPORT_LANGUAGE_QUANTITY] = { {16, 20, 14, 15, 12, 15, 14, 13, 9, 12, 10, 13, 13, 9}, {32, 40, 28, 30, 24, 30, 28, 26, 19, 26, 22, 26, 26, 19}, {32, 40, 28, 30, 24, 30, 28, 26, 19, 26, 22, 26, 26, 19}, {12, 12, 11, 12, 10, 12, 11, 10, 8, 10, 9, 10, 10, 8}, {12, 12, 11, 12, 10, 12, 11, 10, 8, 10, 9, 10, 10, 8} }; const int recoUiPassword::PASSWORD_FONT_SIZE[UiConfig::SUPPORT_SCREEN_SIZE_QUANTITY][UiConfig::SUPPORT_LANGUAGE_QUANTITY] = { {20, 20, 14, 15, 12, 15, 14, 13, 9, 12, 10, 13, 13, 9}, {40, 40, 28, 30, 24, 30, 28, 26, 19, 26, 22, 26, 26, 19}, {40, 40, 28, 30, 24, 30, 28, 26, 19, 26, 22, 26, 26, 19}, {14, 14, 11, 12, 10, 12, 11, 10, 8, 10, 9, 10, 10, 8}, {14, 14, 11, 12, 10, 12, 11, 10, 8, 10, 9, 10, 10, 8} }; const int recoUiPassword::NUM_BTN_FONT_SIZE[UiConfig::SUPPORT_SCREEN_SIZE_QUANTITY][UiConfig::SUPPORT_LANGUAGE_QUANTITY] = { {20, 20, 14, 15, 12, 15, 14, 13, 9, 12, 10, 13, 13, 9}, {40, 40, 28, 30, 24, 30, 28, 26, 19, 26, 22, 26, 26, 19}, {40, 40, 28, 30, 24, 30, 28, 26, 19, 26, 22, 26, 26, 19}, {16, 16, 11, 12, 10, 12, 11, 10, 8, 10, 9, 10, 10, 8}, {16, 16, 11, 12, 10, 12, 11, 10, 8, 10, 9, 10, 10, 8} }; const int recoUiPassword::CONFIRM_BTN_FONT_SIZE[UiConfig::SUPPORT_SCREEN_SIZE_QUANTITY][UiConfig::SUPPORT_LANGUAGE_QUANTITY] = { {20, 20, 14, 15, 12, 15, 14, 13, 9, 12, 10, 13, 13, 9}, {40, 40, 28, 30, 24, 30, 28, 26, 19, 26, 22, 26, 26, 19}, {40, 40, 28, 30, 24, 30, 28, 26, 19, 26, 22, 26, 26, 19}, {14, 14, 10, 11, 9, 11, 10, 9, 7, 9, 8, 9, 9, 7}, {14, 14, 10, 11, 9, 11, 10, 9, 7, 9, 8, 9, 9, 7} }; const QString recoUiPassword::PWD_BG[UiConfig::SUPPORT_SCREEN_SIZE_QUANTITY] = { ":/res/image/pwd_bg_small.jpg", ":/res/image/pwd_bg_large.jpg", ":/res/image/pwd_bg_middle.jpg", ":/res/image/pwd_bg_large.jpg", ":/res/image/pwd_bg_middle.jpg" }; const QString recoUiPassword::CONFIRM_BTN_BG[UiConfig::SUPPORT_SCREEN_SIZE_QUANTITY] = { ":/res/image/pwd_confirm_small.png", ":/res/image/pwd_confirm_large.png", ":/res/image/pwd_confirm_middle.png", ":/res/image/pwd_confirm_large.png", ":/res/image/pwd_confirm_middle.png" }; const QString recoUiPassword::CONFIRM_BTN_DISABLE_BG[UiConfig::SUPPORT_SCREEN_SIZE_QUANTITY] = { ":/res/image/pwd_confirm_small_disable.png", ":/res/image/pwd_confirm_large_disable.png", ":/res/image/pwd_confirm_middle_disable.png", ":/res/image/pwd_confirm_large_disable.png", ":/res/image/pwd_confirm_middle_disable.png" }; const int recoUiPassword::CONFIRM_BTN_W[UiConfig::SUPPORT_SCREEN_SIZE_QUANTITY] = {344, 430, 430, 430, 430}; const int recoUiPassword::CONFIRM_BTN_H[UiConfig::SUPPORT_SCREEN_SIZE_QUANTITY] = {72, 90, 90, 90, 90}; const QString recoUiPassword::BACK_BTN[UiConfig::SUPPORT_SCREEN_SIZE_QUANTITY] = { ":/res/image/pwd_back_small.png", ":/res/image/pwd_back_large.png", ":/res/image/pwd_back_middle.png", ":/res/image/pwd_back_large.png", ":/res/image/pwd_back_middle.png" }; const int recoUiPassword::BACK_BTN_W[UiConfig::SUPPORT_SCREEN_SIZE_QUANTITY] = {20, 24, 24, 24, 24}; const int recoUiPassword::BACK_BTN_H[UiConfig::SUPPORT_SCREEN_SIZE_QUANTITY] = {35, 44, 44, 44, 44}; const QString recoUiPassword::DEL_BTN[UiConfig::SUPPORT_SCREEN_SIZE_QUANTITY] = { ":/res/image/pwd_del_small.png", ":/res/image/pwd_del_large_black.png", ":/res/image/pwd_del_middle.png", ":/res/image/pwd_del_large_black.png", ":/res/image/pwd_del_middle.png" }; const int recoUiPassword::DEL_BTN_W[UiConfig::SUPPORT_SCREEN_SIZE_QUANTITY] = {344, 35, 35, 35, 35}; const int recoUiPassword::DEL_BTN_H[UiConfig::SUPPORT_SCREEN_SIZE_QUANTITY] = {344, 24, 24, 24, 24}; const QString recoUiPassword::NUM_BTN[UiConfig::SUPPORT_SCREEN_SIZE_QUANTITY] = { ":/res/image/num_btn_small.png", ":/res/image/num_btn_large.png", ":/res/image/num_btn_middle.png", ":/res/image/num_btn_large.png", ":/res/image/num_btn_middle.png" }; recoUiPassword::recoUiPassword(QWidget *parent) : WidgetWithBackstageInterface(parent) { qDebug() << "recoUiPassword()"; resize(UiConfig::GetInstance()->getUiWidth(), UiConfig::GetInstance()->getUiHeight()); setAutoFillBackground(true); QPalette palette(this->palette()); palette.setBrush(QPalette::Window,QBrush(QPixmap(PWD_BG[UiConfig::GetInstance()->getScreenConfigIndex()]))); setPalette(palette); const int btnWidth = UiConfig::GetInstance()->getUiWidth() / 5; m_btnBack = new QPushButton(this); setButtonBackImage(m_btnBack, BACK_BTN[UiConfig::GetInstance()->getScreenConfigIndex()], BACK_BTN_W[UiConfig::GetInstance()->getScreenConfigIndex()], BACK_BTN_H[UiConfig::GetInstance()->getScreenConfigIndex()]); m_btnBack->setFixedSize(btnWidth, btnWidth); //m_btnBack->setStyleSheet("QPushButton:focus{outline: none;}"); m_btnBack->setFocusPolicy(Qt::NoFocus); connect(m_btnBack, SIGNAL(clicked()), this, SLOT(slotBtnClicked())); QPalette labelPal; labelPal.setColor(QPalette::Background,QColor(0, 0, 0, 0)); QFont ft; ft.setWeight(ft.weight() * 2 > 99 ? 99 : ft.weight() * 2);//Weight must be between 0 and 99 //ft.setBold(true); m_labelName = new QLabel(this); //m_labelName->setText(tr("某某某")); m_labelName->setPalette(labelPal); ft.setPointSize(PERSON_NAME_FONT_SIZE[UiConfig::GetInstance()->getScreenConfigIndex()][UiConfig::GetInstance()->getLanguageType()]); m_labelName->setFont(ft); m_labelName->hide(); m_labelWelStr = new QLabel(this); m_labelWelStr->setText(tr("欢迎光临")); labelPal.setColor(QPalette::WindowText,QColor(203, 242, 252)); m_labelWelStr->setPalette(labelPal); ft.setPointSize(WEL_MSG_FONT_SIZE[UiConfig::GetInstance()->getScreenConfigIndex()][UiConfig::GetInstance()->getLanguageType()]); m_labelWelStr->setFont(ft); m_labelWelStr->hide(); if(UiConfig::GetInstance()->isRkDevice()){ m_editPwd = new QPasswordLineEdit(this, "."); } else{ m_editPwd = new QPasswordLineEdit(this); } m_editPwd->setReadOnly(true); QPalette lineEditPal; lineEditPal.setColor(QPalette::Text,QColor(255, 255, 255, 255)); m_editPwd->setPalette(lineEditPal); ft.setPointSize(PASSWORD_FONT_SIZE[UiConfig::GetInstance()->getScreenConfigIndex()][UiConfig::GetInstance()->getLanguageType()]); m_editPwd->setFont(ft); m_editPwd->setStyleSheet("background:transparent;border-width:0;border-style:outset"); m_editPwd->setAlignment(Qt::AlignCenter); QPalette btnPal; btnPal.setColor(QPalette::ButtonText,QColor(255, 255, 255, 255)); QGridLayout* glayMid = new QGridLayout(); for(int i=0; isetText(QString::number(i)); m_btnsNum[i]->setPalette(btnPal); ft.setPointSize(NUM_BTN_FONT_SIZE[UiConfig::GetInstance()->getScreenConfigIndex()][UiConfig::GetInstance()->getLanguageType()]); m_btnsNum[i]->setFont(ft); m_btnsNum[i]->setFlat(true); m_btnsNum[i]->setCursor(QCursor(Qt::PointingHandCursor)); m_btnsNum[i]->setFocusPolicy(Qt::NoFocus); m_btnsNum[i]->setFixedSize(btnWidth, btnWidth); m_btnsNum[i]->setStyleSheet("background-color:transparent;border-radius:0px;focus{outline: none;}"); /*const QString numBtnStyle = QString("QPushButton {" "border: 0px;" "background-color:transparent;" "background:url(%1);" "}" "QPushButton:hover { " "border: 0px;" "background:url(%2);" "background-repeat:none;" "background-position:center;" "}" "QPushButton:pressed {" "border: 0px;" "background:url(%3);" "background-repeat:none;" "background-position:center;" //"background-origin: content;" // 设置背景图片基于content,默认是基于border的 //"padding-left: 8px;" //设置content相对于border的偏移,如果此属性要对背景图片生效的话,需要设置上面的属性 "}") .arg(":/res/image/num_btn_large.png") .arg(":/res/image/num_btn_large.png") .arg(":/res/image/num_btn_large.png"); m_btnsNum[i]->setStyleSheet(numBtnStyle); m_btnsNum[i]->setStyleSheet("QPushButton {" "font-size:100px;" "color:yellow; " "border-radius:150px;" //圆角大小,因为矩形的一半为150,所以圆角大小 设置为150以后,将会成为一个原型,小于150,就是圆角矩形了。 "background-color:rgba(0,255,0,200);" //设置按钮背景为绿色 "}" "QPushButton:hover { " "font-size:100px;" "color:green;" "border-radius:150px;" "background-color:rgba(255,255,0,200);" //设置按钮背景为黄色 = 红+绿 "}" "QPushButton:pressed {" "color:orange; " "border-width:3;" "border-radius:150px;" "border-color:orange;" "border-style:solid;" "background-color:cyan;" "}"); */ connect(m_btnsNum[i], SIGNAL(clicked()), this, SLOT(slotBtnClicked())); if(!UiConfig::GetInstance()->isRkDevice()){ connect(m_btnsNum[i], SIGNAL(pressed()), this, SLOT(slotBtnPressed())); connect(m_btnsNum[i], SIGNAL(released()), this, SLOT(slotBtnReleased())); } if(i > 0){ const int pos = i - 1; glayMid->addWidget(m_btnsNum[i], pos / 3, pos % 3); } } m_btnBackspace = new QPushButton(this); setButtonBackImage(m_btnBackspace, DEL_BTN[UiConfig::GetInstance()->getScreenConfigIndex()], DEL_BTN_W[UiConfig::GetInstance()->getScreenConfigIndex()], DEL_BTN_H[UiConfig::GetInstance()->getScreenConfigIndex()]); m_btnBackspace->setFixedSize(btnWidth, btnWidth); connect(m_btnBackspace, SIGNAL(clicked()), this, SLOT(slotBtnClicked())); //m_btnClear = new QPushButton(this); //m_btnClear->setText(tr("清空")); //connect(m_btnClear, SIGNAL(clicked()), this, SLOT(slotBtnClicked())); //glayMid->addWidget(m_btnClear, 3, 0); glayMid->addWidget(m_btnsNum[0], 3, 1); glayMid->addWidget(m_btnBackspace, 3, 2); m_btnConfirm = new QPushButton(this); m_btnConfirm->setText(tr("确认")); m_btnConfirm->setPalette(btnPal); m_btnConfirm->setFlat(true); m_btnConfirm->setCursor(QCursor(Qt::PointingHandCursor)); m_btnConfirm->setFocusPolicy(Qt::NoFocus); m_btnConfirm->setFixedSize(CONFIRM_BTN_W[UiConfig::GetInstance()->getScreenConfigIndex()], UiConfig::GetInstance()->isRkDevice() ? (CONFIRM_BTN_H[UiConfig::GetInstance()->getScreenConfigIndex()] >> 2 << 2) : CONFIRM_BTN_H[UiConfig::GetInstance()->getScreenConfigIndex()]); ft.setWeight(ft.weight() * 2 > 99 ? 99 : ft.weight() * 2);//Weight must be between 0 and 99 ft.setPointSize(CONFIRM_BTN_FONT_SIZE[UiConfig::GetInstance()->getScreenConfigIndex()][UiConfig::GetInstance()->getLanguageType()]); m_btnConfirm->setFont(ft); #if 1 const QString confirmBtnStyle = QString("background-color:transparent;" "color:white;" "border-image: url(%1);" ) .arg(CONFIRM_BTN_BG[UiConfig::GetInstance()->getScreenConfigIndex()]); #else QString confirmBtnStyle = QString("QPushButton{background:url(%1); background-color:transparent;border: none; }" //正常 "QPushButton:hover{background:url(%2); background-color:transparent; }" //滑过 "QPushButton:pressed{background:url(%3); background-color:transparent; }") //按下 .arg(CONFIRM_BTN_BG[UiConfig::GetInstance()->getScreenConfigIndex()]) .arg(CONFIRM_BTN_DISABLE_BG[UiConfig::GetInstance()->getScreenConfigIndex()]) .arg(CONFIRM_BTN_DISABLE_BG[UiConfig::GetInstance()->getScreenConfigIndex()]); #endif //qDebug() << "confirmBtnStyle:" << confirmBtnStyle; m_btnConfirm->setStyleSheet(confirmBtnStyle); connect(m_btnConfirm, SIGNAL(clicked()), this, SLOT(slotBtnClicked())); QVBoxLayout* vlay = new QVBoxLayout(); vlay->addWidget(m_btnBack, 1, Qt::AlignLeft | Qt::AlignTop); vlay->addWidget(m_labelName, 1, Qt::AlignCenter | Qt::AlignTop); vlay->addWidget(m_labelWelStr, 1, Qt::AlignCenter | Qt::AlignTop); vlay->addWidget(m_editPwd, 80, Qt::AlignCenter | Qt::AlignBottom); vlay->addLayout(glayMid); vlay->addWidget(m_btnConfirm, 1, Qt::AlignCenter | Qt::AlignTop); vlay->setContentsMargins(0, 10, 0, (UiConfig::GetInstance()->getUiHeight() / 12) >> 1 << 1); //vlay->setMargin(0); setLayout(vlay); m_timer = new QTimer(this); connect(m_timer, SIGNAL(timeout()), this, SLOT(slotTimeout())); } void recoUiPassword::reset(const QString& name) { m_editPwd->clear(); m_pwd.clear(); m_timeCnt = 0; m_tryTime = 0; m_timer->start(TIMEOUT); m_btnConfirm->setEnabled(false); slotShowPwdUiPersonName(name); //m_backstageIf->pauseDataFlow(); m_backstageIf->stopIdentyState(); m_need2ResetDecisionCenterTimer = !name.isEmpty(); } void recoUiPassword::slotBtnClicked() { qDebug() << "slotBtnClicked"; const QObject* send = sender(); if (send == m_btnConfirm) { m_timeCnt = 0; qDebug() << "password:" << m_pwd; m_backstageIf->sendPassword(m_pwd.toStdString().c_str()); m_editPwd->clear(); m_pwd.clear(); m_btnConfirm->setEnabled(false); m_timer->stop(); m_tryTime++; if(m_tryTime >= TRY_TIME){ emit signalShowRecognizePage(); //m_backstageIf->resumeDataFlow(); } } else if (send == m_btnBackspace) { m_timeCnt = 0; QString text = m_editPwd->text(); if(text.size()){ m_pwd = m_pwd.left(m_pwd.size() - 1); m_editPwd->setText(text.left(text.size() - 1)); m_btnConfirm->setEnabled(m_editPwd->text().length() >= PWD_LEN_MIN); } } //else if (send == m_btnClear) { //m_editPwd->clear(); //} else if (send == m_btnBack) { emit signalShowRecognizePage(); m_timer->stop(); //m_backstageIf->resumeDataFlow(); m_backstageIf->verifyAbort(); } else{ m_timeCnt = 0; if(m_editPwd->text().length() >= PWD_LEN_MAX){ return; } for(int i=0; ihide(); m_labelWelStr->hide(); } m_pwd += m_btnsNum[i]->text(); m_editPwd->setText(m_editPwd->text() + m_btnsNum[i]->text()); m_btnConfirm->setEnabled(m_editPwd->text().length() >= PWD_LEN_MIN); break; } } } if(UiConfig::GetInstance()->isRkDevice()){ update(); } } void recoUiPassword::slotBtnPressed() { const QString numBtnStyle = QString("QPushButton {" "border: 0px;"//"background-color:transparent;" "}" "QPushButton:pressed {" "border: 0px;" "background:url(%1);" "background-repeat:none;" "background-position:center;" "}") .arg(NUM_BTN[UiConfig::GetInstance()->getScreenConfigIndex()]); dynamic_cast(sender())->setStyleSheet(numBtnStyle); } void recoUiPassword::slotBtnReleased() { qDebug() << "slotBtnReleased"; dynamic_cast(sender())->setStyleSheet("background-color:transparent;border-radius:0px;focus{outline: none;}"); } void recoUiPassword::slotTimeout() { m_timeCnt++; qDebug() << "slotTimeout:" << m_timeCnt; if(m_need2ResetDecisionCenterTimer && m_timeCnt < (PROC_OVERTIME - BACKSTAGE_PROC_OVERTIME) ){ m_backstageIf->resetDecisionCenterTimer(); } else if(m_timeCnt >= PROC_OVERTIME){ m_timer->stop(); emit signalShowRecognizePage(); //m_backstageIf->resumeDataFlow(); } } void recoUiPassword::slotShowPwdUiPersonName(const QString& name) { if(name.isEmpty()){ m_labelName->hide(); m_labelWelStr->hide(); } else{ m_labelName->setText(name); m_labelName->setStyleSheet("color:#CBF2FC;"); m_labelName->show(); m_labelWelStr->show(); } } void recoUiPassword::slotShowUserPwdError(int type, int color) { m_timer->start(); switch(type){ case 0: m_labelName->setText(tr("密码错误")); if(0 == color){ m_labelName->setStyleSheet("color:#DB1624;"); } m_labelWelStr->hide(); m_labelName->show(); break; default: break; } }