edit/crop: Enable reset and save on selection change
This commit is contained in:
parent
6fa42d542b
commit
51883734f5
3 changed files with 31 additions and 19 deletions
|
|
@ -18,7 +18,6 @@
|
||||||
//! Shows an resizable cropping selection
|
//! Shows an resizable cropping selection
|
||||||
|
|
||||||
use std::cell::OnceCell;
|
use std::cell::OnceCell;
|
||||||
use std::marker::PhantomData;
|
|
||||||
|
|
||||||
use adw::prelude::*;
|
use adw::prelude::*;
|
||||||
use adw::subclass::prelude::*;
|
use adw::subclass::prelude::*;
|
||||||
|
|
@ -74,8 +73,6 @@ mod imp {
|
||||||
|
|
||||||
#[property(get, construct_only)]
|
#[property(get, construct_only)]
|
||||||
original_image: OnceCell<LpImage>,
|
original_image: OnceCell<LpImage>,
|
||||||
#[property(get=Self::cropped)]
|
|
||||||
cropped: PhantomData<bool>,
|
|
||||||
|
|
||||||
#[property(get, set)]
|
#[property(get, set)]
|
||||||
child: OnceCell<gtk::Widget>,
|
child: OnceCell<gtk::Widget>,
|
||||||
|
|
@ -141,6 +138,14 @@ mod imp {
|
||||||
obj.insert_action_group("edit-crop", Some(&actions));
|
obj.insert_action_group("edit-crop", Some(&actions));
|
||||||
|
|
||||||
obj.action_set_enabled("edit-crop.reset", false);
|
obj.action_set_enabled("edit-crop.reset", false);
|
||||||
|
|
||||||
|
self.selection.connect_cropped_notify(glib::clone!(
|
||||||
|
#[weak]
|
||||||
|
obj,
|
||||||
|
move |_| {
|
||||||
|
obj.action_set_enabled("edit-crop.reset", obj.imp().is_reset_enabled());
|
||||||
|
}
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispose(&self) {
|
fn dispose(&self) {
|
||||||
|
|
@ -152,10 +157,6 @@ mod imp {
|
||||||
impl BinImpl for LpEditCrop {}
|
impl BinImpl for LpEditCrop {}
|
||||||
|
|
||||||
impl LpEditCrop {
|
impl LpEditCrop {
|
||||||
fn cropped(&self) -> bool {
|
|
||||||
self.selection.is_cropped()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn reset_selection(&self) {
|
fn reset_selection(&self) {
|
||||||
self.selection.reset();
|
self.selection.reset();
|
||||||
}
|
}
|
||||||
|
|
@ -246,6 +247,10 @@ mod imp {
|
||||||
obj.action_set_enabled("edit-crop.reset", true);
|
obj.action_set_enabled("edit-crop.reset", true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_reset_enabled(&self) -> bool {
|
||||||
|
self.obj().edit_window().operations().is_some() || self.selection.cropped()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -214,6 +214,9 @@ mod imp {
|
||||||
/// Last selected crop area
|
/// Last selected crop area
|
||||||
crop_area_image_coord: Cell<Option<(u32, u32, u32, u32)>>,
|
crop_area_image_coord: Cell<Option<(u32, u32, u32, u32)>>,
|
||||||
|
|
||||||
|
#[property(get)]
|
||||||
|
cropped: Cell<bool>,
|
||||||
|
|
||||||
#[property(get, set=Self::set_crop_x, explicit_notify)]
|
#[property(get, set=Self::set_crop_x, explicit_notify)]
|
||||||
crop_x: Cell<f32>,
|
crop_x: Cell<f32>,
|
||||||
#[property(get, set=Self::set_crop_y, explicit_notify)]
|
#[property(get, set=Self::set_crop_y, explicit_notify)]
|
||||||
|
|
@ -391,6 +394,11 @@ mod imp {
|
||||||
|
|
||||||
self.update_apply_crop_visibility();
|
self.update_apply_crop_visibility();
|
||||||
|
|
||||||
|
if self.is_cropped() != self.cropped.get() {
|
||||||
|
self.cropped.set(self.is_cropped());
|
||||||
|
self.obj().notify_cropped();
|
||||||
|
}
|
||||||
|
|
||||||
// Selection area
|
// Selection area
|
||||||
self.selection_overlay.allocate(
|
self.selection_overlay.allocate(
|
||||||
width as i32,
|
width as i32,
|
||||||
|
|
@ -925,7 +933,7 @@ mod imp {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_apply_crop_visibility(&self) {
|
fn update_apply_crop_visibility(&self) {
|
||||||
let visibile = self.obj().is_cropped()
|
let visibile = self.is_cropped()
|
||||||
&& self.selection_in_resize.get().is_none()
|
&& self.selection_in_resize.get().is_none()
|
||||||
&& self.selection_in_move.get().is_none();
|
&& self.selection_in_move.get().is_none();
|
||||||
|
|
||||||
|
|
@ -944,7 +952,7 @@ mod imp {
|
||||||
pub(super) fn crop_area_image_coord(&self) -> Option<(u32, u32, u32, u32)> {
|
pub(super) fn crop_area_image_coord(&self) -> Option<(u32, u32, u32, u32)> {
|
||||||
let obj = self.obj();
|
let obj = self.obj();
|
||||||
|
|
||||||
if !obj.is_cropped() {
|
if !self.is_cropped() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1010,6 +1018,7 @@ mod imp {
|
||||||
&& obj.crop_y() == 0.
|
&& obj.crop_y() == 0.
|
||||||
&& obj.crop_width() as i32 == self.total_width()
|
&& obj.crop_width() as i32 == self.total_width()
|
||||||
&& obj.crop_height() as i32 == self.total_height();
|
&& obj.crop_height() as i32 == self.total_height();
|
||||||
|
|
||||||
!untouched
|
!untouched
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1044,8 +1053,4 @@ impl LpEditCropSelection {
|
||||||
pub fn image(&self) -> LpImage {
|
pub fn image(&self) -> LpImage {
|
||||||
self.imp().image()
|
self.imp().image()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_cropped(&self) -> bool {
|
|
||||||
self.imp().is_cropped()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -120,11 +120,13 @@ mod imp {
|
||||||
|
|
||||||
let obj = self.obj();
|
let obj = self.obj();
|
||||||
|
|
||||||
obj.edit_crop().connect_cropped_notify(glib::clone!(
|
obj.edit_crop()
|
||||||
#[weak]
|
.selection()
|
||||||
obj,
|
.connect_cropped_notify(glib::clone!(
|
||||||
move |_| obj.imp().done.set_sensitive(obj.is_done_sensitive())
|
#[weak]
|
||||||
));
|
obj,
|
||||||
|
move |_| obj.imp().done.set_sensitive(obj.is_done_sensitive())
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl BinImpl for LpEditWindow {}
|
impl BinImpl for LpEditWindow {}
|
||||||
|
|
@ -376,7 +378,7 @@ impl LpEditWindow {
|
||||||
.borrow()
|
.borrow()
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.is_some_and(|x| !x.operations().is_empty())
|
.is_some_and(|x| !x.operations().is_empty())
|
||||||
|| self.edit_crop().cropped()
|
|| self.edit_crop().selection().cropped()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_operation(&self, operation: glycin::Operation) {
|
pub fn add_operation(&self, operation: glycin::Operation) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue