From e44198de08c121b3d32775e0353b5e326fecc307 Mon Sep 17 00:00:00 2001 From: Colin Clark Date: Fri, 24 Mar 2017 19:45:44 +0000 Subject: [PATCH] Fix #245: Zoom settings on status bar 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 | 67 +++++++++++-- doc/docbook/GuideOptionsImage.xml | 58 +----------- src/layout.c | 115 ++++++++++++++++++++++- src/menu.c | 74 +++++++++++++++ src/menu.h | 4 +- src/preferences.c | 27 ------ 6 files changed, 250 insertions(+), 95 deletions(-) diff --git a/doc/docbook/GuideMainWindowStatusBar.xml b/doc/docbook/GuideMainWindowStatusBar.xml index 255fc607..d749b37c 100644 --- a/doc/docbook/GuideMainWindowStatusBar.xml +++ b/doc/docbook/GuideMainWindowStatusBar.xml @@ -82,23 +82,76 @@ 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. -
- Zoom - 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. - 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). - -
Buttons Statusbar buttons corresponds to selected menu action. +
+ Zoom + 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. + 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). + + Clicking this button permits control of the behavior of the zoom and scroll settings used when changing the displayed image. + + + + Zoom to original size + + + The new image is set to its original size. + + + + + Fit image to window + + + The new image's zoom is changed so that the image will fit within the current view area. + + + + + Leave zoom at previous setting + + + The zoom setting is unchanged, the new image will be scaled the same as the previous image. + + + + + + + Scroll to top left corner + + + The new image is displayed from top left corner. + + + + + Scroll to image center + + + The new image is centered + + + + + Keep the region from previous iamge + + + The new image is positioned as the previous one, whenever possible. + + + +
Exif rotate - Toggles the auto-rotation of images if they have Exif orientation data. + Toggles the auto-rotation of images if they have Exif orientation data. Refer also to the FAQ . diff --git a/doc/docbook/GuideOptionsImage.xml b/doc/docbook/GuideOptionsImage.xml index 9f583601..e64016e2 100644 --- a/doc/docbook/GuideOptionsImage.xml +++ b/doc/docbook/GuideOptionsImage.xml @@ -105,62 +105,6 @@
-
- When new image is selected - This controls the behavior of the zoom and scroll settings when changing the displayed image. - - - - Zoom to original size - - - The new image is set to it's original size. - - - - - Fit image to window - - - The new image's zoom is changed so that the image will fit within the current view area. - - - - - Leave zoom at previous setting - - - The zoom setting is unchanged, the new image will be scaled the same as the previous image. - - - - - - - Scroll to top left corner - - - The new image is displayed from top left corner. - - - - - Scroll to image center - - - The new image is centered - - - - - Keep the region from previous iamge - - - The new image is positioned as the previous one, whenever possible. - - - -
Appearance @@ -204,7 +148,7 @@
Convenience - + Auto rotate proofs using EXIF information diff --git a/src/layout.c b/src/layout.c index 83cafd11..89a55334 100644 --- a/src/layout.c +++ b/src/layout.c @@ -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); diff --git a/src/menu.c b/src/menu.c index ffd4195d..e5bde775 100644 --- a/src/menu.c +++ b/src/menu.c @@ -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 diff --git a/src/menu.h b/src/menu.h index 5e7c9878..aec4fd4b 100644 --- a/src/menu.h +++ b/src/menu.h @@ -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); diff --git a/src/preferences.c b/src/preferences.c index 046ed43c..57f3e7b7 100644 --- a/src/preferences.c +++ b/src/preferences.c @@ -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"), -- 2.20.1