|
1 | 1 | """This module defines Canvas widget - the core component for drawing image labels""" |
2 | 2 |
|
3 | 3 | import math |
4 | | -from copy import deepcopy |
5 | 4 | from PyQt6 import QtCore, QtGui, QtWidgets |
6 | 5 | from PyQt6.QtCore import Qt, QTimer |
7 | 6 | from PyQt6.QtGui import QWheelEvent |
@@ -2039,33 +2038,29 @@ def rotate_point(self, p, center, theta): |
2039 | 2038 |
|
2040 | 2039 | def bounded_rotate_shapes(self, i, shape, theta): |
2041 | 2040 | """Rotate shapes. Adjust position to be bounded by pixmap border""" |
2042 | | - new_shape = deepcopy(shape) |
2043 | 2041 | if len(shape.points) == 2: |
2044 | | - new_shape.points[0] = shape.points[0] |
2045 | | - new_shape.points[1] = QtCore.QPointF( |
2046 | | - (shape.points[0].x() + shape.points[1].x()) / 2, |
2047 | | - shape.points[0].y(), |
2048 | | - ) |
2049 | | - new_shape.points.append(shape.points[1]) |
2050 | | - new_shape.points.append( |
| 2042 | + p0 = shape.points[0] |
| 2043 | + p1 = shape.points[1] |
| 2044 | + shape.points = [ |
| 2045 | + p0, |
2051 | 2046 | QtCore.QPointF( |
2052 | | - shape.points[1].x(), |
2053 | | - (shape.points[0].y() + shape.points[1].y()) / 2, |
2054 | | - ) |
2055 | | - ) |
| 2047 | + (p0.x() + p1.x()) / 2, |
| 2048 | + p0.y(), |
| 2049 | + ), |
| 2050 | + p1, |
| 2051 | + QtCore.QPointF(p1.x(), (p0.y() + p1.y()) / 2), |
| 2052 | + ] |
2056 | 2053 | center = QtCore.QPointF( |
2057 | | - (new_shape.points[0].x() + new_shape.points[2].x()) / 2, |
2058 | | - (new_shape.points[0].y() + new_shape.points[2].y()) / 2, |
| 2054 | + (shape.points[0].x() + shape.points[2].x()) / 2, |
| 2055 | + (shape.points[0].y() + shape.points[2].y()) / 2, |
2059 | 2056 | ) |
2060 | | - for j, p in enumerate(new_shape.points): |
| 2057 | + for j, p in enumerate(shape.points): |
2061 | 2058 | pos = self.rotate_point(p, center, theta) |
2062 | 2059 | # TODO: Reserved for now |
2063 | 2060 | # if self.out_off_pixmap(pos): |
2064 | 2061 | # return False # No need to rotate |
2065 | | - new_shape.points[j] = pos |
2066 | | - new_shape.direction = (new_shape.direction - theta) % (2 * math.pi) |
2067 | | - self.selected_shapes[i].points = new_shape.points |
2068 | | - self.selected_shapes[i].direction = new_shape.direction |
| 2062 | + shape.points[j] = pos |
| 2063 | + shape.direction = (shape.direction - theta) % (2 * math.pi) |
2069 | 2064 | return True |
2070 | 2065 |
|
2071 | 2066 | def deselect_shape(self): |
@@ -3369,11 +3364,14 @@ def move_by_keyboard(self, offset): |
3369 | 3364 | def rotate_by_keyboard(self, theta): |
3370 | 3365 | """Rotate selected shapes by an theta (using keyboard)""" |
3371 | 3366 | if self.selected_shapes: |
| 3367 | + rotating_shape = False |
3372 | 3368 | for i, shape in enumerate(self.selected_shapes): |
3373 | 3369 | if shape._shape_type == "rotation": |
3374 | 3370 | self.bounded_rotate_shapes(i, shape, theta) |
3375 | | - self.repaint() |
3376 | | - self.rotating_shape = True |
| 3371 | + rotating_shape = True |
| 3372 | + if rotating_shape: |
| 3373 | + self.repaint() |
| 3374 | + self.rotating_shape = True |
3377 | 3375 |
|
3378 | 3376 | # QT Overload |
3379 | 3377 | def keyPressEvent(self, ev): |
|
0 commit comments