Moved out generation of credits menu icon from svg to td_ui.

This commit is contained in:
23rd 2024-10-27 11:25:53 +03:00
parent 2e0e4006a1
commit 9e0c731b32
3 changed files with 47 additions and 29 deletions

View file

@ -46,6 +46,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/admin_log/history_admin_log_section.h"
#include "info/bot/earn/info_bot_earn_widget.h"
#include "info/channel_statistics/boosts/info_boosts_widget.h"
#include "info/channel_statistics/earn/earn_icons.h"
#include "info/profile/info_profile_values.h"
#include "info/info_memento.h"
#include "lang/lang_keys.h"
@ -1622,42 +1623,18 @@ void Controller::fillBotBalanceButton() {
});
}
{
constexpr auto kSizeShift = 3;
constexpr auto kStrokeWidth = 5;
const auto icon = Ui::CreateChild<Ui::RpWidget>(button);
icon->resize(Size(st::menuIconLinks.width() - kSizeShift));
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));
const auto svg = icon->lifetime().make_state<QSvgRenderer>(
colorized.toUtf8());
svg->setViewBox(svg->viewBox() + Margins(kStrokeWidth));
const auto starSize = Size(icon->height());
icon->paintRequest(
) | rpl::start_with_next([=] {
const auto image = Ui::Earn::MenuIconCredits();
icon->resize(image.size() / style::DevicePixelRatio());
icon->paintRequest() | rpl::start_with_next([=] {
auto p = QPainter(icon);
svg->render(&p, Rect(starSize));
p.drawImage(0, 0, image);
}, icon->lifetime());
button->sizeValue(
) | rpl::start_with_next([=](const QSize &size) {
icon->moveToLeft(
button->st().iconLeft + kSizeShift / 2.,
button->st().iconLeft,
(size.height() - icon->height()) / 2);
}, icon->lifetime());
}

View file

@ -7,8 +7,12 @@ 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 <QFile>
#include <QtSvg/QSvgRenderer>
namespace Ui::Earn {
@ -58,4 +62,39 @@ QImage IconCurrencyColored(
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

View file

@ -13,4 +13,6 @@ namespace Ui::Earn {
const style::font &font,
const QColor &c);
[[nodiscard]] QImage MenuIconCredits();
} // namespace Ui::Earn