editing: Only show apply button if needed
This commit is contained in:
parent
cb31b93ee1
commit
a5e20baaa0
2 changed files with 27 additions and 25 deletions
|
|
@ -15,6 +15,8 @@
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
//! Shows an resizable cropping selection
|
||||||
|
|
||||||
use std::cell::{Cell, OnceCell};
|
use std::cell::{Cell, OnceCell};
|
||||||
|
|
||||||
use adw::prelude::*;
|
use adw::prelude::*;
|
||||||
|
|
@ -29,6 +31,7 @@ use crate::util::ErrorType;
|
||||||
use crate::widgets::edit::LpEditCropSelection;
|
use crate::widgets::edit::LpEditCropSelection;
|
||||||
use crate::widgets::{LpEditWindow, LpImage};
|
use crate::widgets::{LpEditWindow, LpImage};
|
||||||
|
|
||||||
|
/// Aspect ratio modes that can be selected
|
||||||
#[derive(Debug, Clone, Copy, Default, glib::Enum)]
|
#[derive(Debug, Clone, Copy, Default, glib::Enum)]
|
||||||
#[enum_type(name = "LpAspectRatio")]
|
#[enum_type(name = "LpAspectRatio")]
|
||||||
pub enum LpAspectRatio {
|
pub enum LpAspectRatio {
|
||||||
|
|
@ -108,6 +111,9 @@ mod imp {
|
||||||
klass.install_action("edit-crop.reset", None, |obj, _, _| {
|
klass.install_action("edit-crop.reset", None, |obj, _, _| {
|
||||||
obj.handle_error(obj.imp().apply_reset());
|
obj.handle_error(obj.imp().apply_reset());
|
||||||
});
|
});
|
||||||
|
klass.install_action("edit-crop.apply-crop", None, |obj, _, _| {
|
||||||
|
obj.handle_error(obj.imp().apply_crop());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
|
fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
|
||||||
|
|
@ -126,13 +132,7 @@ mod imp {
|
||||||
|
|
||||||
self.image.duplicate_from(&obj.original_image());
|
self.image.duplicate_from(&obj.original_image());
|
||||||
|
|
||||||
self.apply_crop.connect_clicked(glib::clone!(
|
obj.action_set_enabled("edit-crop.reset", false);
|
||||||
#[weak]
|
|
||||||
obj,
|
|
||||||
move |_| {
|
|
||||||
obj.handle_error(obj.imp().apply_crop());
|
|
||||||
}
|
|
||||||
));
|
|
||||||
|
|
||||||
// Selection changed notifications
|
// Selection changed notifications
|
||||||
|
|
||||||
|
|
@ -202,7 +202,7 @@ mod imp {
|
||||||
impl LpEditCrop {
|
impl LpEditCrop {
|
||||||
fn selection_changed(&self) {
|
fn selection_changed(&self) {
|
||||||
let apply_sensitive = self.selection.is_copped();
|
let apply_sensitive = self.selection.is_copped();
|
||||||
self.apply_crop.set_sensitive(apply_sensitive);
|
self.apply_crop.set_visible(apply_sensitive);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn crop_area_image_coord(&self) -> Option<(u32, u32, u32, u32)> {
|
fn crop_area_image_coord(&self) -> Option<(u32, u32, u32, u32)> {
|
||||||
|
|
@ -245,10 +245,7 @@ mod imp {
|
||||||
|
|
||||||
fn apply_crop(&self) -> Result<(), EditingError> {
|
fn apply_crop(&self) -> Result<(), EditingError> {
|
||||||
if let Some(crop) = self.crop_area_image_coord() {
|
if let Some(crop) = self.crop_area_image_coord() {
|
||||||
let edit_window = self.obj().edit_window();
|
self.add_operation(Operation::Clip(crop))?;
|
||||||
|
|
||||||
edit_window.add_operation(Operation::Clip(crop));
|
|
||||||
self.image.set_operations(edit_window.operations())?;
|
|
||||||
|
|
||||||
self.reset_selection();
|
self.reset_selection();
|
||||||
}
|
}
|
||||||
|
|
@ -257,10 +254,7 @@ mod imp {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn apply_mirror(&self) -> Result<(), EditingError> {
|
fn apply_mirror(&self) -> Result<(), EditingError> {
|
||||||
let edit_window = self.obj().edit_window();
|
self.add_operation(Operation::MirrorHorizontally)?;
|
||||||
|
|
||||||
edit_window.add_operation(Operation::MirrorHorizontally);
|
|
||||||
self.image.set_operations(edit_window.operations())?;
|
|
||||||
|
|
||||||
self.reset_selection();
|
self.reset_selection();
|
||||||
|
|
||||||
|
|
@ -268,10 +262,7 @@ mod imp {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn apply_rotate_cw(&self) -> Result<(), EditingError> {
|
fn apply_rotate_cw(&self) -> Result<(), EditingError> {
|
||||||
let edit_window = self.obj().edit_window();
|
self.add_operation(Operation::Rotate(gufo_common::orientation::Rotation::_90))?;
|
||||||
|
|
||||||
edit_window.add_operation(Operation::Rotate(gufo_common::orientation::Rotation::_90));
|
|
||||||
self.image.set_operations(edit_window.operations())?;
|
|
||||||
|
|
||||||
self.reset_selection();
|
self.reset_selection();
|
||||||
|
|
||||||
|
|
@ -279,10 +270,7 @@ mod imp {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn apply_rotate_ccw(&self) -> Result<(), EditingError> {
|
fn apply_rotate_ccw(&self) -> Result<(), EditingError> {
|
||||||
let edit_window = self.obj().edit_window();
|
self.add_operation(Operation::Rotate(gufo_common::orientation::Rotation::_270))?;
|
||||||
|
|
||||||
edit_window.add_operation(Operation::Rotate(gufo_common::orientation::Rotation::_270));
|
|
||||||
self.image.set_operations(edit_window.operations())?;
|
|
||||||
|
|
||||||
self.reset_selection();
|
self.reset_selection();
|
||||||
|
|
||||||
|
|
@ -296,6 +284,20 @@ mod imp {
|
||||||
obj.edit_window().set_operations(None);
|
obj.edit_window().set_operations(None);
|
||||||
self.reset_selection();
|
self.reset_selection();
|
||||||
|
|
||||||
|
self.obj().action_set_enabled("edit-crop.reset", false);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn add_operation(&self, operation: Operation) -> Result<(), EditingError> {
|
||||||
|
let obj = self.obj();
|
||||||
|
|
||||||
|
let edit_window = obj.edit_window();
|
||||||
|
edit_window.add_operation(operation);
|
||||||
|
self.image.set_operations(edit_window.operations())?;
|
||||||
|
|
||||||
|
obj.action_set_enabled("edit-crop.reset", true);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -301,7 +301,7 @@
|
||||||
<child type="overlay">
|
<child type="overlay">
|
||||||
<object class="GtkButton" id="apply_crop">
|
<object class="GtkButton" id="apply_crop">
|
||||||
<property name="label">Apply</property>
|
<property name="label">Apply</property>
|
||||||
<property name="action-name">edit.apply-crop</property>
|
<property name="action-name">edit-crop.apply-crop</property>
|
||||||
<property name="halign">end</property>
|
<property name="halign">end</property>
|
||||||
<property name="valign">start</property>
|
<property name="valign">start</property>
|
||||||
<style>
|
<style>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue