ShaderNode/NodeEditor: Replace QVBoxLayout by QFormLayout
This commit is contained in:
parent
3fc4de26e3
commit
0ec927b82e
|
|
@ -18,7 +18,7 @@ class CastVec : public ShaderNode
|
||||||
CastVec(ShaderGraph& graph);
|
CastVec(ShaderGraph& graph);
|
||||||
~CastVec() = default;
|
~CastVec() = default;
|
||||||
|
|
||||||
void BuildNodeEdition(QVBoxLayout* layout) override;
|
void BuildNodeEdition(QFormLayout* layout) override;
|
||||||
|
|
||||||
Nz::ShaderAst::ExpressionPtr GetExpression(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count) const override;
|
Nz::ShaderAst::ExpressionPtr GetExpression(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count) const override;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,14 +10,12 @@ ShaderNode(graph)
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename From, typename To>
|
template<typename From, typename To>
|
||||||
void CastVec<From, To>::BuildNodeEdition(QVBoxLayout* layout)
|
void CastVec<From, To>::BuildNodeEdition(QFormLayout* layout)
|
||||||
{
|
{
|
||||||
ShaderNode::BuildNodeEdition(layout);
|
ShaderNode::BuildNodeEdition(layout);
|
||||||
|
|
||||||
if constexpr (ComponentDiff > 0)
|
if constexpr (ComponentDiff > 0)
|
||||||
{
|
{
|
||||||
QFormLayout* formLayout = new QFormLayout;
|
|
||||||
|
|
||||||
for (std::size_t i = 0; i < ComponentDiff; ++i)
|
for (std::size_t i = 0; i < ComponentDiff; ++i)
|
||||||
{
|
{
|
||||||
QDoubleSpinBox* spinbox = new QDoubleSpinBox;
|
QDoubleSpinBox* spinbox = new QDoubleSpinBox;
|
||||||
|
|
@ -30,10 +28,8 @@ void CastVec<From, To>::BuildNodeEdition(QVBoxLayout* layout)
|
||||||
UpdateOutput();
|
UpdateOutput();
|
||||||
});
|
});
|
||||||
|
|
||||||
formLayout->addRow(QString::fromUtf8(&s_vectorComponents[FromComponents + i], 1), spinbox);
|
layout->addRow(QString::fromUtf8(&s_vectorComponents[FromComponents + i], 1), spinbox);
|
||||||
}
|
}
|
||||||
|
|
||||||
layout->addLayout(formLayout);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ void InputValue::OnInputListUpdate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputValue::BuildNodeEdition(QVBoxLayout* layout)
|
void InputValue::BuildNodeEdition(QFormLayout* layout)
|
||||||
{
|
{
|
||||||
ShaderNode::BuildNodeEdition(layout);
|
ShaderNode::BuildNodeEdition(layout);
|
||||||
|
|
||||||
|
|
@ -83,7 +83,7 @@ void InputValue::BuildNodeEdition(QVBoxLayout* layout)
|
||||||
for (const auto& inputEntry : GetGraph().GetInputs())
|
for (const auto& inputEntry : GetGraph().GetInputs())
|
||||||
inputSelection->addItem(QString::fromStdString(inputEntry.name));
|
inputSelection->addItem(QString::fromStdString(inputEntry.name));
|
||||||
|
|
||||||
layout->addWidget(inputSelection);
|
layout->addRow(tr("Input"), inputSelection);
|
||||||
}
|
}
|
||||||
|
|
||||||
Nz::ShaderAst::ExpressionPtr InputValue::GetExpression(Nz::ShaderAst::ExpressionPtr* /*expressions*/, std::size_t count) const
|
Nz::ShaderAst::ExpressionPtr InputValue::GetExpression(Nz::ShaderAst::ExpressionPtr* /*expressions*/, std::size_t count) const
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ class InputValue : public ShaderNode
|
||||||
InputValue(ShaderGraph& graph);
|
InputValue(ShaderGraph& graph);
|
||||||
~InputValue() = default;
|
~InputValue() = default;
|
||||||
|
|
||||||
void BuildNodeEdition(QVBoxLayout* layout) override;
|
void BuildNodeEdition(QFormLayout* layout) override;
|
||||||
|
|
||||||
Nz::ShaderAst::ExpressionPtr GetExpression(Nz::ShaderAst::ExpressionPtr* /*expressions*/, std::size_t count) const override;
|
Nz::ShaderAst::ExpressionPtr GetExpression(Nz::ShaderAst::ExpressionPtr* /*expressions*/, std::size_t count) const override;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -112,7 +112,7 @@ bool SampleTexture::ComputePreview(QPixmap& pixmap)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SampleTexture::BuildNodeEdition(QVBoxLayout* layout)
|
void SampleTexture::BuildNodeEdition(QFormLayout* layout)
|
||||||
{
|
{
|
||||||
ShaderNode::BuildNodeEdition(layout);
|
ShaderNode::BuildNodeEdition(layout);
|
||||||
|
|
||||||
|
|
@ -130,7 +130,7 @@ void SampleTexture::BuildNodeEdition(QVBoxLayout* layout)
|
||||||
for (const auto& textureEntry : GetGraph().GetTextures())
|
for (const auto& textureEntry : GetGraph().GetTextures())
|
||||||
textureSelection->addItem(QString::fromStdString(textureEntry.name));
|
textureSelection->addItem(QString::fromStdString(textureEntry.name));
|
||||||
|
|
||||||
layout->addWidget(textureSelection);
|
layout->addRow(tr("Texture"), textureSelection);
|
||||||
}
|
}
|
||||||
|
|
||||||
Nz::ShaderAst::ExpressionPtr SampleTexture::GetExpression(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count) const
|
Nz::ShaderAst::ExpressionPtr SampleTexture::GetExpression(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count) const
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ class SampleTexture : public ShaderNode
|
||||||
SampleTexture(ShaderGraph& graph);
|
SampleTexture(ShaderGraph& graph);
|
||||||
~SampleTexture() = default;
|
~SampleTexture() = default;
|
||||||
|
|
||||||
void BuildNodeEdition(QVBoxLayout* layout) override;
|
void BuildNodeEdition(QFormLayout* layout) override;
|
||||||
|
|
||||||
Nz::ShaderAst::ExpressionPtr GetExpression(Nz::ShaderAst::ExpressionPtr* /*expressions*/, std::size_t count) const override;
|
Nz::ShaderAst::ExpressionPtr GetExpression(Nz::ShaderAst::ExpressionPtr* /*expressions*/, std::size_t count) const override;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,23 @@
|
||||||
#include <ShaderNode/DataModels/ShaderNode.hpp>
|
#include <ShaderNode/DataModels/ShaderNode.hpp>
|
||||||
#include <QtWidgets/QCheckBox>
|
#include <QtWidgets/QCheckBox>
|
||||||
|
#include <QtWidgets/QComboBox>
|
||||||
|
#include <QtWidgets/QFormLayout>
|
||||||
#include <QtWidgets/QLabel>
|
#include <QtWidgets/QLabel>
|
||||||
#include <QtWidgets/QVBoxLayout>
|
|
||||||
|
|
||||||
ShaderNode::ShaderNode(ShaderGraph& graph) :
|
ShaderNode::ShaderNode(ShaderGraph& graph) :
|
||||||
m_previewSize(64, 64),
|
m_previewSize(64, 64),
|
||||||
m_pixmapLabel(nullptr),
|
m_pixmapLabel(nullptr),
|
||||||
m_graph(graph),
|
m_graph(graph),
|
||||||
|
m_forceVariable(false),
|
||||||
m_isPreviewEnabled(false)
|
m_isPreviewEnabled(false)
|
||||||
{
|
{
|
||||||
m_pixmapLabel = new QLabel;
|
m_pixmapLabel = new QLabel;
|
||||||
m_pixmapLabel->setStyleSheet("background-color: rgba(0,0,0,0)");
|
m_pixmapLabel->setStyleSheet("background-color: rgba(0,0,0,0)");
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderNode::BuildNodeEdition(QVBoxLayout* layout)
|
void ShaderNode::BuildNodeEdition(QFormLayout* layout)
|
||||||
{
|
{
|
||||||
QCheckBox* checkbox = new QCheckBox(tr("Enable preview"));
|
QCheckBox* checkbox = new QCheckBox;
|
||||||
checkbox->setCheckState((m_isPreviewEnabled) ? Qt::Checked : Qt::Unchecked);
|
checkbox->setCheckState((m_isPreviewEnabled) ? Qt::Checked : Qt::Unchecked);
|
||||||
|
|
||||||
connect(checkbox, &QCheckBox::stateChanged, [&](int state)
|
connect(checkbox, &QCheckBox::stateChanged, [&](int state)
|
||||||
|
|
@ -23,7 +25,7 @@ void ShaderNode::BuildNodeEdition(QVBoxLayout* layout)
|
||||||
EnablePreview(state == Qt::Checked);
|
EnablePreview(state == Qt::Checked);
|
||||||
});
|
});
|
||||||
|
|
||||||
layout->addWidget(checkbox);
|
layout->addRow(tr("Enable preview"), checkbox);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderNode::EnablePreview(bool enable)
|
void ShaderNode::EnablePreview(bool enable)
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
class QLabel;
|
class QLabel;
|
||||||
class QVBoxLayout;
|
class QFormLayout;
|
||||||
class ShaderGraph;
|
class ShaderGraph;
|
||||||
|
|
||||||
class ShaderNode : public QtNodes::NodeDataModel
|
class ShaderNode : public QtNodes::NodeDataModel
|
||||||
|
|
@ -18,13 +18,14 @@ class ShaderNode : public QtNodes::NodeDataModel
|
||||||
public:
|
public:
|
||||||
ShaderNode(ShaderGraph& graph);
|
ShaderNode(ShaderGraph& graph);
|
||||||
|
|
||||||
virtual void BuildNodeEdition(QVBoxLayout* layout);
|
virtual void BuildNodeEdition(QFormLayout* layout);
|
||||||
|
|
||||||
void EnablePreview(bool enable);
|
void EnablePreview(bool enable);
|
||||||
|
|
||||||
virtual Nz::ShaderAst::ExpressionPtr GetExpression(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count) const = 0;
|
virtual Nz::ShaderAst::ExpressionPtr GetExpression(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count) const = 0;
|
||||||
inline ShaderGraph& GetGraph();
|
inline ShaderGraph& GetGraph();
|
||||||
inline const ShaderGraph& GetGraph() const;
|
inline const ShaderGraph& GetGraph() const;
|
||||||
|
inline const std::string& GetVariableName() const;
|
||||||
|
|
||||||
void SetPreviewSize(const Nz::Vector2i& size);
|
void SetPreviewSize(const Nz::Vector2i& size);
|
||||||
|
|
||||||
|
|
@ -41,7 +42,9 @@ class ShaderNode : public QtNodes::NodeDataModel
|
||||||
Nz::Vector2i m_previewSize;
|
Nz::Vector2i m_previewSize;
|
||||||
QLabel* m_pixmapLabel;
|
QLabel* m_pixmapLabel;
|
||||||
std::optional<QPixmap> m_pixmap;
|
std::optional<QPixmap> m_pixmap;
|
||||||
|
std::string m_variableName;
|
||||||
ShaderGraph& m_graph;
|
ShaderGraph& m_graph;
|
||||||
|
bool m_forceVariable;
|
||||||
bool m_isPreviewEnabled;
|
bool m_isPreviewEnabled;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
#include <ShaderNode/DataModels/ShaderNode.hpp>
|
#include <ShaderNode/DataModels/ShaderNode.hpp>
|
||||||
|
|
||||||
|
|
||||||
inline ShaderGraph& ShaderNode::GetGraph()
|
inline ShaderGraph& ShaderNode::GetGraph()
|
||||||
{
|
{
|
||||||
return m_graph;
|
return m_graph;
|
||||||
|
|
@ -11,9 +10,17 @@ inline const ShaderGraph& ShaderNode::GetGraph() const
|
||||||
return m_graph;
|
return m_graph;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline const std::string& ShaderNode::GetVariableName() const
|
||||||
|
{
|
||||||
|
return m_variableName;
|
||||||
|
}
|
||||||
|
|
||||||
inline void ShaderNode::SetPreviewSize(const Nz::Vector2i& size)
|
inline void ShaderNode::SetPreviewSize(const Nz::Vector2i& size)
|
||||||
{
|
{
|
||||||
m_previewSize = size;
|
m_previewSize = size;
|
||||||
if (m_isPreviewEnabled)
|
if (m_isPreviewEnabled)
|
||||||
|
{
|
||||||
UpdatePreview();
|
UpdatePreview();
|
||||||
|
embeddedWidgetSizeUpdated();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ class VecValue : public ShaderNode
|
||||||
|
|
||||||
std::shared_ptr<QtNodes::NodeData> outData(QtNodes::PortIndex port) override;
|
std::shared_ptr<QtNodes::NodeData> outData(QtNodes::PortIndex port) override;
|
||||||
|
|
||||||
void BuildNodeEdition(QVBoxLayout* layout) override;
|
void BuildNodeEdition(QFormLayout* layout) override;
|
||||||
|
|
||||||
Nz::ShaderAst::ExpressionPtr GetExpression(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count) const override;
|
Nz::ShaderAst::ExpressionPtr GetExpression(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count) const override;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -68,11 +68,10 @@ std::shared_ptr<QtNodes::NodeData> VecValue<Data>::outData(QtNodes::PortIndex po
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Data>
|
template<typename Data>
|
||||||
void VecValue<Data>::BuildNodeEdition(QVBoxLayout* layout)
|
void VecValue<Data>::BuildNodeEdition(QFormLayout* layout)
|
||||||
{
|
{
|
||||||
ShaderNode::BuildNodeEdition(layout);
|
ShaderNode::BuildNodeEdition(layout);
|
||||||
|
|
||||||
QFormLayout* formLayout = new QFormLayout;
|
|
||||||
for (std::size_t i = 0; i < ComponentCount; ++i)
|
for (std::size_t i = 0; i < ComponentCount; ++i)
|
||||||
{
|
{
|
||||||
QDoubleSpinBox* spinbox = new QDoubleSpinBox;
|
QDoubleSpinBox* spinbox = new QDoubleSpinBox;
|
||||||
|
|
@ -87,10 +86,8 @@ void VecValue<Data>::BuildNodeEdition(QVBoxLayout* layout)
|
||||||
UpdatePreview();
|
UpdatePreview();
|
||||||
});
|
});
|
||||||
|
|
||||||
formLayout->addRow(QString::fromUtf8(&s_vectorComponents[i], 1), spinbox);
|
layout->addRow(QString::fromUtf8(&s_vectorComponents[i], 1), spinbox);
|
||||||
}
|
}
|
||||||
|
|
||||||
layout->addLayout(formLayout);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Data>
|
template<typename Data>
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ m_shaderGraph(graph)
|
||||||
{
|
{
|
||||||
if (node)
|
if (node)
|
||||||
{
|
{
|
||||||
m_nodeEditor->UpdateContent(node->caption(), [node](QVBoxLayout* layout)
|
m_nodeEditor->UpdateContent(node->caption(), [node](QFormLayout* layout)
|
||||||
{
|
{
|
||||||
node->BuildNodeEdition(layout);
|
node->BuildNodeEdition(layout);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
#define NAZARA_SHADERNODES_NODEEDITOR_HPP
|
#define NAZARA_SHADERNODES_NODEEDITOR_HPP
|
||||||
|
|
||||||
#include <ShaderNode/ShaderGraph.hpp>
|
#include <ShaderNode/ShaderGraph.hpp>
|
||||||
#include <QtWidgets/QVBoxLayout>
|
#include <QtWidgets/QFormLayout>
|
||||||
#include <QtWidgets/QWidget>
|
#include <QtWidgets/QWidget>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
|
|
@ -19,7 +19,7 @@ class NodeEditor : public QWidget
|
||||||
template<typename F> void UpdateContent(QString nodeName, F&& callback);
|
template<typename F> void UpdateContent(QString nodeName, F&& callback);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QVBoxLayout* m_layout;
|
QFormLayout* m_layout;
|
||||||
};
|
};
|
||||||
|
|
||||||
#include <ShaderNode/Widgets/NodeEditor.inl>
|
#include <ShaderNode/Widgets/NodeEditor.inl>
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ void NodeEditor::UpdateContent(QString nodeName, F&& callback)
|
||||||
{
|
{
|
||||||
Clear();
|
Clear();
|
||||||
|
|
||||||
m_layout = new QVBoxLayout;
|
m_layout = new QFormLayout;
|
||||||
setLayout(m_layout);
|
setLayout(m_layout);
|
||||||
|
|
||||||
QLabel* label = new QLabel(nodeName);
|
QLabel* label = new QLabel(nodeName);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue