Vuo  2.1.0
VuoRendererValueListForReadOnlyDictionary.cc
Go to the documentation of this file.
1 
14 #include "VuoNodeClass.hh"
15 #include "VuoPort.hh"
16 #include "VuoRendererPort.hh"
17 
23  : VuoRendererInputDrawer(baseNode, signaler)
24 {
25  VuoNode *makeKeyListNode = getKeyListNode();
26  vector<VuoPort *> makeKeyListNodeInputs;
27  if (makeKeyListNode)
28  makeKeyListNodeInputs = makeKeyListNode->getInputPorts();
29 
30  vector<VuoPort *> inputPorts = this->getBase()->getInputPorts();
31  for (int i = VuoNodeClass::unreservedInputPortStartIndex; i < inputPorts.size(); ++i)
32  {
33  string keyName = " ";
34  if (i < makeKeyListNodeInputs.size())
35  {
36  VuoCompilerInputEventPort *keyPort= static_cast<VuoCompilerInputEventPort *>(makeKeyListNodeInputs[i]->getCompiler());
37  keyName = keyPort->getData()->getInitialValue();
38  }
39 
40  inputPorts[i]->getRenderer()->setPortNameToRender(getRenderedPortNameFormForText(keyName));
41  }
42 }
43 
49 string VuoRendererValueListForReadOnlyDictionary::getRenderedPortNameFormForText(string text)
50 {
51  json_object *js = json_tokener_parse(text.c_str());
52  string textWithoutQuotes;
53  if (json_object_get_type(js) == json_type_string)
54  textWithoutQuotes = json_object_get_string(js);
55  json_object_put(js);
56 
57  return textWithoutQuotes;
58 }
59 
64 void VuoRendererValueListForReadOnlyDictionary::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
65 {
66  if (!isSelected())
67  {
68  VuoNode *renderedHostNode = getRenderedHostNode();
69  if (renderedHostNode && renderedHostNode->hasRenderer() && renderedHostNode->getRenderer()->isSelected())
70  this->setSelected(true);
71 
72  else
73  {
74  set<VuoNode *> coattachments = getCoattachments();
75  foreach (VuoNode *coattachment, coattachments)
76  {
77  if (coattachment->hasRenderer() && coattachment->getRenderer()->isSelected())
78  {
79  this->setSelected(true);
80  break;
81  }
82  }
83  }
84  }
85 
86  drawBoundingRect(painter);
87 
88  VuoRendererColors::SelectionType selectionType = (isSelected()? VuoRendererColors::directSelection : VuoRendererColors::noSelection);
89  qint64 timeOfLastActivity = (getRenderActivity()? timeLastExecutionEnded : VuoRendererItem::notTrackingActivity);
90  VuoRendererColors *drawerColors = new VuoRendererColors(getBase()->getTintColor(),
91  selectionType,
92  false,
94  timeOfLastActivity);
95 
96 
97  // Drawer frame
98  painter->fillPath(getDrawerPath(false), drawerColors->nodeFill());
99 
100  // Child input ports
101  layoutPorts();
102 
103  delete drawerColors;
104 }
105 
110 {
111  QRectF r = getDrawerPath(false).boundingRect();
112 
113  // Antialiasing bleed
114  r.adjust(-1,-1,1,1);
115 
116  return r.toAlignedRect();
117 }
118 
124 {
125  QPainterPath p;
126  p.addPath(getDrawerPath(false));
127 
128  return p;
129 }
130 
137 {
139  return false;
140 
141  VuoPort *hostPort = getUnderlyingHostPortForNode(baseNode);
142  VuoNode *hostNode = getUnderlyingHostNodeForNode(baseNode);
143  bool providesValuesToMakeReadOnlyDictionaryNode = (hostPort &&
144  (hostPort->getClass()->getName() == "values") &&
146  return providesValuesToMakeReadOnlyDictionaryNode;
147 }
148 
154 {
155  VuoNode *hostNode = getUnderlyingHostNode();
156  if (!hostNode)
157  return NULL;
158 
159  VuoPort *keyListInputPort = hostNode->getInputPortWithName("keys");
160  return getListNodeConnectedToInputPort(keyListInputPort);
161 }
162 
167 {
168  // The port that will ultimately make use of this node's output values is two nodes downstream.
170 }
171 
176 {
177  // The node that will ultimately make use of this node's output values is two nodes downstream.
179 }
180 
185 {
186  return getDrawerPath(false).boundingRect();
187 }
188 
195 {
196  VuoNode *dictionaryNode = getUnderlyingHostNode();
197  VuoNode *keyListNode = getKeyListNode();
198 
199  set<VuoNode *> coattachments;
200  if (dictionaryNode)
201  coattachments.insert(dictionaryNode);
202  if (keyListNode)
203  coattachments.insert(keyListNode);
204  return coattachments;
205 }