#include "recoUiCallConsole.h" #include #include #include recoUiCallConsole::recoUiCallConsole(QWidget *parent) : WidgetWithBackstageInterface(parent) { qDebug() << "recoUiCallConsole()"; resize(UiConfig::GetInstance()->getUiWidth(), UiConfig::GetInstance()->getUiHeight()); QLabel* labelImg = new QLabel(this); labelImg->setPixmap(QPixmap(":/res/image/reco_msg_face_pic_large.png")); m_labelContactName = new QLabel(this); m_labelTip = new QLabel("xxxxxx", this); m_btnCancel = createButton(QPixmap(":/res/image/fail2_large.png"), tr("取消")); m_btnHungUp = createButton(QPixmap(":/res/image/hung_up_large.png"), tr("结束通话")); m_btnCallAgain = createButton(QPixmap(":/res/image/call_large.png"), tr("重拨")); m_btnVideoCtrl = createButton(QPixmap(":/res/image/enable_video_large.png"), tr("启用摄像头")); m_btnAccept = createButton(QPixmap(":/res/image/call_large.png"), tr("接听")); m_btnReject = createButton(QPixmap(":/res/image/hung_up_large.png"), tr("拒绝")); m_btnOpenDoor = createButton(QPixmap(":/res/image/key-large.png"),"开门"); QHBoxLayout* hlayBtns = new QHBoxLayout(); hlayBtns->addWidget(m_btnOpenDoor); hlayBtns->addWidget(m_btnCancel); hlayBtns->addWidget(m_btnVideoCtrl); hlayBtns->addWidget(m_btnHungUp); hlayBtns->addWidget(m_btnCallAgain); hlayBtns->addWidget(m_btnReject); hlayBtns->addWidget(m_btnAccept); QVBoxLayout* vlay = new QVBoxLayout(); vlay->addWidget(labelImg, 1, Qt::AlignCenter | Qt::AlignTop); vlay->addWidget(m_labelContactName, 1, Qt::AlignCenter | Qt::AlignTop); vlay->addSpacing(UiConfig::GetInstance()->getUiHeight() / 15); vlay->addWidget(m_labelTip, 1, Qt::AlignCenter | Qt::AlignTop); vlay->addStretch(10); vlay->addLayout(hlayBtns); vlay->setContentsMargins(0, UiConfig::GetInstance()->getUiHeight() / 10, 0, UiConfig::GetInstance()->getUiHeight() / 10); setLayout(vlay); m_timer = new QTimer(this); connect(m_timer, SIGNAL(timeout()), this, SLOT(slotTimeout())); setBackgroundTransparent(false); setVideoButtonVisible(false); } void recoUiCallConsole::setBackgroundTransparent(bool transparent) { if (transparent) { setAutoFillBackground(false); } else { setAutoFillBackground(true); QPalette palette(this->palette()); palette.setBrush(QPalette::Window, Qt::darkGray); palette.setColor(QPalette::WindowText, Qt::white); palette.setColor(QPalette::Text, Qt::white); setPalette(palette); } } void recoUiCallConsole::setVideoButtonVisible(bool visible) { m_videoButtonVisible = visible; m_btnVideoCtrl->setVisible(visible); } void recoUiCallConsole::reset(const QString& contactName) { m_labelContactName->setText(contactName); setBackgroundTransparent(false); setStatus(99); m_timeCount = 0; m_timer->start(TIMEOUT); m_btnOpenDoor->hide(); m_initiatorDoorCfg = false; } void recoUiCallConsole::setStatus(int status, const QString& text) { switch(status){ //发起者 case 0://通话接通,不允许开关视频 case 1://通话接通,允许开关视频 m_btnHungUp->show(); m_btnCancel->hide(); m_btnCallAgain->hide(); m_btnReject->hide(); m_btnAccept->hide(); videoCtrl(false); m_labelTip->setText("00:00"); m_timeCount = 1; m_timer->start(1000); if(status - 0){ m_btnVideoCtrl->show(); }else{ m_btnVideoCtrl->hide(); } break; case ShowVideo: { setBackgroundTransparent(true); break; } case HideVideo: { setBackgroundTransparent(false); break; } //接收者 case 50://设备通话请求到达,不允许开关视频 case 51://设备通话请求到达,允许开关视频 setBackgroundTransparent(false); m_btnHungUp->hide(); m_btnCancel->hide(); m_btnCallAgain->hide(); m_btnReject->show(); m_btnAccept->show(); m_btnVideoCtrl->hide(); m_labelContactName->setText(text); m_labelTip->setText(""); videoCtrl(false); m_initiatorVideoCfg = status - 50; m_btnOpenDoor->hide(); m_initiatorDoorCfg = true; m_backstageIf->stopIdentyState(); break; case PlatformCallIn://平台通话请求到达,不允许开关视频 setBackgroundTransparent(false); m_initiatorDoorCfg = false; m_btnOpenDoor->hide(); // 平台没有开门需求 m_btnHungUp->hide(); m_btnCancel->hide(); m_btnCallAgain->hide(); m_btnReject->hide(); m_btnAccept->hide(); videoCtrl(false); m_btnVideoCtrl->hide(); m_labelContactName->setText(text); m_labelTip->setText("00:00"); m_timeCount = 1; m_timer->start(1000); m_backstageIf->stopIdentyState(); break; case 100: m_timer->stop(); emit signalShowRecognizePage(); break; //内部处理 case 99://发起者呼叫中 m_btnCancel->show(); m_btnCallAgain->hide(); m_btnVideoCtrl->hide(); m_btnHungUp->hide(); m_btnReject->hide(); m_btnAccept->hide(); m_labelTip->setText(tr("呼叫中 ...")); break; case 98://发起者超时未接通 m_btnCancel->show(); m_btnCallAgain->show(); m_btnVideoCtrl->hide(); m_btnHungUp->hide(); m_btnReject->hide(); m_btnAccept->hide(); m_labelTip->setText(tr("对方长时间未接听")); break; case 97://接收者接通 m_btnCancel->hide(); m_btnCallAgain->hide(); m_btnHungUp->show(); m_btnReject->hide(); m_btnAccept->hide(); m_labelTip->setText("00:00"); m_timeCount = 1; m_timer->start(1000); if(m_initiatorVideoCfg){ m_btnVideoCtrl->show(); }else{ m_btnVideoCtrl->hide(); } m_btnOpenDoor->setVisible(m_initiatorDoorCfg); break; default:break; } } void recoUiCallConsole::slotBtnClicked() { const QObject* send = sender(); if (send == m_btnCallAgain) { emit signalCallAgain(); setStatus(99); m_timeCount = 0; m_timer->start(TIMEOUT); }else if (send == m_btnHungUp) { m_timer->stop(); m_backstageIf->callHangUp(); emit signalShowRecognizePage(); }else if (send == m_btnCancel) { m_timer->stop(); m_backstageIf->callAbort(); emit signalShowRecognizePage(); }else if(send == m_btnVideoCtrl){ m_videoEnable = !m_videoEnable; videoCtrl(m_videoEnable); m_backstageIf->callSetVideoStream(m_videoEnable); }else if(send == m_btnReject){ m_backstageIf->callReject(); emit signalShowRecognizePage(); }else if(send == m_btnAccept){ m_backstageIf->callAccept(); setStatus(97); } else if (send == m_btnOpenDoor) { m_backstageIf->openCallRemoteDoor(); } if(UiConfig::GetInstance()->isRkDevice()){ update(); } } void recoUiCallConsole::slotTimeout() { if(m_timeCount){ updateCallTime(m_timeCount++); }else{ m_timer->stop(); m_backstageIf->callAbort(); setStatus(98); } } void recoUiCallConsole::videoCtrl(bool enable) { QLabel *icon = m_btnVideoCtrl->findChild("icon"); if (!icon) { qDebug() << "video btn label not found"; return; } QLabel *text = m_btnVideoCtrl->findChild("text"); if (!icon) { qDebug() << "video btn text not found"; return; } text->setText(enable ? tr("禁用摄像头") : tr("启用摄像头")); QPixmap pm(enable ? ":/res/image/disable_video_large.png" : ":/res/image/enable_video_large.png"); pm = pm.scaled(120, 120, Qt::KeepAspectRatio); icon->setPixmap(pm); m_videoEnable = enable; } QPushButton* recoUiCallConsole::createButton(const QPixmap& icon, const QString& btnText) { QPushButton* btn = new QPushButton(this); btn->setFocusPolicy(Qt::NoFocus); btn->setFixedSize(240, 240); btn->setStyleSheet("background-color: transparent;"); connect(btn, SIGNAL(clicked()), this, SLOT(slotBtnClicked())); QLabel* labelIcon = new QLabel(btn); labelIcon->setObjectName("icon"); QPixmap pm(icon); pm = pm.scaled(120, 120, Qt::KeepAspectRatio); labelIcon->setPixmap(pm); QLabel *btnName = new QLabel(btnText, btn); btnName->setObjectName("text"); btnName->setStyleSheet("color: white;"); QVBoxLayout* vlay = new QVBoxLayout(btn); vlay->addWidget(labelIcon, 9, Qt::AlignCenter); vlay->addWidget(btnName, 1, Qt::AlignCenter); vlay->setAlignment(Qt::AlignCenter); return btn; } void recoUiCallConsole::updateCallTime(int second) { m_labelTip->setText(QString::number(second / 60).rightJustified(2, QChar('0')) + ":" + QString::number(second % 60).rightJustified(2, QChar('0'))); }