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

Use QImage scaling and base64 encoding for sharper previews

This commit is contained in:
TheLastProject 2015-03-08 21:01:34 +01:00
parent bd12381bea
commit b659612bd4

View File

@ -24,6 +24,7 @@
#include <QMouseEvent>
#include <QFileDialog>
#include <QFile>
#include <QBuffer>
#include <QMessageBox>
#include <QDesktopServices>
#include <QDesktopWidget>
@ -451,22 +452,13 @@ void FileTransferWidget::showPreview(const QString &filename)
ui->previewLabel->setPixmap(pmap);
ui->previewLabel->show();
// Show preview, but make sure it's not larger than 50% of the screen width/height
QRect maxSize = QApplication::desktop()->screenGeometry();
maxSize.setWidth(0.5*maxSize.width());
maxSize.setHeight(0.5*maxSize.height());
QImage image = QImage(filename);
QSize imageSize(image.width(), image.height());
if (imageSize.width() > maxSize.width() || imageSize.height() > maxSize.height())
{
imageSize.scale(maxSize.width(), maxSize.height(), Qt::KeepAspectRatio);
ui->previewLabel->setToolTip("<html><img src="+QUrl::toPercentEncoding(filename)+" width="+QString::number(imageSize.width())+" height="+QString::number(imageSize.height())+"/></html>");
}
else
{
ui->previewLabel->setToolTip("<html><img src"+QUrl::toPercentEncoding(filename)+"/></html>");
}
// Show mouseover preview, but make sure it's not larger than 50% of the screen width/height
QRect desktopSize = QApplication::desktop()->screenGeometry();
QImage image = QImage(filename).scaled(0.5*desktopSize.width(), 0.5*desktopSize.height(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
QByteArray imageData;
QBuffer buffer(&imageData);
image.save(&buffer, "PNG");
ui->previewLabel->setToolTip("<img src=data:image/png;base64," + imageData.toBase64() + "/>");
}
}