clNoticePopWidget.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #include "clNoticePopWidget.h"
  2. #include "ui_clNoticePopWidget.h"
  3. #include "CAppInfo.h"
  4. #include <QGraphicsDropShadowEffect>
  5. clNoticePopWidget::clNoticePopWidget(QWidget *parent) :
  6. QWidget(parent),
  7. ui(new Ui::clNoticePopWidget)
  8. {
  9. ui->setupUi(this);
  10. setStyleSheet(g_appInfoPtr->m_sQssStr);
  11. }
  12. clNoticePopWidget::~clNoticePopWidget()
  13. {
  14. delete ui;
  15. }
  16. void clNoticePopWidget::setUI(const int nLeft, const int nTop, const int nWidth, const int nHeight)
  17. {
  18. setGeometry(nLeft, nTop, nWidth, nHeight);
  19. ui->widget_npw_BG->setGeometry(g_appInfoPtr->m_fRate*5, g_appInfoPtr->m_fRate*5, width()-g_appInfoPtr->m_fRate*10, height()-g_appInfoPtr->m_fRate*10);
  20. ui->label_noticeIcon->setGeometry(g_appInfoPtr->m_fRate*20, g_appInfoPtr->m_fRate*24,
  21. g_appInfoPtr->m_fRate*16, g_appInfoPtr->m_fRate*12);
  22. ui->label_noticeTitle->adjustSize();
  23. ui->label_noticeTitle->setGeometry(ui->label_noticeIcon->x() + ui->label_noticeIcon->width() + g_appInfoPtr->m_fRate*8,
  24. ui->label_noticeIcon->y() + (ui->label_noticeIcon->height() - ui->label_noticeTitle->height())/2,
  25. ui->label_noticeTitle->width(), ui->label_noticeTitle->height());
  26. ui->txtb_noticeContent->setGeometry(ui->label_noticeIcon->x(), ui->label_noticeTitle->y() + ui->label_noticeTitle->height() + g_appInfoPtr->m_fRate*10,
  27. g_appInfoPtr->m_fRate*260, g_appInfoPtr->m_fRate*60);
  28. ui->btn_detail->setGeometry(ui->widget_npw_BG->width() - g_appInfoPtr->m_fRate*(20 + 80),
  29. ui->widget_npw_BG->height() - g_appInfoPtr->m_fRate*(20 + 30),
  30. g_appInfoPtr->m_fRate*80, g_appInfoPtr->m_fRate*30);
  31. ui->btn_ignore->setGeometry(ui->btn_detail->x() - g_appInfoPtr->m_fRate*10 - ui->btn_detail->width(), ui->btn_detail->y(),
  32. ui->btn_detail->width(), ui->btn_detail->height());
  33. QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect;
  34. effect->setOffset(g_appInfoPtr->m_fRate*4,g_appInfoPtr->m_fRate*4);
  35. effect->setColor(QColor(0,0,0,30));
  36. effect->setBlurRadius(g_appInfoPtr->m_fRate*16);
  37. ui->widget_npw_BG->setGraphicsEffect(effect);
  38. }
  39. void clNoticePopWidget::addNotice(const CNoticeInfo ni)
  40. {
  41. std::vector<CNoticeInfo>::iterator it =
  42. std::find_if(vIgnoreNL.begin(), vIgnoreNL.end(), [&ni](const CNoticeInfo &temp) {
  43. return temp.nId == ni.nId;
  44. });
  45. if (it != vIgnoreNL.end())
  46. {
  47. return;
  48. }
  49. vNL.push_back(ni);
  50. if (vNL.size() == 1)
  51. {
  52. showNotice(ni);
  53. }
  54. }
  55. void clNoticePopWidget::setNoticeRead(__int64 nId)
  56. {
  57. std::vector<CNoticeInfo>::iterator it =
  58. std::find_if(vNL.begin(), vNL.end(), [&nId](const CNoticeInfo &temp) {
  59. return temp.nId == nId;
  60. });
  61. if (it != vNL.end())
  62. {
  63. vNL.erase(it);
  64. if (vNL.size() <= 0)
  65. {
  66. hide();
  67. }
  68. else
  69. {
  70. showNotice(*vNL.begin());
  71. }
  72. }
  73. }
  74. void clNoticePopWidget::showNotice(const CNoticeInfo ni)
  75. {
  76. if (ni.bHasRecalled)
  77. {
  78. ui->label_noticeTitle->setText(QString::fromLocal8Bit("发送者已撤回消息:%1").arg(ni.sTitle));
  79. ui->label_noticeTitle->adjustSize();
  80. ui->txtb_noticeContent->insertPlainText(QString::fromLocal8Bit("该消息已经被发送者撤回。"));
  81. }
  82. else
  83. {
  84. ui->label_noticeTitle->setText(ni.sTitle);
  85. ui->label_noticeTitle->adjustSize();
  86. ui->txtb_noticeContent->insertHtml(ni.sContent);
  87. }
  88. }
  89. int clNoticePopWidget::noticeCount()
  90. {
  91. return vNL.size();
  92. }
  93. void clNoticePopWidget::on_btn_detail_clicked()
  94. {
  95. emit showNoticeDetail(vNL.begin()->nId);
  96. on_btn_ignore_clicked();
  97. }
  98. void clNoticePopWidget::on_btn_ignore_clicked()
  99. {
  100. vIgnoreNL.push_back(*vNL.begin());
  101. vNL.erase(vNL.begin());
  102. if(vNL.size() <= 0)
  103. {
  104. hide();
  105. }
  106. }