26const qreal VuoRendererNode::outerBorderWidth = 1.;
28const qreal VuoRendererNode::nodeTitleHorizontalMargin = 12 ;
29const qreal VuoRendererNode::nodeClassHeight = 12 ;
31const qreal VuoRendererNode::iconRightOffset = 11.;
41 setZValue(nodeZValue);
44 this->signaler = NULL;
47 this->proxyNode = NULL;
48 this->nodeType = VuoRendererNode::node;
53 this->nodeClass = QString::fromUtf8(nodeClass->
getClassName().c_str());
57 this->nodeClass = this->nodeClass.normalized(QString::NormalizationForm_C);
66 this->setFlags(QGraphicsItem::ItemIsMovable |
67 QGraphicsItem::ItemIsSelectable |
68 QGraphicsItem::ItemIsFocusable |
69 QGraphicsItem::ItemSendsGeometryChanges);
71 this->setAcceptHoverEvents(
true);
74 vector<VuoRendererPort *> inputs;
81 setInputPorts(inputs);
85 vector<VuoRendererPort *> outputs;
89 bool isFunctionPort =
false;
92 setOutputPorts(outputs);
95 setPos(baseNode->
getX(), baseNode->
getY());
102void VuoRendererNode::setInputPorts(vector<VuoRendererPort *> inputPorts)
106 this->inputPorts.push_back(*it);
107 (*it)->setParentItem(
this);
109 if ((*it)->isHiddenRefreshPort())
115 (*it)->updateNameRect();
119void VuoRendererNode::setOutputPorts(vector<VuoRendererPort *> outputPorts)
132 this->outputPorts.push_back(*it);
134 (*it)->setParentItem(
this);
139 (*it)->updateNameRect();
151 QPointF point = getPortPoint(p, i++);
161 p->setPos(getPortPoint(p, i++));
188 bool reachedTargetPort =
false;
191 for (
int i =
inputPorts.size()-1; i >= 0; --i)
194 reachedTargetPort =
true;
196 if (reachedTargetPort)
197 layoutConnectedInputDrawer(i);
214void VuoRendererNode::layoutConnectedInputDrawer(
unsigned int i)
225 QPointF point = getPortPoint(p, i);
230 drawer->setPos(mapToScene(point-inputDrawerOffset));
243void VuoRendererNode::drawNodeFrame(QPainter *painter, QRectF nodeInnerFrameRect,
VuoRendererColors *colors)
const
245 QPainterPath nodeOuterFrame = this->nodeFrames.first;
246 QPainterPath nodeInnerFrame = this->nodeFrames.second;
249 painter->fillPath(nodeInnerFrame, colors->
nodeFill());
254 painter->fillPath(nodeOuterFrame, colors->
nodeFrame());
257 if (nodeIsSubcomposition)
258 painter->fillPath(this->subcompositionIndicatorPath, QBrush(QColor::fromRgb(255,255,255,128)));
267 QRectF nodeOuterFrameRect;
270 nodeOuterFrameRect = QRectF(
271 nodeInnerFrameRect.left() - VuoRendererNode::outerBorderWidth,
273 nodeInnerFrameRect.width() + 2*VuoRendererNode::outerBorderWidth,
279 QPainterPath nodeOuterFrame;
283 nodeOuterFrame.moveTo(nodeOuterFrameRect.right(), nodeOuterFrameRect.center().y());
284 addRoundedCorner(nodeOuterFrame,
true, nodeOuterFrameRect.bottomRight(), nodeHeaderBottomCornerRadius,
false,
false);
285 addRoundedCorner(nodeOuterFrame,
true, nodeOuterFrameRect.bottomLeft(), nodeHeaderBottomCornerRadius,
false,
true);
290 QPainterPath nodeInnerFrame;
293 qreal bw = VuoRendererNode::outerBorderWidth;
294 nodeInnerFrame.moveTo(nodeInnerFrameRect.topLeft() - QPoint(bw, 0) - QPoint(0, nodeHeaderBottomCornerRadius));
295 nodeInnerFrame.lineTo(nodeInnerFrameRect.topRight() + QPoint(bw, 0) - QPoint(0, nodeHeaderBottomCornerRadius));
300 return qMakePair(nodeOuterFrame, nodeInnerFrame);
309 if (!isSubcomposition)
310 return QPainterPath();
315 QPainterPath rectPath;
316 rectPath.addRect(QRectF(-0.5 + nodeInnerFrameRect.right() - iconRightOffset,
317 -4. - 1.5*rectSideLength,
322 QPainterPathStroker rectStroker;
323 QPainterPath topLeftStroke = rectStroker.createStroke(rectPath);
326 rectPath.translate(-0.5 + rectSideLength/2,
327 -0.5 + rectSideLength/2);
328 QPainterPath bottomRightStroke = rectStroker.createStroke(rectPath);
331 return topLeftStroke.united(bottomRightStroke);
342 for (
unsigned int i =
inputPorts.size()-1; i > portIndex; --i)
351 qreal currentTypecastOffset = tp->
getPortPath(
true,
true).boundingRect().width()
355 if (currentTypecastOffset > maxOffset)
356 maxOffset = currentTypecastOffset;
360 qreal currentConstantOffset = port->
getPortPath().boundingRect().width()
364 if (currentConstantOffset > maxOffset)
365 maxOffset = currentConstantOffset;
373 qreal targetDrawerOffset =
inputPorts[portIndex]->getRenderer()->getAttachedInputDrawer()->getMaxDrawerLabelWidth()
376 return targetDrawerOffset + maxOffset;
384 vector<VuoRendererInputDrawer *> drawers;
386 for(
unsigned int i = 0; i <
inputPorts.size(); ++i)
390 drawers.push_back(drawer);
403 QRectF updatedFrameRect;
404 QString nodeTitle = QString::fromUtf8(
getBase()->getTitle().c_str());
408 nodeTitle = nodeTitle.normalized(QString::NormalizationForm_C);
411 qreal maxPortRowWidth=0;
415 size_t portRowCount = max(inputPortCount, outputPortCount);
416 for (
int portRow = 0; portRow < portRowCount; ++portRow)
422 qreal thisRowWidth = 0;
423 if (adjustedInputPortRow < inputPortCount)
432 if (adjustedOutputPortRow < outputPortCount)
433 thisRowWidth +=
outputPorts[adjustedOutputPortRow]->getNameRect().width();
435 if(thisRowWidth > maxPortRowWidth)
436 maxPortRowWidth = thisRowWidth;
442 if (this->nodeIsSubcomposition)
443 nodeClassWidth += VuoRendererNode::iconRightOffset;
447 int unalignedFrameWidth =
451 + nodeTitleHorizontalMargin * 2.
477 - 2*VuoRendererNode::outerBorderWidth;
479 if (alignedFrameWidth < unalignedFrameWidth)
482 updatedFrameRect.setWidth(alignedFrameWidth);
485 updatedFrameRect.setHeight(
495 this->frameRect = updatedFrameRect;
508 QRectF r = frameRect;
516 return r.toAlignedRect();
524 return this->proxyNode;
544QPointF VuoRendererNode::getPortPoint(
VuoRendererPort *port,
unsigned int portIndex)
const
559 qreal adjustedPortIndex = (qreal)portIndex - (port->
getOutput() ?
563 qreal portOffset = adjustedPortIndex + 0.5;
567 return QPointF(x, y);
578 return nodeFrames.first.boundingRect();
596 drawNodeFrame(painter, frameRect, colors);
600 QString nodeTitle = QString::fromUtf8(
getBase()->getTitle().c_str());
604 nodeTitle = nodeTitle.normalized(QString::NormalizationForm_C);
608 nodeTitleBoundingRect = QRectF(
609 nodeTitleHorizontalMargin
616 painter->setFont(font);
617 painter->drawText(nodeTitleBoundingRect,Qt::AlignLeft,nodeTitle);
629 -nodeClassHeight - 2.,
634 painter->setFont(font);
635 painter->drawText(r,Qt::AlignLeft,nodeClass);
645 QString text = notAvailable ?
"Not Available" :
"Not Installed";
649 if (
getBase()->getNodeClass()->isPro())
651 QFontMetrics fm(font);
653 stickerRect.setSize(QSize(16,16));
654 stickerRect.moveCenter(frameRect.center().toPoint());
655 stickerRect.translate(-fm.boundingRect(text).width()/2 - 12, -2);
656 QIcon(
":/Icons/menuitem-pro.svg").paint(painter, stickerRect);
661 painter->setFont(font);
662 painter->drawText(frameRect, Qt::AlignCenter, text);
673 this->nodeIsMissing = missingImplementation;
681 return nodeIsMissing;
689 this->proxyNode = proxyNode;
726 QVariant newValue = value;
728 if (change == QGraphicsItem::ItemPositionChange)
740 newValue = value.toPoint();
747 (*it)->setCacheModeForPortAndChildren(QGraphicsItem::NoCache);
748 (*it)->updateGeometry();
754 (*it)->setCacheModeForPortAndChildren(QGraphicsItem::NoCache);
755 (*it)->updateGeometry();
766 if (change == QGraphicsItem::ItemPositionHasChanged)
768 QPointF newPos = value.toPointF();
769 if ((
getBase()->getX() != newPos.x()) || (
getBase()->getY() != newPos.y()))
779 set<VuoRendererNode *> movedNodes;
785 movedNodes.insert(
this);
796 if (change == QGraphicsItem::ItemSelectedHasChanged)
807 attachment->update();
810 attachmentInputPort->update();
831 return QGraphicsItem::itemChange(change, newValue);
849 if (nodeTitleBoundingRect.contains(event->pos()))
870 if (event->button() == Qt::LeftButton)
873 if (QLineF(event->screenPos(), event->buttonDownScreenPos(Qt::LeftButton)).length() < QApplication::startDragDistance())
877 QGraphicsItem::mouseReleaseEvent(event);
887 if (nodeTitleBoundingRect.contains(event->pos()))
906 if (event->key() == Qt::Key_Return)
924 set<VuoCable *> connectedCables;
925 connectedCables.insert(connectedInputCables.begin(), connectedInputCables.end());
926 connectedCables.insert(connectedOutputCables.begin(), connectedOutputCables.end());
928 return connectedCables;
938 set<VuoCable *> connectedInputCables;
941 for(vector<VuoPort *>::iterator inputPort =
inputPorts.begin(); inputPort !=
inputPorts.end(); ++inputPort)
943 vector<VuoCable *> inputCables = (*inputPort)->getConnectedCables(includePublishedCables);
944 connectedInputCables.insert(inputCables.begin(), inputCables.end());
946 if ((*inputPort)->hasRenderer())
952 connectedInputCables.insert(childPortInputCables.begin(), childPortInputCables.end());
957 return connectedInputCables;
966 set<VuoCable *> connectedOutputCables;
969 for(vector<VuoPort *>::iterator outputPort =
outputPorts.begin(); outputPort !=
outputPorts.end(); ++outputPort)
971 vector<VuoCable *> outputCables = (*outputPort)->getConnectedCables(includePublishedCables);
972 connectedOutputCables.insert(outputCables.begin(), outputCables.end());
975 return connectedOutputCables;
983 this->prepareGeometryChange();
987 (*it)->updateGeometry();
990 (*it)->updateGeometry();
999 for (set<VuoCable *>::iterator cable = connectedCables.begin(); cable != connectedCables.end(); ++cable)
1001 if (! (*cable)->hasRenderer())
1035 vector<pair<QString, json_object *> > portNamesAndValues;
1037 for (vector<VuoRendererPort *>::iterator it =
inputPorts.begin(); it !=
inputPorts.end(); ++it)
1044 portNamesAndValues.push_back(make_pair(name, value));
1048 return portNamesAndValues;
1059 newPort->setParentItem(
this);
1060 newPort->stackBefore(oldPort);
1062 scene()->removeItem(oldPort);
1079 newPort->setParentItem(
this);
1165 this->setCacheMode(QGraphicsItem::NoCache);
1167 this->setCacheMode(mode);
1169 for (vector<VuoRendererPort *>::iterator it =
inputPorts.begin(); it !=
inputPorts.end(); ++it)
1170 (*it)->setCacheModeForPortAndChildren(mode);
1173 (*it)->setCacheModeForPortAndChildren(mode);
1182 for (set<VuoCable *>::iterator cable = connectedCables.begin(); cable != connectedCables.end(); ++cable)
1184 if (! (*cable)->hasRenderer())
1188 rc->setCacheMode(mode);
1240 if (!nodeHasUnambiguousInput)
1264 return !nodeHasUnambiguousOutput;
1273 return _eligibilityHighlight;
1282 _eligibilityHighlight = eligibility;