LinkWidget.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <LinkWidget.h>
  9. #include <ExternalLinkDialog.h>
  10. #include <SettingsInterface.h>
  11. #include <QDesktopServices>
  12. #include <QEvent>
  13. #include <QMouseEvent>
  14. #include <QVBoxLayout>
  15. namespace O3DE::ProjectManager
  16. {
  17. LinkLabel::LinkLabel(const QString& text, const QUrl& url, int fontSize, QWidget* parent)
  18. : AzQtComponents::ElidingLabel(text, parent)
  19. , m_url(url)
  20. , m_fontSize(fontSize)
  21. {
  22. SetDefaultStyle();
  23. }
  24. void LinkLabel::mousePressEvent([[maybe_unused]] QMouseEvent* event)
  25. {
  26. if (m_url.isValid())
  27. {
  28. // Check if user request not to be shown external link warning dialog
  29. bool skipDialog = false;
  30. SettingsInterface::Get()->Get(skipDialog, ISettings::ExternalLinkWarningKey);
  31. if (!skipDialog)
  32. {
  33. // Style does not apply if LinkLabel is parent so use parentWidget as parent instead
  34. ExternalLinkDialog* linkDialog = new ExternalLinkDialog(m_url, parentWidget());
  35. if (linkDialog->exec() == QDialog::Accepted)
  36. {
  37. QDesktopServices::openUrl(m_url);
  38. }
  39. }
  40. else
  41. {
  42. QDesktopServices::openUrl(m_url);
  43. }
  44. }
  45. emit clicked();
  46. }
  47. void LinkLabel::enterEvent([[maybe_unused]] QEvent* event)
  48. {
  49. setStyleSheet(QString("font-size: %1px; color: #94D2FF; text-decoration: underline;").arg(m_fontSize));
  50. }
  51. void LinkLabel::leaveEvent([[maybe_unused]] QEvent* event)
  52. {
  53. SetDefaultStyle();
  54. }
  55. QUrl LinkLabel::GetUrl() const
  56. {
  57. return m_url;
  58. }
  59. void LinkLabel::SetUrl(const QUrl& url)
  60. {
  61. m_url = url;
  62. }
  63. void LinkLabel::SetDefaultStyle()
  64. {
  65. setStyleSheet(QString("font-size: %1px; color: #94D2FF;").arg(m_fontSize));
  66. }
  67. } // namespace O3DE::ProjectManager