Vuo  2.3.2
VuoRendererInputDrawer.cc
Go to the documentation of this file.
1 
11 #include "VuoRendererFonts.hh"
13 #include "VuoNodeClass.hh"
14 #include "VuoPort.hh"
15 
16 const qreal VuoRendererInputDrawer::drawerInteriorHorizontalPadding = 20; // VuoRendererFonts::thickPenWidth*3./4.+5
17 const qreal VuoRendererInputDrawer::drawerHorizontalSpacing = 2; // VuoRendererFonts::thickPenWidth*2./20.
18 
23  : VuoRendererInputAttachment(baseNode, signaler)
24 {
25  vector<VuoPort *> inputPorts = this->getBase()->getInputPorts();
26  for (int i = VuoNodeClass::unreservedInputPortStartIndex; i < inputPorts.size(); ++i)
27  drawerPorts.push_back(inputPorts[i]->getRenderer());
28 
31 
32  layoutPorts();
33 }
34 
39 {
40  this->horizontalDrawerOffset = offset;
41 }
42 
47 {
48  qreal maxLabelWidth = 0;
49  foreach (VuoRendererPort *port, drawerPorts)
50  {
51  string portTitle = port->getPortNameToRender();
52  qreal labelWidth = VuoRendererPort::getTextWidth(QString::fromUtf8(portTitle.c_str()));
53 
54  if (labelWidth > maxLabelWidth)
55  maxLabelWidth = labelWidth;
56  }
57 
58  return maxLabelWidth + drawerInteriorHorizontalPadding;
59 }
60 
67 {
68  qreal maxPortWidth = -10;
69  foreach (VuoRendererPort *port, drawerPorts)
70  {
71  qreal portWidth = port->boundingRect().width() - VuoRendererPort::portRadius*2;
72 
73  // Accommodate the width of any collapsed typecast attached to the child port.
74  if (dynamic_cast<VuoRendererTypecastPort *>(port->getBase()->getRenderer()))
75  {
77  portWidth = tp->getPortPath(true, true).boundingRect().width() + VuoRendererPort::portRadius*3 + 5;
78  }
79  else if (!port->getBase()->getConnectedCables(true).empty()) // Leave room for the cable's rounded corner.
80  portWidth += VuoRendererPort::portRadius + 3;
81 
82  if (portWidth > maxPortWidth)
83  maxPortWidth = portWidth;
84  }
85 
87 }
88 
93 {
94  unsigned int i = 0;
95  for (vector<VuoRendererPort *>::iterator it = inputPorts.begin(); it != inputPorts.end(); ++it, ++i)
96  {
97  VuoRendererPort *p = *it;
98 
100  p->setVisible(false);
101 
102  else
103  {
104  p->setVisible(true);
105  int adjustedPortIndex = i-VuoNodeClass::unreservedInputPortStartIndex;
106  qreal portPointY = adjustedPortIndex*VuoRendererPort::portSpacing - .15;
107  p->setPos(QPointF(0,portPointY));
108 
109  VuoRendererTypecastPort *tp = dynamic_cast<VuoRendererTypecastPort *>(p);
110  if (tp)
111  tp->getChildPort()->setPos(QPointF(-tp->getChildPortXOffset(),portPointY));
112  }
113  }
114 
115  // Do not display output ports.
116  for (vector<VuoRendererPort *>::iterator it = outputPorts.begin(); it != outputPorts.end(); ++it)
117  (*it)->setVisible(false);
118 }
119 
123 vector<VuoRendererPort *> VuoRendererInputDrawer::getDrawerPorts(void) const
124 {
125  return drawerPorts;
126 }
127 
131 QPainterPath VuoRendererInputDrawer::getDrawerPath(bool includeDragHandle) const
132 {
133  QRectF hostPortRect = VuoRendererPort::getPortRect();
134  qreal drawerBottomExtensionWidth = qRound(getMaxDrawerLabelWidth());
135 
136  QPainterPath p;
137 
138  // Arm right edge (hide behind the parent port)
139  p.moveTo(horizontalDrawerOffset, -0.5*hostPortRect.height() + 1);
140  p.lineTo(horizontalDrawerOffset, 0.5*hostPortRect.height() - 2);
141 
142  // Arm bottom edge
143  p.lineTo(drawerBottomExtensionWidth, 0.5*hostPortRect.height() - 2);
144 
145  // Right drawer wall
146  qreal adjustedPortRadius = VuoRendererPort::portRadius - 2;
147  qreal drawerBottomExtensionHeight = this->drawerBottomExtensionHeight + (includeDragHandle ? adjustedPortRadius : 0);
149  addRoundedCorner(p, true, QPointF(drawerBottomExtensionWidth, 0.5*hostPortRect.height() + 1 + drawerBottomExtensionHeight - 3), adjustedPortRadius, false, false);
150 
151  // Far drawer bottom
152  addRoundedCorner(p, true, QPointF(hostPortRect.width()/2 - 1, 0.5*hostPortRect.height() + 1 + drawerBottomExtensionHeight - 3), adjustedPortRadius, false, true);
153 
154  // Drawer top left
155  addRoundedCorner(p, true, QPointF(hostPortRect.width()/2 - 1, -0.5*hostPortRect.height() + 1), adjustedPortRadius, true, true);
156 
157  return p;
158 }