awQuestionNavigate.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #include "awQuestionNavigate.h"
  2. #include "ui_awQuestionNavigate.h"
  3. #include "CAppInfo.h"
  4. #include "CCommonTools.h"
  5. #include <QGridLayout>
  6. awQuestionNavigate::awQuestionNavigate(CPaperGroupStruct &pgs, QWidget *parent) :
  7. QWidget(parent),
  8. ui(new Ui::awQuestionNavigate), m_pgs(pgs)
  9. {
  10. ui->setupUi(this);
  11. setStyleSheet(g_appInfoPtr->m_sQssStr);
  12. }
  13. awQuestionNavigate::~awQuestionNavigate()
  14. {
  15. delete ui;
  16. }
  17. int awQuestionNavigate::setUI(const int nWidth)
  18. {
  19. ui->label_questionName->setText(QString::fromLocal8Bit("%1%2").arg(CCommonTools::Arab2Sinogram(m_pgs.nNumber)).arg(m_pgs.sGroupName));
  20. ui->label_questionScore->setText(QString::fromLocal8Bit("%1分").arg(m_pgs.fGroupScore));
  21. ui->widget_qn_groupInfo->setGeometry(0, 0, nWidth, g_appInfoPtr->m_fRate*50);
  22. ui->label_questionName->adjustSize();
  23. ui->label_questionName->setGeometry(0, g_appInfoPtr->m_fRate*20, ui->label_questionName->width(), ui->label_questionName->height());
  24. ui->label_questionScore->adjustSize();
  25. ui->label_questionScore->setGeometry(ui->widget_qn_groupInfo->width() - ui->label_questionScore->width(), ui->label_questionName->y() + (ui->label_questionName->height() - ui->label_questionScore->height())/2,
  26. ui->label_questionScore->width(), ui->label_questionScore->height());
  27. QGridLayout *layout = new QGridLayout;
  28. layout->setHorizontalSpacing(g_appInfoPtr->m_fRate*10);
  29. layout->setVerticalSpacing(g_appInfoPtr->m_fRate*10);
  30. layout->setAlignment(Qt::AlignLeft);
  31. layout->setContentsMargins(0, 0, 0, 0);
  32. m_vItemList.clear();
  33. int nTotal = 0;
  34. int nQuestionSize = m_pgs.vQuestionStruct.size();
  35. for(int i = 0; i < nQuestionSize; ++i)
  36. {
  37. CQuestionStruct &qs = m_pgs.vQuestionStruct[i];
  38. int nSubQuestionSize = qs.vSubQuestionStruct.size();
  39. for(int j = 0; j < nSubQuestionSize; ++j)
  40. {
  41. CSubQuestionStruct &sqs = qs.vSubQuestionStruct[j];
  42. awqn_item *item = new awqn_item(sqs);
  43. connect(item, &awqn_item::showSubQuestion, this, [&](int nOrder) {
  44. emit showSubQuestion(qs.sQuestionId, nOrder, qs.bHasContent);
  45. });
  46. item->setFixedSize(g_appInfoPtr->m_fRate * 30, g_appInfoPtr->m_fRate * 30);
  47. layout->addWidget(item, (sqs.nShowNumber + 4)/5 - 1, (sqs.nShowNumber - 1)%5, 1, 1);
  48. item->setUI();
  49. m_vItemList.push_back(item);
  50. nTotal++;
  51. }
  52. }
  53. int nRow = (nTotal + 4)/5;
  54. ui->widget_qn_questionList->setGeometry(0, ui->widget_qn_groupInfo->y() + ui->widget_qn_groupInfo->height(),
  55. nWidth, nRow*40*g_appInfoPtr->m_fRate);
  56. ui->widget_qn_questionList->setLayout(layout);
  57. setGeometry(0, 0, nWidth, ui->widget_qn_questionList->height() + ui->widget_qn_groupInfo->height());
  58. return height();
  59. }
  60. void awQuestionNavigate::refreshStatus()
  61. {
  62. int nSize = m_vItemList.size();
  63. for(int i = 0; i < nSize; ++i)
  64. {
  65. awqn_item *item = m_vItemList[i];
  66. if(item)
  67. {
  68. item->refreshStatus();
  69. }
  70. }
  71. }
  72. void awQuestionNavigate::setShowType(ITEM_SHOW_TYPE type)
  73. {
  74. int nIndex = 1;
  75. int nSize = m_vItemList.size();
  76. for(int i = 0; i < nSize; ++i)
  77. {
  78. awqn_item *item = m_vItemList[i];
  79. if(item)
  80. {
  81. if(type == ITEM_SHOW_TYPE::ist_showAll)
  82. {
  83. item->setVisible(true);
  84. }
  85. else if(type == ITEM_SHOW_TYPE::ist_showMarked)
  86. {
  87. if(item->isMarked())
  88. {
  89. item->setVisible(true);
  90. }
  91. else
  92. {
  93. item->setVisible(false);
  94. }
  95. }
  96. else if(type == ITEM_SHOW_TYPE::ist_showAnswered)
  97. {
  98. if(item->isAnswered())
  99. {
  100. item->setVisible(true);
  101. }
  102. else
  103. {
  104. item->setVisible(false);
  105. }
  106. }
  107. else if(type == ITEM_SHOW_TYPE::ist_showUnanswered)
  108. {
  109. if(!item->isAnswered())
  110. {
  111. item->setVisible(true);
  112. }
  113. else
  114. {
  115. item->setVisible(false);
  116. }
  117. }
  118. }
  119. }
  120. }