qspmsgdlg.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #include "qspmsgdlg.h"
  2. #include <QRect>
  3. #include <QPalette>
  4. #include <QDesktopServices>
  5. #include "mainwindow.h"
  6. #include "callbacks_gui.h"
  7. #include "comtools.h"
  8. QspMsgDlg::QspMsgDlg(QWidget *parent) : QDialog(parent)
  9. {
  10. }
  11. QspMsgDlg::~QspMsgDlg()
  12. {
  13. }
  14. QspMsgDlg::QspMsgDlg(const QString &caption, const QString &text, QWidget *parent) : QDialog(parent) {
  15. setWindowTitle(caption);
  16. sizePolicy().setHorizontalPolicy(QSizePolicy::Expanding);
  17. sizePolicy().setVerticalPolicy(QSizePolicy::Expanding);
  18. connect(&m_desc, SIGNAL(anchorClicked(QUrl)), this, SLOT(OnLinkClicked(QUrl)));
  19. m_desc.setHtml(text);
  20. m_desc.sizePolicy().setHorizontalPolicy(QSizePolicy::Expanding);
  21. m_desc.sizePolicy().setVerticalPolicy(QSizePolicy::Expanding);
  22. connect(&okButton, SIGNAL(clicked()), this, SLOT(close()));
  23. okButton.setGeometry(QRect(10, 130, 100, 20));
  24. okButton.setText(tr("OK"));
  25. m_desc.document()->setTextWidth(400);
  26. resize(450, m_desc.document()->size().height() + 65);
  27. layout.addWidget(&m_desc);
  28. layout.addWidget(&okButton);
  29. setLayout(&layout);
  30. setModal(true);
  31. //exec();
  32. }
  33. QspMsgDlg::QspMsgDlg(const QColor& backColor,
  34. const QColor& fontColor,
  35. const QFont& new_font,
  36. const QString& caption,
  37. const QString& text,
  38. bool isHtml,
  39. const QString& gamePath,
  40. QWidget *parent) : QDialog(parent)
  41. {
  42. m_desc.SetGamePath(gamePath);
  43. m_desc.SetIsHtml(isHtml);
  44. m_desc.SetBackgroundColor(backColor);
  45. m_desc.SetForegroundColor(fontColor);
  46. m_desc.SetTextFont(new_font);
  47. m_desc.SetText(text);
  48. m_desc.setBackgroundRole(QPalette::NoRole);
  49. QPalette p = palette();
  50. p.setColor(QPalette::Base, backColor);
  51. //p.setColor(QPalette::Window, backColor);
  52. setPalette(p);
  53. // ----------
  54. setWindowTitle(caption);
  55. sizePolicy().setHorizontalPolicy(QSizePolicy::Expanding);
  56. sizePolicy().setVerticalPolicy(QSizePolicy::Expanding);
  57. m_desc.sizePolicy().setHorizontalPolicy(QSizePolicy::Expanding);
  58. m_desc.sizePolicy().setVerticalPolicy(QSizePolicy::Expanding);
  59. connect(&okButton, SIGNAL(clicked()), this, SLOT(close()));
  60. okButton.setGeometry(QRect(10, 130, 100, 20));
  61. okButton.setText("OK");
  62. okButton.setDefault(true);
  63. okButton.setFont(new_font);
  64. okButton.setFocus(Qt::PopupFocusReason);
  65. m_desc.document()->setTextWidth(400);
  66. resize(450, m_desc.document()->size().height() + 65);
  67. layout.addWidget(&m_desc);
  68. layout.addWidget(&okButton);
  69. setLayout(&layout);
  70. setModal(true);
  71. //exec();
  72. }
  73. void QspMsgDlg::OnLinkClicked(const QUrl &url)
  74. {
  75. QString href;
  76. href = QByteArray::fromPercentEncoding(url.toString().toUtf8());
  77. if (href.startsWith("#"))
  78. {
  79. m_desc.setSource(url);
  80. }
  81. else if (href.startsWith("EXEC:", Qt::CaseInsensitive)) //NOTE: was not part of original player
  82. {
  83. QString string = href.mid(5);
  84. if (!QSPExecString(qspStringFromQString(string), QSP_TRUE))
  85. if(this->parent() != 0)
  86. if(this->parent()->objectName() == QStringLiteral("MainWindow"))
  87. qobject_cast<MainWindow*>(this->parent())->ShowError(); //TODO: replace with signal
  88. }
  89. else
  90. {
  91. QDesktopServices::openUrl(url);
  92. }
  93. }