changeset 1584:0cd2268f500b

improved pixel info, changed the menu entry from "Hide" to "Show", added it on default status bar
author nadvornik
date Sat, 02 May 2009 09:15:56 +0000
parents 70d59df4d2a2
children 15de7b420b69
files src/layout.c src/layout.h src/layout_image.c src/layout_util.c src/options.c src/pixbuf-renderer.c src/typedefs.h
diffstat 7 files changed, 68 insertions(+), 51 deletions(-) [+]
line wrap: on
line diff
--- a/src/layout.c	Fri May 01 23:40:01 2009 +0000
+++ b/src/layout.c	Sat May 02 09:15:56 2009 +0000
@@ -52,7 +52,6 @@
 #define TOOLWINDOW_DEF_HEIGHT 450
 
 #define PROGRESS_WIDTH 150
-#define PIXEL_LABEL_WIDTH 130
 #define ZOOM_LABEL_WIDTH 64
 
 #define PANE_DIVIDER_SIZE 10
@@ -605,16 +604,6 @@
 	gtk_box_pack_start(GTK_BOX(hbox), lw->info_sort, FALSE, FALSE, 0);
 	gtk_widget_show(lw->info_sort);
 
-	toolbar = layout_actions_toolbar(lw, TOOLBAR_STATUS);
-	
-	toolbar_frame = gtk_frame_new(NULL);
-	gtk_frame_set_shadow_type(GTK_FRAME(toolbar_frame), GTK_SHADOW_IN);
-	gtk_container_add(GTK_CONTAINER(toolbar_frame), toolbar);
-	gtk_widget_show(toolbar_frame);
-	gtk_widget_show(toolbar);
-
-	if (small_format) gtk_box_pack_end(GTK_BOX(hbox), toolbar_frame, FALSE, FALSE, 0);
-
 	lw->info_status = layout_status_label(NULL, lw->info_box, TRUE, 0, (!small_format));
 
 	if (small_format)
@@ -623,15 +612,24 @@
 		gtk_box_pack_start(GTK_BOX(lw->info_box), hbox, FALSE, FALSE, 0);
 		gtk_widget_show(hbox);
 		}
-	else
+	lw->info_details = layout_status_label(NULL, hbox, TRUE, 0, TRUE);
+	toolbar = layout_actions_toolbar(lw, TOOLBAR_STATUS);
+	
+	toolbar_frame = gtk_frame_new(NULL);
+	gtk_frame_set_shadow_type(GTK_FRAME(toolbar_frame), GTK_SHADOW_IN);
+	gtk_container_add(GTK_CONTAINER(toolbar_frame), toolbar);
+	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);
+	if (small_format)
 		{
-		hbox = lw->info_box;
+		hbox = gtk_hbox_new(FALSE, 0);
+		gtk_box_pack_start(GTK_BOX(lw->info_box), hbox, FALSE, FALSE, 0);
+		gtk_widget_show(hbox);
 		}
