From 691a434ba9fd523d882918c03f033c413279ba60 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Tue, 14 Jun 2022 08:00:47 +0300 Subject: [PATCH] Added premium badge to main settings. --- .../SourceFiles/settings/settings_main.cpp | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/Telegram/SourceFiles/settings/settings_main.cpp b/Telegram/SourceFiles/settings/settings_main.cpp index 26c3090d1..fa373011b 100644 --- a/Telegram/SourceFiles/settings/settings_main.cpp +++ b/Telegram/SourceFiles/settings/settings_main.cpp @@ -35,6 +35,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_session.h" #include "data/data_cloud_themes.h" #include "data/data_chat_filters.h" +#include "data/data_peer_values.h" // Data::AmPremiumValue #include "lang/lang_keys.h" #include "lang/lang_instance.h" #include "storage/localstorage.h" @@ -89,6 +90,7 @@ private: object_ptr _name = { nullptr }; object_ptr _phone = { nullptr }; object_ptr _username = { nullptr }; + object_ptr _badge = { nullptr }; }; @@ -130,6 +132,24 @@ Cover::Cover( _user, _userpic->takeResultImage()); }, _userpic->lifetime()); + + Data::AmPremiumValue( + &controller->session() + ) | rpl::start_with_next([=](bool hasPremium) { + if (hasPremium && !_badge) { + const auto icon = &st::infoPremiumStar; + _badge.create(this); + _badge->show(); + _badge->resize(icon->size()); + _badge->paintRequest( + ) | rpl::start_with_next([icon, check = _badge.data()] { + Painter p(check); + icon->paint(p, 0, 0, check->width()); + }, _badge->lifetime()); + } else if (!hasPremium && _badge) { + _badge.destroy(); + } + }, lifetime()); } Cover::~Cover() = default; @@ -188,9 +208,19 @@ void Cover::initViewers() { void Cover::refreshNameGeometry(int newWidth) { const auto nameLeft = st::settingsNameLeft; const auto nameTop = st::settingsNameTop; - const auto nameWidth = newWidth - nameLeft - st::infoProfileNameRight; + const auto nameWidth = newWidth + - nameLeft + - st::infoProfileNameRight + - (!_badge ? 0 : _badge->width() + st::infoVerifiedCheckPosition.x()); _name->resizeToNaturalWidth(nameWidth); _name->moveToLeft(nameLeft, nameTop, newWidth); + + if (_badge) { + const auto &pos = st::infoVerifiedCheckPosition; + const auto badgeLeft = nameLeft + _name->width() + pos.x(); + const auto badgeTop = nameTop + pos.y(); + _badge->moveToLeft(badgeLeft, badgeTop, newWidth); + } } void Cover::refreshPhoneGeometry(int newWidth) {