Example #1
0
 def mousePressEvent(self,
                     event: QtWidgets.QGraphicsSceneMouseEvent) -> None:
     if not event.button() & QtCore.Qt.LeftButton:
         return
     self._rect.setTopLeft(event.pos())
     self._rect.setBottomRight(event.pos())
     self.prepareGeometryChange()
Example #2
0
	def mouseDoubleClickEvent(self, event:QtWidgets.QGraphicsSceneMouseEvent) -> None:
		""""""
		super(MouseDragScene, self).mouseDoubleClickEvent(event)
		if event.isAccepted():
			return

		if self.items(event.pos()):
			self.itemsDoubleClicked.emit({"items" : self.items(event.pos())})
Example #3
0
 def mouseMoveEvent(self, event: QtWidgets.QGraphicsSceneMouseEvent):
     if event.buttons() & QtCore.Qt.LeftButton:
         pos = self.line.p2()
         if self.image.rect.left() < event.pos().x() < self.image.rect.right():
             pos.setX(event.pos().x())
         if self.image.rect.top() < event.pos().y() < self.image.rect.bottom():
             pos.setY(event.pos().y())
         self.line.setP2(pos)
         self.createSlicePoly()
         self.prepareGeometryChange()
     super().mouseMoveEvent(event)
Example #4
0
 def mousePressEvent(self, event: QtWidgets.QGraphicsSceneMouseEvent):
     if event.buttons() & QtCore.Qt.LeftButton:
         if (
             self.image.rect.left() < event.pos().x() < self.image.rect.right()
             and self.image.rect.top() < event.pos().y() < self.image.rect.bottom()
         ):
             self.line.setPoints(event.pos(), event.pos())
         self.sliced = None
         self.poly = QtGui.QPolygonF()
         self.prepareGeometryChange()
     super().mousePressEvent(event)
Example #5
0
 def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
     self.signalHandler.boxPressed.emit(self.tabIndex, self.rowIndex)
     self.buttonDownRect = QRectF(self.rect())
     for i, handle in enumerate(self.handles):
         if handle.boundingRect().contains(event.pos()):
             if self.handleSelected is None:
                 self.handleSelected = i
Example #6
0
    def mousePressEvent(self,
                        event: QtWidgets.QGraphicsSceneMouseEvent) -> None:
        if not event.button() & QtCore.Qt.LeftButton:
            return
        self.poly.clear()
        self.poly.append(self.snapPos(event.pos()))

        self.prepareGeometryChange()
Example #7
0
    def mouseMoveEvent(self, event: QGraphicsSceneMouseEvent):

        if event.buttons() and Qt.LeftButton:
            self.__m_point = self.mapToParent(event.pos())
            self.setPos(self.__m_point)
            self.scene().update()

        super().mouseMoveEvent(event)
Example #8
0
 def hoverMoveEvent(self, event: QtWidgets.QGraphicsSceneMouseEvent) -> None:
     if self.isSelected():
         edge = self.edgeAt(event.pos())
         if edge is None:
             self.setCursor(QtCore.Qt.ArrowCursor)
         else:
             self.setCursor(self.cursors[edge])
     super().hoverMoveEvent(event)
