clNoticeList.cpp 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. #include "clNoticeList.h"
  2. #include "ui_clNoticeList.h"
  3. #include "CAppInfo.h"
  4. #include "clOperation.h"
  5. #include "CheckHeaderView.h"
  6. #include <QLabel>
  7. #include <QScrollBar>
  8. #include <QHBoxLayout>
  9. #include "logproc.h"
  10. clNoticeList::clNoticeList(QWidget *parent) :
  11. QWidget(parent),
  12. ui(new Ui::clNoticeList)
  13. {
  14. ui->setupUi(this);
  15. setStyleSheet(g_appInfoPtr->m_sQssStr);
  16. }
  17. clNoticeList::~clNoticeList()
  18. {
  19. delete ui;
  20. }
  21. void clNoticeList::setUI(const int nWidth, const int nHeight)
  22. {
  23. setGeometry(0, 0, nWidth, nHeight);
  24. ui->widget_noticelist->setGeometry(0, 0, width(), height());
  25. ui->widget_op_top->setGeometry(0, 0, width(), g_appInfoPtr->m_fRate*72);
  26. ui->btn_setRead->setGeometry(ui->widget_op_top->width() - g_appInfoPtr->m_fRate*30 - g_appInfoPtr->m_fRate*120,
  27. (ui->widget_op_top->height() - g_appInfoPtr->m_fRate*32)/2,
  28. g_appInfoPtr->m_fRate*120, g_appInfoPtr->m_fRate*32);
  29. ui->btn_setRead->setIconSize(QSize(g_appInfoPtr->m_fRate*16, g_appInfoPtr->m_fRate*14));
  30. ui->btn_setRead->setIcon(QIcon(":/images/btn-notice-set-read.png"));
  31. ui->tablewt_examList->setGeometry(g_appInfoPtr->m_fRate*30, ui->widget_op_top->height() + g_appInfoPtr->m_fRate*10,
  32. ui->widget_noticelist->width() - g_appInfoPtr->m_fRate*30*2,
  33. ui->widget_noticelist->height() - ui->widget_op_top->height() - g_appInfoPtr->m_fRate*(10 + 62));
  34. ui->tablewt_examList->setEditTriggers(QAbstractItemView::NoEditTriggers);
  35. //整行选中的方式
  36. ui->tablewt_examList->setSelectionBehavior(QAbstractItemView::SelectRows);
  37. //设置为只能选中一行
  38. ui->tablewt_examList->setSelectionMode(QAbstractItemView::NoSelection);
  39. //隐藏列表头
  40. ui->tablewt_examList->verticalHeader()->setVisible(false);
  41. //隐藏边框
  42. ui->tablewt_examList->setShowGrid(false);
  43. //表头不高亮显示
  44. ui->tablewt_examList->horizontalHeader()->setHighlightSections(false);
  45. //设置行数
  46. ui->tablewt_examList->setRowCount(10);
  47. //设置列数
  48. ui->tablewt_examList->setColumnCount(3);
  49. ui->tablewt_examList->setHorizontalScrollMode(QTableWidget::ScrollPerPixel);
  50. ui->tablewt_examList->horizontalScrollBar()->setSingleStep(g_appInfoPtr->m_fRate*5);
  51. ui->tablewt_examList->setIconSize(QSize(g_appInfoPtr->m_fRate*36, g_appInfoPtr->m_fRate*36));
  52. QStringList sHeadStr;
  53. sHeadStr << QString::fromLocal8Bit("") <<
  54. QString::fromLocal8Bit("标题") <<
  55. QString::fromLocal8Bit("发送时间");
  56. //表头加入checkbox
  57. CheckHeaderView *CheckHead = new CheckHeaderView(0, Qt::Horizontal, ui->tablewt_examList);
  58. connect(CheckHead, &CheckHeaderView::checkboxStateChanged, this, [&](int state){
  59. for(int i = 0; i < ui->tablewt_examList->rowCount(); i++)
  60. {
  61. QCheckBox* chk = dynamic_cast<QCheckBox*>(ui->tablewt_examList->cellWidget(i, 0));
  62. if(chk)
  63. {
  64. chk->setCheckState((Qt::CheckState)state);
  65. }
  66. }
  67. });
  68. ui->tablewt_examList->setHorizontalHeader(CheckHead);
  69. ui->tablewt_examList->setHorizontalHeaderLabels(sHeadStr);
  70. ui->tablewt_examList->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft | Qt::AlignVCenter);
  71. ui->tablewt_examList->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
  72. ui->tablewt_examList->verticalHeader()->setDefaultSectionSize(g_appInfoPtr->m_fRate*48);
  73. ui->tablewt_examList->setColumnWidth(0, g_appInfoPtr->m_fRate*56);
  74. ui->tablewt_examList->setColumnWidth(1, g_appInfoPtr->m_fRate*940);
  75. ui->tablewt_examList->setColumnWidth(2, g_appInfoPtr->m_fRate*112);
  76. ui->tablewt_examList->horizontalHeader()->setStretchLastSection(true);
  77. }
  78. void clNoticeList::setNotice(std::vector<CNoticeInfo> vNL)
  79. {
  80. QString sCheckStyle = QString(R"(QCheckBox
  81. {
  82. outline: none;
  83. height:%1px;
  84. font-size:%2px;
  85. font-family:"Microsoft YaHei";
  86. font-weight:400;
  87. color:rgba(102,102,102,1);
  88. }
  89. QCheckBox::indicator
  90. {
  91. width:%3px;
  92. height:%4px;
  93. }
  94. QCheckBox::indicator:unchecked
  95. {
  96. border: %5px solid rgba(228,229,235,1);
  97. border-radius:%6px;
  98. background:rgba(239,240,245,1);
  99. }
  100. QCheckBox::indicator:checked
  101. {
  102. border-image: url(:/images/icon-checkbox-checked.png);
  103. })").arg((int)(g_appInfoPtr->m_fRate*26))
  104. .arg((int)(g_appInfoPtr->m_fRate*14))
  105. .arg((int)(g_appInfoPtr->m_fRate*14))
  106. .arg((int)(g_appInfoPtr->m_fRate*14))
  107. .arg((int)(g_appInfoPtr->m_fRate*1))
  108. .arg((int)(g_appInfoPtr->m_fRate*3));
  109. vNoticeList.clear();
  110. vNoticeList.assign(vNL.begin(), vNL.end());
  111. int nSize = vNoticeList.size();
  112. for (int i = 0; i < nSize; ++i)
  113. {
  114. CNoticeInfo ni = vNoticeList[i];
  115. QCheckBox *chkBox = new QCheckBox;
  116. chkBox->setStyleSheet(sCheckStyle);
  117. ui->tablewt_examList->setCellWidget(i, 0, chkBox);
  118. QWidget *widget = new QWidget;
  119. QHBoxLayout *layout = new QHBoxLayout;
  120. widget->setLayout(layout);
  121. QLabel *icon = new QLabel;
  122. icon->setFixedSize(QSize(g_appInfoPtr->m_fRate * 16, g_appInfoPtr->m_fRate * 12));
  123. QString sIconFile = "";
  124. if (ni.bHasRead)
  125. {
  126. sIconFile = ":/images/icon-notice-read.png";
  127. }
  128. else
  129. {
  130. sIconFile = ":/images/icon-notice-unread.png";
  131. }
  132. icon->setPixmap(QPixmap(sIconFile).scaled(g_appInfoPtr->m_fRate * 16, g_appInfoPtr->m_fRate * 12));
  133. layout->addWidget(icon);
  134. QMyLabel *text = new QMyLabel(i);
  135. connect(text, &QMyLabel::sgnClick, this, &clNoticeList::on_tablewt_examList_cellClicked);
  136. text->setText(ni.sContent);
  137. text->setFixedWidth(900);
  138. text->setStyleSheet(QString(R"(QLabel
  139. {
  140. font-size:%1px;
  141. font-family:"Microsoft YaHei";
  142. font-weight:400;
  143. color:rgba(51,51,51,1);
  144. })").arg((int)(g_appInfoPtr->m_fRate * 12)));
  145. layout->addWidget(text);
  146. layout->addStretch();
  147. ui->tablewt_examList->setCellWidget(i, 1, widget);
  148. ui->tablewt_examList->setItem(i, 2, new QTableWidgetItem(ni.sPublishTime));
  149. }
  150. }
  151. void clNoticeList::on_tablewt_examList_cellClicked(int row, int column)
  152. {
  153. if ((int)(vNoticeList.size() - 1) < row ||
  154. column == 0)
  155. {
  156. return;
  157. }
  158. if (m_pNoticeDetail == nullptr)
  159. {
  160. m_pNoticeDetail = std::make_shared<clNoticeDetail>(vNoticeList[row], this);
  161. m_pNoticeDetail->setUI(0, 0, width(), height());
  162. connect(m_pNoticeDetail.get(), &clNoticeDetail::gobackNoticeList, this, [&]() {
  163. if (m_pNoticeDetail != nullptr)
  164. {
  165. m_pNoticeDetail.reset();
  166. }
  167. });
  168. }
  169. m_pNoticeDetail->show();
  170. }