enhancements to node edge creation
This commit is contained in:
+61
-4
@@ -112,9 +112,47 @@ void NodeUI::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
}
|
||||
|
||||
if (clicked_socket_ > -1) {
|
||||
drag_line_start_ = pos() + sockets.at(clicked_socket_).center();
|
||||
|
||||
// See if this socket already has an edge connected
|
||||
QVector<NodeEdgePtr> edges = central_widget_->GetEffect()->row(clicked_socket_)->edges();
|
||||
if (!edges.isEmpty()) {
|
||||
|
||||
NodeEdge* e = edges.last().get();
|
||||
|
||||
EffectRow* other_row = (e->input()->GetParentEffect() == central_widget_->GetEffect()) ?
|
||||
e->output() : e->input();
|
||||
|
||||
Node* other_node = other_row->GetParentEffect();
|
||||
|
||||
int other_row_index = other_node->IndexOfRow(other_row);
|
||||
|
||||
NodeUI* other_node_ui = FindUIFromNode(other_node);
|
||||
|
||||
// Start an edge at the opposite end
|
||||
drag_line_start_ = other_node_ui->pos() + other_node_ui->GetNodeSocketRects().at(other_row_index).center();
|
||||
|
||||
drag_source_ = other_row;
|
||||
|
||||
// Disconnect the existing edge, and treat our dynamic one as an edit of that one
|
||||
EffectRow::DisconnectEdge(edges.last());
|
||||
|
||||
} else {
|
||||
|
||||
// Start a new edge here
|
||||
drag_line_start_ = pos() + sockets.at(clicked_socket_).center();
|
||||
|
||||
drag_source_ = central_widget_->GetEffect()->row(clicked_socket_);
|
||||
|
||||
}
|
||||
|
||||
drag_line_ = scene()->addPath(NodeEdgeUI::GetEdgePath(drag_line_start_, event->scenePos()));
|
||||
|
||||
if (!edges.isEmpty()) {
|
||||
drag_line_->setPen(QPen(Qt::white, 2));
|
||||
} else {
|
||||
drag_line_->setPen(QPen(Qt::gray, 2));
|
||||
}
|
||||
|
||||
event->accept();
|
||||
} else {
|
||||
QGraphicsItem::mousePressEvent(event);
|
||||
@@ -135,8 +173,8 @@ void NodeUI::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||
|
||||
// See if the graphics item here is a node
|
||||
NodeUI* mouse_node = dynamic_cast<NodeUI*>(mouse_items.at(j));
|
||||
|
||||
if (mouse_node != nullptr) {
|
||||
|
||||
// If so, get this node's sockets and loop through them
|
||||
QVector<QRectF> mouse_nodes_sockets = mouse_node->GetNodeSocketRects();
|
||||
for (int i=0;i<mouse_nodes_sockets.size();i++) {
|
||||
@@ -146,7 +184,7 @@ void NodeUI::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||
|
||||
// If so, see if the two rows can be connected
|
||||
|
||||
EffectRow* local_row = central_widget_->GetEffect()->row(clicked_socket_);
|
||||
EffectRow* local_row = drag_source_;
|
||||
EffectRow* remote_row = mouse_node->GetRowFromIndex(i);
|
||||
|
||||
// Ensure one is an input and one is an output and whether their data types are compatible
|
||||
@@ -199,7 +237,7 @@ void NodeUI::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
event->accept();
|
||||
|
||||
if (drag_destination_ != nullptr) {
|
||||
EffectRow::ConnectEdge(central_widget_->GetEffect()->row(clicked_socket_), drag_destination_);
|
||||
EffectRow::ConnectEdge(drag_source_, drag_destination_);
|
||||
}
|
||||
} else {
|
||||
QGraphicsItem::mouseReleaseEvent(event);
|
||||
@@ -241,3 +279,22 @@ EffectRow *NodeUI::GetRowFromIndex(int i)
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NodeUI *NodeUI::FindUIFromNode(Node* n)
|
||||
{
|
||||
QList<QGraphicsItem*> all_items = scene()->items();
|
||||
|
||||
for (int j=0;j<all_items.size();j++) {
|
||||
NodeUI* node = dynamic_cast<NodeUI*>(all_items.at(j));
|
||||
if (node != nullptr) {
|
||||
|
||||
// Check if this node has the specified
|
||||
|
||||
if (node->Widget()->GetEffect() == n) {
|
||||
return node;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user