awQuestionNavigate.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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_questionName->setToolTip(ui->label_questionName->text());
  21. ui->label_questionScore->setText(QString::fromLocal8Bit("%1分").arg(m_pgs.fGroupScore));
  22. ui->label_questionScore->adjustSize();
  23. ui->label_questionScore->setGeometry(nWidth - ui->label_questionScore->width(), ui->label_questionName->y() + (ui->label_questionName->height() - ui->label_questionScore->height())/2,
  24. ui->label_questionScore->width(), ui->label_questionScore->height());
  25. ui->label_questionName->setGeometry(0, g_appInfoPtr->m_fRate*20, ui->label_questionScore->x() - g_appInfoPtr->m_fRate*10, ui->label_questionName->height());
  26. ui->label_questionName->adjustSize();
  27. int nNameWidth = ui->label_questionScore->x() - ui->label_questionName->x() - g_appInfoPtr->m_fRate*10;
  28. int nRowCount = (ui->label_questionName->width() + nNameWidth - 1)/nNameWidth;
  29. if(nRowCount > 1)
  30. {
  31. ui->label_questionName->setWordWrap(true);
  32. ui->label_questionName->setGeometry(0, g_appInfoPtr->m_fRate*20,
  33. nNameWidth, nRowCount*ui->label_questionName->height());
  34. }
  35. ui->widget_qn_groupInfo->setGeometry(0, 0, nWidth, g_appInfoPtr->m_fRate*30 + ui->label_questionName->height());
  36. // QGridLayout *layout = new QGridLayout;
  37. // layout->setHorizontalSpacing(g_appInfoPtr->m_fRate*10);
  38. // layout->setVerticalSpacing(g_appInfoPtr->m_fRate*10);
  39. // layout->setAlignment(Qt::AlignLeft);
  40. // layout->setContentsMargins(0, 0, 0, 0);
  41. m_vItemList.clear();
  42. int nTotal = 0;
  43. int nQuestionSize = m_pgs.vQuestionStruct.size();
  44. for(int i = 0; i < nQuestionSize; ++i)
  45. {
  46. CQuestionStruct &qs = m_pgs.vQuestionStruct[i];
  47. int nSubQuestionSize = qs.vSubQuestionStruct.size();
  48. for(int j = 0; j < nSubQuestionSize; ++j)
  49. {
  50. CSubQuestionStruct &sqs = qs.vSubQuestionStruct[j];
  51. awqn_item *item = new awqn_item(sqs, ui->widget_qn_questionList);
  52. connect(item, &awqn_item::showSubQuestion, this, [&](int nOrder) {
  53. emit showSubQuestion(qs.sQuestionId, nOrder, qs.bHasContent);
  54. });
  55. int nCol = nTotal%5;
  56. int nRow = (nTotal + 1 + 4)/5 - 1;
  57. int nY = g_appInfoPtr->m_fRate*nRow * 40;
  58. int nX = g_appInfoPtr->m_fRate*nCol * 40;
  59. item->setUI(nX, nY, (g_appInfoPtr->m_fRate*30), (30*g_appInfoPtr->m_fRate));
  60. m_vItemList.push_back(item);
  61. nTotal++;
  62. }
  63. }
  64. int nRow = (nTotal + 4)/5;
  65. ui->widget_qn_questionList->setGeometry(0, ui->widget_qn_groupInfo->y() + ui->widget_qn_groupInfo->height(),
  66. nWidth, nRow*40*g_appInfoPtr->m_fRate);
  67. // ui->widget_qn_questionList->setLayout(layout);
  68. setGeometry(0, 0, nWidth, ui->widget_qn_questionList->height() + ui->widget_qn_groupInfo->height());
  69. return height();
  70. }
  71. int awQuestionNavigate::showItems(std::vector<awqn_item*> vItemList)
  72. {
  73. int nTotal = 0;
  74. int nQuestionSize = vItemList.size();
  75. for(int i = 0; i < nQuestionSize; ++i)
  76. {
  77. awqn_item *item = vItemList[i];
  78. int nCol = nTotal%5;
  79. int nRow = (nTotal + 1 + 4)/5 - 1;
  80. int nY = g_appInfoPtr->m_fRate*nRow * 40;
  81. int nX = g_appInfoPtr->m_fRate*nCol * 40;
  82. item->setUI(nX, nY, g_appInfoPtr->m_fRate*30, g_appInfoPtr->m_fRate*30);
  83. ++nTotal;
  84. }
  85. int nRow = (nTotal + 4)/5;
  86. int nWidth = width();
  87. ui->widget_qn_questionList->setGeometry(0, ui->widget_qn_groupInfo->y() + ui->widget_qn_groupInfo->height(),
  88. nWidth, nRow*40*g_appInfoPtr->m_fRate);
  89. setFixedHeight(ui->widget_qn_questionList->height() + ui->widget_qn_groupInfo->height());
  90. return height();
  91. }
  92. void awQuestionNavigate::refreshStatus()
  93. {
  94. int nSize = m_vItemList.size();
  95. for(int i = 0; i < nSize; ++i)
  96. {
  97. awqn_item *item = m_vItemList[i];
  98. if(item)
  99. {
  100. item->refreshStatus();
  101. }
  102. }
  103. }
  104. int awQuestionNavigate::setShowType(ITEM_SHOW_TYPE type)
  105. {
  106. std::vector<awqn_item*> vItemList;
  107. int nSize = m_vItemList.size();
  108. for(int i = 0; i < nSize; ++i)
  109. {
  110. awqn_item *item = m_vItemList[i];
  111. if(item)
  112. {
  113. if(type == ITEM_SHOW_TYPE::ist_showAll)
  114. {
  115. item->setVisible(true);
  116. vItemList.push_back(item);
  117. }
  118. else if(type == ITEM_SHOW_TYPE::ist_showMarked)
  119. {
  120. if(item->isMarked())
  121. {
  122. item->setVisible(true);
  123. vItemList.push_back(item);
  124. }
  125. else
  126. {
  127. item->setVisible(false);
  128. }
  129. }
  130. else if(type == ITEM_SHOW_TYPE::ist_showAnswered)
  131. {
  132. if(item->isAnswered())
  133. {
  134. item->setVisible(true);
  135. vItemList.push_back(item);
  136. }
  137. else
  138. {
  139. item->setVisible(false);
  140. }
  141. }
  142. else if(type == ITEM_SHOW_TYPE::ist_showUnanswered)
  143. {
  144. if(!item->isAnswered())
  145. {
  146. item->setVisible(true);
  147. vItemList.push_back(item);
  148. }
  149. else
  150. {
  151. item->setVisible(false);
  152. }
  153. }
  154. }
  155. }
  156. return showItems(vItemList);
  157. }