network: Move on graph with mouse.

mesh
Pierre-Antoine Rouby 2023-03-29 13:47:48 +02:00
parent ee8492fcb5
commit c3e0593137
1 changed files with 17 additions and 1 deletions

View File

@ -256,6 +256,9 @@ class GraphWidget(QGraphicsView):
self.edge_items = []
self.texts = {}
self.m_origin_x = 0.0
self.m_origin_y = 0.0
scene = QGraphicsScene(self)
scene.setItemIndexMethod(QGraphicsScene.NoIndex)
scene.setSceneRect(0, 0, 2000, 2000)
@ -673,7 +676,20 @@ class GraphWidget(QGraphicsView):
self.tmp_line.dest = pos
self.tmp_line.update()
# If state is "move" propagate event
# If state is "move"
if self._state == "move":
# Move on scene
if (not self.selected_item() and
event.buttons() & Qt.LeftButton):
old_p = self.mapToScene(self.m_origin_x, self.m_origin_y)
new_p = self.mapToScene(event.pos())
translation = new_p - old_p
self.translate(translation.x(), translation.y())
self.m_origin_x = event.x()
self.m_origin_y = event.y()
# Propagate event
self.update()
super(GraphWidget, self).mouseMoveEvent(event)