1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Merge pull request #4734

anthony.bilinski (1):
      fix(preview): only downscale preview images, never upscale
This commit is contained in:
sudden6 2017-10-22 14:00:03 +02:00
commit acfe237e74
No known key found for this signature in database
GPG Key ID: 279509B499E032B9

View File

@ -549,8 +549,18 @@ void FileTransferWidget::showPreview(const QString& filename)
ui->previewButton->show(); ui->previewButton->show();
// Show mouseover preview, but make sure it's not larger than 50% of the screen width/height // Show mouseover preview, but make sure it's not larger than 50% of the screen width/height
const QRect desktopSize = QApplication::desktop()->screenGeometry(); const QRect desktopSize = QApplication::desktop()->screenGeometry();
const QImage previewImage = image.scaled(0.5 * desktopSize.width(), 0.5 * desktopSize.height(), const int maxPreviewWidth{desktopSize.width() / 2};
Qt::KeepAspectRatio, Qt::SmoothTransformation); 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; QByteArray imageData;
QBuffer buffer(&imageData); QBuffer buffer(&imageData);
buffer.open(QIODevice::WriteOnly); buffer.open(QIODevice::WriteOnly);