Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 20 additions & 22 deletions faststack/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3177,29 +3177,30 @@ def toggle_stack_membership(self):
self.ui_state.stackSummaryChanged.emit()
self.sync_ui_state()

def _reset_crop_settings(self):
"""Resets crop settings to default (full image) and exits crop mode, and resets rotation."""
def _reset_crop_only(self):
"""Resets crop settings (crop box and straighten) to default and exits crop mode, PRESERVING 90-deg rotation."""
if self.ui_state.isCropping:
self.ui_state.isCropping = False
self.update_status_message("Crop mode exited")
self.ui_state.currentCropBox = (0, 0, 1000, 1000)
# Also clear any editor-side crop box in case it's not fully synced yet
self.image_editor.set_crop_box((0, 0, 1000, 1000))
# Reset rotation and straighten angle
self.image_editor.set_edit_param("rotation", 0)
# Reset straighten angle since it is considered a crop-specific state
self.image_editor.set_edit_param("straighten_angle", 0.0)
# Also update UI state for rotation values if they are exposed
if hasattr(self.ui_state, "rotation"):
self.ui_state.rotation = 0
if hasattr(
self.ui_state, "cropRotation"
): # This is used by Components.qml for the overlay
if hasattr(self.ui_state, "cropRotation"):
self.ui_state.cropRotation = 0.0

# Also reset the straighten angle in current_edits since it affects rotation logic
if "straighten_angle" in self.image_editor.current_edits:
self.image_editor.current_edits["straighten_angle"] = 0.0

def _reset_crop_settings(self):
"""Resets crop settings (using _reset_crop_only) AND resets 90-degree rotation."""
self._reset_crop_only()
# Reset 90-degree rotation
self.image_editor.set_edit_param("rotation", 0)
# Also update UI state for rotation values if they are exposed
if hasattr(self.ui_state, "rotation"):
self.ui_state.rotation = 0

@Slot()
def launch_helicon_default(self):
"""Slot for QML/Keys that cannot pass arguments. Defaults to use_raw=True."""
Expand Down Expand Up @@ -6844,11 +6845,7 @@ def _apply_preview_result(self, payload):
def cancel_crop_mode(self):
"""Cancel crop mode without applying changes."""
if self.ui_state.isCropping:
self.ui_state.isCropping = False
self.ui_state.currentCropBox = (0, 0, 1000, 1000)
# Ensure backend crop state and preview rotation are cleared
self.image_editor.set_crop_box(None)
self.image_editor.set_edit_param("straighten_angle", 0.0)
self._reset_crop_only()
# Notify UI and kick fresh render
self.ui_refresh_generation += 1
self._kick_preview_worker()
Expand Down Expand Up @@ -6876,15 +6873,16 @@ def toggle_crop_mode(self):
if not self.load_image_for_editing():
return

self.ui_state.isCropping = True
# Reset to full image defaults (UI and Backend)
self.ui_state.currentCropBox = (0, 0, 1000, 1000)
self.image_editor.set_crop_box(None)
self._reset_crop_only()
# Set isCropping to True now that reset is done
self.ui_state.isCropping = True

self.ui_state.aspectRatioNames = [r["name"] for r in ASPECT_RATIOS]
self.ui_state.currentAspectRatioIndex = 0

# Reset rotation to 0 when starting fresh crop mode
self.image_editor.set_edit_param("straighten_angle", 0.0)
# Ensure UI and backend are synced and kick render
self.ui_refresh_generation += 1
self._kick_preview_worker()
self.update_status_message("Crop mode: Drag to select area, Enter to crop")

Expand Down
Loading