11 :synopsis: Repackaging of the limiting ROS qt_dotgraph.edge_item module.
13 Oh my spaghettified magnificence,
14 Bless my noggin with a tickle from your noodly appendages!
22 from python_qt_binding.QtCore
import QPointF, Qt
23 from python_qt_binding.QtGui
import QBrush, QPainterPath, QPen, QPolygonF
25 from python_qt_binding.QtGui
import QGraphicsPathItem, QGraphicsPolygonItem, QGraphicsSimpleTextItem
27 from python_qt_binding.QtWidgets
import QGraphicsPathItem, QGraphicsPolygonItem, QGraphicsSimpleTextItem
29 from .graph_item
import GraphItem
39 'dashed': Qt.DashLine,
41 'solid': Qt.SolidLine,
44 def __init__(self, highlight_level, spline, label_center, label, from_node, to_node, parent=None, penwidth=1, edge_color=None, style='solid'):
45 super(EdgeItem, self).
__init__(highlight_level, parent)
50 self.
to_node.add_incoming_edge(self)
54 if edge_color
is not None:
62 if style
in [
'dashed',
'dotted']:
75 self.
_label = QGraphicsSimpleTextItem(label)
76 label_rect = self.
_label.boundingRect()
77 label_rect.moveCenter(label_center)
78 self.
_label.setPos(label_rect.x(), label_rect.y())
81 self.
_label.setAcceptHoverEvents(
True)
84 coordinates = spline.split(
' ')
87 if (coordinates[0].startswith(
'e,')):
88 parts = coordinates.pop(0)[2:].split(
',')
89 end_point = QPointF(float(parts[0]), -float(parts[1]))
91 if (coordinates[0].startswith(
's,')):
92 parts = coordinates.pop(0).split(
',')
95 parts = coordinates.pop(0).split(
',')
96 point = QPointF(float(parts[0]), -float(parts[1]))
97 path = QPainterPath(point)
99 while len(coordinates) > 2:
101 parts = coordinates.pop(0).split(
',')
102 point1 = QPointF(float(parts[0]), -float(parts[1]))
103 parts = coordinates.pop(0).split(
',')
104 point2 = QPointF(float(parts[0]), -float(parts[1]))
105 parts = coordinates.pop(0).split(
',')
106 point3 = QPointF(float(parts[0]), -float(parts[1]))
107 path.cubicTo(point1, point2, point3)
110 if end_point
is not None:
112 self.
_arrow = QGraphicsPolygonItem()
113 polygon = QPolygonF()
114 polygon.append(point3)
115 offset = QPointF(end_point - point3)
116 corner1 = QPointF(-offset.y(), offset.x()) * 0.35
117 corner2 = QPointF(offset.y(), -offset.x()) * 0.35
118 polygon.append(point3 + corner1)
119 polygon.append(end_point)
120 polygon.append(point3 + corner2)
121 self.
_arrow.setPolygon(polygon)
124 self.
_arrow.setAcceptHoverEvents(
True)
127 self.
_path.setPath(path)
128 self.addToGroup(self.
_path)
135 if self.
_label is not None:
136 scene.addItem(self.
_label)
137 if self.
_arrow is not None:
138 scene.addItem(self.
_arrow)
142 if self.
_label is not None:
144 if self.
_arrow is not None:
165 if self.
_arrow is not None:
175 if self.
_label is not None:
205 sibling_edge.set_node_color()