nodes can now be connected through the node editor

This commit is contained in:
itsmattkc
2019-04-13 02:40:58 +10:00
parent 6b67727bd8
commit 8cd96eae64
24 changed files with 480 additions and 85 deletions
+56 -1
View File
@@ -65,13 +65,54 @@ void EffectRow::AddField(EffectField *field)
fields_.append(field);
}
void EffectRow::AddNodeInput(olive::nodes::DataType type)
void EffectRow::AddAcceptedNodeInput(olive::nodes::DataType type)
{
Q_ASSERT(output_type_ == olive::nodes::kInvalid);
accepted_inputs_.append(type);
}
void EffectRow::ConnectEdge(EffectRow *output, EffectRow *input)
{
Q_ASSERT(output->IsNodeOutput());
Q_ASSERT(input->IsNodeInput());
if (!input->node_edges_.isEmpty()) {
DisconnectEdge(input->node_edges_.first());
}
NodeEdgePtr edge = std::make_shared<NodeEdge>(output, input);
output->node_edges_.append(edge);
input->node_edges_.append(edge);
emit output->EdgesChanged();
emit input->EdgesChanged();
}
void EffectRow::DisconnectEdge(NodeEdgePtr edge)
{
EffectRow* output = edge->output();
EffectRow* input = edge->input();
output->node_edges_.removeAll(edge);
input->node_edges_.removeAll(edge);
emit output->EdgesChanged();
emit input->EdgesChanged();
}
QVector<NodeEdge*> EffectRow::edges()
{
QVector<NodeEdge*> edges;
for (int i=0;i<node_edges_.size();i++) {
edges.append(node_edges_.at(i).get());
}
return edges;
}
bool EffectRow::IsKeyframing() {
return keyframing_;
}
@@ -121,6 +162,20 @@ void EffectRow::SetOutputDataType(olive::nodes::DataType type)
output_type_ = type;
}
bool EffectRow::CanAcceptDataType(olive::nodes::DataType type)
{
if (!IsNodeInput()) {
return false;
}
return accepted_inputs_.contains(type);
}
olive::nodes::DataType EffectRow::OutputDataType()
{
return output_type_;
}
bool EffectRow::IsNodeInput()
{
return !accepted_inputs_.isEmpty();
+71 -12
View File
@@ -35,6 +35,7 @@ class KeyframeNavigator;
class ClickableLabel;
#include "effectfields.h"
#include "nodes/nodeedge.h"
/**
* @brief The EffectRow class
@@ -245,6 +246,64 @@ public:
*/
void SetOutputDataType(olive::nodes::DataType type);
/**
* @brief Check if this row can accept the data type specified in type
*
* @return
*
* TRUE if this row can accept this data type. If this row is not an input, this function will always return FALSE.
*/
bool CanAcceptDataType(olive::nodes::DataType type);
/**
* @brief Get this row's output data type
*
* @return
*
* If this is not an output, this will always return olive::nodes::kInvalid
*/
olive::nodes::DataType OutputDataType();
/**
* @brief Adds a node data type that can be accepted by this input
*
* Allows this input to take a node connection from a data type specified by type. An input can take several data
* types.
*
* @param type
*
* The data type to add
*/
void AddAcceptedNodeInput(olive::nodes::DataType type);
/**
* @brief Connect two node sockets together
*
* For outputs, the maximum amount of edges is unlimited and this will continually add to a list of edges. For inputs,
* there can only be one edge and adding a second will destroy the first.
*
* @param edge
*
* The edge to add (output) or replace the current edge (input).
*/
static void ConnectEdge(EffectRow* output, EffectRow* input);
/**
* @brief Disconnect an edge
*
* Disconnects two nodes and destroys the edge object connecting them together
*
* @param edge
*
* Edge to be removed
*/
static void DisconnectEdge(NodeEdgePtr edge);
/**
* @brief Get a list of references to all edges currently connected to this row
*/
QVector<NodeEdge *> edges();
protected:
/**
* @brief Add a field to this row
@@ -258,18 +317,6 @@ protected:
*/
void AddField(EffectField* Field);
/**
* @brief Adds a node data type that can be accepted by this input
*
* Allows this input to take a node connection from a data type specified by type. An input can take several data
* types.
*
* @param type
*
* The data type to add
*/
void AddNodeInput(olive::nodes::DataType type);
public slots:
/**
* @brief Go to previous keyframe
@@ -332,6 +379,13 @@ signals:
*/
void Clicked();
/**
* @brief Edges changed signal
*
* Signal emitted any time an edge is connected or disconnected from this row
*/
void EdgesChanged();
private slots:
/**
* @brief Set keyframing enabled state
@@ -402,6 +456,11 @@ private:
* this.
*/
olive::nodes::DataType output_type_;
/**
* @brief Internal array of node edges. Access with AddEdge() and RemoveEdge().
*/
QVector<NodeEdgePtr> node_edges_;
};
#endif // EFFECTROW_H