From 9c0bba79b23c94113ddd697046205ee5ee183e0d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Mon, 6 Dec 2021 16:11:51 -0500
Subject: [PATCH] previewrender: do not overflow if ratio is greater than 1

Change-Id: Id7f443a354691d7b5b0a71e6e8b35a4cd0005a88
GitLab: #611
---
 src/previewrenderer.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/previewrenderer.cpp b/src/previewrenderer.cpp
index 34452a1dd..3db0759fa 100644
--- a/src/previewrenderer.cpp
+++ b/src/previewrenderer.cpp
@@ -53,8 +53,8 @@ PreviewRenderer::paint(QPainter* painter)
 
             auto aspectRatio = static_cast<qreal>(previewImage->width())
                                / static_cast<qreal>(previewImage->height());
-            auto previewHeight = height();
-            auto previewWidth = previewHeight * aspectRatio;
+            auto previewHeight = aspectRatio < 1 ? height() : width() / aspectRatio;
+            auto previewWidth = aspectRatio < 1 ? previewHeight * aspectRatio : width();
 
             /* Instead of setting fixed size, we could get an x offset for the preview
              * but this would render the horizontal spacers in the parent widget useless.
-- 
GitLab