awMsgBox.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #include "awMsgBox.h"
  2. #include "ui_awMsgBox.h"
  3. #include "CAppInfo.h"
  4. #include <QDesktopWidget>
  5. #include <QGraphicsDropShadowEffect>
  6. std::list<std::shared_ptr<awMsgBox>> awMsgBox::vMsgList;
  7. std::mutex awMsgBox::msgMutex;
  8. awMsgBox::awMsgBox(QWidget *parent) :
  9. QDialog(parent),
  10. ui(new Ui::awMsgBox)
  11. {
  12. ui->setupUi(this);
  13. setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint);
  14. setAttribute(Qt::WA_TranslucentBackground);
  15. setStyleSheet(g_appInfoPtr->m_sQssStr);
  16. if(m_pTimer == nullptr)
  17. {
  18. m_pTimer = std::make_shared<QTimer>();
  19. m_pTimer->setInterval(3 * 1000);
  20. }
  21. connect(m_pTimer.get(), &QTimer::timeout, this, [&]() {
  22. m_pTimer->stop();
  23. if (vMsgList.size() > 0)
  24. {
  25. std::scoped_lock lock(msgMutex);
  26. vMsgList.pop_front();
  27. }
  28. size_t i = 0;
  29. for (std::list<std::shared_ptr<awMsgBox>>::iterator it = vMsgList.begin(); it != vMsgList.end(); ++it)
  30. {
  31. (*it)->setGeometry((*it)->x(),
  32. g_appInfoPtr->m_fRate * 84 + i * g_appInfoPtr->m_fRate * 90,
  33. (*it)->width(), (*it)->height());
  34. ++i;
  35. }
  36. });
  37. m_pTimer->start();
  38. }
  39. awMsgBox::~awMsgBox()
  40. {
  41. m_pTimer->stop();
  42. delete ui;
  43. }
  44. void awMsgBox::initUI()
  45. {
  46. ui->label_awmb_content->adjustSize();
  47. int nCW = g_appInfoPtr->m_fRate*40 + g_appInfoPtr->m_fRate*40 + g_appInfoPtr->m_fRate*(28 + 10) + ui->label_awmb_content->width();
  48. QDesktopWidget *dekwiget = QApplication::desktop();
  49. setGeometry((dekwiget->width() - nCW - g_appInfoPtr->m_fRate*10)/2,
  50. g_appInfoPtr->m_fRate*84 + vMsgList.size()*g_appInfoPtr->m_fRate * 90,
  51. nCW + g_appInfoPtr->m_fRate*10, g_appInfoPtr->m_fRate*90);
  52. ui->widget_awmb_BG->setGeometry(5, 5 , nCW, g_appInfoPtr->m_fRate*80);
  53. ui->label_awmb_icon->setGeometry(g_appInfoPtr->m_fRate*40, g_appInfoPtr->m_fRate*26,
  54. g_appInfoPtr->m_fRate*28, g_appInfoPtr->m_fRate*28);
  55. ui->label_awmb_content->setGeometry(ui->label_awmb_icon->x() + ui->label_awmb_icon->width() + g_appInfoPtr->m_fRate*10,
  56. (height() - ui->label_awmb_content->height())/2,
  57. ui->label_awmb_content->width(), ui->label_awmb_content->height());
  58. ui->btn_awmb_close->setGeometry(ui->widget_awmb_BG->width() - g_appInfoPtr->m_fRate*(10 + 16),
  59. g_appInfoPtr->m_fRate*10, g_appInfoPtr->m_fRate*16, g_appInfoPtr->m_fRate*16);
  60. QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect;
  61. effect->setOffset(g_appInfoPtr->m_fRate*4,g_appInfoPtr->m_fRate*4);
  62. effect->setColor(QColor(0,0,0,30));
  63. effect->setBlurRadius(g_appInfoPtr->m_fRate*16);
  64. ui->widget_awmb_BG->setGraphicsEffect(effect);
  65. }
  66. void ShowMsg(QString sMsg, QWidget *parent)
  67. {
  68. std::shared_ptr<awMsgBox> msg = std::make_shared<awMsgBox>(parent);
  69. msg->setMsg(sMsg);
  70. msg->initUI();
  71. msg->show();
  72. std::scoped_lock lock(awMsgBox::msgMutex);
  73. awMsgBox::vMsgList.push_back(msg);
  74. }
  75. void awMsgBox::setMsg(QString sMsg)
  76. {
  77. ui->label_awmb_content->setText(sMsg);
  78. }
  79. void awMsgBox::on_btn_awmb_close_clicked()
  80. {
  81. reject();
  82. }