-	lw->info_details = layout_status_label(NULL, hbox, TRUE, 0, TRUE);
-	if (!small_format) gtk_box_pack_end(GTK_BOX(hbox), toolbar_frame, FALSE, FALSE, 0);
-	lw->info_pixel = layout_status_label(NULL, hbox, FALSE, PIXEL_LABEL_WIDTH, TRUE);
-	if (lw->options.info_pixel_hidden) gtk_widget_hide(gtk_widget_get_parent(lw->info_pixel));
-	lw->info_zoom = layout_status_label(NULL, hbox, FALSE, ZOOM_LABEL_WIDTH, FALSE);
+	lw->info_pixel = layout_status_label(NULL, hbox, FALSE, 0, small_format); /* expand only in small format */
+	if (!lw->options.show_info_pixel) gtk_widget_hide(gtk_widget_get_parent(lw->info_pixel));
 }
 
 /*
@@ -1708,24 +1706,26 @@
 		}
 }
 
-void layout_info_pixel_toggle(LayoutWindow *lw)
+void layout_info_pixel_set(LayoutWindow *lw, gboolean show)
 {
 	GtkWidget *frame;
 	
 	if (!layout_valid(&lw)) return;
 	if (!lw->info_pixel) return;
 
-	lw->options.info_pixel_hidden = !lw->options.info_pixel_hidden;
+	lw->options.show_info_pixel = show;
 
 	frame = gtk_widget_get_parent(lw->info_pixel);
-	if (lw->options.info_pixel_hidden)
+	if (!lw->options.show_info_pixel)
 		{
-		if (GTK_WIDGET_VISIBLE(frame)) gtk_widget_hide(frame);
+		gtk_widget_hide(frame);
 		}
 	else
 		{
-		if (!GTK_WIDGET_VISIBLE(frame)) gtk_widget_show(frame);
+		gtk_widget_show(frame);
 		}
+	
+	g_signal_emit_by_name (lw->image->pr, "update-pixel");
 }
 
 /*
@@ -2230,7 +2230,7 @@
 	WRITE_SEPARATOR();
 
 	WRITE_NL(); WRITE_BOOL(*layout, toolbar_hidden);
-	WRITE_NL(); WRITE_BOOL(*layout, info_pixel_hidden);
+	WRITE_NL(); WRITE_BOOL(*layout, show_info_pixel);
 
 	WRITE_NL(); WRITE_UINT(*layout, image_overlay.state);
 	WRITE_NL(); WRITE_INT(*layout, image_overlay.histogram_channel);
@@ -2301,7 +2301,7 @@
 		if (READ_BOOL(*layout, tools_float)) continue;
 		if (READ_BOOL(*layout, tools_hidden)) continue;
 		if (READ_BOOL(*layout, toolbar_hidden)) continue;
-		if (READ_BOOL(*layout, info_pixel_hidden)) continue;
+		if (READ_BOOL(*layout, show_info_pixel)) continue;
 
 		if (READ_UINT(*layout, image_overlay.state)) continue;
 		if (READ_INT(*layout, image_overlay.histogram_channel)) continue;
--- a/src/layout.h	Fri May 01 23:40:01 2009 +0000
+++ b/src/layout.h	Sat May 02 09:15:56 2009 +0000
@@ -105,7 +105,7 @@
 
 
 void layout_toolbar_toggle(LayoutWindow *lw);
-void layout_info_pixel_toggle(LayoutWindow *lw);
+void layout_info_pixel_set(LayoutWindow *lw, gboolean show);
 
 void layout_split_change(LayoutWindow *lw, ImageSplitMode mode);
 
--- a/src/layout_image.c	Fri May 01 23:40:01 2009 +0000
+++ b/src/layout_image.c	Sat May 02 09:15:56 2009 +0000
@@ -1540,42 +1540,44 @@
 {
 	LayoutWindow *lw = data;
 	gint x_pixel, y_pixel;
+	gint width, height;
+	gchar *text;
+	PangoAttrList *attrs;
 
 	if (!data || !layout_valid(&lw) || !lw->image
-	    || lw->options.info_pixel_hidden || lw->image->unknown) return;
-	
+	    || !lw->options.show_info_pixel || lw->image->unknown) return;
+
+	pixbuf_renderer_get_image_size(pr, &width, &height);
+	if (width < 1 || height < 1) return;
+
 	pixbuf_renderer_get_mouse_position(pr, &x_pixel, &y_pixel);
 	
 	if(x_pixel >= 0 && y_pixel >= 0)
 		{
 		gint r_mouse, g_mouse, b_mouse;
-		gint width, height;
-		gchar *text;
-		PangoAttrList *attrs;
 			
-		pixbuf_renderer_get_image_size(pr, &width, &height);
-		if (width < 1 || height < 1) return;
-		
 		pixbuf_renderer_get_pixel_colors(pr, x_pixel, y_pixel,
 						 &r_mouse, &g_mouse, &b_mouse);			
 		
-		attrs = pango_attr_list_new();
-		pango_attr_list_insert(attrs, pango_attr_family_new("Monospace"));
-		
-		text = g_strdup_printf(_("pos(%*d,%*d) rgb(%3d,%3d,%3d)"),
+		text = g_strdup_printf(_("[%*d,%*d]: RGB(%3d,%3d,%3d)"),
 					 num_length(width - 1), x_pixel,
 					 num_length(height - 1), y_pixel,
 					 r_mouse, g_mouse, b_mouse);
 		
-		gtk_label_set_text(GTK_LABEL(lw->info_pixel), text);
-		gtk_label_set_attributes(GTK_LABEL(lw->info_pixel), attrs);
-		pango_attr_list_unref(attrs);
-		g_free(text);
 		}
 	else
 		{
-		gtk_label_set_text(GTK_LABEL(lw->info_pixel), "");
+		text = g_strdup_printf(_("[%*s,%*s]: RGB(---,---,---)"),
+					 num_length(width - 1), " ",
+					 num_length(height - 1), " ");
 		}
+
+	attrs = pango_attr_list_new();
+	pango_attr_list_insert(attrs, pango_attr_family_new("Monospace"));
+	gtk_label_set_text(GTK_LABEL(lw->info_pixel), text);
+	gtk_label_set_attributes(GTK_LABEL(lw->info_pixel), attrs);
+	pango_attr_list_unref(attrs);
+	g_free(text);
 }
 
 
--- a/src/layout_util.c	Fri May 01 23:40:01 2009 +0000
+++ b/src/layout_util.c	Sat May 02 09:15:56 2009 +0000
@@ -701,10 +701,10 @@
 {
 	LayoutWindow *lw = data;
 
-	if (lw->options.info_pixel_hidden == gtk_toggle_action_get_active(action)) return;
+	if (lw->options.show_info_pixel == gtk_toggle_action_get_active(action)) return;
 
 	layout_exit_fullscreen(lw);
-	layout_info_pixel_toggle(lw);
+	layout_info_pixel_set(lw, !lw->options.show_info_pixel);
 }
 
 /* NOTE: these callbacks are called also from layout_util_sync_views */
