diff --git a/Telegram/SourceFiles/settings/settings_credits.cpp b/Telegram/SourceFiles/settings/settings_credits.cpp index 4656170f6..10ac6e011 100644 --- a/Telegram/SourceFiles/settings/settings_credits.cpp +++ b/Telegram/SourceFiles/settings/settings_credits.cpp @@ -16,22 +16,56 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "settings/settings_common_session.h" #include "ui/effects/premium_graphics.h" #include "ui/effects/premium_top_bar.h" +#include "ui/image/image_prepare.h" #include "ui/painter.h" #include "ui/rect.h" +#include "ui/text/format_values.h" +#include "ui/text/text_utilities.h" +#include "ui/vertical_list.h" #include "ui/widgets/buttons.h" #include "ui/widgets/labels.h" #include "ui/wrap/fade_wrap.h" +#include "ui/wrap/slide_wrap.h" #include "ui/wrap/vertical_layout.h" #include "window/window_session_controller.h" +#include "styles/style_credits.h" #include "styles/style_info.h" -#include "styles/style_premium.h" +#include "styles/style_layers.h" #include "styles/style_settings.h" +#include + namespace Settings { namespace { using SectionCustomTopBarData = Info::Settings::SectionCustomTopBarData; +[[nodiscard]] QImage GenerateStarForLightTopBar(QRectF rect) { + const auto strokeWidth = 3; + + auto colorized = qs(Ui::Premium::ColorizedSvg( + Ui::Premium::CreditsIconGradientStops())); + colorized.replace( + "stroke=\"none\"", + "stroke=\"" + st::creditsStroke->c.name() + "\""); + colorized.replace("stroke-width=\"1\"", "stroke-width=\"3\""); + auto svg = QSvgRenderer(colorized.toUtf8()); + svg.setViewBox(svg.viewBox() + Margins(strokeWidth)); + + const auto size = Size(st::settingsButton.height); + auto frame = QImage( + size * style::DevicePixelRatio(), + QImage::Format_ARGB32_Premultiplied); + frame.setDevicePixelRatio(style::DevicePixelRatio()); + + frame.fill(Qt::transparent); + { + auto q = QPainter(&frame); + svg.render(&q, Rect(size)); + } + return frame; +} + class Credits : public Section { public: Credits( @@ -57,6 +91,8 @@ private: const not_null _controller; + QImage _star; + base::unique_qptr> _back; base::unique_qptr _close; rpl::variable _backToggles; @@ -73,7 +109,8 @@ Credits::Credits( QWidget *parent, not_null controller) : Section(parent) -, _controller(controller) { +, _controller(controller) +, _star(GenerateStarForLightTopBar({})) { setupContent(); } @@ -100,10 +137,82 @@ void Credits::setStepDataReference(std::any &data) { } void Credits::setupOptions(not_null container) { + const auto options = container->add( + object_ptr>( + container, + object_ptr(container))); + const auto content = options->entity(); + + Ui::AddSkip(content, st::settingsPremiumOptionsPadding.top()); + + const auto fill = [=](Data::CreditTopupOptions options) { + while (content->count()) { + delete content->widgetAt(0); + } + Ui::AddSubsectionTitle( + content, + tr::lng_credits_summary_options_subtitle()); + for (const auto &option : options) { + const auto button = content->add(object_ptr( + content, + tr::lng_credits_summary_options_credits( + lt_count_decimal, + rpl::single(option.credits) | tr::to_count()), + st::creditsTopupButton)); + const auto icon = Ui::CreateChild(button); + icon->resize(Size(button->st().height)); + icon->paintRequest( + ) | rpl::start_with_next([=](const QRect &rect) { + auto p = QPainter(icon); + p.drawImage(0, 0, _star); + }, icon->lifetime()); + const auto price = Ui::CreateChild( + button, + Ui::FillAmountAndCurrency(option.amount, option.currency), + st::creditsTopupPrice); + button->sizeValue( + ) | rpl::start_with_next([=](const QSize &size) { + const auto &st = button->st(); + price->moveToRight(st.padding.right(), st.padding.top()); + icon->moveToLeft(st.iconLeft, st.padding.top()); + }, button->lifetime()); + button->setClickedCallback([=] { + }); + Ui::ToggleChildrenVisibility(button, true); + } + + // Footer. + { + auto text = tr::lng_credits_summary_options_about( + lt_link, + tr::lng_credits_summary_options_about_link( + ) | rpl::map([](const QString &t) { + using namespace Ui::Text; + return Link(t, u"https://telegram.org/tos"_q); + }), + Ui::Text::RichLangValue); + Ui::AddSkip(content); + Ui::AddDividerText(content, std::move(text)); + } + + content->resizeToWidth(container->width()); + }; + + using ApiOptions = Api::CreditsTopupOptions; + const auto apiCredits = content->lifetime().make_state( + _controller->session().user()); + + apiCredits->request( + ) | rpl::start_with_error_done([=](const QString &error) { + _controller->showToast(error); + }, [=] { + fill(apiCredits->options()); + }, content->lifetime()); } void Credits::setupContent() { const auto content = Ui::CreateChild(this); + setupOptions(content); Ui::ResizeFitChild(this, content); } diff --git a/Telegram/SourceFiles/ui/effects/credits.style b/Telegram/SourceFiles/ui/effects/credits.style new file mode 100644 index 000000000..4c27ea541 --- /dev/null +++ b/Telegram/SourceFiles/ui/effects/credits.style @@ -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 +*/ +using "ui/basic.style"; +using "boxes/boxes.style"; +using "ui/widgets/widgets.style"; +using "ui/effects/premium.style"; +using "settings/settings.style"; + +creditsPremiumCover: PremiumCover(defaultPremiumCover) { + about: FlatLabel(userPremiumCoverAbout) { + textFg: boxTitleFg; + } +} +creditsTopupButton: SettingsButton(settingsButton) { + style: semiboldTextStyle; +} +creditsTopupPrice: FlatLabel(defaultFlatLabel) { + textFg: windowSubTextFg; +} diff --git a/Telegram/SourceFiles/ui/effects/premium.style b/Telegram/SourceFiles/ui/effects/premium.style index 0fffd9c5e..afdac7146 100644 --- a/Telegram/SourceFiles/ui/effects/premium.style +++ b/Telegram/SourceFiles/ui/effects/premium.style @@ -364,9 +364,3 @@ boostFeatureLink: icon{{ "settings/premium/features/feature_links", windowBgActi boostFeatureName: icon{{ "settings/premium/features/feature_color_names", windowBgActive }}; boostFeatureStories: icon{{ "settings/premium/features/feature_stories", windowBgActive }}; boostFeatureTranscribe: icon{{ "settings/premium/features/feature_voice", windowBgActive }}; - -creditsPremiumCover: PremiumCover(defaultPremiumCover) { - about: FlatLabel(userPremiumCoverAbout) { - textFg: boxTitleFg; - } -} diff --git a/Telegram/cmake/td_ui.cmake b/Telegram/cmake/td_ui.cmake index 987cca721..8c8cddac4 100644 --- a/Telegram/cmake/td_ui.cmake +++ b/Telegram/cmake/td_ui.cmake @@ -16,6 +16,7 @@ set(style_files ui/filter_icons.style ui/menu_icons.style ui/chat/chat.style + ui/effects/credits.style ui/effects/premium.style boxes/boxes.style dialogs/dialogs.style