mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 21:57:10 +02:00
Moved out badge for giveaway list to td_ui.
This commit is contained in:
parent
474fa56cc0
commit
4150cdff86
4 changed files with 99 additions and 54 deletions
67
Telegram/SourceFiles/info/boosts/giveaway/boost_badge.cpp
Normal file
67
Telegram/SourceFiles/info/boosts/giveaway/boost_badge.cpp
Normal file
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
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 "info/boosts/giveaway/boost_badge.h"
|
||||
|
||||
#include "ui/painter.h"
|
||||
#include "ui/rect.h"
|
||||
|
||||
namespace Info::Statistics {
|
||||
|
||||
QImage CreateBadge(
|
||||
const style::TextStyle &textStyle,
|
||||
const QString &text,
|
||||
int badgeHeight,
|
||||
const style::margins &textPadding,
|
||||
const style::color &bg,
|
||||
const style::color &fg,
|
||||
float64 bgOpacity,
|
||||
const style::margins &iconPadding,
|
||||
const style::icon &icon) {
|
||||
auto badgeText = Ui::Text::String(textStyle, text);
|
||||
const auto badgeTextWidth = badgeText.maxWidth();
|
||||
const auto badgex = 0;
|
||||
const auto badgey = 0;
|
||||
const auto badgeh = 0 + badgeHeight;
|
||||
const auto badgew = badgeTextWidth
|
||||
+ rect::m::sum::h(textPadding);
|
||||
auto result = QImage(
|
||||
QSize(badgew, badgeh) * style::DevicePixelRatio(),
|
||||
QImage::Format_ARGB32_Premultiplied);
|
||||
result.fill(Qt::transparent);
|
||||
result.setDevicePixelRatio(style::DevicePixelRatio());
|
||||
{
|
||||
auto p = Painter(&result);
|
||||
|
||||
p.setPen(Qt::NoPen);
|
||||
p.setBrush(bg);
|
||||
|
||||
const auto r = QRect(badgex, badgey, badgew, badgeh);
|
||||
{
|
||||
auto hq = PainterHighQualityEnabler(p);
|
||||
auto o = ScopedPainterOpacity(p, bgOpacity);
|
||||
p.drawRoundedRect(r, badgeh / 2, badgeh / 2);
|
||||
}
|
||||
|
||||
p.setPen(fg);
|
||||
p.setBrush(Qt::NoBrush);
|
||||
badgeText.drawLeftElided(
|
||||
p,
|
||||
r.x() + textPadding.left(),
|
||||
badgey + textPadding.top(),
|
||||
badgew,
|
||||
badgew * 2);
|
||||
|
||||
icon.paint(
|
||||
p,
|
||||
QPoint(r.x() + iconPadding.left(), r.y() + iconPadding.top()),
|
||||
badgew * 2);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace Info::Statistics
|
27
Telegram/SourceFiles/info/boosts/giveaway/boost_badge.h
Normal file
27
Telegram/SourceFiles/info/boosts/giveaway/boost_badge.h
Normal file
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
namespace style {
|
||||
struct TextStyle;
|
||||
} // namespace style
|
||||
|
||||
namespace Info::Statistics {
|
||||
|
||||
[[nodiscard]] QImage CreateBadge(
|
||||
const style::TextStyle &textStyle,
|
||||
const QString &text,
|
||||
int badgeHeight,
|
||||
const style::margins &textPadding,
|
||||
const style::color &bg,
|
||||
const style::color &fg,
|
||||
float64 bgOpacity,
|
||||
const style::margins &iconPadding,
|
||||
const style::icon &icon);
|
||||
|
||||
} // namespace Info::Statistics
|
|
@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "data/data_session.h"
|
||||
#include "data/data_user.h"
|
||||
#include "history/history_item.h"
|
||||
#include "info/boosts/giveaway/boost_badge.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "main/main_session.h"
|
||||
#include "settings/settings_common.h"
|
||||
|
@ -35,58 +36,6 @@ using BoostCallback = Fn<void(const Data::Boost &)>;
|
|||
constexpr auto kColorIndexUnclaimed = int(3);
|
||||
constexpr auto kColorIndexPending = int(4);
|
||||
|
||||
[[nodiscard]] QImage Badge(
|
||||
const style::TextStyle &textStyle,
|
||||
const QString &text,
|
||||
int badgeHeight,
|
||||
const style::margins &textPadding,
|
||||
const style::color &bg,
|
||||
const style::color &fg,
|
||||
float64 bgOpacity,
|
||||
const style::margins &iconPadding,
|
||||
const style::icon &icon) {
|
||||
auto badgeText = Ui::Text::String(textStyle, text);
|
||||
const auto badgeTextWidth = badgeText.maxWidth();
|
||||
const auto badgex = 0;
|
||||
const auto badgey = 0;
|
||||
const auto badgeh = 0 + badgeHeight;
|
||||
const auto badgew = badgeTextWidth
|
||||
+ rect::m::sum::h(textPadding);
|
||||
auto result = QImage(
|
||||
QSize(badgew, badgeh) * style::DevicePixelRatio(),
|
||||
QImage::Format_ARGB32_Premultiplied);
|
||||
result.fill(Qt::transparent);
|
||||
result.setDevicePixelRatio(style::DevicePixelRatio());
|
||||
{
|
||||
auto p = Painter(&result);
|
||||
|
||||
p.setPen(Qt::NoPen);
|
||||
p.setBrush(bg);
|
||||
|
||||
const auto r = QRect(badgex, badgey, badgew, badgeh);
|
||||
{
|
||||
auto hq = PainterHighQualityEnabler(p);
|
||||
auto o = ScopedPainterOpacity(p, bgOpacity);
|
||||
p.drawRoundedRect(r, badgeh / 2, badgeh / 2);
|
||||
}
|
||||
|
||||
p.setPen(fg);
|
||||
p.setBrush(Qt::NoBrush);
|
||||
badgeText.drawLeftElided(
|
||||
p,
|
||||
r.x() + textPadding.left(),
|
||||
badgey + textPadding.top(),
|
||||
badgew,
|
||||
badgew * 2);
|
||||
|
||||
icon.paint(
|
||||
p,
|
||||
QPoint(r.x() + iconPadding.left(), r.y() + iconPadding.top()),
|
||||
badgew * 2);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void AddArrow(not_null<Ui::RpWidget*> parent) {
|
||||
const auto arrow = Ui::CreateChild<Ui::RpWidget>(parent.get());
|
||||
arrow->paintRequest(
|
||||
|
@ -486,7 +435,7 @@ PaintRoundImageCallback BoostRow::generatePaintUserpicCallback(bool force) {
|
|||
|
||||
void BoostRow::invalidateBadges() {
|
||||
_badge = _boost.multiplier
|
||||
? Badge(
|
||||
? CreateBadge(
|
||||
st::statisticsDetailsBottomCaptionStyle,
|
||||
QString::number(_boost.multiplier),
|
||||
st::boostsListBadgeHeight,
|
||||
|
@ -506,7 +455,7 @@ void BoostRow::invalidateBadges() {
|
|||
? st::boostsListGiveawayMiniIcon
|
||||
: st::boostsListGiftMiniIcon;
|
||||
_rightBadge = (_boost.isGift || _boost.isGiveaway)
|
||||
? Badge(
|
||||
? CreateBadge(
|
||||
st::boostsListRightBadgeTextStyle,
|
||||
_boost.isGiveaway
|
||||
? tr::lng_gift_link_reason_giveaway(tr::now)
|
||||
|
|
|
@ -110,6 +110,8 @@ PRIVATE
|
|||
info/userpic/info_userpic_emoji_builder_layer.cpp
|
||||
info/userpic/info_userpic_emoji_builder_layer.h
|
||||
|
||||
info/boosts/giveaway/boost_badge.cpp
|
||||
info/boosts/giveaway/boost_badge.h
|
||||
info/boosts/giveaway/giveaway_type_row.cpp
|
||||
info/boosts/giveaway/giveaway_type_row.h
|
||||
info/boosts/giveaway/select_countries_box.cpp
|
||||
|
|
Loading…
Add table
Reference in a new issue