/wallet/qt/sociallinks.cpp

https://github.com/NeblioTeam/neblio · C++ · 68 lines · 59 code · 9 blank · 0 comment · 3 complexity · e733eda0464aff39194ac0f84d91d4d2 MD5 · raw file

  1. #include "sociallinks.h"
  2. #include <QClipboard>
  3. #include <QDesktopServices>
  4. #include <QGuiApplication>
  5. #include <QMessageBox>
  6. #include <QUrl>
  7. const char* DiscordLink = "https://discord.gg/PFt3bVw";
  8. const char* FacebookLink = "https://www.facebook.com/neblioteam";
  9. const char* GithubLink = "https://github.com/NeblioTeam/neblio";
  10. const char* InstagramLink = "https://www.instagram.com/neblio.official";
  11. const char* RedditLink = "https://www.reddit.com/r/Neblio";
  12. const char* TelegramLink = "https://t.me/neblio_official";
  13. const char* TwitterLink = "https://twitter.com/NeblioTeam";
  14. const char* YoutubeLink = "https://www.youtube.com/neblio";
  15. ClickableLabel* SocialLinks::makeLabelOfLogo(const QString& iconPath, const QString& link)
  16. {
  17. ClickableLabel* label = new ClickableLabel(this);
  18. QPixmap redditPixmap(iconPath);
  19. redditPixmap = redditPixmap.scaledToHeight(32, Qt::SmoothTransformation);
  20. label->setPixmap(redditPixmap);
  21. label->setToolTip("Click to visit: " + link);
  22. connect(label, &ClickableLabel::clicked, this, [&, link]() { openURL(link); });
  23. return label;
  24. }
  25. void SocialLinks::openURL(const QString& url)
  26. {
  27. if (!QDesktopServices::openUrl(QUrl(url))) {
  28. QMessageBox::StandardButton res =
  29. QMessageBox::warning(this, "Could not find browser",
  30. "Failed to open URL. Would you like to copy the link to clipboard?",
  31. QMessageBox::StandardButton::Yes | QMessageBox::StandardButton::No,
  32. QMessageBox::StandardButton::Yes);
  33. if (res == QMessageBox::StandardButton::Yes) {
  34. QClipboard* clipboard = QGuiApplication::clipboard();
  35. clipboard->setText(url);
  36. }
  37. }
  38. }
  39. SocialLinks::SocialLinks(QWidget* parent) : QWidget(parent)
  40. {
  41. mainLayout = new QGridLayout;
  42. discordLabel = makeLabelOfLogo(":icons/discord-logo", DiscordLink);
  43. facebookLabel = makeLabelOfLogo(":icons/facebook-logo", FacebookLink);
  44. githubLabel = makeLabelOfLogo(":icons/github-logo", GithubLink);
  45. instagramLabel = makeLabelOfLogo(":icons/instagram-logo", InstagramLink);
  46. redditLabel = makeLabelOfLogo(":icons/reddit-logo", RedditLink);
  47. telegramLabel = makeLabelOfLogo(":icons/telegram-logo", TelegramLink);
  48. twitterLabel = makeLabelOfLogo(":icons/twitter-logo", TwitterLink);
  49. youtubeLabel = makeLabelOfLogo(":icons/youtube-logo", YoutubeLink);
  50. mainLayout->addWidget(discordLabel, 0, 0);
  51. mainLayout->addWidget(telegramLabel, 0, 1);
  52. mainLayout->addWidget(twitterLabel, 0, 2);
  53. mainLayout->addWidget(facebookLabel, 0, 3);
  54. mainLayout->addWidget(instagramLabel, 0, 4);
  55. mainLayout->addWidget(redditLabel, 0, 5);
  56. mainLayout->addWidget(youtubeLabel, 0, 6);
  57. mainLayout->addWidget(githubLabel, 0, 7);
  58. this->setLayout(mainLayout);
  59. }