From 4f97a18f973f61b38bec287ac75ed4a9e9beac08 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Fri, 18 Oct 2024 16:55:53 +0300 Subject: [PATCH] EffectComposer: Add ItemFilterComboBox for sampler properties Composed effects property sheet will now show ItemFilterComboBox in addition to UrlChooser for sampler properties. Selecting an item will override the chosen url image for the sampler. Items as samplers are not supported in the effect preview, as effect preview is not part of the main scene. Fixes: QDS-11996 Change-Id: I35b3426803694e000de4618a241fb06cde44b5c9 Reviewed-by: Mats Honkamaa Reviewed-by: Mahmoud Badri --- .../effectcomposer/effectcomposermodel.cpp | 44 ++++++++++++++++--- .../effectcomposer/effectcomposermodel.h | 2 +- src/plugins/effectcomposer/uniform.cpp | 20 ++++++++- 3 files changed, 59 insertions(+), 7 deletions(-) diff --git a/src/plugins/effectcomposer/effectcomposermodel.cpp b/src/plugins/effectcomposer/effectcomposermodel.cpp index 32dce7cef65..3063283bffc 100644 --- a/src/plugins/effectcomposer/effectcomposermodel.cpp +++ b/src/plugins/effectcomposer/effectcomposermodel.cpp @@ -933,6 +933,7 @@ R"( s += " property int animatedFrame: frameAnimation.currentFrame\n"; } + QString imageFixerTag{"___ecImagefixer___"}; QString parentChanged{ R"( function setupParentLayer() @@ -960,6 +961,7 @@ R"( } parent.update() } +%9 } onParentChanged: setupParentLayer() @@ -995,9 +997,12 @@ R"( m_extraMargin ? QString("\n connectSource(true)\n") : QString(), mipmap1, mipmap2, - mipmap3); + mipmap3, + imageFixerTag); } else { - parentChanged = parentChanged.arg(QString(), QString(), QString()); + parentChanged = parentChanged.arg(QString(), QString(), QString(), + QString(), QString(), QString(), + QString(), QString(), QString()); } s += parentChanged; @@ -1015,7 +1020,8 @@ R"( s += '\n'; } - QString customImagesString = getQmlImagesString(true); + QString imageFixerStr; + QString customImagesString = getQmlImagesString(true, imageFixerStr); if (!customImagesString.isEmpty()) s += customImagesString; @@ -1024,6 +1030,9 @@ R"( s += getQmlComponentString(true); s += " }\n"; s += "}\n"; + + s.replace(imageFixerTag, imageFixerStr); + return s; } @@ -2053,14 +2062,38 @@ void EffectComposerModel::setHasValidTarget(bool validTarget) emit hasValidTargetChanged(); } -QString EffectComposerModel::getQmlImagesString(bool localFiles) +QString EffectComposerModel::getQmlImagesString(bool localFiles, QString &outImageFixerStr) { + const QString imageItemChanged{ +R"( + property var old%2: null + function %3 + { + if (old%2) { + old%2.layer.enabled = false + old%2 = null + } + if (%1 != imageItem%1) { + %1.layer.enabled = true + old%2 = %1 + } + } + on%2Changed: %3 +)" + }; + QString imagesString; const QList uniforms = allUniforms(); for (Uniform *uniform : uniforms) { if (uniform->type() == Uniform::Type::Sampler) { QString imagePath = uniform->value().toString(); if (localFiles) { + QString capitalName = uniform->name(); + if (!capitalName.isEmpty()) + capitalName[0] = capitalName[0].toUpper(); + QString funcName = "setupLayer_" + uniform->name() + "()"; + outImageFixerStr += "\n " + funcName; + imagesString += imageItemChanged.arg(uniform->name(), capitalName, funcName); QFileInfo fi(imagePath); imagePath = fi.fileName(); imagesString += QString(" property url %1Url: \"%2\"\n") @@ -2140,7 +2173,8 @@ QString EffectComposerModel::getQmlComponentString(bool localFiles) s += localFiles ? m_exportedEffectPropertiesString : m_previewEffectPropertiesString; if (!localFiles) { - QString customImagesString = getQmlImagesString(false); + QString dummyStr; + QString customImagesString = getQmlImagesString(false, dummyStr); if (!customImagesString.isEmpty()) s += '\n' + customImagesString; } diff --git a/src/plugins/effectcomposer/effectcomposermodel.h b/src/plugins/effectcomposer/effectcomposermodel.h index fc04255f111..0fe4aeb84f9 100644 --- a/src/plugins/effectcomposer/effectcomposermodel.h +++ b/src/plugins/effectcomposer/effectcomposermodel.h @@ -202,7 +202,7 @@ private: void bakeShaders(); void saveResources(const QString &name); - QString getQmlImagesString(bool localFiles); + QString getQmlImagesString(bool localFiles, QString &outImageFixerStr); QString getQmlComponentString(bool localFiles); QString getGeneratedMessage() const; QString getDesignerSpecifics() const; diff --git a/src/plugins/effectcomposer/uniform.cpp b/src/plugins/effectcomposer/uniform.cpp index c42f11063d6..c0129f85557 100644 --- a/src/plugins/effectcomposer/uniform.cpp +++ b/src/plugins/effectcomposer/uniform.cpp @@ -346,9 +346,27 @@ R"( R"( UrlChooser { backendValue: backendValues.%1 + enabled: comboBox_%1.currentIndex === 0 + } + ExpandingSpacer {} + } + + PropertyLabel { + text: "%3" + tooltip: "%4" + } + + SecondColumnLayout { + ItemFilterComboBox { + id: comboBox_%1 + backendValue: backendValues.%2 } )"; - specs += typeSpec.arg(m_name + "Url"); + specs += typeSpec.arg(m_name + "Url") + .arg(m_name) + .arg(m_displayName + tr(" Item")) + .arg(tr("Set this to use an item in the scene as %1 instead of the above image.") + .arg(m_displayName)); break; } case Type::Define: