def mouseMoveEvent(self, event):
        if not self.gesture_active:

            if self.proxy.edgeEditMode == EdgeEditMode.MODE_EDGE_DRAG:
                pos = self.mapToScene(event.pos())
                self.proxy.updatePoseEdgeDrag(Point2D(x=pos.x(), y=pos.y()))

            if self.proxy.edgeEditMode == EdgeEditMode.MODE_EDGE_CUT:
                pos = self.mapToScene(event.pos())
                # self.cutline.line_points.append(pos)
                # self.cutline.update()

            point = self.mapToScene(event.pos())
            self.proxy.lastSceneMousePosition = Point2D(x=point.x(), y=point.y())

            self.proxy.scenePosChanged(Point2D(x=point.x(), y=point.y()))

        super().mouseMoveEvent(event)
Exemple #2
0
    def deserialize_graph(self, G, replace=True):
        if 'viewport_transform' in G.graph:
            self.view.setViewportTransform(
                Transform2D.from_list(G.graph['viewport_transform']))

        for node_id in G.nodes.keys():
            data = G.nodes[node_id]
            type_name = data.get('type_name', None)
            if type_name is None:
                log.error("Invalid Node (missing type_name): %s" % node_id)
                continue

            position = Point2D.from_list(data['position'])
            name = data['name']

            n = self.create_node(type_name,
                                 id=node_id,
                                 name=name,
                                 position=position)
            if n.model is not None:
                n.model.deserialize(data)

        for start_node_id, end_node_id, key, edge_id in G.edges(data='id',
                                                                keys=True):
            data = G.edges[start_node_id, end_node_id, key]
            type_name = data.get('type_name', None)
            if type_name is None:
                log.error("Invalid Edge (missing type_name): %s" % edge_id)
                continue

            source_socket_name = data['source_socket']
            target_socket_name = data['target_socket']
            source_socket = None
            target_socket = None
            for socket in self.view.scene.nodes[start_node_id].output_sockets:
                if socket.name == source_socket_name:
                    source_socket = socket
                    break
            for socket in self.view.scene.nodes[end_node_id].input_sockets:
                if socket.name == target_socket_name:
                    target_socket = socket
                    break
            if source_socket is None or target_socket is None:
                log.error("Invalid edge - missing socket: %s" % edge_id)
                continue

            e = self.create_edge(type_name, id=edge_id)
            e.start_socket = source_socket
            e.end_socket = target_socket

            if e.model is not None:
                e.model.deserialize(data)

            self.edge_connected(edge_id)
    def compute_socket_position(self):
        self._guard |= SOCKET_COMPUTE_HEIGHT_GUARD
        result = Point2D(x=0, y=0)
        from .node_item import NodeItem
        node = self.parent
        if isinstance(node, NodeItem):
            x = 0 if (self.socket_position
                      in (SocketPosition.LEFT_TOP,
                          SocketPosition.LEFT_BOTTOM)) else node.width

            if self.socket_position in (SocketPosition.LEFT_BOTTOM,
                                        SocketPosition.RIGHT_BOTTOM):
                # start from bottom
                y = node.height - node.edge_size - node.padding - self.index * self.socket_spacing
            else:
                # start from top
                y = node.title_height + node.padding + node.edge_size + self.index * self.socket_spacing

            result = Point2D(x=x, y=y)

        self._guard &= ~SOCKET_COMPUTE_HEIGHT_GUARD
        return result
    def leftMouseButtonPress(self, event):
        # get item which we clicked on
        item = self.getItemAtClick(event)

        # we store the position of last LMB click
        point = self.mapToScene(event.pos())
        self.proxy.lastLmbClickScenePos = Point2D(x=point.x(), y=point.y())

        # logic
        if isinstance(item, QNodeItem) or isinstance(item, QEdgeItem) or item is None:
            if event.modifiers() & QtCore.Qt.ShiftModifier:
                event.ignore()
                fake_event = QtGui.QMouseEvent(QtCore.QEvent.MouseButtonPress,
                                               event.localPos(),
                                               event.screenPos(),
                                               QtCore.Qt.LeftButton,
                                               event.buttons() | QtCore.Qt.LeftButton,
                                               event.modifiers() | QtCore.Qt.ControlModifier)
                super().mousePressEvent(fake_event)
                return

        if isinstance(item, QNodeSocket):
            if self.proxy.edgeEditMode == EdgeEditMode.MODE_NOOP:
                self.proxy.edgeEditMode = EdgeEditMode.MODE_EDGE_DRAG
                self.proxy.edgeDragStart(item.proxy if item is not None else None)
                return

        if self.proxy.edgeEditMode == EdgeEditMode.MODE_EDGE_DRAG:
            res = self.proxy.edgeDragEnd(item)
            self.proxy.edgeEditMode = EdgeEditMode.MODE_NOOP
            if res:
                return

        if item is None:
            if event.modifiers() & QtCore.Qt.ControlModifier:
                self.proxy.edgeEditMode = EdgeEditMode.MODE_EDGE_CUT
                fake_event = QtGui.QMouseEvent(QtCore.QEvent.MouseButtonRelease,
                                               event.localPos(),
                                               event.screenPos(),
                                               QtCore.Qt.LeftButton,
                                               QtCore.Qt.NoButton,
                                               event.modifiers())
                super().mouseReleaseEvent(fake_event)
                QtWidgets.QApplication.setOverrideCursor(QtCore.Qt.CrossCursor)
                return
            else:
                self.proxy.rubberBandDraggingRectangle = True

        super().mousePressEvent(event)
 def _default_position(self):
     return Point2D(x=0, y=0)
 def itemChange(self, change, value):
     if change == QGraphicsItem.ItemPositionHasChanged:
         self.proxy.position = Point2D(x=value.x(), y=value.y())
     return super(QNodeItem, self).itemChange(change, value)
 def _default_pos_destination(self):
     if self.end_socket is not None:
         return self.end_socket.absolute_position
     return Point2D(x=0, y=0)
 def _default_pos_source(self):
     if self.start_socket is not None:
         return self.start_socket.absolute_position
     return Point2D(x=0, y=0)