mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 06:07:06 +02:00
Moved out drawing of label for subscription rows to single place.
This commit is contained in:
parent
4f7364b798
commit
457301493f
3 changed files with 81 additions and 39 deletions
|
@ -22,6 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "lang/lang_keys.h"
|
||||
#include "main/main_session.h"
|
||||
#include "main/session/session_show.h"
|
||||
#include "settings/settings_credits_graphics.h" // PaintSubscriptionRightLabelCallback
|
||||
#include "ui/effects/credits_graphics.h"
|
||||
#include "ui/effects/outline_segments.h" // Ui::UnreadStoryOutlineGradient.
|
||||
#include "ui/effects/toggle_arrow.h"
|
||||
|
@ -758,6 +759,7 @@ private:
|
|||
const int _rowHeight;
|
||||
|
||||
PaintRoundImageCallback _paintUserpicCallback;
|
||||
std::optional<Settings::SubscriptionRightLabel> _rightLabel;
|
||||
QString _title;
|
||||
QString _name;
|
||||
|
||||
|
@ -782,6 +784,14 @@ CreditsRow::CreditsRow(
|
|||
&_guard,
|
||||
[this, update = descriptor.updateCallback] { update(this); }));
|
||||
}
|
||||
if (!_subscription.cancelled
|
||||
&& !_subscription.expired
|
||||
&& _subscription.subscription) {
|
||||
_rightLabel = Settings::PaintSubscriptionRightLabelCallback(
|
||||
&peer->session(),
|
||||
st::boostsListBox.item,
|
||||
_subscription.subscription.credits);
|
||||
}
|
||||
init();
|
||||
}
|
||||
|
||||
|
@ -843,14 +853,6 @@ void CreditsRow::init() {
|
|||
.append(manager.creditsEmoji()),
|
||||
kMarkupTextOptions,
|
||||
_context);
|
||||
} else if (_subscription.subscription.credits && !isSpecial) {
|
||||
const auto peer = PeerListRow::peer();
|
||||
_rightText.setMarkedText(
|
||||
st::semiboldTextStyle,
|
||||
manager.creditsEmoji().append(
|
||||
Lang::FormatCountDecimal(_subscription.subscription.credits)),
|
||||
kMarkupTextOptions,
|
||||
_context);
|
||||
}
|
||||
if (!_paintUserpicCallback) {
|
||||
_paintUserpicCallback = !isSpecial
|
||||
|
@ -876,7 +878,9 @@ PaintRoundImageCallback CreditsRow::generatePaintUserpicCallback(bool force) {
|
|||
}
|
||||
|
||||
QSize CreditsRow::rightActionSize() const {
|
||||
if (_subscription.cancelled || _subscription.expired) {
|
||||
if (_rightLabel) {
|
||||
return _rightLabel->size;
|
||||
} else if (_subscription.cancelled || _subscription.expired) {
|
||||
const auto text = _subscription.cancelled
|
||||
? tr::lng_credits_subscription_status_off_right(tr::now)
|
||||
: tr::lng_credits_subscription_status_none_right(tr::now);
|
||||
|
@ -910,41 +914,20 @@ void CreditsRow::rightActionPaint(
|
|||
bool actionSelected) {
|
||||
const auto &font = _rightText.style()->font;
|
||||
const auto rightSkip = st::boxRowPadding.right();
|
||||
if (_subscription) {
|
||||
if (_rightLabel) {
|
||||
return _rightLabel->draw(p, x, y, _rowHeight);
|
||||
} else if (_subscription.cancelled || _subscription.expired) {
|
||||
const auto &statusFont = st::contactsStatusFont;
|
||||
const auto &st = st::boostsListBox.item;
|
||||
const auto textHeight = font->height + statusFont->height;
|
||||
const auto skip = (_rowHeight - textHeight) / 2;
|
||||
if (_subscription.cancelled || _subscription.expired) {
|
||||
y += _rowHeight / 2;
|
||||
p.setFont(statusFont);
|
||||
p.setPen(st::attentionButtonFg);
|
||||
p.drawTextRight(
|
||||
rightSkip,
|
||||
y - statusFont->height / 2,
|
||||
outerWidth,
|
||||
_subscription.expired
|
||||
? tr::lng_credits_subscription_status_none_right(tr::now)
|
||||
: tr::lng_credits_subscription_status_off_right(tr::now));
|
||||
return;
|
||||
}
|
||||
|
||||
p.setPen(st.statusFg);
|
||||
y += _rowHeight / 2;
|
||||
p.setFont(statusFont);
|
||||
p.setPen(st::attentionButtonFg);
|
||||
p.drawTextRight(
|
||||
rightSkip,
|
||||
y + _rowHeight - skip - statusFont->height,
|
||||
y - statusFont->height / 2,
|
||||
outerWidth,
|
||||
tr::lng_group_invite_joined_right(tr::now));
|
||||
|
||||
p.setPen(st.nameFg);
|
||||
_rightText.draw(p, Ui::Text::PaintContext{
|
||||
.position = QPoint(
|
||||
outerWidth - _rightText.maxWidth() - rightSkip,
|
||||
y + skip),
|
||||
.outerWidth = outerWidth,
|
||||
.availableWidth = outerWidth,
|
||||
});
|
||||
_subscription.expired
|
||||
? tr::lng_credits_subscription_status_none_right(tr::now)
|
||||
: tr::lng_credits_subscription_status_off_right(tr::now));
|
||||
return;
|
||||
}
|
||||
y += _rowHeight / 2;
|
||||
|
|
|
@ -233,6 +233,51 @@ void AddViewMediaHandler(
|
|||
|
||||
} // namespace
|
||||
|
||||
SubscriptionRightLabel PaintSubscriptionRightLabelCallback(
|
||||
not_null<Main::Session*> session,
|
||||
const style::PeerListItem &st,
|
||||
int amount) {
|
||||
const auto text = std::make_shared<Ui::Text::String>();
|
||||
text->setMarkedText(
|
||||
st::semiboldTextStyle,
|
||||
TextWithEntities()
|
||||
.append(session->data().customEmojiManager().creditsEmoji())
|
||||
.append(QChar::Space)
|
||||
.append(Lang::FormatCountDecimal(amount)),
|
||||
kMarkupTextOptions,
|
||||
Core::MarkedTextContext{
|
||||
.session = session,
|
||||
.customEmojiRepaint = [] {},
|
||||
});
|
||||
const auto &font = text->style()->font;
|
||||
const auto &statusFont = st::contactsStatusFont;
|
||||
const auto status = tr::lng_group_invite_joined_right(tr::now);
|
||||
const auto rightSkip = st::boxRowPadding.right();
|
||||
const auto statusWidth = statusFont->width(status);
|
||||
const auto size = QSize(
|
||||
std::max(text->maxWidth(), statusWidth) + rightSkip,
|
||||
font->height + statusFont->height);
|
||||
const auto statusX = size.width() - statusWidth;
|
||||
auto draw = [=](QPainter &p, int x, int y, int h) {
|
||||
p.setPen(st.statusFg);
|
||||
p.setFont(statusFont);
|
||||
const auto skip = y + (h - size.height()) / 2;
|
||||
p.drawText(
|
||||
x + statusX,
|
||||
font->height + statusFont->ascent + skip,
|
||||
status);
|
||||
|
||||
p.setPen(st.nameFg);
|
||||
const auto textWidth = text->maxWidth();
|
||||
text->draw(p, Ui::Text::PaintContext{
|
||||
.position = QPoint(x + size.width() - textWidth, skip),
|
||||
.outerWidth = textWidth,
|
||||
.availableWidth = textWidth,
|
||||
});
|
||||
};
|
||||
return { std::move(draw), size };
|
||||
}
|
||||
|
||||
void FillCreditOptions(
|
||||
std::shared_ptr<Main::SessionShow> show,
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
|
|
|
@ -18,6 +18,7 @@ struct SubscriptionEntry;
|
|||
} // namespace Data
|
||||
|
||||
namespace Main {
|
||||
class Session;
|
||||
class SessionShow;
|
||||
} // namespace Main
|
||||
|
||||
|
@ -25,6 +26,10 @@ namespace Window {
|
|||
class SessionController;
|
||||
} // namespace Window
|
||||
|
||||
namespace style {
|
||||
struct PeerListItem;
|
||||
} // namespace style
|
||||
|
||||
namespace Ui {
|
||||
class GenericBox;
|
||||
class RpWidget;
|
||||
|
@ -33,6 +38,15 @@ class VerticalLayout;
|
|||
|
||||
namespace Settings {
|
||||
|
||||
struct SubscriptionRightLabel {
|
||||
Fn<void(QPainter &, int x, int y, int h)> draw;
|
||||
QSize size;
|
||||
};
|
||||
SubscriptionRightLabel PaintSubscriptionRightLabelCallback(
|
||||
not_null<Main::Session*> session,
|
||||
const style::PeerListItem &st,
|
||||
int amount);
|
||||
|
||||
void FillCreditOptions(
|
||||
std::shared_ptr<Main::SessionShow> show,
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
|
|
Loading…
Add table
Reference in a new issue