From 8b1f2be27be18459ba2c8f4d675b5bf36f7d2307 Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Mon, 1 Sep 2025 17:41:26 +1000 Subject: internal: format cpp --- plugin/src/Caelestia/cachingimagemanager.cpp | 114 +++++++++++++++------------ 1 file changed, 62 insertions(+), 52 deletions(-) (limited to 'plugin/src/Caelestia/cachingimagemanager.cpp') diff --git a/plugin/src/Caelestia/cachingimagemanager.cpp b/plugin/src/Caelestia/cachingimagemanager.cpp index a5f71ba..8f2867a 100644 --- a/plugin/src/Caelestia/cachingimagemanager.cpp +++ b/plugin/src/Caelestia/cachingimagemanager.cpp @@ -1,14 +1,14 @@ #include "cachingimagemanager.hpp" -#include -#include -#include #include -#include -#include #include -#include +#include #include +#include +#include +#include +#include +#include qreal CachingImageManager::effectiveScale() const { if (m_item && m_item->window()) { @@ -49,8 +49,12 @@ void CachingImageManager::setItem(QQuickItem* item) { emit itemChanged(); if (item) { - m_widthConn = connect(item, &QQuickItem::widthChanged, this, [this]() { updateSource(); }); - m_heightConn = connect(item, &QQuickItem::heightChanged, this, [this]() { updateSource(); }); + m_widthConn = connect(item, &QQuickItem::widthChanged, this, [this]() { + updateSource(); + }); + m_heightConn = connect(item, &QQuickItem::heightChanged, this, [this]() { + updateSource(); + }); updateSource(); } } @@ -104,49 +108,54 @@ void CachingImageManager::updateSource(const QString& path) { QThreadPool::globalInstance()->start([path, self] { const QString sha = self->sha256sum(path); - QMetaObject::invokeMethod(self, [path, sha, self]() { - if (!self || self->m_path != path) { - // Object is destroyed or path has changed, ignore - return; - } - - const QSize size = self->effectiveSize(); - - if (!self->m_item || !size.width() || !size.height()) { - return; - } - - const QString fillMode = self->m_item->property("fillMode").toString(); - const QString filename = QString("%1@%2x%3-%4.png") - .arg(sha).arg(size.width()).arg(size.height()) - .arg(fillMode == "PreserveAspectCrop" ? "crop" : fillMode == "PreserveAspectFit" ? "fit" : "stretch"); - - const QUrl cache = self->m_cacheDir.resolved(QUrl(filename)); - if (self->m_cachePath == cache) { - return; - } - - self->m_cachePath = cache; - emit self->cachePathChanged(); - - if (!cache.isLocalFile()) { - qWarning() << "CachingImageManager::updateSource: cachePath" << cache << "is not a local file"; - return; - } - - const QImageReader reader(cache.toLocalFile()); - if (reader.canRead()) { - self->m_item->setProperty("source", cache); - } else { - self->m_item->setProperty("source", QUrl::fromLocalFile(path)); - self->createCache(path, cache.toLocalFile(), fillMode, size); - } - - // Clear current running sha if same - if (self->m_shaPath == path) { - self->m_shaPath = QString(); - } - }, Qt::QueuedConnection); + QMetaObject::invokeMethod( + self, + [path, sha, self]() { + if (!self || self->m_path != path) { + // Object is destroyed or path has changed, ignore + return; + } + + const QSize size = self->effectiveSize(); + + if (!self->m_item || !size.width() || !size.height()) { + return; + } + + const QString fillMode = self->m_item->property("fillMode").toString(); + // clang-format off + const QString filename = QString("%1@%2x%3-%4.png") + .arg(sha).arg(size.width()).arg(size.height()) + .arg(fillMode == "PreserveAspectCrop" ? "crop" : fillMode == "PreserveAspectFit" ? "fit" : "stretch"); + // clang-format on + + const QUrl cache = self->m_cacheDir.resolved(QUrl(filename)); + if (self->m_cachePath == cache) { + return; + } + + self->m_cachePath = cache; + emit self->cachePathChanged(); + + if (!cache.isLocalFile()) { + qWarning() << "CachingImageManager::updateSource: cachePath" << cache << "is not a local file"; + return; + } + + const QImageReader reader(cache.toLocalFile()); + if (reader.canRead()) { + self->m_item->setProperty("source", cache); + } else { + self->m_item->setProperty("source", QUrl::fromLocalFile(path)); + self->createCache(path, cache.toLocalFile(), fillMode, size); + } + + // Clear current running sha if same + if (self->m_shaPath == path) { + self->m_shaPath = QString(); + } + }, + Qt::QueuedConnection); }); } @@ -154,7 +163,8 @@ QUrl CachingImageManager::cachePath() const { return m_cachePath; } -void CachingImageManager::createCache(const QString& path, const QString& cache, const QString& fillMode, const QSize& size) const { +void CachingImageManager::createCache( + const QString& path, const QString& cache, const QString& fillMode, const QSize& size) const { QThreadPool::globalInstance()->start([path, cache, fillMode, size] { QImage image(path); -- cgit v1.2.3-freya