From c1d20d16fddda77e0ebc2a030044d39b5238b640 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Thu, 23 Nov 2023 00:44:19 +0300 Subject: [PATCH] Added small preview to story statistics. --- .../info_statistics_inner_widget.cpp | 9 +++ .../info_statistics_recent_message.cpp | 56 +++++++++++++------ 2 files changed, 47 insertions(+), 18 deletions(-) diff --git a/Telegram/SourceFiles/info/statistics/info_statistics_inner_widget.cpp b/Telegram/SourceFiles/info/statistics/info_statistics_inner_widget.cpp index 60ac080419..62f77f4788 100644 --- a/Telegram/SourceFiles/info/statistics/info_statistics_inner_widget.cpp +++ b/Telegram/SourceFiles/info/statistics/info_statistics_inner_widget.cpp @@ -626,6 +626,15 @@ void InnerWidget::fill() { Ui::AddSkip(inner); Ui::AddDivider(inner); } + } else if (_state.stats.story) { + if (const auto story = _peer->owner().stories().lookup(_storyId)) { + Ui::AddSkip(inner); + const auto preview = inner->add( + object_ptr(this, *story, QImage())); + preview->setAttribute(Qt::WA_TransparentForMouseEvents); + Ui::AddSkip(inner); + Ui::AddDivider(inner); + } } FillOverview(inner, _state.stats); FillStatistic(inner, descriptor, _state.stats); diff --git a/Telegram/SourceFiles/info/statistics/info_statistics_recent_message.cpp b/Telegram/SourceFiles/info/statistics/info_statistics_recent_message.cpp index af2202ed1e..57fee44c61 100644 --- a/Telegram/SourceFiles/info/statistics/info_statistics_recent_message.cpp +++ b/Telegram/SourceFiles/info/statistics/info_statistics_recent_message.cpp @@ -43,13 +43,14 @@ namespace { [[nodiscard]] QImage PreparePreviewImage( QImage original, ImageRoundRadius radius, + int size, bool spoiler) { if (original.width() * 10 < original.height() || original.height() * 10 < original.width()) { return QImage(); } const auto factor = style::DevicePixelRatio(); - const auto size = st::peerListBoxItem.photoSize * factor; + size *= factor; const auto scaled = original.scaled( QSize(size, size), Qt::KeepAspectRatioByExpanding, @@ -156,10 +157,10 @@ void MessagePreview::setInfo(int views, int shares, int reactions) { : QString()); _shares = Ui::Text::String( st::statisticsHeaderTitleTextStyle, - (shares >= 0) ? Lang::FormatCountDecimal(shares) : QString()); + (shares > 0) ? Lang::FormatCountDecimal(shares) : QString()); _reactions = Ui::Text::String( st::statisticsHeaderTitleTextStyle, - (reactions >= 0) ? Lang::FormatCountDecimal(reactions) : QString()); + (reactions > 0) ? Lang::FormatCountDecimal(reactions) : QString()); _viewsWidth = (_views.maxWidth()); _sharesWidth = (_shares.maxWidth()); _reactionsWidth = (_reactions.maxWidth()); @@ -208,10 +209,40 @@ void MessagePreview::processPreview() { } else if (computed.loaded) { _lifetimeDownload.destroy(); } - _preview = PreparePreviewImage( - computed.image->original(), - _messageId ? ImageRoundRadius::Large : ImageRoundRadius::Ellipse, - !!_spoiler); + if (_storyId) { + const auto line = st::dialogsStoriesFull.lineTwice; + const auto rect = Rect(Size(st::peerListBoxItem.photoSize)); + const auto penWidth = line / 2.; + const auto offset = 1.5 * penWidth * 2; + const auto preview = PreparePreviewImage( + computed.image->original(), + ImageRoundRadius::Ellipse, + st::peerListBoxItem.photoSize - offset * 2, + !!_spoiler); + auto image = QImage( + rect.size() * style::DevicePixelRatio(), + QImage::Format_ARGB32_Premultiplied); + image.fill(Qt::transparent); + { + auto p = QPainter(&image); + p.drawImage(offset, offset, preview); + auto hq = PainterHighQualityEnabler(p); + auto gradient = Ui::UnreadStoryOutlineGradient(); + gradient.setStart(rect.topRight()); + gradient.setFinalStop(rect.bottomLeft()); + + p.setPen(QPen(gradient, penWidth)); + p.setBrush(Qt::NoBrush); + p.drawEllipse(rect - Margins(penWidth)); + } + _preview = std::move(image); + } else { + _preview = PreparePreviewImage( + computed.image->original(), + ImageRoundRadius::Large, + st::peerListBoxItem.photoSize, + !!_spoiler); + } }, _lifetimeDownload); } @@ -253,17 +284,6 @@ void MessagePreview::paintEvent(QPaintEvent *e) { _spoiler->index(crl::now(), paused)), _cornerCache); } - if (_storyId) { - auto hq = PainterHighQualityEnabler(p); - const auto line = st::dialogsStoriesFull.lineTwice / 2.; - auto gradient = Ui::UnreadStoryOutlineGradient(); - gradient.setStart(rect.topRight()); - gradient.setFinalStop(rect.bottomLeft()); - - p.setPen(QPen(gradient, line)); - p.setBrush(Qt::NoBrush); - p.drawEllipse(rect + Margins(1.5 * line)); - } } const auto topTextTop = st::peerListBoxItem.namePosition.y(); const auto bottomTextTop = st::peerListBoxItem.statusPosition.y();