awWaitExam.cpp 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1.  #include "awWaitExam.h"
  2. #include "ui_awWaitExam.h"
  3. #include "CAppInfo.h"
  4. #include "awMsgBox.h"
  5. #include <QListWidgetItem>
  6. #include <QHBoxLayout>
  7. #include <QLabel>
  8. awWaitExam::awWaitExam(QWidget *parent) :
  9. QWidget(parent),
  10. ui(new Ui::awWaitExam)
  11. {
  12. ui->setupUi(this);
  13. setStyleSheet(g_appInfoPtr->m_sQssStr);
  14. qRegisterMetaType<CGetExamProperty>("CGetExamProperty");
  15. connect(g_httpBllPtr.get(), &CHttpBll::sgnGetExamProperty, this, &awWaitExam::onGetExamProperty);
  16. qRegisterMetaType<CGetExamRecordPaperStruct>("CGetExamRecordPaperStruct");
  17. connect(g_httpBllPtr.get(), &CHttpBll::sgnGetExamRecordPaperStruct, this, &awWaitExam::onGetExamRecordPaperStruct);
  18. qRegisterMetaType<CStartExam>("CStartExam");
  19. connect(g_httpBllPtr.get(), &CHttpBll::sgnStartExam, this, &awWaitExam::onStartExam);
  20. CHttpRequestPackage hrp;
  21. hrp.sUri = QString("/api/ecs_exam_work/exam/getExamPropertyFromCacheByStudentSession/%1/%2")
  22. .arg(g_appInfoPtr->m_oExamInfo.nExamId).arg("BEFORE_EXAM_REMARK");
  23. hrp.nRequestType = RequestType::rtGetExamProperty;
  24. hrp.sCommonStr = "BEFORE_EXAM_REMARK";
  25. g_httpBllPtr->get(hrp);
  26. CHttpRequestPackage hrp1;
  27. hrp1.sUri = "/api/ecs_oe_student/client/exam/process/startExam";
  28. hrp1.nRequestType = RequestType::rtStartExam;
  29. hrp1.sParamList.push_back(QString("examStudentId,%1").arg(g_appInfoPtr->m_oExamInfo.nExamStudentId));
  30. hrp1.eParamType = HttpParamType::hptUrl;
  31. g_httpBllPtr->post(hrp1);
  32. bHasStruct = false;
  33. nCountDownCount = 60 * 2;
  34. m_pTimer = std::make_shared<QTimer>();
  35. m_pTimer->setInterval(1000);
  36. m_pTimer->start();
  37. connect(m_pTimer.get(), &QTimer::timeout, this, [&]() {
  38. --nCountDownCount;
  39. ui->btn_we_startExam->setText(QString::fromLocal8Bit("接受以上条款,开始考试(倒计时:%1:%2:%3)")
  40. .arg(nCountDownCount / 3600, 2, 10, QChar('0'))
  41. .arg((nCountDownCount % 3600) / 60, 2, 10, QChar('0'))
  42. .arg(nCountDownCount % 60, 2, 10, QChar('0')));
  43. if (bHasStruct && nCountDownCount < 110)
  44. {
  45. ui->btn_we_startExam->setStyleSheet(QString(R"( QPushButton
  46. {
  47. background:rgba(19,187,138,1);
  48. border-radius:%1px;
  49. font-size:%2px;
  50. font-family:"Microsoft YaHei";
  51. font-weight:600;
  52. color:rgba(255,255,255,0.5);
  53. })").arg((int)(g_appInfoPtr->m_fRate*10))
  54. .arg((int)(g_appInfoPtr->m_fRate * 14)));
  55. }
  56. if (nCountDownCount == 0)
  57. {
  58. m_pTimer->stop();
  59. emit enterExam();
  60. return;
  61. }
  62. });
  63. }
  64. awWaitExam::~awWaitExam()
  65. {
  66. delete ui;
  67. }
  68. void awWaitExam::setUI(const int nLeft, const int nTop, const int nWidth, const int nHeight)
  69. {
  70. setGeometry(nLeft, nTop, nWidth, nHeight);
  71. ui->widget_we_preNotice->setGeometry(0, 0, width()*970/(970+270), height());
  72. ui->widget_we_paperStruct->setGeometry(ui->widget_we_preNotice->x() + ui->widget_we_preNotice->width() + g_appInfoPtr->m_fRate*20, 0,
  73. width() - ui->widget_we_preNotice->width() - g_appInfoPtr->m_fRate*20, height());
  74. ui->label_we_notice->adjustSize();
  75. ui->label_we_notice->setGeometry(g_appInfoPtr->m_fRate*40, g_appInfoPtr->m_fRate*30,
  76. ui->label_we_notice->width(), ui->label_we_notice->height());
  77. ui->txtb_we_prenotice->setGeometry(ui->label_we_notice->x(), ui->label_we_notice->y() + ui->label_we_notice->height() + g_appInfoPtr->m_fRate*20,
  78. ui->widget_we_preNotice->width() - g_appInfoPtr->m_fRate*40*2, g_appInfoPtr->m_fRate*390);
  79. ui->btn_we_startExam->setGeometry((ui->widget_we_preNotice->width() - g_appInfoPtr->m_fRate*380)/2,
  80. ui->txtb_we_prenotice->y() + ui->txtb_we_prenotice->height() + g_appInfoPtr->m_fRate*110,
  81. g_appInfoPtr->m_fRate*380, g_appInfoPtr->m_fRate*40);
  82. ui->label_we_struct->adjustSize();
  83. ui->label_we_struct->setGeometry(g_appInfoPtr->m_fRate*30, g_appInfoPtr->m_fRate*20,
  84. ui->label_we_struct->width(), ui->label_we_struct->height());
  85. ui->label_we_totalScore->adjustSize();
  86. ui->label_we_totalScore->setGeometry(ui->widget_we_paperStruct->width() - g_appInfoPtr->m_fRate*30 - ui->label_we_totalScore->width(),
  87. ui->label_we_struct->y() + (ui->label_we_struct->height() - ui->label_we_totalScore->height())/2,
  88. ui->label_we_totalScore->width(), ui->label_we_totalScore->height());
  89. ui->lw_we_struct->setGeometry(ui->label_we_struct->x(), ui->label_we_struct->y() + ui->label_we_struct->height() + g_appInfoPtr->m_fRate*20,
  90. ui->widget_we_paperStruct->width() - g_appInfoPtr->m_fRate*30*2,
  91. ui->widget_we_paperStruct->height() - ui->label_we_struct->y() - ui->label_we_struct->height() - g_appInfoPtr->m_fRate*(20 + 30));
  92. }
  93. void awWaitExam::onStartExam(CStartExam startExam)
  94. {
  95. if (startExam.nCode == 200)
  96. {
  97. g_appInfoPtr->m_oExamInfo.nExamRecordDataId = startExam.nExamRecordDataId;
  98. g_appInfoPtr->m_oExamInfo.sCourseCode = startExam.sCourseCode;
  99. g_appInfoPtr->m_oExamInfo.sCourseName = startExam.sCourseName;
  100. g_appInfoPtr->m_oExamInfo.nFaceVerifyMinute = startExam.nFaceVerifyMinute;
  101. CHttpRequestPackage hrp1;
  102. hrp1.sUri = "/api/ecs_oe_student/client/exam/process/getExamRecordPaperStruct";
  103. hrp1.sParamList.push_back(QString("examRecordDataId,%1").arg(g_appInfoPtr->m_oExamInfo.nExamRecordDataId));
  104. hrp1.nRequestType = RequestType::rtGetExamRecordPaperStruct;
  105. hrp1.eParamType = HttpParamType::hptUrl;
  106. g_httpBllPtr->post(hrp1);
  107. }
  108. else
  109. {
  110. if(startExam.sMessage.isEmpty())
  111. {
  112. ShowMsg(QString::fromLocal8Bit("开始考试失败"), g_appInfoPtr->m_pAnsBgWidget);
  113. }
  114. else
  115. {
  116. ShowMsg(startExam.sMessage, g_appInfoPtr->m_pAnsBgWidget);
  117. }
  118. }
  119. }
  120. void awWaitExam::onGetExamRecordPaperStruct(CGetExamRecordPaperStruct getExamRecordPaperStruct)
  121. {
  122. if (getExamRecordPaperStruct.nCode == 200)
  123. {
  124. int nSize = getExamRecordPaperStruct.vPaperGroupStruct.size();
  125. double tTotalScore = 0;
  126. for (int i = 0; i < nSize; ++i)
  127. {
  128. CPaperGroupStruct pgs = getExamRecordPaperStruct.vPaperGroupStruct[i];
  129. QListWidgetItem *pItem = new QListWidgetItem;
  130. QSize size = pItem->sizeHint();
  131. size.setHeight(g_appInfoPtr->m_fRate * 37);
  132. pItem->setSizeHint(size);
  133. ui->lw_we_struct->addItem(pItem);
  134. QWidget *w = new QWidget;
  135. // w->setStyleSheet(QString("QWidget{background:rgba(19, 187, 138, 1); border-radius:%1px}").arg((int)(g_appInfoPtr->m_fRate*10)));
  136. QHBoxLayout *l = new QHBoxLayout;
  137. QString sLabelSubjectStyle = QString(R"(QLabel{
  138. font-size:%1px;
  139. font-family:"Microsoft YaHei";
  140. font-weight:500;
  141. color:rgba(68,68,68,1);})").arg((int)(g_appInfoPtr->m_fRate * 12));
  142. QString sLabelSubjectInfoStyle = QString(R"(QLabel{
  143. font-size:%1px;
  144. font-family:"Microsoft YaHei";
  145. font-weight:500;
  146. color:rgba(153,153,153,1);})").arg((int)(g_appInfoPtr->m_fRate * 12));
  147. QLabel *label_subject = new QLabel;
  148. label_subject->setText(QString::fromLocal8Bit("%1、%2").arg(i+1).arg(pgs.sGroupName));
  149. label_subject->setStyleSheet(sLabelSubjectStyle);
  150. label_subject->adjustSize();
  151. QLabel *label_subjectInfo = new QLabel;
  152. label_subjectInfo->setText(QString::fromLocal8Bit("共%1题,共%2分").arg(pgs.nTotalSubquestion).arg(pgs.fGroupScore));
  153. label_subjectInfo->setStyleSheet(sLabelSubjectInfoStyle);
  154. l->setContentsMargins(0, 0, 0, 0);
  155. l->addWidget(label_subject);
  156. l->addStretch();
  157. l->addWidget(label_subjectInfo);
  158. w->setLayout(l);
  159. ui->lw_we_struct->setItemWidget(pItem, w);
  160. tTotalScore += pgs.fGroupScore;
  161. }
  162. ui->label_we_totalScore->setText(QString::fromLocal8Bit("总分:%1").arg(tTotalScore));
  163. bHasStruct = true;
  164. }
  165. else
  166. {
  167. if(getExamRecordPaperStruct.sMessage.isEmpty())
  168. {
  169. ShowMsg(QString::fromLocal8Bit("获取试卷结构失败"), g_appInfoPtr->m_pAnsBgWidget);
  170. }
  171. else
  172. {
  173. ShowMsg(getExamRecordPaperStruct.sMessage, g_appInfoPtr->m_pAnsBgWidget);
  174. }
  175. }
  176. }
  177. void awWaitExam::onGetExamProperty(CGetExamProperty getExamProperty)
  178. {
  179. if (getExamProperty.nCode == 200)
  180. {
  181. if (getExamProperty.sType == "BEFORE_EXAM_REMARK")
  182. {
  183. ui->txtb_we_prenotice->insertHtml(getExamProperty.sBeforeExamRemark);
  184. }
  185. }
  186. else
  187. {
  188. if(getExamProperty.sMessage.isEmpty())
  189. {
  190. ShowMsg(QString::fromLocal8Bit("获取考试信息失败"), g_appInfoPtr->m_pAnsBgWidget);
  191. }
  192. else
  193. {
  194. ShowMsg(getExamProperty.sMessage, g_appInfoPtr->m_pAnsBgWidget);
  195. }
  196. }
  197. }
  198. void awWaitExam::on_btn_we_startExam_clicked()
  199. {
  200. if (bHasStruct && nCountDownCount < 110)
  201. {
  202. m_pTimer->stop();
  203. emit enterExam();
  204. }
  205. }