#include "recoUiCallDial.h" #include #include #include "AsyncEvent.h" #include "recoUiRecognize.h" const int recoUiCallDial::DEV_CODE_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 recoUiCallDial::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 recoUiCallDial::CALL_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 recoUiCallDial::DIAL_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 recoUiCallDial::CALL_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 recoUiCallDial::CALL_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 recoUiCallDial::CALL_BTN_W[UiConfig::SUPPORT_SCREEN_SIZE_QUANTITY] = {344, 430, 430, 430, 430}; const int recoUiCallDial::CALL_BTN_H[UiConfig::SUPPORT_SCREEN_SIZE_QUANTITY] = {72, 90, 90, 90, 90}; const QString recoUiCallDial::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 recoUiCallDial::BACK_BTN_W[UiConfig::SUPPORT_SCREEN_SIZE_QUANTITY] = {20, 24, 24, 24, 24}; const int recoUiCallDial::BACK_BTN_H[UiConfig::SUPPORT_SCREEN_SIZE_QUANTITY] = {35, 44, 44, 44, 44}; const QString recoUiCallDial::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 recoUiCallDial::DEL_BTN_W[UiConfig::SUPPORT_SCREEN_SIZE_QUANTITY] = {344, 35, 35, 35, 35}; const int recoUiCallDial::DEL_BTN_H[UiConfig::SUPPORT_SCREEN_SIZE_QUANTITY] = {344, 24, 24, 24, 24}; const QString recoUiCallDial::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" }; recoUiCallDial::recoUiCallDial(QWidget *parent) : WidgetWithBackstageInterface(parent) { qDebug() << "recoUiCallDial()"; resize(UiConfig::GetInstance()->getUiWidth(), UiConfig::GetInstance()->getUiHeight()); setAutoFillBackground(true); QPalette palette(this->palette()); palette.setBrush(QPalette::Window,QBrush(QPixmap(DIAL_BG[UiConfig::GetInstance()->getScreenConfigIndex()]))); //palette.setBrush(QPalette::Window, Qt::white); setPalette(palette); const int btnWidth = UiConfig::GetInstance()->getUiWidth() / 8; 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())); QFont ft; ft.setWeight(ft.weight() * 2 > 99 ? 99 : ft.weight() * 2);//Weight must be between 0 and 99 m_editDevCode = new QLineEdit(this); m_editDevCode->setFixedWidth(static_cast(UiConfig::GetInstance()->getUiWidth() * 0.9)); m_editDevCode->setReadOnly(true); QPalette lineEditPal; lineEditPal.setColor(QPalette::Text,QColor(255, 255, 255, 255)); m_editDevCode->setPalette(lineEditPal); ft.setPointSize(DEV_CODE_FONT_SIZE[UiConfig::GetInstance()->getScreenConfigIndex()][UiConfig::GetInstance()->getLanguageType()]); m_editDevCode->setFont(ft); m_editDevCode->setStyleSheet("background:transparent;border-width:0;border-style:outset"); m_editDevCode->setAlignment(Qt::AlignCenter); connect(m_editDevCode, SIGNAL(textChanged(const QString&)), this, SLOT(slotTextChanged(const QString&))); 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;}"); 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())); glayMid->addWidget(m_btnsNum[0], 3, 1); glayMid->addWidget(m_btnBackspace, 3, 2); m_btnCall = new QPushButton(this); m_btnCall->setText(tr("呼叫")); m_btnCall->setPalette(btnPal); m_btnCall->setFlat(true); m_btnCall->setCursor(QCursor(Qt::PointingHandCursor)); m_btnCall->setFocusPolicy(Qt::NoFocus); m_btnCall->setFixedSize(CALL_BTN_W[UiConfig::GetInstance()->getScreenConfigIndex()], UiConfig::GetInstance()->isRkDevice() ? (CALL_BTN_H[UiConfig::GetInstance()->getScreenConfigIndex()] >> 2 << 2) : CALL_BTN_H[UiConfig::GetInstance()->getScreenConfigIndex()]); ft.setPointSize(CALL_BTN_FONT_SIZE[UiConfig::GetInstance()->getScreenConfigIndex()][UiConfig::GetInstance()->getLanguageType()]); m_btnCall->setFont(ft); /*m_btnCall->setStyleSheet(QString("background-color:transparent;" "color:white;" "border-image: url(%1);" ).arg(CALL_BTN_BG[UiConfig::GetInstance()->getScreenConfigIndex()]));*/ m_btnCall->setStyleSheet("QPushButton {" "border: 0px;" "border-radius:10px;" "background-color:rgb(31, 164, 38);" "focus{outline: none;}" "}" "QPushButton:pressed {" "background-color:rgb(31, 255, 38);" "focus{outline: none;}" "}"); connect(m_btnCall, SIGNAL(clicked()), this, SLOT(slotBtnClicked())); QVBoxLayout* vlay = new QVBoxLayout(); vlay->addWidget(m_btnBack, 1, Qt::AlignLeft | Qt::AlignTop); vlay->addWidget(m_editDevCode, 1, Qt::AlignCenter | Qt::AlignTop); vlay->addSpacing(UiConfig::GetInstance()->getUiHeight() / 3); vlay->addLayout(glayMid); vlay->addStretch(100); vlay->addWidget(m_btnCall, 1, Qt::AlignCenter | Qt::AlignBottom); vlay->setContentsMargins(0, 10, 0, UiConfig::GetInstance()->getUiHeight() / 20); setLayout(vlay); m_timer = new QTimer(this); connect(m_timer, SIGNAL(timeout()), this, SLOT(slotTimeout())); m_tooltip = new CenterMsgWidget(this); // 不继承父组件样式 m_tooltip->hide(); m_tooltipTimer = new QTimer(this); m_tooltipTimer->setSingleShot(true); connect(m_tooltipTimer, &QTimer::timeout, this, &recoUiCallDial::onTooltipTimeout); } void recoUiCallDial::setToolip(const QString &message, int millisecondTimeout) { if (m_tooltip != nullptr) { m_tooltip->showMsg(message, 64); m_tooltip->show(); m_tooltip->raise(); m_tooltipTimer->start(millisecondTimeout); } } void recoUiCallDial::setPlatformConnected(bool connected) { m_platformConnected = connected; } void recoUiCallDial::onTooltipTimeout(){ m_tooltip->hide(); } void recoUiCallDial::reset() { m_editDevCode->clear(); m_timer->start(TIMEOUT); m_backstageIf->stopIdentyState(); if(m_candidate){ delete m_candidate; m_candidate = nullptr; } } void recoUiCallDial::slotBtnClicked() { m_timer->start(TIMEOUT); const QObject* send = sender(); if (send == m_btnCall) { if (m_platformConnected) { auto code = m_editDevCode->text(); if (code.isEmpty()) { setToolip("号码不能为空", 1500); } else { auto iterator = std::find_if(m_devList.cbegin(), m_devList.cend(), [&code](const stCallDev &device) { return device.code == code.toStdString(); }); if (iterator != m_devList.cend()) { if (iterator->status == 0) { setToolip("呼叫设备离线,请稍后重试", 1500); } else { m_timer->stop(); slotCall(); emit signalCallBtnPressed(QString::fromStdString(iterator->name)); } } else { setToolip("设备不存在", 1500); } } } else { setToolip("当前设备离线,请稍后重试", 1500); } }else if (send == m_btnBackspace) { QString text = m_editDevCode->text(); if(text.size()){ m_editDevCode->setText(text.left(text.size() - 1)); } }else if (send == m_btnBack) { exit(); }else{ if(m_editDevCode->text().length() >= CODE_LEN_MAX){ return; } for(int i=0; isetText(m_editDevCode->text() + m_btnsNum[i]->text()); break; } } } if(UiConfig::GetInstance()->isRkDevice()){ update(); } } void recoUiCallDial::slotBtnPressed() { dynamic_cast(sender())->setStyleSheet(QString("QPushButton {" "border: 0px;" "}" "QPushButton:pressed {" "border: 0px;" "background:url(%1);" "background-repeat:none;" "background-position:center;" "}") .arg(NUM_BTN[UiConfig::GetInstance()->getScreenConfigIndex()])); } void recoUiCallDial::slotBtnReleased() { dynamic_cast(sender())->setStyleSheet("background-color:transparent;border-radius:0px;focus{outline: none;}"); } void recoUiCallDial::slotTimeout() { exit(); } void recoUiCallDial::slotItemChoosed(int index) { if (index < m_devList.size()) { auto event = new AsyncEvent([=]() { m_timer->start(TIMEOUT); m_editDevCode->setText(QString::fromStdString(m_devList.at(index).code)); if (UiConfig::GetInstance()->isRkDevice()) { update(); } }); QCoreApplication::postEvent(this, event); } } void recoUiCallDial::slotTextChanged(const QString& text) { m_devList.clear(); if(m_candidate){ delete m_candidate; m_candidate = nullptr; } if(text.length() < CODE_LEN_MIN){ return; } m_backstageIf->queryCallDevList(text.toStdString(), m_devList); QVector opns; for(auto &item : m_devList){ QString dev{item.code.c_str()}; dev += "("; dev += item.name.c_str(); if(item.status == 0){ dev += tr("-离线"); } dev += ")"; opns.append(myListWidget::SetOpnCfg(dev)); } showCandidate(opns); } void recoUiCallDial::slotCall() { auto iterator = std::find_if(m_devList.cbegin(), m_devList.cend(), [this](const stCallDev &device) { return device.code == m_editDevCode->text().toStdString(); }); if (iterator != m_devList.cend()) { m_backstageIf->callDev(iterator->devTag, iterator->type); } } void recoUiCallDial::showCandidate(const QVector& opns) { if(opns.size() == 0){ return; } m_candidate = new SearchBarCandidate(opns, 0, this); m_candidate->setFixedSize(m_editDevCode->width(), m_editDevCode->height() * 5); m_candidate->move(m_editDevCode->x(), m_editDevCode->y() + m_editDevCode->height() + 20); m_candidate->show(); connect(m_candidate, SIGNAL(signalItemChoosed(int)), this, SLOT(slotItemChoosed(int))); } void recoUiCallDial::exit() { m_timer->stop(); emit signalShowRecognizePage(); }