From 4150cdff8620829b5a355afbca04870fa7ce205e Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Tue, 7 Nov 2023 22:33:57 +0300 Subject: [PATCH] Moved out badge for giveaway list to td_ui. --- .../info/boosts/giveaway/boost_badge.cpp | 67 +++++++++++++++++++ .../info/boosts/giveaway/boost_badge.h | 27 ++++++++ .../info_statistics_list_controllers.cpp | 57 +--------------- Telegram/cmake/td_ui.cmake | 2 + 4 files changed, 99 insertions(+), 54 deletions(-) create mode 100644 Telegram/SourceFiles/info/boosts/giveaway/boost_badge.cpp create mode 100644 Telegram/SourceFiles/info/boosts/giveaway/boost_badge.h diff --git a/Telegram/SourceFiles/info/boosts/giveaway/boost_badge.cpp b/Telegram/SourceFiles/info/boosts/giveaway/boost_badge.cpp new file mode 100644 index 000000000..778257f55 --- /dev/null +++ b/Telegram/SourceFiles/info/boosts/giveaway/boost_badge.cpp @@ -0,0 +1,67 @@ +/* +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/boosts/giveaway/boost_badge.h" + +#include "ui/painter.h" +#include "ui/rect.h" + +namespace Info::Statistics { + +QImage CreateBadge( + const style::TextStyle &textStyle, + const QString &text, + int badgeHeight, + const style::margins &textPadding, + const style::color &bg, + const style::color &fg, + float64 bgOpacity, + const style::margins &iconPadding, + const style::icon &icon) { + auto badgeText = Ui::Text::String(textStyle, text); + const auto badgeTextWidth = badgeText.maxWidth(); + const auto badgex = 0; + const auto badgey = 0; + const auto badgeh = 0 + badgeHeight; + const auto badgew = badgeTextWidth + + rect::m::sum::h(textPadding); + auto result = QImage( + QSize(badgew, badgeh) * style::DevicePixelRatio(), + QImage::Format_ARGB32_Premultiplied); + result.fill(Qt::transparent); + result.setDevicePixelRatio(style::DevicePixelRatio()); + { + auto p = Painter(&result); + + p.setPen(Qt::NoPen); + p.setBrush(bg); + + const auto r = QRect(badgex, badgey, badgew, badgeh); + { + auto hq = PainterHighQualityEnabler(p); + auto o = ScopedPainterOpacity(p, bgOpacity); + p.drawRoundedRect(r, badgeh / 2, badgeh / 2); + } + + p.setPen(fg); + p.setBrush(Qt::NoBrush); + badgeText.drawLeftElided( + p, + r.x() + textPadding.left(), + badgey + textPadding.top(), + badgew, + badgew * 2); + + icon.paint( + p, + QPoint(r.x() + iconPadding.left(), r.y() + iconPadding.top()), + badgew * 2); + } + return result; +} + +} // namespace Info::Statistics diff --git a/Telegram/SourceFiles/info/boosts/giveaway/boost_badge.h b/Telegram/SourceFiles/info/boosts/giveaway/boost_badge.h new file mode 100644 index 000000000..3d31df608 --- /dev/null +++ b/Telegram/SourceFiles/info/boosts/giveaway/boost_badge.h @@ -0,0 +1,27 @@ +/* +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 style { +struct TextStyle; +} // namespace style + +namespace Info::Statistics { + +[[nodiscard]] QImage CreateBadge( + const style::TextStyle &textStyle, + const QString &text, + int badgeHeight, + const style::margins &textPadding, + const style::color &bg, + const style::color &fg, + float64 bgOpacity, + const style::margins &iconPadding, + const style::icon &icon); + +} // namespace Info::Statistics diff --git a/Telegram/SourceFiles/info/statistics/info_statistics_list_controllers.cpp b/Telegram/SourceFiles/info/statistics/info_statistics_list_controllers.cpp index 43606f195..7dd49517b 100644 --- a/Telegram/SourceFiles/info/statistics/info_statistics_list_controllers.cpp +++ b/Telegram/SourceFiles/info/statistics/info_statistics_list_controllers.cpp @@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_session.h" #include "data/data_user.h" #include "history/history_item.h" +#include "info/boosts/giveaway/boost_badge.h" #include "lang/lang_keys.h" #include "main/main_session.h" #include "settings/settings_common.h" @@ -35,58 +36,6 @@ using BoostCallback = Fn; constexpr auto kColorIndexUnclaimed = int(3); constexpr auto kColorIndexPending = int(4); -[[nodiscard]] QImage Badge( - const style::TextStyle &textStyle, - const QString &text, - int badgeHeight, - const style::margins &textPadding, - const style::color &bg, - const style::color &fg, - float64 bgOpacity, - const style::margins &iconPadding, - const style::icon &icon) { - auto badgeText = Ui::Text::String(textStyle, text); - const auto badgeTextWidth = badgeText.maxWidth(); - const auto badgex = 0; - const auto badgey = 0; - const auto badgeh = 0 + badgeHeight; - const auto badgew = badgeTextWidth - + rect::m::sum::h(textPadding); - auto result = QImage( - QSize(badgew, badgeh) * style::DevicePixelRatio(), - QImage::Format_ARGB32_Premultiplied); - result.fill(Qt::transparent); - result.setDevicePixelRatio(style::DevicePixelRatio()); - { - auto p = Painter(&result); - - p.setPen(Qt::NoPen); - p.setBrush(bg); - - const auto r = QRect(badgex, badgey, badgew, badgeh); - { - auto hq = PainterHighQualityEnabler(p); - auto o = ScopedPainterOpacity(p, bgOpacity); - p.drawRoundedRect(r, badgeh / 2, badgeh / 2); - } - - p.setPen(fg); - p.setBrush(Qt::NoBrush); - badgeText.drawLeftElided( - p, - r.x() + textPadding.left(), - badgey + textPadding.top(), - badgew, - badgew * 2); - - icon.paint( - p, - QPoint(r.x() + iconPadding.left(), r.y() + iconPadding.top()), - badgew * 2); - } - return result; -} - void AddArrow(not_null parent) { const auto arrow = Ui::CreateChild(parent.get()); arrow->paintRequest( @@ -486,7 +435,7 @@ PaintRoundImageCallback BoostRow::generatePaintUserpicCallback(bool force) { void BoostRow::invalidateBadges() { _badge = _boost.multiplier - ? Badge( + ? CreateBadge( st::statisticsDetailsBottomCaptionStyle, QString::number(_boost.multiplier), st::boostsListBadgeHeight, @@ -506,7 +455,7 @@ void BoostRow::invalidateBadges() { ? st::boostsListGiveawayMiniIcon : st::boostsListGiftMiniIcon; _rightBadge = (_boost.isGift || _boost.isGiveaway) - ? Badge( + ? CreateBadge( st::boostsListRightBadgeTextStyle, _boost.isGiveaway ? tr::lng_gift_link_reason_giveaway(tr::now) diff --git a/Telegram/cmake/td_ui.cmake b/Telegram/cmake/td_ui.cmake index b9eab3397..cdf8cbf27 100644 --- a/Telegram/cmake/td_ui.cmake +++ b/Telegram/cmake/td_ui.cmake @@ -110,6 +110,8 @@ PRIVATE info/userpic/info_userpic_emoji_builder_layer.cpp info/userpic/info_userpic_emoji_builder_layer.h + info/boosts/giveaway/boost_badge.cpp + info/boosts/giveaway/boost_badge.h info/boosts/giveaway/giveaway_type_row.cpp info/boosts/giveaway/giveaway_type_row.h info/boosts/giveaway/select_countries_box.cpp