This commit is contained in:
Ignacio Serantes
2026-05-02 19:44:28 +02:00
parent a824a01579
commit 28b120c9e9
7 changed files with 57 additions and 41 deletions

View File

@@ -689,39 +689,36 @@ class ImageController(QObject):
if self.pixmap_original.isNull():
return QPixmap()
# Ensure pixmap_original is a valid, independent copy before transforming
temp_pixmap = QPixmap(self.pixmap_original)
if temp_pixmap.isNull():
return QPixmap()
# Start with an identity transform
transform = QTransform()
# Use rotated() which returns a new QTransform, potentially safer
transform = QTransform() # Initialize to identity transform
# Apply rotation
if self.rotation != 0:
transform = QTransform().rotated(float(self.rotation))
transform.rotate(float(self.rotation))
transformed_pixmap = temp_pixmap.transformed(
# Apply flips
if self.flip_h:
transform.scale(-1, 1)
if self.flip_v:
transform.scale(1, -1)
# Apply the cumulative transform to the original pixmap
transformed_pixmap = self.pixmap_original.transformed(
transform, Qt.TransformationMode.SmoothTransformation)
# Calculate new size, explicitly converting QSizeF to QSize
new_size_f = transformed_pixmap.size() * self.zoom_factor
new_size = QSize(int(new_size_f.width()), int(new_size_f.height()))
scaled_pixmap = transformed_pixmap.scaled(
new_size, Qt.AspectRatioMode.KeepAspectRatio,
Qt.TransformationMode.SmoothTransformation)
if self.flip_h:
t_flip_h = QTransform()
t_flip_h.scale(-1, 1)
scaled_pixmap = scaled_pixmap.transformed(
t_flip_h, Qt.TransformationMode.SmoothTransformation)
if self.flip_v:
t_flip_v = QTransform()
t_flip_v.scale(1, -1)
scaled_pixmap = scaled_pixmap.transformed(
t_flip_v, Qt.TransformationMode.SmoothTransformation)
return scaled_pixmap
# Apply scaling (zoom) separately after rotation and flips,
# as scaling should be based on the *transformed* dimensions.
# This is important: if you scale before rotation, the scaling
# factors might be applied to the wrong axes.
if self.zoom_factor != 1.0:
new_size_f = transformed_pixmap.size() * self.zoom_factor
new_size = QSize(int(new_size_f.width()), int(new_size_f.height()))
scaled_pixmap = transformed_pixmap.scaled(
new_size, Qt.AspectRatioMode.KeepAspectRatio,
Qt.TransformationMode.SmoothTransformation)
return scaled_pixmap
else:
return transformed_pixmap
def rotate(self, angle):
"""