コード例 #1
0
ファイル: properties.py プロジェクト: obdasystems/eddy
 def positionChanged(self):
     """
     Move the node properly if the position has been changed.
     :rtype: QUndoCommand
     """
     rect = self.diagram.sceneRect()
     xPos = clamp(self.xField.value(), rect.left(), rect.right())
     yPos = clamp(self.yField.value(), rect.top(), rect.bottom())
     pos1 = self.node.pos()
     pos2 = QtCore.QPointF(xPos, yPos)
     if pos1 != pos2:
         initData = self.diagram.setupMove([self.node])
         moveData = self.diagram.completeMove(initData, pos2 - pos1)
         return CommandNodeMove(self.diagram, initData, moveData)
     return None
コード例 #2
0
ファイル: view.py プロジェクト: sdash-redhat/eddy
    def keyPressEvent(self, keyEvent):
        """
        Executed when a combination of key is pressed.
        :type keyEvent: QKeyEvent
        """
        key = keyEvent.key()
        modifiers = keyEvent.modifiers()
        if self.diagram.mode is DiagramMode.Idle:

            if modifiers & QtCore.Qt.ControlModifier and \
                key in {QtCore.Qt.Key_Minus, QtCore.Qt.Key_Plus, QtCore.Qt.Key_0}:

                #############################################
                # ZOOM SHORTCUT
                #################################

                zoom = DiagramView.ZoomDefault
                if key in {QtCore.Qt.Key_Minus, QtCore.Qt.Key_Plus}:
                    zoom = self.zoom
                    zoom += +DiagramView.ZoomStep if key == QtCore.Qt.Key_Plus else -DiagramView.ZoomStep
                    zoom = clamp(zoom, DiagramView.ZoomMin,
                                 DiagramView.ZoomMax)

                if zoom != self.zoom:
                    self.scaleView(zoom)

            else:

                #############################################
                # NODE MOVEMENT
                #################################

                # NOTE: while usually node movement is handled in the Diagram class,
                # movements performed using the keyboard needs to be handled right here.
                # The reason behind is that keyboard arrows are used to scroll the DiagramView
                # viewport, we if we intercept the event in the Diagram class (by calling
                # super().keyPressEvent()) to perform the node move, we will also see the
                # viewport moving, and this is not the desired behavior. We intercept the
                # event here instead and perform the node move.

                selected = self.diagram.selectedNodes()
                if selected and key in {
                        QtCore.Qt.Key_Up, QtCore.Qt.Key_Down,
                        QtCore.Qt.Key_Left, QtCore.Qt.Key_Right
                }:
                    self.diagram.setMode(DiagramMode.NodeMove)
                    offset = QtCore.QPointF(0, 0)
                    if keyEvent.key() == QtCore.Qt.Key_Up:
                        offset += QtCore.QPointF(0, -Diagram.KeyMoveFactor)
                    if keyEvent.key() == QtCore.Qt.Key_Down:
                        offset += QtCore.QPointF(0, +Diagram.KeyMoveFactor)
                    if keyEvent.key() == QtCore.Qt.Key_Left:
                        offset += QtCore.QPointF(-Diagram.KeyMoveFactor, 0)
                    if keyEvent.key() == QtCore.Qt.Key_Right:
                        offset += QtCore.QPointF(+Diagram.KeyMoveFactor, 0)
                    initData = self.diagram.setupMove(selected)
                    moveData = self.diagram.completeMove(initData, offset)
                    self.session.undostack.push(
                        CommandNodeMove(self.diagram, initData, moveData))
                    self.diagram.setMode(DiagramMode.Idle)
                else:
                    super().keyPressEvent(keyEvent)
        else:
            super().keyPressEvent(keyEvent)
コード例 #3
0
    def mouseReleaseEvent(self, mouseEvent):
        """
        Executed when the mouse is released from the scene.
        :type mouseEvent: QGraphicsSceneMouseEvent
        """
        mouseModifiers = mouseEvent.modifiers()
        mouseButton = mouseEvent.button()
        mousePos = mouseEvent.scenePos()

        if mouseButton == QtCore.Qt.LeftButton:
            if self.mode is DiagramMode.LabelMove:

                #############################################
                # LABEL MOVE
                #################################

                if self.isLabelMove():
                    pos = self.mp_Label.pos()
                    if self.mp_LabelPos != pos:
                        item = self.mp_Label.parentItem()
                        command = CommandLabelMove(self, item,
                                                   self.mp_LabelPos, pos)
                        self.session.undostack.push(command)
                    self.setMode(DiagramMode.Idle)

            elif self.mode is DiagramMode.NodeMove:

                #############################################
                # ITEM MOVEMENT
                #################################

                if self.isNodeMove():
                    pos = self.mp_Node.pos()
                    if self.mp_NodePos != pos:
                        moveData = self.completeMove(self.mp_Data)
                        self.session.undostack.push(
                            CommandNodeMove(self, self.mp_Data, moveData))
                    self.setMode(DiagramMode.Idle)

        elif mouseButton == QtCore.Qt.RightButton:

            if self.mode is not DiagramMode.SceneDrag:

                #############################################
                # CONTEXTUAL MENU
                #################################

                item = first(self.items(mousePos))
                if not item:
                    self.clearSelection()
                    items = []
                else:
                    items = self.selectedItems()
                    if item not in items:
                        self.clearSelection()
                        item.setSelected(True)
                        items = [item]

                self.mp_Pos = mousePos
                menu = self.plugin.mf.create(self, items, mousePos)
                menu.exec_(mouseEvent.screenPos())

        super().mouseReleaseEvent(mouseEvent)

        self.mo_Node = None
        self.mp_Data = None
        self.mp_Edge = None
        self.mp_Label = None
        self.mp_LabelPos = None
        self.mp_Node = None
        self.mp_NodePos = None
        self.mp_Pos = None
