Vuo  2.1.0
VuoRendererPort.hh
Go to the documentation of this file.
1 
10 #pragma once
11 
12 #include "VuoRendererItem.hh"
13 
14 #include "VuoBaseDetail.hh"
15 #include "VuoType.hh"
16 #include "VuoPortClass.hh"
18 #include "VuoRendererColors.hh"
19 
21 class VuoCompilerNode;
22 class VuoRendererNode;
24 class VuoCable;
25 class VuoPort;
28 
32 class VuoRendererPort : public VuoRendererItem, public VuoBaseDetail<VuoPort>
33 {
34 public:
36  bool isOutput, bool isRefreshPort, bool isFunctionPort);
37  ~VuoRendererPort();
38 
39  QRectF boundingRect(void) const;
40  QRectF getNameRect(void) const;
41  bool hasPortAction(void) const;
42  QRectF getActionIndicatorRect(void) const;
43  QPainterPath shape(void) const;
44  void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
45 
46  bool getEligibleForSelection(void);
47  bool isEligibleForConnection(void);
50  void extendedHoverEnterEvent(bool cableDragUnderway=false, bool disableConnectedCableHighlight=false);
51  void extendedHoverMoveEvent(bool cableDragUnderway=false, bool disableConnectedCableHighlight=false);
53  bool canConnectDirectlyWithoutSpecializationTo(VuoRendererPort *toPort, bool eventOnlyConnection);
54  bool canConnectDirectlyWithSpecializationTo(VuoRendererPort *toPort, bool eventOnlyConnection);
55  bool canConnectDirectlyWithSpecializationTo(VuoRendererPort *toPort, bool eventOnlyConnection, VuoRendererPort **portToSpecialize, string &specializedTypeName);
56  VuoCable * getCableConnectedTo(VuoRendererPort *toPort, bool includePublishedCables);
57  bool getInput(void) const;
58  bool getOutput(void) const;
59  bool getRefreshPort(void) const;
60  bool getFunctionPort(void) const;
61  void updateNameRect(void);
62  void updateGeometry();
63  QVariant itemChange(GraphicsItemChange change, const QVariant &value);
64  QPainterPath getPortPath() const;
65  static QRectF getPortRect(void);
67  virtual QRectF getPortConstantTextRect(void) const;
68  static int getTextWidth(QString text);
69  VuoType * getDataType(void) const;
70  bool hasURLType(void) const;
71  bool hasRelativeReadURLConstantValue(void) const;
72  bool isConstant(void) const;
73  bool effectivelyHasConnectedDataCable(bool includePublishedCables) const;
74  static string format(const char *format, ...);
75  static string stringAndFree(char *strz);
76  string getConstantAsString(void) const;
77  string getConstantAsTruncatedStringToRender(void) const;
78  string getConstantAsStringToRender(void) const;
79  string getStringForRealValue(double value) const;
80  string getStringForRealValue(float value) const;
81  void setConstant(string constantValue);
82  string getPortNameToRender() const;
83  string getPortNameToRenderWhenDisplayed() const;
84  static QString getPortIdentifierRegExp();
85  static QString sanitizePortIdentifier(QString portID);
86  void setPortNameToRender(string name);
87  bool getPublishable() const;
88  vector<VuoRendererPublishedPort *> getPublishedPorts() const;
89  vector<VuoRendererPublishedPort *> getPublishedPortsConnectedByDataCarryingCables(void) const;
91 
94  set<VuoRendererInputAttachment *> getAllUnderlyingUpstreamInputAttachments(void) const;
95  set<VuoRendererPort *> getPortsConnectedWirelessly(bool includePublishedCables) const;
96 
98  void setTypecastParentPort(VuoRendererPort *typecastParentPort);
100 
102  void setFiredEvent();
103  void setFadePercentageSinceEventFired(qreal percentage);
104  void setCacheModeForPortAndChildren(QGraphicsItem::CacheMode mode);
105 
106  vector<QGraphicsItemAnimation *> getAnimations();
107  void setAnimated(bool animated);
108 
109  bool isHiddenRefreshPort(void);
110 
111  bool carriesData(void) const;
112 
113  // Drawing configuration
114  static const qreal portRadius;
115  static const qreal portSpacing;
116  static const qreal portContainerMargin;
117  static const qreal portInset;
118  static const qreal portBarrierWidth;
119  static const qreal portConstantTextPadding;
120 
121 protected:
122  void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
123  void keyPressEvent(QKeyEvent *event);
124 
125 private:
126 
127  QFont getPortNameFont(void) const;
128  static void addRoundedTriangle(QPainterPath &p, QPointF center, qreal radius, qreal cornerRadius);
129 
130  // Port attributes affecting drawing
131  bool isOutput;
132  bool isFunctionPort;
133  VuoRendererColors::HighlightType _eligibilityHighlight;
134  bool isEligibleForSelection;
135  bool isAnimated;
136  VuoRendererPort *typecastParentPort;
137  qint64 timeLastEventFired;
138  vector<QGraphicsItemAnimation *> animations;
139 
141  friend class TestVuoRenderer;
142 
143 protected:
145 
148 
149  QRectF nameRect;
151 
152  bool portNameRenderingEnabled(void) const;
153  void updateEnabledStatus();
156 
157  QPainterPath cachedPortPath;
158  void updateCachedPortPath();
159 
160  static QRectF getPortConstantTextRectForText(QString text);
161  static QPainterPath getPortPath(qreal inset, VuoPortClass::PortType portType, QString constantText, bool isInputPort, bool carriesData);
162  QRectF getEventBarrierRect(void) const;
163  virtual QPainterPath getWirelessAntennaPath() const;
164  bool hasConnectedWirelessDataCable(bool includePublishedCables) const;
165  bool hasConnectedWirelessEventCable(bool includePublishedCables) const;
167  qint64 getTimeOfLastActivity();
168 
169  void paintPortName(QPainter *painter, VuoRendererColors *colors);
170  void paintEventBarrier(QPainter *painter, VuoRendererColors *colors);
171  void paintActionIndicator(QPainter *painter, VuoRendererColors *colors);
172  void paintWirelessAntenna(QPainter *painter, VuoRendererColors *colors);
174  string getPointStringForCoords(QList<float>) const;
175 
177 };
178