Skip to content

Commit 1a7153e

Browse files
authored
Merge pull request #134 from nallath/add_angled_pipe_layout
Add an angled variant to the pipe draw
2 parents 852d599 + 4c27d61 commit 1a7153e

File tree

2 files changed

+38
-18
lines changed

2 files changed

+38
-18
lines changed

NodeGraphQt/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
PIPE_LAYOUT_STRAIGHT = 0
2222
#: The draw the connection pipes as curved lines.
2323
PIPE_LAYOUT_CURVED = 1
24+
#: The draw the connection pipes as angled lines.
25+
PIPE_LAYOUT_ANGLE = 2
2426

2527
# === PORT ===
2628

NodeGraphQt/qgraphics/pipe.py

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
PIPE_HIGHLIGHT_COLOR, PIPE_DISABLED_COLOR,
88
PIPE_STYLE_DASHED, PIPE_STYLE_DEFAULT, PIPE_STYLE_DOTTED,
99
PIPE_LAYOUT_STRAIGHT, PIPE_WIDTH, IN_PORT, OUT_PORT, Z_VAL_PIPE,
10-
Z_VAL_NODE_WIDGET
11-
)
10+
Z_VAL_NODE_WIDGET,
11+
PIPE_LAYOUT_ANGLE, PIPE_LAYOUT_CURVED)
1212
from NodeGraphQt.qgraphics.port import PortItem
1313

1414
PIPE_STYLES = {
@@ -163,25 +163,43 @@ def draw_path(self, start_port, end_port=None, cursor_pos=None):
163163
path.lineTo(pos2)
164164
self.setPath(path)
165165
return
166+
elif self.viewer_pipe_layout() == PIPE_LAYOUT_CURVED:
167+
ctr_offset_x1, ctr_offset_x2 = pos1.x(), pos2.x()
168+
tangent = ctr_offset_x1 - ctr_offset_x2
169+
tangent = (tangent * -1) if tangent < 0 else tangent
170+
171+
max_width = start_port.node.boundingRect().width() / 2
172+
tangent = max_width if tangent > max_width else tangent
173+
if start_port.port_type == IN_PORT:
174+
ctr_offset_x1 -= tangent
175+
ctr_offset_x2 += tangent
176+
else:
177+
ctr_offset_x1 += tangent
178+
ctr_offset_x2 -= tangent
166179

167-
ctr_offset_x1, ctr_offset_x2 = pos1.x(), pos2.x()
168-
tangent = ctr_offset_x1 - ctr_offset_x2
169-
tangent = (tangent * -1) if tangent < 0 else tangent
170-
171-
max_width = start_port.node.boundingRect().width() / 2
172-
tangent = max_width if tangent > max_width else tangent
180+
ctr_point1 = QtCore.QPointF(ctr_offset_x1, pos1.y())
181+
ctr_point2 = QtCore.QPointF(ctr_offset_x2, pos2.y())
182+
path.cubicTo(ctr_point1, ctr_point2, pos2)
183+
self.setPath(path)
184+
elif self.viewer_pipe_layout() == PIPE_LAYOUT_ANGLE:
185+
ctr_offset_x1, ctr_offset_x2 = pos1.x(), pos2.x()
186+
distance = ctr_offset_x1 - ctr_offset_x2
187+
distance = (distance * -1) if distance < 0 else distance
188+
distance /= 2
189+
if start_port.port_type == IN_PORT:
190+
ctr_offset_x1 -= distance
191+
ctr_offset_x2 += distance
192+
else:
193+
ctr_offset_x1 += distance
194+
ctr_offset_x2 -= distance
173195

174-
if start_port.port_type == IN_PORT:
175-
ctr_offset_x1 -= tangent
176-
ctr_offset_x2 += tangent
177-
else:
178-
ctr_offset_x1 += tangent
179-
ctr_offset_x2 -= tangent
196+
ctr_point1 = QtCore.QPointF(ctr_offset_x1, pos1.y())
197+
ctr_point2 = QtCore.QPointF(ctr_offset_x2, pos2.y())
198+
path.lineTo(ctr_point1)
199+
path.lineTo(ctr_point2)
200+
path.lineTo(pos2)
201+
self.setPath(path)
180202

181-
ctr_point1 = QtCore.QPointF(ctr_offset_x1, pos1.y())
182-
ctr_point2 = QtCore.QPointF(ctr_offset_x2, pos2.y())
183-
path.cubicTo(ctr_point1, ctr_point2, pos2)
184-
self.setPath(path)
185203

186204
def reset_path(self):
187205
path = QtGui.QPainterPath(QtCore.QPointF(0.0, 0.0))

0 commit comments

Comments
 (0)