LinkWidget.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 <QDesktopServices>
  10. #include <QEvent>
  11. #include <QMouseEvent>
  12. #include <QVBoxLayout>
  13. namespace O3DE::ProjectManager
  14. {
  15. LinkLabel::LinkLabel(const QString& text, const QUrl& url, int fontSize, QWidget* parent)
  16. : QLabel(text, parent)
  17. , m_url(url)
  18. , m_fontSize(fontSize)
  19. {
  20. SetDefaultStyle();
  21. }
  22. void LinkLabel::mousePressEvent([[maybe_unused]] QMouseEvent* event)
  23. {
  24. if (m_url.isValid())
  25. {
  26. QDesktopServices::openUrl(m_url);
  27. }
  28. emit clicked();
  29. }
  30. void LinkLabel::enterEvent([[maybe_unused]] QEvent* event)
  31. {
  32. setStyleSheet(QString("font-size: %1px; color: #94D2FF; text-decoration: underline;").arg(m_fontSize));
  33. }
  34. void LinkLabel::leaveEvent([[maybe_unused]] QEvent* event)
  35. {
  36. SetDefaultStyle();
  37. }
  38. void LinkLabel::SetUrl(const QUrl& url)
  39. {
  40. m_url = url;
  41. }
  42. void LinkLabel::SetDefaultStyle()
  43. {
  44. setStyleSheet(QString("font-size: %1px; color: #94D2FF;").arg(m_fontSize));
  45. }
  46. } // namespace O3DE::ProjectManager