Patch: zoom slider in spatial windows
- From: "Rached Ben Mustapha" <benmur gmail com>
- To: nautilus-list gnome org
- Subject: Patch: zoom slider in spatial windows
- Date: Sat, 24 Feb 2007 16:34:49 +0100
Hi,
I often find myself adjusting the zoom level of spatial windows, based
on the number of files they contain. I tried to implement a zoom
slider, as can be seen in some applications these days [1] [2].
I found the result quite usable, but maybe I'm biased. It clutters
some quite simple windows, for a feature that maybe not so many people
use, however. The zoom images could look better with a tooltip and
prelighting.
Anyway, I thought I'd share, so I attached the patch (screenshot at [3]).
Enjoy,
Rached
[1] http://f-spot.org/Image:Main-window.png
[2] http://www.mac.com/1/images/howto_iphoto_screenshot.jpg
[3] http://benmur.free.fr/files/nautilus-spatial-zoom-slider.png
=== modified file 'src/nautilus-spatial-window.c'
--- src/nautilus-spatial-window.c 2006-12-26 15:28:10 +0000
+++ src/nautilus-spatial-window.c 2007-02-24 15:13:38 +0000
@@ -91,6 +91,7 @@
GtkWidget *location_button;
GtkWidget *location_label;
GtkWidget *location_icon;
+ GtkWidget *zoom_slider;
GtkWidget *query_editor;
@@ -424,11 +425,87 @@
}
static void
+zoom_in_image_clicked (GtkWidget *widget, GdkEventButton *event, NautilusView *view)
+{
+ nautilus_view_bump_zoom_level (view, 1);
+}
+
+static void
+zoom_out_image_clicked (GtkWidget *widget, GdkEventButton *event, NautilusView *view)
+{
+ nautilus_view_bump_zoom_level (view, -1);
+}
+
+static void
+update_zoom_slider_value (NautilusView *view, GtkRange *range)
+{
+ NautilusZoomLevel zoom_level;
+
+ zoom_level = nautilus_view_get_zoom_level (view);
+ gtk_range_set_value (range, zoom_level);
+}
+
+static void
+zoom_slider_value_changed (GtkRange *range, NautilusView *view)
+{
+ NautilusZoomLevel zoom_level;
+
+ zoom_level = (NautilusZoomLevel) gtk_range_get_value (range);
+ g_signal_handlers_block_by_func (view, update_zoom_slider_value, range);
+ nautilus_view_zoom_to_level (view, zoom_level);
+ g_signal_handlers_unblock_by_func (view, update_zoom_slider_value, range);
+}
+
+static GtkWidget *
+create_zoom_slider_widget_for_view (NautilusView *view)
+{
+ GtkWidget *box, *scale;
+ GtkWidget *zoom_in_image, *zoom_in_event_box;
+ GtkWidget *zoom_out_image, *zoom_out_event_box;
+
+ box = gtk_hbox_new (FALSE, 0);
+
+ zoom_in_image = gtk_image_new_from_stock (GTK_STOCK_ZOOM_IN, GTK_ICON_SIZE_MENU);
+ zoom_in_event_box = gtk_event_box_new ();
+ gtk_container_add (GTK_CONTAINER (zoom_in_event_box), zoom_in_image);
+ g_signal_connect (G_OBJECT (zoom_in_event_box), "button-press-event", G_CALLBACK (zoom_in_image_clicked), view);
+
+ scale = gtk_hscale_new_with_range (NAUTILUS_ZOOM_LEVEL_SMALLEST, NAUTILUS_ZOOM_LEVEL_LARGEST, 1);
+ gtk_widget_set_size_request (scale, 100, -1); /* This is arbitrary */
+ gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
+ gtk_scale_set_digits (GTK_SCALE (scale), 0);
+ g_object_set (scale, "update-policy", GTK_UPDATE_CONTINUOUS, NULL);
+ g_signal_connect (scale, "value-changed", G_CALLBACK (zoom_slider_value_changed), view);
+ g_signal_connect (view, "zoom_level_changed", G_CALLBACK (update_zoom_slider_value), scale);
+
+ zoom_out_image = gtk_image_new_from_stock (GTK_STOCK_ZOOM_OUT, GTK_ICON_SIZE_MENU);
+ zoom_out_event_box = gtk_event_box_new ();
+ gtk_container_add (GTK_CONTAINER (zoom_out_event_box), zoom_out_image);
+ g_signal_connect (G_OBJECT (zoom_out_event_box), "button-press-event", G_CALLBACK (zoom_out_image_clicked), view);
+
+ gtk_box_pack_end (GTK_BOX (box), zoom_in_event_box, FALSE, FALSE, 0);
+ gtk_box_pack_end (GTK_BOX (box), scale, TRUE, TRUE, 0);
+ gtk_box_pack_end (GTK_BOX (box), zoom_out_event_box, FALSE, FALSE, 0);
+
+ gtk_widget_show_all (box);
+
+ return box;
+}
+
+static void
real_set_content_view_widget (NautilusWindow *window,
NautilusView *new_view)
{
GtkWidget *widget;
+ GtkWidget *zoom_slider;
+
+ zoom_slider = NAUTILUS_SPATIAL_WINDOW (window)->details->zoom_slider;
+ if (zoom_slider != NULL) {
+ gtk_widget_destroy (zoom_slider);
+ NAUTILUS_SPATIAL_WINDOW (window)->details->zoom_slider = NULL;
+ }
+
EEL_CALL_PARENT (NAUTILUS_WINDOW_CLASS, set_content_view_widget,
(window, new_view));
@@ -436,6 +513,12 @@
gtk_container_add (GTK_CONTAINER (NAUTILUS_SPATIAL_WINDOW (window)->details->content_box),
widget);
+
+ if (nautilus_view_supports_zooming (new_view)) {
+ zoom_slider = create_zoom_slider_widget_for_view (new_view);
+ gtk_box_pack_end (GTK_BOX (window->details->statusbar), zoom_slider, FALSE, FALSE, 0);
+ NAUTILUS_SPATIAL_WINDOW (window)->details->zoom_slider = zoom_slider;
+ }
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]