Fixed width of preview for small media in SendFilesBox.

Regression was introduced in 42d4fdb89f.
This commit is contained in:
23rd 2021-05-07 14:49:04 +03:00
parent 116aa01e51
commit cdafd8f171
2 changed files with 28 additions and 23 deletions

View file

@ -69,6 +69,8 @@ SingleMediaPreview::SingleMediaPreview(
, _gifPaused(std::move(gifPaused)) , _gifPaused(std::move(gifPaused))
, _animated(animated) , _animated(animated)
, _sticker(sticker) , _sticker(sticker)
, _minThumbH(st::sendBoxAlbumGroupSize.height()
+ st::sendBoxAlbumGroupSkipTop * 2)
, _photoEditorButton(base::make_unique_q<AbstractButton>(this)) , _photoEditorButton(base::make_unique_q<AbstractButton>(this))
, _controls(base::make_unique_q<AttachControlsWidget>(this)) { , _controls(base::make_unique_q<AttachControlsWidget>(this)) {
Expects(!preview.isNull()); Expects(!preview.isNull());
@ -129,8 +131,6 @@ void SingleMediaPreview::preparePreview(
_previewWidth = qMax(preview.width(), kMinPreviewWidth); _previewWidth = qMax(preview.width(), kMinPreviewWidth);
} }
auto maxthumbh = qMin(qRound(1.5 * _previewWidth), st::confirmMaxHeight); auto maxthumbh = qMin(qRound(1.5 * _previewWidth), st::confirmMaxHeight);
const auto minthumbh = st::sendBoxAlbumGroupSize.height()
+ st::sendBoxAlbumGroupSkipTop * 2;
_previewHeight = qRound(originalHeight _previewHeight = qRound(originalHeight
* float64(_previewWidth) * float64(_previewWidth)
/ originalWidth); / originalWidth);
@ -140,13 +140,11 @@ void SingleMediaPreview::preparePreview(
/ _previewHeight); / _previewHeight);
accumulate_max(_previewWidth, kMinPreviewWidth); accumulate_max(_previewWidth, kMinPreviewWidth);
_previewHeight = maxthumbh; _previewHeight = maxthumbh;
} else if (_previewHeight < minthumbh) {
_previewWidth = qRound(_previewWidth * float64(minthumbh)
/ _previewHeight);
accumulate_max(_previewWidth, kMinPreviewWidth);
_previewHeight = minthumbh;
} }
_previewLeft = (st::boxWideWidth - _previewWidth) / 2; _previewLeft = (st::boxWideWidth - _previewWidth) / 2;
if (_previewHeight < _minThumbH) {
_previewTop = (_minThumbH - _previewHeight) / 2;
}
preview = std::move(preview).scaled( preview = std::move(preview).scaled(
_previewWidth * style::DevicePixelRatio(), _previewWidth * style::DevicePixelRatio(),
@ -160,13 +158,13 @@ void SingleMediaPreview::preparePreview(
prepareAnimatedPreview(animatedPreviewPath); prepareAnimatedPreview(animatedPreviewPath);
_photoEditorButton->resize(_previewWidth, _previewHeight); _photoEditorButton->resize(_previewWidth, _previewHeight);
_photoEditorButton->moveToLeft(_previewLeft, 0); _photoEditorButton->moveToLeft(_previewLeft, _previewTop);
_photoEditorButton->setVisible(!_sticker _photoEditorButton->setVisible(!_sticker
&& !_gifPreview && !_gifPreview
&& !_lottiePreview && !_lottiePreview
&& !_animated); && !_animated);
resize(width(), _previewHeight); resize(width(), std::max(_previewHeight, _minThumbH));
} }
void SingleMediaPreview::resizeEvent(QResizeEvent *e) { void SingleMediaPreview::resizeEvent(QResizeEvent *e) {
@ -233,26 +231,31 @@ void SingleMediaPreview::paintEvent(QPaintEvent *e) {
Painter p(this); Painter p(this);
if (!_sticker) { if (!_sticker) {
if (_previewLeft > st::boxPhotoPadding.left()) { const auto &padding = st::boxPhotoPadding;
if (_previewLeft > padding.left()) {
p.fillRect( p.fillRect(
st::boxPhotoPadding.left(), padding.left(),
0, _previewTop,
_previewLeft - st::boxPhotoPadding.left(), _previewLeft - padding.left(),
_previewHeight, _previewHeight,
st::confirmBg); st::confirmBg);
} }
if ((_previewLeft + _previewWidth) if ((_previewLeft + _previewWidth) < (width() - padding.right())) {
< (width() - st::boxPhotoPadding.right())) {
p.fillRect( p.fillRect(
_previewLeft + _previewWidth, _previewLeft + _previewWidth,
0, _previewTop,
width() width() - padding.right() - _previewLeft - _previewWidth,
- st::boxPhotoPadding.right()
- _previewLeft
- _previewWidth,
_previewHeight, _previewHeight,
st::confirmBg); st::confirmBg);
} }
if (_previewTop > 0) {
p.fillRect(
padding.left(),
0,
width() - padding.right() - padding.left(),
height(),
st::confirmBg);
}
} }
if (_gifPreview && _gifPreview->started()) { if (_gifPreview && _gifPreview->started()) {
auto s = QSize(_previewWidth, _previewHeight); auto s = QSize(_previewWidth, _previewHeight);
@ -265,7 +268,7 @@ void SingleMediaPreview::paintEvent(QPaintEvent *e) {
ImageRoundRadius::None, ImageRoundRadius::None,
RectPart::None, RectPart::None,
paused ? 0 : crl::now()); paused ? 0 : crl::now());
p.drawPixmap(_previewLeft, 0, frame); p.drawPixmap(_previewLeft, _previewTop, frame);
} else if (_lottiePreview && _lottiePreview->ready()) { } else if (_lottiePreview && _lottiePreview->ready()) {
const auto frame = _lottiePreview->frame(); const auto frame = _lottiePreview->frame();
const auto size = frame.size() / style::DevicePixelRatio(); const auto size = frame.size() / style::DevicePixelRatio();
@ -278,13 +281,13 @@ void SingleMediaPreview::paintEvent(QPaintEvent *e) {
frame); frame);
_lottiePreview->markFrameShown(); _lottiePreview->markFrameShown();
} else { } else {
p.drawPixmap(_previewLeft, 0, _preview); p.drawPixmap(_previewLeft, _previewTop, _preview);
} }
if (_animated && !_gifPreview && !_lottiePreview) { if (_animated && !_gifPreview && !_lottiePreview) {
const auto innerSize = st::msgFileLayout.thumbSize; const auto innerSize = st::msgFileLayout.thumbSize;
auto inner = QRect( auto inner = QRect(
_previewLeft + (_previewWidth - innerSize) / 2, _previewLeft + (_previewWidth - innerSize) / 2,
(_previewHeight - innerSize) / 2, _previewTop + (_previewHeight - innerSize) / 2,
innerSize, innerSize,
innerSize); innerSize);
p.setPen(Qt::NoPen); p.setPen(Qt::NoPen);

View file

@ -56,11 +56,13 @@ private:
bool _sticker = false; bool _sticker = false;
QPixmap _preview; QPixmap _preview;
int _previewLeft = 0; int _previewLeft = 0;
int _previewTop = 0;
int _previewWidth = 0; int _previewWidth = 0;
int _previewHeight = 0; int _previewHeight = 0;
Media::Clip::ReaderPointer _gifPreview; Media::Clip::ReaderPointer _gifPreview;
std::unique_ptr<Lottie::SinglePlayer> _lottiePreview; std::unique_ptr<Lottie::SinglePlayer> _lottiePreview;
const int _minThumbH;
const base::unique_qptr<AbstractButton> _photoEditorButton; const base::unique_qptr<AbstractButton> _photoEditorButton;
const base::unique_qptr<AttachControlsWidget> _controls; const base::unique_qptr<AttachControlsWidget> _controls;