diff --git a/Telegram/SourceFiles/settings/settings_credits.cpp b/Telegram/SourceFiles/settings/settings_credits.cpp new file mode 100644 index 000000000..4656170f6 --- /dev/null +++ b/Telegram/SourceFiles/settings/settings_credits.cpp @@ -0,0 +1,231 @@ +/* +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 "settings/settings_credits.h" + +#include "api/api_credits.h" +#include "core/click_handler_types.h" +#include "data/data_user.h" +#include "info/settings/info_settings_widget.h" // SectionCustomTopBarData. +#include "lang/lang_keys.h" +#include "main/main_session.h" +#include "settings/settings_common_session.h" +#include "ui/effects/premium_graphics.h" +#include "ui/effects/premium_top_bar.h" +#include "ui/painter.h" +#include "ui/rect.h" +#include "ui/widgets/buttons.h" +#include "ui/widgets/labels.h" +#include "ui/wrap/fade_wrap.h" +#include "ui/wrap/vertical_layout.h" +#include "window/window_session_controller.h" +#include "styles/style_info.h" +#include "styles/style_premium.h" +#include "styles/style_settings.h" + +namespace Settings { +namespace { + +using SectionCustomTopBarData = Info::Settings::SectionCustomTopBarData; + +class Credits : public Section { +public: + Credits( + QWidget *parent, + not_null controller); + + [[nodiscard]] rpl::producer title() override; + + [[nodiscard]] QPointer createPinnedToTop( + not_null parent) override; + + void showFinished() override; + + [[nodiscard]] bool hasFlexibleTopBar() const override; + + void setStepDataReference(std::any &data) override; + + [[nodiscard]] rpl::producer<> sectionShowBack() override final; + +private: + void setupContent(); + void setupOptions(not_null container); + + const not_null _controller; + + base::unique_qptr> _back; + base::unique_qptr _close; + rpl::variable _backToggles; + rpl::variable _wrap; + Fn _setPaused; + + rpl::event_stream<> _showBack; + rpl::event_stream<> _showFinished; + rpl::variable _buttonText; + +}; + +Credits::Credits( + QWidget *parent, + not_null controller) +: Section(parent) +, _controller(controller) { + setupContent(); +} + +rpl::producer Credits::title() { + return tr::lng_premium_summary_title(); +} + +bool Credits::hasFlexibleTopBar() const { + return true; +} + +rpl::producer<> Credits::sectionShowBack() { + return _showBack.events(); +} + +void Credits::setStepDataReference(std::any &data) { + const auto my = std::any_cast(&data); + if (my) { + _backToggles = std::move( + my->backButtonEnables + ) | rpl::map_to(true); + _wrap = std::move(my->wrapValue); + } +} + +void Credits::setupOptions(not_null container) { +} + +void Credits::setupContent() { + const auto content = Ui::CreateChild(this); + + Ui::ResizeFitChild(this, content); +} + +QPointer Credits::createPinnedToTop( + not_null parent) { + + const auto content = [&]() -> Ui::Premium::TopBarAbstract* { + const auto weak = base::make_weak(_controller); + const auto clickContextOther = [=] { + return QVariant::fromValue(ClickHandlerContext{ + .sessionWindow = weak, + .botStartAutoSubmit = true, + }); + }; + return Ui::CreateChild( + parent.get(), + st::creditsPremiumCover, + Ui::Premium::TopBarDescriptor{ + .clickContextOther = clickContextOther, + .title = tr::lng_credits_summary_title(), + .about = tr::lng_credits_summary_about( + TextWithEntities::Simple), + .light = true, + .gradientStops = Ui::Premium::CreditsIconGradientStops(), + }); + }(); + _setPaused = [=](bool paused) { + content->setPaused(paused); + }; + + _wrap.value( + ) | rpl::start_with_next([=](Info::Wrap wrap) { + content->setRoundEdges(wrap == Info::Wrap::Layer); + }, content->lifetime()); + + content->setMaximumHeight(st::settingsPremiumTopHeight); + content->setMinimumHeight(st::infoLayerTopBarHeight); + + content->resize(content->width(), content->maximumHeight()); + content->additionalHeight( + ) | rpl::start_with_next([=](int additionalHeight) { + const auto wasMax = (content->height() == content->maximumHeight()); + content->setMaximumHeight(st::settingsPremiumTopHeight + + additionalHeight); + if (wasMax) { + content->resize(content->width(), content->maximumHeight()); + } + }, content->lifetime()); + + _wrap.value( + ) | rpl::start_with_next([=](Info::Wrap wrap) { + const auto isLayer = (wrap == Info::Wrap::Layer); + _back = base::make_unique_q>( + content, + object_ptr( + content, + (isLayer ? st::infoTopBarBack : st::infoLayerTopBarBack)), + st::infoTopBarScale); + _back->setDuration(0); + _back->toggleOn(isLayer + ? _backToggles.value() | rpl::type_erased() + : rpl::single(true)); + _back->entity()->addClickHandler([=] { + _showBack.fire({}); + }); + _back->toggledValue( + ) | rpl::start_with_next([=](bool toggled) { + const auto &st = isLayer ? st::infoLayerTopBar : st::infoTopBar; + content->setTextPosition( + toggled ? st.back.width : st.titlePosition.x(), + st.titlePosition.y()); + }, _back->lifetime()); + + if (!isLayer) { + _close = nullptr; + } else { + _close = base::make_unique_q( + content, + st::infoTopBarClose); + _close->addClickHandler([=] { + _controller->parentController()->hideLayer(); + _controller->parentController()->hideSpecialLayer(); + }); + content->widthValue( + ) | rpl::start_with_next([=] { + _close->moveToRight(0, 0); + }, _close->lifetime()); + } + }, content->lifetime()); + + return Ui::MakeWeak(not_null{ content }); +} + +void Credits::showFinished() { + _showFinished.fire({}); +} + +} // namespace + +template <> +struct SectionFactory : AbstractSectionFactory { + object_ptr create( + not_null parent, + not_null controller, + not_null scroll, + rpl::producer containerValue + ) const final override { + return object_ptr(parent, controller); + } + bool hasCustomTopBar() const final override { + return true; + } + + [[nodiscard]] static const std::shared_ptr &Instance() { + static const auto result = std::make_shared(); + return result; + } +}; + +Type CreditsId() { + return Credits::Id(); +} + +} // namespace Settings diff --git a/Telegram/SourceFiles/settings/settings_credits.h b/Telegram/SourceFiles/settings/settings_credits.h new file mode 100644 index 000000000..7484fa637 --- /dev/null +++ b/Telegram/SourceFiles/settings/settings_credits.h @@ -0,0 +1,44 @@ +/* +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 + +#include "settings/settings_type.h" + +enum class PremiumFeature; + +namespace style { +struct RoundButton; +} // namespace style + +namespace ChatHelpers { +class Show; +enum class WindowUsage; +} // namespace ChatHelpers + +namespace Ui { +class RpWidget; +class RoundButton; +class GradientButton; +class VerticalLayout; +} // namespace Ui + +namespace Main { +class Session; +class SessionShow; +} // namespace Main + +namespace Window { +class SessionController; +} // namespace Window + +namespace Settings { + +[[nodiscard]] Type CreditsId(); + +} // namespace Settings + diff --git a/Telegram/SourceFiles/settings/settings_main.cpp b/Telegram/SourceFiles/settings/settings_main.cpp index 551d4f33c..19a63e84f 100644 --- a/Telegram/SourceFiles/settings/settings_main.cpp +++ b/Telegram/SourceFiles/settings/settings_main.cpp @@ -9,17 +9,18 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/application.h" #include "core/click_handler_types.h" +#include "settings/settings_advanced.h" #include "settings/settings_business.h" -#include "settings/settings_codes.h" +#include "settings/settings_calls.h" #include "settings/settings_chat.h" +#include "settings/settings_codes.h" +#include "settings/settings_credits.h" +#include "settings/settings_folders.h" #include "settings/settings_information.h" #include "settings/settings_notifications.h" -#include "settings/settings_privacy_security.h" -#include "settings/settings_advanced.h" -#include "settings/settings_folders.h" -#include "settings/settings_calls.h" #include "settings/settings_power_saving.h" #include "settings/settings_premium.h" +#include "settings/settings_privacy_security.h" #include "settings/settings_scale_preview.h" #include "boxes/language_box.h" #include "boxes/username_box.h" @@ -414,6 +415,15 @@ void SetupPremium( controller->setPremiumRef("settings"); showOther(PremiumId()); }); + AddButtonWithIcon( + container, + tr::lng_credits_summary_title(), + st::settingsButton, + { .icon = &st::menuIconPremium } + )->addClickHandler([=] { + controller->setPremiumRef("settings"); + showOther(CreditsId()); + }); const auto button = AddButtonWithIcon( container, tr::lng_business_title(), diff --git a/Telegram/SourceFiles/ui/effects/premium.style b/Telegram/SourceFiles/ui/effects/premium.style index afdac7146..0fffd9c5e 100644 --- a/Telegram/SourceFiles/ui/effects/premium.style +++ b/Telegram/SourceFiles/ui/effects/premium.style @@ -364,3 +364,9 @@ 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/SourceFiles/ui/effects/premium_graphics.cpp b/Telegram/SourceFiles/ui/effects/premium_graphics.cpp index b701f8500..d04dae62b 100644 --- a/Telegram/SourceFiles/ui/effects/premium_graphics.cpp +++ b/Telegram/SourceFiles/ui/effects/premium_graphics.cpp @@ -1177,6 +1177,13 @@ QGradientStops StoriesIconsGradientStops() { }; } +QGradientStops CreditsIconGradientStops() { + return { + { 0., st::creditsBg1->c }, + { 1., st::creditsBg2->c }, + }; +} + void ShowListBox( not_null box, const style::PremiumLimits &st, diff --git a/Telegram/SourceFiles/ui/effects/premium_graphics.h b/Telegram/SourceFiles/ui/effects/premium_graphics.h index 728dd9d40..339d49a3d 100644 --- a/Telegram/SourceFiles/ui/effects/premium_graphics.h +++ b/Telegram/SourceFiles/ui/effects/premium_graphics.h @@ -124,6 +124,7 @@ void AddAccountsRow( [[nodiscard]] QGradientStops LockGradientStops(); [[nodiscard]] QGradientStops FullHeightGradientStops(); [[nodiscard]] QGradientStops GiftGradientStops(); +[[nodiscard]] QGradientStops CreditsIconGradientStops(); struct ListEntry final { rpl::producer title;