anchor node graphics item by their center
Makes auto-positioning them somewhat easier.
This commit is contained in:
@@ -63,10 +63,10 @@ qreal CalculateEdgeYPoint(NodeViewItem *item, int param_index, NodeViewItem *opp
|
||||
qreal max_height = qMax(opposing->rect().height(), item->rect().height());
|
||||
|
||||
// Calculate the Y distance between the two nodes and create a 0.0-1.0 range for lerping
|
||||
qreal input_value = clamp(0.5 + (opposing->pos().y() - item->pos().y()) / max_height / 4, 0.0, 1.0);
|
||||
qreal input_value = clamp(0.5 + ((opposing->pos().y() + opposing->rect().top()) - (item->pos().y() + item->rect().top())) / max_height / 4, 0.0, 1.0);
|
||||
|
||||
// Use a lerp function to draw the line between the two corners
|
||||
qreal input_y = item->pos().y() + lerp(0.0, item->rect().height(), input_value);
|
||||
qreal input_y = item->pos().y() + item->rect().top() + lerp(0.0, item->rect().height(), input_value);
|
||||
|
||||
// Set Y values according to calculations
|
||||
return input_y;
|
||||
@@ -84,8 +84,8 @@ void NodeViewEdge::Adjust()
|
||||
NodeViewItem* input = NodeView::NodeToUIObject(scene(), edge_->input()->parentNode());
|
||||
|
||||
// Create initial values
|
||||
QPointF output_point = QPointF(output->pos().x() + output->rect().width(), 0);
|
||||
QPointF input_point = QPointF(input->pos().x(), 0);
|
||||
QPointF output_point = QPointF(output->pos().x() + output->rect().left() + output->rect().width(), 0);
|
||||
QPointF input_point = QPointF(input->pos().x() + output->rect().left(), 0);
|
||||
|
||||
// Calculate output/input points
|
||||
output_point.setY(CalculateEdgeYPoint(output, edge_->output()->index(), input));
|
||||
|
||||
@@ -69,7 +69,9 @@ NodeViewItem::NodeViewItem(QGraphicsItem *parent) :
|
||||
|
||||
// Use the current default font height to size this widget
|
||||
// Set default "collapsed" size
|
||||
title_bar_rect_ = QRectF(0, 0, widget_width, font_metrics.height() + node_text_padding_ * 2);
|
||||
int widget_height = font_metrics.height() + node_text_padding_ * 2;
|
||||
|
||||
title_bar_rect_ = QRectF(-widget_width/2, -widget_height/2, widget_width, widget_height);
|
||||
setRect(title_bar_rect_);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user