Moved out generation of currency icon from svg to td_ui.

This commit is contained in:
23rd 2024-10-27 11:03:57 +03:00
parent 187139473d
commit 2e0e4006a1
7 changed files with 92 additions and 55 deletions

View File

@ -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 <QtSvg/QSvgRenderer>
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"(
<svg width="72px" height="72px" viewBox="0 0 72 72">
<g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g transform="translate(9.000000, 14.000000)
" stroke-width="7.2" stroke=")" + color + R"(">
<path d="M2.96014341,0 L50.9898193,0 C51.9732032,-7.06402744e-15
52.7703933,0.797190129 52.7703933,1.78057399 C52.7703933,2.08038611
52.6946886,2.3753442 52.5502994,2.63809702 L29.699977,44.2200383
C28.7527832,45.9436969 26.5876295,46.5731461 24.8639708,45.6259523
C24.2556953,45.2916896 23.7583564,44.7869606 23.4331014,44.1738213
L1.38718565,2.61498853 C0.926351231,1.74626794 1.25700829,0.668450654
2.12572888,0.20761623 C2.38272962,0.0712838007 2.6692209,4.97530809e-16
2.96014341,0 Z"></path>
<line x1="27" y1="44.4532875" x2="27" y2="0"></line>
</g>
</g>
</svg>)";
}
} // 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

View File

@ -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

View File

@ -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 <QtSvg/QSvgRenderer>
#include <QtWidgets/QApplication>
namespace Info::ChannelEarn {
@ -119,31 +119,6 @@ void ShowMenu(not_null<Ui::GenericBox*> 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"(
<svg width="72px" height="72px" viewBox="0 0 72 72">
<g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g transform="translate(9.000000, 14.000000)
" stroke-width="7.2" stroke=")" + color + R"(">
<path d="M2.96014341,0 L50.9898193,0 C51.9732032,-7.06402744e-15
52.7703933,0.797190129 52.7703933,1.78057399 C52.7703933,2.08038611
52.6946886,2.3753442 52.5502994,2.63809702 L29.699977,44.2200383
C28.7527832,45.9436969 26.5876295,46.5731461 24.8639708,45.6259523
C24.2556953,45.2916896 23.7583564,44.7869606 23.4331014,44.1738213
L1.38718565,2.61498853 C0.926351231,1.74626794 1.25700829,0.668450654
2.12572888,0.20761623 C2.38272962,0.0712838007 2.6692209,4.97530809e-16
2.96014341,0 Z"></path>
<line x1="27" y1="44.4532875" x2="27" y2="0"></line>
</g>
</g>
</svg>)";
}
void AddArrow(not_null<Ui::RpWidget*> parent) {
const auto arrow = Ui::CreateChild<Ui::RpWidget>(parent.get());
arrow->paintRequest(
@ -240,23 +215,6 @@ void AddRecipient(not_null<Ui::GenericBox*> 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*> 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));

View File

@ -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 {

View File

@ -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<uint64> AddCurrencyAction(
const auto name = Ui::CreateChild<Ui::FlatLabel>(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));

View File

@ -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)),

View File

@ -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