/dev/Code/Tools/News/NewsShared/Qt/KeepInTouchView.cpp

https://github.com/aws/lumberyard · C++ · 87 lines · 64 code · 12 blank · 11 comment · 15 complexity · d65e4a948da62c2d3bca8a39f7d84497 MD5 · raw file

  1. /*
  2. * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
  3. * its licensors.
  4. *
  5. * For complete copyright and license terms please see the LICENSE at the root of this
  6. * distribution (the "License"). All use of this software is governed by the License,
  7. * or, if provided, by the license below or the license accompanying this file. Do not
  8. * remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
  9. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. *
  11. */
  12. #include "KeepInTouchView.h"
  13. #include "NewsShared/Qt/ui_KeepInTouchView.h"
  14. #include <QMap>
  15. #include <QUrl>
  16. #include <QString>
  17. #include <QDesktopServices>
  18. namespace News
  19. {
  20. KeepInTouchView::KeepInTouchView(QWidget* parent)
  21. : QWidget(parent)
  22. , m_ui(new Ui::KeepInTouchViewWidget())
  23. {
  24. m_ui->setupUi(this);
  25. m_ui->twich_container->setCursor(Qt::PointingHandCursor);
  26. m_ui->twitter_container->setCursor(Qt::PointingHandCursor);
  27. m_ui->youtube_container->setCursor(Qt::PointingHandCursor);
  28. m_ui->facebook_container->setCursor(Qt::PointingHandCursor);
  29. m_ui->twich_container->installEventFilter(this);
  30. m_ui->twitter_container->installEventFilter(this);
  31. m_ui->youtube_container->installEventFilter(this);
  32. m_ui->facebook_container->installEventFilter(this);
  33. }
  34. bool KeepInTouchView::eventFilter(QObject *watched, QEvent *event)
  35. {
  36. if (event->type() == QEvent::MouseButtonRelease)
  37. {
  38. if (watched == m_ui->twich_container)
  39. {
  40. return LaunchSocialMediaUrl(SocialMediaType::Twitch);
  41. }
  42. else if (watched == m_ui->twitter_container)
  43. {
  44. return LaunchSocialMediaUrl(SocialMediaType::Twitter);
  45. }
  46. else if (watched == m_ui->youtube_container)
  47. {
  48. return LaunchSocialMediaUrl(SocialMediaType::YouTube);
  49. }
  50. else if (watched == m_ui->facebook_container)
  51. {
  52. return LaunchSocialMediaUrl(SocialMediaType::Facebook);
  53. }
  54. }
  55. return QWidget::eventFilter(watched, event);
  56. }
  57. bool KeepInTouchView::LaunchSocialMediaUrl(SocialMediaType type)
  58. {
  59. static const QMap<SocialMediaType, const char*> socialMediaTypeToUrlMap =
  60. {
  61. { SocialMediaType::Twitch, m_twitchUrl },
  62. { SocialMediaType::Twitter, m_twitterUrl },
  63. { SocialMediaType::YouTube, m_youtubeUrl },
  64. { SocialMediaType::Facebook, m_facebookUrl }
  65. };
  66. if (socialMediaTypeToUrlMap.contains(type) == false)
  67. {
  68. return false;
  69. }
  70. QString link = socialMediaTypeToUrlMap[type];
  71. Q_EMIT linkActivatedSignal(link);
  72. return QDesktopServices::openUrl(QUrl(link));
  73. }
  74. }
  75. #include "NewsShared/Qt/KeepInTouchView.moc"