26 const qreal VuoRendererNode::outerBorderWidth = 1.;
28 const qreal VuoRendererNode::nodeTitleHorizontalMargin = 12 ;
29 const qreal VuoRendererNode::nodeClassHeight = 12 ;
31 const 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());
102 void VuoRendererNode::setInputPorts(vector<VuoRendererPort *> inputPorts)
106 this->inputPorts.push_back(*it);
107 (*it)->setParentItem(
this);
109 if ((*it)->isHiddenRefreshPort())
115 (*it)->updateNameRect();
119 void 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);
214 void VuoRendererNode::layoutConnectedInputDrawer(
unsigned int i)
225 QPointF point = getPortPoint(p, i);
230 drawer->setPos(mapToScene(point-inputDrawerOffset));
232 drawer->setSelected(this->isSelected());
244 void VuoRendererNode::drawNodeFrame(QPainter *painter, QRectF nodeInnerFrameRect,
VuoRendererColors *colors)
const
246 QPainterPath nodeOuterFrame = this->nodeFrames.first;
247 QPainterPath nodeInnerFrame = this->nodeFrames.second;
250 painter->fillPath(nodeInnerFrame, colors->
nodeFill());
255 painter->fillPath(nodeOuterFrame, colors->
nodeFrame());
258 if (nodeIsSubcomposition)
259 painter->fillPath(this->subcompositionIndicatorPath, QBrush(QColor::fromRgb(255,255,255,128)));
268 QRectF nodeOuterFrameRect;
271 nodeOuterFrameRect = QRectF(
272 nodeInnerFrameRect.left() - VuoRendererNode::outerBorderWidth,
274 nodeInnerFrameRect.width() + 2*VuoRendererNode::outerBorderWidth,
280 QPainterPath nodeOuterFrame;
284 nodeOuterFrame.moveTo(nodeOuterFrameRect.right(), nodeOuterFrameRect.center().y());
285 addRoundedCorner(nodeOuterFrame,
true, nodeOuterFrameRect.bottomRight(), nodeHeaderBottomCornerRadius,
false,
false);
286 addRoundedCorner(nodeOuterFrame,
true, nodeOuterFrameRect.bottomLeft(), nodeHeaderBottomCornerRadius,
false,
true);
291 QPainterPath nodeInnerFrame;
294 qreal bw = VuoRendererNode::outerBorderWidth;
295 nodeInnerFrame.moveTo(nodeInnerFrameRect.topLeft() - QPoint(bw, 0) - QPoint(0, nodeHeaderBottomCornerRadius));
296 nodeInnerFrame.lineTo(nodeInnerFrameRect.topRight() + QPoint(bw, 0) - QPoint(0, nodeHeaderBottomCornerRadius));
301 return qMakePair(nodeOuterFrame, nodeInnerFrame);
310 if (!isSubcomposition)
311 return QPainterPath();
316 QPainterPath rectPath;
317 rectPath.addRect(QRectF(-0.5 + nodeInnerFrameRect.right() - iconRightOffset,
318 -4. - 1.5*rectSideLength,
323 QPainterPathStroker rectStroker;
324 QPainterPath topLeftStroke = rectStroker.createStroke(rectPath);
327 rectPath.translate(-0.5 + rectSideLength/2,
328 -0.5 + rectSideLength/2);
329 QPainterPath bottomRightStroke = rectStroker.createStroke(rectPath);
332 return topLeftStroke.united(bottomRightStroke);
343 for (
unsigned int i =
inputPorts.size()-1; i > portIndex; --i)
352 qreal currentTypecastOffset = tp->
getPortPath(
true,
true).boundingRect().width()
356 if (currentTypecastOffset > maxOffset)
357 maxOffset = currentTypecastOffset;
361 qreal currentConstantOffset = port->
getPortPath().boundingRect().width()
365 if (currentConstantOffset > maxOffset)
366 maxOffset = currentConstantOffset;
374 qreal targetDrawerOffset =
inputPorts[portIndex]->getRenderer()->getAttachedInputDrawer()->getMaxDrawerLabelWidth()
377 return targetDrawerOffset + maxOffset;
385 vector<VuoRendererInputDrawer *> drawers;
387 for(
unsigned int i = 0; i <
inputPorts.size(); ++i)
391 drawers.push_back(drawer);
404 QRectF updatedFrameRect;
405 QString nodeTitle = QString::fromUtf8(
getBase()->getTitle().c_str());
409 nodeTitle = nodeTitle.normalized(QString::NormalizationForm_C);
412 qreal maxPortRowWidth=0;
416 size_t portRowCount = max(inputPortCount, outputPortCount);
417 for (
int portRow = 0; portRow < portRowCount; ++portRow)
423 qreal thisRowWidth = 0;
424 if (adjustedInputPortRow < inputPortCount)
433 if (adjustedOutputPortRow < outputPortCount)
434 thisRowWidth +=
outputPorts[adjustedOutputPortRow]->getNameRect().width();
436 if(thisRowWidth > maxPortRowWidth)
437 maxPortRowWidth = thisRowWidth;
443 if (this->nodeIsSubcomposition)
444 nodeClassWidth += VuoRendererNode::iconRightOffset;
448 int unalignedFrameWidth =
452 + nodeTitleHorizontalMargin * 2.
478 - 2*VuoRendererNode::outerBorderWidth;
480 if (alignedFrameWidth < unalignedFrameWidth)
483 updatedFrameRect.setWidth(alignedFrameWidth);
486 updatedFrameRect.setHeight(
496 this->frameRect = updatedFrameRect;
509 QRectF r = frameRect;
517 return r.toAlignedRect();
525 return this->proxyNode;
534 QPointF VuoRendererNode::getPortPoint(
VuoRendererPort *port,
unsigned int portIndex)
const
549 qreal adjustedPortIndex = (qreal)portIndex - (port->
getOutput() ?
553 qreal portOffset = adjustedPortIndex + 0.5;
557 return QPointF(x, y);
568 return nodeFrames.first.boundingRect();
586 drawNodeFrame(painter, frameRect, colors);
590 QString nodeTitle = QString::fromUtf8(
getBase()->getTitle().c_str());
594 nodeTitle = nodeTitle.normalized(QString::NormalizationForm_C);
598 nodeTitleBoundingRect = QRectF(
599 nodeTitleHorizontalMargin
606 painter->setFont(font);
607 painter->drawText(nodeTitleBoundingRect,Qt::AlignLeft,nodeTitle);
619 -nodeClassHeight - 2.,
624 painter->setFont(font);
625 painter->drawText(r,Qt::AlignLeft,nodeClass);
635 QString text = notAvailable ?
"Not Available" :
"Not Installed";
639 if (
getBase()->getNodeClass()->isPro())
641 QFontMetrics fm(font);
643 stickerRect.setSize(QSize(16,16));
644 stickerRect.moveCenter(frameRect.center().toPoint());
645 stickerRect.translate(-fm.width(text)/2 - 12, -2);
646 QIcon(
":/Icons/menuitem-pro.svg").paint(painter, stickerRect);
651 painter->setFont(font);
652 painter->drawText(frameRect, Qt::AlignCenter, text);
663 this->nodeIsMissing = missingImplementation;
671 return nodeIsMissing;
679 this->proxyNode = proxyNode;
716 QVariant newValue = value;
718 if (change == QGraphicsItem::ItemPositionChange)
730 newValue = value.toPoint();
737 (*it)->setCacheModeForPortAndChildren(QGraphicsItem::NoCache);
738 (*it)->updateGeometry();
744 (*it)->setCacheModeForPortAndChildren(QGraphicsItem::NoCache);
745 (*it)->updateGeometry();
756 if (change == QGraphicsItem::ItemPositionHasChanged)
758 QPointF newPos = value.toPointF();
759 if ((
getBase()->getX() != newPos.x()) || (
getBase()->getY() != newPos.y()))
769 set<VuoRendererNode *> movedNodes;
775 movedNodes.insert(
this);
786 if (change == QGraphicsItem::ItemSelectedHasChanged)
807 return QGraphicsItem::itemChange(change, newValue);
825 if (nodeTitleBoundingRect.contains(event->pos()))
846 if (event->button() == Qt::LeftButton)
849 if (QLineF(event->screenPos(), event->buttonDownScreenPos(Qt::LeftButton)).length() < QApplication::startDragDistance())
853 QGraphicsItem::mouseReleaseEvent(event);
863 if (nodeTitleBoundingRect.contains(event->pos()))
882 if (event->key() == Qt::Key_Return)
900 set<VuoCable *> connectedCables;
901 connectedCables.insert(connectedInputCables.begin(), connectedInputCables.end());
902 connectedCables.insert(connectedOutputCables.begin(), connectedOutputCables.end());
904 return connectedCables;
914 set<VuoCable *> connectedInputCables;
917 for(vector<VuoPort *>::iterator inputPort =
inputPorts.begin(); inputPort !=
inputPorts.end(); ++inputPort)
919 vector<VuoCable *> inputCables = (*inputPort)->getConnectedCables(includePublishedCables);
920 connectedInputCables.insert(inputCables.begin(), inputCables.end());
922 if ((*inputPort)->hasRenderer())
928 connectedInputCables.insert(childPortInputCables.begin(), childPortInputCables.end());
933 return connectedInputCables;
942 set<VuoCable *> connectedOutputCables;
945 for(vector<VuoPort *>::iterator outputPort =
outputPorts.begin(); outputPort !=
outputPorts.end(); ++outputPort)
947 vector<VuoCable *> outputCables = (*outputPort)->getConnectedCables(includePublishedCables);
948 connectedOutputCables.insert(outputCables.begin(), outputCables.end());
951 return connectedOutputCables;
959 this->prepareGeometryChange();
963 (*it)->updateGeometry();
966 (*it)->updateGeometry();
975 for (set<VuoCable *>::iterator cable = connectedCables.begin(); cable != connectedCables.end(); ++cable)
977 if (! (*cable)->hasRenderer())
1011 vector<pair<QString, json_object *> > portNamesAndValues;
1013 for (vector<VuoRendererPort *>::iterator it =
inputPorts.begin(); it !=
inputPorts.end(); ++it)
1020 portNamesAndValues.push_back(make_pair(name, value));
1024 return portNamesAndValues;
1035 newPort->setParentItem(
this);
1036 newPort->stackBefore(oldPort);
1038 scene()->removeItem(oldPort);
1055 newPort->setParentItem(
this);
1141 this->setCacheMode(QGraphicsItem::NoCache);
1143 this->setCacheMode(mode);
1145 for (vector<VuoRendererPort *>::iterator it =
inputPorts.begin(); it !=
inputPorts.end(); ++it)
1146 (*it)->setCacheModeForPortAndChildren(mode);
1149 (*it)->setCacheModeForPortAndChildren(mode);
1158 for (set<VuoCable *>::iterator cable = connectedCables.begin(); cable != connectedCables.end(); ++cable)
1160 if (! (*cable)->hasRenderer())
1164 rc->setCacheMode(mode);
1216 if (!nodeHasUnambiguousInput)
1240 return !nodeHasUnambiguousOutput;
1249 return _eligibilityHighlight;
1258 _eligibilityHighlight = eligibility;