From 2e0e4006a1984eb17b902de6f04d3e0590a52791 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sun, 27 Oct 2024 11:03:57 +0300 Subject: [PATCH] Moved out generation of currency icon from svg to td_ui. --- .../channel_statistics/earn/earn_icons.cpp | 61 +++++++++++++++++++ .../info/channel_statistics/earn/earn_icons.h | 16 +++++ .../earn/info_channel_earn_list.cpp | 52 ++-------------- .../earn/info_channel_earn_list.h | 4 -- .../info/profile/info_profile_actions.cpp | 7 ++- .../window/window_session_controller.cpp | 5 +- Telegram/cmake/td_ui.cmake | 2 + 7 files changed, 92 insertions(+), 55 deletions(-) create mode 100644 Telegram/SourceFiles/info/channel_statistics/earn/earn_icons.cpp create mode 100644 Telegram/SourceFiles/info/channel_statistics/earn/earn_icons.h diff --git a/Telegram/SourceFiles/info/channel_statistics/earn/earn_icons.cpp b/Telegram/SourceFiles/info/channel_statistics/earn/earn_icons.cpp new file mode 100644 index 000000000..47616dff4 --- /dev/null +++ b/Telegram/SourceFiles/info/channel_statistics/earn/earn_icons.cpp @@ -0,0 +1,61 @@ +/* +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/rect.h" + +#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; +} + +} // namespace Ui::Earn diff --git a/Telegram/SourceFiles/info/channel_statistics/earn/earn_icons.h b/Telegram/SourceFiles/info/channel_statistics/earn/earn_icons.h new file mode 100644 index 000000000..e7f7f7d34 --- /dev/null +++ b/Telegram/SourceFiles/info/channel_statistics/earn/earn_icons.h @@ -0,0 +1,16 @@ +/* +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 +*/ +#pragma once + +namespace Ui::Earn { + +[[nodiscard]] QImage IconCurrencyColored( + const style::font &font, + const QColor &c); + +} // namespace Ui::Earn diff --git a/Telegram/SourceFiles/info/channel_statistics/earn/info_channel_earn_list.cpp b/Telegram/SourceFiles/info/channel_statistics/earn/info_channel_earn_list.cpp index 49f4c236c..d4071225d 100644 --- a/Telegram/SourceFiles/info/channel_statistics/earn/info_channel_earn_list.cpp +++ b/Telegram/SourceFiles/info/channel_statistics/earn/info_channel_earn_list.cpp @@ -25,6 +25,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/stickers/data_custom_emoji.h" #include "history/view/controls/history_view_webpage_processor.h" #include "info/channel_statistics/earn/earn_format.h" +#include "info/channel_statistics/earn/earn_icons.h" #include "info/channel_statistics/earn/info_channel_earn_widget.h" #include "info/info_controller.h" #include "info/profile/info_profile_values.h" // Info::Profile::NameValue. @@ -64,7 +65,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "styles/style_credits.h" #include "styles/style_window.h" // mainMenuToggleFourStrokes. -#include #include namespace Info::ChannelEarn { @@ -119,31 +119,6 @@ void ShowMenu(not_null box, const QString &text) { }); } -[[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()); arrow->paintRequest( @@ -240,23 +215,6 @@ void AddRecipient(not_null box, const TextWithEntities &t) { } // namespace -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; -} - InnerWidget::InnerWidget( QWidget *parent, not_null controller, @@ -442,8 +400,8 @@ void InnerWidget::fill() { const auto &st = label->st(); auto icon = Ui::Text::SingleCustomEmoji( session->data().customEmojiManager().registerInternalEmoji( - IconCurrency( - st, + Ui::Earn::IconCurrencyColored( + st.style.font, !isIn ? st::activeButtonBg->c : (*isIn) @@ -465,7 +423,9 @@ void InnerWidget::fill() { const auto bigCurrencyIcon = Ui::Text::SingleCustomEmoji( session->data().customEmojiManager().registerInternalEmoji( - IconCurrency(st::boxTitle, st::activeButtonBg->c), + Ui::Earn::IconCurrencyColored( + st::boxTitle.style.font, + st::activeButtonBg->c), st::channelEarnCurrencyLearnMargins, false)); diff --git a/Telegram/SourceFiles/info/channel_statistics/earn/info_channel_earn_list.h b/Telegram/SourceFiles/info/channel_statistics/earn/info_channel_earn_list.h index 061d69b7e..d67eba323 100644 --- a/Telegram/SourceFiles/info/channel_statistics/earn/info_channel_earn_list.h +++ b/Telegram/SourceFiles/info/channel_statistics/earn/info_channel_earn_list.h @@ -23,10 +23,6 @@ namespace Info::ChannelEarn { class Memento; -[[nodiscard]] QImage IconCurrency( - const style::FlatLabel &label, - const QColor &c); - class InnerWidget final : public Ui::VerticalLayout { public: struct ShowRequest final { diff --git a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp index dae6a8298..0e3a6e9c2 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp @@ -47,7 +47,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/view/history_view_item_preview.h" #include "info/bot/earn/info_bot_earn_widget.h" #include "info/channel_statistics/earn/earn_format.h" -#include "info/channel_statistics/earn/info_channel_earn_list.h" // IconCurrency. +#include "info/channel_statistics/earn/earn_icons.h" +#include "info/channel_statistics/earn/info_channel_earn_list.h" #include "info/profile/info_profile_icon.h" #include "info/profile/info_profile_phone_menu.h" #include "info/profile/info_profile_text.h" @@ -815,8 +816,8 @@ rpl::producer AddCurrencyAction( const auto name = Ui::CreateChild(button, st.rightLabel); const auto icon = Ui::Text::SingleCustomEmoji( user->owner().customEmojiManager().registerInternalEmoji( - Info::ChannelEarn::IconCurrency( - st.rightLabel, + Ui::Earn::IconCurrencyColored( + st.rightLabel.style.font, st.rightLabel.textFg->c), st::channelEarnCurrencyCommonMargins, false)); diff --git a/Telegram/SourceFiles/window/window_session_controller.cpp b/Telegram/SourceFiles/window/window_session_controller.cpp index f46d7a4d1..b9d1fc876 100644 --- a/Telegram/SourceFiles/window/window_session_controller.cpp +++ b/Telegram/SourceFiles/window/window_session_controller.cpp @@ -57,6 +57,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/click_handler_types.h" #include "core/ui_integration.h" #include "base/unixtime.h" +#include "info/channel_statistics/earn/earn_icons.h" #include "ui/controls/userpic_button.h" #include "ui/text/text_utilities.h" #include "ui/text/format_values.h" // Ui::FormatPhone. @@ -178,8 +179,8 @@ private: return { .tonEmoji = Ui::Text::SingleCustomEmoji( session->data().customEmojiManager().registerInternalEmoji( - Info::ChannelEarn::IconCurrency( - st::collectibleInfo, + Ui::Earn::IconCurrencyColored( + st::collectibleInfo.style.font, st::collectibleInfo.textFg->c), st::collectibleInfoTonMargins, true)), diff --git a/Telegram/cmake/td_ui.cmake b/Telegram/cmake/td_ui.cmake index e42ee37a2..3da81f9d2 100644 --- a/Telegram/cmake/td_ui.cmake +++ b/Telegram/cmake/td_ui.cmake @@ -153,6 +153,8 @@ PRIVATE info/channel_statistics/earn/earn_format.cpp info/channel_statistics/earn/earn_format.h + info/channel_statistics/earn/earn_icons.cpp + info/channel_statistics/earn/earn_icons.h intro/intro_code_input.cpp intro/intro_code_input.h