awBackground.cpp 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. #include "awBackground.h"
  2. #include "ui_awBackground.h"
  3. #include "CAppInfo.h"
  4. #include "awMsgBox.h"
  5. #include <QDesktopWidget>
  6. awBackground::awBackground(AW_WIDGET_TYPE wt, QWidget *parent) :
  7. QWidget(parent),
  8. ui(new Ui::awBackground), m_wt(wt)
  9. {
  10. ui->setupUi(this);
  11. setStyleSheet(g_appInfoPtr->m_sQssStr);
  12. initUI();
  13. g_appInfoPtr->m_pAnsBgWidget = this;
  14. if (!g_appInfoPtr->m_oExamInfo.sCourseCode.isEmpty() &&
  15. !g_appInfoPtr->m_oExamInfo.sCourseName.isEmpty())
  16. {
  17. ui->label_awbg_exam->setText(QString::fromLocal8Bit("%1(%2)")
  18. .arg(g_appInfoPtr->m_oExamInfo.sCourseName)
  19. .arg(g_appInfoPtr->m_oExamInfo.sCourseCode));
  20. }
  21. qRegisterMetaType<CGetCourseInfo>("CGetCourseInfo");
  22. connect(g_httpBllPtr.get(), &CHttpBll::sgnGetCourseInfo, this, &awBackground::onGetCourseInfo);
  23. m_pServerTime = std::make_shared<QTimer>();
  24. m_pServerTime->setInterval(1000);
  25. connect(m_pServerTime.get(), &QTimer::timeout, this, [&]() {
  26. ui->label_serverTime->adjustSize();
  27. ui->label_serverTime->setText(QString::fromLocal8Bit("服务器时间:%1")
  28. .arg(QDateTime::fromMSecsSinceEpoch(g_appInfoPtr->serverMTime()).toString("yyyy-MM-dd hh:mm:ss")));
  29. });
  30. m_pServerTime->start();
  31. }
  32. awBackground::~awBackground()
  33. {
  34. g_appInfoPtr->m_pAnsBgWidget = nullptr;
  35. awMsgBox::clear(this);
  36. delete ui;
  37. }
  38. void awBackground::initUI()
  39. {
  40. //ui->label_awbg_exam->setText(QString::fromLocal8Bit("%1(%2)").arg().arg());
  41. ui->label_awbg_student->setText(QString::fromLocal8Bit("%1 | %2 | %3 | %4")
  42. .arg(g_appInfoPtr->m_sStudentName).arg(g_appInfoPtr->m_sStudentCode)
  43. .arg(g_appInfoPtr->m_sStudentIdentityNumber).arg(g_appInfoPtr->m_sOrgName));
  44. QDesktopWidget *dekwiget = QApplication::desktop();
  45. setGeometry(0, 0, dekwiget->width(), dekwiget->height());
  46. ui->widget_awbg_BG->setGeometry(0, 0, width(), height());
  47. ui->widget_awbg_top->setGeometry(0, 0, ui->widget_awbg_BG->width(), g_appInfoPtr->m_fRate*112);
  48. ui->label_awbg_examIcon->setGeometry(g_appInfoPtr->m_fRate*30, g_appInfoPtr->m_fRate*20,
  49. g_appInfoPtr->m_fRate*16, g_appInfoPtr->m_fRate*16);
  50. ui->label_awbg_exam->adjustSize();
  51. ui->label_awbg_exam->setGeometry(ui->label_awbg_examIcon->x() + ui->label_awbg_examIcon->width() + g_appInfoPtr->m_fRate*10,
  52. ui->label_awbg_examIcon->y() + (ui->label_awbg_examIcon->height() - ui->label_awbg_exam->height())/2,
  53. ui->label_awbg_exam->width(), ui->label_awbg_exam->height());
  54. ui->btn_aw_close->setVisible(!g_appInfoPtr->m_bFullScreenTop);
  55. ui->btn_aw_minisize->setVisible(!g_appInfoPtr->m_bFullScreenTop);
  56. ui->label_awbg_student->adjustSize();
  57. int nStudentLeft = ui->widget_awbg_top->width() - g_appInfoPtr->m_fRate*30 - ui->label_awbg_student->width();
  58. if(!g_appInfoPtr->m_bFullScreenTop)
  59. {
  60. ui->btn_aw_close->setGeometry(ui->widget_awbg_top->width() - g_appInfoPtr->m_fRate*(30 + 24),
  61. ui->label_awbg_exam->y(), g_appInfoPtr->m_fRate * 24, g_appInfoPtr->m_fRate * 24);
  62. ui->btn_aw_minisize->setGeometry(ui->btn_aw_close->x() - g_appInfoPtr->m_fRate*6 - ui->btn_aw_close->width(),
  63. ui->btn_aw_close->y(), ui->btn_aw_close->width(), ui->btn_aw_close->height());
  64. nStudentLeft = ui->btn_aw_minisize->x() - g_appInfoPtr->m_fRate*20 - ui->label_awbg_student->width();
  65. }
  66. ui->label_awbg_student->setGeometry(nStudentLeft,
  67. ui->label_awbg_exam->y(), ui->label_awbg_student->width(), ui->label_awbg_student->height());
  68. ui->label_awbg_studentIcon->setGeometry(ui->label_awbg_student->x() - g_appInfoPtr->m_fRate*(10 + 16),
  69. ui->label_awbg_examIcon->y(), ui->label_awbg_examIcon->width(), ui->label_awbg_examIcon->height());
  70. ui->label_cl_company->adjustSize();
  71. ui->label_cl_company->setGeometry(g_appInfoPtr->m_fRate*30, ui->widget_awbg_BG->height() - g_appInfoPtr->m_fRate*10 - ui->label_cl_company->height(),
  72. ui->label_cl_company->width(), ui->label_cl_company->height());
  73. if(!g_appInfoPtr->m_sVersionCode.isEmpty())
  74. {
  75. ui->label_cl_version->setText(QString("V%1").arg(g_appInfoPtr->m_sVersionCode));
  76. }
  77. ui->label_cl_version->adjustSize();
  78. ui->label_cl_version->setGeometry(ui->widget_awbg_BG->width() - g_appInfoPtr->m_fRate*30 - ui->label_cl_version->width(),
  79. ui->label_cl_company->y(), ui->label_cl_version->width(), ui->label_cl_version->height());
  80. ui->label_serverTime->setText(QString::fromLocal8Bit("服务器时间:%1")
  81. .arg(QDateTime::fromMSecsSinceEpoch(g_appInfoPtr->serverMTime()).toString("yyyy-MM-dd hh:mm:ss")));
  82. ui->label_serverTime->adjustSize();
  83. ui->label_serverTime->setGeometry(ui->label_cl_version->x() - g_appInfoPtr->m_fRate*20 - ui->label_serverTime->width(),
  84. ui->label_cl_company->y(), ui->label_serverTime->width(), ui->label_serverTime->height());
  85. if (m_wt == AW_WIDGET_TYPE::awwt_waitExam)
  86. {
  87. if(m_pWaitExam == nullptr)
  88. {
  89. m_pWaitExam = std::make_shared<awWaitExam>(this);
  90. connect(m_pWaitExam.get(), &awWaitExam::exitEaxm, this, [&](){
  91. m_pWaitExam.reset();
  92. emit closeWidget();
  93. });
  94. connect(m_pWaitExam.get(), &awWaitExam::enterExam, this, [&](){
  95. m_pWaitExam.reset();
  96. CHttpRequestPackage hrp;
  97. hrp.sUri = QString("/api/ecs_oe_student/client/exam/process/getCourseInfo/%1").arg(g_appInfoPtr->m_oExamInfo.nExamRecordDataId);
  98. hrp.sParamList.push_back(QString("examRecordDataId,%1").arg(g_appInfoPtr->m_oExamInfo.nExamRecordDataId));
  99. hrp.nRequestType = RequestType::rtGetCourseInfo;
  100. hrp.eParamType = HttpParamType::hptUrl;
  101. g_httpBllPtr->post(hrp);
  102. m_wt = AW_WIDGET_TYPE::awwt_answerWidget;
  103. });
  104. }
  105. m_pWaitExam->setUI(g_appInfoPtr->m_fRate*20, g_appInfoPtr->m_fRate*56, width() - g_appInfoPtr->m_fRate*20*2,
  106. height() - g_appInfoPtr->m_fRate*(56 + 38));
  107. m_pWaitExam->show();
  108. }
  109. else if (m_wt == AW_WIDGET_TYPE::awwt_answerWidget)
  110. {
  111. CHttpRequestPackage hrp;
  112. hrp.sUri = QString("/api/ecs_oe_student/client/exam/process/getCourseInfo/%1").arg(g_appInfoPtr->m_oExamInfo.nExamRecordDataId);
  113. hrp.sParamList.push_back(QString("examRecordDataId,%1").arg(g_appInfoPtr->m_oExamInfo.nExamRecordDataId));
  114. hrp.nRequestType = RequestType::rtGetCourseInfo;
  115. hrp.eParamType = HttpParamType::hptUrl;
  116. g_httpBllPtr->post(hrp);
  117. }
  118. else if (m_wt == AW_WIDGET_TYPE::awwt_examScore)
  119. {
  120. CHttpRequestPackage hrp;
  121. hrp.sUri = QString("/api/ecs_oe_student/client/exam/process/getCourseInfo/%1").arg(g_appInfoPtr->m_oExamInfo.nExamRecordDataId);
  122. hrp.sParamList.push_back(QString("examRecordDataId,%1").arg(g_appInfoPtr->m_oExamInfo.nExamRecordDataId));
  123. hrp.nRequestType = RequestType::rtGetCourseInfo;
  124. hrp.eParamType = HttpParamType::hptUrl;
  125. g_httpBllPtr->post(hrp);
  126. if(m_pExamScore == nullptr)
  127. {
  128. m_pExamScore = std::make_shared<awExamScore>(this);
  129. connect(m_pExamScore.get(), &awExamScore::goHomePage, this, [&](){
  130. emit closeWidget();
  131. });
  132. }
  133. m_pExamScore->setUI(g_appInfoPtr->m_fRate * 20, g_appInfoPtr->m_fRate * 56, width() - g_appInfoPtr->m_fRate * 20 * 2,
  134. height() - g_appInfoPtr->m_fRate*(56 + 38));
  135. m_pExamScore->show();
  136. }
  137. }
  138. void awBackground::showExamAnswer()
  139. {
  140. if(m_pAnswerWidget == nullptr)
  141. {
  142. m_pAnswerWidget = std::make_shared<answerWidget>(this);
  143. connect(m_pAnswerWidget.get(), &answerWidget::gobackLogin, this, &awBackground::gobackLogin);
  144. connect(m_pAnswerWidget.get(), &answerWidget::showPracticeInfo, this, [&](){
  145. m_pAnswerWidget.reset();
  146. emit showPracticeInfo();
  147. });
  148. connect(m_pAnswerWidget.get(), &answerWidget::gobackCourseList, this, [&](){
  149. m_pAnswerWidget.reset();
  150. emit closeWidget();
  151. });
  152. connect(m_pAnswerWidget.get(), &answerWidget::showExamScore, this, [&](){
  153. m_pAnswerWidget.reset();
  154. m_wt = AW_WIDGET_TYPE::awwt_examScore;
  155. if(m_pExamScore == nullptr)
  156. {
  157. m_pExamScore = std::make_shared<awExamScore>(this);
  158. connect(m_pExamScore.get(), &awExamScore::goHomePage, this, [&](){
  159. emit closeWidget();
  160. });
  161. }
  162. m_pExamScore->setUI(g_appInfoPtr->m_fRate * 20, g_appInfoPtr->m_fRate * 56, width() - g_appInfoPtr->m_fRate * 20 * 2,
  163. height() - g_appInfoPtr->m_fRate*(56 + 38));
  164. m_pExamScore->show();
  165. });
  166. }
  167. m_pAnswerWidget->setUI(g_appInfoPtr->m_fRate * 20, g_appInfoPtr->m_fRate * 56, width() - g_appInfoPtr->m_fRate * 20 * 2,
  168. height() - g_appInfoPtr->m_fRate*(56 + 38));
  169. m_pAnswerWidget->show();
  170. }
  171. void awBackground::onGetCourseInfo(CGetCourseInfo getCourseInfo)
  172. {
  173. if (getCourseInfo.nCode == 200)
  174. {
  175. ui->label_awbg_exam->setText(QString::fromLocal8Bit("%1(%2)").arg(getCourseInfo.sCourseName).arg(getCourseInfo.sCourseCode));
  176. g_appInfoPtr->m_oExamInfo.sCourseCode = getCourseInfo.sCourseCode;
  177. g_appInfoPtr->m_oExamInfo.sCourseName = getCourseInfo.sCourseName;
  178. if(m_wt == AW_WIDGET_TYPE::awwt_answerWidget)
  179. {
  180. showExamAnswer();
  181. }
  182. }
  183. else
  184. {
  185. if(getCourseInfo.sMessage.isEmpty())
  186. {
  187. ShowMsg(QString::fromLocal8Bit("获取科目信息失败"), g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  188. }
  189. else
  190. {
  191. ShowMsg(getCourseInfo.sMessage, g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  192. }
  193. }
  194. }
  195. void awBackground::on_btn_aw_close_clicked()
  196. {
  197. QApplication::quit();
  198. }
  199. void awBackground::on_btn_aw_minisize_clicked()
  200. {
  201. emit minisize();
  202. }