Make preview files on the local disk for the 'Latest uploads' smaller

This commit is contained in:
Yuriy Puchkov
2020-10-28 11:48:40 +02:00
parent 2f03c51aab
commit babbbb8f9b
4 changed files with 17 additions and 4 deletions

View File

@@ -30,9 +30,20 @@ const QString& History::path()
void History::save(const QPixmap& pixmap, const QString& fileName)
{
// scale preview only in local disk
QPixmap pixmapScaled = QPixmap(pixmap);
if (pixmap.height() / HISTORYPIXMAP_MAX_PREVIEW_HEIGHT >=
pixmap.width() / HISTORYPIXMAP_MAX_PREVIEW_WIDTH) {
pixmapScaled = pixmap.scaledToHeight(HISTORYPIXMAP_MAX_PREVIEW_HEIGHT);
} else {
pixmapScaled = pixmap.scaledToWidth(HISTORYPIXMAP_MAX_PREVIEW_WIDTH);
}
// save preview
QFile file(path() + fileName);
file.open(QIODevice::WriteOnly);
pixmap.save(&file, "PNG");
pixmapScaled.save(&file, "PNG");
history();
}

View File

@@ -3,6 +3,9 @@
#define HISTORY_MAX_SIZE 25
#define HISTORYPIXMAP_MAX_PREVIEW_WIDTH 160
#define HISTORYPIXMAP_MAX_PREVIEW_HEIGHT 90
#include <QList>
#include <QPixmap>
#include <QString>

View File

@@ -106,6 +106,8 @@ void HistoryWidget::addLine(const QString& path, const QString& fileName)
QPixmap pixmap;
pixmap.load(fullFileName, "png");
// TODO - remove much later, it is still required to keep old previews works
// fine
if (pixmap.height() / HISTORYPIXMAP_MAX_PREVIEW_HEIGHT >=
pixmap.width() / HISTORYPIXMAP_MAX_PREVIEW_WIDTH) {
pixmap = pixmap.scaledToHeight(HISTORYPIXMAP_MAX_PREVIEW_HEIGHT);

View File

@@ -1,9 +1,6 @@
#ifndef HISTORYWIDGET_H
#define HISTORYWIDGET_H
#define HISTORYPIXMAP_MAX_PREVIEW_WIDTH 160
#define HISTORYPIXMAP_MAX_PREVIEW_HEIGHT 90
#include <QDialog>
#include <QObject>
#include <QString>