2022-05-17 00:04:44 +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 "ui/effects/premium_graphics.h"
|
|
|
|
|
|
|
|
#include "lang/lang_keys.h"
|
2022-07-05 19:29:46 +00:00
|
|
|
#include "ui/abstract_button.h"
|
2022-05-17 00:04:44 +00:00
|
|
|
#include "ui/effects/animations.h"
|
|
|
|
#include "ui/effects/gradient.h"
|
|
|
|
#include "ui/effects/numbers_animation.h"
|
2022-06-13 11:27:20 +00:00
|
|
|
#include "ui/text/text_utilities.h"
|
|
|
|
#include "ui/layers/generic_box.h"
|
2022-05-31 10:32:07 +00:00
|
|
|
#include "ui/text/text_options.h"
|
|
|
|
#include "ui/widgets/checkbox.h"
|
2022-05-17 00:04:44 +00:00
|
|
|
#include "ui/wrap/padding_wrap.h"
|
|
|
|
#include "ui/wrap/vertical_layout.h"
|
2022-07-05 19:04:43 +00:00
|
|
|
#include "styles/style_premium.h"
|
2022-05-17 00:04:44 +00:00
|
|
|
#include "styles/style_boxes.h"
|
2022-06-13 11:27:20 +00:00
|
|
|
#include "styles/style_settings.h"
|
2022-05-18 04:28:35 +00:00
|
|
|
#include "styles/style_layers.h"
|
2022-05-17 00:04:44 +00:00
|
|
|
#include "styles/style_widgets.h"
|
2022-07-05 19:29:46 +00:00
|
|
|
#include "styles/style_window.h"
|
2022-05-17 00:04:44 +00:00
|
|
|
|
2022-05-31 10:32:07 +00:00
|
|
|
#include <QtGui/QBrush>
|
|
|
|
|
2022-05-17 00:04:44 +00:00
|
|
|
namespace Ui {
|
|
|
|
namespace Premium {
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
using TextFactory = Fn<QString(int)>;
|
|
|
|
|
2022-05-31 10:32:07 +00:00
|
|
|
constexpr auto kBubbleRadiusSubtractor = 2;
|
2022-05-24 04:20:22 +00:00
|
|
|
constexpr auto kDeflectionSmall = 20.;
|
2022-05-17 00:04:44 +00:00
|
|
|
constexpr auto kDeflection = 30.;
|
|
|
|
|
|
|
|
constexpr auto kStepBeforeDeflection = 0.75;
|
|
|
|
constexpr auto kStepAfterDeflection = kStepBeforeDeflection
|
|
|
|
+ (1. - kStepBeforeDeflection) / 2.;
|
|
|
|
|
2022-05-24 04:20:22 +00:00
|
|
|
[[nodiscard]] TextFactory ProcessTextFactory(
|
|
|
|
std::optional<tr::phrase<lngtag_count>> phrase) {
|
|
|
|
return phrase
|
|
|
|
? TextFactory([=](int n) { return (*phrase)(tr::now, lt_count, n); })
|
|
|
|
: TextFactory([=](int n) { return QString::number(n); });
|
|
|
|
}
|
|
|
|
|
2022-05-17 00:04:44 +00:00
|
|
|
[[nodiscard]] QLinearGradient ComputeGradient(
|
|
|
|
not_null<QWidget*> content,
|
|
|
|
int left,
|
|
|
|
int width) {
|
|
|
|
|
|
|
|
// Take a full width of parent box without paddings.
|
|
|
|
const auto fullGradientWidth = content->parentWidget()->width();
|
|
|
|
auto fullGradient = QLinearGradient(0, 0, fullGradientWidth, 0);
|
2022-05-20 14:57:01 +00:00
|
|
|
fullGradient.setStops(ButtonGradientStops());
|
2022-05-17 00:04:44 +00:00
|
|
|
|
|
|
|
auto gradient = QLinearGradient(0, 0, width, 0);
|
|
|
|
const auto fullFinal = float64(fullGradient.finalStop().x());
|
|
|
|
left += ((fullGradientWidth - content->width()) / 2);
|
|
|
|
gradient.setColorAt(
|
|
|
|
.0,
|
|
|
|
anim::gradient_color_at(fullGradient, left / fullFinal));
|
|
|
|
gradient.setColorAt(
|
|
|
|
1.,
|
|
|
|
anim::gradient_color_at(fullGradient, (left + width) / fullFinal));
|
|
|
|
|
|
|
|
return gradient;
|
|
|
|
}
|
|
|
|
|
2022-07-05 21:41:05 +00:00
|
|
|
class PartialGradient final {
|
|
|
|
public:
|
|
|
|
PartialGradient(int from, int to, QGradientStops stops);
|
|
|
|
|
|
|
|
[[nodiscard]] QLinearGradient compute(int position, int size) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
const int _from;
|
|
|
|
const int _to;
|
|
|
|
QLinearGradient _gradient;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
PartialGradient::PartialGradient(int from, int to, QGradientStops stops)
|
|
|
|
: _from(from)
|
|
|
|
, _to(to)
|
|
|
|
, _gradient(0, 0, 0, to - from) {
|
|
|
|
_gradient.setStops(std::move(stops));
|
|
|
|
}
|
|
|
|
|
|
|
|
QLinearGradient PartialGradient::compute(int position, int size) const {
|
|
|
|
const auto pointTop = position - _from;
|
|
|
|
const auto pointBottom = pointTop + size;
|
|
|
|
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));
|
|
|
|
return resultGradient;
|
|
|
|
}
|
|
|
|
|
2022-05-17 00:04:44 +00:00
|
|
|
class Bubble final {
|
|
|
|
public:
|
2022-05-28 03:50:40 +00:00
|
|
|
using EdgeProgress = float64;
|
|
|
|
|
2022-05-17 00:04:44 +00:00
|
|
|
Bubble(
|
|
|
|
Fn<void()> updateCallback,
|
|
|
|
TextFactory textFactory,
|
2022-06-07 05:48:33 +00:00
|
|
|
const style::icon *icon,
|
|
|
|
bool premiumPossible);
|
2022-05-17 00:04:44 +00:00
|
|
|
|
|
|
|
[[nodiscard]] int counter() const;
|
|
|
|
[[nodiscard]] int height() const;
|
|
|
|
[[nodiscard]] int width() const;
|
|
|
|
[[nodiscard]] int bubbleRadius() const;
|
2022-05-28 03:50:40 +00:00
|
|
|
[[nodiscard]] int countMaxWidth(int maxCounter) const;
|
2022-05-17 00:04:44 +00:00
|
|
|
|
|
|
|
void setCounter(int value);
|
2022-05-28 03:50:40 +00:00
|
|
|
void setTailEdge(EdgeProgress edge);
|
2022-05-17 00:04:44 +00:00
|
|
|
void paintBubble(Painter &p, const QRect &r, const QBrush &brush);
|
|
|
|
|
|
|
|
[[nodiscard]] rpl::producer<> widthChanges() const;
|
|
|
|
|
|
|
|
private:
|
2022-05-28 03:50:40 +00:00
|
|
|
[[nodiscard]] int filledWidth() const;
|
|
|
|
|
2022-05-17 00:04:44 +00:00
|
|
|
const Fn<void()> _updateCallback;
|
|
|
|
const TextFactory _textFactory;
|
|
|
|
|
|
|
|
const style::font &_font;
|
|
|
|
const style::margins &_padding;
|
|
|
|
const style::icon *_icon;
|
|
|
|
NumbersAnimation _numberAnimation;
|
|
|
|
const QSize _tailSize;
|
|
|
|
const int _height;
|
|
|
|
const int _textTop;
|
2022-06-07 05:48:33 +00:00
|
|
|
const bool _premiumPossible;
|
2022-05-17 00:04:44 +00:00
|
|
|
|
|
|
|
int _counter = -1;
|
2022-05-28 03:50:40 +00:00
|
|
|
EdgeProgress _tailEdge = 0.;
|
2022-05-17 00:04:44 +00:00
|
|
|
|
|
|
|
rpl::event_stream<> _widthChanges;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
Bubble::Bubble(
|
|
|
|
Fn<void()> updateCallback,
|
|
|
|
TextFactory textFactory,
|
2022-06-07 05:48:33 +00:00
|
|
|
const style::icon *icon,
|
|
|
|
bool premiumPossible)
|
2022-05-17 00:04:44 +00:00
|
|
|
: _updateCallback(std::move(updateCallback))
|
|
|
|
, _textFactory(std::move(textFactory))
|
|
|
|
, _font(st::premiumBubbleFont)
|
|
|
|
, _padding(st::premiumBubblePadding)
|
|
|
|
, _icon(icon)
|
|
|
|
, _numberAnimation(_font, _updateCallback)
|
|
|
|
, _tailSize(st::premiumBubbleTailSize)
|
|
|
|
, _height(st::premiumBubbleHeight + _tailSize.height())
|
2022-06-07 05:48:33 +00:00
|
|
|
, _textTop((_height - _tailSize.height() - _font->height) / 2)
|
|
|
|
, _premiumPossible(premiumPossible) {
|
2022-05-24 04:20:22 +00:00
|
|
|
_numberAnimation.setDisabledMonospace(true);
|
2022-05-17 00:04:44 +00:00
|
|
|
_numberAnimation.setWidthChangedCallback([=] {
|
|
|
|
_widthChanges.fire({});
|
|
|
|
});
|
2022-05-28 03:50:40 +00:00
|
|
|
_numberAnimation.setText(_textFactory(0), 0);
|
|
|
|
_numberAnimation.finishAnimating();
|
2022-05-17 00:04:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int Bubble::counter() const {
|
|
|
|
return _counter;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Bubble::height() const {
|
|
|
|
return _height;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Bubble::bubbleRadius() const {
|
2022-05-31 10:32:07 +00:00
|
|
|
return (_height - _tailSize.height()) / 2 - kBubbleRadiusSubtractor;
|
2022-05-17 00:04:44 +00:00
|
|
|
}
|
|
|
|
|
2022-05-28 03:50:40 +00:00
|
|
|
int Bubble::filledWidth() const {
|
2022-05-17 00:04:44 +00:00
|
|
|
return _padding.left()
|
|
|
|
+ _icon->width()
|
|
|
|
+ st::premiumBubbleTextSkip
|
|
|
|
+ _padding.right();
|
|
|
|
}
|
|
|
|
|
2022-05-28 03:50:40 +00:00
|
|
|
int Bubble::width() const {
|
|
|
|
return filledWidth() + _numberAnimation.countWidth();
|
|
|
|
}
|
|
|
|
|
|
|
|
int Bubble::countMaxWidth(int maxCounter) const {
|
|
|
|
auto numbers = Ui::NumbersAnimation(_font, [] {});
|
|
|
|
numbers.setDisabledMonospace(true);
|
|
|
|
numbers.setDuration(0);
|
|
|
|
numbers.setText(_textFactory(0), 0);
|
|
|
|
numbers.setText(_textFactory(maxCounter), maxCounter);
|
|
|
|
numbers.finishAnimating();
|
|
|
|
return filledWidth() + numbers.maxWidth();
|
|
|
|
}
|
|
|
|
|
2022-05-17 00:04:44 +00:00
|
|
|
void Bubble::setCounter(int value) {
|
|
|
|
if (_counter != value) {
|
|
|
|
_counter = value;
|
|
|
|
_numberAnimation.setText(_textFactory(_counter), _counter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-28 03:50:40 +00:00
|
|
|
void Bubble::setTailEdge(EdgeProgress edge) {
|
|
|
|
_tailEdge = std::clamp(edge, 0., 1.);
|
2022-05-17 00:04:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Bubble::paintBubble(Painter &p, const QRect &r, const QBrush &brush) {
|
|
|
|
if (_counter < 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-05-28 03:50:40 +00:00
|
|
|
const auto penWidth = st::premiumBubblePenWidth;
|
|
|
|
const auto penWidthHalf = penWidth / 2;
|
|
|
|
const auto bubbleRect = r - style::margins(
|
|
|
|
penWidthHalf,
|
|
|
|
penWidthHalf,
|
|
|
|
penWidthHalf,
|
|
|
|
_tailSize.height() + penWidthHalf);
|
2022-05-17 00:04:44 +00:00
|
|
|
{
|
|
|
|
const auto radius = bubbleRadius();
|
|
|
|
auto pathTail = QPainterPath();
|
|
|
|
|
2022-05-28 03:50:40 +00:00
|
|
|
const auto tailWHalf = _tailSize.width() / 2.;
|
|
|
|
const auto progress = _tailEdge;
|
|
|
|
|
|
|
|
const auto tailTop = bubbleRect.y() + bubbleRect.height();
|
|
|
|
const auto tailLeftFull = bubbleRect.x()
|
|
|
|
+ (bubbleRect.width() * 0.5)
|
|
|
|
- tailWHalf;
|
|
|
|
const auto tailLeft = bubbleRect.x()
|
|
|
|
+ (bubbleRect.width() * 0.5 * (progress + 1.))
|
|
|
|
- tailWHalf;
|
|
|
|
const auto tailCenter = tailLeft + tailWHalf;
|
|
|
|
const auto tailRight = [&] {
|
|
|
|
const auto max = bubbleRect.x() + bubbleRect.width();
|
|
|
|
const auto right = tailLeft + _tailSize.width();
|
|
|
|
const auto bottomMax = max - radius;
|
|
|
|
return (right > bottomMax)
|
|
|
|
? std::max(float64(tailCenter), float64(bottomMax))
|
|
|
|
: right;
|
|
|
|
}();
|
2022-06-07 05:48:33 +00:00
|
|
|
if (_premiumPossible) {
|
|
|
|
pathTail.moveTo(tailLeftFull, tailTop);
|
|
|
|
pathTail.lineTo(tailLeft, tailTop);
|
|
|
|
pathTail.lineTo(tailCenter, tailTop + _tailSize.height());
|
|
|
|
pathTail.lineTo(tailRight, tailTop);
|
|
|
|
pathTail.lineTo(tailRight, tailTop - radius);
|
|
|
|
pathTail.moveTo(tailLeftFull, tailTop);
|
|
|
|
}
|
2022-05-17 00:04:44 +00:00
|
|
|
auto pathBubble = QPainterPath();
|
|
|
|
pathBubble.setFillRule(Qt::WindingFill);
|
|
|
|
pathBubble.addRoundedRect(bubbleRect, radius, radius);
|
|
|
|
|
2022-05-28 03:50:40 +00:00
|
|
|
PainterHighQualityEnabler hq(p);
|
|
|
|
p.setPen(QPen(
|
|
|
|
brush,
|
|
|
|
penWidth,
|
|
|
|
Qt::SolidLine,
|
|
|
|
Qt::RoundCap,
|
|
|
|
Qt::RoundJoin));
|
|
|
|
p.setBrush(brush);
|
|
|
|
p.drawPath(pathTail + pathBubble);
|
2022-05-17 00:04:44 +00:00
|
|
|
}
|
|
|
|
p.setPen(st::activeButtonFg);
|
|
|
|
p.setFont(_font);
|
|
|
|
const auto iconLeft = r.x() + _padding.left();
|
|
|
|
_icon->paint(
|
|
|
|
p,
|
|
|
|
iconLeft,
|
2022-05-28 03:50:40 +00:00
|
|
|
bubbleRect.y() + (bubbleRect.height() - _icon->height()) / 2,
|
|
|
|
bubbleRect.width());
|
2022-05-17 00:04:44 +00:00
|
|
|
_numberAnimation.paint(
|
|
|
|
p,
|
|
|
|
iconLeft + _icon->width() + st::premiumBubbleTextSkip,
|
|
|
|
r.y() + _textTop,
|
|
|
|
width() / 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<> Bubble::widthChanges() const {
|
|
|
|
return _widthChanges.events();
|
|
|
|
}
|
|
|
|
|
|
|
|
class BubbleWidget final : public Ui::RpWidget {
|
|
|
|
public:
|
|
|
|
BubbleWidget(
|
|
|
|
not_null<Ui::RpWidget*> parent,
|
|
|
|
TextFactory textFactory,
|
|
|
|
int current,
|
|
|
|
int maxCounter,
|
2022-06-07 05:48:33 +00:00
|
|
|
bool premiumPossible,
|
2022-05-17 00:04:44 +00:00
|
|
|
rpl::producer<> showFinishes,
|
|
|
|
const style::icon *icon);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
const int _currentCounter;
|
|
|
|
const int _maxCounter;
|
|
|
|
Bubble _bubble;
|
2022-05-28 03:50:40 +00:00
|
|
|
const int _maxBubbleWidth;
|
2022-06-07 05:48:33 +00:00
|
|
|
const bool _premiumPossible;
|
2022-05-17 00:04:44 +00:00
|
|
|
|
|
|
|
Ui::Animations::Simple _appearanceAnimation;
|
|
|
|
QSize _spaceForDeflection;
|
|
|
|
|
|
|
|
QLinearGradient _cachedGradient;
|
|
|
|
|
2022-05-24 04:20:22 +00:00
|
|
|
float64 _deflection;
|
|
|
|
|
2022-05-28 03:50:40 +00:00
|
|
|
bool _ignoreDeflection = false;
|
|
|
|
float64 _stepBeforeDeflection;
|
|
|
|
float64 _stepAfterDeflection;
|
|
|
|
|
2022-05-17 00:04:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
BubbleWidget::BubbleWidget(
|
|
|
|
not_null<Ui::RpWidget*> parent,
|
|
|
|
TextFactory textFactory,
|
|
|
|
int current,
|
|
|
|
int maxCounter,
|
2022-06-07 05:48:33 +00:00
|
|
|
bool premiumPossible,
|
2022-05-17 00:04:44 +00:00
|
|
|
rpl::producer<> showFinishes,
|
|
|
|
const style::icon *icon)
|
|
|
|
: RpWidget(parent)
|
|
|
|
, _currentCounter(current)
|
|
|
|
, _maxCounter(maxCounter)
|
2022-06-07 05:48:33 +00:00
|
|
|
, _bubble([=] { update(); }, std::move(textFactory), icon, premiumPossible)
|
2022-05-28 03:50:40 +00:00
|
|
|
, _maxBubbleWidth(_bubble.countMaxWidth(_maxCounter))
|
2022-06-07 05:48:33 +00:00
|
|
|
, _premiumPossible(premiumPossible)
|
2022-05-28 03:50:40 +00:00
|
|
|
, _deflection(kDeflection)
|
|
|
|
, _stepBeforeDeflection(kStepBeforeDeflection)
|
|
|
|
, _stepAfterDeflection(kStepAfterDeflection) {
|
2022-05-17 00:04:44 +00:00
|
|
|
const auto resizeTo = [=](int w, int h) {
|
2022-05-24 04:20:22 +00:00
|
|
|
_deflection = (w > st::premiumBubbleWidthLimit)
|
|
|
|
? kDeflectionSmall
|
|
|
|
: kDeflection;
|
2022-05-17 00:04:44 +00:00
|
|
|
_spaceForDeflection = QSize(
|
|
|
|
st::premiumBubbleSkip,
|
|
|
|
st::premiumBubbleSkip);
|
|
|
|
resize(QSize(w, h) + _spaceForDeflection);
|
|
|
|
};
|
|
|
|
|
|
|
|
resizeTo(_bubble.width(), _bubble.height());
|
|
|
|
_bubble.widthChanges(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
resizeTo(_bubble.width(), _bubble.height());
|
|
|
|
}, lifetime());
|
|
|
|
|
|
|
|
const auto moveEndPoint = _currentCounter / float64(_maxCounter);
|
|
|
|
const auto computeLeft = [=](float64 pointRatio, float64 animProgress) {
|
|
|
|
const auto &padding = st::boxRowPadding;
|
2022-05-28 03:50:40 +00:00
|
|
|
const auto halfWidth = (_maxBubbleWidth / 2);
|
|
|
|
const auto left = padding.left();
|
|
|
|
const auto right = padding.right();
|
2022-05-17 00:04:44 +00:00
|
|
|
return ((parent->width() - left - right)
|
|
|
|
* pointRatio
|
|
|
|
* animProgress)
|
2022-05-28 03:50:40 +00:00
|
|
|
- halfWidth
|
2022-05-17 00:04:44 +00:00
|
|
|
+ left;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::move(
|
|
|
|
showFinishes
|
|
|
|
) | rpl::take(1) | rpl::start_with_next([=] {
|
|
|
|
const auto computeEdge = [=] {
|
2022-05-28 03:50:40 +00:00
|
|
|
return parent->width()
|
|
|
|
- st::boxRowPadding.right()
|
|
|
|
- _maxBubbleWidth;
|
2022-05-17 00:04:44 +00:00
|
|
|
};
|
2022-05-28 03:50:40 +00:00
|
|
|
const auto checkBubbleEdges = [&]() -> Bubble::EdgeProgress {
|
2022-05-17 00:04:44 +00:00
|
|
|
const auto finish = computeLeft(moveEndPoint, 1.);
|
2022-05-28 03:50:40 +00:00
|
|
|
const auto edge = computeEdge();
|
|
|
|
return (finish >= edge)
|
|
|
|
? (finish - edge) / (_maxBubbleWidth / 2.)
|
|
|
|
: 0.;
|
2022-05-17 00:04:44 +00:00
|
|
|
};
|
2022-05-28 03:50:40 +00:00
|
|
|
const auto bubbleEdge = checkBubbleEdges();
|
|
|
|
_ignoreDeflection = bubbleEdge;
|
|
|
|
if (_ignoreDeflection) {
|
|
|
|
_stepBeforeDeflection = 1.;
|
|
|
|
_stepAfterDeflection = 1.;
|
|
|
|
}
|
2022-05-17 00:04:44 +00:00
|
|
|
|
|
|
|
_appearanceAnimation.start([=](float64 value) {
|
|
|
|
const auto moveProgress = std::clamp(
|
2022-05-28 03:50:40 +00:00
|
|
|
(value / _stepBeforeDeflection),
|
2022-05-17 00:04:44 +00:00
|
|
|
0.,
|
|
|
|
1.);
|
|
|
|
const auto counterProgress = std::clamp(
|
2022-05-28 03:50:40 +00:00
|
|
|
(value / _stepAfterDeflection),
|
2022-05-17 00:04:44 +00:00
|
|
|
0.,
|
|
|
|
1.);
|
|
|
|
moveToLeft(
|
2022-05-28 03:50:40 +00:00
|
|
|
computeLeft(moveEndPoint, moveProgress)
|
|
|
|
- (_maxBubbleWidth / 2.) * bubbleEdge,
|
2022-05-17 00:04:44 +00:00
|
|
|
0);
|
|
|
|
|
|
|
|
const auto counter = int(0 + counterProgress * _currentCounter);
|
2022-05-28 03:50:40 +00:00
|
|
|
// if (!(counter % 4) || counterProgress > 0.8) {
|
2022-05-17 00:04:44 +00:00
|
|
|
_bubble.setCounter(counter);
|
2022-05-28 03:50:40 +00:00
|
|
|
// }
|
|
|
|
|
|
|
|
const auto edgeProgress = value * bubbleEdge;
|
|
|
|
_bubble.setTailEdge(edgeProgress);
|
2022-05-17 00:04:44 +00:00
|
|
|
update();
|
|
|
|
},
|
|
|
|
0.,
|
|
|
|
1.,
|
2022-05-28 03:50:40 +00:00
|
|
|
st::premiumBubbleSlideDuration
|
|
|
|
* (_ignoreDeflection ? kStepBeforeDeflection : 1.),
|
2022-05-20 13:12:56 +00:00
|
|
|
anim::easeOutCirc);
|
2022-05-17 00:04:44 +00:00
|
|
|
}, lifetime());
|
|
|
|
}
|
|
|
|
|
|
|
|
void BubbleWidget::paintEvent(QPaintEvent *e) {
|
2022-05-28 03:50:40 +00:00
|
|
|
if (_bubble.counter() <= 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-05-17 00:04:44 +00:00
|
|
|
Painter p(this);
|
|
|
|
|
|
|
|
const auto padding = QMargins(
|
|
|
|
0,
|
|
|
|
_spaceForDeflection.height(),
|
|
|
|
_spaceForDeflection.width(),
|
|
|
|
0);
|
|
|
|
const auto bubbleRect = rect() - padding;
|
|
|
|
|
|
|
|
if (_appearanceAnimation.animating()) {
|
|
|
|
auto gradient = ComputeGradient(
|
|
|
|
parentWidget(),
|
|
|
|
x(),
|
|
|
|
bubbleRect.width());
|
|
|
|
_cachedGradient = std::move(gradient);
|
|
|
|
|
|
|
|
const auto progress = _appearanceAnimation.value(1.);
|
|
|
|
const auto scaleProgress = std::clamp(
|
2022-05-28 03:50:40 +00:00
|
|
|
(progress / _stepBeforeDeflection),
|
2022-05-17 00:04:44 +00:00
|
|
|
0.,
|
|
|
|
1.);
|
|
|
|
const auto scale = scaleProgress;
|
|
|
|
const auto rotationProgress = std::clamp(
|
2022-05-28 03:50:40 +00:00
|
|
|
(progress - _stepBeforeDeflection) / (1. - _stepBeforeDeflection),
|
2022-05-17 00:04:44 +00:00
|
|
|
0.,
|
|
|
|
1.);
|
|
|
|
const auto rotationProgressReverse = std::clamp(
|
2022-05-28 03:50:40 +00:00
|
|
|
(progress - _stepAfterDeflection) / (1. - _stepAfterDeflection),
|
2022-05-17 00:04:44 +00:00
|
|
|
0.,
|
|
|
|
1.);
|
|
|
|
|
|
|
|
const auto offsetX = bubbleRect.x() + bubbleRect.width() / 2;
|
|
|
|
const auto offsetY = bubbleRect.y() + bubbleRect.height();
|
|
|
|
p.translate(offsetX, offsetY);
|
|
|
|
p.scale(scale, scale);
|
2022-05-28 03:50:40 +00:00
|
|
|
if (!_ignoreDeflection) {
|
|
|
|
p.rotate(rotationProgress * _deflection
|
|
|
|
- rotationProgressReverse * _deflection);
|
|
|
|
}
|
2022-05-17 00:04:44 +00:00
|
|
|
p.translate(-offsetX, -offsetY);
|
|
|
|
}
|
|
|
|
|
2022-06-07 05:48:33 +00:00
|
|
|
_bubble.paintBubble(
|
|
|
|
p,
|
|
|
|
bubbleRect,
|
|
|
|
_premiumPossible ? QBrush(_cachedGradient) : st::windowBgActive->b);
|
2022-05-17 00:04:44 +00:00
|
|
|
}
|
|
|
|
|
2022-05-18 04:28:35 +00:00
|
|
|
class Line final : public Ui::RpWidget {
|
|
|
|
public:
|
2022-05-31 10:32:07 +00:00
|
|
|
Line(
|
|
|
|
not_null<Ui::RpWidget*> parent,
|
|
|
|
int max,
|
|
|
|
TextFactory textFactory,
|
|
|
|
int min);
|
2022-06-14 10:54:30 +00:00
|
|
|
Line(not_null<Ui::RpWidget*> parent, QString max, QString min);
|
2022-05-18 04:28:35 +00:00
|
|
|
|
2022-06-13 11:27:20 +00:00
|
|
|
void setColorOverride(QBrush brush);
|
|
|
|
|
2022-05-18 04:28:35 +00:00
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *event) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void recache(const QSize &s);
|
|
|
|
|
|
|
|
int _leftWidth = 0;
|
|
|
|
int _rightWidth = 0;
|
|
|
|
|
|
|
|
QPixmap _leftPixmap;
|
|
|
|
QPixmap _rightPixmap;
|
|
|
|
|
|
|
|
Ui::Text::String _leftText;
|
|
|
|
Ui::Text::String _rightText;
|
|
|
|
Ui::Text::String _rightLabel;
|
2022-05-31 10:32:07 +00:00
|
|
|
Ui::Text::String _leftLabel;
|
2022-05-18 04:28:35 +00:00
|
|
|
|
2022-06-13 11:27:20 +00:00
|
|
|
std::optional<QBrush> _overrideBrush;
|
|
|
|
|
2022-05-18 04:28:35 +00:00
|
|
|
};
|
|
|
|
|
2022-05-31 10:32:07 +00:00
|
|
|
Line::Line(
|
|
|
|
not_null<Ui::RpWidget*> parent,
|
|
|
|
int max,
|
|
|
|
TextFactory textFactory,
|
|
|
|
int min)
|
2022-06-14 10:54:30 +00:00
|
|
|
: Line(
|
|
|
|
parent,
|
|
|
|
max ? textFactory(max) : QString(),
|
|
|
|
min ? textFactory(min) : QString()) {
|
|
|
|
}
|
|
|
|
|
|
|
|
Line::Line(not_null<Ui::RpWidget*> parent, QString max, QString min)
|
2022-05-18 04:28:35 +00:00
|
|
|
: Ui::RpWidget(parent)
|
2022-06-14 09:42:43 +00:00
|
|
|
, _leftText(st::semiboldTextStyle, tr::lng_premium_free(tr::now))
|
|
|
|
, _rightText(st::semiboldTextStyle, tr::lng_premium(tr::now))
|
2022-06-14 10:54:30 +00:00
|
|
|
, _rightLabel(st::semiboldTextStyle, max)
|
|
|
|
, _leftLabel(st::semiboldTextStyle, min) {
|
2022-05-18 04:28:35 +00:00
|
|
|
resize(width(), st::requestsAcceptButton.height);
|
|
|
|
|
|
|
|
sizeValue(
|
|
|
|
) | rpl::start_with_next([=](const QSize &s) {
|
2022-06-02 10:50:47 +00:00
|
|
|
if (s.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
2022-05-18 04:28:35 +00:00
|
|
|
_leftWidth = (s.width() / 2);
|
|
|
|
_rightWidth = (s.width() - _leftWidth);
|
|
|
|
recache(s);
|
|
|
|
update();
|
|
|
|
}, lifetime());
|
|
|
|
}
|
|
|
|
|
2022-06-13 11:27:20 +00:00
|
|
|
void Line::setColorOverride(QBrush brush) {
|
|
|
|
if (brush.style() == Qt::NoBrush) {
|
|
|
|
_overrideBrush = std::nullopt;
|
|
|
|
} else {
|
|
|
|
_overrideBrush = brush;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-18 04:28:35 +00:00
|
|
|
void Line::paintEvent(QPaintEvent *event) {
|
|
|
|
Painter p(this);
|
|
|
|
|
|
|
|
p.drawPixmap(0, 0, _leftPixmap);
|
|
|
|
p.drawPixmap(_leftWidth, 0, _rightPixmap);
|
|
|
|
|
|
|
|
p.setFont(st::normalFont);
|
|
|
|
|
|
|
|
const auto textPadding = st::premiumLineTextSkip;
|
|
|
|
const auto textTop = (height() - _leftText.minHeight()) / 2;
|
|
|
|
|
|
|
|
p.setPen(st::windowFg);
|
2022-05-31 10:32:07 +00:00
|
|
|
_leftLabel.drawRight(
|
|
|
|
p,
|
|
|
|
textPadding,
|
|
|
|
textTop,
|
|
|
|
_leftWidth - textPadding,
|
|
|
|
_leftWidth,
|
|
|
|
style::al_right);
|
2022-05-18 04:28:35 +00:00
|
|
|
_leftText.drawLeft(
|
|
|
|
p,
|
|
|
|
textPadding,
|
|
|
|
textTop,
|
|
|
|
_leftWidth - textPadding,
|
|
|
|
_leftWidth);
|
|
|
|
|
|
|
|
p.setPen(st::activeButtonFg);
|
|
|
|
_rightLabel.drawRight(
|
|
|
|
p,
|
|
|
|
textPadding,
|
|
|
|
textTop,
|
|
|
|
_rightWidth - textPadding,
|
|
|
|
width(),
|
|
|
|
style::al_right);
|
|
|
|
_rightText.drawLeftElided(
|
|
|
|
p,
|
|
|
|
_leftWidth + textPadding,
|
|
|
|
textTop,
|
|
|
|
_rightWidth - _rightLabel.countWidth(_rightWidth) - textPadding * 2,
|
|
|
|
_rightWidth);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Line::recache(const QSize &s) {
|
|
|
|
const auto r = QRect(0, 0, _leftWidth, s.height());
|
|
|
|
auto pixmap = QPixmap(r.size() * style::DevicePixelRatio());
|
|
|
|
pixmap.setDevicePixelRatio(style::DevicePixelRatio());
|
|
|
|
pixmap.fill(Qt::transparent);
|
|
|
|
|
|
|
|
auto pathRound = QPainterPath();
|
|
|
|
pathRound.addRoundedRect(r, st::buttonRadius, st::buttonRadius);
|
|
|
|
|
|
|
|
{
|
|
|
|
auto leftPixmap = pixmap;
|
|
|
|
Painter p(&leftPixmap);
|
|
|
|
PainterHighQualityEnabler hq(p);
|
|
|
|
auto pathRect = QPainterPath();
|
|
|
|
auto halfRect = r;
|
|
|
|
halfRect.setLeft(r.center().x());
|
|
|
|
pathRect.addRect(halfRect);
|
|
|
|
|
|
|
|
p.fillPath(pathRound + pathRect, st::windowShadowFgFallback);
|
|
|
|
|
|
|
|
_leftPixmap = std::move(leftPixmap);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
auto rightPixmap = pixmap;
|
|
|
|
Painter p(&rightPixmap);
|
|
|
|
PainterHighQualityEnabler hq(p);
|
|
|
|
auto pathRect = QPainterPath();
|
|
|
|
auto halfRect = r;
|
|
|
|
halfRect.setRight(r.center().x());
|
|
|
|
pathRect.addRect(halfRect);
|
|
|
|
|
2022-06-13 11:27:20 +00:00
|
|
|
if (_overrideBrush) {
|
|
|
|
p.fillPath(pathRound + pathRect, *_overrideBrush);
|
|
|
|
} else {
|
|
|
|
auto gradient = ComputeGradient(
|
|
|
|
this,
|
|
|
|
(_leftPixmap.width() / style::DevicePixelRatio()) + r.x(),
|
|
|
|
r.width());
|
|
|
|
p.fillPath(pathRound + pathRect, QBrush(std::move(gradient)));
|
|
|
|
}
|
2022-05-18 04:28:35 +00:00
|
|
|
|
|
|
|
_rightPixmap = std::move(rightPixmap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-17 00:04:44 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
void AddBubbleRow(
|
|
|
|
not_null<Ui::VerticalLayout*> parent,
|
|
|
|
rpl::producer<> showFinishes,
|
|
|
|
int min,
|
|
|
|
int current,
|
|
|
|
int max,
|
2022-06-07 05:48:33 +00:00
|
|
|
bool premiumPossible,
|
2022-05-17 00:04:44 +00:00
|
|
|
std::optional<tr::phrase<lngtag_count>> phrase,
|
|
|
|
const style::icon *icon) {
|
|
|
|
const auto container = parent->add(
|
|
|
|
object_ptr<Ui::FixedHeightWidget>(parent, 0));
|
|
|
|
const auto bubble = Ui::CreateChild<BubbleWidget>(
|
|
|
|
container,
|
2022-05-24 04:20:22 +00:00
|
|
|
ProcessTextFactory(phrase),
|
2022-05-17 00:04:44 +00:00
|
|
|
current,
|
|
|
|
max,
|
2022-06-07 05:48:33 +00:00
|
|
|
premiumPossible,
|
2022-05-17 00:04:44 +00:00
|
|
|
std::move(showFinishes),
|
|
|
|
icon);
|
|
|
|
rpl::combine(
|
|
|
|
container->sizeValue(),
|
|
|
|
bubble->sizeValue()
|
|
|
|
) | rpl::start_with_next([=](const QSize &parentSize, const QSize &size) {
|
|
|
|
container->resize(parentSize.width(), size.height());
|
|
|
|
}, bubble->lifetime());
|
|
|
|
}
|
|
|
|
|
2022-06-14 10:54:30 +00:00
|
|
|
void AddLimitRow(
|
|
|
|
not_null<Ui::VerticalLayout*> parent,
|
|
|
|
QString max,
|
|
|
|
QString min) {
|
|
|
|
parent->add(object_ptr<Line>(parent, max, min), st::boxRowPadding);
|
|
|
|
}
|
|
|
|
|
2022-05-24 04:20:22 +00:00
|
|
|
void AddLimitRow(
|
|
|
|
not_null<Ui::VerticalLayout*> parent,
|
|
|
|
int max,
|
2022-05-31 10:32:07 +00:00
|
|
|
std::optional<tr::phrase<lngtag_count>> phrase,
|
|
|
|
int min) {
|
2022-06-14 10:54:30 +00:00
|
|
|
const auto factory = ProcessTextFactory(phrase);
|
|
|
|
AddLimitRow(
|
|
|
|
parent,
|
|
|
|
max ? factory(max) : QString(),
|
|
|
|
min ? factory(min) : QString());
|
2022-05-31 10:32:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AddAccountsRow(
|
|
|
|
not_null<Ui::VerticalLayout*> parent,
|
|
|
|
AccountsRowArgs &&args) {
|
|
|
|
const auto container = parent->add(
|
|
|
|
object_ptr<Ui::FixedHeightWidget>(parent, st::premiumAccountsHeight),
|
2022-05-18 04:28:35 +00:00
|
|
|
st::boxRowPadding);
|
2022-05-31 10:32:07 +00:00
|
|
|
|
|
|
|
struct Account {
|
|
|
|
not_null<Ui::AbstractButton*> widget;
|
|
|
|
Ui::RoundImageCheckbox checkbox;
|
|
|
|
Ui::Text::String name;
|
|
|
|
QPixmap badge;
|
|
|
|
};
|
|
|
|
struct State {
|
|
|
|
std::vector<Account> accounts;
|
|
|
|
};
|
|
|
|
const auto state = container->lifetime().make_state<State>();
|
|
|
|
const auto group = args.group;
|
|
|
|
|
|
|
|
const auto imageRadius = args.st.imageRadius;
|
|
|
|
const auto checkSelectWidth = args.st.selectWidth;
|
|
|
|
const auto nameFg = args.stNameFg;
|
|
|
|
|
|
|
|
const auto cacheBadge = [=](int center) {
|
|
|
|
const auto &padding = st::premiumAccountsLabelPadding;
|
|
|
|
const auto size = st::premiumAccountsLabelSize
|
|
|
|
+ QSize(
|
|
|
|
padding.left() + padding.right(),
|
|
|
|
padding.top() + padding.bottom());
|
|
|
|
auto badge = QPixmap(size * style::DevicePixelRatio());
|
|
|
|
badge.setDevicePixelRatio(style::DevicePixelRatio());
|
|
|
|
badge.fill(Qt::transparent);
|
|
|
|
|
|
|
|
Painter p(&badge);
|
|
|
|
PainterHighQualityEnabler hq(p);
|
|
|
|
|
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
const auto rectOut = QRect(QPoint(), size);
|
|
|
|
const auto rectIn = rectOut - padding;
|
|
|
|
|
|
|
|
const auto radius = st::premiumAccountsLabelRadius;
|
|
|
|
p.setBrush(st::premiumButtonFg);
|
|
|
|
p.drawRoundedRect(rectOut, radius, radius);
|
|
|
|
|
|
|
|
const auto left = center - rectIn.width() / 2;
|
|
|
|
p.setBrush(QBrush(ComputeGradient(container, left, rectIn.width())));
|
|
|
|
p.drawRoundedRect(rectIn, radius / 2, radius / 2);
|
|
|
|
|
|
|
|
p.setPen(st::premiumButtonFg);
|
|
|
|
p.setFont(st::semiboldFont);
|
|
|
|
p.drawText(rectIn, u"+1"_q, style::al_center);
|
|
|
|
|
|
|
|
return badge;
|
|
|
|
};
|
|
|
|
|
|
|
|
for (auto &entry : args.entries) {
|
|
|
|
const auto widget = Ui::CreateChild<Ui::AbstractButton>(container);
|
|
|
|
auto name = Ui::Text::String(imageRadius * 2);
|
|
|
|
name.setText(args.stName, entry.name, Ui::NameTextOptions());
|
|
|
|
state->accounts.push_back(Account{
|
|
|
|
.widget = widget,
|
|
|
|
.checkbox = Ui::RoundImageCheckbox(
|
|
|
|
args.st,
|
|
|
|
[=] { widget->update(); },
|
|
|
|
base::take(entry.paintRoundImage)),
|
|
|
|
.name = std::move(name),
|
|
|
|
});
|
|
|
|
const auto index = int(state->accounts.size()) - 1;
|
2022-06-02 10:50:47 +00:00
|
|
|
state->accounts[index].checkbox.setChecked(
|
|
|
|
index == group->value(),
|
|
|
|
anim::type::instant);
|
2022-05-31 10:32:07 +00:00
|
|
|
|
|
|
|
widget->paintRequest(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
Painter p(widget);
|
|
|
|
const auto width = widget->width();
|
|
|
|
const auto photoLeft = (width - (imageRadius * 2)) / 2;
|
|
|
|
const auto photoTop = checkSelectWidth;
|
2022-06-01 22:21:26 +00:00
|
|
|
const auto &account = state->accounts[index];
|
2022-05-31 10:32:07 +00:00
|
|
|
account.checkbox.paint(p, photoLeft, photoTop, width);
|
|
|
|
|
|
|
|
const auto &badgeSize = account.badge.size()
|
|
|
|
/ style::DevicePixelRatio();
|
|
|
|
p.drawPixmap(
|
|
|
|
(width - badgeSize.width()) / 2,
|
|
|
|
photoTop + (imageRadius * 2) - badgeSize.height() / 2,
|
|
|
|
account.badge);
|
|
|
|
|
|
|
|
p.setPen(nameFg);
|
|
|
|
p.setBrush(Qt::NoBrush);
|
|
|
|
account.name.drawLeftElided(
|
|
|
|
p,
|
|
|
|
0,
|
|
|
|
photoTop + imageRadius * 2 + st::premiumAccountsNameTop,
|
|
|
|
width,
|
|
|
|
width,
|
|
|
|
2,
|
|
|
|
style::al_top,
|
|
|
|
0,
|
|
|
|
-1,
|
|
|
|
0,
|
|
|
|
true);
|
|
|
|
}, widget->lifetime());
|
|
|
|
|
|
|
|
widget->setClickedCallback([=] {
|
|
|
|
group->setValue(index);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
container->sizeValue(
|
|
|
|
) | rpl::start_with_next([=](const QSize &size) {
|
|
|
|
const auto count = state->accounts.size();
|
|
|
|
const auto columnWidth = size.width() / count;
|
|
|
|
for (auto i = 0; i < count; i++) {
|
2022-06-01 22:21:26 +00:00
|
|
|
auto &account = state->accounts[i];
|
|
|
|
account.widget->resize(columnWidth, size.height());
|
2022-05-31 10:32:07 +00:00
|
|
|
const auto left = columnWidth * i;
|
2022-06-01 22:21:26 +00:00
|
|
|
account.widget->moveToLeft(left, 0);
|
|
|
|
account.badge = cacheBadge(left + columnWidth / 2);
|
|
|
|
|
|
|
|
const auto photoWidth = ((imageRadius + checkSelectWidth) * 2);
|
|
|
|
account.checkbox.setColorOverride(QBrush(
|
|
|
|
ComputeGradient(
|
|
|
|
container,
|
|
|
|
left + (columnWidth - photoWidth) / 2,
|
|
|
|
photoWidth)));
|
2022-05-31 10:32:07 +00:00
|
|
|
}
|
|
|
|
}, container->lifetime());
|
2022-06-02 10:50:47 +00:00
|
|
|
|
|
|
|
group->setChangedCallback([=](int value) {
|
|
|
|
for (auto i = 0; i < state->accounts.size(); i++) {
|
|
|
|
state->accounts[i].checkbox.setChecked(i == value);
|
|
|
|
}
|
|
|
|
});
|
2022-05-18 04:28:35 +00:00
|
|
|
}
|
|
|
|
|
2022-05-20 14:57:01 +00:00
|
|
|
QGradientStops LimitGradientStops() {
|
|
|
|
return {
|
|
|
|
{ 0.0, st::premiumButtonBg1->c },
|
|
|
|
{ .25, st::premiumButtonBg1->c },
|
|
|
|
{ .85, st::premiumButtonBg2->c },
|
|
|
|
{ 1.0, st::premiumButtonBg3->c },
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
QGradientStops ButtonGradientStops() {
|
|
|
|
return {
|
|
|
|
{ 0., st::premiumButtonBg1->c },
|
|
|
|
{ 0.6, st::premiumButtonBg2->c },
|
|
|
|
{ 1., st::premiumButtonBg3->c },
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
QGradientStops LockGradientStops() {
|
|
|
|
return ButtonGradientStops();
|
|
|
|
}
|
|
|
|
|
2022-06-13 11:27:20 +00:00
|
|
|
QGradientStops FullHeightGradientStops() {
|
|
|
|
return {
|
|
|
|
{ 0.0, st::premiumIconBg1->c },
|
|
|
|
{ .28, st::premiumIconBg2->c },
|
|
|
|
{ .55, st::premiumButtonBg2->c },
|
|
|
|
{ 1.0, st::premiumButtonBg1->c },
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-07-05 19:29:46 +00:00
|
|
|
QGradientStops GiftGradientStops() {
|
|
|
|
return {
|
|
|
|
{ 0., st::premiumButtonBg1->c },
|
|
|
|
{ 1., st::premiumButtonBg2->c },
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-06-13 11:27:20 +00:00
|
|
|
void ShowListBox(
|
|
|
|
not_null<Ui::GenericBox*> box,
|
|
|
|
std::vector<ListEntry> entries) {
|
|
|
|
|
|
|
|
const auto &stLabel = st::defaultFlatLabel;
|
|
|
|
const auto &titlePadding = st::settingsPremiumPreviewTitlePadding;
|
|
|
|
const auto &descriptionPadding = st::settingsPremiumPreviewAboutPadding;
|
|
|
|
|
|
|
|
auto lines = std::vector<Line*>();
|
|
|
|
lines.reserve(int(entries.size()));
|
|
|
|
|
|
|
|
const auto content = box->verticalLayout();
|
|
|
|
for (auto &entry : entries) {
|
2022-06-14 16:38:52 +00:00
|
|
|
content->add(
|
2022-06-13 11:27:20 +00:00
|
|
|
object_ptr<Ui::FlatLabel>(
|
|
|
|
content,
|
|
|
|
base::take(entry.subtitle) | rpl::map(Ui::Text::Bold),
|
|
|
|
stLabel),
|
|
|
|
titlePadding);
|
2022-06-14 16:38:52 +00:00
|
|
|
content->add(
|
2022-06-13 11:27:20 +00:00
|
|
|
object_ptr<Ui::FlatLabel>(
|
|
|
|
content,
|
|
|
|
base::take(entry.description),
|
|
|
|
st::boxDividerLabel),
|
|
|
|
descriptionPadding);
|
|
|
|
|
|
|
|
const auto limitRow = content->add(
|
|
|
|
object_ptr<Line>(
|
|
|
|
content,
|
|
|
|
entry.rightNumber,
|
|
|
|
TextFactory([=, text = ProcessTextFactory(std::nullopt)](
|
|
|
|
int n) {
|
|
|
|
if (entry.customRightText && (n == entry.rightNumber)) {
|
|
|
|
return *entry.customRightText;
|
|
|
|
} else {
|
|
|
|
return text(n);
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
entry.leftNumber),
|
|
|
|
st::settingsPremiumPreviewLinePadding);
|
|
|
|
lines.push_back(limitRow);
|
|
|
|
}
|
|
|
|
|
|
|
|
content->resizeToWidth(content->height());
|
|
|
|
|
|
|
|
// Color lines.
|
|
|
|
Assert(lines.size() > 2);
|
|
|
|
const auto from = lines.front()->y();
|
|
|
|
const auto to = lines.back()->y() + lines.back()->height();
|
|
|
|
|
2022-07-05 21:41:05 +00:00
|
|
|
const auto partialGradient = [&] {
|
2022-06-13 11:27:20 +00:00
|
|
|
auto stops = Ui::Premium::FullHeightGradientStops();
|
2022-07-05 21:41:05 +00:00
|
|
|
// Reverse.
|
2022-06-13 11:27:20 +00:00
|
|
|
for (auto &stop : stops) {
|
|
|
|
stop.first = std::abs(stop.first - 1.);
|
|
|
|
}
|
2022-07-05 21:41:05 +00:00
|
|
|
return PartialGradient(from, to, std::move(stops));
|
|
|
|
}();
|
2022-06-13 11:27:20 +00:00
|
|
|
|
|
|
|
for (auto i = 0; i < int(lines.size()); i++) {
|
|
|
|
const auto &line = lines[i];
|
|
|
|
|
2022-07-05 21:41:05 +00:00
|
|
|
const auto brush = QBrush(
|
|
|
|
partialGradient.compute(line->y(), line->height()));
|
2022-06-13 11:27:20 +00:00
|
|
|
line->setColorOverride(brush);
|
|
|
|
}
|
|
|
|
box->addSkip(st::settingsPremiumPreviewLinePadding.bottom());
|
|
|
|
|
|
|
|
box->setTitle(tr::lng_premium_summary_subtitle_double_limits());
|
|
|
|
box->setWidth(st::boxWideWidth);
|
|
|
|
}
|
|
|
|
|
2022-07-05 19:29:46 +00:00
|
|
|
void AddGiftOptions(
|
|
|
|
not_null<Ui::VerticalLayout*> parent,
|
|
|
|
std::shared_ptr<Ui::RadiobuttonGroup> group,
|
|
|
|
std::vector<GiftInfo> gifts) {
|
|
|
|
|
|
|
|
struct Edges {
|
|
|
|
Ui::RpWidget *top = nullptr;
|
|
|
|
Ui::RpWidget *bottom = nullptr;
|
|
|
|
};
|
|
|
|
const auto edges = parent->lifetime().make_state<Edges>();
|
|
|
|
struct Animation {
|
|
|
|
int nowIndex = 0;
|
|
|
|
Ui::Animations::Simple animation;
|
|
|
|
};
|
|
|
|
const auto animation = parent->lifetime().make_state<Animation>();
|
|
|
|
|
|
|
|
const auto stops = GiftGradientStops();
|
|
|
|
|
|
|
|
const auto addRow = [&](const GiftInfo &info, int index) {
|
|
|
|
const auto row = parent->add(
|
|
|
|
object_ptr<Ui::AbstractButton>(parent),
|
|
|
|
st::premiumGiftRowPaddings);
|
|
|
|
row->resize(row->width(), st::premiumGiftRowHeight);
|
|
|
|
{
|
|
|
|
if (!index) {
|
|
|
|
edges->top = row;
|
|
|
|
}
|
|
|
|
edges->bottom = row;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto &stCheckbox = st::defaultBoxCheckbox;
|
|
|
|
const auto radio = Ui::CreateChild<Ui::Radiobutton>(
|
|
|
|
row,
|
|
|
|
group,
|
|
|
|
index,
|
|
|
|
QString(),
|
|
|
|
stCheckbox);
|
|
|
|
radio->setAttribute(Qt::WA_TransparentForMouseEvents);
|
|
|
|
|
|
|
|
row->sizeValue(
|
|
|
|
) | rpl::start_with_next([=, margins = stCheckbox.margin](
|
|
|
|
const QSize &s) {
|
|
|
|
const auto radioHeight = radio->height()
|
|
|
|
- margins.top()
|
|
|
|
- margins.bottom();
|
|
|
|
radio->moveToLeft(
|
|
|
|
st::premiumGiftRowMargins.left(),
|
|
|
|
(s.height() - radioHeight) / 2);
|
|
|
|
}, radio->lifetime());
|
|
|
|
|
|
|
|
row->paintRequest(
|
|
|
|
) | rpl::start_with_next([=](const QRect &r) {
|
|
|
|
Painter p(row);
|
|
|
|
PainterHighQualityEnabler hq(p);
|
|
|
|
|
|
|
|
p.fillRect(r, Qt::transparent);
|
|
|
|
|
|
|
|
const auto left = st::premiumGiftRowTextLeft;
|
|
|
|
const auto borderWidth = st::premiumGiftRowBorderWidth;
|
|
|
|
const auto halfHeight = row->height() / 2;
|
|
|
|
|
|
|
|
const auto titleFont = st::semiboldFont;
|
|
|
|
p.setFont(titleFont);
|
|
|
|
p.setPen(st::boxTextFg);
|
|
|
|
p.drawText(
|
|
|
|
left,
|
|
|
|
st::premiumGiftRowSubtitleTop + titleFont->ascent,
|
|
|
|
info.duration);
|
|
|
|
|
|
|
|
const auto discountFont = st::windowFiltersButton.badgeStyle.font;
|
|
|
|
const auto discountWidth = discountFont->width(info.discount);
|
|
|
|
const auto &discountMargins = st::premiumGiftRowBadgeMargins;
|
|
|
|
const auto discountRect = QRect(
|
|
|
|
left,
|
|
|
|
halfHeight + discountMargins.top(),
|
|
|
|
discountWidth
|
|
|
|
+ discountMargins.left()
|
|
|
|
+ discountMargins.right(),
|
|
|
|
st::premiumGiftRowBadgeHeight);
|
|
|
|
{
|
|
|
|
const auto from = edges->top->y();
|
|
|
|
const auto to = edges->bottom->y() + edges->bottom->height();
|
|
|
|
auto partialGradient = PartialGradient(from, to, stops);
|
|
|
|
|
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
p.setBrush(partialGradient.compute(row->y(), row->height()));
|
|
|
|
const auto round = st::premiumGiftRowBadgeRadius;
|
|
|
|
p.drawRoundedRect(discountRect, round, round);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (animation->nowIndex == index) {
|
|
|
|
const auto progress = animation->animation.value(1.);
|
|
|
|
const auto w = row->width();
|
|
|
|
auto gradient = QLinearGradient(w - w * progress, 0, w * 2, 0);
|
|
|
|
gradient.setSpread(QGradient::Spread::RepeatSpread);
|
|
|
|
gradient.setStops(stops);
|
|
|
|
const auto pen = QPen(QBrush(gradient), borderWidth);
|
|
|
|
p.setPen(pen);
|
|
|
|
p.setBrush(Qt::NoBrush);
|
|
|
|
const auto borderRect = row->rect()
|
|
|
|
- QMargins(
|
|
|
|
pen.width() / 2,
|
|
|
|
pen.width() / 2,
|
|
|
|
pen.width() / 2,
|
|
|
|
pen.width() / 2);
|
|
|
|
const auto round = st::premiumGiftRowBorderRadius;
|
|
|
|
p.drawRoundedRect(borderRect, round, round);
|
|
|
|
}
|
|
|
|
|
|
|
|
p.setPen(st::boxBg);
|
|
|
|
p.setFont(discountFont);
|
|
|
|
p.drawText(discountRect, info.discount, style::al_center);
|
|
|
|
|
|
|
|
const auto perRect = QMargins(0, 0, row->width(), 0)
|
|
|
|
+ discountRect.translated(
|
|
|
|
discountRect.width() + discountMargins.left(),
|
|
|
|
0);
|
|
|
|
p.setPen(st::windowSubTextFg);
|
|
|
|
p.setFont(st::shareBoxListItem.nameStyle.font);
|
|
|
|
p.drawText(perRect, info.perMonth, style::al_left);
|
|
|
|
|
|
|
|
const auto totalRect = row->rect()
|
|
|
|
- QMargins(0, 0, st::premiumGiftRowMargins.right(), 0);
|
|
|
|
p.setFont(st::normalFont);
|
|
|
|
p.drawText(totalRect, info.total, style::al_right);
|
|
|
|
}, row->lifetime());
|
|
|
|
|
|
|
|
row->setClickedCallback([=, duration = st::defaultCheck.duration] {
|
|
|
|
group->setValue(index);
|
|
|
|
animation->nowIndex = group->value();
|
|
|
|
animation->animation.stop();
|
|
|
|
animation->animation.start(
|
|
|
|
[=] { parent->update(); },
|
|
|
|
0.,
|
|
|
|
1.,
|
|
|
|
duration);
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
for (auto i = 0; i < gifts.size(); i++) {
|
|
|
|
addRow(gifts[i], i);
|
|
|
|
}
|
|
|
|
|
|
|
|
parent->resizeToWidth(parent->height());
|
|
|
|
parent->update();
|
|
|
|
}
|
|
|
|
|
2022-05-17 00:04:44 +00:00
|
|
|
} // namespace Premium
|
|
|
|
} // namespace Ui
|