diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2024-02-14 14:45:20 +0100 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2024-02-15 05:07:22 +0100 |
commit | 5b993fa8ede67871a8b2434505bc3c3d8bb906c6 (patch) | |
tree | 852069b8cae09d9cf4a44770ad305e05cee32236 /src/gui/platform/darwin | |
parent | 477381993a3899c73e240e0fb2dc2b9f67f8cb63 (diff) |
AppleIconEngine: fix aspect ratio adjustment
The requested icon might not be square, so fit the image
we have correctly into the requested size.
Fixes: QTBUG-121764
Pick-to: 6.7
Change-Id: I877dedf5aa779cd82a75a1a49b26c08e3cea6163
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/gui/platform/darwin')
-rw-r--r-- | src/gui/platform/darwin/qappleiconengine.mm | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/gui/platform/darwin/qappleiconengine.mm b/src/gui/platform/darwin/qappleiconengine.mm index 154d3b79bb..049bd827f9 100644 --- a/src/gui/platform/darwin/qappleiconengine.mm +++ b/src/gui/platform/darwin/qappleiconengine.mm @@ -185,18 +185,19 @@ QPixmap QAppleIconEngine::scaledPixmap(const QSize &size, QIcon::Mode mode, QIco } const auto *image = configuredImage(m_image, color); - // the size we want is typically square, but the icon might not be. So - // ask for a pixmap with the same aspect ratio as the icon, and then - // center that within a pixmap of the requested size. + // The size we want might have a different aspect ratio than the icon we have. + // So ask for a pixmap with the same aspect ratio as the icon, constrained to the + // size we want, and then center that within a pixmap of the requested size. QSizeF renderSize = size * scale; - const bool aspectRatioAdjusted = image.size.width != image.size.height; + const double inputAspectRatio = image.size.width / image.size.height; + const double outputAspectRatio = size.width() / size.height(); + const bool aspectRatioAdjusted = !qFuzzyCompare(inputAspectRatio, outputAspectRatio); if (aspectRatioAdjusted) { - double aspectRatio = image.size.width / image.size.height; // don't grow - if (aspectRatio < 1) - renderSize.rwidth() = renderSize.height() * aspectRatio; + if (outputAspectRatio > inputAspectRatio) + renderSize.rwidth() = renderSize.height() * inputAspectRatio; else - renderSize.rheight() = renderSize.width() / aspectRatio; + renderSize.rheight() = renderSize.width() / inputAspectRatio; } QPixmap iconPixmap = imageToPixmap(image, renderSize); |