diff --git a/Telegram/SourceFiles/history/view/history_view_element.h b/Telegram/SourceFiles/history/view/history_view_element.h index 654eea2f00..05aadbcdcb 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.h +++ b/Telegram/SourceFiles/history/view/history_view_element.h @@ -262,6 +262,9 @@ public: virtual bool hasOutLayout() const; virtual bool drawBubble() const; virtual bool hasBubble() const; + virtual int minWidthForMedia() const { + return 0; + } virtual bool hasFastReply() const; virtual bool displayFastReply() const; virtual std::optional rightActionSize() const; diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index 29e87d4741..1a1e8f7297 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -421,30 +421,7 @@ QSize Message::performCountOptimalSize() { minHeight += entry->minHeight(); } } - if (item->repliesAreComments() && !views->replies.text.isEmpty()) { - const auto limit = HistoryMessageViews::kMaxRecentRepliers; - const auto single = st::historyCommentsUserpicSize; - const auto shift = st::historyCommentsUserpicOverlap; - const auto added = single - + (limit - 1) * (single - shift) - + st::historyCommentsSkipLeft - + st::historyCommentsSkipRight - + st::historyCommentsSkipText - + st::historyCommentsOpenOutSelected.width() - + st::historyCommentsSkipRight - + st::mediaUnreadSkip - + st::mediaUnreadSize; - accumulate_max(maxWidth, added + views->replies.textWidth); - } else if (item->externalReply()) { - const auto added = st::historyCommentsIn.width() - + st::historyCommentsSkipLeft - + st::historyCommentsSkipRight - + st::historyCommentsSkipText - + st::historyCommentsOpenOutSelected.width() - + st::historyCommentsSkipRight; - accumulate_max(maxWidth, added + st::semiboldFont->width( - tr::lng_replies_view_original(tr::now))); - } + accumulate_max(maxWidth, minWidthForMedia()); } else if (media) { media->initDimensions(); maxWidth = media->maxWidth(); @@ -2028,6 +2005,36 @@ bool Message::hasBubble() const { return drawBubble(); } +int Message::minWidthForMedia() const { + auto result = infoWidth() + 2 * (st::msgDateImgDelta + st::msgDateImgPadding.x()); + const auto views = data()->Get(); + if (data()->repliesAreComments() && !views->replies.text.isEmpty()) { + const auto limit = HistoryMessageViews::kMaxRecentRepliers; + const auto single = st::historyCommentsUserpicSize; + const auto shift = st::historyCommentsUserpicOverlap; + const auto added = single + + (limit - 1) * (single - shift) + + st::historyCommentsSkipLeft + + st::historyCommentsSkipRight + + st::historyCommentsSkipText + + st::historyCommentsOpenOutSelected.width() + + st::historyCommentsSkipRight + + st::mediaUnreadSkip + + st::mediaUnreadSize; + accumulate_max(result, added + views->replies.textWidth); + } else if (data()->externalReply()) { + const auto added = st::historyCommentsIn.width() + + st::historyCommentsSkipLeft + + st::historyCommentsSkipRight + + st::historyCommentsSkipText + + st::historyCommentsOpenOutSelected.width() + + st::historyCommentsSkipRight; + accumulate_max(result, added + st::semiboldFont->width( + tr::lng_replies_view_original(tr::now))); + } + return result; +} + bool Message::hasFastReply() const { if (context() == Context::Replies) { if (data()->isDiscussionPost()) { diff --git a/Telegram/SourceFiles/history/view/history_view_message.h b/Telegram/SourceFiles/history/view/history_view_message.h index 4d210c5608..3ffa3cff12 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.h +++ b/Telegram/SourceFiles/history/view/history_view_message.h @@ -91,6 +91,7 @@ public: bool hasOutLayout() const override; bool drawBubble() const override; bool hasBubble() const override; + int minWidthForMedia() const override; bool hasFastReply() const override; bool displayFastReply() const override; bool displayRightActionComments() const; diff --git a/Telegram/SourceFiles/history/view/media/history_view_location.cpp b/Telegram/SourceFiles/history/view/media/history_view_location.cpp index b195cbd66c..e07b932e26 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_location.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_location.cpp @@ -82,7 +82,7 @@ QSize Location::countOptimalSize() { th = (st::maxMediaSize * th) / tw; tw = st::maxMediaSize; } - auto minWidth = qMax(st::minPhotoSize, _parent->infoWidth() + 2 * (st::msgDateImgDelta + st::msgDateImgPadding.x())); + auto minWidth = qMax(st::minPhotoSize, _parent->minWidthForMedia()); auto maxWidth = qMax(tw, minWidth); auto minHeight = qMax(th, st::minPhotoSize); @@ -118,7 +118,7 @@ QSize Location::countCurrentSize(int newWidth) { } else { newWidth = tw; } - auto minWidth = qMax(st::minPhotoSize, _parent->infoWidth() + 2 * (st::msgDateImgDelta + st::msgDateImgPadding.x())); + auto minWidth = qMax(st::minPhotoSize, _parent->minWidthForMedia()); accumulate_max(newWidth, minWidth); accumulate_max(newHeight, st::minPhotoSize); if (_parent->hasBubble()) { diff --git a/Telegram/SourceFiles/history/view/media/history_view_photo.cpp b/Telegram/SourceFiles/history/view/media/history_view_photo.cpp index 7e63148e02..6421bab8c6 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_photo.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_photo.cpp @@ -154,7 +154,9 @@ QSize Photo::countOptimalSize() { if (_serviceWidth > 0) { return { _serviceWidth, _serviceWidth }; } - const auto minWidth = qMax((_parent->hasBubble() ? st::historyPhotoBubbleMinWidth : st::minPhotoSize), _parent->infoWidth() + 2 * (st::msgDateImgDelta + st::msgDateImgPadding.x())); + const auto minWidth = qMax( + (_parent->hasBubble() ? st::historyPhotoBubbleMinWidth : st::minPhotoSize), + _parent->minWidthForMedia()); const auto maxActualWidth = qMax(tw, minWidth); maxWidth = qMax(maxActualWidth, th); minHeight = qMax(th, st::minPhotoSize); @@ -194,7 +196,9 @@ QSize Photo::countCurrentSize(int newWidth) { if (_pixw < 1) _pixw = 1; if (_pixh < 1) _pixh = 1; - auto minWidth = qMax((_parent->hasBubble() ? st::historyPhotoBubbleMinWidth : st::minPhotoSize), _parent->infoWidth() + 2 * (st::msgDateImgDelta + st::msgDateImgPadding.x())); + auto minWidth = qMax( + (_parent->hasBubble() ? st::historyPhotoBubbleMinWidth : st::minPhotoSize), + _parent->minWidthForMedia()); newWidth = qMax(_pixw, minWidth); auto newHeight = qMax(_pixh, st::minPhotoSize); if (_parent->hasBubble() && !_caption.isEmpty()) {