diff --git a/Telegram/SourceFiles/info/channel_statistics/earn/channel_earn.style b/Telegram/SourceFiles/info/channel_statistics/earn/channel_earn.style index 4c7acfe31..3c20cedbf 100644 --- a/Telegram/SourceFiles/info/channel_statistics/earn/channel_earn.style +++ b/Telegram/SourceFiles/info/channel_statistics/earn/channel_earn.style @@ -109,6 +109,9 @@ channelEarnLearnDescription: FlatLabel(defaultFlatLabel) { align: align(top); } +channelEarnCurrencyCommonMargins: margins(0px, 3px, 1px, 0px); +channelEarnCurrencyLearnMargins: margins(0px, 2px, 0px, 0px); + sponsoredAboutTitleIcon: icon {{ "sponsored/large_about", activeButtonFg }}; sponsoredAboutPrivacyIcon: icon {{ "sponsored/privacy_about", boxTextFg }}; sponsoredAboutRemoveIcon: icon {{ "sponsored/remove_about", boxTextFg }}; diff --git a/Telegram/SourceFiles/info/channel_statistics/earn/info_earn_inner_widget.cpp b/Telegram/SourceFiles/info/channel_statistics/earn/info_earn_inner_widget.cpp index 505900670..2d922d344 100644 --- a/Telegram/SourceFiles/info/channel_statistics/earn/info_earn_inner_widget.cpp +++ b/Telegram/SourceFiles/info/channel_statistics/earn/info_earn_inner_widget.cpp @@ -48,6 +48,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "styles/style_statistics.h" #include "styles/style_window.h" // mainMenuToggleFourStrokes. +#include #include namespace Info::ChannelEarn { @@ -69,6 +70,30 @@ void ShowMenu(not_null box, const QString &text) { menu->popup(QCursor::pos()); } +[[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"( + + + + + + + +)"; +} void AddArrow(not_null parent) { const auto arrow = Ui::CreateChild(parent.get()); @@ -139,6 +164,7 @@ void AddRecipient(not_null box, const TextWithEntities &t) { }); } +#if 0 [[nodiscard]] TextWithEntities EmojiCurrency( not_null session) { auto emoji = TextWithEntities{ @@ -152,6 +178,24 @@ void AddRecipient(not_null box, const TextWithEntities &t) { } return emoji; } +#endif + +[[nodiscard]] QImage IconCurrency( + const style::FlatLabel &label, + const QColor &c) { + const auto s = Size(label.style.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; +} [[nodiscard]] QString FormatDate(const QDateTime &date) { return tr::lng_group_call_starts_short_date( @@ -201,7 +245,6 @@ void InnerWidget::fill() { constexpr auto kMinus = QChar(0x2212); constexpr auto kApproximately = QChar(0x2248); - const auto currency = u"TON"_q; const auto multiplier = data.usdRate; constexpr auto kNonInteractivePeriod = 1717200000; @@ -219,13 +262,35 @@ void InnerWidget::fill() { }; const auto addEmojiToMajor = [=]( not_null label, - EarnInt value) { - auto emoji = EmojiCurrency(session); + EarnInt value, + std::optional isIn, + std::optional margins) { + const auto &st = label->st(); + auto icon = Ui::Text::SingleCustomEmoji( + session->data().customEmojiManager().registerInternalEmoji( + IconCurrency( + st, + !isIn + ? st::activeButtonBg->c + : (*isIn) + ? st::boxTextFgGood->c + : st::menuIconAttentionColor->c), + margins ? *margins : st::channelEarnCurrencyCommonMargins, + false)); + auto prepended = !isIn + ? TextWithEntities() + : TextWithEntities::Simple((*isIn) ? QChar('+') : kMinus); label->setMarkedText( - emoji.append(' ').append(MajorPart(value)), + prepended.append(icon).append(MajorPart(value)), makeContext(label)); }; + const auto bigCurrencyIcon = Ui::Text::SingleCustomEmoji( + session->data().customEmojiManager().registerInternalEmoji( + IconCurrency(st::boxTitle, st::activeButtonBg->c), + st::channelEarnCurrencyLearnMargins, + false)); + const auto arrow = Ui::Text::SingleCustomEmoji( session->data().customEmojiManager().registerInternalEmoji( st::topicButtonArrow, @@ -357,7 +422,7 @@ void InnerWidget::fill() { tr::lng_channel_earn_learn_coin_title( lt_emoji, rpl::single( - Ui::Text::Link(EmojiCurrency(session), 1)), + Ui::Text::Link(bigCurrencyIcon, 1)), Ui::Text::RichLangValue ) | rpl::start_with_next([=](TextWithEntities t) { l->setMarkedText(std::move(t), makeContext(l)); @@ -406,6 +471,8 @@ void InnerWidget::fill() { container, tr::lng_channel_earn_learn_close(), st::defaultActiveButton); + button->setTextTransform( + Ui::RoundButton::TextTransform::NoTransform); button->resizeToWidth(box->width() - st.buttonPadding.left() - st.buttonPadding.left()); @@ -466,7 +533,7 @@ void InnerWidget::fill() { const auto majorLabel = Ui::CreateChild( line, st::channelEarnOverviewMajorLabel); - addEmojiToMajor(majorLabel, value); + addEmojiToMajor(majorLabel, value, {}, {}); const auto minorLabel = Ui::CreateChild( line, MinorPart(value), @@ -511,17 +578,18 @@ void InnerWidget::fill() { addOverview(data.overallRevenue, tr::lng_channel_earn_total); Ui::AddSkip(container); } +#ifndef _DEBUG if (!channel->amCreator()) { Ui::AddSkip(container); Ui::AddSkip(container); return; } +#endif Ui::AddSkip(container); Ui::AddDivider(container); Ui::AddSkip(container); if (channel) { const auto value = data.availableBalance; - Ui::AddSkip(container); AddHeader(container, tr::lng_channel_earn_balance_title); Ui::AddSkip(container); @@ -533,7 +601,11 @@ void InnerWidget::fill() { const auto majorLabel = Ui::CreateChild( labels, st::channelEarnBalanceMajorLabel); - addEmojiToMajor(majorLabel, value); + { + const auto &m = st::channelEarnCurrencyCommonMargins; + const auto p = QMargins(m.left(), 0, m.right(), m.bottom()); + addEmojiToMajor(majorLabel, value, {}, p); + } majorLabel->setAttribute(Qt::WA_TransparentForMouseEvents); const auto minorLabel = Ui::CreateChild( labels, @@ -616,9 +688,6 @@ void InnerWidget::fill() { : tr::lng_channel_earn_balance_about_temp); Ui::AddSkip(container); } - Ui::AddSkip(container); - Ui::AddDivider(container); - Ui::AddSkip(container); { AddHeader(container, tr::lng_channel_earn_history_title); Ui::AddSkip(container); @@ -683,20 +752,16 @@ void InnerWidget::fill() { const auto color = (isIn ? st::boxTextFgGood : st::menuIconAttentionColor)->c; - const auto majorText = (isIn ? '+' : kMinus) - + MajorPart(entry.amount); const auto majorLabel = Ui::CreateChild( wrap, - majorText, st::channelEarnHistoryMajorLabel); + addEmojiToMajor(majorLabel, entry.amount, isIn, {}); majorLabel->setAttribute(Qt::WA_TransparentForMouseEvents); majorLabel->setTextColorOverride(color); - const auto minorText = MinorPart(entry.amount) - + ' ' - + currency; + const auto minorText = MinorPart(entry.amount); const auto minorLabel = Ui::CreateChild( wrap, - minorText, + rpl::single(minorText), st::channelEarnHistoryMinorLabel); minorLabel->setAttribute(Qt::WA_TransparentForMouseEvents); minorLabel->setTextColorOverride(color); @@ -705,7 +770,7 @@ void InnerWidget::fill() { rpl::single(QString())); Ui::ToggleChildrenVisibility(wrap, true); - const auto detailsBox = [=, peer = _peer]( + const auto detailsBox = [=, amount = entry.amount, peer = _peer]( not_null box) { Ui::AddSkip(box->verticalLayout()); Ui::AddSkip(box->verticalLayout()); @@ -716,8 +781,8 @@ void InnerWidget::fill() { const auto majorLabel = Ui::CreateChild( labels, - majorText, st::channelEarnOverviewMajorLabel); + addEmojiToMajor(majorLabel, amount, isIn, {}); majorLabel->setAttribute(Qt::WA_TransparentForMouseEvents); majorLabel->setTextColorOverride(color); const auto minorLabel = Ui::CreateChild(