[gnome-photos/wip/rishi/zoom: 2/10] application, preview-view: Let the zoom-in/out GActions accept a delta



commit c93d51694cbeaa7b2fe9a710b6482e675ba1ed3d
Author: Debarshi Ray <debarshir gnome org>
Date:   Tue Jun 6 21:51:25 2017 +0200

    application, preview-view: Let the zoom-in/out GActions accept a delta
    
    Scroll events have fractional deltas, so the entire zoom factor that is
    used for a single key press cannot be used.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=742662

 src/photos-application.c  |    8 ++++----
 src/photos-preview-view.c |   21 +++++++++++++++++----
 2 files changed, 21 insertions(+), 8 deletions(-)
---
diff --git a/src/photos-application.c b/src/photos-application.c
index 406c03b..11c9ed8 100644
--- a/src/photos-application.c
+++ b/src/photos-application.c
@@ -1918,10 +1918,10 @@ photos_application_startup (GApplication *application)
   self->zoom_best_fit_action = g_simple_action_new ("zoom-best-fit", NULL);
   g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (self->zoom_best_fit_action));
 
-  self->zoom_in_action = g_simple_action_new ("zoom-in", NULL);
+  self->zoom_in_action = g_simple_action_new ("zoom-in", G_VARIANT_TYPE_DOUBLE);
   g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (self->zoom_in_action));
 
-  self->zoom_out_action = g_simple_action_new ("zoom-out", NULL);
+  self->zoom_out_action = g_simple_action_new ("zoom-out", G_VARIANT_TYPE_DOUBLE);
   g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (self->zoom_out_action));
 
   g_signal_connect_swapped (self->state->mode_cntrlr,
@@ -1945,8 +1945,8 @@ photos_application_startup (GApplication *application)
   gtk_application_set_accels_for_action (GTK_APPLICATION (self), "app.search", search_accels);
   gtk_application_set_accels_for_action (GTK_APPLICATION (self), "app.select-all", select_all_accels);
   gtk_application_set_accels_for_action (GTK_APPLICATION (self), "app.zoom-best-fit", zoom_best_fit_accels);
-  gtk_application_set_accels_for_action (GTK_APPLICATION (self), "app.zoom-in", zoom_in_accels);
-  gtk_application_set_accels_for_action (GTK_APPLICATION (self), "app.zoom-out", zoom_out_accels);
+  gtk_application_set_accels_for_action (GTK_APPLICATION (self), "app.zoom-in(1.0)", zoom_in_accels);
+  gtk_application_set_accels_for_action (GTK_APPLICATION (self), "app.zoom-out(1.0)", zoom_out_accels);
 
   g_signal_connect_swapped (self->state->item_mngr,
                             "load-finished",
diff --git a/src/photos-preview-view.c b/src/photos-preview-view.c
index 11990d4..6c93c37 100644
--- a/src/photos-preview-view.c
+++ b/src/photos-preview-view.c
@@ -726,24 +726,30 @@ photos_preview_view_zoom_best_fit (PhotosPreviewView *self)
 
 
 static void
-photos_preview_view_zoom_in (PhotosPreviewView *self)
+photos_preview_view_zoom_in (PhotosPreviewView *self, GVariant *parameter)
 {
   GtkWidget *view;
   GtkWidget *view_container;
   gboolean best_fit;
+  gdouble delta;
   gdouble zoom;
   gdouble zoom_factor;
+  gdouble zoom_factor_for_delta;
 
   g_return_if_fail (self->zoom_best_fit > 0.0);
 
+  delta = g_variant_get_double (parameter);
+  g_return_if_fail (delta > 0.0);
+
   view_container = gtk_stack_get_visible_child (GTK_STACK (self->stack));
   view = photos_preview_view_get_view_from_view_container (view_container);
 
   best_fit = photos_image_view_get_best_fit (PHOTOS_IMAGE_VIEW (view));
   zoom_factor = best_fit ? ZOOM_FACTOR_1 : ZOOM_FACTOR_2;
+  zoom_factor_for_delta = pow (zoom_factor, delta);
 
   zoom = photos_image_view_get_zoom (PHOTOS_IMAGE_VIEW (view));
-  zoom *= zoom_factor;
+  zoom *= zoom_factor_for_delta;
 
   photos_image_view_set_zoom (PHOTOS_IMAGE_VIEW (view), zoom);
 
@@ -753,19 +759,26 @@ photos_preview_view_zoom_in (PhotosPreviewView *self)
 
 
 static void
-photos_preview_view_zoom_out (PhotosPreviewView *self)
+photos_preview_view_zoom_out (PhotosPreviewView *self, GVariant *parameter)
 {
   GtkWidget *view;
   GtkWidget *view_container;
+  gdouble delta;
   gdouble zoom;
+  gdouble zoom_factor_for_delta;
 
   g_return_if_fail (self->zoom_best_fit > 0.0);
 
+  delta = g_variant_get_double (parameter);
+  g_return_if_fail (delta > 0.0);
+
   view_container = gtk_stack_get_visible_child (GTK_STACK (self->stack));
   view = photos_preview_view_get_view_from_view_container (view_container);
 
+  zoom_factor_for_delta = pow (ZOOM_FACTOR_2, delta);
+
   zoom = photos_image_view_get_zoom (PHOTOS_IMAGE_VIEW (view));
-  zoom /= ZOOM_FACTOR_2;
+  zoom /= zoom_factor_for_delta;
 
   if (zoom < self->zoom_best_fit || photos_utils_equal_double (self->zoom_best_fit, zoom))
     {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]