cloeViewPaper.cpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. cloeViewPaper::cloeViewPaper(QString sPaper, QWidget *parent) :
  8. QWidget(parent),
  9. ui(new Ui::cloeViewPaper)
  10. {
  11. ui->setupUi(this);
  12. initPaper(sPaper);
  13. initUI();
  14. }
  15. cloeViewPaper::~cloeViewPaper()
  16. {
  17. delete ui;
  18. }
  19. void cloeViewPaper::initUI()
  20. {
  21. QDesktopWidget *dekwiget = QApplication::desktop();
  22. setGeometry(0, 0, dekwiget->width(), dekwiget->height());
  23. ui->widget_awbg_BG->setGeometry(0, 0, width(), height());
  24. ui->widget_cloe_viewpaper->setGeometry(g_appInfoPtr->m_fRate*20, g_appInfoPtr->m_fRate*56, width() - g_appInfoPtr->m_fRate*20*2,
  25. height() - g_appInfoPtr->m_fRate*(56 + 38));
  26. ui->label_clopvp_paperName->adjustSize();
  27. ui->label_clopvp_paperName->setGeometry((ui->widget_cloe_viewpaper->width() - ui->label_clopvp_paperName->width())/2,
  28. g_appInfoPtr->m_fRate * 30, ui->label_clopvp_paperName->width(), ui->label_clopvp_paperName->height());
  29. ui->label_clopvp_courseInfo->adjustSize();
  30. ui->label_clopvp_courseInfo->setGeometry((ui->widget_cloe_viewpaper->width() - ui->label_clopvp_courseInfo->width()) / 2,
  31. ui->label_clopvp_paperName->y() + ui->label_clopvp_paperName->height() + g_appInfoPtr->m_fRate * 10,
  32. ui->label_clopvp_courseInfo->width(), ui->label_clopvp_courseInfo->height());
  33. ui->label_HLine->setGeometry(0, ui->label_clopvp_courseInfo->y() + ui->label_clopvp_courseInfo->height() + g_appInfoPtr->m_fRate * 30,
  34. ui->widget_cloe_viewpaper->width(), g_appInfoPtr->m_fRate *1);
  35. ui->tb_clopvp_paper->setGeometry(g_appInfoPtr->m_fRate * 40, ui->label_HLine->y() + ui->label_HLine->height() + g_appInfoPtr->m_fRate * 30,
  36. 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);
  37. ui->widget_awbg_top->setGeometry(0, 0, ui->widget_awbg_BG->width(), g_appInfoPtr->m_fRate*112);
  38. ui->label_awbg_examIcon->setGeometry(g_appInfoPtr->m_fRate*30, g_appInfoPtr->m_fRate*20,
  39. g_appInfoPtr->m_fRate*16, g_appInfoPtr->m_fRate*16);
  40. ui->label_awbg_exam->adjustSize();
  41. ui->label_awbg_exam->setGeometry(ui->label_awbg_examIcon->x() + ui->label_awbg_examIcon->width() + g_appInfoPtr->m_fRate*10,
  42. ui->label_awbg_examIcon->y() + (ui->label_awbg_examIcon->height() - ui->label_awbg_exam->height())/2,
  43. ui->label_awbg_exam->width(), ui->label_awbg_exam->height());
  44. ui->btn_clop_goback->setGeometry(ui->widget_awbg_top->width() - g_appInfoPtr->m_fRate*(20 + 108), g_appInfoPtr->m_fRate*12,
  45. g_appInfoPtr->m_fRate*108, g_appInfoPtr->m_fRate*32);
  46. ui->btn_clop_goback->setIconSize(QSize(g_appInfoPtr->m_fRate*14, g_appInfoPtr->m_fRate*14));
  47. ui->btn_clop_goback->setIcon(QIcon(":/images/icon-goback-list.png"));
  48. ui->label_cl_company->adjustSize();
  49. 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(),
  50. ui->label_cl_company->width(), ui->label_cl_company->height());
  51. ui->label_cl_version->adjustSize();
  52. ui->label_cl_version->setGeometry(ui->widget_awbg_BG->width() - g_appInfoPtr->m_fRate*30 - ui->label_cl_version->width(),
  53. ui->label_cl_company->y(), ui->label_cl_version->width(), ui->label_cl_version->height());
  54. ui->label_serverTime->adjustSize();
  55. ui->label_serverTime->setGeometry(ui->label_cl_version->x() - g_appInfoPtr->m_fRate*20 - ui->label_serverTime->width(),
  56. ui->label_cl_company->y(), ui->label_serverTime->width(), ui->label_serverTime->height());
  57. }
  58. void cloeViewPaper::initPaper(QString sPaper)
  59. {
  60. Json::Reader reader;
  61. Json::Value jPaper = Json::Value::null;
  62. if (!reader.parse(sPaper.toStdString(), jPaper))
  63. {
  64. ShowMsg(QString::fromLocal8Bit("解析试卷出错!"), this);
  65. return;
  66. }
  67. ui->label_clopvp_paperName->setText(QString::fromLocal8Bit("%1 试卷").arg(jPaper["name"].asString().c_str()));
  68. ui->label_clopvp_courseInfo->setText(QString::fromLocal8Bit("课程代码:%1 | 本试卷满分%2分")
  69. .arg(jPaper["course"]["code"].asString().c_str()).arg(jPaper["totalScore"].asDouble()));
  70. QTextCursor cursor = ui->tb_clopvp_paper->textCursor();
  71. QTextBlockFormat textStyleFormat = cursor.blockFormat();
  72. textStyleFormat.setLineHeight(g_appInfoPtr->m_fRate * 5, QTextBlockFormat::LineDistanceHeight);
  73. cursor.setBlockFormat(textStyleFormat);
  74. int nIndex = 1;
  75. int nSize = jPaper["paperDetails"].size();
  76. for (int i = 0; i < nSize; ++i)
  77. {
  78. Json::Value jPaperDetails = jPaper["paperDetails"][i];
  79. QString sTitle = QString::fromLocal8Bit("%1、%2(本大题共%3小题,满分%4分)")
  80. .arg(jPaperDetails["cnNum"].asString().c_str()).arg(jPaperDetails["name"].asString().c_str())
  81. .arg(jPaperDetails["unitCount"].asString().c_str()).arg(jPaperDetails["score"].asString().c_str());
  82. QTextCharFormat fmt;
  83. QFont font;
  84. font.setFamily("Microsoft YaHei");
  85. font.setPixelSize(g_appInfoPtr->m_fRate * 16);
  86. font.setWeight(QFont::DemiBold);
  87. fmt.setFont(font);
  88. cursor.insertText(sTitle, fmt);
  89. cursor.insertText("\n");
  90. int nQuestionSize = jPaperDetails["paperDetailUnits"].size();
  91. for (int j = 0; j < nQuestionSize; ++j)
  92. {
  93. Json::Value jQuestion = jPaperDetails["paperDetailUnits"][j];
  94. QString sBody = QString::fromLocal8Bit("%1、%2(%3分)")
  95. .arg(nIndex).arg(jQuestion["question"]["quesBody"].asString().c_str())
  96. .arg(jQuestion["score"].asDouble());
  97. font.setPixelSize(g_appInfoPtr->m_fRate * 14);
  98. font.setWeight(QFont::Medium);
  99. fmt.setFont(font);
  100. cursor.insertText(QString::fromLocal8Bit("%1、")
  101. .arg(nIndex), fmt);
  102. cursor.insertHtml(jQuestion["question"]["quesBody"].asString().c_str());
  103. cursor.insertText(QString::fromLocal8Bit("(%1分)")
  104. .arg(jQuestion["score"].asDouble()), fmt);
  105. cursor.insertText("\n\r");
  106. }
  107. }
  108. }
  109. void cloeViewPaper::on_btn_clop_goback_clicked()
  110. {
  111. emit goback();
  112. }