awBackground.cpp 10 KB

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