Commit 4e1b3b94 authored by Pierre-Antoine Rouby's avatar Pierre-Antoine Rouby
Browse files

network: Minor change.

Showing with 14 additions and 11 deletions
+14 -11
......@@ -129,10 +129,10 @@ class EdgeItem(QGraphicsItem):
# painter.drawRect(self.boundingRect())
line = QLineF(self.src_node.pos(), self.dest_node.pos())
if line.length() == 0.0:
return
# Select color
color = Qt.blue
if self.graph.selected_item() == self:
color = Qt.red
......@@ -143,6 +143,7 @@ class EdgeItem(QGraphicsItem):
painter.setPen(QPen(color, 3, Qt.SolidLine, Qt.RoundCap,
Qt.RoundJoin))
# Draw the line
painter.drawLine(line)
line_center = QPointF(
......@@ -150,7 +151,7 @@ class EdgeItem(QGraphicsItem):
(self.src_node.pos().y() + self.dest_node.pos().y()) / 2,
)
# Draw the arrows if there's enough room.
# Draw the arrows
angle = math.acos(line.dx() / line.length())
if line.dy() >= 0:
angle = (math.pi * 2.0) - angle
......@@ -174,27 +175,28 @@ class NodeText(QGraphicsTextItem):
self.item = node_item
self.setPlainText(self.item.node.name)
self.setDefaultTextColor(Qt.black)
#self.setPos(self.item.pos())
self.set_custom_pos(self.item.pos())
self.setZValue(2)
def set_custom_pos(self, pos):
x = pos.x()
y = pos.y() - 42
y = pos.y() - 42 # Dont panic! The answer is 42
self.setPos(QPointF(x,y))
def paint(self, painter, option, widget):
color = QColor(Qt.white)
color.setAlpha(128)
# Draw text background
painter.setBrush(color)
painter.drawRect(self.boundingRect())
# Draw text
super(NodeText, self).paint(painter, option, widget)
def rename(self):
# Update the node text
self.setPlainText(self.item.node.name)
class NewEdgeLine(QGraphicsItem):
......@@ -349,7 +351,7 @@ class GraphWidget(QGraphicsView):
)
)
self.setSelectedItem(None)
self.set_selected_item(None)
for edge in edges:
self.graph.remove_edge(edge.edge.name)
......@@ -394,7 +396,7 @@ class GraphWidget(QGraphicsView):
return
edge = self.graph.add_edge(node1.node, node2.node)
self.setSelectedItem(None)
self.set_selected_item(None)
self.setSelectedNewEdgeSrcNode(None)
# Reset the temporary line
self.tmp_line = None
......@@ -466,7 +468,7 @@ class GraphWidget(QGraphicsView):
"""
return self._selected_item
def setSelectedItem(self, item):
def set_selected_item(self, item):
"""Set current selected item
Args:
......@@ -636,6 +638,8 @@ class GraphWidget(QGraphicsView):
def mouseMoveEvent(self, event):
pos = self.mapToScene(event.pos())
# Selecte item on the fly
items = self.items(event.pos())
selectable_items = list(
filter(
......@@ -644,11 +648,10 @@ class GraphWidget(QGraphicsView):
)
)
# Selecte item on the fly
if selectable_items:
self.setSelectedItem(selectable_items[0])
self.set_selected_item(selectable_items[0])
else:
self.setSelectedItem(None)
self.set_selected_item(None)
# Update temporary line
if self.selected_new_edge_src_node() is not None:
......
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