コード例 #1
0
    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()
コード例 #2
0
ファイル: flow_items.py プロジェクト: hzyrc6011/pmgwidgets
 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())
         self.port_clicked.emit(self)
     elif evt.button() == Qt.RightButton:
         pass
     elif evt.button() == Qt.MidButton:
         pass
コード例 #3
0
ファイル: flow_items.py プロジェクト: hzyrc6011/pmgwidgets
 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
コード例 #4
0
    def mouseMoveEvent(self, event: QGraphicsSceneMouseEvent) -> None:
        parent: QGraphicsItem = self.parentItem()
        center: QPointF = parent.scenePos()
        pos: QPointF = event.scenePos()

        dy = pos.y() - center.y()
        dx = pos.x() - center.x()
        angle = math.atan2(dy, dx)
        angle = Angle(rad=angle)

        self._setAngle(angle)
        self.events.angle.emit(angle)
コード例 #5
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
コード例 #6
0
    def mouseReleaseEvent(self, event: QGraphicsSceneMouseEvent):
        """
        mouseReleaseEvent

        Parameters
        ----------
        event : QGraphicsSceneMouseEvent
        """
        self.ungrabMouse()
        event.accept()
        node = self._scene.locate_node_at(event.scenePos(), self._scene.views()[0].transform())

        interaction = NodeConnectionInteraction(node, self._connection, self._scene)
        if node and interaction.try_connect():
            node.reset_reaction_to_connection()

        if self._connection.requires_port:
            self._scene.delete_connection(self._connection)
コード例 #7
0
ファイル: flow_items.py プロジェクト: hzyrc6011/pmgwidgets
 def mouseMoveEvent(self, event: QGraphicsSceneMouseEvent) -> None:
     self.setPos(
         round_position(
             QPointF(event.scenePos().x() - self.relative_pos[0],
                     event.scenePos().y() - self.relative_pos[1])))
     self.node.refresh_pos()