From 9cb08d288dea668cce452210f4cc882f2f8b4f07 Mon Sep 17 00:00:00 2001 From: Sophie Herold Date: Fri, 17 Jan 2025 23:23:59 +0100 Subject: [PATCH] edit/crop: Apply crop on rotation and flip --- src/widgets/edit/crop.rs | 5 +++++ src/widgets/edit/crop_selection.rs | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/src/widgets/edit/crop.rs b/src/widgets/edit/crop.rs index da6508b..8dbd38b 100644 --- a/src/widgets/edit/crop.rs +++ b/src/widgets/edit/crop.rs @@ -219,6 +219,7 @@ mod imp { fn selection_changed(&self) { let crop_area_image_coord = self.crop_area_image_coord(); if self.selection.is_in_user_change() { + log::trace!("Setting crop are in image coordinates to {crop_area_image_coord:?}"); self.crop_area_image_coord.replace(crop_area_image_coord); } @@ -285,24 +286,28 @@ mod imp { } fn apply_mirror_horizontally(&self) { + self.apply_crop(); self.add_operation(Operation::MirrorHorizontally); self.reset_selection(); } fn apply_mirror_vertically(&self) { + self.apply_crop(); self.add_operation(Operation::MirrorVertically); self.reset_selection(); } fn apply_rotate_cw(&self) { + self.apply_crop(); self.add_operation(Operation::Rotate(gufo_common::orientation::Rotation::_270)); self.reset_selection(); } fn apply_rotate_ccw(&self) { + self.apply_crop(); self.add_operation(Operation::Rotate(gufo_common::orientation::Rotation::_90)); self.reset_selection(); diff --git a/src/widgets/edit/crop_selection.rs b/src/widgets/edit/crop_selection.rs index 0420374..94f86a1 100644 --- a/src/widgets/edit/crop_selection.rs +++ b/src/widgets/edit/crop_selection.rs @@ -161,6 +161,8 @@ mod imp { pub(super) selection_in_resize: Cell>, /// Set while in drag gesture for moving crop area pub(super) selection_in_move: Cell>, + /// Set while resetting the crop area + pub(super) selection_in_reset: Cell, // Animates changes between different fixed aspect ratios aspect_ratio_animation: OnceCell, @@ -774,11 +776,16 @@ impl LpEditCropSelection { } pub fn reset(&self, x: f64, y: f64, width: f64, height: f64) { + let imp = self.imp(); + + imp.selection_in_reset.replace(true); self.set_image_area(x, y, width, height); self.set_crop_size(0., 0., width, height); + imp.selection_in_reset.replace(false); } pub fn set_image_area(&self, x: f64, y: f64, width: f64, height: f64) { + log::trace!("Setting image area to ({x}, {y}, {width}, {height})"); self.set_margin_start(x as i32); self.set_margin_top(y as i32); self.set_total_width(width as i32); @@ -786,6 +793,7 @@ impl LpEditCropSelection { } pub fn set_crop_size(&self, x: f64, y: f64, width: f64, height: f64) { + log::trace!("Setting crop area to ({x}, {y}, {width}, {height})"); self.set_crop_x(x as f32); self.set_crop_y(y as f32); self.set_crop_width(width as f32); @@ -803,6 +811,7 @@ impl LpEditCropSelection { pub fn is_in_user_change(&self) -> bool { self.imp().selection_in_resize.get().is_some() || self.imp().selection_in_move.get().is_some() + || self.imp().selection_in_reset.get() || self.imp().aspect_ratio_animation().state() == adw::AnimationState::Playing } }