From cdafd8f171c52a8a3f583dccca41cd7d3011502d Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Fri, 7 May 2021 14:49:04 +0300 Subject: [PATCH] Fixed width of preview for small media in SendFilesBox. Regression was introduced in 42d4fdb89f. --- .../attach/attach_single_media_preview.cpp | 49 ++++++++++--------- .../chat/attach/attach_single_media_preview.h | 2 + 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/Telegram/SourceFiles/ui/chat/attach/attach_single_media_preview.cpp b/Telegram/SourceFiles/ui/chat/attach/attach_single_media_preview.cpp index 31f73ee04..da13b1509 100644 --- a/Telegram/SourceFiles/ui/chat/attach/attach_single_media_preview.cpp +++ b/Telegram/SourceFiles/ui/chat/attach/attach_single_media_preview.cpp @@ -69,6 +69,8 @@ SingleMediaPreview::SingleMediaPreview( , _gifPaused(std::move(gifPaused)) , _animated(animated) , _sticker(sticker) +, _minThumbH(st::sendBoxAlbumGroupSize.height() + + st::sendBoxAlbumGroupSkipTop * 2) , _photoEditorButton(base::make_unique_q(this)) , _controls(base::make_unique_q(this)) { Expects(!preview.isNull()); @@ -129,8 +131,6 @@ void SingleMediaPreview::preparePreview( _previewWidth = qMax(preview.width(), kMinPreviewWidth); } auto maxthumbh = qMin(qRound(1.5 * _previewWidth), st::confirmMaxHeight); - const auto minthumbh = st::sendBoxAlbumGroupSize.height() - + st::sendBoxAlbumGroupSkipTop * 2; _previewHeight = qRound(originalHeight * float64(_previewWidth) / originalWidth); @@ -140,13 +140,11 @@ void SingleMediaPreview::preparePreview( / _previewHeight); accumulate_max(_previewWidth, kMinPreviewWidth); _previewHeight = maxthumbh; - } else if (_previewHeight < minthumbh) { - _previewWidth = qRound(_previewWidth * float64(minthumbh) - / _previewHeight); - accumulate_max(_previewWidth, kMinPreviewWidth); - _previewHeight = minthumbh; } _previewLeft = (st::boxWideWidth - _previewWidth) / 2; + if (_previewHeight < _minThumbH) { + _previewTop = (_minThumbH - _previewHeight) / 2; + } preview = std::move(preview).scaled( _previewWidth * style::DevicePixelRatio(), @@ -160,13 +158,13 @@ void SingleMediaPreview::preparePreview( prepareAnimatedPreview(animatedPreviewPath); _photoEditorButton->resize(_previewWidth, _previewHeight); - _photoEditorButton->moveToLeft(_previewLeft, 0); + _photoEditorButton->moveToLeft(_previewLeft, _previewTop); _photoEditorButton->setVisible(!_sticker && !_gifPreview && !_lottiePreview && !_animated); - resize(width(), _previewHeight); + resize(width(), std::max(_previewHeight, _minThumbH)); } void SingleMediaPreview::resizeEvent(QResizeEvent *e) { @@ -233,26 +231,31 @@ void SingleMediaPreview::paintEvent(QPaintEvent *e) { Painter p(this); if (!_sticker) { - if (_previewLeft > st::boxPhotoPadding.left()) { + const auto &padding = st::boxPhotoPadding; + if (_previewLeft > padding.left()) { p.fillRect( - st::boxPhotoPadding.left(), - 0, - _previewLeft - st::boxPhotoPadding.left(), + padding.left(), + _previewTop, + _previewLeft - padding.left(), _previewHeight, st::confirmBg); } - if ((_previewLeft + _previewWidth) - < (width() - st::boxPhotoPadding.right())) { + if ((_previewLeft + _previewWidth) < (width() - padding.right())) { p.fillRect( _previewLeft + _previewWidth, - 0, - width() - - st::boxPhotoPadding.right() - - _previewLeft - - _previewWidth, + _previewTop, + width() - padding.right() - _previewLeft - _previewWidth, _previewHeight, st::confirmBg); } + if (_previewTop > 0) { + p.fillRect( + padding.left(), + 0, + width() - padding.right() - padding.left(), + height(), + st::confirmBg); + } } if (_gifPreview && _gifPreview->started()) { auto s = QSize(_previewWidth, _previewHeight); @@ -265,7 +268,7 @@ void SingleMediaPreview::paintEvent(QPaintEvent *e) { ImageRoundRadius::None, RectPart::None, paused ? 0 : crl::now()); - p.drawPixmap(_previewLeft, 0, frame); + p.drawPixmap(_previewLeft, _previewTop, frame); } else if (_lottiePreview && _lottiePreview->ready()) { const auto frame = _lottiePreview->frame(); const auto size = frame.size() / style::DevicePixelRatio(); @@ -278,13 +281,13 @@ void SingleMediaPreview::paintEvent(QPaintEvent *e) { frame); _lottiePreview->markFrameShown(); } else { - p.drawPixmap(_previewLeft, 0, _preview); + p.drawPixmap(_previewLeft, _previewTop, _preview); } if (_animated && !_gifPreview && !_lottiePreview) { const auto innerSize = st::msgFileLayout.thumbSize; auto inner = QRect( _previewLeft + (_previewWidth - innerSize) / 2, - (_previewHeight - innerSize) / 2, + _previewTop + (_previewHeight - innerSize) / 2, innerSize, innerSize); p.setPen(Qt::NoPen); diff --git a/Telegram/SourceFiles/ui/chat/attach/attach_single_media_preview.h b/Telegram/SourceFiles/ui/chat/attach/attach_single_media_preview.h index b4523d66c..3c54da015 100644 --- a/Telegram/SourceFiles/ui/chat/attach/attach_single_media_preview.h +++ b/Telegram/SourceFiles/ui/chat/attach/attach_single_media_preview.h @@ -56,11 +56,13 @@ private: bool _sticker = false; QPixmap _preview; int _previewLeft = 0; + int _previewTop = 0; int _previewWidth = 0; int _previewHeight = 0; Media::Clip::ReaderPointer _gifPreview; std::unique_ptr _lottiePreview; + const int _minThumbH; const base::unique_qptr _photoEditorButton; const base::unique_qptr _controls;