32 portConstantsChangedSinceLastCachedOutline =
true;
34 setZValue(cableZValue);
48 floatingEndpointLoc = QPointF();
49 floatingEndpointPreviousToPort = NULL;
50 previouslyAlwaysEventOnly =
false;
51 floatingEndpointAboveEventPort =
false;
55 this->setAcceptHoverEvents(
true);
56 this->setFlags(QGraphicsItem::ItemIsSelectable);
69 QRectF r = cablePath.boundingRect();
80 return r.toAlignedRect();
90 return QPainterPath();
95 QPainterPathStroker s;
98 return s.createStroke(p);
104 QPointF VuoRendererCable::getStartPoint(
void)
const
114 QList<QGraphicsView *> views = scene()->views();
122 return floatingEndpointLoc;
128 QPointF VuoRendererCable::getEndPoint(
void)
const
139 QList<QGraphicsView *> views = scene()->views();
148 return toNodeProxy->pos() + toPort->
getRenderer()->pos() + QPointF(0, -.35);
150 return rn->pos() + toPort->
getRenderer()->pos() + QPointF(0, -.35);
154 return floatingEndpointLoc;
163 return QPainterPath();
174 void VuoRendererCable::arclineTo(QPainterPath &cablePath, QPointF to,
float radius,
float fromCableStandoff)
const
176 QPointF from = cablePath.currentPosition();
177 float direction = from.y() < to.y() ? 1 : -1;
179 QRectF fromRect(from - QPointF(radius, -radius*2*direction), from + QPointF(radius, 0));
181 if (to.x() >= from.x() + radius*2)
187 float stopAngle = -atan2(to.y() - from.y(), to.x() - from.x()) * 180/M_PI;
188 cablePath.arcTo(fromRect, -90, -stopAngle*direction);
191 QRectF toRect(to - QPointF(radius, radius*2*direction), to + QPointF(radius, 0));
192 cablePath.arcTo(toRect, -90 + stopAngle*direction, -stopAngle*direction);
200 cablePath.arcTo(fromRect, -90, 90);
202 float fromNodeEscape = 0;
213 QRectF nodeRect = rn->sceneBoundingRect();
214 QRectF portRect = fromPort->
getRenderer()->sceneBoundingRect();
215 if (from.y() < to.y())
217 fromNodeEscape = nodeRect.bottom() - portRect.bottom();
220 fromNodeEscape = portRect.top() - nodeRect.top();
223 fromNodeEscape += fromCableStandoff;
226 float toNodeEscape = 0;
237 QRectF nodeRect = rn->sceneBoundingRect();
238 QRectF portRect = toPort->
getRenderer()->sceneBoundingRect();
239 if (from.y() < to.y())
241 toNodeEscape = portRect.top() - nodeRect.top();
244 toNodeEscape = nodeRect.bottom() - portRect.bottom();
250 fromNodeEscape += direction>0 ? 4.85 : 3.15;
252 toNodeEscape += direction>0 ? 8 : -1.75;
254 toNodeEscape += direction>0 ? 4.15 : 4.85;
257 if (fromNodeEscape + toNodeEscape + radius*3 >= fabs(from.y() - to.y()))
258 fromNodeEscape = toNodeEscape = 0;
260 QPointF fromEscaped = cablePath.currentPosition() + QPointF(0, fromNodeEscape*direction);
261 QPointF toEscaped = to - QPointF(radius, (radius + toNodeEscape)*direction);
263 QRectF fromEscapedRect(fromEscaped - QPointF(radius*2, radius*direction),
264 fromEscaped + QPointF(0, radius*direction));
266 float stopAngle = atan2(fromEscaped.x() - toEscaped.x(), fromEscaped.y() - toEscaped.y()) * 180/M_PI;
267 if (to.y() > from.y())
268 stopAngle = 180-stopAngle;
270 cablePath.arcTo(fromEscapedRect, 0, -stopAngle);
274 QRectF toEscapedRect(toEscaped - QPointF(0, radius*direction), toEscaped + QPointF(radius*2, radius*direction));
275 cablePath.arcTo(toEscapedRect, 180 - stopAngle, stopAngle);
277 QRectF toRect(to-QPointF(radius, radius*2*direction), to + QPointF(radius, 0));
278 cablePath.arcTo(toRect, 180, 90);
290 QPainterPath cablePath(from);
294 float fromStandoff = 0;
295 float fromCableStandoff = 0;
298 if (fromNode && fromPort)
300 vector<VuoPort *> outputs = (from.y() < to.y())
303 for (vector<VuoPort *>::iterator i = outputs.begin(); i != outputs.end(); ++i)
305 vector<VuoCable *> cables = (*i)->getConnectedCables();
306 if ((*i)->hasRenderer() && !cables.empty())
308 bool hasOnlyWireless =
true;
309 for (vector<VuoCable *>::iterator cable = cables.begin(); cable != cables.end(); ++cable)
310 if ((*cable)->hasRenderer())
315 hasOnlyWireless =
false;
335 float toStandoff = 0;
338 if (toNode && toPort)
340 vector<VuoPort *> inputs = (from.y() < to.y())
343 for (vector<VuoPort *>::iterator i = inputs.begin(); i != inputs.end(); ++i)
344 if ((*i)->hasRenderer() && (*i)->getRenderer()->isConstant())
346 float constantFlagWidth = (*i)->getRenderer()->getPortConstantTextRect().width();
347 toStandoff = fmax(toStandoff, constantFlagWidth);
357 QPointF fromWithStandoff(from.x() + fromStandoff, from.y());
358 QPointF toWithStandoff( to.x() - toStandoff, to.y());
360 float length = (from - to).manhattanLength();
367 cablePath.lineTo(fromWithStandoff);
371 cablePath.lineTo(to);
386 return VuoNode::TintNone;
393 bool VuoRendererCable::isConnectedToSelectedNode(
void)
401 bool toNodeViaAttachmentIsSelected = toNode && toNode->
hasRenderer() &&
406 return (fromNodeIsSelected || toNodeIsSelected || toNodeViaTypeconverterIsSelected || toNodeViaAttachmentIsSelected);
417 bool hoverHighlightingEnabled = isHovered;
422 (isConnectedToSelectedNode()? VuoRendererColors::indirectSelection :
423 VuoRendererColors::noSelection));
425 qint64 timeOfLastActivity = (
getRenderActivity()? timeLastEventPropagated : VuoRendererItem::notTrackingActivity);
428 (selectionType != VuoRendererColors::noSelection?
false : hoverHighlightingEnabled),
429 _eligibilityHighlight,
439 QPointF startPoint = getStartPoint();
440 QPointF endPoint = getEndPoint();
444 QPainterPath outline = getOutline(startPoint, endPoint, renderAsIfCableCarriesData);
445 if (outline.isEmpty())
449 painter->fillPath(outline, QBrush(colors.
cableMain()));
452 if (hoverHighlightingEnabled)
457 QPainterPath yankZone;
458 getYankZonePath(startPoint, endPoint, renderAsIfCableCarriesData, toPortSupportsYanking, yankZone);
460 painter->setClipPath(yankZone);
461 painter->fillPath(outline, QBrush(yankZoneColors.
cableMain()));
463 painter->setClipping(
false);
472 QPainterPath VuoRendererCable::getOutline(QPointF startPoint,
474 bool cableCarriesData)
476 if ((qMakePair(startPoint, endPoint) != this->cachedEndpointsForOutlines)
477 || (cableCarriesData != this->cachedCarriesDataValueForOutlines)
478 || portConstantsChangedSinceLastCachedOutline)
485 QPainterPathStroker mainStroker;
487 mainStroker.setCapStyle(Qt::RoundCap);
488 QPainterPath mainOutline = mainStroker.createStroke(cablePath);
490 this->cachedEndpointsForOutlines = qMakePair(startPoint, endPoint);
491 this->cachedCarriesDataValueForOutlines = cableCarriesData;
492 this->cachedOutline = mainOutline;
493 this->portConstantsChangedSinceLastCachedOutline =
false;
496 return this->cachedOutline;
505 void VuoRendererCable::getYankZonePath(QPointF startPoint,
507 bool cableCarriesData,
508 bool toPortSupportsYanking,
509 QPainterPath &yankZone
512 if ((qMakePair(startPoint, endPoint) != this->cachedEndpointsForYankZone) ||
513 (toPortSupportsYanking != this->cachedToPortSupportsYankingValueForYankZone) ||
514 (cableCarriesData != this->cachedCarriesDataValueForYankZone))
517 QPainterPath yankZone;
518 if (
getBase()->getToPort() && toPortSupportsYanking)
521 this->cachedEndpointsForYankZone = qMakePair(startPoint, endPoint);
522 this->cachedCarriesDataValueForYankZone = cableCarriesData;
523 this->cachedToPortSupportsYankingValueForYankZone = toPortSupportsYanking;
524 this->cachedYankZonePath = yankZone;
527 yankZone = this->cachedYankZonePath;
535 const qreal dataCableToEventCableWidthRatio = 4;
558 if (isPublishedInputCableWithoutVisiblePublishedPort() || isPublishedOutputCableWithoutVisiblePublishedPort())
573 bool VuoRendererCable::isPublishedInputCableWithoutVisiblePublishedPort()
const
585 bool proxyPublishedInputSidebarPortHidden = (! publishedPort->isVisible());
586 if (proxyPublishedInputSidebarPortHidden)
598 bool VuoRendererCable::isPublishedOutputCableWithoutVisiblePublishedPort()
const
610 bool proxyPublishedOutputSidebarPortHidden = (! publishedPort->isVisible());
611 if (proxyPublishedOutputSidebarPortHidden)
624 if (isPublishedInputCableWithoutVisiblePublishedPort() || isPublishedOutputCableWithoutVisiblePublishedPort())
649 QGraphicsItem::CacheMode normalCacheMode = cacheMode();
662 this->setCacheMode(mode);
670 fromPort->setCacheMode(mode);
673 toPort->setCacheMode(mode);
682 portConstantsChangedSinceLastCachedOutline =
true;
691 return floatingEndpointLoc;
702 QGraphicsItem::CacheMode normalCacheMode = cacheMode();
736 QGraphicsItem::CacheMode normalCacheMode = cacheMode();
782 floatingEndpointLoc = loc;
791 floatingEndpointAboveEventPort = aboveEventPort;
799 return floatingEndpointAboveEventPort;
809 this->prepareGeometryChange();
824 scene()->removeItem(
this);
858 qreal yankDistance = QLineF(scenePos, getEndPoint()).length();
868 return floatingEndpointPreviousToPort;
877 this->floatingEndpointPreviousToPort = port;
886 return this->previouslyAlwaysEventOnly;
895 this->previouslyAlwaysEventOnly = eventOnly;
903 QGraphicsItem::CacheMode normalCacheMode = cacheMode();
904 setCacheMode(QGraphicsItem::NoCache);
906 prepareGeometryChange();
908 this->isHovered = hovered;
910 setCacheMode(normalCacheMode);
918 _eligibilityHighlight = eligibility;
926 this->prepareGeometryChange();
943 return (
getBase()->hasCompiler() ?
944 getBase()->getCompiler()->carriesData() :