From 10022a3c6dbd6899ece0e7ef32c21ad96a1f65b5 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 31 Oct 2023 23:06:21 +0400 Subject: [PATCH] Highlight quotes in replies to file albums. --- .../SourceFiles/data/data_media_types.cpp | 5 +-- .../history/view/history_view_element.cpp | 9 +++-- .../view/media/history_view_document.cpp | 6 ++++ .../view/media/history_view_media_grouped.cpp | 34 +++++++++++-------- 4 files changed, 32 insertions(+), 22 deletions(-) diff --git a/Telegram/SourceFiles/data/data_media_types.cpp b/Telegram/SourceFiles/data/data_media_types.cpp index 9cf49244a..cb0278a27 100644 --- a/Telegram/SourceFiles/data/data_media_types.cpp +++ b/Telegram/SourceFiles/data/data_media_types.cpp @@ -538,6 +538,7 @@ ItemPreview Media::toGroupPreview( auto videoCount = 0; auto audioCount = 0; auto fileCount = 0; + auto manyCaptions = false; for (const auto &item : items) { if (const auto media = item->media()) { if (media->photo()) { @@ -571,12 +572,12 @@ ItemPreview Media::toGroupPreview( if (result.text.text.isEmpty()) { result.text = original; } else { - result.text = {}; + manyCaptions = true; } } } } - if (result.text.text.isEmpty()) { + if (manyCaptions || result.text.text.isEmpty()) { const auto mediaCount = photoCount + videoCount; auto genericText = (photoCount && videoCount) ? tr::lng_in_dlg_media_count(tr::now, lt_count, mediaCount) diff --git a/Telegram/SourceFiles/history/view/history_view_element.cpp b/Telegram/SourceFiles/history/view/history_view_element.cpp index 68f8c49ad..991d158dc 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.cpp +++ b/Telegram/SourceFiles/history/view/history_view_element.cpp @@ -621,6 +621,9 @@ void Element::paintHighlight( Painter &p, const PaintContext &context, int geometryHeight) const { + if (context.highlight.opacity == 0.) { + return; + } const auto top = marginTop(); const auto bottom = marginBottom(); const auto fill = qMin(top, bottom); @@ -636,12 +639,8 @@ void Element::paintCustomHighlight( int y, int height, not_null item) const { - const auto opacity = context.highlight.opacity; - if (opacity == 0.) { - return; - } const auto o = p.opacity(); - p.setOpacity(o * opacity); + p.setOpacity(o * context.highlight.opacity); p.fillRect(0, y, width(), height, context.st->msgSelectOverlay()); p.setOpacity(o); } diff --git a/Telegram/SourceFiles/history/view/media/history_view_document.cpp b/Telegram/SourceFiles/history/view/media/history_view_document.cpp index 7530b31ff..06825b37d 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_document.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_document.cpp @@ -1397,6 +1397,8 @@ void Document::drawGrouped( float64 highlightOpacity, not_null cacheKey, not_null cache) const { + const auto maybeMediaHighlight = context.highlightPathCache + && context.highlightPathCache->isEmpty(); p.translate(geometry.topLeft()); draw( p, @@ -1404,6 +1406,10 @@ void Document::drawGrouped( geometry.width(), LayoutMode::Grouped, rounding); + if (maybeMediaHighlight + && !context.highlightPathCache->isEmpty()) { + context.highlightPathCache->translate(geometry.topLeft()); + } p.translate(-geometry.topLeft()); } diff --git a/Telegram/SourceFiles/history/view/media/history_view_media_grouped.cpp b/Telegram/SourceFiles/history/view/media/history_view_media_grouped.cpp index 9766c5aaa..402fb4d05 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_media_grouped.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_media_grouped.cpp @@ -286,6 +286,9 @@ void GroupedMedia::drawHighlight( Painter &p, const PaintContext &context, int top) const { + if (context.highlight.opacity == 0.) { + return; + } auto selection = context.highlight.range; if (_mode != Mode::Column) { if (!selection.empty() && !IsSubGroupSelection(selection)) { @@ -305,9 +308,15 @@ void GroupedMedia::drawHighlight( const auto &part = _parts[i]; const auto rect = part.geometry.translated(0, skip); const auto full = (!i && empty) - || (subpart && IsGroupItemSelection(selection, i)); - auto copy = context; + || (subpart && IsGroupItemSelection(selection, i)) + || (!subpart + && !selection.empty() + && (selection.from < part.content->fullSelectionLength())); + if (!subpart) { + selection = part.content->skipSelection(selection); + } if (full) { + auto copy = context; copy.highlight.range = {}; _parent->paintCustomHighlight( p, @@ -315,18 +324,7 @@ void GroupedMedia::drawHighlight( rect.y(), rect.height(), part.item); - } else if (!selection.empty()) { - copy.highlight.range = selection; - selection = part.content->skipSelection(selection); - } else { - break; } - _parent->paintCustomHighlight( - p, - copy, - rect.y(), - rect.height(), - part.item); } } @@ -344,10 +342,10 @@ void GroupedMedia::draw(Painter &p, const PaintContext &context) const { const auto rounding = inWebPage ? Ui::BubbleRounding{ kSmall, kSmall, kSmall, kSmall } : adjustedBubbleRoundingWithCaption(_caption); - const auto highlight = context.highlight.range; + auto highlight = context.highlight.range; for (auto i = 0, count = int(_parts.size()); i != count; ++i) { const auto &part = _parts[i]; - const auto partContext = context.withSelection(fullSelection + auto partContext = context.withSelection(fullSelection ? FullSelection : textSelection ? selection @@ -359,9 +357,15 @@ void GroupedMedia::draw(Painter &p, const PaintContext &context) const { const auto highlightOpacity = highlighted ? context.highlight.opacity : 0.; + partContext.highlight.range = highlighted + ? TextSelection() + : highlight; if (textSelection) { selection = part.content->skipSelection(selection); } + if (!highlighted) { + highlight = part.content->skipSelection(highlight); + } if (!part.cache.isNull()) { wasCache = true; }