diff --git a/Telegram/SourceFiles/info/profile/info_profile_top_bar.cpp b/Telegram/SourceFiles/info/profile/info_profile_top_bar.cpp index 1f6c0cf6e5..f699224aac 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_top_bar.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_top_bar.cpp @@ -191,6 +191,7 @@ TopBar::TopBar( , _key(descriptor.key) , _wrap(std::move(descriptor.wrap)) , _st(st::infoTopBar) +, _source(descriptor.source) , _badgeTooltipHide( std::make_unique([=] { hideBadgeTooltip(); })) , _botVerify(std::make_unique( @@ -421,8 +422,7 @@ void TopBar::adjustColors(const std::optional &edgeColor) { void TopBar::updateCollectibleStatus() { const auto collectible = _peer->emojiStatusId().collectible; - const auto colorProfile - = _peer->session().api().peerColors().colorProfileFor(_peer); + const auto colorProfile = effectiveColorProfile(); _hasGradientBg = (collectible != nullptr) || (colorProfile && colorProfile->bg.size() > 1); _solidBg = (colorProfile && colorProfile->bg.size() == 1) @@ -890,6 +890,20 @@ void TopBar::setLottieSingleLoop(bool value) { _lottieSingleLoop = value; } +void TopBar::setColorProfileIndex(std::optional index) { + _localColorProfileIndex = index; + updateCollectibleStatus(); +} + +std::optional TopBar::effectiveColorProfile() const { + return _localColorProfileIndex + ? _peer->session().api().peerColors().colorProfileFor( + *_localColorProfileIndex) + : _source == Source::Preview + ? std::nullopt + : _peer->session().api().peerColors().colorProfileFor(_peer); +} + void TopBar::paintEdges(QPainter &p, const QBrush &brush) const { const auto r = rect(); if (_roundEdges) { @@ -1170,14 +1184,28 @@ void TopBar::paintEvent(QPaintEvent *e) { const auto geometry = userpicGeometry(); if (_hasGradientBg && _cachedGradient.isNull()) { - _cachedGradient = Ui::CreateTopBgGradient( - QSize(width(), maximumHeight()), - _peer, - QPoint( - 0, - _hasActions - ? -st::infoProfileTopBarPhotoBgShift - : -st::infoProfileTopBarPhotoBgNoActionsShift)); + const auto collectible = _peer->emojiStatusId().collectible; + const auto colorProfile = effectiveColorProfile(); + const auto offset = QPoint( + 0, + _hasActions + ? -st::infoProfileTopBarPhotoBgShift + : -st::infoProfileTopBarPhotoBgNoActionsShift); + if (collectible) { + _cachedGradient = Ui::CreateTopBgGradient( + QSize(width(), maximumHeight()), + collectible->centerColor, + collectible->edgeColor, + false, + offset); + } else if (colorProfile && colorProfile->bg.size() > 1) { + _cachedGradient = Ui::CreateTopBgGradient( + QSize(width(), maximumHeight()), + colorProfile->bg[1], + colorProfile->bg[0], + false, + offset); + } } if (!_hasGradientBg) { paintEdges(p); @@ -1483,8 +1511,7 @@ void TopBar::paintAnimatedPattern( if (_basePatternImage.isNull()) { const auto collectible = _peer->emojiStatusId().collectible; - const auto colorProfile - = _peer->session().api().peerColors().colorProfileFor(_peer); + const auto colorProfile = effectiveColorProfile(); const auto ratio = style::DevicePixelRatio(); const auto scale = 0.75; const auto size = Ui::Emoji::GetSizeNormal() * scale; @@ -1813,7 +1840,7 @@ void TopBar::paintPinnedToTopGifts( QPainter &p, const QRect &rect, const QRect &userpicRect) { - if (_pinnedToTopGifts.empty()) { + if (_pinnedToTopGifts.empty() || _source == Source::Preview) { return; } diff --git a/Telegram/SourceFiles/info/profile/info_profile_top_bar.h b/Telegram/SourceFiles/info/profile/info_profile_top_bar.h index 8790b9ce01..82d7f6fc79 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_top_bar.h +++ b/Telegram/SourceFiles/info/profile/info_profile_top_bar.h @@ -17,6 +17,7 @@ namespace Data { class ForumTopic; class DocumentMedia; struct SavedStarGift; +struct ColorProfileSet; } // namespace Data namespace Info::Profile { @@ -113,6 +114,7 @@ public: void setRoundEdges(bool value); void setLottieSingleLoop(bool value); void setEnableBackButtonValue(rpl::producer &&producer); + void setColorProfileIndex(std::optional index); void addTopBarMenuButton( not_null controller, Wrap wrap, @@ -181,11 +183,15 @@ private: [[nodiscard]] const style::FlatLabel &statusStyle() const; void setupStatusWithRating(); + [[nodiscard]] auto effectiveColorProfile() + const -> std::optional; + const not_null _peer; Data::ForumTopic *_topic = nullptr; const Key _key; rpl::variable _wrap; const style::InfoTopBar &_st; + const Source _source; std::unique_ptr _badgeTooltipHide; const std::unique_ptr _botVerify; @@ -267,6 +273,8 @@ private: std::vector _storySegments; bool _hasStories = false; + std::optional _localColorProfileIndex; + }; } // namespace Info::Profile