nodeview: allow dragging edges from their arrows

Fixes #1594
This commit is contained in:
itsmattkc
2021-04-27 18:48:40 +10:00
parent cd1d75c6fb
commit a7d7515ba7
4 changed files with 38 additions and 9 deletions
+23 -8
View File
@@ -363,9 +363,20 @@ void NodeView::mousePressEvent(QMouseEvent *event)
{
if (HandPress(event)) return;
if (event->button() == Qt::RightButton) {
QGraphicsItem* item = itemAt(event->pos());
QGraphicsItem* item = itemAt(event->pos());
if (event->button() == Qt::LeftButton) {
NodeViewEdge* edge_item = dynamic_cast<NodeViewEdge*>(item);
if (edge_item && edge_item->arrow_bounding_rect().contains(mapToScene(event->pos()))) {
create_edge_src_ = scene_.NodeToUIObject(edge_item->output().node());
create_edge_src_output_ = edge_item->output().output();
create_edge_ = edge_item;
create_edge_already_exists_ = true;
return;
}
}
if (event->button() == Qt::RightButton) {
if (!item || !item->isSelected()) {
// Qt doesn't do this by default for some reason
if (!(event->modifiers() & Qt::ShiftModifier)) {
@@ -380,11 +391,12 @@ void NodeView::mousePressEvent(QMouseEvent *event)
}
if (event->modifiers() & Qt::ControlModifier) {
NodeViewItem* item = dynamic_cast<NodeViewItem*>(itemAt(event->pos()));
if (item) {
NodeViewItem* node_item = dynamic_cast<NodeViewItem*>(item);
if (node_item) {
create_edge_ = new NodeViewEdge();
create_edge_src_ = item;
create_edge_src_ = node_item;
create_edge_src_output_ = Node::kDefaultOutput;
create_edge_already_exists_ = false;
create_edge_->SetCurved(scene_.GetEdgesAreCurved());
create_edge_->SetFlowDirection(scene_.GetFlowDirection());
@@ -551,7 +563,10 @@ void NodeView::mouseReleaseEvent(QMouseEvent *event)
if (HandRelease(event)) return;
if (create_edge_) {
delete create_edge_;
if (!create_edge_already_exists_) {
delete create_edge_;
}
create_edge_ = nullptr;
if (create_edge_dst_) {
@@ -566,7 +581,7 @@ void NodeView::mouseReleaseEvent(QMouseEvent *event)
if (create_edge_dst_input_.IsValid()) {
// Make connection
Core::instance()->undo_stack()->push(new NodeEdgeAddCommand(create_edge_src_->GetNode(), create_edge_dst_input_));
Core::instance()->undo_stack()->push(new NodeEdgeAddCommand(NodeOutput(create_edge_src_->GetNode(), create_edge_src_output_), create_edge_dst_input_));
create_edge_dst_input_.Reset();
}
+3
View File
@@ -142,6 +142,7 @@ private:
NodeViewEdge* create_edge_;
NodeViewItem* create_edge_src_;
QString create_edge_src_output_;
NodeViewItem* create_edge_dst_;
NodeInput create_edge_dst_input_;
bool create_edge_dst_temp_expanded_;
@@ -161,6 +162,8 @@ private:
double scale_;
bool create_edge_already_exists_;
static const double kMinimumScale;
private slots:
+5 -1
View File
@@ -33,10 +33,12 @@
namespace olive {
#define super QGraphicsPathItem
NodeViewEdge::NodeViewEdge(const NodeOutput &output, const NodeInput &input,
NodeViewItem* from_item, NodeViewItem* to_item,
QGraphicsItem* parent) :
QGraphicsPathItem(parent),
super(parent),
output_(output),
input_(input),
from_item_(from_item),
@@ -150,6 +152,8 @@ void NodeViewEdge::SetPoints(const QPointF &start, const QPointF &end, bool inpu
arrow_points[3] = end;
arrow_ = QPolygonF(arrow_points);
arrow_bounding_rect_ = arrow_.boundingRect();
arrow_bounding_rect_.adjust(-arrow_size_, -arrow_size_, arrow_size_, arrow_size_);
}
void NodeViewEdge::SetFlowDirection(NodeViewCommon::FlowDirection dir)
+7
View File
@@ -70,6 +70,11 @@ public:
return to_item_;
}
const QRectF arrow_bounding_rect() const
{
return arrow_bounding_rect_;
}
void Adjust();
/**
@@ -136,6 +141,8 @@ private:
int arrow_size_;
QRectF arrow_bounding_rect_;
};
}