From e651699e1dae12b0581dfb65e0b4ad92f22873af Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 28 Aug 2024 14:55:23 +0400 Subject: [PATCH] Fix thumbnailed document layout. --- .../view/media/history_view_document.cpp | 49 +++++++++++++++++-- .../view/media/history_view_document.h | 1 + 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/Telegram/SourceFiles/history/view/media/history_view_document.cpp b/Telegram/SourceFiles/history/view/media/history_view_document.cpp index b1c972053..8e77ef8f1 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_document.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_document.cpp @@ -507,8 +507,16 @@ QSize Document::countOptimalSize() { } auto minHeight = st.padding.top() + st.thumbSize + st.padding.bottom(); - if (isBubbleBottom() && !hasTranscribe && _parent->bottomInfoIsWide()) { - minHeight += st::msgDateFont->height - st::msgDateDelta.y(); + if (isBubbleBottom() && !hasTranscribe) { + if (const auto link = thumbedLinkMaxWidth()) { + accumulate_max( + maxWidth, + (tleft + + link + + st.thumbSkip + + _parent->bottomInfoFirstLineWidth() + + tright)); + } } if (!isBubbleTop()) { minHeight -= st::msgFileTopMinus; @@ -530,13 +538,30 @@ QSize Document::countCurrentSize(int newWidth) { const auto captioned = Get(); const auto voice = Get(); const auto hasTranscribe = voice && !voice->transcribeText.isEmpty(); + const auto thumbed = Get(); + const auto &st = thumbed ? st::msgFileThumbLayout : st::msgFileLayout; if (!captioned && !hasTranscribe) { - return File::countCurrentSize(newWidth); + auto result = File::countCurrentSize(newWidth); + if (isBubbleBottom()) { + if (const auto link = thumbedLinkMaxWidth()) { + const auto needed = st.padding.left() + + st.thumbSize + + st.thumbSkip + + link + + st.thumbSkip + + _parent->bottomInfoFirstLineWidth() + + st.padding.right(); + if (result.width() < needed) { + result.setHeight(result.height() + + st::msgDateFont->height + - st::msgDateDelta.y()); + } + } + } + return result; } accumulate_min(newWidth, maxWidth()); - const auto thumbed = Get(); - const auto &st = thumbed ? st::msgFileThumbLayout : st::msgFileLayout; auto newHeight = st.padding.top() + st.thumbSize + st.padding.bottom(); if (!isBubbleTop()) { newHeight -= st::msgFileTopMinus; @@ -1382,6 +1407,20 @@ bool Document::uploading() const { return _data->uploading(); } +[[nodiscard]] int Document::thumbedLinkMaxWidth() const { + if (Has()) { + const auto w = [](const QString &text) { + return st::semiboldFont->width(text.toUpper()); + }; + return std::max({ + w(tr::lng_media_download(tr::now)), + w(tr::lng_media_open_with(tr::now)), + w(tr::lng_media_cancel(tr::now)), + }); + } + return 0; +} + void Document::setStatusSize(int64 newSize, TimeId realDuration) const { const auto duration = (_data->isSong() || _data->isVoiceMessage() diff --git a/Telegram/SourceFiles/history/view/media/history_view_document.h b/Telegram/SourceFiles/history/view/media/history_view_document.h index 2f8ec9ac2..d47cf2045 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_document.h +++ b/Telegram/SourceFiles/history/view/media/history_view_document.h @@ -139,6 +139,7 @@ private: void setStatusSize(int64 newSize, TimeId realDuration = 0) const; bool updateStatusText() const; // returns showPause + [[nodiscard]] int thumbedLinkMaxWidth() const; [[nodiscard]] bool downloadInCorner() const; void drawCornerDownload(