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)
55 self.from_node.add_outgoing_edge(self)
57 self.to_node.add_incoming_edge(self)
60 if edge_color
is not None:
67 if style
in [
'dashed',
'dotted']:
71 self._label_pen.setJoinStyle(Qt.RoundJoin)
73 self._edge_pen.setWidth(penwidth)
75 self._edge_pen.setStyle(self._qt_pen_styles.get(style, Qt.SolidLine))
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)
132 self._arrow.setAcceptHoverEvents(
True)
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:
151 self._label.setToolTip(tool_tip)
152 if self.
_arrow is not None:
153 self._arrow.setToolTip(tool_tip)
156 self._sibling_edges.add(edge)
162 if self._shape_brush.isOpaque():
166 self._label_pen.setColor(color)
167 self._text_brush.setColor(color)
168 if self._shape_brush.isOpaque():
169 self._shape_brush.setColor(color)
170 self._edge_pen.setColor(color)
173 if self.
_arrow is not None:
181 self._label_pen.setColor(color)
183 if self.
_label is not None:
211 self.from_node.set_node_color()
212 self.to_node.set_node_color()
215 sibling_edge.set_node_color()
def add_sibling_edge(self, edge)
def __init__(self, highlight_level, spline, label_center, label, from_node, to_node, parent=None, penwidth=1, edge_color=None, style='solid')
def setToolTip(self, tool_tip)
def set_node_color(self, color=None)
def set_label_color(self, color=None)
def _handle_hoverEnterEvent(self, event)
def add_to_scene(self, scene)
def _handle_hoverLeaveEvent(self, event)