Skip to content

Commit 75920cc

Browse files
committed
port output node updates.
1 parent 9a1e3bf commit 75920cc

File tree

1 file changed

+88
-4
lines changed

1 file changed

+88
-4
lines changed

NodeGraphQt/qgraphics/node_port_out.py

Lines changed: 88 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from Qt import QtCore, QtGui, QtWidgets
33

44
from NodeGraphQt.constants import (NODE_SEL_BORDER_COLOR, NODE_SEL_COLOR)
5-
from NodeGraphQt.qgraphics.node_base import NodeItem
5+
from NodeGraphQt.qgraphics.node_base import NodeItem, NodeItemVertical
66

77

88
class PortOutputNodeItem(NodeItem):
@@ -127,7 +127,7 @@ def set_proxy_mode(self, mode):
127127

128128
def align_label(self, h_offset=0.0, v_offset=0.0):
129129
"""
130-
Center node label text to the top of the node.
130+
Center node label text to the center of the node.
131131
132132
Args:
133133
v_offset (float): vertical offset.
@@ -168,7 +168,7 @@ def draw_node(self):
168168

169169
# align label text
170170
self.align_label()
171-
# arrange icon
171+
# align icon
172172
self.align_icon()
173173
# arrange input and output ports.
174174
self.align_ports()
@@ -181,4 +181,88 @@ def draw_node(self):
181181
class PortOutputNodeVerticalItem(PortOutputNodeItem):
182182

183183
def paint(self, painter, option, widget):
184-
super(PortOutputNodeVerticalItem, self).paint(painter, option, widget)
184+
"""
185+
Draws the node base not the ports or text.
186+
187+
Args:
188+
painter (QtGui.QPainter): painter used for drawing the item.
189+
option (QtGui.QStyleOptionGraphicsItem):
190+
used to describe the parameters needed to draw.
191+
widget (QtWidgets.QWidget): not used.
192+
"""
193+
self.auto_switch_mode()
194+
195+
painter.save()
196+
painter.setBrush(QtCore.Qt.NoBrush)
197+
painter.setPen(QtCore.Qt.NoPen)
198+
199+
margin = 2.0
200+
rect = self.boundingRect()
201+
rect = QtCore.QRectF(rect.left() + margin,
202+
rect.top() + margin,
203+
rect.width() - (margin * 2),
204+
rect.height() - (margin * 2))
205+
206+
text_rect = self._text_item.boundingRect()
207+
text_rect = QtCore.QRectF(
208+
rect.center().x() - (text_rect.width() / 2) - 5,
209+
rect.height() - text_rect.height(),
210+
text_rect.width() + 10,
211+
text_rect.height()
212+
)
213+
214+
painter.setBrush(QtGui.QColor(255, 255, 255, 20))
215+
painter.drawRoundedRect(rect, 20, 20)
216+
217+
painter.setBrush(QtGui.QColor(0, 0, 0, 100))
218+
painter.drawRoundedRect(text_rect, 3, 3)
219+
220+
size = int(rect.height() / 4)
221+
triangle = QtGui.QPolygonF()
222+
triangle.append(QtCore.QPointF(-size, size))
223+
triangle.append(QtCore.QPointF(0.0, 0.0))
224+
triangle.append(QtCore.QPointF(size, size))
225+
226+
transform = QtGui.QTransform()
227+
transform.translate(rect.center().x(), rect.y() + (size / 3))
228+
# transform.rotate(-90)
229+
poly = transform.map(triangle)
230+
231+
if self.selected:
232+
pen = QtGui.QPen(QtGui.QColor(*NODE_SEL_BORDER_COLOR), 1.3)
233+
painter.setBrush(QtGui.QColor(*NODE_SEL_COLOR))
234+
else:
235+
pen = QtGui.QPen(QtGui.QColor(*self.border_color), 1.2)
236+
painter.setBrush(QtGui.QColor(0, 0, 0, 50))
237+
238+
pen.setJoinStyle(QtCore.Qt.MiterJoin)
239+
painter.setPen(pen)
240+
painter.drawPolygon(poly)
241+
242+
edge_size = 30
243+
edge_rect = QtCore.QRectF(rect.center().x() - (edge_size / 2),
244+
rect.y() + (size * 1.6),
245+
edge_size, 4)
246+
painter.drawRect(edge_rect)
247+
248+
painter.restore()
249+
250+
def align_label(self, h_offset=0.0, v_offset=0.0):
251+
"""
252+
Center node label text to the center of the node.
253+
254+
Args:
255+
v_offset (float): vertical offset.
256+
h_offset (float): horizontal offset.
257+
"""
258+
rect = self.boundingRect()
259+
text_rect = self._text_item.boundingRect()
260+
x = rect.center().x() - (text_rect.width() / 2)
261+
y = rect.height() - text_rect.height() - 4.0
262+
self._text_item.setPos(x + h_offset, y + v_offset)
263+
264+
def align_ports(self, v_offset=0.0):
265+
"""
266+
Align input, output ports in the node layout.
267+
"""
268+
NodeItemVertical.align_ports(self, v_offset=v_offset)

0 commit comments

Comments
 (0)