NodeView::NodeView( const QPointF& position, kiwi::core::Node * n) : kiwi::view::NodeView( n ) { assert( n ); n->setView( this ); setFlags(QGraphicsItem::ItemIsMovable); setPos( position ); float nodeHeight = (nodeType()->inputs().size() + nodeType()->outputs().size()) * portsSpacing() + headerHeight(); _rect = QRectF( 0, 0, 150.0, nodeHeight ); int i = 0; for( auto it = nodeType()->inputs().begin(); it != nodeType()->inputs().end(); ++it ) { _inputs.push_back( new PortView(PortView::INPUT, this, i) ); _inputs[i]->setPos( QPointF( leftX(), inputsY() + i * portsSpacing() ) ); ++i; } i = 0; for( auto it = nodeType()->outputs().begin(); it != nodeType()->outputs().end(); ++it ) { _outputs.push_back( new PortView(PortView::OUTPUT, this, i) ); _outputs[i]->setPos( QPointF( rightX(), outputsY() + i * portsSpacing() ) ); ++i; } _dropShadow.setBlurRadius( 16 ); _dropShadow.setXOffset( 0.0 ); _dropShadow.setYOffset( 5.0 ); setGraphicsEffect( &_dropShadow ); }
double polint3(double x, int n, double *xa, double *ya) { int shift=leftX(n, xa, x); double ar; ar=polintN(x,3,xa+shift, ya+shift); if(shift==0) return ar; shift--; return 0.5*( ar+ polintN(x,3,xa+shift, ya+shift)); }
void NodeView::mouseMoveEvent( QGraphicsSceneMouseEvent* event ) { QGraphicsItem::mouseMoveEvent( event ); for(int i = 0; i < _inputs.size(); ++i) { if(_inputs[i]->state() != PortView::DRAG ) _inputs[i]->setPos( QPointF( leftX(), inputsY() + i * portsSpacing() ) ); } for(int i = 0; i < _outputs.size(); ++i) { // update port positions if(_outputs[i]->state() != PortView::DRAG ) _outputs[i]->setPos( QPointF( rightX(), outputsY() + i * portsSpacing() ) ); // update link positions for(int j = 0; j < _outputs[i]->connections().size(); ++j ) { _outputs[i]->connections()[j]->updatePos(); } } }