cloeViewPaper.cpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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->widget_awbg_BG->setGeometry(0, 0, width(), height());
  34. ui->widget_cloe_viewpaper->setGeometry(g_appInfoPtr->m_fRate*20, g_appInfoPtr->m_fRate*56, width() - g_appInfoPtr->m_fRate*20*2,
  35. height() - g_appInfoPtr->m_fRate*(56 + 38));
  36. ui->label_clopvp_paperName->adjustSize();
  37. ui->label_clopvp_paperName->setGeometry((ui->widget_cloe_viewpaper->width() - ui->label_clopvp_paperName->width())/2,
  38. g_appInfoPtr->m_fRate * 30, ui->label_clopvp_paperName->width(), ui->label_clopvp_paperName->height());
  39. ui->label_clopvp_courseInfo->adjustSize();
  40. ui->label_clopvp_courseInfo->setGeometry((ui->widget_cloe_viewpaper->width() - ui->label_clopvp_courseInfo->width()) / 2,
  41. ui->label_clopvp_paperName->y() + ui->label_clopvp_paperName->height() + g_appInfoPtr->m_fRate * 10,
  42. ui->label_clopvp_courseInfo->width(), ui->label_clopvp_courseInfo->height());
  43. ui->label_HLine->setGeometry(0, ui->label_clopvp_courseInfo->y() + ui->label_clopvp_courseInfo->height() + g_appInfoPtr->m_fRate * 30,
  44. ui->widget_cloe_viewpaper->width(), g_appInfoPtr->m_fRate *1);
  45. ui->tb_clopvp_paper->setGeometry(g_appInfoPtr->m_fRate * 40, ui->label_HLine->y() + ui->label_HLine->height() + g_appInfoPtr->m_fRate * 30,
  46. 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);
  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_clop_goback->setGeometry(ui->widget_awbg_top->width() - g_appInfoPtr->m_fRate*(20 + 108), g_appInfoPtr->m_fRate*12,
  55. g_appInfoPtr->m_fRate*108, g_appInfoPtr->m_fRate*32);
  56. ui->btn_clop_goback->setIconSize(QSize(g_appInfoPtr->m_fRate*14, g_appInfoPtr->m_fRate*14));
  57. ui->btn_clop_goback->setIcon(QIcon(":/images/icon-goback-list.png"));
  58. ui->label_cl_company->adjustSize();
  59. 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(),
  60. ui->label_cl_company->width(), ui->label_cl_company->height());
  61. ui->label_cl_version->adjustSize();
  62. ui->label_cl_version->setGeometry(ui->widget_awbg_BG->width() - g_appInfoPtr->m_fRate*30 - ui->label_cl_version->width(),
  63. ui->label_cl_company->y(), ui->label_cl_version->width(), ui->label_cl_version->height());
  64. ui->label_serverTime->adjustSize();
  65. ui->label_serverTime->setGeometry(ui->label_cl_version->x() - g_appInfoPtr->m_fRate*20 - ui->label_serverTime->width(),
  66. ui->label_cl_company->y(), ui->label_serverTime->width(), ui->label_serverTime->height());
  67. }
  68. void cloeViewPaper::setCourseCodeAndName(QString sCode, QString sName)
  69. {
  70. ui->label_awbg_exam->setText(QString::fromLocal8Bit("课程代码:%1 - 课程名称:%2").arg(sCode).arg(sName));
  71. ui->label_awbg_exam->adjustSize();
  72. }
  73. void cloeViewPaper::initPaper(QString sPaper)
  74. {
  75. Json::Reader reader;
  76. Json::Value jPaper = Json::Value::null;
  77. if (!reader.parse(sPaper.toStdString(), jPaper))
  78. {
  79. ShowMsg(QString::fromLocal8Bit("解析试卷出错!"), this, MSG_ICON_TYPE::mit_error);
  80. return;
  81. }
  82. ui->label_clopvp_paperName->setText(QString::fromLocal8Bit("%1 试卷").arg(jPaper["name"].asString().c_str()));
  83. ui->label_clopvp_courseInfo->setText(QString::fromLocal8Bit("课程代码:%1 | 本试卷满分%2分")
  84. .arg(jPaper["course"]["code"].asString().c_str()).arg(jPaper["totalScore"].asDouble()));
  85. QTextCursor cursor = ui->tb_clopvp_paper->textCursor();
  86. QTextBlockFormat textStyleFormat = cursor.blockFormat();
  87. textStyleFormat.setLineHeight(g_appInfoPtr->m_fRate * 5, QTextBlockFormat::LineDistanceHeight);
  88. cursor.setBlockFormat(textStyleFormat);
  89. int nIndex = 1;
  90. int nSize = jPaper["paperDetails"].size();
  91. for (int i = 0; i < nSize; ++i)
  92. {
  93. Json::Value jPaperDetails = jPaper["paperDetails"][i];
  94. QString sTitle = QString::fromLocal8Bit("%1、%2(本大题共%3小题,满分%4分)")
  95. .arg(jPaperDetails["cnNum"].asString().c_str()).arg(jPaperDetails["name"].asString().c_str())
  96. .arg(jPaperDetails["unitCount"].asString().c_str()).arg(jPaperDetails["score"].asString().c_str());
  97. QTextCharFormat fmt;
  98. QFont font;
  99. font.setFamily("Microsoft YaHei");
  100. font.setPixelSize(g_appInfoPtr->m_fRate * 16);
  101. font.setWeight(QFont::DemiBold);
  102. fmt.setFont(font);
  103. cursor.insertText(sTitle, fmt);
  104. cursor.insertText("\n");
  105. int nQuestionSize = jPaperDetails["paperDetailUnits"].size();
  106. for (int j = 0; j < nQuestionSize; ++j)
  107. {
  108. Json::Value jQuestion = jPaperDetails["paperDetailUnits"][j];
  109. QString sBody = QString::fromLocal8Bit("%1、%2(%3分)")
  110. .arg(nIndex).arg(jQuestion["question"]["quesBody"].asString().c_str())
  111. .arg(jQuestion["score"].asDouble());
  112. font.setPixelSize(g_appInfoPtr->m_fRate * 14);
  113. font.setWeight(QFont::Medium);
  114. fmt.setFont(font);
  115. cursor.insertText(QString::fromLocal8Bit("%1、")
  116. .arg(nIndex), fmt);
  117. cursor.insertHtml(jQuestion["question"]["quesBody"].asString().c_str());
  118. cursor.insertText(QString::fromLocal8Bit("(%1分)")
  119. .arg(jQuestion["score"].asDouble()), fmt);
  120. cursor.insertText("\n\r");
  121. }
  122. }
  123. }
  124. void cloeViewPaper::on_btn_clop_goback_clicked()
  125. {
  126. emit goback();
  127. }