Vuo  2.3.2
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 getPortNameRegExp();
85  static QString sanitizePortName(QString portName);
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  void updateToolTip();
130 
131  // Port attributes affecting drawing
132  bool isOutput;
133  bool isFunctionPort;
134  VuoRendererColors::HighlightType _eligibilityHighlight;
135  bool isEligibleForSelection;
136  bool isAnimated;
137  VuoRendererPort *typecastParentPort;
138  qint64 timeLastEventFired;
139  vector<QGraphicsItemAnimation *> animations;
140 
142  friend class TestVuoRenderer;
143 
144 protected:
146 
149 
150  QRectF nameRect;
152 
153  bool portNameRenderingEnabled(void) const;
154  void updateEnabledStatus();
157 
158  QPainterPath cachedPortPath;
159  void updateCachedPortPath();
160 
161  static QRectF getPortConstantTextRectForText(QString text);
162  static QPainterPath getPortPath(qreal inset, VuoPortClass::PortType portType, QString constantText, bool isInputPort, bool carriesData);
163  QRectF getEventBarrierRect(void) const;
164  virtual QPainterPath getWirelessAntennaPath() const;
165  bool hasConnectedWirelessDataCable(bool includePublishedCables) const;
166  bool hasConnectedWirelessEventCable(bool includePublishedCables) const;
168  qint64 getTimeOfLastActivity();
169 
170  void paintPortName(QPainter *painter, VuoRendererColors *colors);
171  void paintEventBarrier(QPainter *painter, VuoRendererColors *colors);
172  void paintActionIndicator(QPainter *painter, VuoRendererColors *colors);
173  void paintWirelessAntenna(QPainter *painter, VuoRendererColors *colors);
175  string getPointStringForCoords(QList<float>) const;
176 
178 };