def mouseMoveEvent(self, event: QGraphicsSceneMouseEvent): """ mouseMoveEvent Parameters ---------- event : QGraphicsSceneMouseEvent """ geom = self._node.geometry state = self._node.state if state.resizing: diff = event.pos() - event.lastPos() w = self._node.model.embedded_widget() if w: self.prepareGeometryChange() old_size = w.size() + QSize(diff.x(), diff.y()) w.setFixedSize(old_size) old_size_f = QSizeF(old_size) self._proxy_widget.setMinimumSize(old_size_f) self._proxy_widget.setMaximumSize(old_size_f) self._proxy_widget.setPos(geom.widget_position) geom.recalculate_size() self.update() self.move_connections() event.accept() else: super().mouseMoveEvent(event) if event.lastPos() != event.pos(): self.move_connections() event.ignore() bounding = self.mapToScene(self.boundingRect()).boundingRect() r = self.scene().sceneRect().united(bounding) self.scene().setSceneRect(r)
def mousePressEvent(self, event: QGraphicsSceneMouseEvent): """ mousePressEvent Parameters ---------- event : QGraphicsSceneMouseEvent """ if self._locked: return # deselect all other items after self one is selected if not self.isSelected() and not (event.modifiers() & Qt.ControlModifier): self._scene.clearSelection() node_geometry = self._node.geometry for port_to_check in (PortType.input, PortType.output): # TODO do not pass sceneTransform port = node_geometry.check_hit_scene_point(port_to_check, event.scenePos(), self.sceneTransform()) if not port: continue connections = port.connections # start dragging existing connection if connections and port_to_check == PortType.input: conn, = connections interaction = NodeConnectionInteraction( self._node, conn, self._scene) interaction.disconnect(port_to_check) elif port_to_check == PortType.output: # initialize new Connection out_policy = port.connection_policy if connections and out_policy == ConnectionPolicy.one: conn, = connections self._scene.delete_connection(conn) # TODO_UPSTREAM: add to FlowScene connection = self._scene.create_connection(port) connection.graphics_object.grabMouse() pos = QPoint(event.pos().x(), event.pos().y()) geom = self._node.geometry state = self._node.state if self._node.model.resizable() and geom.resize_rect.contains(pos): state.resizing = True
def mouseMoveEvent(self, event: QGraphicsSceneMouseEvent): """ mouseMoveEvent Parameters ---------- event : QGraphicsSceneMouseEvent """ self.prepareGeometryChange() # view = event.widget() # TODO/BUG: widget is returning QWidget(), not QGraphicsView... view = self._scene.views()[0] node = self._scene.locate_node_at(event.scenePos(), view.transform()) self._connection.interact_with_node(node) state_required = self._connection.required_port if node: node.react_to_possible_connection( state_required, self._connection.data_type(opposite_port(state_required)), event.scenePos() ) # ------------------- offset = event.pos() - event.lastPos() required_port = self._connection.required_port if required_port != PortType.none: self._geometry.move_end_point(required_port, offset) # ------------------- self.update() event.accept()
def mouseMoveEvent(self, event: QGraphicsSceneMouseEvent): modifiers = QApplication.queryKeyboardModifiers() if modifiers == Qt.ControlModifier: if self.drag: point = event.pos() move_x = self.drag_start.x() - point.x() move_y = self.drag_start.y() - point.y() self.drag_start = point for key, val in self.appdata.project.maps[ self.name]["boxes"].items(): self.appdata.project.maps[self.name]["boxes"][key] = ( val[0] - move_x, val[1] - move_y) self.mapChanged.emit("dummy") self.update() else: if self.drag: self.setTransformationAnchor(QGraphicsView.AnchorUnderMouse) self.translate(1, 1) super(MapView, self).mouseMoveEvent(event)