2022-05-18 18:53:25 +00:00
|
|
|
/*
|
|
|
|
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_premium.h"
|
|
|
|
|
2022-05-24 11:37:05 +00:00
|
|
|
#include "base/random.h"
|
2022-05-22 23:06:35 +00:00
|
|
|
#include "core/application.h"
|
2022-06-08 13:19:39 +00:00
|
|
|
#include "core/click_handler_types.h"
|
2022-05-30 23:37:15 +00:00
|
|
|
#include "data/data_peer_values.h"
|
2022-05-22 23:49:33 +00:00
|
|
|
#include "info/info_wrap_widget.h" // Info::Wrap.
|
2022-05-22 23:06:35 +00:00
|
|
|
#include "info/settings/info_settings_widget.h" // SectionCustomTopBarData.
|
2022-05-18 18:53:25 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2022-06-08 07:26:53 +00:00
|
|
|
#include "boxes/premium_preview_box.h"
|
2022-05-18 18:53:25 +00:00
|
|
|
#include "settings/settings_common.h"
|
2022-05-20 13:12:56 +00:00
|
|
|
#include "settings/settings_premium.h"
|
2022-05-18 18:53:25 +00:00
|
|
|
#include "ui/abstract_button.h"
|
2022-05-23 08:04:31 +00:00
|
|
|
#include "ui/basic_click_handlers.h"
|
2022-05-24 11:37:05 +00:00
|
|
|
#include "ui/effects/animation_value_f.h"
|
2022-05-18 18:53:25 +00:00
|
|
|
#include "ui/effects/gradient.h"
|
2022-05-23 08:04:31 +00:00
|
|
|
#include "ui/effects/premium_graphics.h"
|
2022-05-18 18:53:25 +00:00
|
|
|
#include "ui/text/text_utilities.h"
|
2022-06-03 11:57:06 +00:00
|
|
|
#include "ui/text/format_values.h"
|
2022-06-08 07:26:53 +00:00
|
|
|
#include "ui/layers/generic_box.h"
|
2022-05-18 18:53:25 +00:00
|
|
|
#include "ui/widgets/gradient_round_button.h"
|
|
|
|
#include "ui/widgets/labels.h"
|
2022-05-22 23:06:35 +00:00
|
|
|
#include "ui/wrap/fade_wrap.h"
|
2022-05-18 18:53:25 +00:00
|
|
|
#include "ui/wrap/padding_wrap.h"
|
2022-05-22 23:49:33 +00:00
|
|
|
#include "ui/wrap/slide_wrap.h"
|
2022-05-18 18:53:25 +00:00
|
|
|
#include "ui/wrap/vertical_layout.h"
|
2022-05-20 13:12:56 +00:00
|
|
|
#include "window/window_controller.h"
|
|
|
|
#include "main/main_session.h"
|
2022-05-23 08:04:31 +00:00
|
|
|
#include "main/main_account.h"
|
|
|
|
#include "main/main_app_config.h"
|
2022-05-22 23:49:33 +00:00
|
|
|
#include "window/window_session_controller.h"
|
2022-05-23 14:46:15 +00:00
|
|
|
#include "base/unixtime.h"
|
|
|
|
#include "apiwrap.h"
|
2022-05-31 17:11:59 +00:00
|
|
|
#include "api/api_premium.h"
|
2022-05-18 18:53:25 +00:00
|
|
|
#include "styles/style_boxes.h"
|
|
|
|
#include "styles/style_chat_helpers.h"
|
2022-05-21 03:23:22 +00:00
|
|
|
#include "styles/style_info.h"
|
|
|
|
#include "styles/style_intro.h"
|
2022-05-18 18:53:25 +00:00
|
|
|
#include "styles/style_layers.h"
|
|
|
|
#include "styles/style_settings.h"
|
|
|
|
|
2022-05-23 04:01:31 +00:00
|
|
|
#include <QSvgRenderer>
|
|
|
|
|
2022-05-18 18:53:25 +00:00
|
|
|
namespace Settings {
|
|
|
|
namespace {
|
|
|
|
|
2022-05-22 23:06:35 +00:00
|
|
|
using SectionCustomTopBarData = Info::Settings::SectionCustomTopBarData;
|
|
|
|
|
2022-05-23 04:01:31 +00:00
|
|
|
constexpr auto kBodyAnimationPart = 0.90;
|
|
|
|
constexpr auto kTitleAnimationPart = 0.15;
|
|
|
|
|
2022-05-24 11:37:05 +00:00
|
|
|
constexpr auto kTitleAdditionalScale = 0.15;
|
|
|
|
|
2022-05-29 02:21:27 +00:00
|
|
|
constexpr auto kDeformationMax = 0.1;
|
|
|
|
|
2022-05-23 09:27:32 +00:00
|
|
|
struct Entry {
|
|
|
|
const style::icon *icon;
|
|
|
|
rpl::producer<QString> title;
|
|
|
|
rpl::producer<QString> description;
|
2022-06-14 03:11:35 +00:00
|
|
|
std::optional<PremiumPreview> section;
|
2022-05-23 09:27:32 +00:00
|
|
|
};
|
|
|
|
|
2022-05-24 09:24:39 +00:00
|
|
|
using Order = std::vector<QString>;
|
|
|
|
|
|
|
|
[[nodiscard]] Order FallbackOrder() {
|
|
|
|
return Order{
|
2022-06-13 12:52:21 +00:00
|
|
|
u"double_limits"_q,
|
|
|
|
u"more_upload"_q,
|
|
|
|
u"faster_download"_q,
|
|
|
|
u"voice_to_text"_q,
|
|
|
|
u"no_ads"_q,
|
|
|
|
u"unique_reactions"_q,
|
|
|
|
u"premium_stickers"_q,
|
|
|
|
u"advanced_chat_management"_q,
|
|
|
|
u"profile_badge"_q,
|
|
|
|
u"animated_userpics"_q,
|
2022-05-24 09:24:39 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-05-23 09:27:32 +00:00
|
|
|
[[nodiscard]] base::flat_map<QString, Entry> EntryMap() {
|
|
|
|
return base::flat_map<QString, Entry>{
|
|
|
|
{
|
2022-06-13 12:52:21 +00:00
|
|
|
u"double_limits"_q,
|
2022-05-23 09:27:32 +00:00
|
|
|
Entry{
|
|
|
|
&st::settingsPremiumIconDouble,
|
|
|
|
tr::lng_premium_summary_subtitle_double_limits(),
|
|
|
|
tr::lng_premium_summary_about_double_limits(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2022-06-13 12:52:21 +00:00
|
|
|
u"more_upload"_q,
|
2022-05-23 09:27:32 +00:00
|
|
|
Entry{
|
|
|
|
&st::settingsPremiumIconFiles,
|
|
|
|
tr::lng_premium_summary_subtitle_more_upload(),
|
|
|
|
tr::lng_premium_summary_about_more_upload(),
|
2022-06-14 03:11:35 +00:00
|
|
|
PremiumPreview::MoreUpload,
|
2022-05-23 09:27:32 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2022-06-13 12:52:21 +00:00
|
|
|
u"faster_download"_q,
|
2022-05-23 09:27:32 +00:00
|
|
|
Entry{
|
|
|
|
&st::settingsPremiumIconSpeed,
|
|
|
|
tr::lng_premium_summary_subtitle_faster_download(),
|
|
|
|
tr::lng_premium_summary_about_faster_download(),
|
2022-06-14 03:11:35 +00:00
|
|
|
PremiumPreview::FasterDownload,
|
2022-05-23 09:27:32 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2022-06-13 12:52:21 +00:00
|
|
|
u"voice_to_text"_q,
|
2022-05-23 09:27:32 +00:00
|
|
|
Entry{
|
|
|
|
&st::settingsPremiumIconVoice,
|
|
|
|
tr::lng_premium_summary_subtitle_voice_to_text(),
|
|
|
|
tr::lng_premium_summary_about_voice_to_text(),
|
2022-06-14 03:11:35 +00:00
|
|
|
PremiumPreview::VoiceToText,
|
2022-05-23 09:27:32 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2022-06-13 12:52:21 +00:00
|
|
|
u"no_ads"_q,
|
2022-05-23 09:27:32 +00:00
|
|
|
Entry{
|
|
|
|
&st::settingsPremiumIconChannelsOff,
|
|
|
|
tr::lng_premium_summary_subtitle_no_ads(),
|
|
|
|
tr::lng_premium_summary_about_no_ads(),
|
2022-06-14 03:11:35 +00:00
|
|
|
PremiumPreview::NoAds,
|
2022-05-23 09:27:32 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2022-06-13 12:52:21 +00:00
|
|
|
u"unique_reactions"_q,
|
2022-05-23 09:27:32 +00:00
|
|
|
Entry{
|
|
|
|
&st::settingsPremiumIconLike,
|
|
|
|
tr::lng_premium_summary_subtitle_unique_reactions(),
|
|
|
|
tr::lng_premium_summary_about_unique_reactions(),
|
2022-06-14 03:11:35 +00:00
|
|
|
PremiumPreview::Reactions,
|
2022-05-23 09:27:32 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2022-06-13 12:52:21 +00:00
|
|
|
u"premium_stickers"_q,
|
2022-05-23 09:27:32 +00:00
|
|
|
Entry{
|
|
|
|
&st::settingsIconStickers,
|
|
|
|
tr::lng_premium_summary_subtitle_premium_stickers(),
|
|
|
|
tr::lng_premium_summary_about_premium_stickers(),
|
2022-06-14 03:11:35 +00:00
|
|
|
PremiumPreview::Stickers,
|
2022-05-23 09:27:32 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2022-06-13 12:52:21 +00:00
|
|
|
u"advanced_chat_management"_q,
|
2022-05-23 09:27:32 +00:00
|
|
|
Entry{
|
|
|
|
&st::settingsIconChat,
|
|
|
|
tr::lng_premium_summary_subtitle_advanced_chat_management(),
|
|
|
|
tr::lng_premium_summary_about_advanced_chat_management(),
|
2022-06-14 03:11:35 +00:00
|
|
|
PremiumPreview::AdvancedChatManagement,
|
2022-05-23 09:27:32 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2022-06-13 12:52:21 +00:00
|
|
|
u"profile_badge"_q,
|
2022-05-23 09:27:32 +00:00
|
|
|
Entry{
|
|
|
|
&st::settingsPremiumIconStar,
|
|
|
|
tr::lng_premium_summary_subtitle_profile_badge(),
|
|
|
|
tr::lng_premium_summary_about_profile_badge(),
|
2022-06-14 03:11:35 +00:00
|
|
|
PremiumPreview::ProfileBadge,
|
2022-05-23 09:27:32 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2022-06-13 12:52:21 +00:00
|
|
|
u"animated_userpics"_q,
|
2022-05-23 09:27:32 +00:00
|
|
|
Entry{
|
|
|
|
&st::settingsPremiumIconPlay,
|
|
|
|
tr::lng_premium_summary_subtitle_animated_userpics(),
|
|
|
|
tr::lng_premium_summary_about_animated_userpics(),
|
2022-06-14 03:11:35 +00:00
|
|
|
PremiumPreview::AnimatedUserpics,
|
2022-05-23 09:27:32 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-05-23 14:46:15 +00:00
|
|
|
void SendAppLog(
|
|
|
|
not_null<Main::Session*> session,
|
|
|
|
const QString &type,
|
|
|
|
const MTPJSONValue &data) {
|
|
|
|
const auto now = double(base::unixtime::now())
|
|
|
|
+ (QTime::currentTime().msec() / 1000.);
|
|
|
|
session->api().request(MTPhelp_SaveAppLog(
|
|
|
|
MTP_vector<MTPInputAppEvent>(1, MTP_inputAppEvent(
|
|
|
|
MTP_double(now),
|
|
|
|
MTP_string(type),
|
|
|
|
MTP_long(0),
|
|
|
|
data
|
|
|
|
))
|
|
|
|
)).send();
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] QString ResolveRef(const QString &ref) {
|
|
|
|
return ref.isEmpty() ? "settings" : ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendScreenShow(
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
const std::vector<QString> &order,
|
|
|
|
const QString &ref) {
|
|
|
|
auto list = QVector<MTPJSONValue>();
|
|
|
|
list.reserve(order.size());
|
|
|
|
for (const auto &element : order) {
|
|
|
|
list.push_back(MTP_jsonString(MTP_string(element)));
|
|
|
|
}
|
|
|
|
auto values = QVector<MTPJSONObjectValue>{
|
|
|
|
MTP_jsonObjectValue(
|
|
|
|
MTP_string("premium_promo_order"),
|
|
|
|
MTP_jsonArray(MTP_vector<MTPJSONValue>(std::move(list)))),
|
|
|
|
MTP_jsonObjectValue(
|
|
|
|
MTP_string("source"),
|
|
|
|
MTP_jsonString(MTP_string(ResolveRef(ref)))),
|
|
|
|
};
|
|
|
|
const auto data = MTP_jsonObject(
|
|
|
|
MTP_vector<MTPJSONObjectValue>(std::move(values)));
|
|
|
|
SendAppLog(
|
|
|
|
&controller->session(),
|
|
|
|
"premium.promo_screen_show",
|
|
|
|
data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendScreenAccept(not_null<Window::SessionController*> controller) {
|
|
|
|
SendAppLog(
|
|
|
|
&controller->session(),
|
|
|
|
"premium.promo_screen_accept",
|
|
|
|
MTP_jsonNull());
|
|
|
|
}
|
|
|
|
|
2022-05-24 11:37:05 +00:00
|
|
|
class MiniStars final {
|
|
|
|
public:
|
2022-05-29 03:50:29 +00:00
|
|
|
MiniStars(Fn<void(const QRect &r)> updateCallback);
|
2022-05-24 11:37:05 +00:00
|
|
|
|
|
|
|
void paint(Painter &p, const QRectF &rect);
|
2022-06-14 09:42:43 +00:00
|
|
|
void setPaused(bool paused);
|
2022-05-24 11:37:05 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
struct MiniStar {
|
|
|
|
crl::time birthTime = 0;
|
|
|
|
crl::time deathTime = 0;
|
|
|
|
int angle = 0;
|
|
|
|
float64 size = 0.;
|
|
|
|
float64 alpha = 0.;
|
2022-05-29 02:21:27 +00:00
|
|
|
float64 sinFactor = 0.;
|
2022-05-24 11:37:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Interval {
|
2022-05-24 11:37:05 +00:00
|
|
|
int from = 0;
|
|
|
|
int length = 0;
|
2022-05-24 11:37:05 +00:00
|
|
|
};
|
2022-05-28 22:22:36 +00:00
|
|
|
|
|
|
|
void createStar(crl::time now);
|
|
|
|
[[nodiscard]] int angle() const;
|
|
|
|
[[nodiscard]] crl::time timeNow() const;
|
|
|
|
[[nodiscard]] int randomInterval(const Interval &interval) const;
|
|
|
|
|
2022-05-24 11:37:05 +00:00
|
|
|
const std::vector<Interval> _availableAngles;
|
|
|
|
const Interval _lifeLength;
|
|
|
|
const Interval _deathTime;
|
|
|
|
const Interval _size;
|
|
|
|
const Interval _alpha;
|
2022-05-29 02:21:27 +00:00
|
|
|
const Interval _sinFactor;
|
2022-05-24 11:37:05 +00:00
|
|
|
|
|
|
|
const float64 _appearProgressTill;
|
|
|
|
const float64 _disappearProgressAfter;
|
|
|
|
const float64 _distanceProgressStart;
|
|
|
|
|
|
|
|
QSvgRenderer _sprite;
|
|
|
|
|
|
|
|
Ui::Animations::Basic _animation;
|
|
|
|
|
|
|
|
std::vector<MiniStar> _ministars;
|
|
|
|
|
|
|
|
crl::time _nextBirthTime = 0;
|
2022-06-14 09:42:43 +00:00
|
|
|
bool _paused = false;
|
2022-05-24 11:37:05 +00:00
|
|
|
|
2022-05-29 03:50:29 +00:00
|
|
|
QRect _rectToUpdate;
|
|
|
|
|
2022-05-24 11:37:05 +00:00
|
|
|
};
|
|
|
|
|
2022-05-29 03:50:29 +00:00
|
|
|
MiniStars::MiniStars(Fn<void(const QRect &r)> updateCallback)
|
2022-05-24 11:37:05 +00:00
|
|
|
: _availableAngles({
|
|
|
|
Interval{ -10, 40 },
|
|
|
|
Interval{ 180 + 10 - 40, 40 },
|
|
|
|
Interval{ 180 + 15, 50 },
|
|
|
|
Interval{ -15 - 50, 50 },
|
|
|
|
})
|
|
|
|
, _lifeLength({ 150, 200 })
|
|
|
|
, _deathTime({ 1500, 2000 })
|
|
|
|
, _size({ 10, 20 })
|
|
|
|
, _alpha({ 40, 60 })
|
2022-05-29 02:21:27 +00:00
|
|
|
, _sinFactor({ 10, 190 })
|
2022-05-24 11:37:05 +00:00
|
|
|
, _appearProgressTill(0.2)
|
|
|
|
, _disappearProgressAfter(0.8)
|
|
|
|
, _distanceProgressStart(0.5)
|
|
|
|
, _sprite(u":/gui/icons/settings/starmini.svg"_q)
|
|
|
|
, _animation([=](crl::time now) {
|
2022-06-14 09:42:43 +00:00
|
|
|
if (now > _nextBirthTime && !_paused) {
|
2022-05-24 11:37:05 +00:00
|
|
|
createStar(now);
|
2022-05-28 22:22:36 +00:00
|
|
|
_nextBirthTime = now + randomInterval(_lifeLength);
|
2022-05-24 11:37:05 +00:00
|
|
|
}
|
2022-05-29 03:50:29 +00:00
|
|
|
if (_rectToUpdate.isValid()) {
|
|
|
|
updateCallback(base::take(_rectToUpdate));
|
|
|
|
}
|
2022-05-24 11:37:05 +00:00
|
|
|
}) {
|
2022-05-28 22:22:36 +00:00
|
|
|
if (anim::Disabled()) {
|
|
|
|
const auto from = _deathTime.from + _deathTime.length;
|
|
|
|
for (auto i = -from; i < 0; i += randomInterval(_lifeLength)) {
|
|
|
|
createStar(i);
|
|
|
|
}
|
2022-05-29 03:50:29 +00:00
|
|
|
updateCallback(_rectToUpdate);
|
2022-05-28 22:22:36 +00:00
|
|
|
} else {
|
|
|
|
_animation.start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int MiniStars::randomInterval(const Interval &interval) const {
|
|
|
|
return interval.from + base::RandomIndex(interval.length);
|
|
|
|
}
|
|
|
|
|
|
|
|
crl::time MiniStars::timeNow() const {
|
|
|
|
return anim::Disabled() ? 0 : crl::now();
|
2022-05-24 11:37:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MiniStars::paint(Painter &p, const QRectF &rect) {
|
|
|
|
const auto center = rect.center();
|
|
|
|
const auto opacity = p.opacity();
|
|
|
|
for (const auto &ministar : _ministars) {
|
2022-05-28 22:22:36 +00:00
|
|
|
const auto progress = (timeNow() - ministar.birthTime)
|
2022-05-24 11:37:05 +00:00
|
|
|
/ float64(ministar.deathTime - ministar.birthTime);
|
|
|
|
if (progress > 1.) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const auto appearProgress = std::clamp(
|
|
|
|
progress / _appearProgressTill,
|
|
|
|
0.,
|
|
|
|
1.);
|
|
|
|
const auto rsin = float(std::sin(ministar.angle * M_PI / 180.));
|
|
|
|
const auto rcos = float(std::cos(ministar.angle * M_PI / 180.));
|
|
|
|
const auto end = QPointF(
|
|
|
|
rect.width() / 1.5 * rcos,
|
|
|
|
rect.height() / 1.5 * rsin);
|
|
|
|
|
|
|
|
const auto alphaProgress = 1.
|
|
|
|
- (std::clamp(progress - _disappearProgressAfter, 0., 1.)
|
|
|
|
/ (1. - _disappearProgressAfter));
|
2022-05-28 23:13:24 +00:00
|
|
|
p.setOpacity(ministar.alpha
|
|
|
|
* alphaProgress
|
|
|
|
* appearProgress
|
|
|
|
* opacity);
|
2022-05-24 11:37:05 +00:00
|
|
|
|
2022-05-29 02:21:27 +00:00
|
|
|
const auto deformResult = progress * 360;
|
|
|
|
const auto rsinDeform = float(
|
|
|
|
std::sin(ministar.sinFactor * deformResult * M_PI / 180.));
|
|
|
|
const auto deformH = 1. + kDeformationMax * rsinDeform;
|
|
|
|
const auto deformW = 1. / deformH;
|
|
|
|
|
2022-05-24 11:37:05 +00:00
|
|
|
const auto distanceProgress = _distanceProgressStart + progress;
|
2022-05-28 23:13:24 +00:00
|
|
|
const auto starSide = ministar.size * appearProgress;
|
|
|
|
const auto widthFade = (std::abs(rcos) >= std::abs(rsin));
|
2022-05-29 02:21:27 +00:00
|
|
|
const auto starWidth = starSide
|
|
|
|
* (widthFade ? alphaProgress : 1.)
|
|
|
|
* deformW;
|
|
|
|
const auto starHeight = starSide
|
|
|
|
* (!widthFade ? alphaProgress : 1.)
|
|
|
|
* deformH;
|
2022-05-29 03:50:29 +00:00
|
|
|
const auto renderRect = QRectF(
|
2022-05-24 11:37:05 +00:00
|
|
|
center.x()
|
|
|
|
+ anim::interpolateF(0, end.x(), distanceProgress)
|
2022-05-28 23:13:24 +00:00
|
|
|
- starWidth / 2.,
|
2022-05-24 11:37:05 +00:00
|
|
|
center.y()
|
|
|
|
+ anim::interpolateF(0, end.y(), distanceProgress)
|
2022-05-28 23:13:24 +00:00
|
|
|
- starHeight / 2.,
|
|
|
|
starWidth,
|
2022-05-29 03:50:29 +00:00
|
|
|
starHeight);
|
|
|
|
_sprite.render(&p, renderRect);
|
|
|
|
_rectToUpdate |= renderRect.toRect();
|
2022-05-24 11:37:05 +00:00
|
|
|
}
|
|
|
|
p.setOpacity(opacity);
|
|
|
|
}
|
|
|
|
|
2022-06-14 09:42:43 +00:00
|
|
|
void MiniStars::setPaused(bool paused) {
|
|
|
|
_paused = paused;
|
|
|
|
}
|
|
|
|
|
2022-05-24 11:37:05 +00:00
|
|
|
int MiniStars::angle() const {
|
|
|
|
const auto &interval = _availableAngles[
|
|
|
|
base::RandomIndex(_availableAngles.size())];
|
|
|
|
return base::RandomIndex(interval.length) + interval.from;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MiniStars::createStar(crl::time now) {
|
|
|
|
auto ministar = MiniStar{
|
|
|
|
.birthTime = now,
|
2022-05-28 22:22:36 +00:00
|
|
|
.deathTime = now + randomInterval(_deathTime),
|
2022-05-24 11:37:05 +00:00
|
|
|
.angle = angle(),
|
2022-05-28 22:22:36 +00:00
|
|
|
.size = float64(randomInterval(_size)),
|
|
|
|
.alpha = float64(randomInterval(_alpha)) / 100.,
|
2022-05-29 02:21:27 +00:00
|
|
|
.sinFactor = randomInterval(_sinFactor) / 100.
|
|
|
|
* (base::RandomIndex(2) == 1 ? 1. : -1.),
|
2022-05-24 11:37:05 +00:00
|
|
|
};
|
|
|
|
for (auto i = 0; i < _ministars.size(); i++) {
|
|
|
|
if (ministar.birthTime > _ministars[i].deathTime) {
|
|
|
|
_ministars[i] = ministar;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ministars.push_back(ministar);
|
|
|
|
}
|
|
|
|
|
2022-05-23 04:01:31 +00:00
|
|
|
class TopBar final : public Ui::RpWidget {
|
|
|
|
public:
|
2022-06-13 09:27:38 +00:00
|
|
|
TopBar(
|
|
|
|
not_null<QWidget*> parent,
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
rpl::producer<QString> title,
|
|
|
|
rpl::producer<TextWithEntities> about);
|
2022-05-23 04:01:31 +00:00
|
|
|
|
2022-06-14 09:42:43 +00:00
|
|
|
void setPaused(bool paused);
|
2022-05-23 04:01:31 +00:00
|
|
|
void setRoundEdges(bool value);
|
|
|
|
void setTextPosition(int x, int y);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
2022-05-29 03:50:29 +00:00
|
|
|
void resizeEvent(QResizeEvent *e) override;
|
2022-05-23 04:01:31 +00:00
|
|
|
|
|
|
|
private:
|
2022-05-29 03:50:29 +00:00
|
|
|
[[nodiscard]] QRectF starRect(
|
|
|
|
float64 topProgress,
|
|
|
|
float64 sizeProgress) const;
|
|
|
|
|
2022-05-24 11:37:05 +00:00
|
|
|
const style::font &_titleFont;
|
|
|
|
const style::margins &_titlePadding;
|
2022-06-13 09:27:38 +00:00
|
|
|
object_ptr<Ui::FlatLabel> _about;
|
2022-05-24 11:37:05 +00:00
|
|
|
MiniStars _ministars;
|
2022-05-23 04:01:31 +00:00
|
|
|
QSvgRenderer _star;
|
|
|
|
|
2022-05-29 03:50:29 +00:00
|
|
|
struct {
|
|
|
|
float64 top = 0.;
|
|
|
|
float64 body = 0.;
|
|
|
|
float64 title = 0.;
|
|
|
|
float64 scaleTitle = 0.;
|
|
|
|
} _progress;
|
|
|
|
|
|
|
|
QRectF _ministarsRect;
|
|
|
|
QRectF _starRect;
|
|
|
|
|
2022-05-23 04:01:31 +00:00
|
|
|
QPoint _titlePosition;
|
2022-05-24 11:37:05 +00:00
|
|
|
QPainterPath _titlePath;
|
2022-05-23 04:01:31 +00:00
|
|
|
bool _roundEdges = true;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2022-06-13 09:27:38 +00:00
|
|
|
TopBar::TopBar(
|
|
|
|
not_null<QWidget*> parent,
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
rpl::producer<QString> title,
|
|
|
|
rpl::producer<TextWithEntities> about)
|
2022-05-23 04:01:31 +00:00
|
|
|
: Ui::RpWidget(parent)
|
2022-05-24 11:37:05 +00:00
|
|
|
, _titleFont(st::boxTitle.style.font)
|
|
|
|
, _titlePadding(st::settingsPremiumTitlePadding)
|
2022-06-13 09:27:38 +00:00
|
|
|
, _about(this, std::move(about), st::settingsPremiumAbout)
|
2022-05-29 03:50:29 +00:00
|
|
|
, _ministars([=](const QRect &r) { update(r); })
|
2022-05-24 11:37:05 +00:00
|
|
|
, _star(u":/gui/icons/settings/star.svg"_q) {
|
2022-05-30 23:37:15 +00:00
|
|
|
std::move(
|
2022-06-13 09:27:38 +00:00
|
|
|
title
|
|
|
|
) | rpl::start_with_next([=](QString text) {
|
2022-05-30 23:37:15 +00:00
|
|
|
_titlePath = QPainterPath();
|
2022-06-13 09:27:38 +00:00
|
|
|
_titlePath.addText(0, _titleFont->ascent, _titleFont, text);
|
2022-05-30 23:37:15 +00:00
|
|
|
update();
|
|
|
|
}, lifetime());
|
2022-06-13 09:27:38 +00:00
|
|
|
|
|
|
|
_about->setClickHandlerFilter([=](
|
|
|
|
const ClickHandlerPtr &handler,
|
|
|
|
Qt::MouseButton button) {
|
|
|
|
ActivateClickHandler(_about, handler, {
|
|
|
|
button,
|
|
|
|
QVariant::fromValue(ClickHandlerContext{
|
|
|
|
.sessionWindow = base::make_weak(controller.get()),
|
|
|
|
.botStartAutoSubmit = true,
|
|
|
|
})
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
});
|
2022-05-23 04:01:31 +00:00
|
|
|
}
|
|
|
|
|
2022-06-14 09:42:43 +00:00
|
|
|
void TopBar::setPaused(bool paused) {
|
|
|
|
_ministars.setPaused(paused);
|
|
|
|
}
|
|
|
|
|
2022-05-23 04:01:31 +00:00
|
|
|
void TopBar::setRoundEdges(bool value) {
|
|
|
|
_roundEdges = value;
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TopBar::setTextPosition(int x, int y) {
|
|
|
|
_titlePosition = { x, y };
|
|
|
|
}
|
|
|
|
|
2022-05-29 03:50:29 +00:00
|
|
|
QRectF TopBar::starRect(float64 topProgress, float64 sizeProgress) const {
|
|
|
|
const auto starSize = st::settingsPremiumStarSize * sizeProgress;
|
|
|
|
return QRectF(
|
|
|
|
QPointF(
|
|
|
|
(width() - starSize.width()) / 2,
|
|
|
|
st::settingsPremiumStarTopSkip * topProgress),
|
|
|
|
starSize);
|
|
|
|
};
|
2022-05-23 04:01:31 +00:00
|
|
|
|
2022-05-29 03:50:29 +00:00
|
|
|
void TopBar::resizeEvent(QResizeEvent *e) {
|
|
|
|
const auto progress = (e->size().height() - minimumHeight())
|
2022-05-23 04:01:31 +00:00
|
|
|
/ float64(maximumHeight() - minimumHeight());
|
2022-05-29 03:50:29 +00:00
|
|
|
_progress.top = 1. -
|
2022-05-23 04:01:31 +00:00
|
|
|
std::clamp(
|
|
|
|
(1. - progress) / kBodyAnimationPart,
|
|
|
|
0.,
|
|
|
|
1.);
|
2022-05-29 03:50:29 +00:00
|
|
|
_progress.body = _progress.top;
|
|
|
|
_progress.title = 1. - progress;
|
|
|
|
_progress.scaleTitle = 1. + kTitleAdditionalScale * progress;
|
|
|
|
|
|
|
|
_ministarsRect = starRect(_progress.top, 1.);
|
|
|
|
_starRect = starRect(_progress.top, _progress.body);
|
|
|
|
|
2022-06-13 09:27:38 +00:00
|
|
|
const auto &padding = st::boxRowPadding;
|
|
|
|
const auto availableWidth = width() - padding.left() - padding.right();
|
|
|
|
const auto titleTop = _starRect.top()
|
|
|
|
+ _starRect.height()
|
|
|
|
+ _titlePadding.top();
|
|
|
|
const auto titlePathRect = _titlePath.boundingRect();
|
|
|
|
const auto aboutTop = titleTop
|
|
|
|
+ titlePathRect.height()
|
|
|
|
+ _titlePadding.bottom();
|
|
|
|
_about->resizeToWidth(availableWidth);
|
|
|
|
_about->moveToLeft(padding.left(), aboutTop);
|
|
|
|
_about->setOpacity(_progress.body);
|
|
|
|
|
2022-05-29 03:50:29 +00:00
|
|
|
Ui::RpWidget::resizeEvent(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TopBar::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
|
|
|
|
|
|
|
p.fillRect(e->rect(), Qt::transparent);
|
2022-05-23 04:01:31 +00:00
|
|
|
|
|
|
|
const auto r = rect();
|
|
|
|
|
|
|
|
const auto gradientPointTop = r.height() / 3. * 2.;
|
|
|
|
auto gradient = QLinearGradient(
|
|
|
|
QPointF(0, gradientPointTop),
|
|
|
|
QPointF(r.width(), r.height() - gradientPointTop));
|
|
|
|
gradient.setColorAt(0., st::premiumButtonBg1->c);
|
|
|
|
gradient.setColorAt(.6, st::premiumButtonBg2->c);
|
|
|
|
gradient.setColorAt(1., st::premiumButtonBg3->c);
|
|
|
|
|
|
|
|
PainterHighQualityEnabler hq(p);
|
2022-06-14 09:42:43 +00:00
|
|
|
if (_roundEdges) {
|
|
|
|
const auto radius = st::boxRadius;
|
2022-06-14 12:23:09 +00:00
|
|
|
p.setPen(Qt::NoPen);
|
2022-06-14 09:42:43 +00:00
|
|
|
p.setBrush(gradient);
|
|
|
|
p.drawRoundedRect(
|
|
|
|
r + QMargins{ 0, 0, 0, radius + 1 },
|
|
|
|
radius,
|
|
|
|
radius);
|
|
|
|
} else {
|
|
|
|
p.fillRect(r, gradient);
|
|
|
|
}
|
2022-05-23 04:01:31 +00:00
|
|
|
|
2022-05-29 03:50:29 +00:00
|
|
|
p.setOpacity(_progress.body);
|
|
|
|
p.translate(_starRect.center());
|
|
|
|
p.scale(_progress.body, _progress.body);
|
|
|
|
p.translate(-_starRect.center());
|
|
|
|
if (_progress.top) {
|
|
|
|
_ministars.paint(p, _ministarsRect);
|
|
|
|
}
|
2022-05-24 11:37:05 +00:00
|
|
|
p.resetTransform();
|
|
|
|
|
2022-05-29 03:50:29 +00:00
|
|
|
_star.render(&p, _starRect);
|
2022-05-23 04:01:31 +00:00
|
|
|
|
|
|
|
p.setPen(st::premiumButtonFg);
|
|
|
|
|
2022-05-24 11:37:05 +00:00
|
|
|
const auto titlePathRect = _titlePath.boundingRect();
|
2022-05-23 04:01:31 +00:00
|
|
|
|
|
|
|
// Title.
|
2022-05-24 04:02:32 +00:00
|
|
|
p.setOpacity(1.);
|
2022-05-24 11:37:05 +00:00
|
|
|
p.setFont(_titleFont);
|
2022-05-24 04:02:32 +00:00
|
|
|
const auto fullStarRect = starRect(1., 1.);
|
|
|
|
const auto fullTitleTop = fullStarRect.top()
|
|
|
|
+ fullStarRect.height()
|
2022-05-24 11:37:05 +00:00
|
|
|
+ _titlePadding.top();
|
|
|
|
p.translate(
|
2022-05-24 04:02:32 +00:00
|
|
|
anim::interpolate(
|
2022-05-24 11:37:05 +00:00
|
|
|
(width() - titlePathRect.width()) / 2,
|
2022-05-23 04:01:31 +00:00
|
|
|
_titlePosition.x(),
|
2022-05-29 03:50:29 +00:00
|
|
|
_progress.title),
|
|
|
|
anim::interpolate(fullTitleTop, _titlePosition.y(), _progress.title));
|
2022-05-24 11:37:05 +00:00
|
|
|
|
|
|
|
p.translate(titlePathRect.center());
|
2022-05-29 03:50:29 +00:00
|
|
|
p.scale(_progress.scaleTitle, _progress.scaleTitle);
|
2022-05-24 11:37:05 +00:00
|
|
|
p.translate(-titlePathRect.center());
|
|
|
|
p.fillPath(_titlePath, st::premiumButtonFg);
|
2022-05-23 04:01:31 +00:00
|
|
|
}
|
|
|
|
|
2022-05-18 18:53:25 +00:00
|
|
|
class Premium : public Section<Premium> {
|
|
|
|
public:
|
|
|
|
Premium(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<Window::SessionController*> controller);
|
|
|
|
|
|
|
|
[[nodiscard]] rpl::producer<QString> title() override;
|
|
|
|
|
2022-05-21 03:23:22 +00:00
|
|
|
[[nodiscard]] QPointer<Ui::RpWidget> createPinnedToTop(
|
|
|
|
not_null<QWidget*> parent) override;
|
2022-05-18 18:53:25 +00:00
|
|
|
[[nodiscard]] QPointer<Ui::RpWidget> createPinnedToBottom(
|
|
|
|
not_null<Ui::RpWidget*> parent) override;
|
|
|
|
|
2022-06-12 05:23:23 +00:00
|
|
|
void showFinished() override;
|
|
|
|
|
2022-05-21 03:25:01 +00:00
|
|
|
[[nodiscard]] bool hasFlexibleTopBar() const override;
|
|
|
|
|
2022-05-22 23:06:35 +00:00
|
|
|
void setStepDataReference(std::any &data) override;
|
|
|
|
|
|
|
|
[[nodiscard]] rpl::producer<> sectionShowBack() override final;
|
|
|
|
|
2022-05-18 18:53:25 +00:00
|
|
|
private:
|
2022-05-23 08:04:31 +00:00
|
|
|
void setupContent();
|
|
|
|
|
|
|
|
const not_null<Window::SessionController*> _controller;
|
2022-05-23 14:46:15 +00:00
|
|
|
const QString _ref;
|
2022-05-18 18:53:25 +00:00
|
|
|
|
2022-06-14 09:42:43 +00:00
|
|
|
QPointer<Ui::GradientButton> _subscribe;
|
2022-05-22 23:49:33 +00:00
|
|
|
base::unique_qptr<Ui::FadeWrap<Ui::IconButton>> _back;
|
2022-05-23 00:00:13 +00:00
|
|
|
base::unique_qptr<Ui::IconButton> _close;
|
2022-05-22 23:06:35 +00:00
|
|
|
rpl::variable<bool> _backToggles;
|
2022-05-22 23:49:33 +00:00
|
|
|
rpl::variable<Info::Wrap> _wrap;
|
2022-06-14 09:42:43 +00:00
|
|
|
Fn<void(bool)> _setPaused;
|
2022-05-22 23:06:35 +00:00
|
|
|
|
|
|
|
rpl::event_stream<> _showBack;
|
2022-06-12 05:23:23 +00:00
|
|
|
rpl::event_stream<> _showFinished;
|
2022-05-22 23:06:35 +00:00
|
|
|
|
2022-05-18 18:53:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Premium::Premium(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<Window::SessionController*> controller)
|
2022-05-23 08:04:31 +00:00
|
|
|
: Section(parent)
|
2022-05-23 14:46:15 +00:00
|
|
|
, _controller(controller)
|
|
|
|
, _ref(ResolveRef(controller->premiumRef())) {
|
2022-05-23 08:04:31 +00:00
|
|
|
setupContent();
|
2022-05-31 17:11:59 +00:00
|
|
|
_controller->session().api().premium().reload();
|
2022-05-18 18:53:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<QString> Premium::title() {
|
|
|
|
return tr::lng_premium_summary_title();
|
|
|
|
}
|
|
|
|
|
2022-05-21 03:25:01 +00:00
|
|
|
bool Premium::hasFlexibleTopBar() const {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-05-22 23:06:35 +00:00
|
|
|
rpl::producer<> Premium::sectionShowBack() {
|
|
|
|
return _showBack.events();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Premium::setStepDataReference(std::any &data) {
|
|
|
|
const auto my = std::any_cast<SectionCustomTopBarData>(&data);
|
|
|
|
if (my) {
|
|
|
|
_backToggles = std::move(
|
|
|
|
my->backButtonEnables
|
|
|
|
) | rpl::map_to(true);
|
2022-05-22 23:49:33 +00:00
|
|
|
_wrap = std::move(my->wrapValue);
|
2022-05-22 23:06:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-23 08:04:31 +00:00
|
|
|
void Premium::setupContent() {
|
2022-05-18 18:53:25 +00:00
|
|
|
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
|
|
|
|
|
2022-05-24 09:24:39 +00:00
|
|
|
const auto &stDefault = st::settingsButton;
|
2022-05-18 18:53:25 +00:00
|
|
|
const auto &stLabel = st::defaultFlatLabel;
|
|
|
|
const auto iconSize = st::settingsPremiumIconDouble.size();
|
2022-05-24 09:24:39 +00:00
|
|
|
const auto &titlePadding = st::settingsPremiumRowTitlePadding;
|
|
|
|
const auto &descriptionPadding = st::settingsPremiumRowAboutPadding;
|
2022-05-18 18:53:25 +00:00
|
|
|
|
2022-05-24 09:24:39 +00:00
|
|
|
AddSkip(content, stDefault.padding.top() + titlePadding.top());
|
2022-05-24 03:14:52 +00:00
|
|
|
|
2022-05-23 09:27:32 +00:00
|
|
|
auto entryMap = EntryMap();
|
2022-05-18 18:53:25 +00:00
|
|
|
auto iconContainers = std::vector<Ui::AbstractButton*>();
|
2022-05-23 09:27:32 +00:00
|
|
|
iconContainers.reserve(int(entryMap.size()));
|
2022-05-18 18:53:25 +00:00
|
|
|
|
2022-06-14 03:11:35 +00:00
|
|
|
const auto addRow = [&](Entry &entry) {
|
2022-05-18 18:53:25 +00:00
|
|
|
const auto labelAscent = stLabel.style.font->ascent;
|
2022-06-13 07:36:09 +00:00
|
|
|
const auto button = Ui::CreateChild<Ui::SettingsButton>(
|
|
|
|
content,
|
|
|
|
rpl::single(QString()));
|
2022-05-18 18:53:25 +00:00
|
|
|
|
|
|
|
const auto label = content->add(
|
|
|
|
object_ptr<Ui::FlatLabel>(
|
|
|
|
content,
|
2022-06-14 03:11:35 +00:00
|
|
|
std::move(entry.title) | rpl::map(Ui::Text::Bold),
|
2022-05-18 18:53:25 +00:00
|
|
|
stLabel),
|
|
|
|
titlePadding);
|
2022-06-13 07:36:09 +00:00
|
|
|
label->setAttribute(Qt::WA_TransparentForMouseEvents);
|
|
|
|
const auto description = content->add(
|
2022-05-18 18:53:25 +00:00
|
|
|
object_ptr<Ui::FlatLabel>(
|
|
|
|
content,
|
2022-06-14 03:11:35 +00:00
|
|
|
std::move(entry.description),
|
2022-05-18 18:53:25 +00:00
|
|
|
st::boxDividerLabel),
|
|
|
|
descriptionPadding);
|
2022-06-13 07:36:09 +00:00
|
|
|
description->setAttribute(Qt::WA_TransparentForMouseEvents);
|
2022-05-18 18:53:25 +00:00
|
|
|
|
|
|
|
const auto dummy = Ui::CreateChild<Ui::AbstractButton>(content);
|
|
|
|
dummy->setAttribute(Qt::WA_TransparentForMouseEvents);
|
|
|
|
|
|
|
|
content->sizeValue(
|
|
|
|
) | rpl::start_with_next([=](const QSize &s) {
|
|
|
|
dummy->resize(s.width(), iconSize.height());
|
|
|
|
}, dummy->lifetime());
|
|
|
|
|
|
|
|
label->geometryValue(
|
|
|
|
) | rpl::start_with_next([=](const QRect &r) {
|
|
|
|
dummy->moveToLeft(0, r.y() + (r.height() - labelAscent));
|
|
|
|
}, dummy->lifetime());
|
|
|
|
|
2022-06-13 07:36:09 +00:00
|
|
|
rpl::combine(
|
|
|
|
content->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<Ui::IconButton>(
|
|
|
|
button,
|
|
|
|
st::backButton);
|
|
|
|
arrow->setIconOverride(
|
|
|
|
&st::menuIconSubmenuArrow,
|
|
|
|
&st::menuIconSubmenuArrow);
|
|
|
|
arrow->setAttribute(Qt::WA_TransparentForMouseEvents);
|
|
|
|
button->sizeValue(
|
|
|
|
) | rpl::start_with_next([=](const QSize &s) {
|
|
|
|
arrow->moveToRight(0, (s.height() - arrow->height()) / 2);
|
|
|
|
}, arrow->lifetime());
|
|
|
|
|
2022-06-14 03:11:35 +00:00
|
|
|
const auto section = entry.section;
|
2022-06-13 11:27:20 +00:00
|
|
|
button->setClickedCallback([=, controller = _controller] {
|
2022-06-14 09:42:43 +00:00
|
|
|
_setPaused(true);
|
|
|
|
const auto hidden = crl::guard(this, [=] {
|
|
|
|
_setPaused(false);
|
|
|
|
});
|
|
|
|
|
2022-06-14 03:11:35 +00:00
|
|
|
if (section) {
|
2022-06-14 09:42:43 +00:00
|
|
|
ShowPremiumPreviewToBuy(controller, *section, hidden);
|
2022-06-14 03:11:35 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-06-13 11:27:20 +00:00
|
|
|
controller->show(Box([=](not_null<Ui::GenericBox*> box) {
|
|
|
|
DoubledLimitsPreviewBox(box, &controller->session());
|
2022-06-14 12:40:50 +00:00
|
|
|
|
2022-06-14 12:03:13 +00:00
|
|
|
box->addTopButton(st::boxTitleClose, [=] {
|
|
|
|
box->closeBox();
|
2022-06-14 09:42:43 +00:00
|
|
|
});
|
2022-06-14 12:40:50 +00:00
|
|
|
|
|
|
|
Data::AmPremiumValue(
|
|
|
|
&controller->session()
|
|
|
|
) | rpl::skip(1) | rpl::start_with_next([=] {
|
|
|
|
box->closeBox();
|
|
|
|
}, box->lifetime());
|
|
|
|
|
2022-06-14 12:03:13 +00:00
|
|
|
if (controller->session().premium()) {
|
|
|
|
box->addButton(tr::lng_close(), [=] {
|
|
|
|
box->closeBox();
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
const auto button = CreateSubscribeButton(
|
|
|
|
controller,
|
|
|
|
box,
|
|
|
|
[] { return u"double_limits"_q; });
|
|
|
|
|
|
|
|
box->boxClosing(
|
|
|
|
) | rpl::start_with_next(hidden, box->lifetime());
|
|
|
|
|
|
|
|
box->setShowFinishedCallback([=] {
|
|
|
|
button->startGlareAnimation();
|
|
|
|
});
|
|
|
|
|
|
|
|
box->setStyle(st::premiumPreviewDoubledLimitsBox);
|
|
|
|
box->widthValue(
|
|
|
|
) | rpl::start_with_next([=](int width) {
|
|
|
|
const auto &padding =
|
|
|
|
st::premiumPreviewDoubledLimitsBox.buttonPadding;
|
|
|
|
button->resizeToWidth(width
|
|
|
|
- padding.left()
|
|
|
|
- padding.right());
|
|
|
|
button->moveToLeft(padding.left(), padding.top());
|
|
|
|
}, button->lifetime());
|
|
|
|
box->addButton(
|
|
|
|
object_ptr<Ui::AbstractButton>::fromRaw(button));
|
|
|
|
}
|
2022-06-13 11:27:20 +00:00
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
2022-05-18 18:53:25 +00:00
|
|
|
iconContainers.push_back(dummy);
|
|
|
|
};
|
|
|
|
|
2022-05-23 09:27:32 +00:00
|
|
|
auto icons = std::vector<const style::icon *>();
|
|
|
|
icons.reserve(int(entryMap.size()));
|
|
|
|
{
|
|
|
|
const auto &account = _controller->session().account();
|
|
|
|
const auto mtpOrder = account.appConfig().get<Order>(
|
|
|
|
"premium_promo_order",
|
2022-05-24 09:24:39 +00:00
|
|
|
FallbackOrder());
|
2022-05-23 09:27:32 +00:00
|
|
|
const auto processEntry = [&](Entry &entry) {
|
|
|
|
icons.push_back(entry.icon);
|
2022-06-14 03:11:35 +00:00
|
|
|
addRow(entry);
|
2022-05-23 09:27:32 +00:00
|
|
|
};
|
|
|
|
|
2022-05-24 09:24:39 +00:00
|
|
|
for (const auto &key : mtpOrder) {
|
|
|
|
auto it = entryMap.find(key);
|
|
|
|
if (it == end(entryMap)) {
|
|
|
|
continue;
|
2022-05-23 09:27:32 +00:00
|
|
|
}
|
2022-05-24 09:24:39 +00:00
|
|
|
processEntry(it->second);
|
2022-05-23 09:27:32 +00:00
|
|
|
}
|
2022-05-23 14:46:15 +00:00
|
|
|
|
|
|
|
SendScreenShow(_controller, mtpOrder, _ref);
|
2022-05-23 09:27:32 +00:00
|
|
|
}
|
2022-05-18 18:53:25 +00:00
|
|
|
|
|
|
|
content->resizeToWidth(content->height());
|
|
|
|
|
|
|
|
// Icons.
|
|
|
|
Assert(iconContainers.size() > 2);
|
|
|
|
const auto from = iconContainers.front()->y();
|
|
|
|
const auto to = iconContainers.back()->y() + iconSize.height();
|
|
|
|
auto gradient = QLinearGradient(0, 0, 0, to - from);
|
2022-06-13 11:27:20 +00:00
|
|
|
gradient.setStops(Ui::Premium::FullHeightGradientStops());
|
2022-05-18 18:53:25 +00:00
|
|
|
for (auto i = 0; i < int(icons.size()); i++) {
|
|
|
|
const auto &iconContainer = iconContainers[i];
|
|
|
|
|
|
|
|
const auto pointTop = iconContainer->y() - from;
|
|
|
|
const auto pointBottom = pointTop + iconContainer->height();
|
|
|
|
const auto ratioTop = pointTop / float64(to - from);
|
|
|
|
const auto ratioBottom = pointBottom / float64(to - from);
|
|
|
|
|
|
|
|
auto resultGradient = QLinearGradient(
|
|
|
|
QPointF(),
|
|
|
|
QPointF(0, pointBottom - pointTop));
|
|
|
|
|
|
|
|
resultGradient.setColorAt(
|
|
|
|
.0,
|
|
|
|
anim::gradient_color_at(gradient, ratioTop));
|
|
|
|
resultGradient.setColorAt(
|
|
|
|
.1,
|
|
|
|
anim::gradient_color_at(gradient, ratioBottom));
|
|
|
|
|
|
|
|
const auto brush = QBrush(resultGradient);
|
|
|
|
AddButtonIcon(
|
|
|
|
iconContainer,
|
2022-05-24 09:24:39 +00:00
|
|
|
stDefault,
|
2022-05-18 18:53:25 +00:00
|
|
|
{ .icon = icons[i], .backgroundBrush = brush });
|
|
|
|
}
|
|
|
|
|
2022-05-24 09:24:39 +00:00
|
|
|
AddSkip(content, descriptionPadding.bottom());
|
2022-05-29 03:54:47 +00:00
|
|
|
#if 0
|
2022-05-18 18:53:25 +00:00
|
|
|
AddSkip(content);
|
|
|
|
AddDivider(content);
|
|
|
|
AddSkip(content);
|
|
|
|
|
|
|
|
content->add(
|
|
|
|
object_ptr<Ui::FlatLabel>(
|
|
|
|
content,
|
|
|
|
tr::lng_premium_summary_bottom_subtitle(
|
|
|
|
) | rpl::map(Ui::Text::Bold),
|
|
|
|
stLabel),
|
|
|
|
st::settingsSubsectionTitlePadding);
|
|
|
|
content->add(
|
|
|
|
object_ptr<Ui::FlatLabel>(
|
|
|
|
content,
|
|
|
|
tr::lng_premium_summary_bottom_about(Ui::Text::RichLangValue),
|
|
|
|
st::aboutLabel),
|
|
|
|
st::boxRowPadding);
|
2022-05-24 09:24:39 +00:00
|
|
|
AddSkip(content, stDefault.padding.top() + stDefault.padding.bottom());
|
2022-05-29 03:54:47 +00:00
|
|
|
#endif
|
2022-05-18 18:53:25 +00:00
|
|
|
|
|
|
|
Ui::ResizeFitChild(this, content);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-05-21 03:23:22 +00:00
|
|
|
QPointer<Ui::RpWidget> Premium::createPinnedToTop(
|
|
|
|
not_null<QWidget*> parent) {
|
2022-06-13 09:27:38 +00:00
|
|
|
auto title = _controller->session().premium()
|
|
|
|
? tr::lng_premium_summary_title()
|
|
|
|
: rpl::conditional(
|
|
|
|
Data::AmPremiumValue(&_controller->session()),
|
|
|
|
tr::lng_premium_summary_title_subscribed(),
|
|
|
|
tr::lng_premium_summary_title());
|
|
|
|
auto about = rpl::conditional(
|
|
|
|
Data::AmPremiumValue(&_controller->session()),
|
|
|
|
_controller->session().api().premium().statusTextValue(),
|
|
|
|
tr::lng_premium_summary_top_about(Ui::Text::RichLangValue));
|
|
|
|
|
2022-05-30 23:37:15 +00:00
|
|
|
const auto content = Ui::CreateChild<TopBar>(
|
|
|
|
parent.get(),
|
2022-06-13 09:27:38 +00:00
|
|
|
_controller,
|
|
|
|
std::move(title),
|
|
|
|
std::move(about));
|
2022-06-14 09:42:43 +00:00
|
|
|
_setPaused = [=](bool paused) {
|
|
|
|
content->setPaused(paused);
|
|
|
|
_subscribe->setGlarePaused(paused);
|
|
|
|
};
|
2022-05-23 04:01:31 +00:00
|
|
|
|
|
|
|
_wrap.value(
|
|
|
|
) | rpl::start_with_next([=](Info::Wrap wrap) {
|
|
|
|
content->setRoundEdges(wrap == Info::Wrap::Layer);
|
2022-05-21 03:23:22 +00:00
|
|
|
}, content->lifetime());
|
|
|
|
|
2022-05-23 04:01:31 +00:00
|
|
|
content->setMaximumHeight(st::introQrStepsTop);
|
|
|
|
content->setMinimumHeight(st::infoLayerTopBarHeight);
|
|
|
|
|
|
|
|
content->resize(content->width(), content->maximumHeight());
|
2022-05-21 03:23:22 +00:00
|
|
|
|
2022-05-22 23:49:33 +00:00
|
|
|
_wrap.value(
|
|
|
|
) | rpl::start_with_next([=](Info::Wrap wrap) {
|
2022-05-23 00:00:13 +00:00
|
|
|
const auto isLayer = (wrap == Info::Wrap::Layer);
|
2022-05-22 23:49:33 +00:00
|
|
|
_back = base::make_unique_q<Ui::FadeWrap<Ui::IconButton>>(
|
|
|
|
content,
|
|
|
|
object_ptr<Ui::IconButton>(
|
|
|
|
content,
|
2022-05-23 00:00:13 +00:00
|
|
|
isLayer
|
2022-05-22 23:49:33 +00:00
|
|
|
? st::settingsPremiumLayerTopBarBack
|
|
|
|
: st::settingsPremiumTopBarBack),
|
|
|
|
st::infoTopBarScale);
|
|
|
|
_back->setDuration(0);
|
|
|
|
_back->toggleOn(_backToggles.value());
|
|
|
|
_back->entity()->addClickHandler([=] {
|
|
|
|
_showBack.fire({});
|
|
|
|
});
|
2022-05-23 04:01:31 +00:00
|
|
|
_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());
|
2022-05-23 00:00:13 +00:00
|
|
|
|
|
|
|
if (!isLayer) {
|
|
|
|
_close = nullptr;
|
|
|
|
} else {
|
|
|
|
_close = base::make_unique_q<Ui::IconButton>(
|
|
|
|
content,
|
|
|
|
st::settingsPremiumTopBarClose);
|
|
|
|
_close->addClickHandler([=] {
|
|
|
|
_controller->parentController()->hideLayer();
|
|
|
|
_controller->parentController()->hideSpecialLayer();
|
|
|
|
});
|
|
|
|
content->widthValue(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
_close->moveToRight(0, 0);
|
|
|
|
}, _close->lifetime());
|
|
|
|
}
|
2022-05-23 04:01:31 +00:00
|
|
|
}, content->lifetime());
|
2022-05-22 23:06:35 +00:00
|
|
|
|
2022-05-23 04:01:31 +00:00
|
|
|
return Ui::MakeWeak(not_null<Ui::RpWidget*>{ content });
|
2022-05-21 03:23:22 +00:00
|
|
|
}
|
|
|
|
|
2022-06-12 05:23:23 +00:00
|
|
|
void Premium::showFinished() {
|
|
|
|
_showFinished.fire({});
|
|
|
|
}
|
|
|
|
|
2022-05-18 18:53:25 +00:00
|
|
|
QPointer<Ui::RpWidget> Premium::createPinnedToBottom(
|
|
|
|
not_null<Ui::RpWidget*> parent) {
|
2022-05-31 17:11:44 +00:00
|
|
|
const auto content = Ui::CreateChild<Ui::RpWidget>(parent.get());
|
2022-05-18 18:53:25 +00:00
|
|
|
|
2022-06-14 09:42:43 +00:00
|
|
|
_subscribe = CreateSubscribeButton(_controller, content, [=] {
|
|
|
|
return _ref;
|
2022-05-23 08:04:31 +00:00
|
|
|
});
|
2022-06-13 09:27:38 +00:00
|
|
|
|
2022-06-12 05:23:23 +00:00
|
|
|
_showFinished.events(
|
|
|
|
) | rpl::take(1) | rpl::start_with_next([=] {
|
2022-06-14 09:42:43 +00:00
|
|
|
_subscribe->startGlareAnimation();
|
|
|
|
}, _subscribe->lifetime());
|
2022-06-13 09:27:38 +00:00
|
|
|
|
2022-05-31 17:11:44 +00:00
|
|
|
content->widthValue(
|
|
|
|
) | rpl::start_with_next([=](int width) {
|
2022-06-07 12:58:14 +00:00
|
|
|
const auto padding = st::settingsPremiumButtonPadding;
|
2022-06-14 09:42:43 +00:00
|
|
|
_subscribe->resizeToWidth(width - padding.left() - padding.right());
|
|
|
|
}, _subscribe->lifetime());
|
2022-06-08 13:19:39 +00:00
|
|
|
|
2022-06-07 07:41:44 +00:00
|
|
|
const auto session = &_controller->session();
|
2022-05-31 17:11:44 +00:00
|
|
|
rpl::combine(
|
2022-06-14 09:42:43 +00:00
|
|
|
_subscribe->heightValue(),
|
2022-06-07 07:41:44 +00:00
|
|
|
Data::AmPremiumValue(session),
|
2022-06-08 12:53:16 +00:00
|
|
|
session->premiumPossibleValue()
|
2022-05-31 17:11:59 +00:00
|
|
|
) | rpl::start_with_next([=](
|
|
|
|
int buttonHeight,
|
2022-06-07 07:41:44 +00:00
|
|
|
bool premium,
|
|
|
|
bool premiumPossible) {
|
2022-05-31 17:11:44 +00:00
|
|
|
const auto padding = st::settingsPremiumButtonPadding;
|
2022-06-07 07:41:44 +00:00
|
|
|
const auto finalHeight = !premiumPossible
|
|
|
|
? 0
|
|
|
|
: !premium
|
2022-06-12 12:51:55 +00:00
|
|
|
? (padding.top() + buttonHeight + padding.bottom())
|
2022-06-13 09:27:38 +00:00
|
|
|
: 0;
|
2022-05-31 17:11:44 +00:00
|
|
|
content->resize(content->width(), finalHeight);
|
2022-06-14 09:42:43 +00:00
|
|
|
_subscribe->moveToLeft(padding.left(), padding.top());
|
|
|
|
_subscribe->setVisible(!premium && premiumPossible);
|
|
|
|
}, _subscribe->lifetime());
|
2022-05-18 18:53:25 +00:00
|
|
|
|
|
|
|
return Ui::MakeWeak(not_null<Ui::RpWidget*>{ content });
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
Type PremiumId() {
|
|
|
|
return Premium::Id();
|
|
|
|
}
|
|
|
|
|
2022-05-23 14:46:15 +00:00
|
|
|
void ShowPremium(not_null<Main::Session*> session, const QString &ref) {
|
2022-05-20 13:12:56 +00:00
|
|
|
const auto active = Core::App().activeWindow();
|
|
|
|
const auto controller = (active && active->isPrimary())
|
|
|
|
? active->sessionController()
|
|
|
|
: nullptr;
|
|
|
|
if (controller && session == &controller->session()) {
|
2022-05-23 14:46:15 +00:00
|
|
|
ShowPremium(controller, ref);
|
2022-05-20 13:12:56 +00:00
|
|
|
} else {
|
|
|
|
for (const auto &controller : session->windows()) {
|
|
|
|
if (controller->window().isPrimary()) {
|
2022-05-23 14:46:15 +00:00
|
|
|
ShowPremium(controller, ref);
|
2022-05-20 13:12:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-23 14:46:15 +00:00
|
|
|
void ShowPremium(
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
const QString &ref) {
|
2022-06-08 07:26:53 +00:00
|
|
|
if (!controller->session().premiumPossible()) {
|
|
|
|
controller->show(Box(PremiumUnavailableBox));
|
|
|
|
return;
|
|
|
|
}
|
2022-05-23 14:46:15 +00:00
|
|
|
controller->setPremiumRef(ref);
|
|
|
|
controller->showSettings(Settings::PremiumId());
|
|
|
|
}
|
|
|
|
|
2022-05-23 08:04:31 +00:00
|
|
|
void StartPremiumPayment(
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
const QString &ref) {
|
|
|
|
const auto account = &controller->session().account();
|
|
|
|
const auto username = account->appConfig().get<QString>(
|
|
|
|
"premium_bot_username",
|
|
|
|
QString());
|
|
|
|
const auto slug = account->appConfig().get<QString>(
|
|
|
|
"premium_invoice_slug",
|
|
|
|
QString());
|
|
|
|
if (!username.isEmpty()) {
|
2022-05-23 11:45:22 +00:00
|
|
|
controller->showPeerByLink(Window::SessionNavigation::PeerByLinkInfo{
|
|
|
|
.usernameOrId = username,
|
|
|
|
.resolveType = Window::ResolveType::BotStart,
|
|
|
|
.startToken = ref,
|
|
|
|
.startAutoSubmit = true,
|
|
|
|
});
|
2022-05-23 08:04:31 +00:00
|
|
|
} else if (!slug.isEmpty()) {
|
|
|
|
UrlClickHandler::Open("https://t.me/$" + slug);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-14 09:42:43 +00:00
|
|
|
QString LookupPremiumRef(PremiumPreview section) {
|
|
|
|
for (const auto &[ref, entry] : EntryMap()) {
|
|
|
|
if (entry.section == section) {
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
not_null<Ui::GradientButton*> CreateSubscribeButton(
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
not_null<Ui::RpWidget*> parent,
|
|
|
|
Fn<QString()> computeRef) {
|
|
|
|
const auto result = Ui::CreateChild<Ui::GradientButton>(
|
|
|
|
parent.get(),
|
|
|
|
Ui::Premium::ButtonGradientStops());
|
|
|
|
|
|
|
|
result->setClickedCallback([=] {
|
|
|
|
SendScreenAccept(controller);
|
|
|
|
StartPremiumPayment(controller, computeRef());
|
|
|
|
});
|
|
|
|
|
|
|
|
const auto &st = st::premiumPreviewBox.button;
|
|
|
|
result->resize(parent->width(), st.height);
|
|
|
|
|
|
|
|
const auto premium = &controller->session().api().premium();
|
|
|
|
premium->reload();
|
|
|
|
const auto computeCost = [=] {
|
|
|
|
const auto amount = premium->monthlyAmount();
|
|
|
|
const auto currency = premium->monthlyCurrency();
|
|
|
|
const auto valid = (amount > 0) && !currency.isEmpty();
|
|
|
|
return Ui::FillAmountAndCurrency(
|
|
|
|
valid ? amount : 500,
|
|
|
|
valid ? currency : "USD");
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto label = Ui::CreateChild<Ui::FlatLabel>(
|
|
|
|
result,
|
|
|
|
tr::lng_premium_summary_button(
|
|
|
|
lt_cost,
|
|
|
|
premium->statusTextValue() | rpl::map(computeCost)),
|
|
|
|
st::premiumPreviewButtonLabel);
|
|
|
|
label->setAttribute(Qt::WA_TransparentForMouseEvents);
|
|
|
|
rpl::combine(
|
|
|
|
result->widthValue(),
|
|
|
|
label->widthValue()
|
|
|
|
) | rpl::start_with_next([=](int outer, int width) {
|
|
|
|
label->moveToLeft(
|
|
|
|
(outer - width) / 2,
|
|
|
|
st::premiumPreviewBox.button.textTop,
|
|
|
|
outer);
|
|
|
|
}, label->lifetime());
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2022-05-18 18:53:25 +00:00
|
|
|
} // namespace Settings
|