コード例 #1
0
    def mouseMove(self, event: QKeyEvent):
        if not self.begin or not self.isDrawing:
            return

        if event.modifiers() == Qt.ShiftModifier:

            if getBiggerDiff(event.pos(), self.begin) == 'X':
                self.end = QPoint(event.pos().x(), self.begin.y())
            else:
                self.end = QPoint(self.begin.x(), event.pos().y())

        else:
            self.end = event.pos()

        self.app.repaint()
コード例 #2
0
    def mouseMove(self, event: QKeyEvent):
        if not self.editType:
            return

        begin = self.curMemento.begin
        end = self.curMemento.end

        newPoint: QPoint = event.pos()
        if self.editType == 'BEGIN':
            # Shift pressed
            if event.modifiers() == Qt.ShiftModifier:
                # Parallel to x axis
                if getBiggerDiff(end, newPoint) == 'X':
                    newPoint = QPoint(newPoint.x(), end.y())
                else:
                    # Parallel to Y axis
                    newPoint = QPoint(end.x(), newPoint.y())

            self.selected.setBegin(newPoint)

        elif self.editType == 'END':
            # Shift pressed
            if event.modifiers() == Qt.ShiftModifier:
                # Parallel to x axis
                if getBiggerDiff(begin, newPoint) == 'X':
                    newPoint = QPoint(newPoint.x(), begin.y())
                else:
                    # Parallel to y axis
                    newPoint = QPoint(begin.x(), newPoint.y())

            self.selected.setEnd(newPoint)

        self.app.repaint()
コード例 #3
0
    def mouseMove(self, event: QKeyEvent):
        if not self.begin or not self.isDrawing:
            return

        end = event.pos()

        if event.modifiers() & Qt.ShiftModifier:
            # if shift then draw square with bigger size
            if getBiggerDiff(event.pos(), self.begin) == 'X':
                end = QPoint(end.x(),
                             end.x() - self.begin.x() + self.begin.y())
            else:
                end = QPoint(end.y() - self.begin.y() + self.begin.x(),
                             end.y())

        if event.modifiers() & Qt.AltModifier:
            # calculate new end point
            newEndX = end.x() + (end.x() - self.begin.x())
            newEndY = end.y() + (end.y() - self.begin.y())

            end = QPoint(newEndX, newEndY)

        self.end = end
        self.app.repaint()