qspmsgdlg.cpp 3.1 KB

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