From c2fcbd64d37b7efd780ec0c0b70918babff076b2 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Mon, 6 Sep 2021 17:04:56 +0300 Subject: [PATCH] Revert "optimize QSize::scale()" This reverts commit d4b64a5536a75b7fc656ee1e445b4d53ffc332cf. --- src/core/tools/qsize.cpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/core/tools/qsize.cpp b/src/core/tools/qsize.cpp index 63c3dbf0b..0d1e7977e 100644 --- a/src/core/tools/qsize.cpp +++ b/src/core/tools/qsize.cpp @@ -182,22 +182,21 @@ void QSize::scale(const QSize &s, Qt::AspectRatioMode mode) if (mode == Qt::IgnoreAspectRatio || wd == 0 || ht == 0) { wd = s.wd; ht = s.ht; - } else if (mode == Qt::KeepAspectRatio) { - int rw = s.ht * wd / ht; - if (rw <= s.wd) { - wd = rw; - ht = s.ht; - } else { - ht = s.wd * ht / wd; - wd = s.wd; + } else { + bool useHeight; + qint64 rw = qint64(s.ht) * qint64(wd) / qint64(ht); + + if (mode == Qt::KeepAspectRatio) { + useHeight = (rw <= s.wd); + } else { // mode == Qt::KeepAspectRatioByExpanding + useHeight = (rw >= s.wd); } - } else { // mode == Qt::KeepAspectRatioByExpanding - int rw = s.ht * wd / ht; - if (rw >= s.wd) { + + if (useHeight) { wd = rw; ht = s.ht; } else { - ht = s.wd * ht / wd; + ht = qint32(qint64(s.wd) * qint64(ht) / qint64(wd)); wd = s.wd; } } -- 2.11.0