CustomMessageDlg.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #include "CustomMessageDlg.h"
  2. #include "ui_CustomMessageDlg.h"
  3. CustomMessageDlg::CustomMessageDlg(QWidget *parent)
  4. : QDialog(parent)
  5. , ui(new Ui::CustomMessageDlg)
  6. {
  7. ui->setupUi(this);
  8. this->setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::Dialog);
  9. //setAttribute(Qt::WA_TranslucentBackground);
  10. ns_module::ST_BUTTON_DONE butDone = { 1,2,"test",4,"test" };
  11. RunMsgWnd(butDone);
  12. }
  13. CustomMessageDlg::~CustomMessageDlg()
  14. {
  15. delete ui;
  16. }
  17. void CustomMessageDlg::RunMsgWnd(const ns_module::ST_BUTTON_DONE& butDone)
  18. {
  19. QString str = R"(QLabel { background-image: url()";
  20. switch (butDone.nId)
  21. {
  22. case ns_module::EN_MSG_WND_ICO::IHINT:
  23. str += ":/images/Mess/hint.png";
  24. break;
  25. case ns_module::EN_MSG_WND_ICO::IWARN:
  26. str += ":/images/Mess/warn.png";
  27. break;
  28. case ns_module::EN_MSG_WND_ICO::IERROR:
  29. str += ":/images/Mess/error.png";
  30. break;
  31. case ns_module::EN_MSG_WND_ICO::IRUN:
  32. str += ":/images/Mess/run.png";
  33. break;
  34. case ns_module::EN_MSG_WND_ICO::ISTOP:
  35. str += ":/images/Mess/stop.png";
  36. break;
  37. default:
  38. break;
  39. }
  40. str += R"();})";
  41. ui->errorLogLabel->setStyleSheet(str);
  42. ui->tIDlabel_errID->setText(QString::number(butDone.lError));
  43. ui->errorInfoTextEdit->setText(QString::fromLocal8Bit(butDone.strErrMeassage.c_str()));
  44. ui->errorDetailsInfoTextEdit->setText(QString::fromLocal8Bit(butDone.strErrMeassage.c_str()));
  45. }
  46. void CustomMessageDlg::mousePressEvent(QMouseEvent* event)
  47. {
  48. if(event->button() == Qt::LeftButton && event->pos().y() <= 48)
  49. {
  50. m_isTitleBarClicked = true;
  51. m_dragPosition = event->globalPos() - frameGeometry().topLeft();
  52. event->accept();
  53. }
  54. else
  55. {
  56. m_isTitleBarClicked = false;
  57. QDialog::mousePressEvent(event);
  58. }
  59. }
  60. void CustomMessageDlg::mouseMoveEvent(QMouseEvent* event)
  61. {
  62. if(m_isTitleBarClicked && (event->buttons() & Qt::LeftButton))
  63. {
  64. move(event->globalPos() - m_dragPosition);
  65. event->accept();
  66. }
  67. else
  68. {
  69. QDialog::mouseMoveEvent(event);
  70. }
  71. }
  72. void CustomMessageDlg::on_tCloseBut_clicked()
  73. {
  74. on_closeBut_clicked(); // TODO: 都交给它
  75. }
  76. void CustomMessageDlg::on_closeBut_clicked()
  77. {
  78. this->close();
  79. }