QmlDesigner: Generate the effect qml code

Task-number: QDS-10811
Change-Id: I5f0e969ee21ae49580c2632da483f5701dab9c41
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
This commit is contained in:
Amr Essam
2023-10-03 16:00:01 +03:00
committed by Amr Elsayed
parent d08b4bcb31
commit 340a1c1156
4 changed files with 82 additions and 1 deletions

View File

@@ -851,7 +851,7 @@ void EffectMakerModel::setShadersUpToDate(bool UpToDate)
emit shadersUpToDateChanged(); emit shadersUpToDateChanged();
} }
QString EffectMakerModel::getQmlComponentString(bool localFiles) QString EffectMakerModel::getQmlImagesString(bool localFiles)
{ {
Q_UNUSED(localFiles) Q_UNUSED(localFiles)
@@ -859,6 +859,72 @@ QString EffectMakerModel::getQmlComponentString(bool localFiles)
return QString(); return QString();
} }
QString EffectMakerModel::getQmlComponentString(bool localFiles)
{
auto addProperty = [localFiles](const QString &name, const QString &var,
const QString &type, bool blurHelper = false)
{
if (localFiles) {
const QString parent = blurHelper ? QString("blurHelper.") : QString("rootItem.");
return QString("readonly property alias %1: %2%3\n").arg(name, parent, var);
} else {
const QString parent = blurHelper ? "blurHelper." : QString();
return QString("readonly property %1 %2: %3%4\n").arg(type, name, parent, var);
}
};
QString customImagesString = getQmlImagesString(localFiles);
QString vertexShaderFilename = "file:///" + m_fragmentShaderFile.fileName();
QString fragmentShaderFilename = "file:///" + m_vertexShaderFile.fileName();
QString s;
QString l1 = localFiles ? QStringLiteral(" ") : QStringLiteral("");
QString l2 = localFiles ? QStringLiteral(" ") : QStringLiteral(" ");
QString l3 = localFiles ? QStringLiteral(" ") : QStringLiteral(" ");
if (!localFiles)
s += "import QtQuick\n";
s += l1 + "ShaderEffect {\n";
if (m_shaderFeatures.enabled(ShaderFeatures::Source))
s += l2 + addProperty("iSource", "source", "Item");
if (m_shaderFeatures.enabled(ShaderFeatures::Time))
s += l2 + addProperty("iTime", "animatedTime", "real");
if (m_shaderFeatures.enabled(ShaderFeatures::Frame))
s += l2 + addProperty("iFrame", "animatedFrame", "int");
if (m_shaderFeatures.enabled(ShaderFeatures::Resolution)) {
// Note: Pixel ratio is currently always 1.0
s += l2 + "readonly property vector3d iResolution: Qt.vector3d(width, height, 1.0)\n";
}
if (m_shaderFeatures.enabled(ShaderFeatures::Mouse)) { // Do we need interactive effects?
s += l2 + "readonly property vector4d iMouse: Qt.vector4d(rootItem._effectMouseX, rootItem._effectMouseY,\n";
s += l2 + " rootItem._effectMouseZ, rootItem._effectMouseW)\n";
}
if (m_shaderFeatures.enabled(ShaderFeatures::BlurSources)) {
s += l2 + addProperty("iSourceBlur1", "blurSrc1", "Item", true);
s += l2 + addProperty("iSourceBlur2", "blurSrc2", "Item", true);
s += l2 + addProperty("iSourceBlur3", "blurSrc3", "Item", true);
s += l2 + addProperty("iSourceBlur4", "blurSrc4", "Item", true);
s += l2 + addProperty("iSourceBlur5", "blurSrc5", "Item", true);
}
// When used in preview component, we need property with value
// and when in exported component, property with binding to root value.
s += localFiles ? m_exportedEffectPropertiesString : m_previewEffectPropertiesString;
if (!customImagesString.isEmpty())
s += '\n' + customImagesString;
s += '\n';
s += l2 + "vertexShader: '" + vertexShaderFilename + "'\n";
s += l2 + "fragmentShader: '" + fragmentShaderFilename + "'\n";
s += l2 + "anchors.fill: parent\n";
if (m_shaderFeatures.enabled(ShaderFeatures::GridMesh)) {
QString gridSize = QString("%1, %2").arg(m_shaderFeatures.gridMeshWidth()).arg(m_shaderFeatures.gridMeshHeight());
s += l2 + "mesh: GridMesh {\n";
s += l3 + QString("resolution: Qt.size(%1)\n").arg(gridSize);
s += l2 + "}\n";
}
s += l1 + "}\n";
return s;
}
void EffectMakerModel::updateQmlComponent() void EffectMakerModel::updateQmlComponent()
{ {
// Clear possible QML runtime errors // Clear possible QML runtime errors

View File

@@ -124,6 +124,7 @@ private:
void updateCustomUniforms(); void updateCustomUniforms();
void bakeShaders(); void bakeShaders();
QString getQmlImagesString(bool localFiles);
QString getQmlComponentString(bool localFiles); QString getQmlComponentString(bool localFiles);
QList<CompositionNode *> m_nodes; QList<CompositionNode *> m_nodes;

View File

@@ -77,5 +77,15 @@ void ShaderFeatures::checkLine(const QString &line, Features &features)
features.setFlag(BlurSources, true); features.setFlag(BlurSources, true);
} }
int ShaderFeatures::gridMeshHeight() const
{
return m_gridMeshHeight;
}
int ShaderFeatures::gridMeshWidth() const
{
return m_gridMeshWidth;
}
} // namespace EffectMaker } // namespace EffectMaker

View File

@@ -28,6 +28,10 @@ public:
bool enabled(ShaderFeatures::Feature feature) const; bool enabled(ShaderFeatures::Feature feature) const;
int gridMeshWidth() const;
int gridMeshHeight() const;
private: private:
void checkLine(const QString &line, ShaderFeatures::Features &features); void checkLine(const QString &line, ShaderFeatures::Features &features);
ShaderFeatures::Features m_enabledFeatures; ShaderFeatures::Features m_enabledFeatures;