From 05fb0f81f9289b5113d72a58d2f2ebc134a7d64d Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 26 Sep 2024 11:43:22 +0400 Subject: [PATCH] Show gifts about text. --- Telegram/Resources/langs/lang.strings | 2 ++ .../peer_gifts/info_peer_gifts_widget.cpp | 32 ++++++++++++++++--- Telegram/SourceFiles/ui/effects/credits.style | 7 ++++ 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 1c03165c6..eb63fb9b6 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -1927,6 +1927,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_similar_channels_show_more" = "Show more channels"; "lng_peer_gifts_title" = "Gifts"; +"lng_peer_gifts_about" = "These gifts were sent to {user} by other users."; +"lng_peer_gifts_about_mine" = "These gifts were sent to you by other users. Click on a gift to convert it to Stars or change its privacy settings."; "lng_premium_gift_duration_months#one" = "for {count} month"; "lng_premium_gift_duration_months#other" = "for {count} months"; diff --git a/Telegram/SourceFiles/info/peer_gifts/info_peer_gifts_widget.cpp b/Telegram/SourceFiles/info/peer_gifts/info_peer_gifts_widget.cpp index 91956613c..46ec0f1d7 100644 --- a/Telegram/SourceFiles/info/peer_gifts/info_peer_gifts_widget.cpp +++ b/Telegram/SourceFiles/info/peer_gifts/info_peer_gifts_widget.cpp @@ -12,6 +12,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "info/peer_gifts/info_peer_gifts_common.h" #include "info/info_controller.h" #include "ui/layers/generic_box.h" +#include "ui/text/text_utilities.h" +#include "ui/widgets/box_content_divider.h" +#include "ui/widgets/labels.h" #include "ui/ui_utility.h" #include "lang/lang_keys.h" #include "main/main_session.h" @@ -47,7 +50,7 @@ constexpr auto kPerPage = 50; } // namespace -class InnerWidget final : public Ui::RpWidget { +class InnerWidget final : public Ui::BoxContentDivider { public: InnerWidget( QWidget *parent, @@ -87,6 +90,7 @@ private: const not_null _window; Delegate _delegate; not_null _controller; + std::unique_ptr _about; const not_null _user; std::vector _entries; int _totalCount = 0; @@ -113,10 +117,19 @@ InnerWidget::InnerWidget( QWidget *parent, not_null controller, not_null user) -: RpWidget(parent) +: BoxContentDivider(parent) , _window(controller->parentController()) , _delegate(_window) , _controller(controller) +, _about(std::make_unique( + this, + (user->isSelf() + ? tr::lng_peer_gifts_about_mine(Ui::Text::RichLangValue) + : tr::lng_peer_gifts_about( + lt_user, + rpl::single(Ui::Text::Bold(user->shortName())), + Ui::Text::RichLangValue)), + st::giftListAbout)) , _user(user) , _totalCount(_user->peerGiftsCount()) , _api(&_user->session().mtp()) { @@ -184,7 +197,11 @@ void InnerWidget::visibleTopBottomUpdated( void InnerWidget::paintEvent(QPaintEvent *e) { auto p = QPainter(this); - p.fillRect(e->rect(), st::boxDividerBg); + const auto aboutSize = _about->size().grownBy(st::giftListAboutMargin); + const auto skips = QMargins(0, 0, 0, aboutSize.height()); + p.fillRect(rect().marginsRemoved(skips), st::boxDividerBg->c); + paintTop(p); + paintBottom(p, skips.bottom()); } void InnerWidget::loadMore() { @@ -336,7 +353,14 @@ int InnerWidget::resizeGetHeight(int width) { const auto rows = (count + _perRow - 1) / _perRow; const auto skiph = st::giftBoxGiftSkip.y(); - return padding.bottom() * 2 + rows * (singleh + skiph) - skiph; + auto result = padding.bottom() * 2 + rows * (singleh + skiph) - skiph; + + const auto margin = st::giftListAboutMargin; + _about->resizeToWidth(width - margin.left() - margin.right()); + _about->moveToLeft(margin.left(), result + margin.top()); + result += margin.top() + _about->height() + margin.bottom(); + + return result; } void InnerWidget::saveState(not_null memento) { diff --git a/Telegram/SourceFiles/ui/effects/credits.style b/Telegram/SourceFiles/ui/effects/credits.style index 1209ba052..025139366 100644 --- a/Telegram/SourceFiles/ui/effects/credits.style +++ b/Telegram/SourceFiles/ui/effects/credits.style @@ -126,3 +126,10 @@ giftBoxTextField: InputField(defaultInputField) { } giftBoxTextPadding: margins(20px, 15px, 20px, 11px); giftBoxHiddenMark: icon{{ "menu/stealth", premiumButtonFg }}; +giftListAbout: FlatLabel(defaultFlatLabel) { + minWidth: 240px; + textFg: membersAboutLimitFg; + align: align(top); + style: boxLabelStyle; +} +giftListAboutMargin: margins(12px, 24px, 12px, 24px);