mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-14 13:17:08 +02:00
Moved out colorizing of svg star to td_ui.
This commit is contained in:
parent
811d75e383
commit
bef216bc93
5 changed files with 71 additions and 71 deletions
|
@ -54,7 +54,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/boxes/boost_box.h"
|
||||
#include "ui/controls/emoji_button.h"
|
||||
#include "ui/controls/userpic_button.h"
|
||||
#include "ui/effects/premium_top_bar.h"
|
||||
#include "ui/effects/premium_graphics.h"
|
||||
#include "ui/rect.h"
|
||||
#include "ui/rp_widget.h"
|
||||
#include "ui/vertical_list.h"
|
||||
|
|
|
@ -27,7 +27,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "styles/style_settings.h"
|
||||
#include "styles/style_window.h"
|
||||
|
||||
#include <QtCore/QFile>
|
||||
#include <QtGui/QBrush>
|
||||
#include <QtSvg/QSvgRenderer>
|
||||
|
||||
namespace Ui {
|
||||
namespace Premium {
|
||||
|
@ -903,6 +905,70 @@ void Line::recache(const QSize &s) {
|
|||
|
||||
} // namespace
|
||||
|
||||
QString Svg() {
|
||||
return u":/gui/icons/settings/star.svg"_q;
|
||||
}
|
||||
|
||||
QByteArray ColorizedSvg(const QGradientStops &gradientStops) {
|
||||
auto f = QFile(Svg());
|
||||
if (!f.open(QIODevice::ReadOnly)) {
|
||||
return QByteArray();
|
||||
}
|
||||
auto content = QString::fromUtf8(f.readAll());
|
||||
auto stops = [&] {
|
||||
auto s = QString();
|
||||
for (const auto &stop : gradientStops) {
|
||||
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();
|
||||
}
|
||||
|
||||
QImage GenerateStarForLightTopBar(QRectF rect) {
|
||||
auto svg = QSvgRenderer(Ui::Premium::Svg());
|
||||
|
||||
const auto size = rect.size().toSize();
|
||||
auto frame = QImage(
|
||||
size * style::DevicePixelRatio(),
|
||||
QImage::Format_ARGB32_Premultiplied);
|
||||
frame.setDevicePixelRatio(style::DevicePixelRatio());
|
||||
|
||||
auto mask = frame;
|
||||
mask.fill(Qt::transparent);
|
||||
{
|
||||
auto p = QPainter(&mask);
|
||||
auto gradient = QLinearGradient(
|
||||
0,
|
||||
size.height(),
|
||||
size.width(),
|
||||
0);
|
||||
gradient.setStops(Ui::Premium::ButtonGradientStops());
|
||||
p.setPen(Qt::NoPen);
|
||||
p.setBrush(gradient);
|
||||
p.drawRect(0, 0, size.width(), size.height());
|
||||
}
|
||||
frame.fill(Qt::transparent);
|
||||
{
|
||||
auto q = QPainter(&frame);
|
||||
svg.render(&q, QRect(QPoint(), size));
|
||||
q.setCompositionMode(QPainter::CompositionMode_SourceIn);
|
||||
q.drawImage(0, 0, mask);
|
||||
}
|
||||
return frame;
|
||||
}
|
||||
|
||||
void AddBubbleRow(
|
||||
not_null<Ui::VerticalLayout*> parent,
|
||||
const style::PremiumBubble &st,
|
||||
|
|
|
@ -41,6 +41,10 @@ namespace Premium {
|
|||
|
||||
inline constexpr auto kLimitRowRatio = 0.5;
|
||||
|
||||
[[nodiscard]] QString Svg();
|
||||
[[nodiscard]] QByteArray ColorizedSvg(const QGradientStops &gradientStops);
|
||||
[[nodiscard]] QImage GenerateStarForLightTopBar(QRectF rect);
|
||||
|
||||
void AddBubbleRow(
|
||||
not_null<Ui::VerticalLayout*> parent,
|
||||
const style::PremiumBubble &st,
|
||||
|
|
|
@ -16,8 +16,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "styles/style_settings.h"
|
||||
#include "styles/style_premium.h"
|
||||
|
||||
#include <QtCore/QFile>
|
||||
|
||||
namespace Ui::Premium {
|
||||
namespace {
|
||||
|
||||
|
@ -42,70 +40,6 @@ constexpr auto kMinAcceptableContrast = 4.5; // 1.14;
|
|||
|
||||
} // namespace
|
||||
|
||||
QString Svg() {
|
||||
return u":/gui/icons/settings/star.svg"_q;
|
||||
}
|
||||
|
||||
QByteArray ColorizedSvg(const QGradientStops &gradientStops) {
|
||||
auto f = QFile(Svg());
|
||||
if (!f.open(QIODevice::ReadOnly)) {
|
||||
return QByteArray();
|
||||
}
|
||||
auto content = QString::fromUtf8(f.readAll());
|
||||
auto stops = [&] {
|
||||
auto s = QString();
|
||||
for (const auto &stop : gradientStops) {
|
||||
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();
|
||||
}
|
||||
|
||||
QImage GenerateStarForLightTopBar(QRectF rect) {
|
||||
auto svg = QSvgRenderer(Ui::Premium::Svg());
|
||||
|
||||
const auto size = rect.size().toSize();
|
||||
auto frame = QImage(
|
||||
size * style::DevicePixelRatio(),
|
||||
QImage::Format_ARGB32_Premultiplied);
|
||||
frame.setDevicePixelRatio(style::DevicePixelRatio());
|
||||
|
||||
auto mask = frame;
|
||||
mask.fill(Qt::transparent);
|
||||
{
|
||||
auto p = QPainter(&mask);
|
||||
auto gradient = QLinearGradient(
|
||||
0,
|
||||
size.height(),
|
||||
size.width(),
|
||||
0);
|
||||
gradient.setStops(Ui::Premium::ButtonGradientStops());
|
||||
p.setPen(Qt::NoPen);
|
||||
p.setBrush(gradient);
|
||||
p.drawRect(0, 0, size.width(), size.height());
|
||||
}
|
||||
frame.fill(Qt::transparent);
|
||||
{
|
||||
auto q = QPainter(&frame);
|
||||
svg.render(&q, QRect(QPoint(), size));
|
||||
q.setCompositionMode(QPainter::CompositionMode_SourceIn);
|
||||
q.drawImage(0, 0, mask);
|
||||
}
|
||||
return frame;
|
||||
}
|
||||
|
||||
TopBarAbstract::TopBarAbstract(
|
||||
QWidget *parent,
|
||||
const style::PremiumCover &st)
|
||||
|
|
|
@ -25,10 +25,6 @@ class FlatLabel;
|
|||
|
||||
namespace Ui::Premium {
|
||||
|
||||
[[nodiscard]] QString Svg();
|
||||
[[nodiscard]] QByteArray ColorizedSvg(const QGradientStops &gradientStops);
|
||||
[[nodiscard]] QImage GenerateStarForLightTopBar(QRectF rect);
|
||||
|
||||
class TopBarAbstract : public RpWidget {
|
||||
public:
|
||||
TopBarAbstract(
|
||||
|
|
Loading…
Add table
Reference in a new issue