Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
fix(preview): only downscale preview images, never upscale
Browse files Browse the repository at this point in the history
Fixes #4733
  • Loading branch information
anthonybilinski committed Oct 20, 2017
1 parent 2f1bf10 commit 45b3575
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/chatlog/content/filetransferwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 45b3575

Please sign in to comment.