Fix #245: Zoom settings on status bar
authorColin Clark <cclark@mcb.net>
Fri, 24 Mar 2017 19:45:44 +0000 (19:45 +0000)
committerColin Clark <cclark@mcb.net>
Fri, 24 Mar 2017 19:45:44 +0000 (19:45 +0000)
https://github.com/BestImageViewer/geeqie/issues/245

Move commonly used zoom settings from Preferences to a button on the
status bar

doc/docbook/GuideMainWindowStatusBar.xml
doc/docbook/GuideOptionsImage.xml
src/layout.c
src/menu.c
src/menu.h
src/preferences.c

index 255fc60..d749b37 100644 (file)
     <para>This section displays the dimensions (width x height) and file byte size of the image that is active in the image pane. When the format of the file in the image pane can not be determined the dimensions will show as “(0 x 0)”, in addition “(no read permision)” may appear if the file permissions do not allow reading the contents of the file.</para>\r
     <para />\r
   </section>\r
-  <section id="Zoom">\r
-    <title>Zoom</title>\r
-    <para>This section displays the current zoom ratio. A ratio of 1:1 is the image's original size. When the left number is larger the image is displayed larger than original size, when the right number is larger the image is displayed smaller.</para>\r
-    <para>A tilde (~) appears within the ratio display when the zoom is set to fit the image within the display area. In this zoom mode the ratio is automatically adjusted, and the displayed ratio may not be the actual ratio because the status bar display rounds the actual value to the nearest tenth (0.1).</para>\r
-    <para />\r
-  </section>\r
   <section id="Buttons">\r
     <title>Buttons</title>\r
     <para>Statusbar buttons corresponds to selected menu action.</para>\r
     <para />\r
+    <section id="Zoom">\r
+      <title>Zoom</title>\r
+      <para>The button label displays the current zoom ratio. A ratio of 1:1 is the image's original size. When the left number is larger the image is displayed larger than original size, when the right number is larger the image is displayed smaller.</para>\r
+      <para>A tilde (~) appears within the ratio display when the zoom is set to fit the image within the display area. In this zoom mode the ratio is automatically adjusted, and the displayed ratio may not be the actual ratio because the status bar display rounds the actual value to the nearest tenth (0.1).</para>\r
+      <para />\r
+      <para>Clicking this button permits control of the behavior of the zoom and scroll settings used when changing the displayed image.</para>\r
+      <variablelist>\r
+        <varlistentry>\r
+          <term>\r
+            <guilabel>Zoom to original size</guilabel>\r
+          </term>\r
+          <listitem>\r
+            <para>The new image is set to its original size.</para>\r
+          </listitem>\r
+        </varlistentry>\r
+        <varlistentry>\r
+          <term>\r
+            <guilabel>Fit image to window</guilabel>\r
+          </term>\r
+          <listitem>\r
+            <para>The new image's zoom is changed so that the image will fit within the current view area.</para>\r
+          </listitem>\r
+        </varlistentry>\r
+        <varlistentry>\r
+          <term>\r
+            <guilabel>Leave zoom at previous setting</guilabel>\r
+          </term>\r
+          <listitem>\r
+            <para>The zoom setting is unchanged, the new image will be scaled the same as the previous image.</para>\r
+          </listitem>\r
+        </varlistentry>\r
+      </variablelist>\r
+      <variablelist>\r
+        <varlistentry>\r
+          <term>\r
+            <guilabel>Scroll to top left corner</guilabel>\r
+          </term>\r
+          <listitem>\r
+            <para>The new image is displayed from top left corner.</para>\r
+          </listitem>\r
+        </varlistentry>\r
+        <varlistentry>\r
+          <term>\r
+            <guilabel>Scroll to image center</guilabel>\r
+          </term>\r
+          <listitem>\r
+            <para>The new image is centered</para>\r
+          </listitem>\r
+        </varlistentry>\r
+        <varlistentry>\r
+          <term>\r
+            <guilabel>Keep the region from previous iamge</guilabel>\r
+          </term>\r
+          <listitem>\r
+            <para>The new image is positioned as the previous one, whenever possible.</para>\r
+          </listitem>\r
+        </varlistentry>\r
+      </variablelist>\r
+    </section>\r
     <section id="ExifRotate">\r
       <title>Exif rotate</title>\r
       <para>\r
         <guiicon>\r
           <inlinegraphic fileref="gtk-color-picker.png" />\r
         </guiicon>\r
-        Toggles the auto-rotation of images if they have Exif orientation data. \r
+        Toggles the auto-rotation of images if they have Exif orientation data.\r
         Refer also to the\r
         <link linkend="HowdotheExifauto-rotationcommandswork">FAQ</link>\r
         .\r
index 9f58360..e64016e 100644 (file)
       </varlistentry>\r
     </variablelist>\r
   </section>\r
