MessageDialog.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include "MessageDialog.h"
  2. #include "Common/AutoWrap.h"
  3. #include "Common/StyleSheet.h"
  4. MessageDialog::MessageDialog(const QString &title, const QString &content, QWidget *parent) : MaskDialogBase(parent)
  5. {
  6. m_content = content;
  7. m_titleLabel = new QLabel(title, widget);
  8. m_contentLabel = new QLabel(content, widget);
  9. m_yesButton = new QPushButton("OK", widget);
  10. m_cancelButton = new QPushButton("Cancel", widget);
  11. initWidget();
  12. }
  13. void MessageDialog::initWidget()
  14. {
  15. windowMask->resize(this->size());
  16. widget->setMaximumWidth(540);
  17. m_titleLabel->move(24, 24);
  18. m_contentLabel->move(24, 56);
  19. m_contentLabel->setText(TextWrap::wrap(m_content, 71).first);
  20. setQss();
  21. initLayout();
  22. connect(m_yesButton, &QPushButton::clicked, this, &MessageDialog::onYesButtonClicked);
  23. connect(m_cancelButton, &QPushButton::clicked, this, &MessageDialog::onCancelButtonClicked);
  24. }
  25. void MessageDialog::initLayout()
  26. {
  27. m_contentLabel->adjustSize();
  28. widget->setFixedSize(48 + m_contentLabel->width(), m_contentLabel->y() + m_contentLabel->height() + 92);
  29. m_yesButton->resize((widget->width() - 54) / 2, 32);
  30. m_cancelButton->resize(m_yesButton->width(), 32);
  31. m_yesButton->move(24, widget->height() - 56);
  32. m_cancelButton->move(widget->width() - 24 - m_cancelButton->width(), widget->height() - 56);
  33. }
  34. void MessageDialog::setQss()
  35. {
  36. windowMask->setObjectName("windowMask");
  37. m_titleLabel->setObjectName("titleLabel");
  38. m_contentLabel->setObjectName("contentLabel");
  39. FluentStyleSheet::apply("MESSAGE_DIALOG", this);
  40. }
  41. void MessageDialog::onCancelButtonClicked()
  42. {
  43. emit cancelSignal();
  44. setResult(QDialog::Rejected);
  45. close();
  46. }
  47. void MessageDialog::onYesButtonClicked()
  48. {
  49. setEnabled(false);
  50. emit yesSignal();
  51. setResult(QDialog::Accepted);
  52. close();
  53. }