answerWidget.cpp 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531
  1. #include "answerWidget.h"
  2. #include "ui_answerWidget.h"
  3. #include "CAppInfo.h"
  4. #include "awMsgBox.h"
  5. #include "awQuestionNavigate.h"
  6. #include "CCommonTools.h"
  7. #include "logproc.h"
  8. #include "inprogressFace.h"
  9. #include "popMsgBox.h"
  10. answerWidget::answerWidget(QWidget *parent) :
  11. QWidget(parent),
  12. ui(new Ui::answerWidget)
  13. {
  14. ui->setupUi(this);
  15. setStyleSheet(g_appInfoPtr->m_sQssStr);
  16. m_sRemoteList
  17. << "qq"
  18. <<"teamviewer"
  19. <<"lookmypc"
  20. <<"xt"
  21. <<"winaw32"
  22. <<"pcaquickconnect"
  23. <<"sessioncontroller"
  24. <<"sunloginclient"
  25. <<"sunloginremote"
  26. <<"wechat"
  27. <<"wemeetapp";
  28. m_sRemoteTipList<<"QQ"
  29. <<"TeamViewer"
  30. <<"LookMyPC"
  31. << QString::fromLocal8Bit("协通")
  32. <<"Symantec PCAnywhere"
  33. <<"Symantec PCAnywhere"
  34. <<"Symantec PCAnywhere"
  35. << QString::fromLocal8Bit("向日葵")
  36. << QString::fromLocal8Bit("向日葵")
  37. << QString::fromLocal8Bit("微信")
  38. << QString::fromLocal8Bit("腾讯会议");
  39. qRegisterMetaType<CGetExamById>("CGetExamById");
  40. connect(g_httpBllPtr.get(), &CHttpBll::sgnGetExamById, this, &answerWidget::onGetExamById);
  41. qRegisterMetaType<CGetExamRecordPaperStruct>("CGetExamRecordPaperStruct");
  42. connect(g_httpBllPtr.get(), &CHttpBll::sgnGetExamRecordPaperStruct, this, &answerWidget::onGetExamRecordPaperStruct);
  43. qRegisterMetaType<CGetExamProperty>("CGetExamProperty");
  44. connect(g_httpBllPtr.get(), &CHttpBll::sgnGetExamProperty, this, &answerWidget::onGetExamProperty);
  45. qRegisterMetaType<CWeiXinAnswerEnabled>("CWeiXinAnswerEnabled");
  46. connect(g_httpBllPtr.get(), &CHttpBll::sgnWeiXinAnswerEnabled, this, &answerWidget::onWeiXinAnswerEnabled);
  47. qRegisterMetaType<CGetQuestionContent>("CGetQuestionContent");
  48. connect(g_httpBllPtr.get(), &CHttpBll::sgnGetQuestionContent, this, &answerWidget::onGetQuestionContent);
  49. qRegisterMetaType<CFindExamQuestionList>("CFindExamQuestionList");
  50. connect(g_httpBllPtr.get(), &CHttpBll::sgnFindExamQuestionList, this, &answerWidget::onFindExamQuestionList);
  51. qRegisterMetaType<CStartAnswer>("CStartAnswer");
  52. connect(g_httpBllPtr.get(), &CHttpBll::sgnStartAnswer, this, &answerWidget::onStartAnswer);
  53. qRegisterMetaType<CExamHeartbeat>("CExamHeartbeat");
  54. connect(g_httpBllPtr.get(), &CHttpBll::sgnExamHeartbeat, this, &answerWidget::onExamHeartbeat);
  55. qRegisterMetaType<CSubmitQuestionAnswer>("CSubmitQuestionAnswer");
  56. connect(g_httpBllPtr.get(), &CHttpBll::sgnSubmitQuestionAnswer, this, &answerWidget::onSubmitQuestionAnswer);
  57. qRegisterMetaType<CEndExam>("CEndExam");
  58. connect(g_httpBllPtr.get(), &CHttpBll::sgnEndExam, this, &answerWidget::onEndExam);
  59. qRegisterMetaType<CGetOrgPropertiesByGroupWithoutCache>("CGetOrgPropertiesByGroupWithoutCache");
  60. connect(g_httpBllPtr.get(), &CHttpBll::sgnGetOrgPropertiesByGroupWithoutCache, this, &answerWidget::onGetOrgPropertiesByGroupWithoutCache);
  61. qRegisterMetaType<CStartFaceLiveVerify>("CStartFaceLiveVerify");
  62. connect(g_httpBllPtr.get(), &CHttpBll::sgnStartFaceLiveVerify, this, &answerWidget::onStartFaceLiveVerify);
  63. #ifdef _DEBUG
  64. //g_appInfoPtr->m_oExamInfo.bLivenessCheck = false;
  65. // g_appInfoPtr->m_oExamInfo.bFaceCheck = false;
  66. #endif // _DEBUG
  67. //m_MonitorEnumeratorPtr = std::make_shared<CMultiMonitorEnumerator>();
  68. m_nLeftSeconds = 0;
  69. m_nHeartBreatFailedCount = 0;
  70. bShowLeftHint = false;
  71. CHttpRequestPackage hrp;
  72. hrp.sUri = QString("/api/ecs_exam_work/exam/getExamPropertyFromCacheByStudentSession/%1/%2")
  73. .arg(g_appInfoPtr->m_oExamInfo.nExamId).arg("SNAPSHOT_INTERVAL,PRACTICE_TYPE,FREEZE_TIME,PRACTICE_TYPE");
  74. hrp.nRequestType = RequestType::rtGetExamProperty;
  75. hrp.sCommonStr = "SNAPSHOT_INTERVAL,PRACTICE_TYPE,FREEZE_TIME";
  76. g_httpBllPtr->get(hrp);
  77. {
  78. CHttpRequestPackage hrp;
  79. hrp.sUri = QString("/api/ecs_exam_work/exam/%1").arg(g_appInfoPtr->m_oExamInfo.nExamId);
  80. hrp.nRequestType = RequestType::rtGetExamById;
  81. g_httpBllPtr->get(hrp);
  82. }
  83. CHttpRequestPackage hrp1;
  84. hrp1.sUri = "/api/ecs_oe_student/client/exam/process/getExamRecordPaperStruct";
  85. hrp1.sParamList.push_back(QString("examRecordDataId,%1").arg(g_appInfoPtr->m_oExamInfo.nExamRecordDataId));
  86. hrp1.nRequestType = RequestType::rtGetExamRecordPaperStruct;
  87. hrp1.eParamType = HttpParamType::hptUrl;
  88. g_httpBllPtr->post(hrp1);
  89. {
  90. CHttpRequestPackage hrp;
  91. hrp.sUri = "/api/ecs_oe_student/client/exam/process/findExamQuestionList";
  92. hrp.nRequestType = RequestType::rtFindExamQuestionList;
  93. g_httpBllPtr->post(hrp);
  94. }
  95. {
  96. CHttpRequestPackage hrp;
  97. hrp.sUri = QString("/api/ecs_exam_work/exam/weixinAnswerEnabled/%1")
  98. .arg(g_appInfoPtr->m_oExamInfo.nExamId);
  99. hrp.sParamList.push_back(QString::fromLocal8Bit("courseCode,%1").arg(g_appInfoPtr->m_oExamInfo.sCourseCode));
  100. hrp.nRequestType = RequestType::rtWeiXinAnswerEnabled;
  101. g_httpBllPtr->get(hrp);
  102. }
  103. m_pCountDownTimer = std::make_shared<QTimer>();
  104. m_pCountDownTimer->setInterval(1000);
  105. connect(m_pCountDownTimer.get(), &QTimer::timeout, this, [&](){
  106. --m_nLeftSeconds;
  107. ui->label_lastTime->setText(QString("%1:%2:%3").arg(m_nLeftSeconds/60/60, 2, 10, QChar('0'))
  108. .arg(m_nLeftSeconds/60%60, 2, 10, QChar('0'))
  109. .arg(m_nLeftSeconds%60, 2, 10, QChar('0')));
  110. if(m_nLeftSeconds <= 0)
  111. {
  112. // m_pCountDownTimer->stop();
  113. handinPaper();
  114. }
  115. if(m_nLeftSeconds <= 5*60 &&
  116. m_nLeftSeconds >= 5 * 60 - 5 &&
  117. !bShowLeftHint)
  118. {
  119. bShowLeftHint = true;
  120. if(m_ptimeLeftTips == nullptr)
  121. {
  122. m_ptimeLeftTips = std::make_shared<awTimeLeftTips>(MASK_POP_WIDGET_TYPE::wt_timeLeft, (QWidget*)(this->parent()));
  123. connect(m_ptimeLeftTips.get(), &awTimeLeftTips::timeLeftConfirm, this, [&](){
  124. m_ptimeLeftTips.reset();
  125. });
  126. }
  127. m_ptimeLeftTips->show();
  128. }
  129. if(g_appInfoPtr->m_oExamInfo.bLivenessCheck &&
  130. g_appInfoPtr->m_oExamInfo.nFaceLiveVerifyId > 0)
  131. {
  132. if(bShowLivenessTip && (m_nUsedExamSeconds + m_nEnterExamTime - m_nLeftSeconds + g_appInfoPtr->m_oExamInfo.nActionAlert) > g_appInfoPtr->m_oExamInfo.nFaceVerifyDoMinute*60)
  133. {
  134. bShowLivenessTip = false;
  135. m_nEnterLivenessFaceSeconds = m_nLeftSeconds - 20;
  136. ShowMsg(QString::fromLocal8Bit("%1秒后开始指定动作检测,请准备!").arg(g_appInfoPtr->m_oExamInfo.nActionAlert), g_appInfoPtr->m_pAnsBgWidget);
  137. }
  138. if((m_nUsedExamSeconds + m_nEnterExamTime - m_nLeftSeconds) > g_appInfoPtr->m_oExamInfo.nFaceVerifyDoMinute * 60
  139. && m_nEnterLivenessFaceSeconds > m_nLeftSeconds)
  140. {
  141. //活体检测
  142. if(m_pFaceLiveness == nullptr)
  143. {
  144. stopCapture();
  145. m_pFaceLiveness = std::make_shared<faceLiveness>(g_appInfoPtr->m_pAnsBgWidget);
  146. connect(m_pFaceLiveness.get(), &faceLiveness::faceLivenessFaild, this, [&](){
  147. g_appInfoPtr->m_oExamInfo.nFaceLiveVerifyId = 0;
  148. m_pFaceLiveness.reset();
  149. if(g_appInfoPtr->m_oExamInfo.nFaceVerifyTimes < 2)
  150. {
  151. emit gobackLogin();
  152. }
  153. else
  154. {
  155. //交卷
  156. handinPaper();
  157. }
  158. });
  159. connect(m_pFaceLiveness.get(), &faceLiveness::faceLivenessSucceed, this, [&](){
  160. g_appInfoPtr->m_oExamInfo.nFaceLiveVerifyId = 0;
  161. m_pFaceLiveness.reset();
  162. if (g_appInfoPtr->m_oExamInfo.bFaceCheck)
  163. {
  164. startCapture();
  165. }
  166. });
  167. m_pFaceLiveness->show();
  168. }
  169. }
  170. }
  171. });
  172. if (g_appInfoPtr->m_bDisableRemoteAssistance)
  173. {
  174. qRegisterMetaType<CGetSoftwareConfig>("CGetSoftwareConfig");
  175. connect(g_httpBllPtr.get(), &CHttpBll::sgnGetSoftwareConfig, this, &answerWidget::onGetSoftwareConfig);
  176. CHttpRequestPackage hrp;
  177. hrp.sUri = QString("https://%1/oe_client/software.json").arg(g_appInfoPtr->m_sEscDomain);
  178. hrp.nRequestType = RequestType::rtGetSoftwareConfig;
  179. g_httpBllPtr->getUrl(hrp);
  180. }
  181. m_pHeartbeatTimer = std::make_shared<QTimer>();
  182. m_pHeartbeatTimer->setInterval(60*1000);
  183. connect(m_pHeartbeatTimer.get(), &QTimer::timeout, this, [&](){
  184. heartBreat();
  185. if(g_appInfoPtr->m_bDisableRemoteAssistance)
  186. {
  187. checkRemoteBreach();
  188. }
  189. });
  190. }
  191. answerWidget::~answerWidget()
  192. {
  193. awMsgBox::clear(this);
  194. if (g_inProcessFace)
  195. {
  196. stopCapture();
  197. g_inProcessFace.reset();
  198. }
  199. delete ui;
  200. }
  201. void answerWidget::onGetSoftwareConfig(CGetSoftwareConfig getSoftwareConfig)
  202. {
  203. if (getSoftwareConfig.nCode == 200)
  204. {
  205. QString sSoftwareConfig = QByteArray::fromBase64(getSoftwareConfig.sSoftwareConfig.toLocal8Bit());
  206. if(!sSoftwareConfig.isEmpty())
  207. {
  208. Json::Reader reader;
  209. Json::Value jsonRoot = Json::Value::null;
  210. if (reader.parse(sSoftwareConfig.toStdString(), jsonRoot))
  211. {
  212. QString sCamera = jsonRoot["vCamList"].asString().c_str();
  213. QStringList cameraList = sCamera.split("\n", QString::SkipEmptyParts);
  214. QString sRemoteApp = jsonRoot["remoteApp"].asString().c_str();
  215. QStringList remoteAppList = sRemoteApp.split("\n", QString::SkipEmptyParts);
  216. m_sRemoteList += remoteAppList;
  217. m_sRemoteTipList += remoteAppList;
  218. }
  219. }
  220. }
  221. }
  222. void answerWidget::checkRemoteBreach()
  223. {
  224. static int nIndex = 0;
  225. ++nIndex;
  226. if(nIndex % 3 == 0)
  227. {
  228. std::shared_ptr<CMultiMonitorEnumerator> m_MonitorEnumeratorPtr = std::make_shared<CMultiMonitorEnumerator>();
  229. bool bExit = false;
  230. QString sCheckStr = "";
  231. if (CCommonTools::isUseRDP())
  232. {
  233. sCheckStr = QString::fromLocal8Bit("检测是否开启远程桌面");
  234. qDebug() << QString::fromLocal8Bit("开启远程桌面");
  235. bExit = true;
  236. }
  237. if (m_MonitorEnumeratorPtr->getMontorNumber() > 1)
  238. {
  239. sCheckStr = QString::fromLocal8Bit("请检测是否开启分屏");
  240. qDebug() << QString::fromLocal8Bit("开启双屏");
  241. bExit = true;
  242. }
  243. QStringList appList;
  244. CCommonTools::getAllAppNameList(appList, m_sRemoteList, m_sRemoteTipList);
  245. if (appList.count() > 0)
  246. {
  247. bExit = true;
  248. for (int i = 0; i < appList.count(); i++)
  249. {
  250. if (sCheckStr.isEmpty())
  251. {
  252. sCheckStr = QString::fromLocal8Bit("请检测是否开启%1").arg(appList[i]);
  253. }
  254. else
  255. {
  256. sCheckStr += QString::fromLocal8Bit("、%1").arg(appList[i]);
  257. }
  258. }
  259. }
  260. QApplication::processEvents();
  261. if (bExit)
  262. {
  263. //退出
  264. awTimeLeftTips *wExitExam = new awTimeLeftTips(MASK_POP_WIDGET_TYPE::wt_exitExam, (QWidget*)(this->parent()));
  265. wExitExam->setText(sCheckStr, QString::fromLocal8Bit("退出考试"));
  266. connect(wExitExam, &awTimeLeftTips::timeLeftConfirm, this, [this, wExitExam]() {
  267. if (m_pNetWorkErrorTimerPtr)
  268. {
  269. m_pNetWorkErrorTimerPtr->stop();
  270. }
  271. delete wExitExam;
  272. emit gobackLogin();
  273. });
  274. wExitExam->show();
  275. if (m_pNetWorkErrorTimerPtr == nullptr)
  276. {
  277. m_pNetWorkErrorTimerPtr = std::make_shared<QTimer>();
  278. m_pNetWorkErrorTimerPtr->setInterval(30 * 1000);
  279. connect(m_pNetWorkErrorTimerPtr.get(), &QTimer::timeout, [this, wExitExam]() {
  280. m_pNetWorkErrorTimerPtr->stop();
  281. delete wExitExam;
  282. emit gobackLogin();
  283. });
  284. }
  285. m_pNetWorkErrorTimerPtr->start();
  286. }
  287. }
  288. }
  289. void answerWidget::setUI(const int nLeft, const int nTop, const int nWidth, const int nHeight)
  290. {
  291. setGeometry(nLeft, nTop, nWidth, nHeight);
  292. ui->widget_aw_answerBG->setGeometry(0, 0, width()*970/(970+270), height());
  293. ui->widget_navigate->setGeometry(ui->widget_aw_answerBG->x() + ui->widget_aw_answerBG->width() + g_appInfoPtr->m_fRate*20, 0,
  294. width() - ui->widget_aw_answerBG->width() - g_appInfoPtr->m_fRate*20, height());
  295. ui->widget_aw_face->setGeometry(0, ui->widget_navigate->height() - g_appInfoPtr->m_fRate*140, ui->widget_navigate->width(), g_appInfoPtr->m_fRate*140);
  296. ui->widget_aw_top->setGeometry(0, 0, ui->widget_aw_answerBG->width(), g_appInfoPtr->m_fRate*56);
  297. ui->widget_ng_top->setGeometry(0, 0, ui->widget_navigate->width(), g_appInfoPtr->m_fRate*56);
  298. ui->label_answerProgress->adjustSize();
  299. ui->label_answerProgress->setGeometry(g_appInfoPtr->m_fRate*20, (ui->widget_aw_top->height() - ui->label_answerProgress->height())/2,
  300. ui->label_answerProgress->width(), ui->label_answerProgress->height());
  301. ui->pgb_answerProgress->setGeometry(ui->label_answerProgress->x() + ui->label_answerProgress->width() + g_appInfoPtr->m_fRate*8,
  302. (ui->widget_aw_top->height() - g_appInfoPtr->m_fRate*20)/2,
  303. g_appInfoPtr->m_fRate*200, g_appInfoPtr->m_fRate*20);
  304. ui->btn_handInPaper->setGeometry(ui->widget_aw_top->width() - g_appInfoPtr->m_fRate*(10 + 100), g_appInfoPtr->m_fRate*10,
  305. g_appInfoPtr->m_fRate*100, g_appInfoPtr->m_fRate*36);
  306. ui->label_lastTimeIcon->setGeometry(g_appInfoPtr->m_fRate*48, g_appInfoPtr->m_fRate*12, g_appInfoPtr->m_fRate*32, g_appInfoPtr->m_fRate*32);
  307. ui->label_lastTime->adjustSize();
  308. ui->label_lastTime->setGeometry(ui->label_lastTimeIcon->x() + ui->label_lastTimeIcon->width() + g_appInfoPtr->m_fRate*10,
  309. ui->label_lastTimeIcon->y() + (ui->label_lastTimeIcon->height() - ui->label_lastTime->height())/2,
  310. ui->label_lastTime->width(), ui->label_lastTime->height());
  311. ui->btn_all->setGeometry(g_appInfoPtr->m_fRate*30, ui->widget_ng_top->height() + g_appInfoPtr->m_fRate*20,
  312. g_appInfoPtr->m_fRate*90, g_appInfoPtr->m_fRate*28);
  313. ui->btn_allNum->setGeometry(ui->btn_all->x() + ui->btn_all->width() - g_appInfoPtr->m_fRate*(4 + 30), ui->btn_all->y() + (ui->btn_all->height() - g_appInfoPtr->m_fRate*20)/2,
  314. g_appInfoPtr->m_fRate*30, g_appInfoPtr->m_fRate*20);
  315. ui->btn_answered->setGeometry(ui->btn_all->x() + ui->btn_all->width() + g_appInfoPtr->m_fRate*10,
  316. ui->btn_all->y(), ui->btn_all->width(), ui->btn_all->height());
  317. ui->btn_answeredNum->setGeometry(ui->btn_answered->x() + ui->btn_answered->width() - g_appInfoPtr->m_fRate*(4 + 30), ui->btn_allNum->y(),
  318. ui->btn_allNum->width(), ui->btn_allNum->height());
  319. ui->btn_unanswered->setGeometry(ui->btn_all->x(), ui->btn_all->y() + ui->btn_all->height() + g_appInfoPtr->m_fRate*10,
  320. ui->btn_all->width(), ui->btn_all->height());
  321. ui->btn_unansweredNum->setGeometry(ui->btn_allNum->x(), ui->btn_unanswered->y() + (ui->btn_unanswered->height() - g_appInfoPtr->m_fRate*20)/2,
  322. ui->btn_allNum->width(), ui->btn_allNum->height());
  323. ui->btn_marked->setGeometry(ui->btn_answered->x(), ui->btn_unanswered->y(), ui->btn_all->width(), ui->btn_all->height());
  324. ui->btn_markedNum->setGeometry(ui->btn_answeredNum->x(), ui->btn_unansweredNum->y(), ui->btn_allNum->width(), ui->btn_allNum->height());
  325. ui->label_HLine->setGeometry(ui->btn_all->x(), ui->btn_unanswered->y() + ui->btn_unanswered->height() + g_appInfoPtr->m_fRate*20,
  326. ui->widget_navigate->width() - ui->btn_all->x()*2, g_appInfoPtr->m_fRate*1 < 1 ? 1 : g_appInfoPtr->m_fRate*1);
  327. ui->lw_aw_questionList->setGeometry(0, ui->label_HLine->y(), ui->widget_navigate->width(),
  328. ui->widget_aw_face->y() - ui->label_HLine->y() - ui->label_HLine->height());
  329. }
  330. void answerWidget::onGetExamById(CGetExamById getExamById)
  331. {
  332. if (getExamById.nCode == 200)
  333. {
  334. g_appInfoPtr->m_oExamInfo.nExamId = getExamById.nId;
  335. g_appInfoPtr->m_oExamInfo.sExamType = getExamById.sExamType;
  336. g_appInfoPtr->m_oExamInfo.nDuration = getExamById.nDuration;
  337. }
  338. else
  339. {
  340. if(getExamById.sMessage.isEmpty())
  341. {
  342. ShowMsg(QString::fromLocal8Bit("获取考试信息出错"), g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  343. }
  344. else
  345. {
  346. ShowMsg(getExamById.sMessage, g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  347. }
  348. }
  349. }
  350. void answerWidget::onGetExamRecordPaperStruct(CGetExamRecordPaperStruct getExamRecordPaperStruct)
  351. {
  352. if (getExamRecordPaperStruct.nCode == 200)
  353. {
  354. m_vPaperGroupStruct.swap(getExamRecordPaperStruct.vPaperGroupStruct);
  355. int nSize = m_vPaperGroupStruct.size();
  356. QString sQuestionId = "";
  357. for (int i = 0; i < nSize; ++i)
  358. {
  359. CPaperGroupStruct &pgs = m_vPaperGroupStruct[i];
  360. awQuestionNavigate *questionItem = new awQuestionNavigate(pgs);
  361. connect(questionItem, &awQuestionNavigate::showSubQuestion, this, [&](QString sQuestionId, int nOrder, bool bHasContent) {
  362. showQuestionByOrder(nOrder);
  363. /*if (bHasContent)
  364. {
  365. for (CQuestionStruct &qs : pgs.vQuestionStruct)
  366. {
  367. if (qs.sQuestionId == sQuestionId)
  368. {
  369. QString sGroupTitleText = QString::fromLocal8Bit("%1、%2 (共%3题)").arg(CCommonTools::Arab2Sinogram(pgs.nNumber)).arg(pgs.sGroupName).arg(pgs.nTotalSubquestion);
  370. QString sGroupProgressText = QString::fromLocal8Bit("完成进度(%1/%2)").arg(pgs.nAnsweredCount).arg(pgs.nTotalSubquestion);
  371. showSubQuestion(qs, nOrder, sGroupTitleText, sGroupProgressText);
  372. }
  373. }
  374. }
  375. else
  376. {
  377. getQuestionContent(sQuestionId, nOrder);
  378. }
  379. */
  380. });
  381. QListWidgetItem *pItem = new QListWidgetItem;
  382. ui->lw_aw_questionList->addItem(pItem);
  383. ui->lw_aw_questionList->setItemWidget(pItem, questionItem);
  384. int nHeight = questionItem->setUI(ui->lw_aw_questionList->width() - g_appInfoPtr->m_fRate*60);
  385. QSize size = pItem->sizeHint();
  386. size.setHeight(nHeight);
  387. pItem->setSizeHint(size);
  388. }
  389. }
  390. else
  391. {
  392. if(getExamRecordPaperStruct.sMessage.isEmpty())
  393. {
  394. ShowMsg(QString::fromLocal8Bit("获取考试结构出错"), g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  395. }
  396. else
  397. {
  398. ShowMsg(getExamRecordPaperStruct.sMessage, g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  399. }
  400. }
  401. }
  402. CAnsweredQuestion answerWidget::findQuestionByOrder(CFindExamQuestionList &feql, int nOrder)
  403. {
  404. for (int i = 0; i < feql.vAnsweredQuestion.size(); ++i)
  405. {
  406. if (feql.vAnsweredQuestion[i].nOrder == nOrder)
  407. {
  408. return feql.vAnsweredQuestion[i];
  409. }
  410. }
  411. }
  412. void answerWidget::onFindExamQuestionList(CFindExamQuestionList findExamQuestionList)
  413. {
  414. if (findExamQuestionList.nCode == 200)
  415. {
  416. int nTotal = 0;
  417. int nAnswered = 0;
  418. int nMarked = 0;
  419. int nSize = m_vPaperGroupStruct.size();
  420. for (int i = 0; i < nSize; ++i)
  421. {
  422. int nQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct.size();
  423. for (int j = 0; j < nQuestionSize; ++j)
  424. {
  425. int nSubQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct.size();
  426. for (int k = 0; k < nSubQuestionSize; ++k)
  427. {
  428. nTotal++;
  429. int nOrder = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct[k].nOrder;
  430. CAnsweredQuestion aq= findQuestionByOrder(findExamQuestionList, nOrder);
  431. m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct[k].bAnswered = aq.bIsAnswer;
  432. m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct[k].bMarked = aq.bIsSign;
  433. m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct[k].sStudentAnswer = aq.sStudentAnswer;
  434. if(!aq.sStudentAnswer.isEmpty() && (aq.sQuestionType == QUESTION_TYPE::SingleChoice ||
  435. aq.sQuestionType == QUESTION_TYPE::MultipleChoice ||
  436. aq.sQuestionType == QUESTION_TYPE::TrueOrFalse))
  437. {
  438. Json::Reader reader;
  439. Json::Value jAnswer = Json::Value::null;
  440. if (!reader.parse(aq.sStudentAnswer.toStdString(), jAnswer))
  441. {
  442. // ShowMsg(QString::fromLocal8Bit("解析题干出错!"), g_appInfoPtr->m_answerWidget);
  443. myDebug() << QString::fromLocal8Bit("解析答案出错!");
  444. }
  445. QString sAnswer = "";
  446. int nSize = jAnswer["sections"].size();
  447. for(int i = 0; i < nSize; ++i)
  448. {
  449. int bSize = jAnswer["sections"][i]["blocks"].size();
  450. for(int j = 0; j < bSize; ++j)
  451. {
  452. if(jAnswer["sections"][i]["blocks"][j]["type"] == "text")
  453. {
  454. sAnswer += jAnswer["sections"][i]["blocks"][j]["value"].asString().c_str();
  455. }
  456. }
  457. }
  458. m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct[k].sStudentAnswer = sAnswer;
  459. }
  460. if (aq.bIsAnswer)
  461. {
  462. nAnswered++;
  463. }
  464. if (aq.bIsSign)
  465. {
  466. nMarked++;
  467. }
  468. if (!aq.sAudioPlayTimes.isEmpty())
  469. {
  470. Json::Reader reader;
  471. Json::Value jAudioPlayTimes = Json::Value::null;
  472. if (reader.parse(aq.sAudioPlayTimes.toStdString(), jAudioPlayTimes))
  473. {
  474. for (int ja = 0; ja < jAudioPlayTimes.size(); ++ja)
  475. {
  476. Json::Value jAudioPlayItem = jAudioPlayTimes[ja];
  477. g_appInfoPtr->m_jAudioPlayedCount[jAudioPlayItem["name"].asString()] = jAudioPlayItem["times"].asInt();
  478. }
  479. }
  480. }
  481. }
  482. }
  483. }
  484. showQuestionByOrder(1);
  485. on_btn_all_clicked();
  486. ui->btn_allNum->setText(QString::number(nTotal));
  487. ui->btn_answeredNum->setText(QString::number(nAnswered));
  488. ui->btn_markedNum->setText(QString::number(nMarked));
  489. ui->btn_unansweredNum->setText(QString::number(nTotal - nAnswered));
  490. ui->pgb_answerProgress->setMaximum(nTotal);
  491. ui->pgb_answerProgress->setValue(nAnswered);
  492. refreshStatus();
  493. //开始答题
  494. CHttpRequestPackage hrp1;
  495. hrp1.sUri = "/api/ecs_oe_student/client/exam/process/startAnswer";
  496. hrp1.sParamList.push_back(QString("examRecordDataId,%1").arg(g_appInfoPtr->m_oExamInfo.nExamRecordDataId));
  497. hrp1.nRequestType = RequestType::rtStartAnswer;
  498. hrp1.eParamType = HttpParamType::hptUrl;
  499. g_httpBllPtr->post(hrp1);
  500. }
  501. else
  502. {
  503. if(findExamQuestionList.sMessage.isEmpty())
  504. {
  505. ShowMsg(QString::fromLocal8Bit("获取题目信息出错"), g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  506. }
  507. else
  508. {
  509. ShowMsg(findExamQuestionList.sMessage, g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  510. }
  511. }
  512. }
  513. void answerWidget::onGetExamProperty(CGetExamProperty getExamProperty)
  514. {
  515. if (getExamProperty.nCode == 200)
  516. {
  517. if (getExamProperty.sType == "SNAPSHOT_INTERVAL,PRACTICE_TYPE,FREEZE_TIME")
  518. {
  519. m_nSnapshotInterval = getExamProperty.nSnapshotInterval;
  520. g_appInfoPtr->m_oExamInfo.sPracticeType = getExamProperty.sPracticeType;
  521. m_nFreezeTime = getExamProperty.nFreezeTime;
  522. }
  523. }
  524. else
  525. {
  526. if(getExamProperty.sMessage.isEmpty())
  527. {
  528. ShowMsg(QString::fromLocal8Bit("获取考试信息出错"), g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  529. }
  530. else
  531. {
  532. ShowMsg(getExamProperty.sMessage, g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  533. }
  534. }
  535. }
  536. void answerWidget::onWeiXinAnswerEnabled(CWeiXinAnswerEnabled weiXinAnswerEnabled)
  537. {
  538. if (weiXinAnswerEnabled.nCode == 200)
  539. {
  540. g_appInfoPtr->m_bWeiXinAnswerEnabled = weiXinAnswerEnabled.bEnabled;
  541. }
  542. else
  543. {
  544. if(weiXinAnswerEnabled.sMessage.isEmpty())
  545. {
  546. ShowMsg(QString::fromLocal8Bit("获取考试信息失败"), g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  547. }
  548. else
  549. {
  550. ShowMsg(weiXinAnswerEnabled.sMessage, g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  551. }
  552. }
  553. }
  554. void answerWidget::showSubQuestion(CQuestionStruct &qs, int nOrder, QString sTitle, QString sProgress)
  555. {
  556. if (qs.sBody.isEmpty())
  557. {
  558. if (m_pQuestion != nullptr)
  559. {
  560. m_pQuestion.reset();
  561. }
  562. if (m_pQuestionSet != nullptr)
  563. {
  564. m_pQuestionSet.reset();
  565. }
  566. m_pQuestion = std::make_shared<question>(qs, nOrder, ui->btn_allNum->text().toInt(), ui->widget_aw_answerBG);
  567. connect(m_pQuestion.get(), &question::uploadAnswer, this, [&](int nIndex, __int64 timeStamp, QString sAnswer){
  568. uploadAnswer(nIndex, sAnswer);
  569. });
  570. connect(m_pQuestion.get(), &question::questionAnswered, this, [&](bool bAnswered, int nIndex){
  571. refreshStatus();
  572. int nSize = m_vPaperGroupStruct.size();
  573. for (int i = 0; i < nSize; ++i)
  574. {
  575. int nQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct.size();
  576. for (int j = 0; j < nQuestionSize; ++j)
  577. {
  578. int nSubQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct.size();
  579. for (int k = 0; k < nSubQuestionSize; ++k)
  580. {
  581. CSubQuestionStruct sqs = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct[k];
  582. if(sqs.nOrder == nIndex)
  583. {
  584. QString sGroupProgressText = QString::fromLocal8Bit("完成进度(%1/%2)").arg(m_vPaperGroupStruct[i].nAnsweredCount).arg(m_vPaperGroupStruct[i].nTotalSubquestion);
  585. m_pQuestion->setGroupInfo("", sGroupProgressText);
  586. break;
  587. }
  588. }
  589. }
  590. }
  591. });
  592. connect(m_pQuestion.get(), &question::markedItem, this, [&](bool bMarked, int nIndex){
  593. refreshStatus();
  594. });
  595. connect(m_pQuestion.get(), &question::previousQuestion, this, [&](int nOrder){
  596. if(nOrder > 1)
  597. {
  598. showQuestionByOrder(nOrder - 1);
  599. }
  600. });
  601. connect(m_pQuestion.get(), &question::nextQuestion, this, [&](int nOrder){
  602. showQuestionByOrder(nOrder + 1);
  603. });
  604. m_pQuestion->setGroupInfo(sTitle, sProgress);
  605. m_pQuestion->setUI(0, g_appInfoPtr->m_fRate * 86,
  606. ui->widget_aw_answerBG->width(), ui->widget_aw_answerBG->height() - g_appInfoPtr->m_fRate * (86 + 20));
  607. m_pQuestion->show();
  608. }
  609. else
  610. {
  611. if (m_pQuestion != nullptr)
  612. {
  613. m_pQuestion.reset();
  614. }
  615. if (m_pQuestionSet != nullptr)
  616. {
  617. m_pQuestionSet.reset();
  618. }
  619. m_pQuestionSet = std::make_shared<questionSet>(qs, nOrder, ui->btn_allNum->text().toInt(), ui->widget_aw_answerBG);
  620. connect(m_pQuestionSet.get(), &questionSet::uploadAnswer, this, [&](int nIndex, __int64 timeStamp, QString sAnswer){
  621. uploadAnswer(nIndex, sAnswer);
  622. });
  623. connect(m_pQuestionSet.get(), &questionSet::questionAnswered, this, [&](bool bAnswered, int nIndex){
  624. refreshStatus();
  625. int nSize = m_vPaperGroupStruct.size();
  626. for (int i = 0; i < nSize; ++i)
  627. {
  628. int nQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct.size();
  629. for (int j = 0; j < nQuestionSize; ++j)
  630. {
  631. int nSubQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct.size();
  632. for (int k = 0; k < nSubQuestionSize; ++k)
  633. {
  634. CSubQuestionStruct sqs = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct[k];
  635. if(sqs.nOrder == nIndex)
  636. {
  637. QString sGroupProgressText = QString::fromLocal8Bit("完成进度(%1/%2)").arg(m_vPaperGroupStruct[i].nAnsweredCount).arg(m_vPaperGroupStruct[i].nTotalSubquestion);
  638. m_pQuestionSet->setGroupInfo("", sGroupProgressText);
  639. break;
  640. }
  641. }
  642. }
  643. }
  644. });
  645. connect(m_pQuestionSet.get(), &questionSet::markedItem, this, [&](bool bMarked, int nIndex){
  646. refreshStatus();
  647. });
  648. connect(m_pQuestionSet.get(), &questionSet::previousQuestion, this, [&](int nOrder){
  649. if(nOrder > 1)
  650. {
  651. showQuestionByOrder(nOrder - 1);
  652. }
  653. });
  654. connect(m_pQuestionSet.get(), &questionSet::nextQuestion, this, [&](int nOrder){
  655. showQuestionByOrder(nOrder + 1);
  656. });
  657. m_pQuestionSet->setGroupInfo(sTitle, sProgress);
  658. m_pQuestionSet->setUI(0, g_appInfoPtr->m_fRate * 86,
  659. ui->widget_aw_answerBG->width(), ui->widget_aw_answerBG->height() - g_appInfoPtr->m_fRate * (86 + 20));
  660. m_pQuestionSet->show();
  661. }
  662. }
  663. void answerWidget::refreshStatus()
  664. {
  665. int nCount = ui->lw_aw_questionList->count();
  666. for(int i = 0; i < nCount; ++i)
  667. {
  668. awQuestionNavigate *questionItem = dynamic_cast<awQuestionNavigate*>(ui->lw_aw_questionList->itemWidget(ui->lw_aw_questionList->item(i)));
  669. if(questionItem)
  670. {
  671. questionItem->refreshStatus();
  672. }
  673. }
  674. int nTotal = 0;
  675. int nAnswered = 0;
  676. int nMarked = 0;
  677. int nSize = m_vPaperGroupStruct.size();
  678. for (int i = 0; i < nSize; ++i)
  679. {
  680. int nQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct.size();
  681. int nAnswerCount = 0;
  682. for (int j = 0; j < nQuestionSize; ++j)
  683. {
  684. int nSubQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct.size();
  685. for (int k = 0; k < nSubQuestionSize; ++k)
  686. {
  687. CSubQuestionStruct sqs = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct[k];
  688. nTotal++;
  689. if (sqs.bAnswered)
  690. {
  691. nAnswerCount++;
  692. nAnswered++;
  693. }
  694. if (sqs.bMarked)
  695. {
  696. nMarked++;
  697. }
  698. }
  699. }
  700. m_vPaperGroupStruct[i].nAnsweredCount = nAnswerCount;
  701. }
  702. ui->btn_allNum->setText(QString::number(nTotal));
  703. ui->btn_answeredNum->setText(QString::number(nAnswered));
  704. ui->btn_markedNum->setText(QString::number(nMarked));
  705. ui->btn_unansweredNum->setText(QString::number(nTotal - nAnswered));
  706. ui->pgb_answerProgress->setMaximum(nTotal);
  707. ui->pgb_answerProgress->setValue(nAnswered);
  708. }
  709. void answerWidget::showQuestionByOrder(int nOrder)
  710. {
  711. int nSize = m_vPaperGroupStruct.size();
  712. for (int i = 0; i < nSize; ++i)
  713. {
  714. int nQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct.size();
  715. for (int j = 0; j < nQuestionSize; ++j)
  716. {
  717. int nSubQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct.size();
  718. bool bHasContent = m_vPaperGroupStruct[i].vQuestionStruct[j].bHasContent;
  719. for (int k = 0; k < nSubQuestionSize; ++k)
  720. {
  721. CSubQuestionStruct &sqs = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct[k];
  722. sqs.bCurrent = false;
  723. if(sqs.nOrder == nOrder)
  724. {
  725. sqs.bCurrent = true;
  726. if (bHasContent)
  727. {
  728. QString sGroupTitleText = QString::fromLocal8Bit("%1、%2 (共%3题)").arg(CCommonTools::Arab2Sinogram(m_vPaperGroupStruct[i].nNumber)).arg(m_vPaperGroupStruct[i].sGroupName).arg(m_vPaperGroupStruct[i].nTotalSubquestion);
  729. QString sGroupProgressText = QString::fromLocal8Bit("完成进度(%1/%2)").arg(m_vPaperGroupStruct[i].nAnsweredCount).arg(m_vPaperGroupStruct[i].nTotalSubquestion);
  730. showSubQuestion(m_vPaperGroupStruct[i].vQuestionStruct[j], nOrder, sGroupTitleText, sGroupProgressText);
  731. }
  732. else
  733. {
  734. getQuestionContent(m_vPaperGroupStruct[i].vQuestionStruct[j].sQuestionId, nOrder);
  735. }
  736. }
  737. }
  738. }
  739. }
  740. refreshStatus();
  741. }
  742. void answerWidget::uploadAnswer(int nIndex, QString sAnswer)
  743. {
  744. int nSize = m_vPaperGroupStruct.size();
  745. for (int i = 0; i < nSize; ++i)
  746. {
  747. int nQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct.size();
  748. for (int j = 0; j < nQuestionSize; ++j)
  749. {
  750. int nSubQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct.size();
  751. for (int k = 0; k < nSubQuestionSize; ++k)
  752. {
  753. CSubQuestionStruct sqs = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct[k];
  754. if(!sqs.bUpload)
  755. {
  756. CHttpRequestPackage hrp;
  757. hrp.sUri = QString("/api/ecs_oe_student/client/exam/process/submitQuestionAnswer");
  758. hrp.nRequestType = RequestType::rtSubmitQuestionAnswer;
  759. hrp.eParamType = HttpParamType::hptCustomBody;
  760. hrp.sParamList.push_back(QString("CustomBody,%1").arg(sAnswer));
  761. hrp.sCommonStr = QString("%1,%2").arg(sqs.nOrder).arg(sqs.nVersion);
  762. g_httpBllPtr->post(hrp);
  763. }
  764. }
  765. }
  766. }
  767. }
  768. void answerWidget::onSubmitQuestionAnswer(CSubmitQuestionAnswer submitQuestionAnswer)
  769. {
  770. if(submitQuestionAnswer.nCode == 200)
  771. {
  772. int nSize = m_vPaperGroupStruct.size();
  773. for (int i = 0; i < nSize; ++i)
  774. {
  775. int nQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct.size();
  776. for (int j = 0; j < nQuestionSize; ++j)
  777. {
  778. int nSubQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct.size();
  779. for (int k = 0; k < nSubQuestionSize; ++k)
  780. {
  781. CSubQuestionStruct &sqs = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct[k];
  782. if(sqs.nOrder == submitQuestionAnswer.nOrder &&
  783. submitQuestionAnswer.nVersion >= sqs.nVersion)
  784. {
  785. sqs.bUpload = true;
  786. break;
  787. }
  788. }
  789. }
  790. }
  791. }
  792. else
  793. {
  794. if(submitQuestionAnswer.sMessage.isEmpty())
  795. {
  796. ShowMsg(QString::fromLocal8Bit("提交答案失败"), g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  797. }
  798. else
  799. {
  800. ShowMsg(submitQuestionAnswer.sMessage, g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  801. }
  802. }
  803. }
  804. void answerWidget::getQuestionContent(QString sQuestionId, int nOrder)
  805. {
  806. CHttpRequestPackage hrp;
  807. hrp.sUri = QString("/api/ecs_oe_student/client/exam/process/getQuestionContent")
  808. .arg(g_appInfoPtr->m_oExamInfo.nExamId);
  809. hrp.nRequestType = RequestType::rtGetQuestionContent;
  810. hrp.eParamType = HttpParamType::hptUrl;
  811. hrp.sCommonStr = sQuestionId + "," + QString::number(nOrder);
  812. hrp.sParamList.push_back(QString("questionId,%1").arg(sQuestionId));
  813. g_httpBllPtr->post(hrp);
  814. }
  815. void answerWidget::onGetQuestionContent(CGetQuestionContent getQuestionContent)
  816. {
  817. if (getQuestionContent.nCode == 200)
  818. {
  819. for (CPaperGroupStruct &pgs : m_vPaperGroupStruct)
  820. {
  821. for (CQuestionStruct &qs : pgs.vQuestionStruct)
  822. {
  823. if (qs.sQuestionId == getQuestionContent.sQuestionId)
  824. {
  825. qs.sBody = getQuestionContent.sBody;
  826. qs.sVersion = getQuestionContent.sVersion;
  827. qs.bhasAudios = getQuestionContent.bhasAudios;
  828. for (int i = 0; i < getQuestionContent.vSubQuestion.size(); ++i)
  829. {
  830. CSubQuestion sq = getQuestionContent.vSubQuestion[i];
  831. qs.vSubQuestionStruct[i].sBody = sq.sBody;
  832. qs.vSubQuestionStruct[i].vRightAnswer.swap(sq.vRightAnswer);
  833. qs.vSubQuestionStruct[i].vOptions.swap(sq.vOptions);
  834. }
  835. QString sGroupTitleText = QString::fromLocal8Bit("%1、%2 (共%3题)").arg(CCommonTools::Arab2Sinogram(pgs.nNumber)).arg(pgs.sGroupName).arg(pgs.nTotalSubquestion);
  836. QString sGroupProgressText = QString::fromLocal8Bit("完成进度(%1/%2)").arg(pgs.nAnsweredCount).arg(pgs.nTotalSubquestion);
  837. showSubQuestion(qs, getQuestionContent.sOrder.toInt(), sGroupTitleText, sGroupProgressText);
  838. break;
  839. }
  840. }
  841. }
  842. }
  843. else
  844. {
  845. if(getQuestionContent.sMessage.isEmpty())
  846. {
  847. ShowMsg(QString::fromLocal8Bit("获取题目内容失败"), g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  848. }
  849. else
  850. {
  851. ShowMsg(getQuestionContent.sMessage, g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  852. }
  853. }
  854. }
  855. void answerWidget::onStartAnswer(CStartAnswer startAnswer)
  856. {
  857. if(startAnswer.nCode == 200)
  858. {
  859. m_nUsedExamSeconds = startAnswer.nUsedExamSeconds;
  860. m_pHeartbeatTimer->start();
  861. heartBreat();
  862. //获取活体参数
  863. if (g_appInfoPtr->m_oExamInfo.bLivenessCheck)
  864. {
  865. CHttpRequestPackage hrp;
  866. hrp.sUri = QString("/api/ecs_core/org/getOrgPropertiesByGroupWithoutCache/%1/config4Edit1")
  867. .arg(g_appInfoPtr->m_sRootOrgId);
  868. hrp.nRequestType = RequestType::rtGetOrgPropertiesByGroupWithoutCache;
  869. g_httpBllPtr->get(hrp);
  870. {
  871. CHttpRequestPackage hrp;
  872. hrp.sUri = QString("/api/ecs_oe_student/client/exam/process/startFaceLiveVerify")
  873. .arg(g_appInfoPtr->m_sRootOrgId);
  874. hrp.nRequestType = RequestType::rtStartFaceLiveVerify;
  875. hrp.sParamList.push_back(QString("examRecordDataId,%1").arg(g_appInfoPtr->m_oExamInfo.nExamRecordDataId));
  876. hrp.eParamType = HttpParamType::hptUrl;
  877. g_httpBllPtr->post(hrp);
  878. }
  879. }
  880. }
  881. else
  882. {
  883. if(startAnswer.sMessage.isEmpty())
  884. {
  885. ShowMsg(QString::fromLocal8Bit("开始作答失败"), g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  886. }
  887. else
  888. {
  889. ShowMsg(startAnswer.sMessage, g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  890. }
  891. }
  892. }
  893. void answerWidget::onGetOrgPropertiesByGroupWithoutCache(CGetOrgPropertiesByGroupWithoutCache orgProperties)
  894. {
  895. if(orgProperties.nCode == 200)
  896. {
  897. g_appInfoPtr->m_oExamInfo.nActionNum = orgProperties.nActionNum;
  898. g_appInfoPtr->m_oExamInfo.sActionOptions = orgProperties.sActionOptions;
  899. g_appInfoPtr->m_oExamInfo.sActionOrder = orgProperties.sActionOrder;
  900. g_appInfoPtr->m_oExamInfo.nActionDuration = orgProperties.nActionDuration;
  901. g_appInfoPtr->m_oExamInfo.nActionAlert = orgProperties.nActionAlert;
  902. }
  903. else
  904. {
  905. if(orgProperties.sMessage.isEmpty())
  906. {
  907. ShowMsg(QString::fromLocal8Bit("获取考试信息失败"), g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  908. }
  909. else
  910. {
  911. ShowMsg(orgProperties.sMessage, g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  912. }
  913. }
  914. }
  915. void answerWidget::onStartFaceLiveVerify(CStartFaceLiveVerify startFaceLiveVerify)
  916. {
  917. if(startFaceLiveVerify.nCode == 200)
  918. {
  919. g_appInfoPtr->m_oExamInfo.nFaceLiveVerifyId = startFaceLiveVerify.nFaceLiveVerifyId;
  920. g_appInfoPtr->m_oExamInfo.nFaceVerifyTimes = startFaceLiveVerify.nTimes;
  921. g_appInfoPtr->m_oExamInfo.nFaceVerifyDoMinute = startFaceLiveVerify.nStartMinute;
  922. bShowLivenessTip = true;
  923. }
  924. else
  925. {
  926. if(startFaceLiveVerify.sMessage.isEmpty())
  927. {
  928. ShowMsg(QString::fromLocal8Bit("开启活体验证失败"), g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  929. }
  930. else
  931. {
  932. ShowMsg(startFaceLiveVerify.sMessage, g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  933. }
  934. }
  935. }
  936. void answerWidget::heartBreat()
  937. {
  938. CHttpRequestPackage hrp;
  939. hrp.sUri = QString("/api/ecs_oe_student/client/exam/process/examHeartbeat");
  940. hrp.nRequestType = RequestType::rtExamHeartbeat;
  941. g_httpBllPtr->post(hrp);
  942. }
  943. void answerWidget::onExamHeartbeat(CExamHeartbeat examHeartbeat)
  944. {
  945. if (examHeartbeat.nCode == 200)
  946. {
  947. if(m_nHeartBreatFailedCount > 0)
  948. {
  949. //m_pHeartbeatTimer->stop();
  950. m_pHeartbeatTimer->setInterval(60 * 1000);
  951. //m_pHeartbeatTimer->start();
  952. m_nHeartBreatFailedCount = 0;
  953. }
  954. m_nLeftSeconds = examHeartbeat.nLeftTime/1000;
  955. if(m_nEnterExamTime == 0)
  956. {
  957. m_nEnterExamTime = m_nLeftSeconds;
  958. }
  959. m_pCountDownTimer->start();
  960. //过程中人脸识别
  961. if(g_appInfoPtr->m_oExamInfo.bFaceCheck)
  962. {
  963. if(g_inProcessFace == nullptr)
  964. {
  965. g_inProcessFace = std::make_shared<CInprogressFace>();
  966. connect(g_inProcessFace.get(), &CInprogressFace::compareFailed, this, [&](QString sErrorMsg){
  967. ShowMsg(sErrorMsg, g_appInfoPtr->m_pAnsBgWidget);
  968. });
  969. startCapture();
  970. }
  971. m_nNextFaceCountSecond = m_nLeftSeconds - CCommonTools::genRandomNumber(1, 10);
  972. }
  973. }
  974. else
  975. {
  976. if(m_nHeartBreatFailedCount == 0)
  977. {
  978. // m_pHeartbeatTimer->stop();
  979. m_pHeartbeatTimer->setInterval(10 * 1000);
  980. //m_pHeartbeatTimer->start();
  981. }
  982. ++m_nHeartBreatFailedCount;
  983. if (m_nHeartBreatFailedCount >= m_nHeartBreatFailedExitCount)
  984. {
  985. //退出
  986. awTimeLeftTips *wExitExam = new awTimeLeftTips(MASK_POP_WIDGET_TYPE::wt_exitExam, (QWidget*)(this->parent()));
  987. connect(wExitExam, &awTimeLeftTips::timeLeftConfirm, this, [this, wExitExam]() {
  988. if (m_pNetWorkErrorTimerPtr)
  989. {
  990. m_pNetWorkErrorTimerPtr->stop();
  991. }
  992. delete wExitExam;
  993. emit gobackLogin();
  994. });
  995. wExitExam->show();
  996. if (m_pNetWorkErrorTimerPtr == nullptr)
  997. {
  998. m_pNetWorkErrorTimerPtr = std::make_shared<QTimer>();
  999. m_pNetWorkErrorTimerPtr->setInterval(30 * 1000);
  1000. connect(m_pNetWorkErrorTimerPtr.get(), &QTimer::timeout, [this, wExitExam]() {
  1001. m_pNetWorkErrorTimerPtr->stop();
  1002. delete wExitExam;
  1003. emit gobackLogin();
  1004. });
  1005. }
  1006. m_pNetWorkErrorTimerPtr->start();
  1007. }
  1008. if(examHeartbeat.sMessage.isEmpty())
  1009. {
  1010. ShowMsg(QString::fromLocal8Bit("网络连接异常,请检查网络设置"), g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  1011. }
  1012. else
  1013. {
  1014. ShowMsg(examHeartbeat.sMessage, g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  1015. }
  1016. }
  1017. }
  1018. void answerWidget::on_btn_handInPaper_clicked()
  1019. {
  1020. if(m_nFreezeTime*60 > m_nUsedExamSeconds + m_nEnterExamTime - m_nLeftSeconds)
  1021. {
  1022. ShowMsg(QString::fromLocal8Bit("冻结时间内不允许交卷"), this, MSG_ICON_TYPE::mit_error);
  1023. return;
  1024. }
  1025. if(m_pHandinPaper == nullptr)
  1026. {
  1027. m_pHandinPaper = std::make_shared<awHandinPaper>(ui->btn_answeredNum->text().toInt(),
  1028. ui->btn_unansweredNum->text().toInt(),
  1029. ui->btn_markedNum->text().toInt(), (QWidget*)(this->parent()));
  1030. connect(m_pHandinPaper.get(), &awHandinPaper::handinPaper, this, [&](){
  1031. m_pHandinPaper.reset();
  1032. //交卷
  1033. handinPaper();
  1034. });
  1035. connect(m_pHandinPaper.get(), &awHandinPaper::cancelHandinPaper, this, [&](){
  1036. m_pHandinPaper.reset();
  1037. });
  1038. }
  1039. m_pHandinPaper->show();
  1040. }
  1041. bool answerWidget::checkAnswer()
  1042. {
  1043. bool bRet = true;
  1044. int nSize = m_vPaperGroupStruct.size();
  1045. for (int i = 0; i < nSize; ++i)
  1046. {
  1047. int nQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct.size();
  1048. for (int j = 0; j < nQuestionSize; ++j)
  1049. {
  1050. int nSubQuestionSize = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct.size();
  1051. for (int k = 0; k < nSubQuestionSize; ++k)
  1052. {
  1053. CSubQuestionStruct sqs = m_vPaperGroupStruct[i].vQuestionStruct[j].vSubQuestionStruct[k];
  1054. if (!sqs.bUpload)
  1055. {
  1056. bRet = false;
  1057. CHttpRequestPackage hrp;
  1058. hrp.sUri = QString("/api/ecs_oe_student/client/exam/process/submitQuestionAnswer");
  1059. hrp.nRequestType = RequestType::rtSubmitQuestionAnswer;
  1060. hrp.eParamType = HttpParamType::hptCustomBody;
  1061. hrp.sParamList.push_back(QString("CustomBody,%1").arg(sqs.sUploadAnswer));
  1062. hrp.sCommonStr = QString("%1,%2").arg(sqs.nOrder).arg(sqs.nVersion);
  1063. g_httpBllPtr->post(hrp);
  1064. }
  1065. }
  1066. }
  1067. }
  1068. return bRet;
  1069. }
  1070. void answerWidget::handinPaper()
  1071. {
  1072. m_pCountDownTimer->stop();
  1073. if(g_appInfoPtr->m_oExamInfo.bFaceCheck)
  1074. {
  1075. stopCapture();
  1076. }
  1077. if(g_inProcessFace != nullptr)
  1078. {
  1079. stopCapture();
  1080. g_inProcessFace.reset();
  1081. }
  1082. if(m_pResumeExam == nullptr)
  1083. {
  1084. m_pResumeExam = std::make_shared<awResumeExam>((QWidget*)(this->parent()), QString::fromLocal8Bit("交卷中请稍候…"));
  1085. }
  1086. m_pResumeExam->show();
  1087. if (checkAnswer())
  1088. {
  1089. CHttpRequestPackage hrp;
  1090. hrp.sUri = QString("/api/ecs_oe_student/client/exam/process/endExam");
  1091. hrp.sCommonStr = __FILE__;
  1092. hrp.nRequestType = RequestType::rtEndExam;
  1093. g_httpBllPtr->post(hrp);
  1094. }
  1095. else
  1096. {
  1097. if (m_pHandinPaperTimer == nullptr)
  1098. {
  1099. m_pHandinPaperTimer = std::make_shared<QTimer>();
  1100. m_pHandinPaperTimer->setInterval(10 * 1000);
  1101. connect(m_pHandinPaperTimer.get(), &QTimer::timeout, this, [&]() {
  1102. if (checkAnswer())
  1103. {
  1104. m_pHandinPaperTimer->stop();
  1105. CHttpRequestPackage hrp;
  1106. hrp.sUri = QString("/api/ecs_oe_student/client/exam/process/endExam");
  1107. hrp.sCommonStr = __FILE__;
  1108. hrp.nRequestType = RequestType::rtEndExam;
  1109. g_httpBllPtr->post(hrp);
  1110. }
  1111. });
  1112. }
  1113. }
  1114. }
  1115. void answerWidget::onEndExam(CEndExam endExam)
  1116. {
  1117. if(endExam.sModuleName == __FILE__)
  1118. {
  1119. if (endExam.nCode == 200)
  1120. {
  1121. m_pHeartbeatTimer->stop();
  1122. m_pResumeExam.reset();
  1123. if (g_appInfoPtr->m_oExamInfo.sExamType == EXAM_TYPES::PRACTICE)
  1124. {
  1125. if(g_appInfoPtr->m_oExamInfo.sPracticeType != "NO_ANSWER")
  1126. {
  1127. emit showPracticeInfo();
  1128. }
  1129. else
  1130. {
  1131. emit gobackCourseList();
  1132. }
  1133. }
  1134. else
  1135. {
  1136. emit showExamScore();
  1137. }
  1138. }
  1139. else
  1140. {
  1141. QTimer::singleShot(5*1000, this, [](){
  1142. CHttpRequestPackage hrp;
  1143. hrp.sUri = QString("/api/ecs_oe_student/client/exam/process/endExam");
  1144. hrp.sCommonStr = __FILE__;
  1145. hrp.nRequestType = RequestType::rtEndExam;
  1146. g_httpBllPtr->post(hrp);
  1147. });
  1148. /*
  1149. if(endExam.sMessage.isEmpty())
  1150. {
  1151. ShowMsg(QString::fromLocal8Bit("交卷失败"), g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  1152. }
  1153. else
  1154. {
  1155. ShowMsg(endExam.sMessage, g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  1156. }*/
  1157. }
  1158. }
  1159. }
  1160. void answerWidget::on_btn_all_clicked()
  1161. {
  1162. int nCount = ui->lw_aw_questionList->count();
  1163. for(int i = 0; i < nCount; ++i)
  1164. {
  1165. awQuestionNavigate *questionItem = dynamic_cast<awQuestionNavigate*>(ui->lw_aw_questionList->itemWidget(ui->lw_aw_questionList->item(i)));
  1166. if(questionItem)
  1167. {
  1168. int nHeight = questionItem->setShowType(ITEM_SHOW_TYPE::ist_showAll);
  1169. QListWidgetItem *listItem = ui->lw_aw_questionList->item(i);
  1170. if(listItem)
  1171. {
  1172. QSize size = listItem->sizeHint();
  1173. size.setHeight(nHeight);
  1174. listItem->setSizeHint(size);
  1175. }
  1176. }
  1177. }
  1178. setChecked(ui->btn_all, true);
  1179. setChecked(ui->btn_marked, false);
  1180. setChecked(ui->btn_answered, false);
  1181. setChecked(ui->btn_unanswered, false);
  1182. }
  1183. void answerWidget::setChecked(QPushButton *btn, bool bChecked)
  1184. {
  1185. QString sNormal = QString(R"(QPushButton
  1186. {
  1187. outline:none;
  1188. background:rgba(242,243,247,1);
  1189. border-radius:%1px;
  1190. border:1px solid rgba(240,244,249,1);
  1191. font-size:%2px;
  1192. font-family:"Microsoft YaHei";
  1193. font-weight:500;
  1194. color:rgba(153,153,153,1);
  1195. padding-left:%3px;
  1196. text-align:left;
  1197. })").arg((int)(g_appInfoPtr->m_fRate*14))
  1198. .arg((int)(g_appInfoPtr->m_fRate*12))
  1199. .arg((int)(g_appInfoPtr->m_fRate*15));
  1200. QString sChecked = QString(R"(QPushButton
  1201. {
  1202. outline:none;
  1203. background:rgba(242,243,247,1);
  1204. border-radius:%1px;
  1205. border:1px solid rgba(189,200,217,1);
  1206. font-size:%2px;
  1207. font-family:"Microsoft YaHei";
  1208. font-weight:500;
  1209. color:rgba(153,153,153,1);
  1210. padding-left:%3px;
  1211. text-align:left;
  1212. })").arg((int)(g_appInfoPtr->m_fRate*14))
  1213. .arg((int)(g_appInfoPtr->m_fRate*12))
  1214. .arg((int)(g_appInfoPtr->m_fRate*15));
  1215. btn->setStyleSheet(bChecked ? sChecked : sNormal);
  1216. }
  1217. void answerWidget::on_btn_answered_clicked()
  1218. {
  1219. int nCount = ui->lw_aw_questionList->count();
  1220. for(int i = 0; i < nCount; ++i)
  1221. {
  1222. awQuestionNavigate *questionItem = dynamic_cast<awQuestionNavigate*>(ui->lw_aw_questionList->itemWidget(ui->lw_aw_questionList->item(i)));
  1223. if(questionItem)
  1224. {
  1225. int nHeight = questionItem->setShowType(ITEM_SHOW_TYPE::ist_showAnswered);
  1226. QListWidgetItem *listItem = ui->lw_aw_questionList->item(i);
  1227. if(listItem)
  1228. {
  1229. QSize size = listItem->sizeHint();
  1230. size.setHeight(nHeight);
  1231. listItem->setSizeHint(size);
  1232. }
  1233. }
  1234. }
  1235. setChecked(ui->btn_all, false);
  1236. setChecked(ui->btn_marked, false);
  1237. setChecked(ui->btn_answered, true);
  1238. setChecked(ui->btn_unanswered, false);
  1239. }
  1240. void answerWidget::on_btn_unanswered_clicked()
  1241. {
  1242. int nCount = ui->lw_aw_questionList->count();
  1243. for(int i = 0; i < nCount; ++i)
  1244. {
  1245. awQuestionNavigate *questionItem = dynamic_cast<awQuestionNavigate*>(ui->lw_aw_questionList->itemWidget(ui->lw_aw_questionList->item(i)));
  1246. if(questionItem)
  1247. {
  1248. int nHeight = questionItem->setShowType(ITEM_SHOW_TYPE::ist_showUnanswered);
  1249. QListWidgetItem *listItem = ui->lw_aw_questionList->item(i);
  1250. if(listItem)
  1251. {
  1252. QSize size = listItem->sizeHint();
  1253. size.setHeight(nHeight);
  1254. listItem->setSizeHint(size);
  1255. }
  1256. }
  1257. }
  1258. setChecked(ui->btn_all, false);
  1259. setChecked(ui->btn_marked, false);
  1260. setChecked(ui->btn_answered, false);
  1261. setChecked(ui->btn_unanswered, true);
  1262. }
  1263. void answerWidget::on_btn_marked_clicked()
  1264. {
  1265. int nCount = ui->lw_aw_questionList->count();
  1266. for(int i = 0; i < nCount; ++i)
  1267. {
  1268. awQuestionNavigate *questionItem = dynamic_cast<awQuestionNavigate*>(ui->lw_aw_questionList->itemWidget(ui->lw_aw_questionList->item(i)));
  1269. if(questionItem)
  1270. {
  1271. int nHeight = questionItem->setShowType(ITEM_SHOW_TYPE::ist_showMarked);
  1272. QListWidgetItem *listItem = ui->lw_aw_questionList->item(i);
  1273. if(listItem)
  1274. {
  1275. QSize size = listItem->sizeHint();
  1276. size.setHeight(nHeight);
  1277. listItem->setSizeHint(size);
  1278. }
  1279. }
  1280. }
  1281. setChecked(ui->btn_all, false);
  1282. setChecked(ui->btn_marked, true);
  1283. setChecked(ui->btn_answered, false);
  1284. setChecked(ui->btn_unanswered, false);
  1285. }
  1286. void answerWidget::on_btn_allNum_clicked()
  1287. {
  1288. on_btn_all_clicked();
  1289. }
  1290. void answerWidget::on_btn_answeredNum_clicked()
  1291. {
  1292. on_btn_answered_clicked();
  1293. }
  1294. void answerWidget::on_btn_unansweredNum_clicked()
  1295. {
  1296. on_btn_unanswered_clicked();
  1297. }
  1298. void answerWidget::on_btn_markedNum_clicked()
  1299. {
  1300. on_btn_marked_clicked();
  1301. }
  1302. void answerWidget::onRenderVideoFrame(const char* userId, TRTCVideoStreamType streamType, TRTCVideoFrame* frame)
  1303. {
  1304. if(g_clientVideoProcPtr->isCameraTest())
  1305. {
  1306. __int64 nServerTime = g_appInfoPtr->serverMTime();
  1307. if(nServerTime - m_lastFaceTime >= 100)
  1308. {
  1309. m_lastFaceTime = nServerTime;
  1310. cv::Mat matImg;
  1311. cv::cvtColor(cv::Mat(frame->height, frame->width, CV_8UC4, frame->data), matImg, CV_RGBA2RGB);
  1312. if(matImg.empty())
  1313. {
  1314. qDebug()<<"widgetCameraTest frame is empty";
  1315. return;
  1316. }
  1317. std::scoped_lock lock(m_imageMutex);
  1318. m_nCurImage = matImg;
  1319. }
  1320. }
  1321. }
  1322. void answerWidget::startCapture()
  1323. {
  1324. // if(m_pinitTimer == nullptr)
  1325. // {
  1326. // m_pinitTimer = std::make_shared<QTimer>();
  1327. // m_pinitTimer->setInterval(1000);
  1328. // connect(m_pinitTimer.get(), &QTimer::timeout, this, [&](){
  1329. // m_pinitTimer->stop();
  1330. // if(!m_cam.open(0))
  1331. // {
  1332. // ShowMsg(QString::fromLocal8Bit("打开摄像头失败"), this, MSG_ICON_TYPE::mit_error);
  1333. // return;
  1334. // }
  1335. // int inWidth = ui->widget_aw_face->width();
  1336. // m_cam.set(CV_CAP_PROP_FRAME_WIDTH, inWidth*3);
  1337. // int inHeight = ui->widget_aw_face->height();
  1338. // m_cam.set(CV_CAP_PROP_FRAME_HEIGHT, inHeight*3);
  1339. // m_cam.set(CV_CAP_PROP_FPS, 5);
  1340. // m_pVideoTimer->start();
  1341. // });
  1342. // }
  1343. g_clientVideoProcPtr->startTest(this);
  1344. g_inProcessFace->startFaceVerify(true);
  1345. if(m_pVideoTimer == nullptr)
  1346. {
  1347. m_pVideoTimer = std::make_shared<QTimer>();
  1348. m_pVideoTimer->setInterval(200);
  1349. m_nLastCaptureSecond = m_nLeftSeconds;
  1350. connect(m_pVideoTimer.get(), &QTimer::timeout, this, [&](){
  1351. cv::Mat frame;
  1352. {
  1353. std::scoped_lock lock(m_imageMutex);
  1354. frame = m_nCurImage;
  1355. }
  1356. if(frame.empty())
  1357. {
  1358. qDebug()<<"widgetCameraTest frame is empty";
  1359. return;
  1360. }
  1361. if (g_inProcessFace != nullptr &&
  1362. m_nLastCaptureSecond - m_nLeftSeconds > g_appInfoPtr->m_oExamInfo.nSnapshotInterval*60)
  1363. {
  1364. m_nLastCaptureSecond = m_nLeftSeconds;
  1365. g_inProcessFace->addImage(frame);
  1366. }
  1367. if(g_inProcessFace != nullptr &&
  1368. m_nNextFaceCountSecond > m_nLeftSeconds)
  1369. {
  1370. m_nNextFaceCountSecond = m_nLeftSeconds - CCommonTools::genRandomNumber(1, 10);
  1371. g_inProcessFace->addFaceCountImage(frame);
  1372. }
  1373. QImage img = CCommonTools::Mat2QImage(frame);
  1374. ui->widget_aw_face->setAutoFillBackground(true);
  1375. QPalette palette;
  1376. palette.setBrush(QPalette::Window, QBrush(img.scaled(ui->widget_aw_face->width(), ui->widget_aw_face->height())));
  1377. ui->widget_aw_face->setPalette(palette);
  1378. });
  1379. }
  1380. m_pVideoTimer->start();
  1381. }
  1382. void answerWidget::stopCapture()
  1383. {
  1384. m_pVideoTimer->stop();
  1385. g_inProcessFace->startFaceVerify(false);
  1386. g_clientVideoProcPtr->stopTest();
  1387. // m_pVideoTimer->stop();
  1388. // if(m_cam.isOpened())
  1389. // {
  1390. // m_cam.release();
  1391. // }
  1392. }