Exemplo n.º 1
0
 def mousePressEvent(self, evt: QGraphicsSceneMouseEvent):
     if evt.button() == Qt.LeftButton:
         pos = (evt.scenePos().x(), evt.scenePos().y())
         self.relative_pos = (pos[0] - self.x(), pos[1] - self.y())
         if not evt.modifiers() == Qt.ControlModifier:
             self.scene().signal_clear_selection.emit()
         self.scene().select_item(self)
         self.color = COLOR_SELECTED
     elif evt.button() == Qt.RightButton:
         pass
     elif evt.button() == Qt.MidButton:
         pass
Exemplo n.º 2
0
    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