diff options
| author | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-08-27 23:36:54 +1000 |
|---|---|---|
| committer | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-08-27 23:36:54 +1000 |
| commit | a1d5a1639239846da3faa4a4ba3ab27bf33b58a6 (patch) | |
| tree | 2745a5ab3c2155d4a8c478bda7c861545f658792 /plugin/src/Caelestia | |
| parent | plugin: better getDominantColour (diff) | |
| download | caelestia-shell-a1d5a1639239846da3faa4a4ba3ab27bf33b58a6.tar.gz caelestia-shell-a1d5a1639239846da3faa4a4ba3ab27bf33b58a6.tar.bz2 caelestia-shell-a1d5a1639239846da3faa4a4ba3ab27bf33b58a6.zip | |
plugin: fix getDominantColour scaling
Diffstat (limited to 'plugin/src/Caelestia')
| -rw-r--r-- | plugin/src/Caelestia/cutils.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/plugin/src/Caelestia/cutils.cpp b/plugin/src/Caelestia/cutils.cpp index d17cd56..3e7742b 100644 --- a/plugin/src/Caelestia/cutils.cpp +++ b/plugin/src/Caelestia/cutils.cpp @@ -95,7 +95,7 @@ void CUtils::getDominantColour(QQuickItem* item, QJSValue callback) const { this->getDominantColour(item, 128, 128, callback); } -void CUtils::getDominantColour(QQuickItem* item, int width, int height, QJSValue callback) const { +void CUtils::getDominantColour(QQuickItem* item, int targetWidth, int targetHeight, QJSValue callback) const { if (!item) { qWarning() << "CUtils::getDominantColour: an item is required"; return; @@ -106,12 +106,20 @@ void CUtils::getDominantColour(QQuickItem* item, int width, int height, QJSValue return; } - QSharedPointer<QQuickItemGrabResult> grabResult = item->grabToImage(QSize(width, height)); + QSharedPointer<QQuickItemGrabResult> grabResult = item->grabToImage(); QObject::connect(grabResult.data(), &QQuickItemGrabResult::ready, this, - [grabResult, item, callback, this]() { + [grabResult, item, targetWidth, targetHeight, callback, this]() { QImage image = grabResult->image(); + if (image.width() > targetWidth && image.height() > targetHeight) { + image = image.scaled(targetWidth, targetHeight); + } else if (image.width() > targetWidth) { + image = image.scaledToWidth(targetWidth); + } else if (image.height() > targetHeight) { + image = image.scaledToHeight(targetHeight); + } + if (image.format() != QImage::Format_ARGB32) { image = image.convertToFormat(QImage::Format_ARGB32); } |