mirror of https://gitlab.com/pamhyr/pamhyr2
network: Define edge shape.
parent
461f23058d
commit
33e752ad19
|
|
@ -110,7 +110,7 @@ class EdgeItem(QGraphicsItem):
|
|||
self.prepareGeometryChange()
|
||||
|
||||
def boundingRect(self):
|
||||
pen_width = 3.0
|
||||
pen_width = 2.0
|
||||
extra = (pen_width + 5) / 2.0
|
||||
|
||||
return QRectF(
|
||||
|
|
@ -121,12 +121,25 @@ class EdgeItem(QGraphicsItem):
|
|||
)
|
||||
).normalized().adjusted(-extra, -extra, extra, extra)
|
||||
|
||||
def shape(self):
|
||||
vec = self.dest_node.pos() - self.src_node.pos()
|
||||
vec = vec * (5 / math.sqrt(QPointF.dotProduct(vec, vec)))
|
||||
extra = QPointF(vec.y(), -vec.x())
|
||||
|
||||
result = QPainterPath(self.src_node.pos() - vec + extra)
|
||||
result.lineTo(self.src_node.pos() - vec - extra)
|
||||
result.lineTo(self.dest_node.pos() + vec - extra)
|
||||
result.lineTo(self.dest_node.pos() + vec + extra)
|
||||
result.closeSubpath()
|
||||
|
||||
return result
|
||||
|
||||
def paint(self, painter, option, widget):
|
||||
# color = QColor(Qt.white)
|
||||
# color.setAlpha(128)
|
||||
|
||||
# painter.setBrush(color)
|
||||
# painter.drawRect(self.boundingRect())
|
||||
# painter.drawPath(self.shape())
|
||||
|
||||
line = QLineF(self.src_node.pos(), self.dest_node.pos())
|
||||
if line.length() == 0.0:
|
||||
|
|
@ -564,10 +577,6 @@ class GraphWidget(QGraphicsView):
|
|||
self.scaleView(1 / 1.2)
|
||||
elif key == Qt.Key_Escape:
|
||||
self.reset_selection()
|
||||
elif key == Qt.Key_Space or key == Qt.Key_Enter:
|
||||
for item in self.scene().items():
|
||||
if isinstance(item, Node):
|
||||
item.setPos(-150 + qrand() % 300, -150 + qrand() % 300)
|
||||
else:
|
||||
super(GraphWidget, self).keyPressEvent(event)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue