From 4dddf2ef4e3a876551cf3f9d900586952928a063 Mon Sep 17 00:00:00 2001 From: Nikita Zlobin Date: Thu, 7 Jun 2018 04:35:59 +0500 Subject: [PATCH] Better code to calculate connection line coordinates --- source/patchcanvas.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/source/patchcanvas.py b/source/patchcanvas.py index 61c25d637..b598c22e0 100644 --- a/source/patchcanvas.py +++ b/source/patchcanvas.py @@ -1546,10 +1546,12 @@ class CanvasLine(QGraphicsLineItem): def updateLinePos(self): if self.item1.getPortMode() == PORT_MODE_OUTPUT: - line = QLineF(self.item1.scenePos().x() + self.item1.getPortWidth() + 12, - self.item1.scenePos().y() + float(canvas.theme.port_height)/2, - self.item2.scenePos().x(), - self.item2.scenePos().y() + float(canvas.theme.port_height)/2) + rect1 = self.item1.sceneBoundingRect() + rect2 = self.item2.sceneBoundingRect() + line = QLineF(rect1.right(), + rect1.top() + float(canvas.theme.port_height)/2, + rect2.left(), + rect2.top() + float(canvas.theme.port_height)/2) self.setLine(line) self.m_lineSelected = False @@ -1645,17 +1647,15 @@ class CanvasBezierLine(QGraphicsPathItem): def updateLinePos(self): if self.item1.getPortMode() == PORT_MODE_OUTPUT: - item1_x = self.item1.scenePos().x() + self.item1.getPortWidth() + 12 - item1_y = self.item1.scenePos().y() + float(canvas.theme.port_height)/2 - - item2_x = self.item2.scenePos().x() - item2_y = self.item2.scenePos().y() + float(canvas.theme.port_height)/2 - - item1_mid_x = abs(item1_x - item2_x) / 2 - item1_new_x = item1_x + item1_mid_x - - item2_mid_x = abs(item1_x - item2_x) / 2 - item2_new_x = item2_x - item2_mid_x + rect1 = self.item1.sceneBoundingRect() + rect2 = self.item2.sceneBoundingRect() + + item1_x = rect1.right() + item2_x = rect2.left() + item1_y = rect1.top() + float(canvas.theme.port_height)/2 + item2_y = rect2.top() + float(canvas.theme.port_height)/2 + item1_new_x = item1_x + abs(item1_x - item2_x) / 2 + item2_new_x = item2_x - abs(item1_x - item2_x) / 2 path = QPainterPath(QPointF(item1_x, item1_y)) path.cubicTo(item1_new_x, item1_y, item2_new_x, item2_y, item2_x, item2_y)