-  <section id="Whennewimageisselected">\r
-    <title>When new image is selected</title>\r
-    <para>This controls the behavior of the zoom and scroll settings when changing the displayed image.</para>\r
-    <variablelist>\r
-      <varlistentry>\r
-        <term>\r
-          <guilabel>Zoom to original size</guilabel>\r
-        </term>\r
-        <listitem>\r
-          <para>The new image is set to it's original size.</para>\r
-        </listitem>\r
-      </varlistentry>\r
-      <varlistentry>\r
-        <term>\r
-          <guilabel>Fit image to window</guilabel>\r
-        </term>\r
-        <listitem>\r
-          <para>The new image's zoom is changed so that the image will fit within the current view area.</para>\r
-        </listitem>\r
-      </varlistentry>\r
-      <varlistentry>\r
-        <term>\r
-          <guilabel>Leave zoom at previous setting</guilabel>\r
-        </term>\r
-        <listitem>\r
-          <para>The zoom setting is unchanged, the new image will be scaled the same as the previous image.</para>\r
-        </listitem>\r
-      </varlistentry>\r
-    </variablelist>\r
-    <variablelist>\r
-      <varlistentry>\r
-        <term>\r
-          <guilabel>Scroll to top left corner</guilabel>\r
-        </term>\r
-        <listitem>\r
-          <para>The new image is displayed from top left corner.</para>\r
-        </listitem>\r
-      </varlistentry>\r
-      <varlistentry>\r
-        <term>\r
-          <guilabel>Scroll to image center</guilabel>\r
-        </term>\r
-        <listitem>\r
-          <para>The new image is centered</para>\r
-        </listitem>\r
-      </varlistentry>\r
-      <varlistentry>\r
-        <term>\r
-          <guilabel>Keep the region from previous iamge</guilabel>\r
-        </term>\r
-        <listitem>\r
-          <para>The new image is positioned as the previous one, whenever possible.</para>\r
-        </listitem>\r
-      </varlistentry>\r
-    </variablelist>\r
-  </section>\r
   <section id="Appearance">\r
     <title>Appearance</title>\r
     <variablelist>\r
   <section id="Convenience">\r
     <title>Convenience</title>\r
     <variablelist>\r
-       <varlistentry>\r
+      <varlistentry>\r
         <term>\r
           <guilabel>Auto rotate proofs using EXIF information</guilabel>\r
         </term>\r
index 83cafd1..89a5533 100644 (file)
@@ -428,6 +428,113 @@ static GtkWidget *layout_sort_button(LayoutWindow *lw)
        return button;
 }
 
