cloeViewPaper.cpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #include "cloeViewPaper.h"
  2. #include "ui_cloeViewPaper.h"
  3. #include "CAppInfo.h"
  4. #include "awMsgBox.h"
  5. #include "json/json.h"
  6. #include <QDesktopWidget>
  7. #include <QDateTime>
  8. cloeViewPaper::cloeViewPaper(QString sPaper, QWidget *parent) :
  9. QWidget(parent),
  10. ui(new Ui::cloeViewPaper)
  11. {
  12. ui->setupUi(this);
  13. initPaper(sPaper);
  14. initUI();
  15. m_pServerTime = std::make_shared<QTimer>();
  16. m_pServerTime->setInterval(1000);
  17. connect(m_pServerTime.get(), &QTimer::timeout, this, [&]() {
  18. ui->label_serverTime->adjustSize();
  19. ui->label_serverTime->setText(QString::fromLocal8Bit("服务器时间:%1")
  20. .arg(QDateTime::fromMSecsSinceEpoch(g_appInfoPtr->serverMTime()).toString("yyyy-MM-dd hh:mm:ss")));
  21. });
  22. m_pServerTime->start();
  23. }
  24. cloeViewPaper::~cloeViewPaper()
  25. {
  26. awMsgBox::clear(this);
  27. delete ui;
  28. }
  29. void cloeViewPaper::initUI()
  30. {
  31. QDesktopWidget *dekwiget = QApplication::desktop();
  32. setGeometry(0, 0, dekwiget->width(), dekwiget->height());
  33. ui->label_cl_company->setVisible(false);
  34. ui->widget_awbg_BG->setGeometry(0, 0, width(), height());
  35. ui->widget_cloe_viewpaper->setGeometry(g_appInfoPtr->m_fRate*20, g_appInfoPtr->m_fRate*56, width() - g_appInfoPtr->m_fRate*20*2,
  36. height() - g_appInfoPtr->m_fRate*(56 + 38));
  37. ui->label_clopvp_paperName->adjustSize();
  38. ui->label_clopvp_paperName->setGeometry((ui->widget_cloe_viewpaper->width() - ui->label_clopvp_paperName->width())/2,
  39. g_appInfoPtr->m_fRate * 30, ui->label_clopvp_paperName->width(), ui->label_clopvp_paperName->height());
  40. ui->label_clopvp_courseInfo->adjustSize();
  41. ui->label_clopvp_courseInfo->setGeometry((ui->widget_cloe_viewpaper->width() - ui->label_clopvp_courseInfo->width()) / 2,
  42. ui->label_clopvp_paperName->y() + ui->label_clopvp_paperName->height() + g_appInfoPtr->m_fRate * 10,
  43. ui->label_clopvp_courseInfo->width(), ui->label_clopvp_courseInfo->height());
  44. ui->label_HLine->setGeometry(0, ui->label_clopvp_courseInfo->y() + ui->label_clopvp_courseInfo->height() + g_appInfoPtr->m_fRate * 30,
  45. ui->widget_cloe_viewpaper->width(), g_appInfoPtr->m_fRate *1);
  46. ui->tb_clopvp_paper->setGeometry(g_appInfoPtr->m_fRate * 40, ui->label_HLine->y() + ui->label_HLine->height() + g_appInfoPtr->m_fRate * 30,
  47. ui->widget_cloe_viewpaper->width() - g_appInfoPtr->m_fRate * 40*2, ui->widget_cloe_viewpaper->height() - ui->label_HLine->y() - ui->label_HLine->height() - g_appInfoPtr->m_fRate * 30*2);
  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_clop_goback->setGeometry(ui->widget_awbg_top->width() - g_appInfoPtr->m_fRate*(20 + 108), g_appInfoPtr->m_fRate*12,
  56. g_appInfoPtr->m_fRate*108, g_appInfoPtr->m_fRate*32);
  57. ui->btn_clop_goback->setIconSize(QSize(g_appInfoPtr->m_fRate*14, g_appInfoPtr->m_fRate*14));
  58. ui->btn_clop_goback->setIcon(QIcon(":/images/icon-goback-list.png"));
  59. ui->label_cl_company->adjustSize();
  60. 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(),
  61. ui->label_cl_company->width(), ui->label_cl_company->height());
  62. ui->label_cl_version->adjustSize();
  63. ui->label_cl_version->setGeometry(ui->widget_awbg_BG->width() - g_appInfoPtr->m_fRate*30 - ui->label_cl_version->width(),
  64. ui->label_cl_company->y(), ui->label_cl_version->width(), ui->label_cl_version->height());
  65. ui->label_serverTime->adjustSize();
  66. ui->label_serverTime->setGeometry(ui->label_cl_version->x() - g_appInfoPtr->m_fRate*20 - ui->label_serverTime->width(),
  67. ui->label_cl_company->y(), ui->label_serverTime->width(), ui->label_serverTime->height());
  68. }
  69. void cloeViewPaper::setCourseCodeAndName(QString sCode, QString sName)
  70. {
  71. ui->label_awbg_exam->setText(QString::fromLocal8Bit("课程代码:%1 - 课程名称:%2").arg(sCode).arg(sName));
  72. ui->label_awbg_exam->adjustSize();
  73. }
  74. void cloeViewPaper::initPaper(QString sPaper)
  75. {
  76. Json::Reader reader;
  77. Json::Value jPaper = Json::Value::null;
  78. if (!reader.parse(sPaper.toStdString(), jPaper))
  79. {
  80. ShowMsg(QString::fromLocal8Bit("解析试卷出错!"), this, MSG_ICON_TYPE::mit_error);
  81. return;
  82. }
  83. ui->label_clopvp_paperName->setText(QString::fromLocal8Bit("%1 试卷").arg(jPaper["name"].asString().c_str()));
  84. ui->label_clopvp_courseInfo->setText(QString::fromLocal8Bit("课程代码:%1 | 本试卷满分%2分")
  85. .arg(jPaper["course"]["code"].asString().c_str()).arg(jPaper["totalScore"].asDouble()));
  86. QTextCursor cursor = ui->tb_clopvp_paper->textCursor();
  87. QTextBlockFormat textStyleFormat = cursor.blockFormat();
  88. textStyleFormat.setLineHeight(g_appInfoPtr->m_fRate * 5, QTextBlockFormat::LineDistanceHeight);
  89. cursor.setBlockFormat(textStyleFormat);
  90. int nIndex = 1;
  91. int nSize = jPaper["paperDetails"].size();
  92. for (int i = 0; i < nSize; ++i)
  93. {
  94. Json::Value jPaperDetails = jPaper["paperDetails"][i];
  95. QString sTitle = QString::fromLocal8Bit("%1、%2(本大题共%3小题,满分%4分)")
  96. .arg(jPaperDetails["cnNum"].asString().c_str()).arg(jPaperDetails["name"].asString().c_str())
  97. .arg(jPaperDetails["unitCount"].asString().c_str()).arg(jPaperDetails["score"].asString().c_str());
  98. QTextCharFormat fmt;
  99. QFont font;
  100. font.setFamily("Microsoft YaHei");
  101. font.setPixelSize(g_appInfoPtr->m_fRate * 16);
  102. font.setWeight(QFont::DemiBold);
  103. fmt.setFont(font);
  104. cursor.insertText(sTitle, fmt);
  105. cursor.insertText("\n");
  106. int nQuestionSize = jPaperDetails["paperDetailUnits"].size();
  107. for (int j = 0; j < nQuestionSize; ++j)
  108. {
  109. Json::Value jQuestion = jPaperDetails["paperDetailUnits"][j];
  110. QString sBody = QString::fromLocal8Bit("%1、%2(%3分)")
  111. .arg(nIndex).arg(jQuestion["question"]["quesBody"].asString().c_str())
  112. .arg(jQuestion["score"].asDouble());
  113. font.setPixelSize(g_appInfoPtr->m_fRate * 14);
  114. font.setWeight(QFont::Medium);
  115. fmt.setFont(font);
  116. cursor.insertText(QString::fromLocal8Bit("%1、")
  117. .arg(nIndex), fmt);
  118. cursor.insertHtml(jQuestion["question"]["quesBody"].asString().c_str());
  119. cursor.insertText(QString::fromLocal8Bit("(%1分)")
  120. .arg(jQuestion["score"].asDouble()), fmt);
  121. cursor.insertText("\n\r");
  122. }
  123. }
  124. }
  125. void cloeViewPaper::on_btn_clop_goback_clicked()
  126. {
  127. emit goback();
  128. }