/* This file is part of Telegram Desktop, the official desktop application for the Telegram messaging service. For license and copyright information please follow this link: https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "info/channel_statistics/earn/earn_icons.h" #include "ui/effects/premium_graphics.h" #include "ui/rect.h" #include "styles/style_menu_icons.h" #include "styles/style_widgets.h" #include "styles/style_info.h" // infoIconReport. #include #include namespace Ui::Earn { namespace { [[nodiscard]] QByteArray CurrencySvg(const QColor &c) { const auto color = u"rgb(%1,%2,%3)"_q .arg(c.red()) .arg(c.green()) .arg(c.blue()) .toUtf8(); return R"( )"; } } // namespace QImage IconCurrencyColored( const style::font &font, const QColor &c) { const auto s = Size(font->ascent); auto svg = QSvgRenderer(CurrencySvg(c)); auto image = QImage( s * style::DevicePixelRatio(), QImage::Format_ARGB32_Premultiplied); image.setDevicePixelRatio(style::DevicePixelRatio()); image.fill(Qt::transparent); { auto p = QPainter(&image); svg.render(&p, Rect(s)); } return image; } QByteArray CurrencySvgColored(const QColor &c) { return CurrencySvg(c); } QImage MenuIconCurrency(const QSize &size) { auto image = QImage( size * style::DevicePixelRatio(), QImage::Format_ARGB32_Premultiplied); image.setDevicePixelRatio(style::DevicePixelRatio()); image.fill(Qt::transparent); auto p = QPainter(&image); st::infoIconReport.paintInCenter( p, Rect(size), st::infoIconFg->c); p.setCompositionMode(QPainter::CompositionMode_Clear); const auto w = st::lineWidth * 6; p.fillRect( QRect( rect::center(Rect(size)).x() - w / 2, rect::center(Rect(size)).y() - w, w, w * 2), Qt::white); p.setCompositionMode(QPainter::CompositionMode_SourceOver); const auto s = Size(st::inviteLinkSubscribeBoxTerms.style.font->ascent); auto svg = QSvgRenderer(CurrencySvg(st::infoIconFg->c)); svg.render( &p, QRectF( (size.width() - s.width()) / 2., (size.height() - s.height()) / 2., s.width(), s.height())); return image; } QImage MenuIconCredits() { constexpr auto kStrokeWidth = 5; const auto sizeShift = st::lineWidth * 1.5; auto colorized = [&] { auto f = QFile(Ui::Premium::Svg()); if (!f.open(QIODevice::ReadOnly)) { return QString(); } return QString::fromUtf8(f.readAll()).replace( u"#fff"_q, u"#ffffff00"_q); }(); colorized.replace( u"stroke=\"none\""_q, u"stroke=\"%1\""_q.arg(st::menuIconColor->c.name())); colorized.replace( u"stroke-width=\"1\""_q, u"stroke-width=\"%1\""_q.arg(kStrokeWidth)); auto svg = QSvgRenderer(colorized.toUtf8()); svg.setViewBox(svg.viewBox() + Margins(style::ConvertScale(kStrokeWidth))); auto image = QImage( st::menuIconLinks.size() * style::DevicePixelRatio(), QImage::Format_ARGB32_Premultiplied); image.setDevicePixelRatio(style::DevicePixelRatio()); image.fill(Qt::transparent); { auto p = QPainter(&image); svg.render(&p, Rect(st::menuIconLinks.size()) - Margins(sizeShift)); } return image; } } // namespace Ui::Earn