print: Init preview image more cleanly

This commit is contained in:
Sophie Herold 2023-12-26 23:32:37 +01:00
parent db6a7e7f2a
commit 0e490f38ad
2 changed files with 15 additions and 7 deletions

View file

@ -249,6 +249,8 @@ mod imp {
#[property(get, set, construct_only)] #[property(get, set, construct_only)]
pub(super) image: OnceCell<LpImage>, pub(super) image: OnceCell<LpImage>,
#[property(get, set, construct_only)] #[property(get, set, construct_only)]
pub(super) preview_image: OnceCell<LpImage>,
#[property(get, set, construct_only)]
pub(super) parent_window: OnceCell<gtk::Window>, pub(super) parent_window: OnceCell<gtk::Window>,
#[property(get, set, construct_only)] #[property(get, set, construct_only)]
pub(super) print_settings: OnceCell<gtk::PrintSettings>, pub(super) print_settings: OnceCell<gtk::PrintSettings>,
@ -479,19 +481,25 @@ glib::wrapper! {
impl LpPrint { impl LpPrint {
pub fn new( pub fn new(
image1: LpImage, image: LpImage,
parent_window: gtk::Window, parent_window: gtk::Window,
print_settings: Option<gtk::PrintSettings>, print_settings: Option<gtk::PrintSettings>,
page_setup: Option<gtk::PageSetup>, page_setup: Option<gtk::PageSetup>,
) -> Self { ) -> Self {
let image = LpImage::new_still(); let preview_image = LpImage::new_still();
image.set_fixed_background_color(Some(gdk::RGBA::new(0.94, 0.94, 0.94, 1.))); preview_image.set_fixed_background_color(Some(gdk::RGBA::new(0.94, 0.94, 0.94, 1.)));
let image2 = image.clone(); if let Some(file) = image.file() {
glib::spawn_future_local(async move { image2.load(&image1.file().unwrap()).await }); let preview_image_ = preview_image.clone();
glib::spawn_future_local(async move { preview_image_.load(&file).await });
} else {
log::error!("Trying to print image without file");
}
let print_settings = print_settings.unwrap_or_default(); let print_settings = print_settings.unwrap_or_default();
let obj: Self = glib::Object::builder() let obj: Self = glib::Object::builder()
.property("image", image) .property("image", image)
.property("preview-image", preview_image)
.property("print-settings", print_settings) .property("print-settings", print_settings)
.property("parent-window", parent_window) .property("parent-window", parent_window)
.build(); .build();

View file

@ -62,7 +62,7 @@ mod imp_page {
let width = self.print().user_width() * self.display_scale(); let width = self.print().user_width() * self.display_scale();
let height = self.print().user_height() * self.display_scale(); let height = self.print().user_height() * self.display_scale();
let image = self.print().image(); let image = self.print().preview_image();
image.allocate( image.allocate(
width as i32, width as i32,
@ -195,7 +195,7 @@ impl Default for LpPrintPreviewPage {
impl LpPrintPreviewPage { impl LpPrintPreviewPage {
fn init(&self) { fn init(&self) {
let imp = self.imp(); let imp = self.imp();
let image = imp.preview().print().image(); let image = imp.preview().print().preview_image();
image.set_sensitive(false); image.set_sensitive(false);
image.set_parent(self); image.set_parent(self);