2023-08-17 18:38:40 +03:00
|
|
|
// 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 <QObject>
|
|
|
|
|
#include <QVariant>
|
|
|
|
|
|
2023-09-15 15:36:15 +03:00
|
|
|
#include <qmldesigner/components/propertyeditor/propertyeditorvalue.h>
|
|
|
|
|
|
2023-08-21 15:26:32 +03:00
|
|
|
QT_FORWARD_DECLARE_CLASS(QColor)
|
2023-08-18 15:39:40 +03:00
|
|
|
QT_FORWARD_DECLARE_CLASS(QJsonObject)
|
2023-08-21 15:26:32 +03:00
|
|
|
QT_FORWARD_DECLARE_CLASS(QVector2D)
|
2023-08-18 15:39:40 +03:00
|
|
|
|
2023-09-15 15:36:15 +03:00
|
|
|
namespace EffectMaker {
|
|
|
|
|
|
2023-08-17 18:38:40 +03:00
|
|
|
|
2023-08-24 15:21:52 +03:00
|
|
|
|
2023-08-17 18:38:40 +03:00
|
|
|
class Uniform : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
2023-09-05 18:03:05 +03:00
|
|
|
Q_PROPERTY(QString uniformName MEMBER m_displayName CONSTANT)
|
2023-08-28 13:30:36 +03:00
|
|
|
Q_PROPERTY(QString uniformType READ typeName CONSTANT)
|
2023-09-08 13:21:27 +03:00
|
|
|
Q_PROPERTY(QString uniformDescription READ description CONSTANT)
|
2023-08-21 22:18:16 +03:00
|
|
|
Q_PROPERTY(QVariant uniformValue READ value WRITE setValue NOTIFY uniformValueChanged)
|
2023-08-24 15:21:52 +03:00
|
|
|
Q_PROPERTY(QVariant uniformBackendValue READ backendValue NOTIFY uniformBackendValueChanged)
|
2023-08-21 14:38:50 +03:00
|
|
|
Q_PROPERTY(QVariant uniformMinValue MEMBER m_minValue CONSTANT)
|
|
|
|
|
Q_PROPERTY(QVariant uniformMaxValue MEMBER m_maxValue CONSTANT)
|
2023-08-21 11:52:11 +03:00
|
|
|
|
2023-08-17 18:38:40 +03:00
|
|
|
public:
|
|
|
|
|
enum class Type
|
|
|
|
|
{
|
|
|
|
|
Bool,
|
|
|
|
|
Int,
|
|
|
|
|
Float,
|
|
|
|
|
Vec2,
|
|
|
|
|
Vec3,
|
|
|
|
|
Vec4,
|
|
|
|
|
Color,
|
|
|
|
|
Sampler,
|
|
|
|
|
Define
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Uniform(const QJsonObject &props);
|
|
|
|
|
|
2023-08-28 13:30:36 +03:00
|
|
|
Type type() const;
|
|
|
|
|
QString typeName() const;
|
2023-08-18 11:47:16 +03:00
|
|
|
|
|
|
|
|
QVariant value() const;
|
|
|
|
|
void setValue(const QVariant &newValue);
|
|
|
|
|
|
2023-08-24 15:21:52 +03:00
|
|
|
QVariant backendValue() const;
|
|
|
|
|
|
2023-08-18 11:47:16 +03:00
|
|
|
QVariant defaultValue() const;
|
|
|
|
|
|
|
|
|
|
QVariant minValue() const;
|
|
|
|
|
QVariant maxValue() const;
|
|
|
|
|
|
|
|
|
|
QString name() const;
|
|
|
|
|
QString description() const;
|
|
|
|
|
|
|
|
|
|
QString customValue() const;
|
|
|
|
|
void setCustomValue(const QString &newCustomValue);
|
|
|
|
|
bool useCustomValue() const;
|
|
|
|
|
|
|
|
|
|
bool enabled() const;
|
|
|
|
|
void setEnabled(bool newEnabled);
|
|
|
|
|
|
|
|
|
|
bool enableMipmap() const;
|
2023-08-17 18:38:40 +03:00
|
|
|
|
2023-08-28 13:30:36 +03:00
|
|
|
static QString stringFromType(Uniform::Type type);
|
|
|
|
|
static Uniform::Type typeFromString(const QString &typeString);
|
2023-09-08 11:27:00 +03:00
|
|
|
static QString typeToProperty(Uniform::Type type);
|
2023-08-28 13:30:36 +03:00
|
|
|
|
2023-08-21 22:18:16 +03:00
|
|
|
signals:
|
|
|
|
|
void uniformValueChanged();
|
2023-08-24 15:21:52 +03:00
|
|
|
void uniformBackendValueChanged();
|
2023-08-21 22:18:16 +03:00
|
|
|
|
2023-08-17 18:38:40 +03:00
|
|
|
private:
|
2023-08-18 15:39:40 +03:00
|
|
|
QString mipmapPropertyName(const QString &name) const;
|
|
|
|
|
bool getBoolValue(const QJsonValue &jsonValue, bool defaultValue);
|
|
|
|
|
QString getResourcePath(const QString &value) const;
|
2023-08-21 15:26:32 +03:00
|
|
|
void setValueData(const QString &value, const QString &defaultValue,
|
|
|
|
|
const QString &minValue, const QString &maxValue);
|
2023-08-28 13:30:36 +03:00
|
|
|
|
|
|
|
|
QVariant getInitializedVariant(bool maxValue);
|
|
|
|
|
QVariant valueStringToVariant(const QString &value);
|
2023-08-18 15:39:40 +03:00
|
|
|
|
2023-08-17 18:38:40 +03:00
|
|
|
Type m_type;
|
|
|
|
|
QVariant m_value;
|
|
|
|
|
QVariant m_defaultValue;
|
|
|
|
|
QVariant m_minValue;
|
|
|
|
|
QVariant m_maxValue;
|
|
|
|
|
QString m_name;
|
2023-09-05 18:03:05 +03:00
|
|
|
QString m_displayName;
|
2023-08-17 18:38:40 +03:00
|
|
|
QString m_description;
|
|
|
|
|
QString m_customValue;
|
|
|
|
|
bool m_useCustomValue = false;
|
2023-08-18 11:47:16 +03:00
|
|
|
bool m_enabled = true;
|
2023-08-17 18:38:40 +03:00
|
|
|
bool m_enableMipmap = false;
|
2023-09-15 15:36:15 +03:00
|
|
|
QmlDesigner::PropertyEditorValue *m_backendValue = nullptr;
|
2023-08-17 18:38:40 +03:00
|
|
|
|
2023-08-21 11:52:11 +03:00
|
|
|
bool operator==(const Uniform &rhs) const noexcept
|
2023-08-17 18:38:40 +03:00
|
|
|
{
|
|
|
|
|
return this->m_name == rhs.m_name;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2023-09-15 15:36:15 +03:00
|
|
|
} // namespace EffectMaker
|