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)
48 self.from_node.add_outgoing_edge(self)
50 self.to_node.add_incoming_edge(self)
54 if edge_color
is not None:
62 if style
in [
'dashed',
'dotted']:
66 self._label_pen.setJoinStyle(Qt.RoundJoin)
68 self._edge_pen.setWidth(penwidth)
70 self._edge_pen.setStyle(self._qt_pen_styles.get(style, Qt.SolidLine))
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:
143 self._label.setToolTip(tool_tip)
144 if self.
_arrow is not None:
145 self._arrow.setToolTip(tool_tip)
148 self._sibling_edges.add(edge)
154 if self._shape_brush.isOpaque():
158 self._label_pen.setColor(color)
159 self._text_brush.setColor(color)
160 if self._shape_brush.isOpaque():
161 self._shape_brush.setColor(color)
162 self._edge_pen.setColor(color)
165 if self.
_arrow is not None:
173 self._label_pen.setColor(color)
175 if self.
_label is not None:
183 if self._highlight_level > 1:
186 self.from_node.set_node_color(self._COLOR_BLUE)
188 self.to_node.set_node_color(self._COLOR_GREEN)
191 self.from_node.set_node_color(self._COLOR_TEAL)
192 self.to_node.set_node_color(self._COLOR_TEAL)
193 if self._highlight_level > 2:
196 sibling_edge.set_node_color(self._COLOR_ORANGE)
200 if self._highlight_level > 1:
201 self.from_node.set_node_color()
202 self.to_node.set_node_color()
203 if self._highlight_level > 2:
205 sibling_edge.set_node_color()
def set_node_color(self, color=None)
def add_to_scene(self, scene)
def __init__(self, highlight_level, spline, label_center, label, from_node, to_node, parent=None, penwidth=1, edge_color=None, style='solid')
def set_label_color(self, color=None)
def setToolTip(self, tool_tip)
def _handle_hoverEnterEvent(self, event)
def add_sibling_edge(self, edge)
def _handle_hoverLeaveEvent(self, event)