From b1e537e54eaf7ae777e504c4076462927a6ea434 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Wed, 16 Oct 2024 16:08:50 +0300 Subject: [PATCH] Added subscription icon to channel photo in ReceiptCreditsBox. --- Telegram/SourceFiles/api/api_chat_invite.cpp | 46 ++++++++++++++----- .../boxes/peers/edit_peer_invite_link.cpp | 5 +- .../settings/settings_credits_graphics.cpp | 43 +++++++++++++++-- .../settings/settings_credits_graphics.h | 5 ++ 4 files changed, 81 insertions(+), 18 deletions(-) diff --git a/Telegram/SourceFiles/api/api_chat_invite.cpp b/Telegram/SourceFiles/api/api_chat_invite.cpp index be07e72ac..0a53c61dd 100644 --- a/Telegram/SourceFiles/api/api_chat_invite.cpp +++ b/Telegram/SourceFiles/api/api_chat_invite.cpp @@ -25,6 +25,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "settings/settings_credits_graphics.h" #include "ui/boxes/confirm_box.h" #include "ui/controls/userpic_button.h" +#include "ui/effects/credits_graphics.h" #include "ui/effects/premium_graphics.h" #include "ui/effects/premium_stars_colored.h" #include "ui/empty_userpic.h" @@ -129,6 +130,7 @@ void ConfirmSubscriptionBox( struct State final { std::shared_ptr photoMedia; std::unique_ptr photoEmpty; + QImage frame; std::optional api; Ui::RpWidget* saveButton = nullptr; @@ -146,25 +148,45 @@ void ConfirmSubscriptionBox( const auto userpic = userpicWrap->entity(); const auto photoSize = st::confirmInvitePhotoSize; userpic->resize(Size(photoSize)); + const auto creditsIconSize = photoSize / 3; + const auto creditsIconCallback = + Ui::PaintOutlinedColoredCreditsIconCallback( + creditsIconSize, + 1.5); + state->frame = QImage( + Size(photoSize * style::DevicePixelRatio()), + QImage::Format_ARGB32_Premultiplied); + state->frame.setDevicePixelRatio(style::DevicePixelRatio()); const auto options = Images::Option::RoundCircle; userpic->paintRequest( ) | rpl::start_with_next([=, small = Data::PhotoSize::Small] { - auto p = QPainter(userpic); - if (state->photoMedia) { - if (const auto image = state->photoMedia->image(small)) { - p.drawPixmap( + state->frame.fill(Qt::transparent); + { + auto p = QPainter(&state->frame); + if (state->photoMedia) { + if (const auto image = state->photoMedia->image(small)) { + p.drawPixmap( + 0, + 0, + image->pix(Size(photoSize), { .options = options })); + } + } else if (state->photoEmpty) { + state->photoEmpty->paintCircle( + p, 0, 0, - image->pix(Size(photoSize), { .options = options })); + userpic->width(), + photoSize); + } + if (creditsIconCallback) { + p.translate( + photoSize - creditsIconSize, + photoSize - creditsIconSize); + creditsIconCallback(p); } - } else if (state->photoEmpty) { - state->photoEmpty->paintCircle( - p, - 0, - 0, - userpic->width(), - photoSize); } + auto p = QPainter(userpic); + p.drawImage(0, 0, state->frame); }, userpicWrap->lifetime()); userpicWrap->setAttribute(Qt::WA_TransparentForMouseEvents); if (photo) { diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_invite_link.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_invite_link.cpp index 8e1a11030..4dc7f897b 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_invite_link.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_invite_link.cpp @@ -956,12 +956,11 @@ void Controller::rowClicked(not_null row) { Ui::AddSkip(content); Ui::AddSkip(content); - const auto &stUser = st::boostReplaceUserpic; + const auto photoSize = st::boostReplaceUserpic.photoSize; const auto session = &row->peer()->session(); content->add(object_ptr>( content, - object_ptr(content, channel, stUser)) - )->setAttribute(Qt::WA_TransparentForMouseEvents); + Settings::SubscriptionUserpic(content, channel, photoSize))); Ui::AddSkip(content); Ui::AddSkip(content); diff --git a/Telegram/SourceFiles/settings/settings_credits_graphics.cpp b/Telegram/SourceFiles/settings/settings_credits_graphics.cpp index 1e92b697b..7e813cf10 100644 --- a/Telegram/SourceFiles/settings/settings_credits_graphics.cpp +++ b/Telegram/SourceFiles/settings/settings_credits_graphics.cpp @@ -52,6 +52,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "statistics/widgets/chart_header_widget.h" #include "ui/boxes/confirm_box.h" #include "ui/controls/userpic_button.h" +#include "ui/dynamic_image.h" +#include "ui/dynamic_thumbnails.h" #include "ui/effects/credits_graphics.h" #include "ui/effects/premium_graphics.h" #include "ui/effects/premium_stars_colored.h" @@ -772,9 +774,15 @@ void ReceiptCreditsBox( GenericEntryPhoto(content, callback, stUser.photoSize))); AddViewMediaHandler(thumb->entity(), controller, e); } else if (peer && !e.gift) { - content->add(object_ptr>( - content, - object_ptr(content, peer, stUser))); + if (e.subscriptionUntil.isNull() && s.until.isNull()) { + content->add(object_ptr>( + content, + object_ptr(content, peer, stUser))); + } else { + content->add(object_ptr>( + content, + SubscriptionUserpic(content, peer, stUser.photoSize))); + } } else if (e.gift || isPrize) { struct State final { DocumentData *sticker = nullptr; @@ -1541,6 +1549,35 @@ object_ptr PaidMediaThumbnail( photoSize); } +object_ptr SubscriptionUserpic( + not_null parent, + not_null peer, + int photoSize) { + auto widget = object_ptr(parent); + const auto raw = widget.data(); + widget->resize(photoSize, photoSize); + const auto userpicMedia = Ui::MakeUserpicThumbnail(peer, false); + userpicMedia->subscribeToUpdates([=] { raw->update(); }); + const auto creditsIconSize = photoSize / 3; + const auto creditsIconCallback = + Ui::PaintOutlinedColoredCreditsIconCallback( + creditsIconSize, + 1.5); + widget->paintRequest() | rpl::start_with_next([=] { + auto p = QPainter(raw); + p.fillRect(Rect(Size(photoSize)), Qt::transparent); + auto image = userpicMedia->image(photoSize); + { + auto q = QPainter(&image); + q.translate(photoSize, photoSize); + q.translate(-creditsIconSize, -creditsIconSize); + creditsIconCallback(q); + } + p.drawImage(0, 0, image); + }, widget->lifetime()); + return widget; +} + void SmallBalanceBox( not_null box, std::shared_ptr show, diff --git a/Telegram/SourceFiles/settings/settings_credits_graphics.h b/Telegram/SourceFiles/settings/settings_credits_graphics.h index bfc266e3e..fb19e2bff 100644 --- a/Telegram/SourceFiles/settings/settings_credits_graphics.h +++ b/Telegram/SourceFiles/settings/settings_credits_graphics.h @@ -126,6 +126,11 @@ void ShowRefundInfoBox( int totalCount, int photoSize); +[[nodiscard]] object_ptr SubscriptionUserpic( + not_null parent, + not_null peer, + int photoSize); + struct SmallBalanceBot { UserId botId = 0; };