diff --git a/Telegram/SourceFiles/history/history_item_components.h b/Telegram/SourceFiles/history/history_item_components.h index d4bc894b13..8b38c294da 100644 --- a/Telegram/SourceFiles/history/history_item_components.h +++ b/Telegram/SourceFiles/history/history_item_components.h @@ -746,8 +746,7 @@ struct HistoryDocumentCaptioned : public RuntimeComponent { - QString name; - int namew = 0; + Ui::Text::String name; }; struct HistoryDocumentVoicePlayback { diff --git a/Telegram/SourceFiles/history/view/media/history_view_document.cpp b/Telegram/SourceFiles/history/view/media/history_view_document.cpp index 62bf0f64b1..e7d20d7975 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_document.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_document.cpp @@ -303,7 +303,7 @@ Document::Document( createComponents(); if (const auto named = Get()) { fillNamedFromData(named); - _tooltipFilename.setTooltipText(named->name); + _tooltipFilename.setTooltipText(named->name.toString()); } if ((_data->isVoiceMessage() || isRound) @@ -406,9 +406,9 @@ void Document::createComponents() { } void Document::fillNamedFromData(not_null named) { - const auto nameString = named->name = CleanTagSymbols( - Ui::Text::FormatSongNameFor(_data).string()); - named->namew = st::semiboldFont->width(nameString); + named->name.setText( + st::semiboldTextStyle, + CleanTagSymbols(Ui::Text::FormatSongNameFor(_data).string())); } QSize Document::countOptimalSize() { @@ -497,8 +497,8 @@ QSize Document::countOptimalSize() { accumulate_max(maxWidth, tleft + MaxStatusWidth(_data) + unread + _parent->skipBlockWidth() + st::msgPadding.right()); } - if (auto named = Get()) { - accumulate_max(maxWidth, tleft + named->namew + tright); + if (const auto named = Get()) { + accumulate_max(maxWidth, tleft + named->name.maxWidth() + tright); accumulate_min(maxWidth, st::msgMaxWidth); } if (voice && voice->transcribe) { @@ -876,16 +876,15 @@ void Document::draw( progress, inTTLViewer); p.restore(); - } else if (auto named = Get()) { - p.setFont(st::semiboldFont); + } else if (const auto named = Get()) { p.setPen(stm->historyFileNameFg); - const auto elided = (namewidth < named->namew); - if (elided) { - p.drawTextLeft(nameleft, nametop, width, st::semiboldFont->elided(named->name, namewidth, Qt::ElideMiddle)); - } else { - p.drawTextLeft(nameleft, nametop, width, named->name, named->namew); - } - _tooltipFilename.setElided(elided); + named->name.draw(p, { + .position = QPoint(nameleft, nametop), + .outerWidth = width, + .availableWidth = namewidth, + .elisionLines = 1, + }); + _tooltipFilename.setElided(namewidth < named->name.maxWidth()); } auto statusText = voiceStatusOverride.isEmpty() ? _statusText : voiceStatusOverride;