earn_icons.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #include "info/channel_statistics/earn/earn_icons.h"
  8. #include "ui/effects/premium_graphics.h"
  9. #include "ui/rect.h"
  10. #include "styles/style_menu_icons.h"
  11. #include "styles/style_widgets.h"
  12. #include "styles/style_info.h" // infoIconReport.
  13. #include <QFile>
  14. #include <QtSvg/QSvgRenderer>
  15. namespace Ui::Earn {
  16. namespace {
  17. [[nodiscard]] QByteArray CurrencySvg(const QColor &c) {
  18. const auto color = u"rgb(%1,%2,%3)"_q
  19. .arg(c.red())
  20. .arg(c.green())
  21. .arg(c.blue())
  22. .toUtf8();
  23. return R"(
  24. <svg width="72px" height="72px" viewBox="0 0 72 72">
  25. <g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
  26. <g transform="translate(9.000000, 14.000000)
  27. " stroke-width="7.2" stroke=")" + color + R"(">
  28. <path d="M2.96014341,0 L50.9898193,0 C51.9732032,-7.06402744e-15
  29. 52.7703933,0.797190129 52.7703933,1.78057399 C52.7703933,2.08038611
  30. 52.6946886,2.3753442 52.5502994,2.63809702 L29.699977,44.2200383
  31. C28.7527832,45.9436969 26.5876295,46.5731461 24.8639708,45.6259523
  32. C24.2556953,45.2916896 23.7583564,44.7869606 23.4331014,44.1738213
  33. L1.38718565,2.61498853 C0.926351231,1.74626794 1.25700829,0.668450654
  34. 2.12572888,0.20761623 C2.38272962,0.0712838007 2.6692209,4.97530809e-16
  35. 2.96014341,0 Z"></path>
  36. <line x1="27" y1="44.4532875" x2="27" y2="0"></line>
  37. </g>
  38. </g>
  39. </svg>)";
  40. }
  41. } // namespace
  42. QImage IconCurrencyColored(
  43. const style::font &font,
  44. const QColor &c) {
  45. const auto s = Size(font->ascent);
  46. auto svg = QSvgRenderer(CurrencySvg(c));
  47. auto image = QImage(
  48. s * style::DevicePixelRatio(),
  49. QImage::Format_ARGB32_Premultiplied);
  50. image.setDevicePixelRatio(style::DevicePixelRatio());
  51. image.fill(Qt::transparent);
  52. {
  53. auto p = QPainter(&image);
  54. svg.render(&p, Rect(s));
  55. }
  56. return image;
  57. }
  58. QByteArray CurrencySvgColored(const QColor &c) {
  59. return CurrencySvg(c);
  60. }
  61. QImage MenuIconCurrency(const QSize &size) {
  62. auto image = QImage(
  63. size * style::DevicePixelRatio(),
  64. QImage::Format_ARGB32_Premultiplied);
  65. image.setDevicePixelRatio(style::DevicePixelRatio());
  66. image.fill(Qt::transparent);
  67. auto p = QPainter(&image);
  68. st::infoIconReport.paintInCenter(
  69. p,
  70. Rect(size),
  71. st::infoIconFg->c);
  72. p.setCompositionMode(QPainter::CompositionMode_Clear);
  73. const auto w = st::lineWidth * 6;
  74. p.fillRect(
  75. QRect(
  76. rect::center(Rect(size)).x() - w / 2,
  77. rect::center(Rect(size)).y() - w,
  78. w,
  79. w * 2),
  80. Qt::white);
  81. p.setCompositionMode(QPainter::CompositionMode_SourceOver);
  82. const auto s = Size(st::inviteLinkSubscribeBoxTerms.style.font->ascent);
  83. auto svg = QSvgRenderer(CurrencySvg(st::infoIconFg->c));
  84. svg.render(
  85. &p,
  86. QRectF(
  87. (size.width() - s.width()) / 2.,
  88. (size.height() - s.height()) / 2.,
  89. s.width(),
  90. s.height()));
  91. return image;
  92. }
  93. QImage MenuIconCredits() {
  94. constexpr auto kStrokeWidth = 5;
  95. const auto sizeShift = st::lineWidth * 1.5;
  96. auto colorized = [&] {
  97. auto f = QFile(Ui::Premium::Svg());
  98. if (!f.open(QIODevice::ReadOnly)) {
  99. return QString();
  100. }
  101. return QString::fromUtf8(f.readAll()).replace(
  102. u"#fff"_q,
  103. u"#ffffff00"_q);
  104. }();
  105. colorized.replace(
  106. u"stroke=\"none\""_q,
  107. u"stroke=\"%1\""_q.arg(st::menuIconColor->c.name()));
  108. colorized.replace(
  109. u"stroke-width=\"1\""_q,
  110. u"stroke-width=\"%1\""_q.arg(kStrokeWidth));
  111. auto svg = QSvgRenderer(colorized.toUtf8());
  112. svg.setViewBox(svg.viewBox()
  113. + Margins(style::ConvertScale(kStrokeWidth)));
  114. auto image = QImage(
  115. st::menuIconLinks.size() * style::DevicePixelRatio(),
  116. QImage::Format_ARGB32_Premultiplied);
  117. image.setDevicePixelRatio(style::DevicePixelRatio());
  118. image.fill(Qt::transparent);
  119. {
  120. auto p = QPainter(&image);
  121. svg.render(&p, Rect(st::menuIconLinks.size()) - Margins(sizeShift));
  122. }
  123. return image;
  124. }
  125. } // namespace Ui::Earn