Highlight quotes in replies to file albums.

This commit is contained in:
John Preston 2023-10-31 23:06:21 +04:00
parent 0dbb195106
commit 10022a3c6d
4 changed files with 32 additions and 22 deletions

View File

@ -538,6 +538,7 @@ ItemPreview Media::toGroupPreview(
auto videoCount = 0; auto videoCount = 0;
auto audioCount = 0; auto audioCount = 0;
auto fileCount = 0; auto fileCount = 0;
auto manyCaptions = false;
for (const auto &item : items) { for (const auto &item : items) {
if (const auto media = item->media()) { if (const auto media = item->media()) {
if (media->photo()) { if (media->photo()) {
@ -571,12 +572,12 @@ ItemPreview Media::toGroupPreview(
if (result.text.text.isEmpty()) { if (result.text.text.isEmpty()) {
result.text = original; result.text = original;
} else { } else {
result.text = {}; manyCaptions = true;
} }
} }
} }
} }
if (result.text.text.isEmpty()) { if (manyCaptions || result.text.text.isEmpty()) {
const auto mediaCount = photoCount + videoCount; const auto mediaCount = photoCount + videoCount;
auto genericText = (photoCount && videoCount) auto genericText = (photoCount && videoCount)
? tr::lng_in_dlg_media_count(tr::now, lt_count, mediaCount) ? tr::lng_in_dlg_media_count(tr::now, lt_count, mediaCount)

View File

@ -621,6 +621,9 @@ void Element::paintHighlight(
Painter &p, Painter &p,
const PaintContext &context, const PaintContext &context,
int geometryHeight) const { int geometryHeight) const {
if (context.highlight.opacity == 0.) {
return;
}
const auto top = marginTop(); const auto top = marginTop();
const auto bottom = marginBottom(); const auto bottom = marginBottom();
const auto fill = qMin(top, bottom); const auto fill = qMin(top, bottom);
@ -636,12 +639,8 @@ void Element::paintCustomHighlight(
int y, int y,
int height, int height,
not_null<const HistoryItem*> item) const { not_null<const HistoryItem*> item) const {
const auto opacity = context.highlight.opacity;
if (opacity == 0.) {
return;
}
const auto o = p.opacity(); 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.fillRect(0, y, width(), height, context.st->msgSelectOverlay());
p.setOpacity(o); p.setOpacity(o);
} }

View File

@ -1397,6 +1397,8 @@ void Document::drawGrouped(
float64 highlightOpacity, float64 highlightOpacity,
not_null<uint64*> cacheKey, not_null<uint64*> cacheKey,
not_null<QPixmap*> cache) const { not_null<QPixmap*> cache) const {
const auto maybeMediaHighlight = context.highlightPathCache
&& context.highlightPathCache->isEmpty();
p.translate(geometry.topLeft()); p.translate(geometry.topLeft());
draw( draw(
p, p,
@ -1404,6 +1406,10 @@ void Document::drawGrouped(
geometry.width(), geometry.width(),
LayoutMode::Grouped, LayoutMode::Grouped,
rounding); rounding);
if (maybeMediaHighlight
&& !context.highlightPathCache->isEmpty()) {
context.highlightPathCache->translate(geometry.topLeft());
}
p.translate(-geometry.topLeft()); p.translate(-geometry.topLeft());
} }

View File

@ -286,6 +286,9 @@ void GroupedMedia::drawHighlight(
Painter &p, Painter &p,
const PaintContext &context, const PaintContext &context,
int top) const { int top) const {
if (context.highlight.opacity == 0.) {
return;
}
auto selection = context.highlight.range; auto selection = context.highlight.range;
if (_mode != Mode::Column) { if (_mode != Mode::Column) {
if (!selection.empty() && !IsSubGroupSelection(selection)) { if (!selection.empty() && !IsSubGroupSelection(selection)) {
@ -305,9 +308,15 @@ void GroupedMedia::drawHighlight(
const auto &part = _parts[i]; const auto &part = _parts[i];
const auto rect = part.geometry.translated(0, skip); const auto rect = part.geometry.translated(0, skip);
const auto full = (!i && empty) const auto full = (!i && empty)
|| (subpart && IsGroupItemSelection(selection, i)); || (subpart && IsGroupItemSelection(selection, i))
auto copy = context; || (!subpart
&& !selection.empty()
&& (selection.from < part.content->fullSelectionLength()));
if (!subpart) {
selection = part.content->skipSelection(selection);
}
if (full) { if (full) {
auto copy = context;
copy.highlight.range = {}; copy.highlight.range = {};
_parent->paintCustomHighlight( _parent->paintCustomHighlight(
p, p,
@ -315,18 +324,7 @@ void GroupedMedia::drawHighlight(
rect.y(), rect.y(),
rect.height(), rect.height(),
part.item); 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 const auto rounding = inWebPage
? Ui::BubbleRounding{ kSmall, kSmall, kSmall, kSmall } ? Ui::BubbleRounding{ kSmall, kSmall, kSmall, kSmall }
: adjustedBubbleRoundingWithCaption(_caption); : adjustedBubbleRoundingWithCaption(_caption);
const auto highlight = context.highlight.range; auto highlight = context.highlight.range;
for (auto i = 0, count = int(_parts.size()); i != count; ++i) { for (auto i = 0, count = int(_parts.size()); i != count; ++i) {
const auto &part = _parts[i]; const auto &part = _parts[i];
const auto partContext = context.withSelection(fullSelection auto partContext = context.withSelection(fullSelection
? FullSelection ? FullSelection
: textSelection : textSelection
? selection ? selection
@ -359,9 +357,15 @@ void GroupedMedia::draw(Painter &p, const PaintContext &context) const {
const auto highlightOpacity = highlighted const auto highlightOpacity = highlighted
? context.highlight.opacity ? context.highlight.opacity
: 0.; : 0.;
partContext.highlight.range = highlighted
? TextSelection()
: highlight;
if (textSelection) { if (textSelection) {
selection = part.content->skipSelection(selection); selection = part.content->skipSelection(selection);
} }
if (!highlighted) {
highlight = part.content->skipSelection(highlight);
}
if (!part.cache.isNull()) { if (!part.cache.isNull()) {
wasCache = true; wasCache = true;
} }