From 45b3575d7902d99a3c8a31987b4ef92d4ba5d78f Mon Sep 17 00:00:00 2001 From: "anthony.bilinski" Date: Fri, 13 Oct 2017 14:52:27 -0700 Subject: [PATCH] fix(preview): only downscale preview images, never upscale Fixes #4733 --- src/chatlog/content/filetransferwidget.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/chatlog/content/filetransferwidget.cpp b/src/chatlog/content/filetransferwidget.cpp index 429fe4ba6..d1bbb9506 100644 --- a/src/chatlog/content/filetransferwidget.cpp +++ b/src/chatlog/content/filetransferwidget.cpp @@ -549,8 +549,18 @@ void FileTransferWidget::showPreview(const QString& filename) ui->previewButton->show(); // Show mouseover preview, but make sure it's not larger than 50% of the screen width/height const QRect desktopSize = QApplication::desktop()->screenGeometry(); - const QImage previewImage = image.scaled(0.5 * desktopSize.width(), 0.5 * desktopSize.height(), - Qt::KeepAspectRatio, Qt::SmoothTransformation); + const int maxPreviewWidth{desktopSize.width() / 2}; + const int maxPreviewHeight{desktopSize.height() /2}; + const QImage previewImage = [&image, maxPreviewWidth, maxPreviewHeight]() { + if (image.width() > maxPreviewWidth || image.height() > maxPreviewHeight) { + return image.scaled(maxPreviewWidth, maxPreviewHeight, + Qt::KeepAspectRatio, Qt::SmoothTransformation); + } + else { + return image; + } + }(); + QByteArray imageData; QBuffer buffer(&imageData); buffer.open(QIODevice::WriteOnly);