FaceAccess/Linguist/setUi/settingUiRecoSet.cpp
2024-07-11 11:27:12 +08:00

297 lines
13 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "settingUiRecoSet.h"
#include <QDebug>
#include "UiConfig.h"
int settingUiRecoSet::m_pageIndex = 0;
settingUiRecoSet::settingUiRecoSet(int pageIndex, QWidget *parent)
: SettingUiPage(QVector<SettingUiPage::SetOpn>{
SetOpn(tr("身份核验"), "", myListWidget::enPropertySwitch),
SetOpn(tr("活体检测"), "", static_cast<myListWidget::enProperty>(myListWidget::enPropertyMoreArrow | myListWidget::enPropertyIndent1)),
SetOpn(tr("人脸识别阈值"), "xx", static_cast<myListWidget::enProperty>(myListWidget::enPropertyMoreArrow | myListWidget::enPropertyIndent1)),
SetOpn(tr("人脸识别自定义阈值0-100"), "xx", static_cast<myListWidget::enProperty>(myListWidget::enPropertyMoreArrow | myListWidget::enPropertyIndent1)),
SetOpn(tr("居民二代身份证"), "", static_cast<myListWidget::enProperty>(myListWidget::enPropertySwitch | myListWidget::enPropertyIndent1)),
SetOpn(tr("口罩检测"), "", myListWidget::enPropertySwitch),
SetOpn(tr("未戴口罩禁止通行"), "", static_cast<myListWidget::enProperty>(myListWidget::enPropertySwitch | myListWidget::enPropertyIndent1)),
SetOpn(tr("健康码核验"), "", myListWidget::enPropertySwitch),
SetOpn(tr("允许无人脸核验"), "", static_cast<myListWidget::enProperty>(myListWidget::enPropertySwitch | myListWidget::enPropertyIndent1)),
SetOpn(tr("允许陌生人通行"), "", static_cast<myListWidget::enProperty>(myListWidget::enPropertySwitch | myListWidget::enPropertyIndent1)),
SetOpn(tr("核验通行条件"), "", static_cast<myListWidget::enProperty>(myListWidget::enPropertyMoreArrow | myListWidget::enPropertyIndent1))
}, parent)
{
m_pageIndex = pageIndex;
qDebug() << "settingUiRecoSet()";
}
settingUiRecoSet::~settingUiRecoSet()
{
qDebug() << "~settingUiRecoSet()";
}
void settingUiRecoSet::setBackstageUiinterface(BackstageInterfaceForUi* interface)
{
m_backstageIf = interface;
reset();
}
void settingUiRecoSet::reset()
{
if(nullptr == m_backstageIf){
return;
}
for(int i = 0; i < config.size(); i ++)
{
QListWidgetItem* pItem = m_listWidget->item(i);
myListWidget* wdt = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(pItem));
if(wdt == nullptr){
return;
}
QString str;
switch(i)
{
case enRecoIdeSw:
case enRecoMaskSw:
case enRecoNoMaskNoPassSw:
case enRecoLiveSw:
case enRecoIDFaceVerify:
case enHealthCodeSw:
case enHealthCodeNoFaceRequiredSw:
case enHealthCodeAllowStrangerSw:
{
bool switch_option = false;
if(enRecoIdeSw == i){
switch_option = m_backstageIf->getIdentificationSw();
}else if(enRecoMaskSw == i){
switch_option = m_backstageIf->getMaskCheckSwitch();
}else if(enRecoNoMaskNoPassSw == i){
switch_option = m_backstageIf->getNoMaskNoPassSwitch();
}else if(enRecoLiveSw == i){
switch_option = m_backstageIf->getLivingBodySw();
}else if(enRecoIDFaceVerify == i){
switch_option = m_backstageIf->getIDFaceVerifySw();
}else if(enHealthCodeSw == i){
switch_option = m_backstageIf->getHealthCodeSw();
}else if(enHealthCodeNoFaceRequiredSw == i){
switch_option = m_backstageIf->getHealthCodeNoFaceRequired();
}else if(enHealthCodeAllowStrangerSw == i){
switch_option = m_backstageIf->getHealthCodeAllowStranger();
}
wdt->updateIcon(switch_option ? ":/res/image/on.png" : ":/res/image/off.png");
}
break;
case enRecoIdeThreCustom:
str = QString::number(m_backstageIf->getCustomSimilarity());
break;
case enRecoIdeThre:
{
enSimilarityTh opt = m_backstageIf->getSimilarityTh();
str = RecoSimThre[static_cast<int>(opt)];
}
break;
// case enRecoLiveThre:
// str = LivingThre[static_cast<int>(m_backstageIf->getLivingBodyTh())];
// break;
default:
break;
}
wdt->updateLabel(str);
}
controlListWidgetItemShow(m_backstageIf->getIdentificationSw(), enRecoLiveSw);
//controlListWidgetItemShow(m_backstageIf->getIdentificationSw(), enRecoLiveThre);
controlListWidgetItemShow(m_backstageIf->getIdentificationSw(), enRecoIdeThre);
controlListWidgetItemShow(m_backstageIf->getIdentificationSw() ? SimilarityThCustom == m_backstageIf->getSimilarityTh() : false, enRecoIdeThreCustom);
controlListWidgetItemShow(m_backstageIf->getIdentificationSw(), enRecoIDFaceVerify);
controlListWidgetItemShow(m_backstageIf->getMaskCheckSwitch(), enRecoNoMaskNoPassSw);
controlListWidgetItemShow(m_backstageIf->getHealthCodeSw(), enHealthCodeNoFaceRequiredSw);
controlListWidgetItemShow(m_backstageIf->getHealthCodeSw(), enHealthCodeAllowStrangerSw);
controlListWidgetItemShow(m_backstageIf->getHealthCodeSw(), enHealthCodePassCfg);
}
void settingUiRecoSet::slotItemClicked(QListWidgetItem* item)
{
int row = m_listWidget->currentRow();
myListWidget* wdt = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(item));
if(wdt == nullptr){
return;
}
switch(row){
case enRecoIdeSw:
case enRecoMaskSw:
case enRecoNoMaskNoPassSw:
case enRecoLiveSw:
case enRecoIDFaceVerify:
case enHealthCodeSw:
case enHealthCodeNoFaceRequiredSw:
case enHealthCodeAllowStrangerSw:
{
bool setting_value = false;
if(enRecoIdeSw == row){
setting_value = static_cast<bool>(m_backstageIf->getIdentificationSw());
}
else if(enRecoMaskSw == row){
setting_value = static_cast<bool>(m_backstageIf->getMaskCheckSwitch());
}
else if(enRecoNoMaskNoPassSw == row){
setting_value = static_cast<bool>(m_backstageIf->getNoMaskNoPassSwitch());
}
else if(enRecoLiveSw == row){
setting_value = static_cast<bool>(m_backstageIf->getLivingBodySw());
}
else if(enRecoIDFaceVerify == row){
setting_value = static_cast<bool>(m_backstageIf->getIDFaceVerifySw());
}
else if(enHealthCodeSw == row){
setting_value = m_backstageIf->getHealthCodeSw();
}
else if(enHealthCodeNoFaceRequiredSw == row){
setting_value = m_backstageIf->getHealthCodeNoFaceRequired();
}
else if(enHealthCodeAllowStrangerSw == row){
setting_value = m_backstageIf->getHealthCodeAllowStranger();
}
setting_value = static_cast<bool>(!setting_value);
wdt->updateIcon(setting_value ? ":/res/image/on.png" : ":/res/image/off.png");
if(enRecoIdeSw == row){
m_backstageIf->setIdentificationSw(setting_value);
controlListWidgetItemShow(setting_value, enRecoLiveSw);
//controlListWidgetItemShow(setting_value, enRecoLiveThre);
controlListWidgetItemShow(setting_value, enRecoIdeThre);
controlListWidgetItemShow(setting_value, enRecoIDFaceVerify);
controlListWidgetItemShow(setting_value ? SimilarityThCustom == m_backstageIf->getSimilarityTh() : false, enRecoIdeThreCustom);
}
else if(enRecoMaskSw == row){
m_backstageIf->setMaskCheckSwitch(setting_value);
controlListWidgetItemShow(setting_value, enRecoNoMaskNoPassSw);
}
else if(enRecoNoMaskNoPassSw == row){
m_backstageIf->setNoMaskNoPassSwitch(setting_value);
}
else if(enRecoLiveSw == row){
m_backstageIf->setLivingBodySw(setting_value);
}
else if(enRecoIDFaceVerify == row){
m_backstageIf->setIDFaceVerifySw(setting_value);
}
else if(enHealthCodeSw == row){
m_backstageIf->setHealthCodeSw(setting_value);
controlListWidgetItemShow(setting_value, enHealthCodeNoFaceRequiredSw);
controlListWidgetItemShow(setting_value, enHealthCodeAllowStrangerSw);
controlListWidgetItemShow(setting_value, enHealthCodePassCfg);
if(setting_value){
myListWidget* wdg = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(m_listWidget->item(enRecoIdeSw)));
if(wdg){wdg->updateIcon(":/res/image/on.png");}
wdg = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(m_listWidget->item(enRecoIDFaceVerify)));
if(wdg){wdg->updateIcon(":/res/image/on.png");}
}
}
else if(enHealthCodeNoFaceRequiredSw == row){
m_backstageIf->setHealthCodeNoFaceRequired(setting_value);
}
else if(enHealthCodeAllowStrangerSw == row){
m_backstageIf->setHealthCodeAllowStranger(setting_value);
}
}
break;
case enRecoIdeThreCustom:
{
int currentValue = 10;
int min = 0;
int max = 100;
QString tip("this is a line of prompt text");
#ifndef DEBUG_MODE
if(enRecoIdeThreCustom == row){
currentValue = m_backstageIf->getCustomSimilarity();
min = 0;
max = 100;
tip.clear();
}
#endif
SliderDialog dlg(currentValue, min, max, tip, parent()->parent());
if(dlg.exec() == QDialog::Accepted)
{
QString str("valueSet");
int valueSet = dlg.getValueSet();
#ifndef DEBUG_MODE
if(enRecoIdeThreCustom == row){
m_backstageIf->setCustomSimilarity(valueSet);
str = QString::number(valueSet);
}
#endif
wdt->updateLabel(str);
}
}
break;
case enRecoIdeThre:
{
int choosed = 0;
QVector<QString>& options = const_cast<QVector<QString>&>(RecoSimThre);
if(enRecoIdeThre == row){
choosed = static_cast<int>(m_backstageIf->getSimilarityTh());
}
#if 0
else if(enRecoLiveThre == row){
options = LivingThre;
choosed = static_cast<int>(m_backstageIf->getLivingBodyTh());
}
#endif
RadioBtnChooseDialog dlg(options, parent()->parent(), choosed);
if(dlg.exec() == QDialog::Accepted){
int newChoosed = dlg.getChoosedIndex();
if(newChoosed != choosed){
if(enRecoIdeThre == row){
m_backstageIf->setSimilarityTh(static_cast<enSimilarityTh>(newChoosed));
if(SimilarityThCustom == static_cast<enSimilarityTh>(newChoosed)){
//重新获取当前的阈值显示到条目上,因为当前是从别的档位切换过来的,阈值已经改变,设计的问题:只保存一个当前阈值,没有单独保存自定义的阈值
QListWidgetItem* pItem = m_listWidget->item(enRecoIdeThreCustom);
myListWidget* swWidget = dynamic_cast<myListWidget*>(m_listWidget->itemWidget(pItem));
if(swWidget != nullptr){
swWidget->updateLabel(QString::number(m_backstageIf->getCustomSimilarity()));
}
controlListWidgetItemShow(true, enRecoIdeThreCustom);
}
else{
controlListWidgetItemShow(false, enRecoIdeThreCustom);
}
}
#if 0
else if(enRecoLiveThre == row){
m_backstageIf->setLivingBodyTh(static_cast<enLivingBodyTh>(newChoosed));
}
#endif
wdt->updateLabel(options[newChoosed]);
}
}
}
break;
case enHealthCodePassCfg:
{
const QStringList titles{"健康码色", "核酸检测", "行程信息", "疫苗"};
const QVector<QStringList> sels{{"无限制", "仅绿码可通行", "绿码、黄码可通行", "绿码、黄码、红码可通行"},
{"无限制", "限24小时内阴性", "限48小时内阴性", "限72小时内阴性", "限阴性"},
{"无限制", "限14天内未到过中高风险地区"},
{"无限制", "限至少打了第1针", "限至少打了第2针", "限至少打了第3针"} };
ComSelectDialog dlg(titles, sels, parent()->parent());
int codeColorCfg;
int c19tCfg;
int tripCfg;
int abtCfg;
m_backstageIf->getHealthCodePassCfg(codeColorCfg, c19tCfg, tripCfg, abtCfg);
dlg.setRow(0, codeColorCfg);
dlg.setRow(1, c19tCfg);
dlg.setRow(2, tripCfg);
dlg.setRow(3, abtCfg);
if(dlg.exec() == QDialog::Accepted){
m_backstageIf->setHealthCodePassCfg(dlg.getRow(0), dlg.getRow(1), dlg.getRow(2), dlg.getRow(3));
}
}
break;
default:
break;
}
}