コード例 #4
0
ファイル: diagram.py プロジェクト: obdasystems/eddy
    def mouseReleaseEvent(self, mouseEvent):
        """
        Executed when the mouse is released from the scene.
        :type mouseEvent: QGraphicsSceneMouseEvent
        """
        self.project.colour_items_in_case_of_unsatisfiability_or_inconsistent_ontology(
        )

        mouseModifiers = mouseEvent.modifiers()
        mouseButton = mouseEvent.button()
        mousePos = mouseEvent.scenePos()

        if mouseButton == QtCore.Qt.LeftButton:

            if self.mode is DiagramMode.EdgeAdd:

                #############################################
                # EDGE INSERTION
                #################################

                if self.isEdgeAdd():

                    edge = self.mp_Edge
                    edge.source.updateNode(selected=False)
                    currentNode = first(
                        self.items(mousePos, edges=False, skip={edge.source}))
                    insertEdge = False

                    if currentNode:
                        currentNode.updateNode(selected=False)
                        pvr = self.project.profile.checkEdge(
                            edge.source, edge, currentNode)
                        if pvr.isValid():
                            edge.target = currentNode
                            insertEdge = True

                    # We temporarily remove the item from the diagram and we perform the
                    # insertion using the undo command that will also emit the sgnItemAdded
                    # signal hence all the widgets will be notified of the edge insertion.
                    # We do this because while creating the edge we need to display it so the
                    # user knows what he is connecting, but we don't want to truly insert
                    # it till it's necessary (when the mouse is released and the validation
                    # confirms that the generated expression is a valid graphol expression).
                    self.removeItem(edge)

                    if insertEdge:
                        self.session.undostack.push(CommandEdgeAdd(self, edge))
                        edge.updateEdge()

                    self.clearSelection()
                    self.project.profile.reset()
                    statusBar = self.session.statusBar()
                    statusBar.clearMessage()

                    self.sgnItemInsertionCompleted.emit(edge, mouseModifiers)

            elif self.mode is DiagramMode.LabelMove:

                #############################################
                # LABEL MOVE
                #################################

                if self.isLabelMove():
                    pos = self.mp_Label.pos()
                    if self.mp_LabelPos != pos:
                        item = self.mp_Label.parentItem()
                        command = CommandLabelMove(self, item,
                                                   self.mp_LabelPos, pos)
                        self.session.undostack.push(command)
                    self.setMode(DiagramMode.Idle)

            elif self.mode is DiagramMode.NodeMove:

                #############################################
                # ITEM MOVEMENT
                #################################

                if self.isNodeMove():
                    pos = self.mp_Node.pos()
                    if self.mp_NodePos != pos:
                        moveData = self.completeMove(self.mp_Data)
                        self.session.undostack.push(
                            CommandNodeMove(self, self.mp_Data, moveData))
                    self.setMode(DiagramMode.Idle)

        elif mouseButton == QtCore.Qt.RightButton:

            if self.mode is not DiagramMode.SceneDrag:

                #############################################
                # CONTEXTUAL MENU
                #################################

                item = first(self.items(mousePos))
                if not item:
                    self.clearSelection()
                    items = []
                else:
                    items = self.selectedItems()
                    if item not in items:
                        self.clearSelection()
                        item.setSelected(True)
                        items = [item]

                self.mp_Pos = mousePos
                menu = self.session.mf.create(self, items, mousePos)
                menu.exec_(mouseEvent.screenPos())

        super().mouseReleaseEvent(mouseEvent)

        self.mo_Node = None
        self.mp_Data = None
        self.mp_Edge = None
        self.mp_Label = None
        self.mp_LabelPos = None
        self.mp_Node = None
        self.mp_NodePos = None
        self.mp_Pos = None