@@ -1321,9 +1321,9 @@
 static GtkToggleActionEntry menu_toggle_entries[] = {
   { "Thumbnails",	PIXBUF_INLINE_ICON_THUMB,		N_("Show _Thumbnails"),	"T",		N_("Show Thumbnails"),	CB(layout_menu_thumb_cb),	 FALSE },
   { "ShowMarks",        NULL,		N_("Show _Marks"),	"M",		NULL,	CB(layout_menu_marks_cb),	 FALSE  },
+  { "ShowInfoPixel",	GTK_STOCK_COLOR_PICKER,		N_("Show Pi_xel Info"),	NULL,		NULL,	CB(layout_menu_info_pixel_cb),	 FALSE  },
   { "FloatTools",	PIXBUF_INLINE_ICON_FLOAT,		N_("_Float file list"),	"L",		NULL,	CB(layout_menu_float_cb),	 FALSE  },
   { "HideToolbar",	NULL,		N_("Hide tool_bar"),	NULL,		NULL,	CB(layout_menu_toolbar_cb),	 FALSE  },
-  { "HideInfoPixel",	NULL,		N_("Hide Pi_xel Info"),	NULL,		NULL,	CB(layout_menu_info_pixel_cb),	 FALSE  },
   { "SBar",		NULL,		N_("_Info"),		"<control>K",	NULL,	CB(layout_menu_bar_cb),		 FALSE  },
   { "SBarSort",		NULL,		N_("Sort _manager"),	"<shift>S",	NULL,	CB(layout_menu_bar_sort_cb),	 FALSE  },
   { "SlideShow",	NULL,		N_("Toggle _slideshow"),"S",		NULL,	CB(layout_menu_slideshow_cb),	 FALSE  },
@@ -1506,7 +1506,7 @@
 "      <menuitem action='FloatTools'/>"
 "      <menuitem action='HideTools'/>"
 "      <menuitem action='HideToolbar'/>"
-"      <menuitem action='HideInfoPixel'/>"
+"      <menuitem action='ShowInfoPixel'/>"
 "      <placeholder name='ToolsSection'/>"
 "      <separator/>"
 "      <menuitem action='SBar'/>"
@@ -1959,6 +1959,7 @@
 			layout_toolbar_add(lw, type, "FloatTools");
 			break;
 		case TOOLBAR_STATUS:
+			layout_toolbar_add(lw, type, "ShowInfoPixel");
 			layout_toolbar_add(lw, type, "UseColorProfiles");
 			layout_toolbar_add(lw, type, "SaveMetadata");
 			break;
@@ -2158,8 +2159,8 @@
 	action = gtk_action_group_get_action(lw->action_group, "HideToolbar");
 	gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.toolbar_hidden);
 	
