mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +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 "lang/lang_keys.h"
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
#include "main/session/session_show.h"
|
#include "main/session/session_show.h"
|
||||||
|
#include "settings/settings_credits_graphics.h" // PaintSubscriptionRightLabelCallback
|
||||||
#include "ui/effects/credits_graphics.h"
|
#include "ui/effects/credits_graphics.h"
|
||||||
#include "ui/effects/outline_segments.h" // Ui::UnreadStoryOutlineGradient.
|
#include "ui/effects/outline_segments.h" // Ui::UnreadStoryOutlineGradient.
|
||||||
#include "ui/effects/toggle_arrow.h"
|
#include "ui/effects/toggle_arrow.h"
|
||||||
|
@ -758,6 +759,7 @@ private:
|
||||||
const int _rowHeight;
|
const int _rowHeight;
|
||||||
|
|
||||||
PaintRoundImageCallback _paintUserpicCallback;
|
PaintRoundImageCallback _paintUserpicCallback;
|
||||||
|
std::optional<Settings::SubscriptionRightLabel> _rightLabel;
|
||||||
QString _title;
|
QString _title;
|
||||||
QString _name;
|
QString _name;
|
||||||
|
|
||||||
|
@ -782,6 +784,14 @@ CreditsRow::CreditsRow(
|
||||||
&_guard,
|
&_guard,
|
||||||
[this, update = descriptor.updateCallback] { update(this); }));
|
[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();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -843,14 +853,6 @@ void CreditsRow::init() {
|
||||||
.append(manager.creditsEmoji()),
|
.append(manager.creditsEmoji()),
|
||||||
kMarkupTextOptions,
|
kMarkupTextOptions,
|
||||||
_context);
|
_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) {
|
if (!_paintUserpicCallback) {
|
||||||
_paintUserpicCallback = !isSpecial
|
_paintUserpicCallback = !isSpecial
|
||||||
|
@ -876,7 +878,9 @@ PaintRoundImageCallback CreditsRow::generatePaintUserpicCallback(bool force) {
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize CreditsRow::rightActionSize() const {
|
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
|
const auto text = _subscription.cancelled
|
||||||
? tr::lng_credits_subscription_status_off_right(tr::now)
|
? tr::lng_credits_subscription_status_off_right(tr::now)
|
||||||
: tr::lng_credits_subscription_status_none_right(tr::now);
|
: tr::lng_credits_subscription_status_none_right(tr::now);
|
||||||
|
@ -910,41 +914,20 @@ void CreditsRow::rightActionPaint(
|
||||||
bool actionSelected) {
|
bool actionSelected) {
|
||||||
const auto &font = _rightText.style()->font;
|
const auto &font = _rightText.style()->font;
|
||||||
const auto rightSkip = st::boxRowPadding.right();
|
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 &statusFont = st::contactsStatusFont;
|
||||||
const auto &st = st::boostsListBox.item;
|
y += _rowHeight / 2;
|
||||||
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);
|
|
||||||
p.setFont(statusFont);
|
p.setFont(statusFont);
|
||||||
|
p.setPen(st::attentionButtonFg);
|
||||||
p.drawTextRight(
|
p.drawTextRight(
|
||||||
rightSkip,
|
rightSkip,
|
||||||
y + _rowHeight - skip - statusFont->height,
|
y - statusFont->height / 2,
|
||||||
outerWidth,
|
outerWidth,
|
||||||
tr::lng_group_invite_joined_right(tr::now));
|
_subscription.expired
|
||||||
|
? tr::lng_credits_subscription_status_none_right(tr::now)
|
||||||
p.setPen(st.nameFg);
|
: tr::lng_credits_subscription_status_off_right(tr::now));
|
||||||
_rightText.draw(p, Ui::Text::PaintContext{
|
|
||||||
.position = QPoint(
|
|
||||||
outerWidth - _rightText.maxWidth() - rightSkip,
|
|
||||||
y + skip),
|
|
||||||
.outerWidth = outerWidth,
|
|
||||||
.availableWidth = outerWidth,
|
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
y += _rowHeight / 2;
|
y += _rowHeight / 2;
|
||||||
|
|
|
@ -233,6 +233,51 @@ void AddViewMediaHandler(
|
||||||
|
|
||||||
} // namespace
|
} // 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(
|
void FillCreditOptions(
|
||||||
std::shared_ptr<Main::SessionShow> show,
|
std::shared_ptr<Main::SessionShow> show,
|
||||||
not_null<Ui::VerticalLayout*> container,
|
not_null<Ui::VerticalLayout*> container,
|
||||||
|
|
|
@ -18,6 +18,7 @@ struct SubscriptionEntry;
|
||||||
} // namespace Data
|
} // namespace Data
|
||||||
|
|
||||||
namespace Main {
|
namespace Main {
|
||||||
|
class Session;
|
||||||
class SessionShow;
|
class SessionShow;
|
||||||
} // namespace Main
|
} // namespace Main
|
||||||
|
|
||||||
|
@ -25,6 +26,10 @@ namespace Window {
|
||||||
class SessionController;
|
class SessionController;
|
||||||
} // namespace Window
|
} // namespace Window
|
||||||
|
|
||||||
|
namespace style {
|
||||||
|
struct PeerListItem;
|
||||||
|
} // namespace style
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class GenericBox;
|
class GenericBox;
|
||||||
class RpWidget;
|
class RpWidget;
|
||||||
|
@ -33,6 +38,15 @@ class VerticalLayout;
|
||||||
|
|
||||||
namespace Settings {
|
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(
|
void FillCreditOptions(
|
||||||
std::shared_ptr<Main::SessionShow> show,
|
std::shared_ptr<Main::SessionShow> show,
|
||||||
not_null<Ui::VerticalLayout*> container,
|
not_null<Ui::VerticalLayout*> container,
|
||||||
|
|
Loading…
Add table
Reference in a new issue