clNoticeList.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. #include "clNoticeList.h"
  2. #include "ui_clNoticeList.h"
  3. #include <QLabel>
  4. #include <QScrollBar>
  5. #include <QHBoxLayout>
  6. #include "CAppInfo.h"
  7. #include "clOperation.h"
  8. #include "CheckHeaderView.h"
  9. #include "logproc.h"
  10. #include "awMsgBox.h"
  11. clNoticeList::clNoticeList(QWidget *parent) :
  12. QWidget(parent),
  13. ui(new Ui::clNoticeList)
  14. {
  15. ui->setupUi(this);
  16. setStyleSheet(g_appInfoPtr->m_sQssStr);
  17. qRegisterMetaType<CUpdateNoticeReadStatus>("CUpdateNoticeReadStatus");
  18. connect(g_httpBllPtr.get(), &CHttpBll::sgnUpdateNoticeReadStatus, this, &clNoticeList::onUpdateNoticeReadStatus);
  19. }
  20. clNoticeList::~clNoticeList()
  21. {
  22. delete ui;
  23. }
  24. void clNoticeList::setUI(const int nWidth, const int nHeight)
  25. {
  26. setGeometry(0, 0, nWidth, nHeight);
  27. ui->widget_noticelist->setGeometry(0, 0, width(), height());
  28. ui->widget_op_top->setGeometry(0, 0, width(), g_appInfoPtr->m_fRate*72);
  29. ui->btn_setRead->setGeometry(ui->widget_op_top->width() - g_appInfoPtr->m_fRate*30 - g_appInfoPtr->m_fRate*120,
  30. (ui->widget_op_top->height() - g_appInfoPtr->m_fRate*32)/2,
  31. g_appInfoPtr->m_fRate*120, g_appInfoPtr->m_fRate*32);
  32. ui->btn_setRead->setIconSize(QSize(g_appInfoPtr->m_fRate*16, g_appInfoPtr->m_fRate*14));
  33. ui->btn_setRead->setIcon(QIcon(":/images/btn-notice-set-read.png"));
  34. ui->tablewt_examList->setGeometry(g_appInfoPtr->m_fRate*30, ui->widget_op_top->height() + g_appInfoPtr->m_fRate*10,
  35. ui->widget_noticelist->width() - g_appInfoPtr->m_fRate*30*2,
  36. ui->widget_noticelist->height() - ui->widget_op_top->height() - g_appInfoPtr->m_fRate*(10 + 62));
  37. ui->tablewt_examList->setEditTriggers(QAbstractItemView::NoEditTriggers);
  38. //整行选中的方式
  39. ui->tablewt_examList->setSelectionBehavior(QAbstractItemView::SelectRows);
  40. //设置为只能选中一行
  41. ui->tablewt_examList->setSelectionMode(QAbstractItemView::NoSelection);
  42. //隐藏列表头
  43. ui->tablewt_examList->verticalHeader()->setVisible(false);
  44. //隐藏边框
  45. ui->tablewt_examList->setShowGrid(false);
  46. //表头不高亮显示
  47. ui->tablewt_examList->horizontalHeader()->setHighlightSections(false);
  48. //设置行数
  49. ui->tablewt_examList->setRowCount(10);
  50. //设置列数
  51. ui->tablewt_examList->setColumnCount(3);
  52. ui->tablewt_examList->setHorizontalScrollMode(QTableWidget::ScrollPerPixel);
  53. ui->tablewt_examList->horizontalScrollBar()->setSingleStep(g_appInfoPtr->m_fRate*5);
  54. ui->tablewt_examList->setIconSize(QSize(g_appInfoPtr->m_fRate*36, g_appInfoPtr->m_fRate*36));
  55. QStringList sHeadStr;
  56. sHeadStr << QString::fromLocal8Bit("") <<
  57. QString::fromLocal8Bit("标题") <<
  58. QString::fromLocal8Bit("发送时间");
  59. //表头加入checkbox
  60. CheckHeaderView *CheckHead = new CheckHeaderView(0, Qt::Horizontal, ui->tablewt_examList);
  61. connect(CheckHead, &CheckHeaderView::checkboxStateChanged, this, [&](int state){
  62. for(int i = 0; i < ui->tablewt_examList->rowCount(); i++)
  63. {
  64. QCheckBox* chk = dynamic_cast<QCheckBox*>(ui->tablewt_examList->cellWidget(i, 0));
  65. if(chk)
  66. {
  67. chk->setCheckState((Qt::CheckState)state);
  68. }
  69. }
  70. });
  71. ui->tablewt_examList->setHorizontalHeader(CheckHead);
  72. ui->tablewt_examList->setHorizontalHeaderLabels(sHeadStr);
  73. ui->tablewt_examList->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft | Qt::AlignVCenter);
  74. ui->tablewt_examList->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
  75. ui->tablewt_examList->verticalHeader()->setDefaultSectionSize(g_appInfoPtr->m_fRate*48);
  76. ui->tablewt_examList->setColumnWidth(0, g_appInfoPtr->m_fRate*56);
  77. ui->tablewt_examList->setColumnWidth(1, g_appInfoPtr->m_fRate*940);
  78. ui->tablewt_examList->setColumnWidth(2, g_appInfoPtr->m_fRate*112);
  79. ui->tablewt_examList->horizontalHeader()->setStretchLastSection(true);
  80. }
  81. void clNoticeList::setNotice(std::vector<CNoticeInfo> vNL)
  82. {
  83. QString sCheckStyle = QString(R"(QCheckBox
  84. {
  85. outline: none;
  86. height:%1px;
  87. font-size:%2px;
  88. font-family:"Microsoft YaHei";
  89. font-weight:400;
  90. color:rgba(102,102,102,1);
  91. }
  92. QCheckBox::indicator
  93. {
  94. width:%3px;
  95. height:%4px;
  96. }
  97. QCheckBox::indicator:unchecked
  98. {
  99. border: %5px solid rgba(228,229,235,1);
  100. border-radius:%6px;
  101. background:rgba(239,240,245,1);
  102. }
  103. QCheckBox::indicator:checked
  104. {
  105. border-image: url(:/images/icon-checkbox-checked.png);
  106. })").arg((int)(g_appInfoPtr->m_fRate*26))
  107. .arg((int)(g_appInfoPtr->m_fRate*14))
  108. .arg((int)(g_appInfoPtr->m_fRate*14))
  109. .arg((int)(g_appInfoPtr->m_fRate*14))
  110. .arg((int)(g_appInfoPtr->m_fRate*1 < 1 ? 1 : g_appInfoPtr->m_fRate*1))
  111. .arg((int)(g_appInfoPtr->m_fRate*3));
  112. vNoticeList.clear();
  113. vNoticeList.assign(vNL.begin(), vNL.end());
  114. int nSize = vNoticeList.size();
  115. for (int i = 0; i < nSize; ++i)
  116. {
  117. CNoticeInfo ni = vNoticeList[i];
  118. QCheckBox *chkBox = new QCheckBox;
  119. chkBox->setStyleSheet(sCheckStyle);
  120. ui->tablewt_examList->setCellWidget(i, 0, chkBox);
  121. QWidget *widget = new QWidget;
  122. QHBoxLayout *layout = new QHBoxLayout;
  123. widget->setLayout(layout);
  124. QLabel *icon = new QLabel;
  125. icon->setObjectName("icon");
  126. icon->setFixedSize(QSize(g_appInfoPtr->m_fRate * 16, g_appInfoPtr->m_fRate * 12));
  127. QString sIconFile = "";
  128. if (ni.bHasRead)
  129. {
  130. sIconFile = ":/images/icon-notice-read.png";
  131. }
  132. else
  133. {
  134. sIconFile = ":/images/icon-notice-unread.png";
  135. }
  136. icon->setPixmap(QPixmap(sIconFile).scaled(g_appInfoPtr->m_fRate * 16, g_appInfoPtr->m_fRate * 12));
  137. layout->addWidget(icon);
  138. QMyLabel *text = new QMyLabel(i);
  139. connect(text, &QMyLabel::sgnClick, this, &clNoticeList::on_tablewt_examList_cellClicked);
  140. if (ni.bHasRecalled)
  141. {
  142. text->setText(QString::fromLocal8Bit("发送者已撤回消息:%1").arg(ni.sTitle));
  143. }
  144. else
  145. {
  146. text->setText(ni.sTitle);
  147. }
  148. text->setFixedWidth(900);
  149. text->setStyleSheet(QString(R"(QLabel
  150. {
  151. font-size:%1px;
  152. font-family:"Microsoft YaHei";
  153. font-weight:400;
  154. color:rgba(51,51,51,1);
  155. })").arg((int)(g_appInfoPtr->m_fRate * 12)));
  156. layout->addWidget(text);
  157. layout->addStretch();
  158. ui->tablewt_examList->setCellWidget(i, 1, widget);
  159. ui->tablewt_examList->setItem(i, 2, new QTableWidgetItem(ni.sPublishTime));
  160. }
  161. }
  162. void clNoticeList::on_tablewt_examList_cellClicked(int row, int column)
  163. {
  164. if ((int)(vNoticeList.size() - 1) < row ||
  165. column == 0)
  166. {
  167. return;
  168. }
  169. showNotice(vNoticeList[row]);
  170. }
  171. void clNoticeList::viewNotice(__int64 nId)
  172. {
  173. for(CNoticeInfo ni : vNoticeList)
  174. {
  175. if(ni.nId == nId)
  176. {
  177. showNotice(ni);
  178. }
  179. }
  180. }
  181. void clNoticeList::showNotice(CNoticeInfo ni)
  182. {
  183. if (m_pNoticeDetail == nullptr)
  184. {
  185. m_pNoticeDetail = std::make_shared<clNoticeDetail>(ni, this);
  186. m_pNoticeDetail->setUI(0, 0, width(), height());
  187. connect(m_pNoticeDetail.get(), &clNoticeDetail::gobackNoticeList, this, [&]() {
  188. if (m_pNoticeDetail != nullptr)
  189. {
  190. m_pNoticeDetail.reset();
  191. }
  192. });
  193. }
  194. m_pNoticeDetail->show();
  195. setNoticeRead(QString::number(ni.nId));
  196. }
  197. //noticeId 通知ID,多个以逗号分隔
  198. void clNoticeList::setNoticeRead(QString sIds)
  199. {
  200. CHttpRequestPackage hrp;
  201. hrp.sUri = "/api/ecs_exam_work/notice/updateNoticeReadStatus";
  202. hrp.sParamList.push_back(QString("noticeId,%1").arg(sIds));
  203. hrp.nRequestType = RequestType::rtUpdateNoticeReadStatus;
  204. hrp.sCommonStr = sIds;
  205. g_httpBllPtr->post(hrp);
  206. }
  207. void clNoticeList::on_btn_setRead_clicked()
  208. {
  209. QStringList list;
  210. for(int i = 0; i < ui->tablewt_examList->rowCount(); i++)
  211. {
  212. QCheckBox* chk = dynamic_cast<QCheckBox*>(ui->tablewt_examList->cellWidget(i, 0));
  213. if(chk && chk->isChecked())
  214. {
  215. list<<QString::number(vNoticeList[i].nId);
  216. }
  217. }
  218. if(list.count() > 0)
  219. {
  220. QString sIds = list.join(",");
  221. setNoticeRead(sIds);
  222. }
  223. }
  224. void clNoticeList::onUpdateNoticeReadStatus(CUpdateNoticeReadStatus unrs)
  225. {
  226. if(unrs.nCode == 200)
  227. {
  228. QStringList list = unrs.sIds.split(",");
  229. for(QString sId : list)
  230. {
  231. updateReadStatus(sId.toLongLong());
  232. }
  233. int unReadCount = 0;
  234. int nSize = vNoticeList.size();
  235. for (int i = 0; i < nSize; ++i)
  236. {
  237. CNoticeInfo &ni = vNoticeList[i];
  238. if(!ni.bHasRead)
  239. {
  240. ++unReadCount;
  241. }
  242. }
  243. emit unReadNoticeCount(unReadCount);
  244. }
  245. else
  246. {
  247. if(unrs.sMessage.isEmpty())
  248. {
  249. ShowMsg(QString::fromLocal8Bit("更新通知状态失败"), (QWidget*)(this->parent()), MSG_ICON_TYPE::mit_error);
  250. }
  251. else
  252. {
  253. ShowMsg(unrs.sMessage, (QWidget*)(this->parent()), MSG_ICON_TYPE::mit_error);
  254. }
  255. }
  256. }
  257. void clNoticeList::updateReadStatus(__int64 nId)
  258. {
  259. int nSize = vNoticeList.size();
  260. for (int i = 0; i < nSize; ++i)
  261. {
  262. CNoticeInfo &ni = vNoticeList[i];
  263. if (ni.nId == nId)
  264. {
  265. ni.bHasRead = true;
  266. QString sIconFile = ":/images/icon-notice-read.png";
  267. QWidget *widget = ui->tablewt_examList->cellWidget(i, 1);
  268. if (widget)
  269. {
  270. QLabel *icon = widget->findChild<QLabel*>("icon");
  271. if (icon)
  272. {
  273. icon->setPixmap(QPixmap(sIconFile).scaled(g_appInfoPtr->m_fRate * 16, g_appInfoPtr->m_fRate * 12));
  274. }
  275. }
  276. }
  277. }
  278. emit readNotice(nId);
  279. }