-	action = gtk_action_group_get_action(lw->action_group, "HideInfoPixel");
-	gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.info_pixel_hidden);
+	action = gtk_action_group_get_action(lw->action_group, "ShowInfoPixel");
+	gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.show_info_pixel);
 
 	action = gtk_action_group_get_action(lw->action_group, "ShowMarks");
 	gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.show_marks);
--- a/src/options.c	Fri May 01 23:40:01 2009 +0000
+++ b/src/options.c	Sat May 02 09:15:56 2009 +0000
@@ -202,7 +202,7 @@
 	options->show_marks = FALSE;
 	options->show_thumbnails = FALSE;
 	options->style = 0;
-	options->info_pixel_hidden = TRUE;
+	options->show_info_pixel = FALSE;
 	options->toolbar_hidden = FALSE;
 	options->tools_float = FALSE;
 	options->tools_hidden = FALSE;
--- a/src/pixbuf-renderer.c	Fri May 01 23:40:01 2009 +0000
+++ b/src/pixbuf-renderer.c	Sat May 02 09:15:56 2009 +0000
@@ -3759,6 +3759,18 @@
 	return FALSE;
 }
 
+static gboolean pr_leave_notify_cb(GtkWidget *widget, GdkEventCrossing *cevent, gpointer data)
+{
+	PixbufRenderer *pr;
+
+	pr = PIXBUF_RENDERER(widget);
+	pr->x_mouse = -1;
+	pr->y_mouse = -1;
+
+	pr_update_pixel_signal(pr);
+	return FALSE;
+}
+
 static gboolean pr_mouse_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
 {
 	PixbufRenderer *pr;
@@ -3873,6 +3885,8 @@
 			 G_CALLBACK(pr_mouse_leave_cb), pr);
 	g_signal_connect(G_OBJECT(pr), "hierarchy-changed",
 			 G_CALLBACK(pr_hierarchy_changed_cb), pr);
+	g_signal_connect(G_OBJECT(pr), "leave_notify_event",
+			 G_CALLBACK(pr_leave_notify_cb), pr);
 
 	gtk_widget_set_events(GTK_WIDGET(pr), GDK_POINTER_MOTION_MASK |
 					      GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_PRESS_MASK |
--- a/src/typedefs.h	Fri May 01 23:40:01 2009 +0000
+++ b/src/typedefs.h	Sat May 02 09:15:56 2009 +0000
@@ -503,6 +503,7 @@
 	gboolean show_thumbnails;
 	gboolean show_marks;
 	gboolean show_directory_date;
+	gboolean show_info_pixel;
 
 	struct {
 		gint w;
@@ -536,7 +537,6 @@
 	gboolean tools_float;
 	gboolean tools_hidden;
 	gboolean toolbar_hidden;
-	gboolean info_pixel_hidden;
 
 	gchar *home_path;
 	gchar *last_path;