Commit 3b95e2a6 authored by Paolo Bacchilega's avatar Paolo Bacchilega

added option to change the mouse wheel action

parent ae0b1b86
......@@ -138,6 +138,9 @@
<key name="fullscreen-thumbnails-visible" type="b">
<default>false</default>
</key>
<key name="scroll-action" enum="org.gnome.gthumb.GthScrollAction">
<default>'change-file'</default>
</key>
</schema>
<schema id="org.gnome.gthumb.dialogs" path="/org/gnome/gthumb/dialogs/">
......
......@@ -102,6 +102,84 @@
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkLabel" id="label4">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Mouse wheel:</property>
<property name="use_markup">True</property>
<property name="xalign">0</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox" id="box8">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">12</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkRadioButton" id="scroll_event_change_image_radiobutton">
<property name="label" translatable="yes" context="zoom quality">Change image</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="halign">start</property>
<property name="use_underline">True</property>
<property name="active">True</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkRadioButton" id="scroll_event_zoom_radiobutton">
<property name="label" translatable="yes" context="zoom quality">Zoom</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="halign">start</property>
<property name="use_underline">True</property>
<property name="draw_indicator">True</property>
<property name="group">scroll_event_change_image_radiobutton</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkBox" id="box4">
<property name="visible">True</property>
......@@ -184,7 +262,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
<property name="position">2</property>
</packing>
</child>
<child>
......@@ -262,7 +340,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
<property name="position">3</property>
</packing>
</child>
</object>
......
......@@ -1938,6 +1938,15 @@ gth_image_viewer_page_real_update_info (GthViewerPage *base,
}
static gboolean
gth_image_viewer_page_real_zoom_from_scroll (GthViewerPage *base,
GdkEventScroll *event)
{
GthImageViewerPage *self = GTH_IMAGE_VIEWER_PAGE (base);
return gth_image_viewer_zoom_from_scroll (GTH_IMAGE_VIEWER (self->priv->viewer), event);
}
static void
gth_image_viewer_page_real_show_properties (GthViewerPage *base,
gboolean show)
......@@ -2014,6 +2023,7 @@ gth_viewer_page_interface_init (GthViewerPageInterface *iface)
iface->save_as = gth_image_viewer_page_real_save_as;
iface->revert = gth_image_viewer_page_real_revert;
iface->update_info = gth_image_viewer_page_real_update_info;
iface->zoom_from_scroll = gth_image_viewer_page_real_zoom_from_scroll;
iface->show_properties = gth_image_viewer_page_real_show_properties;
}
......
......@@ -31,6 +31,7 @@
typedef struct {
GtkBuilder *builder;
GSettings *settings;
GSettings *browser_settings;
} BrowserData;
......@@ -39,6 +40,7 @@ browser_data_free (BrowserData *data)
{
g_object_unref (data->builder);
g_object_unref (data->settings);
g_object_unref (data->browser_settings);
g_free (data);
}
......@@ -59,6 +61,15 @@ reset_scrollbars_toggled_cb (GtkToggleButton *button,
}
static void
scroll_event_toggled_cb (GtkToggleButton *button,
BrowserData *data)
{
g_settings_set_enum (data->browser_settings,
PREF_VIEWER_SCROLL_ACTION,
(GTK_WIDGET (button) == GET_WIDGET ("scroll_event_change_image_radiobutton")) ? GTH_SCROLL_ACTION_CHANGE_FILE : GTH_SCROLL_ACTION_ZOOM);
}
static void
zoom_quality_radiobutton_toggled_cb (GtkToggleButton *button,
BrowserData *data)
......@@ -90,6 +101,7 @@ image_viewer__dlg_preferences_construct_cb (GtkWidget *dialog,
data = g_new0 (BrowserData, 1);
data->builder = _gtk_builder_new_from_file ("image-viewer-preferences.ui", "image_viewer");
data->settings = g_settings_new (GTHUMB_IMAGE_VIEWER_SCHEMA);
data->browser_settings = g_settings_new (GTHUMB_BROWSER_SCHEMA);
notebook = _gtk_builder_get_widget (dialog_builder, "notebook");
......@@ -107,6 +119,11 @@ image_viewer__dlg_preferences_construct_cb (GtkWidget *dialog,
else
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("zoom_quality_high_radiobutton")), TRUE);
if (g_settings_get_enum (data->browser_settings, PREF_VIEWER_SCROLL_ACTION) == GTH_SCROLL_ACTION_CHANGE_FILE)
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("scroll_event_change_image_radiobutton")), TRUE);
else
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("scroll_event_zoom_radiobutton")), TRUE);
gtk_combo_box_set_active (GTK_COMBO_BOX (GET_WIDGET ("transparency_style_combobox")),
g_settings_get_enum (data->settings, PREF_IMAGE_VIEWER_TRANSPARENCY_STYLE));
......@@ -114,6 +131,14 @@ image_viewer__dlg_preferences_construct_cb (GtkWidget *dialog,
"changed",
G_CALLBACK (zoom_change_changed_cb),
data);
g_signal_connect (GET_WIDGET ("scroll_event_change_image_radiobutton"),
"toggled",
G_CALLBACK (scroll_event_toggled_cb),
data);
g_signal_connect (GET_WIDGET ("scroll_event_zoom_radiobutton"),
"toggled",
G_CALLBACK (scroll_event_toggled_cb),
data);
g_signal_connect (GET_WIDGET ("zoom_quality_low_radiobutton"),
"toggled",
G_CALLBACK (zoom_quality_radiobutton_toggled_cb),
......
......@@ -183,6 +183,7 @@ struct _GthBrowserPrivate {
guint folder_tree_open_folder_id;
GtkWidget *apply_editor_changes_button;
gboolean ask_to_save_modified_images;
GthScrollAction scroll_action;
/* settings */
......@@ -4086,6 +4087,16 @@ pref_msg_save_modified_image_changed (GSettings *settings,
}
static void
pref_scroll_action_changed (GSettings *settings,
const char *key,
gpointer user_data)
{
GthBrowser *browser = user_data;
browser->priv->scroll_action = g_settings_get_enum (settings, key);
}
static gboolean
_gth_browser_realize (GtkWidget *browser,
gpointer *data)
......@@ -4904,6 +4915,7 @@ gth_browser_init (GthBrowser *browser)
browser->priv->viewer_sidebar = g_settings_get_enum (browser->priv->browser_settings, PREF_BROWSER_VIEWER_SIDEBAR);
browser->priv->fast_file_type = g_settings_get_boolean (browser->priv->browser_settings, PREF_BROWSER_FAST_FILE_TYPE);
browser->priv->ask_to_save_modified_images = g_settings_get_boolean (browser->priv->messages_settings, PREF_MSG_SAVE_MODIFIED_IMAGE);
browser->priv->scroll_action = g_settings_get_enum (browser->priv->browser_settings, PREF_VIEWER_SCROLL_ACTION);
/* load the history only for the first window */
{
......@@ -4972,6 +4984,10 @@ gth_browser_init (GthBrowser *browser)
"changed::" PREF_MSG_SAVE_MODIFIED_IMAGE,
G_CALLBACK (pref_msg_save_modified_image_changed),
browser);
g_signal_connect (browser->priv->browser_settings,
"changed::" PREF_VIEWER_SCROLL_ACTION,
G_CALLBACK (pref_scroll_action_changed),
browser);
browser->priv->constructed = TRUE;
}
......@@ -5612,6 +5628,8 @@ gboolean
gth_browser_viewer_scroll_event_cb (GthBrowser *browser,
GdkEventScroll *event)
{
gboolean handled;
g_return_val_if_fail (event != NULL, FALSE);
if (! _gth_browser_can_change_image (browser))
......@@ -5626,12 +5644,25 @@ gth_browser_viewer_scroll_event_cb (GthBrowser *browser,
if ((event->direction != GDK_SCROLL_UP) && (event->direction != GDK_SCROLL_DOWN))
return FALSE;
if (event->direction == GDK_SCROLL_UP)
gth_browser_show_prev_image (browser, FALSE, FALSE);
else
gth_browser_show_next_image (browser, FALSE, FALSE);
handled = FALSE;
switch (browser->priv->scroll_action) {
case GTH_SCROLL_ACTION_CHANGE_FILE:
if (event->direction == GDK_SCROLL_UP)
gth_browser_show_prev_image (browser, FALSE, FALSE);
else
gth_browser_show_next_image (browser, FALSE, FALSE);
handled = TRUE;
break;
return TRUE;
case GTH_SCROLL_ACTION_ZOOM:
handled = gth_viewer_page_zoom_from_scroll (browser->priv->viewer_page, event);
break;
default:
break;
}
return handled;
}
......
......@@ -111,6 +111,12 @@ typedef enum {
GTH_ACTION_TREE_OPEN
} GthAction;
typedef enum {
GTH_SCROLL_ACTION_NONE,
GTH_SCROLL_ACTION_CHANGE_FILE,
GTH_SCROLL_ACTION_ZOOM
} GthScrollAction;
struct _GthBrowser
{
GthWindow __parent;
......
......@@ -972,27 +972,8 @@ gth_image_viewer_scroll_event (GtkWidget *widget,
/* Control + Scroll-Up / Control + Scroll-Down ==> Zoom In / Zoom Out */
if (event->state & GDK_CONTROL_MASK) {
if (self->priv->zoom_enabled) {
double new_zoom_level;
switch (event->direction) {
case GDK_SCROLL_UP:
case GDK_SCROLL_DOWN:
if (event->direction == GDK_SCROLL_UP)
new_zoom_level = get_next_zoom (self->priv->zoom_level);
else
new_zoom_level = get_prev_zoom (self->priv->zoom_level);
set_zoom_centered_at (self, new_zoom_level, FALSE, (int) event->x, (int) event->y);
gtk_widget_queue_resize (GTK_WIDGET (self));
retval = TRUE;
break;
default:
break;
}
}
return retval;
if (self->priv->zoom_enabled && gth_image_viewer_zoom_from_scroll (self, event))
return TRUE;
}
/* Scroll Left / Scroll Right ==> Scroll the image horizontally */
......@@ -2206,6 +2187,34 @@ gth_image_viewer_zoom_out (GthImageViewer *self)
}
gboolean
gth_image_viewer_zoom_from_scroll (GthImageViewer *self,
GdkEventScroll *event)
{
gboolean handled;
double new_zoom_level;
handled = FALSE;
switch (event->direction) {
case GDK_SCROLL_UP:
case GDK_SCROLL_DOWN:
if (event->direction == GDK_SCROLL_UP)
new_zoom_level = get_next_zoom (self->priv->zoom_level);
else
new_zoom_level = get_prev_zoom (self->priv->zoom_level);
set_zoom_centered_at (self, new_zoom_level, FALSE, (int) event->x, (int) event->y);
gtk_widget_queue_resize (GTK_WIDGET (self));
handled = TRUE;
break;
default:
break;
}
return handled;
}
void
gth_image_viewer_set_fit_mode (GthImageViewer *self,
GthFit fit_mode)
......
......@@ -216,6 +216,8 @@ void gth_image_viewer_set_zoom_change (GthImageViewer
GthZoomChange gth_image_viewer_get_zoom_change (GthImageViewer *viewer);
void gth_image_viewer_zoom_in (GthImageViewer *viewer);
void gth_image_viewer_zoom_out (GthImageViewer *viewer);
gboolean gth_image_viewer_zoom_from_scroll (GthImageViewer *viewer,
GdkEventScroll *event);
void gth_image_viewer_set_fit_mode (GthImageViewer *viewer,
GthFit fit_mode);
GthFit gth_image_viewer_get_fit_mode (GthImageViewer *viewer);
......
......@@ -80,6 +80,7 @@ G_BEGIN_DECLS
#define PREF_BROWSER_REUSE_ACTIVE_WINDOW "reuse-active-window"
#define PREF_FULLSCREEN_THUMBNAILS_VISIBLE "fullscreen-thumbnails-visible"
#define PREF_FULLSCREEN_SIDEBAR "fullscreen-sidebar"
#define PREF_VIEWER_SCROLL_ACTION "scroll-action"
/* keys: add to catalog */
......
......@@ -191,6 +191,17 @@ gth_viewer_page_show_properties (GthViewerPage *self,
}
gboolean
gth_viewer_page_zoom_from_scroll (GthViewerPage *self,
GdkEventScroll *event)
{
if (GTH_VIEWER_PAGE_GET_INTERFACE (self)->zoom_from_scroll != NULL)
return GTH_VIEWER_PAGE_GET_INTERFACE (self)->zoom_from_scroll (self, event);
else
return FALSE;
}
void
gth_viewer_page_file_loaded (GthViewerPage *self,
GthFileData *file_data,
......
......@@ -24,6 +24,7 @@
#include <gtk/gtk.h>
#include "gth-file-data.h"
#include "typedefs.h"
G_BEGIN_DECLS
......@@ -75,6 +76,8 @@ struct _GthViewerPageInterface {
GthFileData *file_data);
void (*show_properties) (GthViewerPage *self,
gboolean show);
gboolean (*zoom_from_scroll) (GthViewerPage *self,
GdkEventScroll *event);
/*< signals >*/
......@@ -112,6 +115,8 @@ void gth_viewer_page_update_info (GthViewerPage *self,
GthFileData *file_data);
void gth_viewer_page_show_properties (GthViewerPage *self,
gboolean show);
gboolean gth_viewer_page_zoom_from_scroll (GthViewerPage *self,
GdkEventScroll *event);
void gth_viewer_page_file_loaded (GthViewerPage *self,
GthFileData *file_data,
GFileInfo *updated_metadata,
......
......@@ -131,6 +131,12 @@ typedef enum /*< skip >*/ {
} GthColorSpace;
typedef enum /*< skip >*/ {
GTH_ZOOM_IN,
GTH_ZOOM_OUT
} GthZoomType;
typedef enum /*< skip >*/ {
/* Shortcut handled by Gtk, not customizable, specified for
* documentation. */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment