[Xfce4-commits] <ristretto:ristretto-0.0> Implement scrollwheel-action on picture-viewer
Stephan Arts
noreply at xfce.org
Sun Oct 23 19:17:45 CEST 2011
Updating branch refs/heads/ristretto-0.0
to 692ce7e6229f1ef0e4a4867447567cb316d36d9e (commit)
from 5ac321c922b325dc603e2c91ab82589be34f0e17 (commit)
commit 692ce7e6229f1ef0e4a4867447567cb316d36d9e
Author: Stephan Arts <stephan at xfce.org>
Date: Sat Sep 5 08:00:47 2009 +0200
Implement scrollwheel-action on picture-viewer
ChangeLog | 6 +++
src/picture_viewer.c | 113 +++++++++++++++++++++++++++-------------------
src/preferences_dialog.c | 102 ++++++++++++++++++++++++++++++++++++-----
src/settings.c | 42 +++++++++++++-----
4 files changed, 193 insertions(+), 70 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 67b4578..42d2d65 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
2009-09-05 Stephan Arts <stephan at xfce.org>
+ * src/picture_viewer.c,
+ src/settings.c,
+ src/preferences_dialog.c: Implement scrollwheel action on picture-viewer
+
+2009-09-05 Stephan Arts <stephan at xfce.org>
+
* src/main_window.c,
src/settings.c,
src/settings.h: Add convenience-functions for setting properties
diff --git a/src/picture_viewer.c b/src/picture_viewer.c
index 666a405..d8ad98e 100644
--- a/src/picture_viewer.c
+++ b/src/picture_viewer.c
@@ -67,6 +67,7 @@ struct _RsttoPictureViewerPriv
GtkMenu *menu;
RsttoPictureViewerState state;
RsttoZoomMode zoom_mode;
+ RsttoSettings *settings;
GdkPixbuf *dst_pixbuf; /* The pixbuf which ends up on screen */
@@ -195,6 +196,7 @@ rstto_picture_viewer_init(RsttoPictureViewer *viewer)
viewer->priv->cb_value_changed = cb_rstto_picture_viewer_value_changed;
viewer->priv->dst_pixbuf = NULL;
+ viewer->priv->settings = rstto_settings_new();
viewer->priv->zoom_mode = RSTTO_ZOOM_MODE_CUSTOM;
gtk_widget_set_redraw_on_allocate(GTK_WIDGET(viewer), TRUE);
gtk_widget_set_events (GTK_WIDGET(viewer),
@@ -407,7 +409,6 @@ rstto_picture_viewer_expose(GtkWidget *widget, GdkEventExpose *event)
static void
rstto_picture_viewer_paint (GtkWidget *widget)
{
- RsttoSettings *settings_manager = rstto_settings_new();
RsttoPictureViewer *viewer = RSTTO_PICTURE_VIEWER(widget);
GdkPixbuf *pixbuf = viewer->priv->dst_pixbuf;
GdkColor color;
@@ -421,10 +422,10 @@ rstto_picture_viewer_paint (GtkWidget *widget)
g_value_init (&val_bg_color_fs, GDK_TYPE_COLOR);
g_value_init (&val_bg_color_override, G_TYPE_BOOLEAN);
- g_object_get_property (G_OBJECT(settings_manager), "bgcolor", &val_bg_color);
- g_object_get_property (G_OBJECT(settings_manager), "bgcolor-override", &val_bg_color_override);
+ g_object_get_property (G_OBJECT(viewer->priv->settings), "bgcolor", &val_bg_color);
+ g_object_get_property (G_OBJECT(viewer->priv->settings), "bgcolor-override", &val_bg_color_override);
- g_object_get_property (G_OBJECT(settings_manager), "bgcolor-fullscreen", &val_bg_color_fs);
+ g_object_get_property (G_OBJECT(viewer->priv->settings), "bgcolor-fullscreen", &val_bg_color_fs);
color.pixel = 0x0;
@@ -643,13 +644,16 @@ rstto_picture_viewer_paint (GtkWidget *widget)
widget->allocation.height);
g_object_unref(buffer);
}
- g_object_unref (settings_manager);
}
static void
rstto_picture_viewer_destroy(GtkObject *object)
{
-
+ if (RSTTO_PICTURE_VIEWER (object)->priv->settings)
+ {
+ g_object_unref (RSTTO_PICTURE_VIEWER (object)->priv->settings);
+ RSTTO_PICTURE_VIEWER (object)->priv->settings = NULL;
+ }
}
static gboolean
@@ -817,56 +821,75 @@ rstto_picture_viewer_calculate_scale (RsttoPictureViewer *viewer)
static void
cb_rstto_picture_viewer_scroll_event (RsttoPictureViewer *viewer, GdkEventScroll *event)
{
- /*
- RsttoImageListEntry *entry = rstto_image_list_get_file(viewer->priv->image_list);
+ gchar *scrollwheel_action = NULL;
+ gdouble *p_scale = NULL;
+ gboolean *p_fit_to_screen= NULL;
- if (entry == NULL)
- {
- return;
- }
+ scrollwheel_action = rstto_settings_get_string_property (viewer->priv->settings, "scrollwheel-primary-action");
- gdouble scale = rstto_image_list_entry_get_scale(entry);
- viewer->priv->zoom_mode = RSTTO_ZOOM_MODE_CUSTOM;
- switch(event->direction)
+ if (scrollwheel_action)
{
- case GDK_SCROLL_UP:
- case GDK_SCROLL_LEFT:
- if (scale= 0.05)
- return;
- if (viewer->priv->refresh.idle_id > 0)
+ /** Zoom **/
+ if (!strcmp (scrollwheel_action, "zoom"))
+ {
+ viewer->priv->zoom_mode = RSTTO_ZOOM_MODE_CUSTOM;
+ p_scale = g_object_get_data (G_OBJECT (viewer->priv->image), "viewer-scale");
+ p_fit_to_screen = g_object_get_data (G_OBJECT (viewer->priv->image), "viewer-fit-to-screen");
+ *p_fit_to_screen = FALSE;
+ switch(event->direction)
{
- g_source_remove(viewer->priv->refresh.idle_id);
- }
- rstto_image_list_entry_set_scale(entry, scale / 1.1);
- rstto_image_list_entry_set_fit_to_screen (entry, FALSE);
+ case GDK_SCROLL_UP:
+ case GDK_SCROLL_LEFT:
+ if (*p_scale <= 0.05)
+ return;
+ if (viewer->priv->repaint.idle_id > 0)
+ {
+ g_source_remove(viewer->priv->repaint.idle_id);
+ }
- viewer->vadjustment->value = ((viewer->vadjustment->value + event->y) / 1.1) - event->y;
- viewer->hadjustment->value = ((viewer->hadjustment->value + event->x) / 1.1) - event->x;
+ *p_scale = *p_scale / 1.1;
+ viewer->vadjustment->value = ((viewer->vadjustment->value + event->y) / 1.1) - event->y;
+ viewer->hadjustment->value = ((viewer->hadjustment->value + event->x) / 1.1) - event->x;
- viewer->priv->refresh.idle_id = g_idle_add((GSourceFunc)cb_rstto_picture_viewer_queued_repaint, viewer);
- break;
- case GDK_SCROLL_DOWN:
- case GDK_SCROLL_RIGHT:
- if (scale >= 16)
- return;
- if (viewer->priv->refresh.idle_id > 0)
- {
- g_source_remove(viewer->priv->refresh.idle_id);
- }
- rstto_image_list_entry_set_scale(entry, scale * 1.1);
- rstto_image_list_entry_set_fit_to_screen (entry, FALSE);
+ break;
+ case GDK_SCROLL_DOWN:
+ case GDK_SCROLL_RIGHT:
+ if (*p_scale >= 16.0)
+ return;
+ if (viewer->priv->repaint.idle_id > 0)
+ {
+ g_source_remove(viewer->priv->repaint.idle_id);
+ }
+ *p_scale = *p_scale * 1.1;
- viewer->vadjustment->value = ((viewer->vadjustment->value + event->y) * 1.1) - event->y;
- viewer->hadjustment->value = ((viewer->hadjustment->value + event->x) * 1.1) - event->x;
+ viewer->vadjustment->value = ((viewer->vadjustment->value + event->y) * 1.1) - event->y;
+ viewer->hadjustment->value = ((viewer->hadjustment->value + event->x) * 1.1) - event->x;
+ break;
+ }
gtk_adjustment_value_changed(viewer->hadjustment);
gtk_adjustment_value_changed(viewer->vadjustment);
+ viewer->priv->repaint.idle_id = g_idle_add((GSourceFunc)cb_rstto_picture_viewer_queued_repaint, viewer);
+ }
- viewer->priv->refresh.idle_id = g_idle_add((GSourceFunc)cb_rstto_picture_viewer_queued_repaint, viewer);
- break;
+ /** Navigate **/
+ if (!strcmp (scrollwheel_action, "switch"))
+ {
+ viewer->priv->zoom_mode = RSTTO_ZOOM_MODE_CUSTOM;
+ switch(event->direction)
+ {
+ case GDK_SCROLL_UP:
+ case GDK_SCROLL_LEFT:
+ rstto_image_list_iter_previous (viewer->priv->iter);
+ break;
+ case GDK_SCROLL_DOWN:
+ case GDK_SCROLL_RIGHT:
+ rstto_image_list_iter_next (viewer->priv->iter);
+ break;
+ }
+ }
}
- */
}
static gboolean
@@ -1437,11 +1460,10 @@ rstto_picture_viewer_set_image (RsttoPictureViewer *viewer, RsttoImage *image)
gdouble *scale = NULL;
gboolean *fit_to_screen = NULL;
- RsttoSettings *settings_manager = rstto_settings_new();
GValue max_size = {0,};
g_value_init (&max_size, G_TYPE_UINT);
- g_object_get_property (G_OBJECT(settings_manager), "image-quality", &max_size);
+ g_object_get_property (G_OBJECT(viewer->priv->settings), "image-quality", &max_size);
if (viewer->priv->image)
{
@@ -1480,7 +1502,6 @@ rstto_picture_viewer_set_image (RsttoPictureViewer *viewer, RsttoImage *image)
{
rstto_picture_viewer_queued_repaint (viewer, TRUE);
}
- g_object_unref (settings_manager);
}
/**
diff --git a/src/preferences_dialog.c b/src/preferences_dialog.c
index 4b34610..9fbeb7e 100644
--- a/src/preferences_dialog.c
+++ b/src/preferences_dialog.c
@@ -51,6 +51,12 @@ static void
cb_rstto_preferences_dialog_cache_spin_button_value_changed (GtkSpinButton *, gpointer);
static void
cb_rstto_preferences_dialog_image_quality_combo_box_changed (GtkComboBox *, gpointer);
+static void
+cb_rstto_preferences_dialog_no_scrollwheel_action_radio_button_toggled (GtkToggleButton *, gpointer);
+static void
+cb_rstto_preferences_dialog_zoom_scrollwheel_action_radio_button_toggled (GtkToggleButton *, gpointer);
+static void
+cb_rstto_preferences_dialog_switch_scrollwheel_action_radio_button_toggled (GtkToggleButton *, gpointer );
static GtkWidgetClass *parent_class = NULL;
@@ -76,6 +82,11 @@ struct _RsttoPreferencesDialogPriv
struct
{
+ GtkWidget *scroll_frame;
+ GtkWidget *scroll_vbox;
+ GtkWidget *no_scrollwheel_action_radio_button;
+ GtkWidget *zoom_scrollwheel_action_radio_button;
+ GtkWidget *switch_scrollwheel_action_radio_button;
} control_tab;
struct
@@ -128,8 +139,8 @@ rstto_preferences_dialog_init(RsttoPreferencesDialog *dialog)
guint uint_preload_images;
gboolean bool_enable_cache;
gboolean bool_bgcolor_override;
+ gchar *scrollwheel_primary_action;
GdkColor *bgcolor;
- GtkWidget *scroll_frame, *scroll_vbox;
GtkWidget *timeout_frame, *timeout_vbox, *timeout_lbl, *timeout_hscale;
GtkWidget *scaling_frame, *scaling_vbox;
GtkWidget *widget;
@@ -155,6 +166,7 @@ rstto_preferences_dialog_init(RsttoPreferencesDialog *dialog)
"enable-cache", &bool_enable_cache,
"bgcolor-override", &bool_bgcolor_override,
"bgcolor", &bgcolor,
+ "scrollwheel-primary-action", &scrollwheel_primary_action,
NULL);
/*****************/
@@ -206,7 +218,7 @@ rstto_preferences_dialog_init(RsttoPreferencesDialog *dialog)
dialog->priv->display_tab.image_quality_hbox= gtk_hbox_new (FALSE, 4);
dialog->priv->display_tab.image_quality_combo= gtk_combo_box_new_text ();
- gtk_combo_box_append_text (GTK_COMBO_BOX (dialog->priv->display_tab.image_quality_combo), _("Really High"));
+ gtk_combo_box_append_text (GTK_COMBO_BOX (dialog->priv->display_tab.image_quality_combo), _("Best"));
gtk_combo_box_append_text (GTK_COMBO_BOX (dialog->priv->display_tab.image_quality_combo), _("High"));
gtk_combo_box_append_text (GTK_COMBO_BOX (dialog->priv->display_tab.image_quality_combo), _("Medium"));
gtk_combo_box_append_text (GTK_COMBO_BOX (dialog->priv->display_tab.image_quality_combo), _("Low"));
@@ -255,7 +267,6 @@ rstto_preferences_dialog_init(RsttoPreferencesDialog *dialog)
timeout_frame = xfce_create_framebox_with_content (_("Timeout"), timeout_vbox);
gtk_box_pack_start (GTK_BOX (slideshow_main_vbox), timeout_frame, FALSE, FALSE, 0);
-
timeout_lbl = gtk_label_new(_("The time period an individual image is displayed during a slideshow\n(in seconds)"));
timeout_hscale = gtk_hscale_new_with_range(1, 60, 1);
gtk_misc_set_alignment(GTK_MISC(timeout_lbl), 0, 0.5);
@@ -270,18 +281,47 @@ rstto_preferences_dialog_init(RsttoPreferencesDialog *dialog)
control_main_lbl = gtk_label_new(_("Control"));
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), control_main_vbox, control_main_lbl);
- scroll_vbox = gtk_vbox_new(FALSE, 0);
- scroll_frame = xfce_create_framebox_with_content (_("Scrollwheel"), scroll_vbox);
- gtk_box_pack_start (GTK_BOX (control_main_vbox), scroll_frame, FALSE, FALSE, 0);
- gtk_widget_set_sensitive (scroll_vbox, FALSE);
+ dialog->priv->control_tab.scroll_vbox = gtk_vbox_new(FALSE, 0);
+ dialog->priv->control_tab.scroll_frame = xfce_create_framebox_with_content (_("Scrollwheel"), dialog->priv->control_tab.scroll_vbox);
+ gtk_box_pack_start (GTK_BOX (control_main_vbox), dialog->priv->control_tab.scroll_frame, FALSE, FALSE, 0);
+
+ dialog->priv->control_tab.no_scrollwheel_action_radio_button = gtk_radio_button_new_with_label (NULL, _("No action"));
+ gtk_container_add (GTK_CONTAINER (dialog->priv->control_tab.scroll_vbox), dialog->priv->control_tab.no_scrollwheel_action_radio_button);
+
- widget = gtk_radio_button_new_with_label (NULL, _("No action"));
- gtk_container_add (GTK_CONTAINER (scroll_vbox), widget);
- widget = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (widget), _("Zoom in and out"));
- gtk_container_add (GTK_CONTAINER (scroll_vbox), widget);
- widget = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (widget), _("Switch images"));
- gtk_container_add (GTK_CONTAINER (scroll_vbox), widget);
+ dialog->priv->control_tab.zoom_scrollwheel_action_radio_button = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (dialog->priv->control_tab.no_scrollwheel_action_radio_button), _("Zoom in and out"));
+ gtk_container_add (GTK_CONTAINER (dialog->priv->control_tab.scroll_vbox), dialog->priv->control_tab.zoom_scrollwheel_action_radio_button);
+
+ dialog->priv->control_tab.switch_scrollwheel_action_radio_button = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (dialog->priv->control_tab.no_scrollwheel_action_radio_button), _("Switch images"));
+ gtk_container_add (GTK_CONTAINER (dialog->priv->control_tab.scroll_vbox), dialog->priv->control_tab.switch_scrollwheel_action_radio_button);
+
+ if (scrollwheel_primary_action)
+ {
+ if (!strcmp (scrollwheel_primary_action, "zoom"))
+ {
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->control_tab.zoom_scrollwheel_action_radio_button), TRUE);
+ }
+ else if (!strcmp (scrollwheel_primary_action, "switch"))
+ {
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->control_tab.switch_scrollwheel_action_radio_button), TRUE);
+ }
+ else
+ {
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->control_tab.no_scrollwheel_action_radio_button), TRUE);
+ }
+ }
+ else
+ {
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->control_tab.no_scrollwheel_action_radio_button), TRUE);
+ }
+
+ g_signal_connect (G_OBJECT (dialog->priv->control_tab.no_scrollwheel_action_radio_button),
+ "toggled", (GCallback)cb_rstto_preferences_dialog_no_scrollwheel_action_radio_button_toggled, dialog);
+ g_signal_connect (G_OBJECT (dialog->priv->control_tab.zoom_scrollwheel_action_radio_button),
+ "toggled", (GCallback)cb_rstto_preferences_dialog_zoom_scrollwheel_action_radio_button_toggled, dialog);
+ g_signal_connect (G_OBJECT (dialog->priv->control_tab.switch_scrollwheel_action_radio_button),
+ "toggled", (GCallback)cb_rstto_preferences_dialog_switch_scrollwheel_action_radio_button_toggled, dialog);
/*******************/
/** Behaviour tab **/
/*******************/
@@ -521,3 +561,39 @@ cb_rstto_preferences_dialog_image_quality_combo_box_changed (GtkComboBox *combo_
break;
}
}
+
+static void
+cb_rstto_preferences_dialog_no_scrollwheel_action_radio_button_toggled (GtkToggleButton *button,
+ gpointer user_data)
+{
+ RsttoPreferencesDialog *dialog = RSTTO_PREFERENCES_DIALOG (user_data);
+
+ if (gtk_toggle_button_get_active (button))
+ {
+ rstto_settings_set_string_property (dialog->priv->settings, "scrollwheel-primary-action", "none");
+ }
+}
+
+static void
+cb_rstto_preferences_dialog_zoom_scrollwheel_action_radio_button_toggled (GtkToggleButton *button,
+ gpointer user_data)
+{
+ RsttoPreferencesDialog *dialog = RSTTO_PREFERENCES_DIALOG (user_data);
+
+ if (gtk_toggle_button_get_active (button))
+ {
+ rstto_settings_set_string_property (dialog->priv->settings, "scrollwheel-primary-action", "zoom");
+ }
+}
+
+static void
+cb_rstto_preferences_dialog_switch_scrollwheel_action_radio_button_toggled (GtkToggleButton *button,
+ gpointer user_data)
+{
+ RsttoPreferencesDialog *dialog = RSTTO_PREFERENCES_DIALOG (user_data);
+
+ if (gtk_toggle_button_get_active (button))
+ {
+ rstto_settings_set_string_property (dialog->priv->settings, "scrollwheel-primary-action", "switch");
+ }
+}
diff --git a/src/settings.c b/src/settings.c
index 39cfef2..e9bd00f 100644
--- a/src/settings.c
+++ b/src/settings.c
@@ -69,7 +69,8 @@ enum
PROP_BGCOLOR_FULLSCREEN,
PROP_CURRENT_URI,
PROP_SLIDESHOW_TIMEOUT,
- PROP_SCROLLWHEEL_ACTION,
+ PROP_SCROLLWHEEL_PRIMARY_ACTION,
+ PROP_SCROLLWHEEL_SECONDARY_ACTION,
};
GType
@@ -117,7 +118,8 @@ struct _RsttoSettingsPriv
GdkColor *bgcolor;
gboolean bgcolor_override;
GdkColor *bgcolor_fullscreen;
- gchar *scrollwheel_action;
+ gchar *scrollwheel_primary_action;
+ gchar *scrollwheel_secondary_action;
};
@@ -153,7 +155,8 @@ rstto_settings_init (GObject *object)
xfconf_g_property_bind (settings->priv->channel, "/window/show-navigation-toolbar", G_TYPE_BOOLEAN, settings, "show-nav-toolbar");
xfconf_g_property_bind (settings->priv->channel, "/window/show-thumbnailbar", G_TYPE_BOOLEAN, settings, "show-thumbnailbar");
xfconf_g_property_bind (settings->priv->channel, "/window/navigationbar-position", G_TYPE_STRING, settings, "navigationbar-position");
- xfconf_g_property_bind (settings->priv->channel, "/window/scrollwheel-action", G_TYPE_STRING, settings, "scrollwheel-action");
+ xfconf_g_property_bind (settings->priv->channel, "/window/scrollwheel-primary-action", G_TYPE_STRING, settings, "scrollwheel-primary-action");
+ xfconf_g_property_bind (settings->priv->channel, "/window/scrollwheel-secondary-action", G_TYPE_STRING, settings, "scrollwheel-secondary-action");
xfconf_g_property_bind (settings->priv->channel, "/slideshow/timeout", G_TYPE_UINT, settings, "slideshow-timeout");
@@ -292,13 +295,22 @@ rstto_settings_class_init (GObjectClass *object_class)
PROP_CURRENT_URI,
pspec);
- pspec = g_param_spec_string ("scrollwheel-action",
+ pspec = g_param_spec_string ("scrollwheel-primary-action",
+ "",
+ "",
+ "navigate",
+ G_PARAM_READWRITE);
+ g_object_class_install_property (object_class,
+ PROP_SCROLLWHEEL_PRIMARY_ACTION,
+ pspec);
+
+ pspec = g_param_spec_string ("scrollwheel-secondary-action",
"",
"",
"zoom",
G_PARAM_READWRITE);
g_object_class_install_property (object_class,
- PROP_CURRENT_URI,
+ PROP_SCROLLWHEEL_SECONDARY_ACTION,
pspec);
pspec = g_param_spec_uint ("slideshow-timeout",
@@ -477,10 +489,15 @@ rstto_settings_set_property (GObject *object,
settings->priv->bgcolor_fullscreen->green = color->green;
settings->priv->bgcolor_fullscreen->blue = color->blue;
break;
- case PROP_SCROLLWHEEL_ACTION:
- if (settings->priv->scrollwheel_action)
- g_free (settings->priv->scrollwheel_action);
- settings->priv->scrollwheel_action = g_value_dup_string (value);
+ case PROP_SCROLLWHEEL_PRIMARY_ACTION:
+ if (settings->priv->scrollwheel_primary_action)
+ g_free (settings->priv->scrollwheel_primary_action);
+ settings->priv->scrollwheel_primary_action = g_value_dup_string (value);
+ break;
+ case PROP_SCROLLWHEEL_SECONDARY_ACTION:
+ if (settings->priv->scrollwheel_secondary_action)
+ g_free (settings->priv->scrollwheel_secondary_action);
+ settings->priv->scrollwheel_secondary_action = g_value_dup_string (value);
break;
default:
break;
@@ -543,8 +560,11 @@ rstto_settings_get_property (GObject *object,
case PROP_BGCOLOR_OVERRIDE:
g_value_set_boolean (value, settings->priv->bgcolor_override);
break;
- case PROP_SCROLLWHEEL_ACTION:
- g_value_set_string (value, settings->priv->scrollwheel_action);
+ case PROP_SCROLLWHEEL_PRIMARY_ACTION:
+ g_value_set_string (value, settings->priv->scrollwheel_primary_action);
+ break;
+ case PROP_SCROLLWHEEL_SECONDARY_ACTION:
+ g_value_set_string (value, settings->priv->scrollwheel_secondary_action);
break;
default:
break;
More information about the Xfce4-commits
mailing list