Ejemplo n.º 1
0
    def __init__(self, x, y, scaleFactor, text, obj, v, parent):
        """
        Default class constructor.

        :param `x`: TOWRITE
        :type `x`: qreal
        :param `y`: TOWRITE
        :type `y`: qreal
        :param `scaleFactor`: TOWRITE
        :type `scaleFactor`: qreal
        :param `text`: TOWRITE
        :type `text`: QString
        :param `obj`: TOWRITE
        :type `obj`: `BaseObject`
        :param `v`: TOWRITE
        :type `v`: `View`
        :param `parent`: TOWRITE
        :type `parent`: `QUndoCommand`_
        """
        super(UndoableScaleCommand, self).__init__(parent)

        self.gview = v
        self.object = obj
        self.setText(text)

        # Prevent division by zero and other wacky behavior
        if scaleFactor <= 0.0:
            self.dx = 0.0
            self.dy = 0.0
            self.factor = 1.0
            QMessageBox.critical(
                0, QObject.tr("ScaleFactor Error"),
                QObject.
                tr("Hi there. If you are not a developer, report this as a bug. "
                   "If you are a developer, your code needs examined, and possibly your head too."
                   ))
        else:
            # Calculate the offset
            oldX = self.object.x()  # qreal
            oldY = self.object.y()  # qreal
            scaleLine = QLineF(x, y, oldX, oldY)
            scaleLine.setLength(scaleLine.length() * scaleFactor)
            newX = scaleLine.x2()  # qreal
            newY = scaleLine.y2()  # qreal

            self.dx = newX - oldX
            self.dy = newY - oldY
            self.factor = scaleFactor
Ejemplo n.º 2
0
    def __init__(self, x, y, scaleFactor, text, obj, v, parent=None):
        """
        Default class constructor.

        :param `x`: TOWRITE
        :type `x`: qreal
        :param `y`: TOWRITE
        :type `y`: qreal
        :param `scaleFactor`: TOWRITE
        :type `scaleFactor`: qreal
        :param `text`: TOWRITE
        :type `text`: QString
        :param `obj`: TOWRITE
        :type `obj`: `BaseObject`
        :param `v`: TOWRITE
        :type `v`: `View`
        :param `parent`: TOWRITE
        :type `parent`: `QUndoCommand`_
        """
        super(UndoableScaleCommand, self).__init__(parent)

        self.gview = v
        self.object = obj
        self.setText(text)

        # Prevent division by zero and other wacky behavior
        if scaleFactor <= 0.0:
            self.dx = 0.0
            self.dy = 0.0
            self.factor = 1.0
            QMessageBox.critical(0, QObject.tr("ScaleFactor Error"),
                                 QObject.tr("Hi there. If you are not a developer, report this as a bug. "
                                 "If you are a developer, your code needs examined, and possibly your head too."))
        else:
            # Calculate the offset
            oldX = self.object.x()  # qreal
            oldY = self.object.y()  # qreal
            scaleLine = QLineF(x, y, oldX, oldY)
            scaleLine.setLength(scaleLine.length() * scaleFactor)
            newX = scaleLine.x2()  # qreal
            newY = scaleLine.y2()  # qreal

            self.dx = newX - oldX
            self.dy = newY - oldY
            self.factor = scaleFactor