forked from qt-creator/qt-creator
QmlDesigner: Add effect maker uniforms model
Also some initial relevant UI part. Change-Id: I79a4a060d0e2af0aeff86e27ebe3c70faf5681c2 Task-number: QDS-10404 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
This commit is contained in:
@@ -12,26 +12,19 @@ import EffectMakerBackend
|
|||||||
HelperWidgets.Section {
|
HelperWidgets.Section {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
caption: model.nodeName
|
caption: nodeName
|
||||||
category: "EffectMaker"
|
category: "EffectMaker"
|
||||||
|
|
||||||
// TODO: implement effect properties
|
|
||||||
// property var propList: model.props
|
|
||||||
|
|
||||||
Column {
|
Column {
|
||||||
anchors.fill: parent
|
spacing: 10
|
||||||
spacing: 2
|
|
||||||
|
|
||||||
// Repeater {
|
Repeater {
|
||||||
// id: effects
|
model: nodeUniformsModel
|
||||||
// model: effectList
|
|
||||||
// width: parent.width
|
EffectCompositionNodeUniform {
|
||||||
// height: parent.height
|
width: root.width
|
||||||
// delegate: Text {
|
}
|
||||||
// width: parent.width
|
}
|
||||||
// //height: StudioTheme.Values.checkIndicatorHeight * 2 // TODO: update or remove
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,81 @@
|
|||||||
|
// Copyright (C) 2023 The Qt Company Ltd.
|
||||||
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
|
import QtQuick
|
||||||
|
import QtQuick.Layouts
|
||||||
|
import QtQuickDesignerTheme
|
||||||
|
import HelperWidgets as HelperWidgets
|
||||||
|
import StudioControls as StudioControls
|
||||||
|
import StudioTheme 1.0 as StudioTheme
|
||||||
|
import EffectMakerBackend
|
||||||
|
|
||||||
|
Item {
|
||||||
|
id: root
|
||||||
|
|
||||||
|
height: 22
|
||||||
|
|
||||||
|
RowLayout {
|
||||||
|
spacing: 10
|
||||||
|
anchors.fill: parent
|
||||||
|
|
||||||
|
Text {
|
||||||
|
text: uniformName
|
||||||
|
color: StudioTheme.Values.themeTextColor
|
||||||
|
font.pointSize: StudioTheme.Values.smallFontSize
|
||||||
|
horizontalAlignment: Text.AlignRight
|
||||||
|
Layout.preferredWidth: 80
|
||||||
|
}
|
||||||
|
|
||||||
|
Loader {
|
||||||
|
sourceComponent: floatValue // TODO: set component based on prop type
|
||||||
|
Layout.fillWidth: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Component {
|
||||||
|
id: floatValue
|
||||||
|
|
||||||
|
Row {
|
||||||
|
width: parent.width
|
||||||
|
spacing: 5
|
||||||
|
|
||||||
|
StudioControls.RealSpinBox {
|
||||||
|
id: spinBox
|
||||||
|
|
||||||
|
width: 40
|
||||||
|
actionIndicatorVisible: false
|
||||||
|
spinBoxIndicatorVisible: false
|
||||||
|
inputHAlignment: Qt.AlignHCenter
|
||||||
|
from: 21
|
||||||
|
to: 78
|
||||||
|
stepSize: 1
|
||||||
|
onValueChanged: slider.value = realValue
|
||||||
|
}
|
||||||
|
|
||||||
|
StudioControls.Slider {
|
||||||
|
id: slider
|
||||||
|
|
||||||
|
width: parent.width - 60
|
||||||
|
labels: false
|
||||||
|
actionIndicatorVisible: false
|
||||||
|
from: 21
|
||||||
|
to: 78
|
||||||
|
stepSize: 1
|
||||||
|
onValueChanged: spinBox.realValue = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Component { // TODO
|
||||||
|
id: colorValue
|
||||||
|
|
||||||
|
Row {
|
||||||
|
width: parent.width
|
||||||
|
spacing: 5
|
||||||
|
|
||||||
|
HelperWidgets.ColorEditor {
|
||||||
|
backendValue: "#ffff00"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -713,6 +713,7 @@ extend_qtc_plugin(QmlDesigner
|
|||||||
effectmakerview.cpp effectmakerview.h
|
effectmakerview.cpp effectmakerview.h
|
||||||
effectmakermodel.cpp effectmakermodel.h
|
effectmakermodel.cpp effectmakermodel.h
|
||||||
effectmakernodesmodel.cpp effectmakernodesmodel.h
|
effectmakernodesmodel.cpp effectmakernodesmodel.h
|
||||||
|
effectmakeruniformsmodel.cpp effectmakeruniformsmodel.h
|
||||||
effectnode.cpp effectnode.h
|
effectnode.cpp effectnode.h
|
||||||
effectnodescategory.cpp effectnodescategory.h
|
effectnodescategory.cpp effectnodescategory.h
|
||||||
compositionnode.cpp compositionnode.h
|
compositionnode.cpp compositionnode.h
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "compositionnode.h"
|
#include "compositionnode.h"
|
||||||
|
|
||||||
#include "effectutils.h"
|
#include "effectutils.h"
|
||||||
|
#include "effectmakeruniformsmodel.h"
|
||||||
#include "uniform.h"
|
#include "uniform.h"
|
||||||
|
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
@@ -33,6 +34,11 @@ QString CompositionNode::description() const
|
|||||||
return m_description;
|
return m_description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QObject *CompositionNode::uniformsModel()
|
||||||
|
{
|
||||||
|
return &m_unifomrsModel;
|
||||||
|
}
|
||||||
|
|
||||||
void CompositionNode::parse(const QString &qenPath)
|
void CompositionNode::parse(const QString &qenPath)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -72,17 +78,8 @@ void CompositionNode::parse(const QString &qenPath)
|
|||||||
|
|
||||||
// parse properties
|
// parse properties
|
||||||
QJsonArray properties = json.value("properties").toArray();
|
QJsonArray properties = json.value("properties").toArray();
|
||||||
for (const auto /*QJsonValueRef*/ &prop : properties) {
|
for (const auto /*QJsonValueRef*/ &prop : properties)
|
||||||
QJsonObject propObj = prop.toObject();
|
m_unifomrsModel.addUniform(new Uniform(prop.toObject()));
|
||||||
Uniform *u = new Uniform(propObj);
|
|
||||||
Q_UNUSED(u)
|
|
||||||
|
|
||||||
// TODO
|
|
||||||
propObj.value("name");
|
|
||||||
propObj.value("type");
|
|
||||||
propObj.value("defaultValue");
|
|
||||||
propObj.value("description");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace QmlDesigner
|
} // namespace QmlDesigner
|
||||||
|
|||||||
@@ -3,15 +3,20 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "effectmakeruniformsmodel.h"
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
|
class Uniform;
|
||||||
|
|
||||||
class CompositionNode : public QObject
|
class CompositionNode : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
Q_PROPERTY(QString nodeName MEMBER m_name CONSTANT)
|
Q_PROPERTY(QString nodeName MEMBER m_name CONSTANT)
|
||||||
|
Q_PROPERTY(QObject *nodeUniformsModel READ uniformsModel NOTIFY uniformsModelChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CompositionNode(const QString &qenPath);
|
CompositionNode(const QString &qenPath);
|
||||||
@@ -20,6 +25,11 @@ public:
|
|||||||
QString vertexCode() const;
|
QString vertexCode() const;
|
||||||
QString description() const;
|
QString description() const;
|
||||||
|
|
||||||
|
QObject *uniformsModel();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void uniformsModelChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void parse(const QString &qenPath);
|
void parse(const QString &qenPath);
|
||||||
|
|
||||||
@@ -27,6 +37,8 @@ private:
|
|||||||
QString m_fragmentCode;
|
QString m_fragmentCode;
|
||||||
QString m_vertexCode;
|
QString m_vertexCode;
|
||||||
QString m_description;
|
QString m_description;
|
||||||
|
|
||||||
|
EffectMakerUniformsModel m_unifomrsModel;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace QmlDesigner
|
} // namespace QmlDesigner
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ QHash<int, QByteArray> EffectMakerModel::roleNames() const
|
|||||||
{
|
{
|
||||||
QHash<int, QByteArray> roles;
|
QHash<int, QByteArray> roles;
|
||||||
roles[NameRole] = "nodeName";
|
roles[NameRole] = "nodeName";
|
||||||
|
roles[UniformsRole] = "nodeUniformsModel";
|
||||||
return roles;
|
return roles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ signals:
|
|||||||
private:
|
private:
|
||||||
enum Roles {
|
enum Roles {
|
||||||
NameRole = Qt::UserRole + 1,
|
NameRole = Qt::UserRole + 1,
|
||||||
// TODO
|
UniformsRole
|
||||||
};
|
};
|
||||||
|
|
||||||
bool isValidIndex(int idx) const;
|
bool isValidIndex(int idx) const;
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
// Copyright (C) 2023 The Qt Company Ltd.
|
||||||
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
|
#include "effectmakeruniformsmodel.h"
|
||||||
|
|
||||||
|
#include "uniform.h"
|
||||||
|
|
||||||
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
|
namespace QmlDesigner {
|
||||||
|
|
||||||
|
EffectMakerUniformsModel::EffectMakerUniformsModel(QObject *parent)
|
||||||
|
: QAbstractListModel{parent}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QHash<int, QByteArray> EffectMakerUniformsModel::roleNames() const
|
||||||
|
{
|
||||||
|
QHash<int, QByteArray> roles;
|
||||||
|
roles[NameRole] = "uniformName";
|
||||||
|
roles[DescriptionRole] = "uniformDescription";
|
||||||
|
roles[ValueRole] = "uniformValue";
|
||||||
|
roles[DefaultValueRole] = "uniformDefaultValue";
|
||||||
|
roles[MinValueRole] = "uniformMinValue";
|
||||||
|
roles[MaxValueRole] = "uniformMaxValue";
|
||||||
|
roles[TypeRole] = "uniformType";
|
||||||
|
return roles;
|
||||||
|
}
|
||||||
|
|
||||||
|
int EffectMakerUniformsModel::rowCount(const QModelIndex &parent) const
|
||||||
|
{
|
||||||
|
Q_UNUSED(parent)
|
||||||
|
|
||||||
|
return m_uniforms.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant EffectMakerUniformsModel::data(const QModelIndex &index, int role) const
|
||||||
|
{
|
||||||
|
QTC_ASSERT(index.isValid() && index.row() < m_uniforms.size(), return {});
|
||||||
|
QTC_ASSERT(roleNames().contains(role), return {});
|
||||||
|
|
||||||
|
return m_uniforms.at(index.row())->property(roleNames().value(role));
|
||||||
|
}
|
||||||
|
|
||||||
|
void EffectMakerUniformsModel::resetModel()
|
||||||
|
{
|
||||||
|
beginResetModel();
|
||||||
|
endResetModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
void EffectMakerUniformsModel::addUniform(Uniform *uniform)
|
||||||
|
{
|
||||||
|
beginInsertRows({}, m_uniforms.size(), m_uniforms.size());
|
||||||
|
m_uniforms.append(uniform);
|
||||||
|
endInsertRows();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace QmlDesigner
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
// Copyright (C) 2023 The Qt Company Ltd.
|
||||||
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QStandardItemModel>
|
||||||
|
|
||||||
|
namespace QmlDesigner {
|
||||||
|
|
||||||
|
class Uniform;
|
||||||
|
|
||||||
|
class EffectMakerUniformsModel : public QAbstractListModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
EffectMakerUniformsModel(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
|
int rowCount(const QModelIndex & parent = QModelIndex()) const override;
|
||||||
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
|
|
||||||
|
void resetModel();
|
||||||
|
|
||||||
|
void addUniform(Uniform *uniform);
|
||||||
|
|
||||||
|
private:
|
||||||
|
enum Roles {
|
||||||
|
NameRole = Qt::UserRole + 1,
|
||||||
|
DescriptionRole,
|
||||||
|
ValueRole,
|
||||||
|
DefaultValueRole,
|
||||||
|
MaxValueRole,
|
||||||
|
MinValueRole,
|
||||||
|
TypeRole,
|
||||||
|
};
|
||||||
|
|
||||||
|
QList<Uniform *> m_uniforms;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace QmlDesigner
|
||||||
@@ -14,6 +14,10 @@ class Uniform : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
Q_PROPERTY(QString uniformName MEMBER m_name CONSTANT)
|
||||||
|
Q_PROPERTY(Type uniformType MEMBER m_type CONSTANT)
|
||||||
|
Q_PROPERTY(QVariant uniformValue MEMBER m_value CONSTANT)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum class Type
|
enum class Type
|
||||||
{
|
{
|
||||||
@@ -71,11 +75,10 @@ private:
|
|||||||
bool m_enabled = true;
|
bool m_enabled = true;
|
||||||
bool m_enableMipmap = false;
|
bool m_enableMipmap = false;
|
||||||
|
|
||||||
bool operator==(const Uniform& rhs) const noexcept
|
bool operator==(const Uniform &rhs) const noexcept
|
||||||
{
|
{
|
||||||
return this->m_name == rhs.m_name;
|
return this->m_name == rhs.m_name;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace QmlDesigner
|
} // namespace QmlDesigner
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user