From 00632dff468f94fdfff90a66cf8630ddf3890b64 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sat, 21 May 2022 06:23:22 +0300 Subject: [PATCH] Added initial support of custom top bar for premium settings. --- .../SourceFiles/info/info_wrap_widget.cpp | 26 +++++++++++ .../SourceFiles/settings/settings_premium.cpp | 46 +++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/Telegram/SourceFiles/info/info_wrap_widget.cpp b/Telegram/SourceFiles/info/info_wrap_widget.cpp index dc753062e6..7f38efe0ef 100644 --- a/Telegram/SourceFiles/info/info_wrap_widget.cpp +++ b/Telegram/SourceFiles/info/info_wrap_widget.cpp @@ -17,6 +17,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "settings/cloud_password/settings_cloud_password_email_confirm.h" #include "settings/settings_chat.h" #include "settings/settings_main.h" +#include "settings/settings_premium.h" +#include "ui/effects/ripple_animation.h" // maskByDrawer. #include "ui/widgets/discrete_sliders.h" #include "ui/widgets/buttons.h" #include "ui/widgets/shadow.h" @@ -55,6 +57,12 @@ const style::InfoTopBar &TopBarStyle(Wrap wrap) { : st::infoTopBar; } +[[nodiscard]] bool HasCustomTopBar(not_null controller) { + const auto section = controller->section(); + return (section.type() == Section::Type::Settings + && (section.settingsType() == ::Settings::PremiumId())); +} + } // namespace struct WrapWidget::StackItem { @@ -346,6 +354,10 @@ void WrapWidget::setupTop() { //} else { // createTopBar(); //} + if (HasCustomTopBar(_controller.get())) { + _topBar.destroy(); + return; + } createTopBar(); } @@ -957,6 +969,20 @@ void WrapWidget::showNewContent( const auto layer = (wrap() == Wrap::Layer); animationParams.withFade = layer; animationParams.topSkip = layer ? st::boxRadius : 0; + + if (HasCustomTopBar(_controller.get()) + || HasCustomTopBar(newController.get())) { + + const auto s = QSize( + newContent->width(), + animationParams.topSkip); + auto image = Ui::RippleAnimation::maskByDrawer(s, false, [&]( + QPainter &p) { + const auto r = QRect(0, 0, s.width(), s.height() * 2); + p.drawRoundedRect(r, st::boxRadius, st::boxRadius); + }); + animationParams.topMask = Ui::PixmapFromImage(std::move(image)); + } } if (saveToStack) { auto item = StackItem(); diff --git a/Telegram/SourceFiles/settings/settings_premium.cpp b/Telegram/SourceFiles/settings/settings_premium.cpp index 000e7c5ec9..ec42ed9a78 100644 --- a/Telegram/SourceFiles/settings/settings_premium.cpp +++ b/Telegram/SourceFiles/settings/settings_premium.cpp @@ -27,6 +27,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_app_config.h" #include "styles/style_boxes.h" #include "styles/style_chat_helpers.h" +#include "styles/style_info.h" +#include "styles/style_intro.h" #include "styles/style_layers.h" #include "styles/style_settings.h" @@ -41,6 +43,8 @@ public: [[nodiscard]] rpl::producer title() override; + [[nodiscard]] QPointer createPinnedToTop( + not_null parent) override; [[nodiscard]] QPointer createPinnedToBottom( not_null parent) override; @@ -228,6 +232,48 @@ void Premium::setupContent() { } +QPointer Premium::createPinnedToTop( + not_null parent) { + const auto container = Ui::CreateChild(parent.get()); + const auto content = container->add(object_ptr(container)); + content->resize(content->width(), st::introQrStepsTop); + + container->setAttribute(Qt::WA_OpaquePaintEvent, false); + content->setAttribute(Qt::WA_OpaquePaintEvent, false); + + content->paintRequest( + ) | rpl::start_with_next([=](const QRect &paintRect) { + Painter p(content); + + p.fillRect(paintRect, Qt::transparent); + + const auto rect = content->rect(); + auto pathTop = QPainterPath(); + pathTop.addRoundedRect(rect, st::boxRadius, st::boxRadius); + auto pathBottom = QPainterPath(); + pathBottom.addRect( + QRect( + QPoint(rect.x(), rect.y() + rect.height() - st::boxRadius), + QSize(rect.width(), st::boxRadius))); + + const auto gradientPointTop = rect.height() / 3. * 2.; + auto gradient = QLinearGradient( + QPointF(0, gradientPointTop), + QPointF(rect.width(), rect.height() - gradientPointTop)); + gradient.setColorAt(0., st::premiumButtonBg1->c); + gradient.setColorAt(.6, st::premiumButtonBg2->c); + gradient.setColorAt(1., st::premiumButtonBg3->c); + + PainterHighQualityEnabler hq(p); + p.fillPath(pathTop + pathBottom, gradient); + }, content->lifetime()); + + container->setMaximumHeight(st::introQrStepsTop); + container->setMinimumHeight(st::infoLayerTopBarHeight); + + return Ui::MakeWeak(not_null{ container }); +} + QPointer Premium::createPinnedToBottom( not_null parent) {