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 <QMouseEvent>
#include <QFileDialog> #include <QFileDialog>
#include <QFile> #include <QFile>
#include <QBuffer>
#include <QMessageBox> #include <QMessageBox>
#include <QDesktopServices> #include <QDesktopServices>
#include <QDesktopWidget> #include <QDesktopWidget>
@ -451,22 +452,13 @@ void FileTransferWidget::showPreview(const QString &filename)
ui->previewLabel->setPixmap(pmap); ui->previewLabel->setPixmap(pmap);
ui->previewLabel->show(); ui->previewLabel->show();
// Show 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
QRect maxSize = QApplication::desktop()->screenGeometry(); QRect desktopSize = QApplication::desktop()->screenGeometry();
maxSize.setWidth(0.5*maxSize.width()); QImage image = QImage(filename).scaled(0.5*desktopSize.width(), 0.5*desktopSize.height(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
maxSize.setHeight(0.5*maxSize.height()); QByteArray imageData;
QBuffer buffer(&imageData);
QImage image = QImage(filename); image.save(&buffer, "PNG");
QSize imageSize(image.width(), image.height()); ui->previewLabel->setToolTip("<img src=data:image/png;base64," + imageData.toBase64() + "/>");
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>");
}
} }
} }