plugin/cim: fix cache path

Different cache paths for different fill modes
This commit is contained in:
2 * r + 2 * t 2025-08-30 17:05:49 +10:00
parent 6ce97df535
commit 95bf6e3f52
2 changed files with 8 additions and 7 deletions

View file

@ -111,7 +111,10 @@ void CachingImageManager::updateSource(const QString& path) {
int width = effectiveWidth(); int width = effectiveWidth();
int height = effectiveHeight(); int height = effectiveHeight();
const QString filename = QString("%1@%2x%3.png").arg(sha).arg(width).arg(height); const QString fillMode = m_item->property("fillMode").toString();
const QString filename = QString("%1@%2x%3-%4.png")
.arg(sha).arg(width).arg(height)
.arg(fillMode == "PreserveAspectCrop" ? "crop" : fillMode == "PreserveAspectFit" ? "fit" : "stretch");
const QUrl cache = m_cacheDir.resolved(QUrl(filename)); const QUrl cache = m_cacheDir.resolved(QUrl(filename));
if (m_cachePath == cache) { if (m_cachePath == cache) {
@ -132,7 +135,7 @@ void CachingImageManager::updateSource(const QString& path) {
m_item->setProperty("source", cache); m_item->setProperty("source", cache);
} else { } else {
m_item->setProperty("source", QUrl::fromLocalFile(path)); m_item->setProperty("source", QUrl::fromLocalFile(path));
createCache(path, cache.toLocalFile(), QSize(width, height)); createCache(path, cache.toLocalFile(), fillMode, QSize(width, height));
} }
// Clear current running sha if same // Clear current running sha if same
@ -147,10 +150,8 @@ QUrl CachingImageManager::cachePath() const {
return m_cachePath; return m_cachePath;
} }
void CachingImageManager::createCache(const QString& path, const QString& cache, const QSize& size) const { void CachingImageManager::createCache(const QString& path, const QString& cache, const QString& fillMode, const QSize& size) const {
QString fillMode = m_item->property("fillMode").toString(); QThreadPool::globalInstance()->start([path, cache, fillMode, size] {
QThreadPool::globalInstance()->start([fillMode, path, cache, size] {
QImage image(path); QImage image(path);
if (image.isNull()) { if (image.isNull()) {

View file

@ -55,6 +55,6 @@ private:
[[nodiscard]] int effectiveWidth() const; [[nodiscard]] int effectiveWidth() const;
[[nodiscard]] int effectiveHeight() const; [[nodiscard]] int effectiveHeight() const;
void createCache(const QString& path, const QString& cache, const QSize& size) const; void createCache(const QString& path, const QString& cache, const QString& fillMode, const QSize& size) const;
[[nodiscard]] QString sha256sum(const QString& path) const; [[nodiscard]] QString sha256sum(const QString& path) const;
}; };