+static void layout_zoom_menu_cb(GtkWidget *widget, gpointer data)
+{
+       ZoomMode mode;
+
+       if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))) return;
+
+       mode = (ZoomMode)GPOINTER_TO_INT(data);
+       options->image.zoom_mode = mode;
+}
+
+static void layout_scroll_menu_cb(GtkWidget *widget, gpointer data)
+{
+       guint scroll_type;
+
+       if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))) return;
+
+       scroll_type = GPOINTER_TO_UINT(data);
+       options->image.scroll_reset_method = scroll_type;
+       image_options_sync();
+}
+
+static void layout_zoom_menu_hide_cb(GtkWidget *widget, gpointer data)
+{
+       /* destroy the menu */
+       g_object_unref(widget);
+}
+
+static void layout_zoom_button_press_cb(GtkWidget *widget, gpointer data)
+{
+       LayoutWindow *lw = data;
+       GtkWidget *menu;
+       GdkEvent *event;
+       guint32 etime;
+
+       menu = submenu_add_zoom(NULL, G_CALLBACK(layout_zoom_menu_cb),
+                       lw, FALSE, FALSE, TRUE, options->image.zoom_mode);
+
+       /* take ownership of menu */
+#ifdef GTK_OBJECT_FLOATING
+       /* GTK+ < 2.10 */
+       g_object_ref(G_OBJECT(menu));
+       gtk_object_sink(GTK_OBJECT(menu));
+#else
+       /* GTK+ >= 2.10 */
+       g_object_ref_sink(G_OBJECT(menu));
+#endif
+
+       menu_item_add_divider(menu);
+
+       menu_item_add_radio(menu, _("Scroll to top left corner"),
+                       GUINT_TO_POINTER(SCROLL_RESET_TOPLEFT),
+                       options->image.scroll_reset_method == SCROLL_RESET_TOPLEFT,
+                       G_CALLBACK(layout_scroll_menu_cb),
+                       GUINT_TO_POINTER(SCROLL_RESET_TOPLEFT));
+       menu_item_add_radio(menu, _("Scroll to image center"),
+                       GUINT_TO_POINTER(SCROLL_RESET_CENTER),
+                       options->image.scroll_reset_method == SCROLL_RESET_CENTER,
+                       G_CALLBACK(layout_scroll_menu_cb),
+                       GUINT_TO_POINTER(SCROLL_RESET_CENTER));
+       menu_item_add_radio(menu, _("Keep the region from previous image"),
+                       GUINT_TO_POINTER(SCROLL_RESET_NOCHANGE),
+                       options->image.scroll_reset_method == SCROLL_RESET_NOCHANGE,
+                       G_CALLBACK(layout_scroll_menu_cb),
+                       GUINT_TO_POINTER(SCROLL_RESET_NOCHANGE));
+
+       g_signal_connect(G_OBJECT(menu), "selection_done",
+                        G_CALLBACK(layout_zoom_menu_hide_cb), NULL);
+
+       event = gtk_get_current_event();
+       if (event)
+               {
+               etime = gdk_event_get_time(event);
+               gdk_event_free(event);
+               }
+       else
+               {
+               etime = 0;
+               }
+
+       gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 0, etime);
+}
+
+static GtkWidget *layout_zoom_button(LayoutWindow *lw, GtkWidget *box, gint size, gboolean expand)
+{
+       GtkWidget *button;
+       GtkWidget *frame;
+
+
+       frame = gtk_frame_new(NULL);
+       if (size) gtk_widget_set_size_request(frame, size, -1);
+       gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN);
+
+       gtk_box_pack_start(GTK_BOX(box), frame, FALSE, FALSE, 0);
+
+       gtk_widget_show(frame);
+
+       button = gtk_button_new_with_label("1:1");
+       g_signal_connect(G_OBJECT(button), "clicked",
+                        G_CALLBACK(layout_zoom_button_press_cb), lw);
+       gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
+
+       gtk_container_add(GTK_CONTAINER(frame), button);
+       gtk_widget_show(button);
+
+       return button;
+}
+
 /*
  *-----------------------------------------------------------------------------
  * status bar
@@ -536,7 +643,7 @@ void layout_status_update_image(LayoutWindow *lw)
                gchar *b;
 
                text = image_zoom_get_as_text(lw->image);
-               gtk_label_set_text(GTK_LABEL(lw->info_zoom), text);
+               gtk_button_set_label(GTK_BUTTON(lw->info_zoom), text);
                g_free(text);
 
                b = image_get_fd(lw->image) ? text_from_size(image_get_fd(lw->image)->size) : g_strdup("0");
@@ -666,8 +773,10 @@ static void layout_status_setup(LayoutWindow *lw, GtkWidget *box, gboolean small
        gtk_widget_show(toolbar_frame);
        gtk_widget_show(toolbar);
        gtk_box_pack_end(GTK_BOX(hbox), toolbar_frame, FALSE, FALSE, 0);
-       lw->info_zoom = layout_status_label(NULL, hbox, FALSE, ZOOM_LABEL_WIDTH, FALSE);
-       gtk_widget_set_tooltip_text(GTK_WIDGET(lw->info_zoom), _("Image zoom level"));
+       lw->info_zoom = layout_zoom_button(lw, hbox, ZOOM_LABEL_WIDTH, TRUE);
+       gtk_widget_set_tooltip_text(GTK_WIDGET(lw->info_zoom), _("Select zoom mode"));
+       gtk_widget_show(lw->info_zoom);
+
        if (small_format)
                {
                hbox = gtk_hbox_new(FALSE, 0);
index ffd4195..e5bde77 100644 (file)
@@ -220,6 +220,80 @@ GtkWidget *submenu_add_sort(GtkWidget *menu, GCallback func, gpointer data,
        return submenu;
 }
 
+gchar *zoom_type_get_text(ZoomMode method)
+{
+       switch (method)
+               {
+               case ZOOM_RESET_ORIGINAL:
+                       return _("Zoom to original size");
+                       break;
+               case ZOOM_RESET_FIT_WINDOW:
+                       return _("Fit image to window");
+                       break;
+               case ZOOM_RESET_NONE:
+                       return _("Leave Zoom at previous setting");
+                       break;
+               default:
+                       return _("Zoom to original size");
+                       break;
+               }
+
+       return "";
+}
+
+static GtkWidget *submenu_add_zoom_item(GtkWidget *menu,
+                                       GCallback func, ZoomMode mode,
+                                       gboolean show_current, ZoomMode show_mode)
+{
+       GtkWidget *item;
+
+       if (show_current)
+               {
+               item = menu_item_add_radio(menu,
+                                          zoom_type_get_text(mode), GINT_TO_POINTER((gint)mode), (mode == show_mode),
+                                          func, GINT_TO_POINTER((gint)mode));
+               }
+       else
+               {
+               item = menu_item_add(menu, zoom_type_get_text(mode),
+                                    func, GINT_TO_POINTER((gint)mode));
+               }
+
+       return item;
+}
+
+GtkWidget *submenu_add_zoom(GtkWidget *menu, GCallback func, gpointer data,
+                           gboolean include_none, gboolean include_path,
+                           gboolean show_current, ZoomMode mode)
+{
+       GtkWidget *submenu;
+
+       if (!menu)
+               {
+               submenu = gtk_menu_new();
+               g_object_set_data(G_OBJECT(submenu), "submenu_data", data);
+               }
+       else
+               {
+               submenu = menu;
+               }
+
+       submenu_add_zoom_item(submenu, func, ZOOM_RESET_ORIGINAL, show_current, mode);
+       submenu_add_zoom_item(submenu, func, ZOOM_RESET_FIT_WINDOW, show_current, mode);
+       submenu_add_zoom_item(submenu, func, ZOOM_RESET_NONE, show_current, mode);
+
+       if (menu)
+               {
+               GtkWidget *item;
+
+               item = menu_item_add(menu, _("Zoom"), NULL, NULL);
+               gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
+               return item;
+               }
+
+       return submenu;
+}
+
 /*
  *-----------------------------------------------------------------------------
  * altering
index 5e7c987..aec4fd4 100644 (file)
@@ -31,7 +31,9 @@ gchar *sort_type_get_text(SortType method);
 GtkWidget *submenu_add_sort(GtkWidget *menu, GCallback func, gpointer data,
                            gboolean include_none, gboolean include_path,
                            gboolean show_current, SortType type);
-
+GtkWidget *submenu_add_zoom(GtkWidget *menu, GCallback func, gpointer data,
+                           gboolean include_none, gboolean include_path,
+                           gboolean show_current, ZoomMode mode);
 gchar *alter_type_get_text(AlterType type);
 GtkWidget *submenu_add_alter(GtkWidget *menu, GCallback func, gpointer data);
 
index 046ed43..57f3e7b 100644 (file)
@@ -1513,33 +1513,6 @@ static void config_tab_image(GtkWidget *notebook)
                             G_CALLBACK(zoom_increment_cb), NULL);
        gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(spin), GTK_UPDATE_ALWAYS);
 
-       group = pref_group_new(vbox, FALSE, _("When new image is selected:"), GTK_ORIENTATION_HORIZONTAL);
-
-       vbox2 = pref_box_new(group, TRUE, GTK_ORIENTATION_VERTICAL, PREF_PAD_SPACE);
-       c_options->image.zoom_mode = options->image.zoom_mode;
-       button = pref_radiobutton_new(vbox2, NULL, _("Zoom to original size"),
-                                     (options->image.zoom_mode == ZOOM_RESET_ORIGINAL),
-                                     G_CALLBACK(zoom_mode_cb), GINT_TO_POINTER(ZOOM_RESET_ORIGINAL));
-       button = pref_radiobutton_new(vbox2, button, _("Fit image to window"),
-                                     (options->image.zoom_mode == ZOOM_RESET_FIT_WINDOW),
-                                     G_CALLBACK(zoom_mode_cb), GINT_TO_POINTER(ZOOM_RESET_FIT_WINDOW));
-       button = pref_radiobutton_new(vbox2, button, _("Leave Zoom at previous setting"),
-                                     (options->image.zoom_mode == ZOOM_RESET_NONE),
-                                     G_CALLBACK(zoom_mode_cb), GINT_TO_POINTER(ZOOM_RESET_NONE));
-
-       vbox2 = pref_box_new(group, TRUE, GTK_ORIENTATION_VERTICAL, PREF_PAD_SPACE);
-       c_options->image.scroll_reset_method = options->image.scroll_reset_method;
-       button = pref_radiobutton_new(vbox2, NULL, _("Scroll to top left corner"),
-                                     (options->image.scroll_reset_method == SCROLL_RESET_TOPLEFT),
-                                     G_CALLBACK(scroll_reset_cb), GINT_TO_POINTER(SCROLL_RESET_TOPLEFT));
-       button = pref_radiobutton_new(vbox2, button, _("Scroll to image center"),
-                                     (options->image.scroll_reset_method == SCROLL_RESET_CENTER),
-                                     G_CALLBACK(scroll_reset_cb), GINT_TO_POINTER(SCROLL_RESET_CENTER));
-       button = pref_radiobutton_new(vbox2, button, _("Keep the region from previous image"),
-                                     (options->image.scroll_reset_method == SCROLL_RESET_NOCHANGE),
-                                     G_CALLBACK(scroll_reset_cb), GINT_TO_POINTER(SCROLL_RESET_NOCHANGE));
-
-
        group = pref_group_new(vbox, FALSE, _("Appearance"), GTK_ORIENTATION_VERTICAL);
 
        pref_checkbox_new_int(group, _("Use custom border color in window mode"),