31 from python_qt_binding.QtCore
import QPointF, Qt
32 from python_qt_binding.QtGui
import QBrush, QPainterPath, QPen, QPolygonF
33 from python_qt_binding.QtWidgets
import (QGraphicsPathItem,
35 QGraphicsSimpleTextItem)
44 'dashed': Qt.DashLine,
46 'solid': Qt.SolidLine,
50 self, highlight_level, spline, label_center, label, from_node, to_node,
51 parent=None, penwidth=1, edge_color=None, style='solid'):
52 super(EdgeItem, self).
__init__(highlight_level, parent)
60 if edge_color
is not None:
67 if style
in [
'dashed',
'dotted']:
81 self.
_label = QGraphicsSimpleTextItem(label)
82 self.
_label.setFont(GraphItem._LABEL_FONT)
83 label_rect = self.
_label.boundingRect()
84 label_rect.moveCenter(label_center)
85 self.
_label.setPos(label_rect.x(), label_rect.y())
88 self.
_label.setAcceptHoverEvents(
True)
92 coordinates = spline.split(
' ')
95 if (coordinates[0].startswith(
'e,')):
96 parts = coordinates.pop(0)[2:].split(
',')
97 end_point = QPointF(float(parts[0]), -float(parts[1]))
99 if (coordinates[0].startswith(
's,')):
100 parts = coordinates.pop(0).split(
',')
103 parts = coordinates.pop(0).split(
',')
104 point = QPointF(float(parts[0]), -float(parts[1]))
105 path = QPainterPath(point)
107 while len(coordinates) > 2:
109 parts = coordinates.pop(0).split(
',')
110 point1 = QPointF(float(parts[0]), -float(parts[1]))
111 parts = coordinates.pop(0).split(
',')
112 point2 = QPointF(float(parts[0]), -float(parts[1]))
113 parts = coordinates.pop(0).split(
',')
114 point3 = QPointF(float(parts[0]), -float(parts[1]))
115 path.cubicTo(point1, point2, point3)
118 if end_point
is not None:
120 self.
_arrow = QGraphicsPolygonItem()
121 polygon = QPolygonF()
122 polygon.append(point3)
123 offset = QPointF(end_point - point3)
124 corner1 = QPointF(-offset.y(), offset.x()) * 0.35
125 corner2 = QPointF(offset.y(), -offset.x()) * 0.35
126 polygon.append(point3 + corner1)
127 polygon.append(end_point)
128 polygon.append(point3 + corner2)
129 self.
_arrow.setPolygon(polygon)
134 self.
_path = QGraphicsPathItem(parent)
135 self.
_path.setPath(path)
136 self.addToGroup(self.
_path)
143 if self.
_label is not None:
144 scene.addItem(self.
_label)
145 if self.
_arrow is not None:
146 scene.addItem(self.
_arrow)
150 if self.
_label is not None:
152 if self.
_arrow is not None:
173 if self.
_arrow is not None:
183 if self.
_label is not None:
215 sibling_edge.set_node_color()