Support custom icon for General topic.

This commit is contained in:
John Preston 2022-11-29 17:25:18 +04:00
parent 57af221d39
commit ac3834bfdb
5 changed files with 79 additions and 8 deletions

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="20px" height="20px" viewBox="0 0 20 20" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>general</title>
<g id="general" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<path d="M14.4576257,1.02558449 C15.189053,1.1696007 15.6657078,1.88165413 15.5222641,2.61600035 L14.8818905,5.62412405 L16.6504058,5.62421139 C17.3957661,5.62421139 18,6.23085664 18,6.97919149 C18,7.72752633 17.3957661,8.33417159 16.6504058,8.33417159 L14.3525674,8.33397488 L13.6850637,11.7513347 L15.3008116,11.7515071 C16.0461719,11.7515071 16.6504058,12.3581524 16.6504058,13.1064872 C16.6504058,13.8548221 16.0461719,14.4614673 15.3008116,14.4614673 L13.1557407,14.4614328 L12.4307242,17.9055215 C12.2872804,18.6398677 11.5780573,19.1184247 10.84663,18.9744085 C10.1152028,18.8303923 9.63854794,18.1183389 9.7819917,17.3839927 L10.4051821,14.4614328 L7.75733538,14.4614328 L7.03234733,17.9055215 C6.90989534,18.5324024 6.37514133,18.9728813 5.76623746,18.9987859 L5.71387199,19 C5.62631985,19.0002755 5.53745163,18.9919715 5.44825318,18.9744085 C4.71682589,18.8303923 4.24017107,18.1183389 4.38361482,17.3839927 L5.00702313,14.4614328 L3.34959422,14.4614673 C2.60423391,14.4614673 2,13.8548221 2,13.1064872 C2,12.3581524 2.60423391,11.7515071 3.34959422,11.7515071 L5.53634616,11.7513347 L6.20384986,8.33397488 L4.69918844,8.33417159 C3.95382813,8.33417159 3.34959422,7.72752633 3.34959422,6.97919149 C3.34959422,6.23085664 3.95382813,5.62421139 4.69918844,5.62421139 L6.73317289,5.62412405 L7.4751547,2.09447154 C7.60110532,1.44967974 8.16325465,1.00209364 8.79363004,1 L8.84631136,1.00087004 C8.91674267,1.00340951 8.98789009,1.01153413 9.05924885,1.02558449 C9.79067614,1.1696007 10.267331,1.88165413 10.1238872,2.61600035 L9.48348515,5.62412405 L12.1315782,5.62412405 L12.8735316,2.09447154 C13.0169753,1.36012532 13.7261984,0.881568286 14.4576257,1.02558449 Z M10.9345052,11.7513347 L11.6020089,8.33397488 L8.95416211,8.33397488 L8.28665842,11.7513347 L10.9345052,11.7513347 Z" id="Combined-Shape-Copy-6" fill="#FFFFFF"></path>
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -35,6 +35,7 @@
<file alias="topic_icons/rose.svg">../../art/topic_icons/rose.svg</file>
<file alias="topic_icons/red.svg">../../art/topic_icons/red.svg</file>
<file alias="topic_icons/gray.svg">../../art/topic_icons/gray.svg</file>
<file alias="topic_icons/general.svg">../../art/topic_icons/general.svg</file>
</qresource>
<qresource prefix="/icons">
<file alias="calls/hands.lottie">../../icons/calls/hands.lottie</file>

View File

@ -143,6 +143,24 @@ QImage ForumTopicIconFrame(
return background;
}
QImage ForumTopicGeneralIconFrame(int size, const style::color &color) {
const auto ratio = style::DevicePixelRatio();
auto svg = QSvgRenderer(ForumTopicIconPath(u"general"_q));
auto result = QImage(
QSize(size, size) * ratio,
QImage::Format_ARGB32_Premultiplied);
result.setDevicePixelRatio(ratio);
result.fill(Qt::transparent);
const auto use = size * 0.8;
const auto skip = size * 0.1;
auto p = QPainter(&result);
svg.render(&p, QRectF(skip, 0, use, use));
p.end();
return style::colorizeImage(result, color);
}
TextWithEntities ForumTopicIconWithTitle(
DocumentId iconId,
const QString &title) {
@ -185,6 +203,13 @@ ForumTopic::ForumTopic(not_null<Forum*> forum, MsgId rootId)
previous.value_or(0),
previous.has_value()));
}, _replies->lifetime());
if (isGeneral()) {
style::PaletteChanged(
) | rpl::start_with_next([=] {
_defaultIcon = QImage();
}, _lifetime);
}
}
ForumTopic::~ForumTopic() {
@ -540,7 +565,11 @@ void ForumTopic::paintUserpic(
.paused = context.paused,
});
} else {
validateDefaultIcon();
if (isGeneral()) {
validateGeneralIcon(context);
} else {
validateDefaultIcon();
}
const auto size = st::defaultForumTopicIcon.size;
if (context.narrow) {
position = QPoint(
@ -562,12 +591,34 @@ void ForumTopic::clearUserpicLoops() {
}
void ForumTopic::validateDefaultIcon() const {
if (_defaultIcon.isNull()) {
_defaultIcon = ForumTopicIconFrame(
_colorId,
_title,
st::defaultForumTopicIcon);
if (!_defaultIcon.isNull()) {
return;
}
_defaultIcon = ForumTopicIconFrame(
_colorId,
_title,
st::defaultForumTopicIcon);
}
void ForumTopic::validateGeneralIcon(
const Dialogs::Ui::PaintContext &context) const {
const auto mask = Flag::GeneralIconActive | Flag::GeneralIconSelected;
const auto flags = context.active
? Flag::GeneralIconActive
: context.selected
? Flag::GeneralIconSelected
: Flag(0);
if (!_defaultIcon.isNull() && ((_flags & mask) == flags)) {
return;
}
const auto size = st::defaultForumTopicIcon.size;
const auto &color = context.active
? st::dialogsTextFgActive
: context.selected
? st::dialogsTextFgOver
: st::dialogsTextFg;
_defaultIcon = ForumTopicGeneralIconFrame(size, color);
_flags = (_flags & ~mask) | flags;
}
void ForumTopic::requestChatListMessage() {

View File

@ -45,6 +45,9 @@ class Forum;
int32 colorId,
const QString &title,
const style::ForumTopicIcon &st);
[[nodiscard]] QImage ForumTopicGeneralIconFrame(
int size,
const style::color &color);
[[nodiscard]] TextWithEntities ForumTopicIconWithTitle(
DocumentId iconId,
const QString &title);
@ -160,12 +163,15 @@ private:
Closed = (1 << 0),
My = (1 << 1),
HasPinnedMessages = (1 << 2),
GeneralIconActive = (1 << 3),
GeneralIconSelected = (1 << 4),
};
friend inline constexpr bool is_flag_type(Flag) { return true; }
using Flags = base::flags<Flag>;
void indexTitleParts();
void validateDefaultIcon() const;
void validateGeneralIcon(const Dialogs::Ui::PaintContext &context) const;
void applyTopicTopMessage(MsgId topMessageId);
void growLastKnownServerMessageId(MsgId id);
@ -197,7 +203,7 @@ private:
TimeId _creationDate = 0;
int _titleVersion = 0;
int32 _colorId = 0;
Flags _flags;
mutable Flags _flags;
std::unique_ptr<Ui::Text::CustomEmoji> _icon;
mutable QImage _defaultIcon; // on-demand

View File

@ -216,11 +216,17 @@ void TopicIconView::setupPlayer(not_null<Data::ForumTopic*> topic) {
}
void TopicIconView::setupImage(not_null<Data::ForumTopic*> topic) {
using namespace Data;
if (topic->isGeneral()) {
_image = ForumTopicGeneralIconFrame(
st::infoForumTopicIcon.size,
st::windowSubTextFg);
return;
}
rpl::combine(
TitleValue(topic),
ColorIdValue(topic)
) | rpl::map([=](const QString &title, int32 colorId) {
using namespace Data;
return ForumTopicIconFrame(colorId, title, st::infoForumTopicIcon);
}) | rpl::start_with_next([=](QImage &&image) {
_image = std::move(image);