EffectMaker: Enable using project assets as effect textures

Also fixed few warnings by adding dummy needed context properties.

Change-Id: Ieed0f9d409302ba9ff1409b9081cda942e46d2e9
Reviewed-by: Amr Elsayed <amr.elsayed@qt.io>
Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
This commit is contained in:
Mahmoud Badri
2023-10-31 18:07:19 +02:00
parent b46d9de784
commit 6a5e7920ce
6 changed files with 29 additions and 10 deletions

View File

@@ -18,7 +18,6 @@ Row {
actionIndicatorVisible: false
//TODO: Disable until we figure out how to use images from outside qds
//onAbsoluteFilePathChanged: uniformValue = absoluteFilePath
onAbsoluteFilePathChanged: uniformValue = absoluteFilePath
}
}

View File

@@ -50,8 +50,21 @@ bool EffectMakerUniformsModel::setData(const QModelIndex &index, const QVariant
return false;
auto uniform = m_uniforms.at(index.row());
uniform->setValue(value);
g_propertyData.insert(uniform->name(), value);
if (uniform->type() == Uniform::Type::Sampler) {
QString updatedValue = value.toString();
int idx = value.toString().indexOf("file:");
QString path = idx > 0 ? updatedValue.right(updatedValue.size() - idx - 5) : updatedValue;
updatedValue = QUrl::fromLocalFile(path).toString();
uniform->setValue(updatedValue);
g_propertyData.insert(uniform->name(), updatedValue);
} else {
uniform->setValue(value);
g_propertyData.insert(uniform->name(), value);
}
emit dataChanged(index, index, {role});
return true;

View File

@@ -14,6 +14,8 @@
#include "qqmlcontext.h"
#include "theme.h"
#include "qmldesigner/components/propertyeditor/assetimageprovider.h"
#include <coreplugin/icore.h>
#include <studioquickwidget.h>
@@ -136,6 +138,11 @@ void EffectMakerWidget::initView()
m_backendModelNode.setup(m_effectMakerView->rootModelNode());
m_quickWidget->rootContext()->setContextProperty("anchorBackend", &m_backendAnchorBinding);
m_quickWidget->rootContext()->setContextProperty("modelNodeBackend", &m_backendModelNode);
m_quickWidget->rootContext()->setContextProperty("activeDragSuffix", "");
m_quickWidget->engine()->addImageProvider("qmldesigner_thumbnails",
new QmlDesigner::AssetImageProvider(
QmlDesigner::QmlDesignerPlugin::imageCache()));
// init the first load of the QML UI elements
reloadQmlSource();

View File

@@ -12,8 +12,8 @@
namespace EffectMaker {
Uniform::Uniform(const QJsonObject &propObj, const QString &qenPath) :
m_qenPath(qenPath)
Uniform::Uniform(const QJsonObject &propObj, const QString &qenPath)
: m_qenPath(qenPath)
{
QString value, defaultValue, minValue, maxValue;
@@ -35,9 +35,10 @@ Uniform::Uniform(const QJsonObject &propObj, const QString &qenPath) :
QString mipmapProperty = mipmapPropertyName(m_name);
g_propertyData[mipmapProperty] = m_enableMipmap;
}
if (propObj.contains("value")) {
value = propObj.value("value").toString();
if (m_type == Type::Sampler && !value.isEmpty())
if (m_type == Type::Sampler)
value = getResourcePath(value);
} else {
// QEN files don't store the current value, so with those use default value

View File

@@ -14,8 +14,6 @@ QT_FORWARD_DECLARE_CLASS(QVector2D)
namespace EffectMaker {
class Uniform : public QObject
{
Q_OBJECT

View File

@@ -4,12 +4,13 @@
#pragma once
#include "imagecache/midsizeimagecacheprovider.h"
#include "qmldesigner_global.h"
#include <QQuickAsyncImageProvider>
namespace QmlDesigner {
class AssetImageProvider : public QQuickAsyncImageProvider
class QMLDESIGNER_EXPORT AssetImageProvider : public QQuickAsyncImageProvider
{
public:
AssetImageProvider(AsynchronousImageCache &imageCache, const QImage &defaultImage = {})