Example #9
0
 def mouseMoveEvent(self, event: QGraphicsSceneMouseEvent):
     box = QRectF(self.buttonDownRect)
     pos = event.pos()
     offset = pos - event.buttonDownPos(Qt.LeftButton)
     if self.handleSelected is None:
         box.translate(offset)
         new_box = box
     elif self.handleSelected == 0:
         pos = box.topLeft() + offset
         new_size = box.bottomRight() - pos
         width = max(new_size.x(), 0)
         height = max(new_size.y(), 0)
         left = min(pos.x(), box.right())
         top = min(pos.y(), box.bottom())
         new_box = QRectF(left, top, width, height)
     elif self.handleSelected == 1:
         pos = box.topLeft() + offset
         height = max(box.bottom() - pos.y(), 0)
         top = min(pos.y(), box.bottom())
         new_box = QRectF(box.left(), top, box.width(), height)
     elif self.handleSelected == 2:
         pos = box.topRight() + offset
         top = min(pos.y(), box.bottom())
         width = max(pos.x() - box.left(), 0)
         height = max(box.bottom() - pos.y(), 0)
         new_box = QRectF(box.left(), top, width, height)
     elif self.handleSelected == 3:
         pos = box.topRight() + offset
         width = max(pos.x() - box.left(), 0)
         new_box = QRectF(box.left(), box.top(), width, box.height())
     elif self.handleSelected == 4:
         pos = box.bottomRight() + offset
         new_size = pos - box.topLeft()
         width = max(new_size.x(), 0)
         height = max(new_size.y(), 0)
         new_box = QRectF(box.left(), box.top(), width, height)
     elif self.handleSelected == 5:
         pos = box.bottomRight() + offset
         height = max(pos.y() - box.top(), 0)
         new_box = QRectF(box.left(), box.top(), box.width(), height)
     elif self.handleSelected == 6:
         pos = box.bottomLeft() + offset
         left = min(pos.x(), box.right())
         width = max(box.right() - pos.x(), 0)
         height = max(pos.y() - box.top(), 0)
         new_box = QRectF(left, box.top(), width, height)
     elif self.handleSelected == 7:
         pos = box.bottomLeft() + offset
         left = min(pos.x(), box.right())
         width = max(box.right() - pos.x(), 0)
         new_box = QRectF(left, box.top(), width, box.height())
     new_box = QRectF(round(new_box.left()), round(new_box.top()),
                      round(new_box.width()), round(new_box.height()))
     self.setRect(new_box)
     self.setHandlesPos()
     self.signalHandler.boxChanged.emit(self.tabIndex, self.rowIndex,
                                        new_box)
Example #10
0
 def mouseMoveEvent(self,
                    event: QtWidgets.QGraphicsSceneMouseEvent) -> None:
     if not event.buttons() & QtCore.Qt.LeftButton:
         return
     if self.poly.size() == 0:
         return
     pos = self.snapPos(event.pos())
     if self.poly.last() != pos:
         self.poly.append(pos)
         self.prepareGeometryChange()
Example #11
0
    def mouseMoveEvent(self, event: QGraphicsSceneMouseEvent):

        if self.__blockMove:
            return
        if self.__currentEndsMove == MoveLineEnds.NONE:
            return

        if self.__tryCapture is not None:
            self.__tryCapture.unCapture(self)

        if self.__currentEndsMove == MoveLineEnds.P1:
            line = QLineF(event.pos(), self.line().p2())
            self.setLine(line)
            self.__updateTextLinePos()
            rect = self.__filteredCapturedObject()
            print(rect)
            if 1 == len(rect):
                rect = rect[0]
                self.__tryCapture = rect
                self.__tryCapture.tryCapture(self)
            self.update()
            return

        if self.__currentEndsMove == MoveLineEnds.P2:
            line = QLineF(self.line().p1(), event.pos())
            self.setLine(line)
            self.__updateTextLinePos()
            rect = self.__filteredCapturedObject()
            print(rect)
            if 1 == len(rect):
                rect = rect[0]
                self.__tryCapture = rect
                self.__tryCapture.tryCapture(self)
            self.update()
            return

        if self.__currentEndsMove == MoveLineEnds.BOTH:
            super().mouseMoveEvent(event)
            self.__updateTextLinePos()
            self.update()
            return
Example #12
0
    def mouseMoveEvent(self, event: QGraphicsSceneMouseEvent):
        if event.buttons() and Qt.LeftButton:
            item = self.parentItem()
            dx = event.scenePos().x() - event.lastScenePos().x()
            dy = event.scenePos().y() - event.lastScenePos().y()
            if item.sourceNode or item.destNode:
                item.adjust()

            item.centerCp.setPoint(item.updateCenterPos())
            item.textCp.setPos(item.textPos)
            item.weightCp.setPos(item.weightPos)
            self.scene().update()
            if self.__m_type == PointType.Center:
                item.moveBy(dx, dy)
                self.scene().update()
            elif self.__m_type == PointType.Edge:
                self.__m_point = self.mapToParent(event.pos())
                #self.setPos(self.__m_point)
                item.setEdgeControlPoint(self.__m_point, self.__m_item_type)
                self.scene().update()
            elif self.__m_type == PointType.Special:
                self.__m_point = self.mapToParent(event.pos())
                #self.setPos(self.__m_point)
                item.setSpecialControlPoint(self.__m_point, self.__m_item_type)
                if self.collidingItem(item):
                    if self.itemType() == ItemType.DestType:
                        item.setDestNode(self.collidingItem(item))
                    if self.itemType() == ItemType.SourceType:
                        item.setSourceNode(self.collidingItem(item))
                    self.collidingItem(item).addBezierEdge(
                        item, self.itemType())

                self.scene().update()
            elif self.__m_type == PointType.Text:
                self.__m_point = self.mapToParent(event.pos())
                self.setPos(self.__m_point)
                self.scene().update()
Example #13
0
    def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
        if self.__blockMove:
            return

        if self.__currentEndsMove != MoveLineEnds.NONE:
            return

        if self.isInBox(event.pos(), self.line().p1()) and self.__endsCapture[0] is None:
            self.__currentEndsMove = MoveLineEnds.P1
            self.setEndsText(MoveLineEnds.P1, True, Qt.red)
            self.setCursor(Qt.ClosedHandCursor)
            return

        if self.isInBox(event.pos(), self.line().p2()) and self.__endsCapture[1] is None:
            self.__currentEndsMove = MoveLineEnds.P2
            self.setEndsText(MoveLineEnds.P2, True, Qt.red)
            self.setCursor(Qt.ClosedHandCursor)
            return

        if self.__endsCapture[0] is None and self.__endsCapture[1] is None:
            self.__currentEndsMove = MoveLineEnds.BOTH
            self.setEndsText(MoveLineEnds.BOTH, True, Qt.red)
            self.setCursor(Qt.ClosedHandCursor)
            super().mousePressEvent(event)
Example #14
0
File: drift.py Project: djdt/pewpew
 def mouseMoveEvent(self, event: QtWidgets.QGraphicsSceneMouseEvent):
     if self.selected_edge in ["top", "bottom"]:
         if self.selected_edge == "top" and event.pos().y() < self.bottom:
             self.top = event.pos().y() - event.pos().y() % self.py
         elif self.selected_edge == "bottom" and event.pos().y() > self.top:
             self.bottom = event.pos().y() - event.pos().y() % self.py
         self.changed = True
         self.update()
     else:
         super().mouseMoveEvent(event)
Example #15
0
    def mouseMoveEvent(self, event: QtWidgets.QGraphicsSceneMouseEvent):
        pos = self.itemChange(QtWidgets.QGraphicsItem.ItemPositionChange, event.pos())
        if self.selected_edge is None:
            super().mouseMoveEvent(event)
        else:
            rect = self.rect()
            if self.selected_edge.startswith("top") and pos.y() < rect.bottom():
                rect.setTop(pos.y())
            elif self.selected_edge.startswith("bottom") and pos.y() > rect.top():
                rect.setBottom(pos.y())
            if self.selected_edge.endswith("left") and pos.x() < rect.right():
                rect.setLeft(pos.x())
            elif self.selected_edge.endswith("right") and pos.x() > rect.left():
                rect.setRight(pos.x())

            self.prepareGeometryChange()
            self.setRect(rect)
Example #16
0
 def mousePressEvent(self, event: QtWidgets.QGraphicsSceneMouseEvent):
     if self.isSelected():
         self.selected_edge = self.edgeAt(event.pos())
     super().mousePressEvent(event)
Example #17
0
 def mousePressEvent(self, event: QtWidgets.QGraphicsSceneMouseEvent):
     if event.buttons() & QtCore.Qt.LeftButton:
         self.line.setPoints(event.pos(), event.pos())
         self.text = ""
         self.prepareGeometryChange()
     super().mousePressEvent(event)
Example #18
0
 def mouseMoveEvent(self, event: QtWidgets.QGraphicsSceneMouseEvent):
     if event.buttons() & QtCore.Qt.LeftButton:
         self.line.setP2(event.pos())
         self.text = f"{self.line.length():.4g} {self.unit}"
         self.prepareGeometryChange()
     super().mouseMoveEvent(event)