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 <mats.honkamaa@qt.io>
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
Miikka Heikkinen
2024-10-18 16:55:53 +03:00
parent 529fb8eca7
commit 4f97a18f97
3 changed files with 59 additions and 7 deletions

View File

@@ -933,6 +933,7 @@ R"(
s += " property int animatedFrame: frameAnimation.currentFrame\n"; s += " property int animatedFrame: frameAnimation.currentFrame\n";
} }
QString imageFixerTag{"___ecImagefixer___"};
QString parentChanged{ QString parentChanged{
R"( R"(
function setupParentLayer() function setupParentLayer()
@@ -960,6 +961,7 @@ R"(
} }
parent.update() parent.update()
} }
%9
} }
onParentChanged: setupParentLayer() onParentChanged: setupParentLayer()
@@ -995,9 +997,12 @@ R"(
m_extraMargin ? QString("\n connectSource(true)\n") : QString(), m_extraMargin ? QString("\n connectSource(true)\n") : QString(),
mipmap1, mipmap1,
mipmap2, mipmap2,
mipmap3); mipmap3,
imageFixerTag);
} else { } else {
parentChanged = parentChanged.arg(QString(), QString(), QString()); parentChanged = parentChanged.arg(QString(), QString(), QString(),
QString(), QString(), QString(),
QString(), QString(), QString());
} }
s += parentChanged; s += parentChanged;
@@ -1015,7 +1020,8 @@ R"(
s += '\n'; s += '\n';
} }
QString customImagesString = getQmlImagesString(true); QString imageFixerStr;
QString customImagesString = getQmlImagesString(true, imageFixerStr);
if (!customImagesString.isEmpty()) if (!customImagesString.isEmpty())
s += customImagesString; s += customImagesString;
@@ -1024,6 +1030,9 @@ R"(
s += getQmlComponentString(true); s += getQmlComponentString(true);
s += " }\n"; s += " }\n";
s += "}\n"; s += "}\n";
s.replace(imageFixerTag, imageFixerStr);
return s; return s;
} }
@@ -2053,14 +2062,38 @@ void EffectComposerModel::setHasValidTarget(bool validTarget)
emit hasValidTargetChanged(); 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; QString imagesString;
const QList<Uniform *> uniforms = allUniforms(); const QList<Uniform *> uniforms = allUniforms();
for (Uniform *uniform : uniforms) { for (Uniform *uniform : uniforms) {
if (uniform->type() == Uniform::Type::Sampler) { if (uniform->type() == Uniform::Type::Sampler) {
QString imagePath = uniform->value().toString(); QString imagePath = uniform->value().toString();
if (localFiles) { 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); QFileInfo fi(imagePath);
imagePath = fi.fileName(); imagePath = fi.fileName();
imagesString += QString(" property url %1Url: \"%2\"\n") imagesString += QString(" property url %1Url: \"%2\"\n")
@@ -2140,7 +2173,8 @@ QString EffectComposerModel::getQmlComponentString(bool localFiles)
s += localFiles ? m_exportedEffectPropertiesString : m_previewEffectPropertiesString; s += localFiles ? m_exportedEffectPropertiesString : m_previewEffectPropertiesString;
if (!localFiles) { if (!localFiles) {
QString customImagesString = getQmlImagesString(false); QString dummyStr;
QString customImagesString = getQmlImagesString(false, dummyStr);
if (!customImagesString.isEmpty()) if (!customImagesString.isEmpty())
s += '\n' + customImagesString; s += '\n' + customImagesString;
} }

View File

@@ -202,7 +202,7 @@ private:
void bakeShaders(); void bakeShaders();
void saveResources(const QString &name); void saveResources(const QString &name);
QString getQmlImagesString(bool localFiles); QString getQmlImagesString(bool localFiles, QString &outImageFixerStr);
QString getQmlComponentString(bool localFiles); QString getQmlComponentString(bool localFiles);
QString getGeneratedMessage() const; QString getGeneratedMessage() const;
QString getDesignerSpecifics() const; QString getDesignerSpecifics() const;

View File

@@ -346,9 +346,27 @@ R"(
R"( R"(
UrlChooser { UrlChooser {
backendValue: backendValues.%1 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; break;
} }
case Type::Define: case Type::Define: