Exemplo n.º 1
0
    def getEdge(self, pos):
        topRectUpperLeft = self.mapFromItem(self,
                                            self.boundingRect().topLeft())
        topRectLowerRight = self.mapFromItem(self,
                                             self.boundingRect().right(),
                                             self.__resizeDistance * 0.25)
        topRect = QtCore.QRectF(topRectUpperLeft, topRectLowerRight)

        rightRectUpperLeft = self.mapFromItem(
            self,
            self.boundingRect().right() - self.__resizeDistance * 0.25, 0)
        rightRectLowerRight = self.mapFromItem(
            self,
            self.boundingRect().bottomRight())
        rightRect = QtCore.QRectF(rightRectUpperLeft, rightRectLowerRight)

        bottomRectUpperLeft = self.mapFromItem(
            self, 0,
            self.boundingRect().bottom() - self.__resizeDistance * 0.25)
        bottomRectLowerRight = self.mapFromItem(
            self,
            self.boundingRect().bottomRight())
        bottomRect = QtCore.QRectF(bottomRectUpperLeft, bottomRectLowerRight)

        leftRectUpperLeft = self.mapFromItem(self,
                                             self.boundingRect().topLeft())
        leftRectLowerRight = self.mapFromItem(
            self,
            self.boundingRect().left() + self.__resizeDistance * 0.25,
            self.boundingRect().bottom())
        leftRect = QtCore.QRectF(leftRectUpperLeft, leftRectLowerRight)

        if topRect.contains(pos):
            return -1  # Disabling the top resize by default.
        elif rightRect.contains(pos):
            return 1
        elif bottomRect.contains(pos):
            return 2
        elif leftRect.contains(pos):
            return 3

        return -1
Exemplo n.º 2
0
    def boundingRect(self):
        srcPoint = self.mapFromScene(
            self.__srcPortCircle.centerInSceneCoords())
        dstPoint = self.mapFromScene(
            self.__dstPortCircle.centerInSceneCoords())
        penWidth = self.__defaultPen.width()

        return QtCore.QRectF(
            min(srcPoint.x(), dstPoint.x()),
            min(srcPoint.y(), dstPoint.y()),
            abs(dstPoint.x() - srcPoint.x()),
            abs(dstPoint.y() - srcPoint.y()),
        ).adjusted(-penWidth / 2, -penWidth / 2, +penWidth / 2, +penWidth / 2)
Exemplo n.º 3
0
    def getCorner(self, pos):
        topLeft = self.mapFromItem(self, self.boundingRect().topLeft())
        bottomRight = self.mapFromItem(self, self.boundingRect().bottomRight())
        rect = QtCore.QRectF(topLeft, bottomRight)

        if (rect.topLeft() - pos).manhattanLength() < self.__resizeDistance:
            return 0
        elif (rect.topRight() - pos).manhattanLength() < self.__resizeDistance:
            return 1
        elif (rect.bottomLeft() -
              pos).manhattanLength() < self.__resizeDistance:
            return 2
        elif (rect.bottomRight() -
              pos).manhattanLength() < self.__resizeDistance:
            return 3

        return -1