editor: Apply rotation to files
This commit is contained in:
parent
4164fa61c3
commit
afcc24e235
10 changed files with 116 additions and 3 deletions
|
|
@ -135,11 +135,15 @@ pub enum FitMode {
|
|||
mod imp {
|
||||
use super::*;
|
||||
use crate::decoder::tiling::SharedFrameBuffer;
|
||||
use crate::editing;
|
||||
|
||||
#[derive(Debug, Default, Properties)]
|
||||
#[properties(wrapper_type = super::LpImage)]
|
||||
pub struct LpImage {
|
||||
pub(super) file: RefCell<Option<gio::File>>,
|
||||
/// Contains a file from which to reload the image after animation has
|
||||
/// finished.
|
||||
pub(super) queued_reload: RefCell<Option<gio::File>>,
|
||||
#[property(get)]
|
||||
pub(super) is_deleted: Cell<bool>,
|
||||
#[property(get)]
|
||||
|
|
@ -235,6 +239,9 @@ mod imp {
|
|||
|
||||
/// Number of snapshots created, debug only
|
||||
pub(super) nth_snapshot: Cell<u8>,
|
||||
|
||||
/// Editing queue
|
||||
pub(super) editing_queue: editing::Queue,
|
||||
}
|
||||
|
||||
#[glib::object_subclass]
|
||||
|
|
|
|||
|
|
@ -283,6 +283,12 @@ impl LpImage {
|
|||
let imp = self.imp();
|
||||
log::debug!("Loading file {}", file.uri());
|
||||
|
||||
if imp.rotation_animation().state() == adw::AnimationState::Playing {
|
||||
log::debug!("Queueing image reload due to playing rotate animation.");
|
||||
self.imp().queued_reload.replace(Some(file.clone()));
|
||||
return;
|
||||
}
|
||||
|
||||
imp.metadata.replace(Metadata::default());
|
||||
self.imp().emmit_metadata_changed();
|
||||
self.imp().set_file_loaded(file).await;
|
||||
|
|
|
|||
|
|
@ -46,11 +46,27 @@ impl imp::LpImage {
|
|||
pub(super) fn rotation_animation(&self) -> &adw::TimedAnimation {
|
||||
let obj = self.obj().to_owned();
|
||||
self.rotation_animation.get_or_init(|| {
|
||||
adw::TimedAnimation::builder()
|
||||
let animation = adw::TimedAnimation::builder()
|
||||
.duration(ROTATION_ANIMATION_DURATION)
|
||||
.widget(&obj)
|
||||
.target(&adw::PropertyAnimationTarget::new(&obj, "rotation"))
|
||||
.build()
|
||||
.build();
|
||||
|
||||
animation.connect_done(glib::clone!(
|
||||
#[weak]
|
||||
obj,
|
||||
move |_| {
|
||||
let imp = obj.imp();
|
||||
if let Some(new_file) = imp.queued_reload.replace(None) {
|
||||
glib::spawn_future_local(async move {
|
||||
log::debug!("Animation finished: Executing delayed reload");
|
||||
obj.load(&new_file).await;
|
||||
});
|
||||
}
|
||||
}
|
||||
));
|
||||
|
||||
animation
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -58,6 +74,7 @@ impl imp::LpImage {
|
|||
impl LpImage {
|
||||
/// Set rotation and mirroring to the state would have after loading
|
||||
pub fn reset_rotation(&self) {
|
||||
log::debug!("Resetting rotation");
|
||||
let orientation = self.metadata().orientation();
|
||||
self.imp().rotation_target.set(-orientation.rotation);
|
||||
self.set_mirrored(orientation.mirrored);
|
||||
|
|
@ -84,5 +101,13 @@ impl LpImage {
|
|||
animation.set_value_to(imp.zoom_level_best_fit_for_rotation(target.get()));
|
||||
animation.play();
|
||||
}
|
||||
|
||||
if let Ok(r) = gufo_common::orientation::Rotation::try_from(angle) {
|
||||
log::debug!("Editing image to rotate by {r:?}");
|
||||
let operation = glycin::Operation::Rotate(r);
|
||||
let editing_queue = &self.imp().editing_queue;
|
||||
editing_queue.push(operation);
|
||||
editing_queue.write_to_image(self);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue