From babbbb8f9bb465c9e16305af60eef24ff39c0801 Mon Sep 17 00:00:00 2001 From: Yuriy Puchkov Date: Wed, 28 Oct 2020 11:48:40 +0200 Subject: [PATCH] Make preview files on the local disk for the 'Latest uploads' smaller --- src/utils/history.cpp | 13 ++++++++++++- src/utils/history.h | 3 +++ src/widgets/historywidget.cpp | 2 ++ src/widgets/historywidget.h | 3 --- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/utils/history.cpp b/src/utils/history.cpp index 35b48567..83844a7f 100644 --- a/src/utils/history.cpp +++ b/src/utils/history.cpp @@ -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(); } diff --git a/src/utils/history.h b/src/utils/history.h index a4569175..a0d7266b 100644 --- a/src/utils/history.h +++ b/src/utils/history.h @@ -3,6 +3,9 @@ #define HISTORY_MAX_SIZE 25 +#define HISTORYPIXMAP_MAX_PREVIEW_WIDTH 160 +#define HISTORYPIXMAP_MAX_PREVIEW_HEIGHT 90 + #include #include #include diff --git a/src/widgets/historywidget.cpp b/src/widgets/historywidget.cpp index 4a80eddf..83a0d8a5 100644 --- a/src/widgets/historywidget.cpp +++ b/src/widgets/historywidget.cpp @@ -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); diff --git a/src/widgets/historywidget.h b/src/widgets/historywidget.h index b713f666..163342bc 100644 --- a/src/widgets/historywidget.h +++ b/src/widgets/historywidget.h @@ -1,9 +1,6 @@ #ifndef HISTORYWIDGET_H #define HISTORYWIDGET_H -#define HISTORYPIXMAP_MAX_PREVIEW_WIDTH 160 -#define HISTORYPIXMAP_MAX_PREVIEW_HEIGHT 90 - #include #include #include