mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 06:07:06 +02:00
Replaced gradient header in Premium Settings for dark themes.
This commit is contained in:
parent
35c59ad35a
commit
5505a566be
5 changed files with 100 additions and 32 deletions
|
@ -1 +1 @@
|
|||
<svg width="84" height="81" viewBox="0 0 84 81" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><g transform="translate(-190.000000, -73.000000)" fill="#fff"><path d="M217.584175 95.7198452l10.102137-20.1302773C228.851735 73.2672578 231.669488 72.3342655 233.979937 73.5056713 234.886993 73.9655512 235.620771 74.7092927 236.070698 75.6248193l9.540513 19.41335C246.390574 96.6240434 247.914247 97.7068442 249.661599 97.9165844L269.640156 100.314675C272.352386 100.640233 274.288515 103.114133 273.96462 105.840286 273.831224 106.963049 273.321003 108.006556 272.518147 108.798619l-15.7911 15.578821C256.089452 125.006464 255.780497 125.898568 255.89167 126.789576L258.515919 147.821772C258.891602 150.832711 256.767771 153.579675 253.772209 153.957287 252.636962 154.100393 251.485656 153.881854 250.480518 153.332463L233.796907 144.21349C232.589892 143.553757 231.136827 143.534799 229.913183 144.162822l-17.2854 8.871545C210.195073 154.282929 207.215982 153.312865 205.973797 150.867667 205.509027 149.952785 205.337643 148.915649 205.483212 147.898872L206.864713 138.249309C207.540411 133.529666 210.458736 129.435705 214.68762 127.274973L233.885915 117.465678C234.398537 117.203755 234.602854 116.57373 234.342269 116.058476 234.140381 115.659283 233.708181 115.433429 233.267119 115.496635l-23.479483 3.364749C206.198378 119.375746 202.558336 118.361996 199.744254 116.064306L191.92377 109.678904C189.692048 107.856709 189.352516 104.561073 191.165405 102.317895 192.008458 101.274743 193.218498 100.597614 194.544752 100.426837L214.594132 97.8451554C215.880032 97.679575 217.000319 96.8832795 217.584175 95.7198452z"/></g></g></svg>
|
||||
<svg width="84" height="81" viewBox="0 0 84 81" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><g transform="translate(-190.000000, -73.000000)" fill="#fff"><defs>gradientPlaceholder</defs><path d="M217.584175 95.7198452l10.102137-20.1302773C228.851735 73.2672578 231.669488 72.3342655 233.979937 73.5056713 234.886993 73.9655512 235.620771 74.7092927 236.070698 75.6248193l9.540513 19.41335C246.390574 96.6240434 247.914247 97.7068442 249.661599 97.9165844L269.640156 100.314675C272.352386 100.640233 274.288515 103.114133 273.96462 105.840286 273.831224 106.963049 273.321003 108.006556 272.518147 108.798619l-15.7911 15.578821C256.089452 125.006464 255.780497 125.898568 255.89167 126.789576L258.515919 147.821772C258.891602 150.832711 256.767771 153.579675 253.772209 153.957287 252.636962 154.100393 251.485656 153.881854 250.480518 153.332463L233.796907 144.21349C232.589892 143.553757 231.136827 143.534799 229.913183 144.162822l-17.2854 8.871545C210.195073 154.282929 207.215982 153.312865 205.973797 150.867667 205.509027 149.952785 205.337643 148.915649 205.483212 147.898872L206.864713 138.249309C207.540411 133.529666 210.458736 129.435705 214.68762 127.274973L233.885915 117.465678C234.398537 117.203755 234.602854 116.57373 234.342269 116.058476 234.140381 115.659283 233.708181 115.433429 233.267119 115.496635l-23.479483 3.364749C206.198378 119.375746 202.558336 118.361996 199.744254 116.064306L191.92377 109.678904C189.692048 107.856709 189.352516 104.561073 191.165405 102.317895 192.008458 101.274743 193.218498 100.597614 194.544752 100.426837L214.594132 97.8451554C215.880032 97.679575 217.000319 96.8832795 217.584175 95.7198452z"/></g></g></svg>
|
||||
|
|
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
|
@ -33,6 +33,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "settings/settings_premium.h"
|
||||
#include "ui/abstract_button.h"
|
||||
#include "ui/basic_click_handlers.h"
|
||||
#include "ui/color_contrast.h"
|
||||
#include "ui/effects/gradient.h"
|
||||
#include "ui/effects/premium_graphics.h"
|
||||
#include "ui/effects/premium_stars_colored.h"
|
||||
|
@ -66,11 +67,39 @@ using SectionCustomTopBarData = Info::Settings::SectionCustomTopBarData;
|
|||
|
||||
constexpr auto kBodyAnimationPart = 0.90;
|
||||
constexpr auto kTitleAdditionalScale = 0.15;
|
||||
constexpr auto kMinAcceptableContrast = 4.5; // 1.14;
|
||||
|
||||
[[nodiscard]] QString Svg() {
|
||||
return u":/gui/icons/settings/star.svg"_q;
|
||||
}
|
||||
|
||||
[[nodiscard]] QByteArray ColorizedSvg() {
|
||||
auto f = QFile(Svg());
|
||||
if (!f.open(QIODevice::ReadOnly)) {
|
||||
return QByteArray();
|
||||
}
|
||||
auto content = qs(f.readAll());
|
||||
auto stops = [] {
|
||||
auto s = QString();
|
||||
for (const auto &stop : Ui::Premium::ButtonGradientStops()) {
|
||||
s += QString("<stop offset='%1' stop-color='%2'/>")
|
||||
.arg(QString::number(stop.first), stop.second.name());
|
||||
}
|
||||
return s;
|
||||
}();
|
||||
const auto color = QString("<linearGradient id='Gradient2' "
|
||||
"x1='%1' x2='%2' y1='%3' y2='%4'>%5</linearGradient>")
|
||||
.arg(0)
|
||||
.arg(1)
|
||||
.arg(1)
|
||||
.arg(0)
|
||||
.arg(std::move(stops));
|
||||
content.replace(u"gradientPlaceholder"_q, color);
|
||||
content.replace(u"#fff"_q, u"url(#Gradient2)"_q);
|
||||
f.close();
|
||||
return content.toUtf8();
|
||||
}
|
||||
|
||||
[[nodiscard]] Data::SubscriptionOptions SubscriptionOptionsForRows(
|
||||
Data::SubscriptionOptions result) {
|
||||
for (auto &option : result) {
|
||||
|
@ -532,7 +561,6 @@ private:
|
|||
std::unique_ptr<EmojiStatusTopBar> _emojiStatus;
|
||||
QImage _imageStar;
|
||||
|
||||
QRectF _ministarsRect;
|
||||
QRectF _starRect;
|
||||
|
||||
};
|
||||
|
@ -805,16 +833,7 @@ void TopBarUser::paintEvent(QPaintEvent *e) {
|
|||
void TopBarUser::resizeEvent(QResizeEvent *e) {
|
||||
_starRect = TopBarAbstract::starRect(1., 1.);
|
||||
|
||||
const auto &rect = _starRect;
|
||||
const auto center = rect.center();
|
||||
const auto size = QSize(
|
||||
rect.width() * Ui::Premium::MiniStars::kSizeFactor,
|
||||
rect.height());
|
||||
const auto ministarsRect = QRect(
|
||||
QPoint(center.x() - size.width(), center.y() - size.height()),
|
||||
QPoint(center.x() + size.width(), center.y() + size.height()));
|
||||
_ministars.setPosition(ministarsRect.topLeft());
|
||||
_ministars.setSize(ministarsRect.size());
|
||||
_ministars.setCenter(_starRect.toRect());
|
||||
|
||||
if (_emojiStatus) {
|
||||
_emojiStatus->setCenter(_starRect.center());
|
||||
|
@ -840,7 +859,7 @@ private:
|
|||
const style::font &_titleFont;
|
||||
const style::margins &_titlePadding;
|
||||
object_ptr<Ui::FlatLabel> _about;
|
||||
Ui::Premium::MiniStars _ministars;
|
||||
Ui::Premium::ColoredMiniStars _ministars;
|
||||
QSvgRenderer _star;
|
||||
|
||||
struct {
|
||||
|
@ -850,7 +869,8 @@ private:
|
|||
float64 scaleTitle = 0.;
|
||||
} _progress;
|
||||
|
||||
QRectF _ministarsRect;
|
||||
bool _isDark = false;
|
||||
|
||||
QRectF _starRect;
|
||||
|
||||
QPoint _titlePosition;
|
||||
|
@ -867,8 +887,7 @@ TopBar::TopBar(
|
|||
, _titleFont(st::boxTitle.style.font)
|
||||
, _titlePadding(st::settingsPremiumTitlePadding)
|
||||
, _about(this, std::move(about), st::settingsPremiumAbout)
|
||||
, _ministars([=](const QRect &r) { update(r); })
|
||||
, _star(Svg()) {
|
||||
, _ministars(this) {
|
||||
std::move(
|
||||
title
|
||||
) | rpl::start_with_next([=](QString text) {
|
||||
|
@ -889,6 +908,27 @@ TopBar::TopBar(
|
|||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
rpl::single(
|
||||
rpl::empty_value()
|
||||
) | rpl::then(
|
||||
style::PaletteChanged()
|
||||
) | rpl::start_with_next([=] {
|
||||
const auto contrast = Ui::CountContrast(
|
||||
st::boxBg->c,
|
||||
st::premiumButtonFg->c);
|
||||
_isDark = (contrast > kMinAcceptableContrast);
|
||||
|
||||
if (!_isDark) {
|
||||
_star.load(Svg());
|
||||
_ministars.setColorOverride(st::premiumButtonFg->c);
|
||||
} else {
|
||||
_star.load(ColorizedSvg());
|
||||
_ministars.setColorOverride(std::nullopt);
|
||||
}
|
||||
auto event = QResizeEvent(size(), size());
|
||||
resizeEvent(&event);
|
||||
}, lifetime());
|
||||
}
|
||||
|
||||
void TopBar::setPaused(bool paused) {
|
||||
|
@ -911,7 +951,8 @@ void TopBar::resizeEvent(QResizeEvent *e) {
|
|||
_progress.title = 1. - progress;
|
||||
_progress.scaleTitle = 1. + kTitleAdditionalScale * progress;
|
||||
|
||||
_ministarsRect = starRect(_progress.top, 1.);
|
||||
_ministars.setCenter(starRect(_progress.top, 1.).toRect());
|
||||
|
||||
_starRect = starRect(_progress.top, _progress.body);
|
||||
|
||||
const auto &padding = st::boxRowPadding;
|
||||
|
@ -937,22 +978,26 @@ void TopBar::paintEvent(QPaintEvent *e) {
|
|||
|
||||
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);
|
||||
if (!_isDark) {
|
||||
const auto gradientPointTop = r.height() / 3. * 2.;
|
||||
auto gradient = QLinearGradient(
|
||||
QPointF(0, gradientPointTop),
|
||||
QPointF(r.width(), r.height() - gradientPointTop));
|
||||
gradient.setStops(Ui::Premium::ButtonGradientStops());
|
||||
|
||||
TopBarAbstract::paintEdges(p, gradient);
|
||||
TopBarAbstract::paintEdges(p, gradient);
|
||||
} else {
|
||||
TopBarAbstract::paintEdges(p, st::boxBg);
|
||||
TopBarAbstract::paintEdges(p, st::shadowFg);
|
||||
TopBarAbstract::paintEdges(p, st::shadowFg);
|
||||
}
|
||||
|
||||
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);
|
||||
_ministars.paint(p);
|
||||
}
|
||||
p.resetTransform();
|
||||
|
||||
|
|
|
@ -1063,7 +1063,7 @@ void AddGiftOptions(
|
|||
p.drawRoundedRect(borderRect, round, round);
|
||||
}
|
||||
|
||||
p.setPen(st::boxBg);
|
||||
p.setPen(st::premiumButtonFg);
|
||||
p.setFont(discountFont);
|
||||
p.drawText(discountRect, info.discount, style::al_center);
|
||||
|
||||
|
|
|
@ -29,11 +29,15 @@ void ColoredMiniStars::setSize(const QSize &size) {
|
|||
_mask.fill(Qt::transparent);
|
||||
{
|
||||
Painter p(&_mask);
|
||||
auto gradient = QLinearGradient(0, 0, size.width(), 0);
|
||||
gradient.setStops(Ui::Premium::GiftGradientStops());
|
||||
p.setPen(Qt::NoPen);
|
||||
p.setBrush(gradient);
|
||||
p.drawRect(0, 0, size.width(), size.height());
|
||||
if (_colorOverride) {
|
||||
p.fillRect(0, 0, size.width(), size.height(), *_colorOverride);
|
||||
} else {
|
||||
auto gradient = QLinearGradient(0, 0, size.width(), 0);
|
||||
gradient.setStops(Ui::Premium::GiftGradientStops());
|
||||
p.setPen(Qt::NoPen);
|
||||
p.setBrush(gradient);
|
||||
p.drawRect(0, 0, size.width(), size.height());
|
||||
}
|
||||
}
|
||||
|
||||
_size = size;
|
||||
|
@ -53,6 +57,10 @@ void ColoredMiniStars::setPosition(QPoint position) {
|
|||
_position = std::move(position);
|
||||
}
|
||||
|
||||
void ColoredMiniStars::setColorOverride(std::optional<QColor> color) {
|
||||
_colorOverride = color;
|
||||
}
|
||||
|
||||
void ColoredMiniStars::paint(Painter &p) {
|
||||
_frame.fill(Qt::transparent);
|
||||
{
|
||||
|
@ -69,5 +77,17 @@ void ColoredMiniStars::setPaused(bool paused) {
|
|||
_ministars.setPaused(paused);
|
||||
}
|
||||
|
||||
void ColoredMiniStars::setCenter(const QRect &rect) {
|
||||
const auto center = rect.center();
|
||||
const auto size = QSize(
|
||||
rect.width() * Ui::Premium::MiniStars::kSizeFactor,
|
||||
rect.height());
|
||||
const auto ministarsRect = QRect(
|
||||
QPoint(center.x() - size.width(), center.y() - size.height()),
|
||||
QPoint(center.x() + size.width(), center.y() + size.height()));
|
||||
setPosition(ministarsRect.topLeft());
|
||||
setSize(ministarsRect.size());
|
||||
}
|
||||
|
||||
} // namespace Premium
|
||||
} // namespace Ui
|
||||
|
|
|
@ -20,6 +20,8 @@ public:
|
|||
|
||||
void setSize(const QSize &size);
|
||||
void setPosition(QPoint position);
|
||||
void setColorOverride(std::optional<QColor> color);
|
||||
void setCenter(const QRect &rect);
|
||||
void paint(Painter &p);
|
||||
|
||||
void setPaused(bool paused);
|
||||
|
@ -31,6 +33,7 @@ private:
|
|||
QImage _mask;
|
||||
QSize _size;
|
||||
QPoint _position;
|
||||
std::optional<QColor> _colorOverride;
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue