diff --git a/data/gtk/help_overlay.ui b/data/gtk/help_overlay.ui index 7a3ad5d..2fb35bc 100644 --- a/data/gtk/help_overlay.ui +++ b/data/gtk/help_overlay.ui @@ -14,44 +14,162 @@ F10 + + + Toggle Image Properties + win.toggle-properties + + + + + Toggle Fullscreen + win.toggle-fullscreen + + + + + Leave Fullscreen + win.leave-fullscreen + + New Window - <Primary>n + app.new-window Open Help - F1 + app.help Show Keyboard Shortcuts - <Primary>question + win.show-help-overlay + + + + + Close Window + window.close Quit - <Primary>q + app.quit + + + + + + + Navigate Images + + + + Next Image + gesture-two-finger-swipe-right - Show with orginal scale + Previous Image + gesture-two-finger-swipe-left + + + + + Next Image + Right + + + + + Previous Image + Left + + + + + + + Zoom Image + + + Zoom In + gesture-stretch + + + + + Zoom Out + gesture-pinch + + + + + Zoom In + <Ctrl>plus plus + + + + + Zoom Out + <Ctrl>minus minus + + + + + Best Fit + win.zoom-best-fit + + + + + Original Scale 1 - Show with 200% of orginal scale + 200% Scale 2 + + + Rotate Image + + + Rotate Clockwise + gesture-rotate-clockwise + + + + + Rotate Counterclockwise + gesture-rotate-counterclockwise + + + + + Rotate Clockwise + <Ctrl>R + + + + + Rotate Counterclockwise + <Ctrl><Shift>R + + + + diff --git a/data/gtk/window.ui b/data/gtk/window.ui index 791a778..0b14642 100644 --- a/data/gtk/window.ui +++ b/data/gtk/window.ui @@ -121,11 +121,24 @@ + + + + managed + + + F10 + activate + + + + help-about-symbolic + Image Properties diff --git a/src/application.rs b/src/application.rs index 1412699..07446ea 100644 --- a/src/application.rs +++ b/src/application.rs @@ -131,16 +131,39 @@ impl LpApplication { self.add_action_entries(actions).unwrap(); self.set_accels_for_action("app.help", &["F1"]); - self.set_accels_for_action("app.quit", &["Q"]); - self.set_accels_for_action("app.new-window", &["N"]); - self.set_accels_for_action("win.open", &["O"]); - self.set_accels_for_action("win.print", &["P"]); - self.set_accels_for_action("win.copy", &["C"]); - self.set_accels_for_action("win.show-help-overlay", &["question"]); + self.set_accels_for_action("app.quit", &["Q"]); + self.set_accels_for_action("app.new-window", &["N"]); + + self.set_accels_for_action("win.open", &["O"]); + self.set_accels_for_action("win.print", &["P"]); + self.set_accels_for_action("win.copy", &["C"]); + self.set_accels_for_action("win.show-help-overlay", &["question"]); + self.set_accels_for_action("win.leave-fullscreen", &["Escape"]); + self.set_accels_for_action("win.toggle-properties", &["F9"]); self.set_accels_for_action("win.toggle-fullscreen", &["F11"]); - self.set_accels_for_action("window.close", &["W"]); + self.set_accels_for_action("win.zoom-to(1.0)", &["1"]); self.set_accels_for_action("win.zoom-to(2.0)", &["2"]); + self.set_accels_for_action("win.zoom-best-fit", &["0", "0"]); + self.set_accels_for_action( + "win.zoom-in", + &[ + "plus", + "plus", + "equal", + "equal", + "KP_Add", + "KP_Add", + ], + ); + self.set_accels_for_action( + "win.zoom-out", + &["minus", "minus", "KP_Subtract", "KP_Subtract"], + ); + self.set_accels_for_action("win.rotate(90.0)", &["R"]); + self.set_accels_for_action("win.rotate(-90.0)", &["R"]); + + self.set_accels_for_action("window.close", &["W"]); } pub fn show_about(&self) { diff --git a/src/widgets/image.rs b/src/widgets/image.rs index 483852c..7b9a721 100644 --- a/src/widgets/image.rs +++ b/src/widgets/image.rs @@ -671,7 +671,6 @@ impl LpImage { .build(); animation.connect_done(glib::clone!(@weak self as obj => move |_| { - dbg!("animation done"); obj.imp().zoom_hscrollbar_transition.set(false); obj.imp().zoom_vscrollbar_transition.set(false); })); @@ -732,6 +731,13 @@ impl LpImage { self.zoom_to(zoom); } + /// Zoom to best fit + /// + /// Used by shortcut + pub fn zoom_best_fit(&self) { + self.zoom_to(self.zoom_level_best_fit()); + } + /// Zoom to specific level with animation pub fn zoom_to(&self, zoom: f64) { log::debug!("Zoom to {zoom:.3}"); diff --git a/src/window.rs b/src/window.rs index a28be8c..2493828 100644 --- a/src/window.rs +++ b/src/window.rs @@ -62,6 +62,8 @@ mod imp { #[template_child] pub headerbar: TemplateChild, #[template_child] + pub properties_button: TemplateChild, + #[template_child] pub menu_button: TemplateChild, #[template_child] pub toast_overlay: TemplateChild, @@ -106,6 +108,20 @@ mod imp { win.zoom_to(level.unwrap().get().unwrap()); }); + klass.install_action("win.zoom-best-fit", None, move |win, _, _| { + win.zoom_best_fit(); + }); + + klass.install_action("win.leave-fullscreen", None, move |win, _, _| { + win.toggle_fullscreen(false); + }); + + klass.install_action("win.toggle-properties", None, move |win, _, _| { + win.imp() + .properties_button + .set_active(!win.imp().properties_button.is_active()); + }); + klass.install_action("win.open", None, move |win, _, _| { win.pick_file(); }); @@ -284,6 +300,12 @@ impl LpWindow { self.imp().image_view.zoom_to(level); } + fn zoom_best_fit(&self) { + if let Some(page) = self.imp().image_view.current_page() { + page.image().zoom_best_fit(); + } + } + fn pick_file(&self) { let chooser = gtk::FileChooserNative::new( Some("Open Image"), @@ -403,6 +425,10 @@ impl LpWindow { self.action_set_enabled("win.print", enabled); self.action_set_enabled("win.rotate", enabled); self.action_set_enabled("win.copy", enabled); + self.action_set_enabled("win.zoom-best-fit", enabled); + self.action_set_enabled("win.zoom-in", enabled); + self.action_set_enabled("win.zoom-to", enabled); + self.action_set_enabled("win.toggle-properties", enabled); } // Adapted from https://gitlab.gnome.org/GNOME/eog/-/blob/master/src/eog-window.c:eog_window_obtain_desired_size