Added initial dummy settings section for credits.

This commit is contained in:
23rd 2024-05-16 21:44:42 +03:00 committed by John Preston
parent 4a0bffe618
commit b5eb195f43
6 changed files with 304 additions and 5 deletions

View file

@ -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<Credits> {
public:
Credits(
QWidget *parent,
not_null<Window::SessionController*> controller);
[[nodiscard]] rpl::producer<QString> title() override;
[[nodiscard]] QPointer<Ui::RpWidget> createPinnedToTop(
not_null<QWidget*> 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<Ui::VerticalLayout*> container);
const not_null<Window::SessionController*> _controller;
base::unique_qptr<Ui::FadeWrap<Ui::IconButton>> _back;
base::unique_qptr<Ui::IconButton> _close;
rpl::variable<bool> _backToggles;
rpl::variable<Info::Wrap> _wrap;
Fn<void(bool)> _setPaused;
rpl::event_stream<> _showBack;
rpl::event_stream<> _showFinished;
rpl::variable<QString> _buttonText;
};
Credits::Credits(
QWidget *parent,
not_null<Window::SessionController*> controller)
: Section(parent)
, _controller(controller) {
setupContent();
}
rpl::producer<QString> 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<SectionCustomTopBarData>(&data);
if (my) {
_backToggles = std::move(
my->backButtonEnables
) | rpl::map_to(true);
_wrap = std::move(my->wrapValue);
}
}
void Credits::setupOptions(not_null<Ui::VerticalLayout*> container) {
}
void Credits::setupContent() {
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
Ui::ResizeFitChild(this, content);
}
QPointer<Ui::RpWidget> Credits::createPinnedToTop(
not_null<QWidget*> 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<Ui::Premium::TopBar>(
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<Ui::FadeWrap<Ui::IconButton>>(
content,
object_ptr<Ui::IconButton>(
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<Ui::IconButton>(
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<Ui::RpWidget*>{ content });
}
void Credits::showFinished() {
_showFinished.fire({});
}
} // namespace
template <>
struct SectionFactory<Credits> : AbstractSectionFactory {
object_ptr<AbstractSection> create(
not_null<QWidget*> parent,
not_null<Window::SessionController*> controller,
not_null<Ui::ScrollArea*> scroll,
rpl::producer<Container> containerValue
) const final override {
return object_ptr<Credits>(parent, controller);
}
bool hasCustomTopBar() const final override {
return true;
}
[[nodiscard]] static const std::shared_ptr<SectionFactory> &Instance() {
static const auto result = std::make_shared<SectionFactory>();
return result;
}
};
Type CreditsId() {
return Credits::Id();
}
} // namespace Settings

View file

@ -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

View file

@ -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(),

View file

@ -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;
}
}

View file

@ -1177,6 +1177,13 @@ QGradientStops StoriesIconsGradientStops() {
};
}
QGradientStops CreditsIconGradientStops() {
return {
{ 0., st::creditsBg1->c },
{ 1., st::creditsBg2->c },
};
}
void ShowListBox(
not_null<Ui::GenericBox*> box,
const style::PremiumLimits &st,

View file

@ -124,6 +124,7 @@ void AddAccountsRow(
[[nodiscard]] QGradientStops LockGradientStops();
[[nodiscard]] QGradientStops FullHeightGradientStops();
[[nodiscard]] QGradientStops GiftGradientStops();
[[nodiscard]] QGradientStops CreditsIconGradientStops();
struct ListEntry final {
rpl::producer<QString> title;