diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index 97debd0ad3..af21be839e 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -918,6 +918,8 @@ PRIVATE info/bot/earn/info_bot_earn_list.h info/bot/earn/info_bot_earn_widget.cpp info/bot/earn/info_bot_earn_widget.h + info/bot/starref/info_bot_starref_common.cpp + info/bot/starref/info_bot_starref_common.h info/bot/starref/info_bot_starref_join_widget.cpp info/bot/starref/info_bot_starref_join_widget.h info/bot/starref/info_bot_starref_setup_widget.cpp diff --git a/Telegram/SourceFiles/info/bot/earn/info_bot_earn_list.cpp b/Telegram/SourceFiles/info/bot/earn/info_bot_earn_list.cpp index 2cea711b1b..64b734fe6d 100644 --- a/Telegram/SourceFiles/info/bot/earn/info_bot_earn_list.cpp +++ b/Telegram/SourceFiles/info/bot/earn/info_bot_earn_list.cpp @@ -16,8 +16,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_user.h" #include "data/stickers/data_custom_emoji.h" #include "info/bot/earn/info_bot_earn_widget.h" +#include "info/bot/starref/info_bot_starref_common.h" +#include "info/bot/starref/info_bot_starref_join_widget.h" #include "info/channel_statistics/earn/earn_format.h" #include "info/info_controller.h" +#include "info/info_memento.h" #include "info/statistics/info_statistics_inner_widget.h" // FillLoading. #include "info/statistics/info_statistics_list_controllers.h" #include "lang/lang_keys.h" @@ -250,7 +253,17 @@ void InnerWidget::fill() { return v ? ToUsd(v, multiplier, kMinorLength) : QString(); })); } - + { + const auto button = BotStarRef::AddViewListButton( + container, + tr::lng_credits_summary_earn_title(), + tr::lng_credits_summary_earn_about()); + button->setClickedCallback([=] { + _controller->showSection(BotStarRef::Join::Make(peer())); + }); + Ui::AddSkip(container); + Ui::AddDivider(container); + } fillHistory(); } diff --git a/Telegram/SourceFiles/info/bot/starref/info_bot_starref_common.cpp b/Telegram/SourceFiles/info/bot/starref/info_bot_starref_common.cpp new file mode 100644 index 0000000000..2254b48b5f --- /dev/null +++ b/Telegram/SourceFiles/info/bot/starref/info_bot_starref_common.cpp @@ -0,0 +1,115 @@ +/* +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/bot/starref/info_bot_starref_common.h" + +#include "settings/settings_common.h" +#include "ui/widgets/buttons.h" +#include "ui/widgets/labels.h" +#include "ui/wrap/vertical_layout.h" +#include "ui/text/text_utilities.h" +//#include "styles/style_info.h" +#include "styles/style_layers.h" +#include "styles/style_settings.h" +//#include "styles/style_premium.h" + +namespace Info::BotStarRef { + +not_null AddViewListButton( + not_null parent, + rpl::producer title, + rpl::producer subtitle) { + const auto &stLabel = st::defaultFlatLabel; + const auto iconSize = st::settingsPremiumIconDouble.size(); + const auto &titlePadding = st::settingsPremiumRowTitlePadding; + const auto &descriptionPadding = st::settingsPremiumRowAboutPadding; + + const auto button = Ui::CreateChild( + parent, + rpl::single(QString())); + button->show(); + + const auto label = parent->add( + object_ptr( + parent, + std::move(title) | Ui::Text::ToBold(), + stLabel), + titlePadding); + label->setAttribute(Qt::WA_TransparentForMouseEvents); + const auto description = parent->add( + object_ptr( + parent, + std::move(subtitle), + st::boxDividerLabel), + descriptionPadding); + description->setAttribute(Qt::WA_TransparentForMouseEvents); + + const auto dummy = Ui::CreateChild(parent); + dummy->setAttribute(Qt::WA_TransparentForMouseEvents); + dummy->show(); + + parent->sizeValue( + ) | rpl::start_with_next([=](const QSize &s) { + dummy->resize(s.width(), iconSize.height()); + }, dummy->lifetime()); + + button->geometryValue( + ) | rpl::start_with_next([=](const QRect &r) { + dummy->moveToLeft(0, r.y() + (r.height() - iconSize.height()) / 2); + }, dummy->lifetime()); + + ::Settings::AddButtonIcon(dummy, st::settingsButton, { + .icon = &st::settingsStarRefEarnStars, + .backgroundBrush = st::premiumIconBg3, + }); + + rpl::combine( + parent->widthValue(), + label->heightValue(), + description->heightValue() + ) | rpl::start_with_next([=, + topPadding = titlePadding, + bottomPadding = descriptionPadding]( + int width, + int topHeight, + int bottomHeight) { + button->resize( + width, + topPadding.top() + + topHeight + + topPadding.bottom() + + bottomPadding.top() + + bottomHeight + + bottomPadding.bottom()); + }, button->lifetime()); + label->topValue( + ) | rpl::start_with_next([=, padding = titlePadding.top()](int top) { + button->moveToLeft(0, top - padding); + }, button->lifetime()); + const auto arrow = Ui::CreateChild( + button, + st::backButton); + arrow->setIconOverride( + &st::settingsPremiumArrow, + &st::settingsPremiumArrowOver); + arrow->setAttribute(Qt::WA_TransparentForMouseEvents); + button->sizeValue( + ) | rpl::start_with_next([=](const QSize &s) { + const auto &point = st::settingsPremiumArrowShift; + arrow->moveToRight( + -point.x(), + point.y() + (s.height() - arrow->height()) / 2); + }, arrow->lifetime()); + + return button; +} + +QString FormatStarRefCommission(ushort commission) { + return QString::number(commission / 10.) + '%'; +} + +} // namespace Info::BotStarRef \ No newline at end of file diff --git a/Telegram/SourceFiles/info/bot/starref/info_bot_starref_common.h b/Telegram/SourceFiles/info/bot/starref/info_bot_starref_common.h new file mode 100644 index 0000000000..10e31e8720 --- /dev/null +++ b/Telegram/SourceFiles/info/bot/starref/info_bot_starref_common.h @@ -0,0 +1,24 @@ +/* +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 Ui { +class AbstractButton; +class VerticalLayout; +} // namespace Ui + +namespace Info::BotStarRef { + +[[nodiscard]] not_null AddViewListButton( + not_null parent, + rpl::producer title, + rpl::producer subtitle); + +[[nodiscard]] QString FormatStarRefCommission(ushort commission); + +} // namespace Info::BotStarRef diff --git a/Telegram/SourceFiles/info/bot/starref/info_bot_starref_join_widget.cpp b/Telegram/SourceFiles/info/bot/starref/info_bot_starref_join_widget.cpp index cf61d9af04..10899173e0 100644 --- a/Telegram/SourceFiles/info/bot/starref/info_bot_starref_join_widget.cpp +++ b/Telegram/SourceFiles/info/bot/starref/info_bot_starref_join_widget.cpp @@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/click_handler_types.h" #include "data/data_session.h" #include "data/data_user.h" +#include "info/bot/starref/info_bot_starref_common.h" #include "info/profile/info_profile_icon.h" #include "info/info_controller.h" #include "info/info_memento.h" @@ -868,9 +869,5 @@ std::shared_ptr Make(not_null peer) { std::make_shared(peer))); } -QString FormatStarRefCommission(ushort commission) { - return QString::number(commission / 10.) + '%'; -} - } // namespace Info::BotStarRef::Join diff --git a/Telegram/SourceFiles/info/bot/starref/info_bot_starref_join_widget.h b/Telegram/SourceFiles/info/bot/starref/info_bot_starref_join_widget.h index 05dd393ae2..129caed9fa 100644 --- a/Telegram/SourceFiles/info/bot/starref/info_bot_starref_join_widget.h +++ b/Telegram/SourceFiles/info/bot/starref/info_bot_starref_join_widget.h @@ -76,6 +76,4 @@ private: [[nodiscard]] std::shared_ptr Make(not_null peer); -[[nodiscard]] QString FormatStarRefCommission(ushort commission); - } // namespace Info::BotStarRef::Join diff --git a/Telegram/SourceFiles/info/bot/starref/info_bot_starref_setup_widget.cpp b/Telegram/SourceFiles/info/bot/starref/info_bot_starref_setup_widget.cpp index c508bf3efb..950ed997b6 100644 --- a/Telegram/SourceFiles/info/bot/starref/info_bot_starref_setup_widget.cpp +++ b/Telegram/SourceFiles/info/bot/starref/info_bot_starref_setup_widget.cpp @@ -12,7 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/unixtime.h" #include "core/click_handler_types.h" #include "data/data_user.h" -#include "info/bot/starref/info_bot_starref_join_widget.h" +#include "info/bot/starref/info_bot_starref_common.h" #include "info/profile/info_profile_icon.h" #include "info/info_controller.h" #include "info/info_memento.h" @@ -496,7 +496,7 @@ void InnerWidget::setupCommission() { commission, setCommission, setCommission, - [=](int value) { return Join::FormatStarRefCommission(value); }, + [=](int value) { return FormatStarRefCommission(value); }, _state.exists), st::boxRowPadding); @@ -907,92 +907,5 @@ std::shared_ptr Make(not_null peer) { std::make_shared(peer))); } -not_null AddViewListButton( - not_null parent, - rpl::producer title, - rpl::producer subtitle) { - const auto &stLabel = st::defaultFlatLabel; - const auto iconSize = st::settingsPremiumIconDouble.size(); - const auto &titlePadding = st::settingsPremiumRowTitlePadding; - const auto &descriptionPadding = st::settingsPremiumRowAboutPadding; - - const auto button = Ui::CreateChild( - parent, - rpl::single(QString())); - - const auto label = parent->add( - object_ptr( - parent, - std::move(title) | Ui::Text::ToBold(), - stLabel), - titlePadding); - label->setAttribute(Qt::WA_TransparentForMouseEvents); - const auto description = parent->add( - object_ptr( - parent, - std::move(subtitle), - st::boxDividerLabel), - descriptionPadding); - description->setAttribute(Qt::WA_TransparentForMouseEvents); - - const auto dummy = Ui::CreateChild(parent); - dummy->setAttribute(Qt::WA_TransparentForMouseEvents); - - parent->sizeValue( - ) | rpl::start_with_next([=](const QSize &s) { - dummy->resize(s.width(), iconSize.height()); - }, dummy->lifetime()); - - button->geometryValue( - ) | rpl::start_with_next([=](const QRect &r) { - dummy->moveToLeft(0, r.y() + (r.height() - iconSize.height()) / 2); - }, dummy->lifetime()); - - ::Settings::AddButtonIcon(dummy, st::settingsButton, { - .icon = &st::settingsStarRefEarnStars, - .backgroundBrush = st::premiumIconBg3, - }); - - rpl::combine( - parent->widthValue(), - label->heightValue(), - description->heightValue() - ) | rpl::start_with_next([=, - topPadding = titlePadding, - bottomPadding = descriptionPadding]( - int width, - int topHeight, - int bottomHeight) { - button->resize( - width, - topPadding.top() - + topHeight - + topPadding.bottom() - + bottomPadding.top() - + bottomHeight - + bottomPadding.bottom()); - }, button->lifetime()); - label->topValue( - ) | rpl::start_with_next([=, padding = titlePadding.top()](int top) { - button->moveToLeft(0, top - padding); - }, button->lifetime()); - const auto arrow = Ui::CreateChild( - button, - st::backButton); - arrow->setIconOverride( - &st::settingsPremiumArrow, - &st::settingsPremiumArrowOver); - arrow->setAttribute(Qt::WA_TransparentForMouseEvents); - button->sizeValue( - ) | rpl::start_with_next([=](const QSize &s) { - const auto &point = st::settingsPremiumArrowShift; - arrow->moveToRight( - -point.x(), - point.y() + (s.height() - arrow->height()) / 2); - }, arrow->lifetime()); - - return button; -} - } // namespace Info::BotStarRef::Setup diff --git a/Telegram/SourceFiles/info/bot/starref/info_bot_starref_setup_widget.h b/Telegram/SourceFiles/info/bot/starref/info_bot_starref_setup_widget.h index 4a862a0f45..ebc2be7548 100644 --- a/Telegram/SourceFiles/info/bot/starref/info_bot_starref_setup_widget.h +++ b/Telegram/SourceFiles/info/bot/starref/info_bot_starref_setup_widget.h @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "info/info_content_widget.h" +#include "info/bot/starref/info_bot_starref_common.h" namespace Ui::Premium { class TopBarAbstract; @@ -81,9 +82,4 @@ private: [[nodiscard]] std::shared_ptr Make(not_null peer); -[[nodiscard]] not_null AddViewListButton( - not_null parent, - rpl::producer title, - rpl::producer subtitle); - } // namespace Info::BotStarRef::Setup diff --git a/Telegram/SourceFiles/info/channel_statistics/earn/info_channel_earn_list.cpp b/Telegram/SourceFiles/info/channel_statistics/earn/info_channel_earn_list.cpp index 3d721bb115..3b578f56e6 100644 --- a/Telegram/SourceFiles/info/channel_statistics/earn/info_channel_earn_list.cpp +++ b/Telegram/SourceFiles/info/channel_statistics/earn/info_channel_earn_list.cpp @@ -963,7 +963,7 @@ void InnerWidget::fill() { ) | rpl::map(creditsToUsdMap)); } - const auto button = Info::BotStarRef::Setup::AddViewListButton( + const auto button = Info::BotStarRef::AddViewListButton( container, tr::lng_credits_summary_earn_title(), tr::lng_credits_summary_earn_about()); diff --git a/Telegram/SourceFiles/settings/settings_common.cpp b/Telegram/SourceFiles/settings/settings_common.cpp index 77cdd80470..2cee2e2f56 100644 --- a/Telegram/SourceFiles/settings/settings_common.cpp +++ b/Telegram/SourceFiles/settings/settings_common.cpp @@ -89,6 +89,7 @@ void AddButtonIcon( std::move(descriptor)); icon->widget.setAttribute(Qt::WA_TransparentForMouseEvents); icon->widget.resize(icon->icon.size()); + icon->widget.show(); button->sizeValue( ) | rpl::start_with_next([=, left = st.iconLeft](QSize size) { icon->widget.moveToLeft( diff --git a/Telegram/SourceFiles/settings/settings_credits.cpp b/Telegram/SourceFiles/settings/settings_credits.cpp index 4927b572b2..eb4a2435f4 100644 --- a/Telegram/SourceFiles/settings/settings_credits.cpp +++ b/Telegram/SourceFiles/settings/settings_credits.cpp @@ -17,9 +17,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_photo_media.h" #include "data/data_session.h" #include "data/data_user.h" +#include "info/bot/starref/info_bot_starref_common.h" +#include "info/bot/starref/info_bot_starref_join_widget.h" #include "info/channel_statistics/boosts/giveaway/boost_badge.h" // InfiniteRadialAnimationWidget. #include "info/settings/info_settings_widget.h" // SectionCustomTopBarData. #include "info/statistics/info_statistics_list_controllers.h" +#include "info/info_memento.h" #include "lang/lang_keys.h" #include "main/main_session.h" #include "settings/settings_common_session.h" @@ -74,7 +77,7 @@ private: void setupContent(); void setupHistory(not_null container); void setupSubscriptions(not_null container); - + void setupStarRefPromo(not_null container); const not_null _controller; QWidget *_parent = nullptr; @@ -206,6 +209,21 @@ void Credits::setupSubscriptions(not_null container) { } } +void Credits::setupStarRefPromo(not_null container) { + Ui::AddSkip(container); + const auto button = Info::BotStarRef::AddViewListButton( + container, + tr::lng_credits_summary_earn_title(), + tr::lng_credits_summary_earn_about()); + button->setClickedCallback([=] { + const auto self = _controller->session().user(); + _controller->showSection(Info::BotStarRef::Join::Make(self)); + }); + Ui::AddSkip(container); + Ui::AddDivider(container); + Ui::AddSkip(container); +} + void Credits::setupHistory(not_null container) { const auto history = container->add( object_ptr>( @@ -493,6 +511,7 @@ void Credits::setupContent() { Ui::AddSkip(content); Ui::AddDivider(content); + setupStarRefPromo(content); setupSubscriptions(content); setupHistory(content);