awBackground.cpp 11 KB

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