Commit 33e752ad authored by Pierre-Antoine Rouby's avatar Pierre-Antoine Rouby
Browse files

network: Define edge shape.

Showing with 15 additions and 6 deletions
+15 -6
...@@ -110,7 +110,7 @@ class EdgeItem(QGraphicsItem): ...@@ -110,7 +110,7 @@ class EdgeItem(QGraphicsItem):
self.prepareGeometryChange() self.prepareGeometryChange()
def boundingRect(self): def boundingRect(self):
pen_width = 3.0 pen_width = 2.0
extra = (pen_width + 5) / 2.0 extra = (pen_width + 5) / 2.0
return QRectF( return QRectF(
...@@ -121,12 +121,25 @@ class EdgeItem(QGraphicsItem): ...@@ -121,12 +121,25 @@ class EdgeItem(QGraphicsItem):
) )
).normalized().adjusted(-extra, -extra, extra, extra) ).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): def paint(self, painter, option, widget):
# color = QColor(Qt.white) # color = QColor(Qt.white)
# color.setAlpha(128) # color.setAlpha(128)
# painter.setBrush(color) # painter.setBrush(color)
# painter.drawRect(self.boundingRect()) # painter.drawPath(self.shape())
line = QLineF(self.src_node.pos(), self.dest_node.pos()) line = QLineF(self.src_node.pos(), self.dest_node.pos())
if line.length() == 0.0: if line.length() == 0.0:
...@@ -564,10 +577,6 @@ class GraphWidget(QGraphicsView): ...@@ -564,10 +577,6 @@ class GraphWidget(QGraphicsView):
self.scaleView(1 / 1.2) self.scaleView(1 / 1.2)
elif key == Qt.Key_Escape: elif key == Qt.Key_Escape:
self.reset_selection() 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: else:
super(GraphWidget, self).keyPressEvent(event) super(GraphWidget, self).keyPressEvent(event)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment