// Copyright (c) 2024 Sophie Herold
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
//
// SPDX-License-Identifier: GPL-3.0-or-later
//! Shows an resizable cropping selection
use std::cell::{Cell, OnceCell};
use adw::prelude::*;
use adw::subclass::prelude::*;
use adw::{glib, gtk};
use glycin::Operation;
use crate::editing::preview::EditingError;
use crate::util::gettext::*;
use crate::util::root::ParentWindow;
use crate::util::ErrorType;
use crate::widgets::edit::LpEditCropSelection;
use crate::widgets::{LpEditWindow, LpImage};
/// Aspect ratio modes that can be selected
#[derive(Debug, Clone, Copy, Default, glib::Enum)]
#[enum_type(name = "LpAspectRatio")]
pub enum LpAspectRatio {
#[default]
Free,
Original,
/// 1.0
Square,
/// 1.25
R5to4,
/// 1.33
R4to3,
/// 1.5
R3to2,
/// 1.77
R16to9,
}
#[derive(Debug, Clone, Copy, Default, glib::Enum)]
#[enum_type(name = "LpOrientation")]
pub enum LpOrientation {
#[default]
Landscape,
Portrait,
}
mod imp {
use super::*;
#[derive(Debug, Default, gtk::CompositeTemplate, glib::Properties)]
#[properties(wrapper_type = super::LpEditCrop)]
#[template(file = "crop.ui")]
pub struct LpEditCrop {
#[template_child]
image: TemplateChild,
#[template_child]
pub(super) selection: TemplateChild,
#[template_child]
pub apply_crop: TemplateChild,
#[property(get, set, builder(LpAspectRatio::default()))]
aspect_ratio: Cell,
#[property(get, set, builder(LpOrientation::default()))]
orientation: Cell,
#[property(get, construct_only)]
original_image: OnceCell,
#[property(get, construct_only)]
edit_window: OnceCell,
#[property(get, set)]
child: OnceCell,
/// Last selected crop area
crop_area_image_coord: Cell