diff --git a/Telegram/SourceFiles/api/api_chat_invite.cpp b/Telegram/SourceFiles/api/api_chat_invite.cpp index 50bdaf4f04..ea5f2771c5 100644 --- a/Telegram/SourceFiles/api/api_chat_invite.cpp +++ b/Telegram/SourceFiles/api/api_chat_invite.cpp @@ -241,7 +241,7 @@ ConfirmInviteBox::ConfirmInviteBox( } } else { _photoEmpty = std::make_unique( - Data::PeerUserpicColor(0), + Ui::PeerUserpicColor(0), invite.title); } } diff --git a/Telegram/SourceFiles/boxes/filters/edit_filter_chats_list.cpp b/Telegram/SourceFiles/boxes/filters/edit_filter_chats_list.cpp index 5874ab8739..4e4507a464 100644 --- a/Telegram/SourceFiles/boxes/filters/edit_filter_chats_list.cpp +++ b/Telegram/SourceFiles/boxes/filters/edit_filter_chats_list.cpp @@ -248,7 +248,7 @@ void PaintFilterChatsTypeIcon( int y, int outerWidth, int size) { - const auto &color = [&]() -> const style::color& { + const auto &color1 = [&]() -> const style::color& { switch (flag) { case Flag::Contacts: return st::historyPeer4UserpicBg; case Flag::NonContacts: return st::historyPeer7UserpicBg; @@ -261,6 +261,19 @@ void PaintFilterChatsTypeIcon( } Unexpected("Flag in color paintFlagIcon."); }(); + const auto &color2 = [&]() -> const style::color& { + switch (flag) { + case Flag::Contacts: return st::historyPeer4UserpicBg2; + case Flag::NonContacts: return st::historyPeer7UserpicBg2; + case Flag::Groups: return st::historyPeer2UserpicBg2; + case Flag::Channels: return st::historyPeer1UserpicBg2; + case Flag::Bots: return st::historyPeer6UserpicBg2; + case Flag::NoMuted: return st::historyPeer6UserpicBg2; + case Flag::NoArchived: return st::historyPeer4UserpicBg2; + case Flag::NoRead: return st::historyPeer7UserpicBg2; + } + Unexpected("Flag in color paintFlagIcon."); + }(); const auto &icon = [&]() -> const style::icon& { switch (flag) { case Flag::Contacts: return st::windowFilterTypeContacts; @@ -276,7 +289,9 @@ void PaintFilterChatsTypeIcon( }(); const auto rect = style::rtlrect(x, y, size, size, outerWidth); auto hq = PainterHighQualityEnabler(p); - p.setBrush(color->b); + auto bg = QLinearGradient(x, y, x, y + size); + bg.setStops({ { 0., color1->c }, { 1., color2->c } }); + p.setBrush(bg); p.setPen(Qt::NoPen); p.drawEllipse(rect); icon.paintInCenter(p, rect); diff --git a/Telegram/SourceFiles/calls/calls_userpic.cpp b/Telegram/SourceFiles/calls/calls_userpic.cpp index 1a47e8f36c..4cd10d1c8d 100644 --- a/Telegram/SourceFiles/calls/calls_userpic.cpp +++ b/Telegram/SourceFiles/calls/calls_userpic.cpp @@ -197,7 +197,7 @@ void Userpic::createCache(Image *image) { { auto p = QPainter(&filled); Ui::EmptyUserpic( - Data::PeerUserpicColor(_peer->id), + Ui::PeerUserpicColor(_peer->id), _peer->name() ).paint(p, 0, 0, size, size); } diff --git a/Telegram/SourceFiles/data/data_peer.cpp b/Telegram/SourceFiles/data/data_peer.cpp index 28901d3a2b..5f20faf690 100644 --- a/Telegram/SourceFiles/data/data_peer.cpp +++ b/Telegram/SourceFiles/data/data_peer.cpp @@ -69,20 +69,6 @@ int PeerColorIndex(PeerId peerId) { return PeerColorIndex(peerId.value & PeerId::kChatTypeMask); } -style::color PeerUserpicColor(PeerId peerId) { - const style::color colors[] = { - st::historyPeer1UserpicBg, - st::historyPeer2UserpicBg, - st::historyPeer3UserpicBg, - st::historyPeer4UserpicBg, - st::historyPeer5UserpicBg, - st::historyPeer6UserpicBg, - st::historyPeer7UserpicBg, - st::historyPeer8UserpicBg, - }; - return colors[PeerColorIndex(peerId)]; -} - PeerId FakePeerIdForJustName(const QString &name) { constexpr auto kShift = (0xFEULL << 32); const auto base = name.isEmpty() @@ -250,7 +236,7 @@ not_null PeerData::ensureEmptyUserpic() const { if (!_userpicEmpty) { const auto user = asUser(); _userpicEmpty = std::make_unique( - Data::PeerUserpicColor(id), + Ui::PeerUserpicColor(id), user && user->isInaccessible() ? Ui::EmptyUserpic::InaccessibleName() : name()); diff --git a/Telegram/SourceFiles/data/data_peer.h b/Telegram/SourceFiles/data/data_peer.h index 22f3fdd8d4..7ffc167108 100644 --- a/Telegram/SourceFiles/data/data_peer.h +++ b/Telegram/SourceFiles/data/data_peer.h @@ -41,7 +41,6 @@ struct ReactionId; int PeerColorIndex(PeerId peerId); int PeerColorIndex(BareId bareId); -style::color PeerUserpicColor(PeerId peerId); // Must be used only for PeerColor-s. PeerId FakePeerIdForJustName(const QString &name); diff --git a/Telegram/SourceFiles/history/history_item_components.cpp b/Telegram/SourceFiles/history/history_item_components.cpp index 89ee220163..d903f47891 100644 --- a/Telegram/SourceFiles/history/history_item_components.cpp +++ b/Telegram/SourceFiles/history/history_item_components.cpp @@ -105,7 +105,7 @@ HiddenSenderInfo::HiddenSenderInfo(const QString &name, bool external) : name(name) , colorPeerId(Data::FakePeerIdForJustName(name)) , emptyUserpic( - Data::PeerUserpicColor(colorPeerId), + Ui::PeerUserpicColor(colorPeerId), (external ? Ui::EmptyUserpic::ExternalName() : name)) { diff --git a/Telegram/SourceFiles/history/view/media/history_view_contact.cpp b/Telegram/SourceFiles/history/view/media/history_view_contact.cpp index d0c1ac5157..46bb6b37a9 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_contact.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_contact.cpp @@ -122,7 +122,7 @@ QSize Contact::countOptimalSize() { } else { const auto full = _name.toString(); _photoEmpty = std::make_unique( - Data::PeerUserpicColor(_userId + Ui::PeerUserpicColor(_userId ? peerFromUser(_userId) : Data::FakePeerIdForJustName(full)), full); diff --git a/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.cpp b/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.cpp index 4b764bc257..f763bf30c7 100644 --- a/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.cpp @@ -158,11 +158,14 @@ Image *ItemBase::getResultThumb(Data::FileOrigin origin) const { QPixmap ItemBase::getResultContactAvatar(int width, int height) const { if (_result->_type == Result::Type::Contact) { auto result = Ui::EmptyUserpic( - Data::PeerUserpicColor(FakeChatId(BareId(qHash(_result->_id)))), + Ui::PeerUserpicColor(FakeChatId(BareId(qHash(_result->_id)))), _result->getLayoutTitle() ).generate(width); if (result.height() != height * cIntRetinaFactor()) { - result = result.scaled(QSize(width, height) * cIntRetinaFactor(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + result = result.scaled( + QSize(width, height) * cIntRetinaFactor(), + Qt::IgnoreAspectRatio, + Qt::SmoothTransformation); } return result; } diff --git a/Telegram/SourceFiles/ui/empty_userpic.cpp b/Telegram/SourceFiles/ui/empty_userpic.cpp index b5b90fd34d..a74293760d 100644 --- a/Telegram/SourceFiles/ui/empty_userpic.cpp +++ b/Telegram/SourceFiles/ui/empty_userpic.cpp @@ -210,8 +210,8 @@ template } // namespace -EmptyUserpic::EmptyUserpic(const style::color &color, const QString &name) -: _color(color) { +EmptyUserpic::EmptyUserpic(const BgColors &colors, const QString &name) +: _colors(colors) { fillString(name); } @@ -238,7 +238,14 @@ void EmptyUserpic::paint( font.setPixelSize(fontsize); PainterHighQualityEnabler hq(p); - p.setBrush(_color); + { + auto gradient = QLinearGradient(x, y, x, y + size); + gradient.setStops({ + { 0., _colors.color1->c }, + { 1., _colors.color2->c } + }); + p.setBrush(gradient); + } p.setPen(Qt::NoPen); paintBackground(); @@ -295,9 +302,13 @@ void EmptyUserpic::PaintSavedMessages( int y, int outerWidth, int size) { - const auto &bg = st::historyPeerSavedMessagesBg; + auto bg = QLinearGradient(x, y, x, y + size); + bg.setStops({ + { 0., st::historyPeerSavedMessagesBg->c }, + { 1., st::historyPeerSavedMessagesBg2->c } + }); const auto &fg = st::historyPeerUserpicFg; - PaintSavedMessages(p, x, y, outerWidth, size, bg, fg); + PaintSavedMessages(p, x, y, outerWidth, size, QBrush(bg), fg); } void EmptyUserpic::PaintSavedMessagesRounded( @@ -306,9 +317,13 @@ void EmptyUserpic::PaintSavedMessagesRounded( int y, int outerWidth, int size) { - const auto &bg = st::historyPeerSavedMessagesBg; + auto bg = QLinearGradient(x, y, x, y + size); + bg.setStops({ + { 0., st::historyPeerSavedMessagesBg->c }, + { 1., st::historyPeerSavedMessagesBg2->c } + }); const auto &fg = st::historyPeerUserpicFg; - PaintSavedMessagesRounded(p, x, y, outerWidth, size, bg, fg); + PaintSavedMessagesRounded(p, x, y, outerWidth, size, QBrush(bg), fg); } void EmptyUserpic::PaintSavedMessages( @@ -317,12 +332,12 @@ void EmptyUserpic::PaintSavedMessages( int y, int outerWidth, int size, - const style::color &bg, + QBrush bg, const style::color &fg) { x = rtl() ? (outerWidth - x - size) : x; PainterHighQualityEnabler hq(p); - p.setBrush(bg); + p.setBrush(std::move(bg)); p.setPen(Qt::NoPen); p.drawEllipse(x, y, size, size); @@ -335,12 +350,12 @@ void EmptyUserpic::PaintSavedMessagesRounded( int y, int outerWidth, int size, - const style::color &bg, + QBrush bg, const style::color &fg) { x = rtl() ? (outerWidth - x - size) : x; PainterHighQualityEnabler hq(p); - p.setBrush(bg); + p.setBrush(std::move(bg)); p.setPen(Qt::NoPen); p.drawRoundedRect(x, y, size, size, st::roundRadiusSmall, st::roundRadiusSmall); @@ -365,9 +380,13 @@ void EmptyUserpic::PaintRepliesMessages( int y, int outerWidth, int size) { - const auto &bg = st::historyPeerSavedMessagesBg; + auto bg = QLinearGradient(x, y, x, y + size); + bg.setStops({ + { 0., st::historyPeerSavedMessagesBg->c }, + { 1., st::historyPeerSavedMessagesBg2->c } + }); const auto &fg = st::historyPeerUserpicFg; - PaintRepliesMessages(p, x, y, outerWidth, size, bg, fg); + PaintRepliesMessages(p, x, y, outerWidth, size, QBrush(bg), fg); } void EmptyUserpic::PaintRepliesMessagesRounded( @@ -376,9 +395,13 @@ void EmptyUserpic::PaintRepliesMessagesRounded( int y, int outerWidth, int size) { - const auto &bg = st::historyPeerSavedMessagesBg; + auto bg = QLinearGradient(x, y, x, y + size); + bg.setStops({ + { 0., st::historyPeerSavedMessagesBg->c }, + { 1., st::historyPeerSavedMessagesBg2->c } + }); const auto &fg = st::historyPeerUserpicFg; - PaintRepliesMessagesRounded(p, x, y, outerWidth, size, bg, fg); + PaintRepliesMessagesRounded(p, x, y, outerWidth, size, QBrush(bg), fg); } void EmptyUserpic::PaintRepliesMessages( @@ -387,7 +410,7 @@ void EmptyUserpic::PaintRepliesMessages( int y, int outerWidth, int size, - const style::color &bg, + QBrush bg, const style::color &fg) { x = rtl() ? (outerWidth - x - size) : x; @@ -405,7 +428,7 @@ void EmptyUserpic::PaintRepliesMessagesRounded( int y, int outerWidth, int size, - const style::color &bg, + QBrush bg, const style::color &fg) { x = rtl() ? (outerWidth - x - size) : x; @@ -431,7 +454,7 @@ QPixmap EmptyUserpic::GenerateRepliesMessagesRounded(int size) { InMemoryKey EmptyUserpic::uniqueKey() const { const auto first = (uint64(0xFFFFFFFFU) << 32) - | anim::getPremultiplied(_color->c); + | anim::getPremultiplied(_colors.color1->c); auto second = uint64(0); memcpy(&second, _string.constData(), qMin(sizeof(second), _string.size() * sizeof(QChar))); return InMemoryKey(first, second); @@ -512,4 +535,18 @@ void EmptyUserpic::fillString(const QString &name) { EmptyUserpic::~EmptyUserpic() = default; +EmptyUserpic::BgColors PeerUserpicColor(PeerId peerId) { + const EmptyUserpic::BgColors colors[] = { + { st::historyPeer1UserpicBg, st::historyPeer1UserpicBg2 }, + { st::historyPeer2UserpicBg, st::historyPeer2UserpicBg2 }, + { st::historyPeer3UserpicBg, st::historyPeer3UserpicBg2 }, + { st::historyPeer4UserpicBg, st::historyPeer4UserpicBg2 }, + { st::historyPeer5UserpicBg, st::historyPeer5UserpicBg2 }, + { st::historyPeer6UserpicBg, st::historyPeer6UserpicBg2 }, + { st::historyPeer7UserpicBg, st::historyPeer7UserpicBg2 }, + { st::historyPeer8UserpicBg, st::historyPeer8UserpicBg2 }, + }; + return colors[Data::PeerColorIndex(peerId)]; +} + } // namespace Ui diff --git a/Telegram/SourceFiles/ui/empty_userpic.h b/Telegram/SourceFiles/ui/empty_userpic.h index e657e6a593..d20e6ef26d 100644 --- a/Telegram/SourceFiles/ui/empty_userpic.h +++ b/Telegram/SourceFiles/ui/empty_userpic.h @@ -11,10 +11,15 @@ namespace Ui { class EmptyUserpic { public: + struct BgColors { + const style::color color1; + const style::color color2; + }; + [[nodiscard]] static QString ExternalName(); [[nodiscard]] static QString InaccessibleName(); - EmptyUserpic(const style::color &color, const QString &name); + EmptyUserpic(const BgColors &colors, const QString &name); void paint( QPainter &p, @@ -56,7 +61,7 @@ public: int y, int outerWidth, int size, - const style::color &bg, + QBrush bg, const style::color &fg); static void PaintSavedMessagesRounded( QPainter &p, @@ -64,7 +69,7 @@ public: int y, int outerWidth, int size, - const style::color &bg, + QBrush bg, const style::color &fg); static QPixmap GenerateSavedMessages(int size); static QPixmap GenerateSavedMessagesRounded(int size); @@ -87,7 +92,7 @@ public: int y, int outerWidth, int size, - const style::color &bg, + QBrush bg, const style::color &fg); static void PaintRepliesMessagesRounded( QPainter &p, @@ -95,7 +100,7 @@ public: int y, int outerWidth, int size, - const style::color &bg, + QBrush bg, const style::color &fg); static QPixmap GenerateRepliesMessages(int size); static QPixmap GenerateRepliesMessagesRounded(int size); @@ -114,9 +119,11 @@ private: void fillString(const QString &name); - style::color _color; + const BgColors _colors; QString _string; }; +[[nodiscard]] EmptyUserpic::BgColors PeerUserpicColor(PeerId peerId); + } // namespace Ui diff --git a/Telegram/lib_ui b/Telegram/lib_ui index ff821bc3d7..eb285b14c7 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit ff821bc3d79761a2b801bd067d38d2a4d7f766e3 +Subproject commit eb285b14c70e0410cd155a58e7f3b1e4891820cd