[glabels/vala] Initial hookup of label to object editor.



commit 066c7ed4e4e7d8c79abf9e30892b37fba6980017
Author: Jim Evins <evins snaught com>
Date:   Wed Mar 14 00:28:21 2012 -0400

    Initial hookup of label to object editor.

 glabels/object_editor.vala |  208 ++++++++++++++++++++++++++++++++++++++-----
 glabels/units_util.vala    |   20 ++--
 glabels/window.vala        |    2 +
 3 files changed, 195 insertions(+), 35 deletions(-)
---
diff --git a/glabels/object_editor.vala b/glabels/object_editor.vala
index b18674f..cb462cf 100644
--- a/glabels/object_editor.vala
+++ b/glabels/object_editor.vala
@@ -26,7 +26,32 @@ namespace glabels
 
 	class ObjectEditor : Gtk.Box
 	{
-		private Prefs prefs;
+		private Prefs           prefs;
+
+		private Label           label;
+
+
+		public double           line_width        { get; set; }
+		public ColorNode        line_color_node   { get; set; }
+
+		public ColorNode        fill_color_node   { get; set; }
+
+		public double           x                 { get; set; }
+		public double           y                 { get; set; }
+
+		public double           w                 { get; set; }
+		public double           h                 { get; set; }
+
+		public bool             shadow_enable     { get; set; }
+		public double           shadow_x          { get; set; }
+		public double           shadow_y          { get; set; }
+		public ColorNode        shadow_color_node { get; set; }
+		public double           shadow_opacity    { get; set; }
+
+
+		private double          w_max;
+		private double          h_max;
+
 
 		private Gtk.Image       title_image;
 		private Gtk.Label       title_label;
@@ -52,7 +77,8 @@ namespace glabels
 		private Gtk.SpinButton  size_h_spin;
 		private Gtk.Label       size_w_units_label;
 		private Gtk.Label       size_h_units_label;
-		/* TODO: aspect lock, and image reset */
+		private Gtk.CheckButton size_aspect_check;
+		private Gtk.Button      size_reset_image_button;
 
 		private Gtk.CheckButton shadow_enable_check;
 		private Gtk.Grid        shadow_controls_grid;
@@ -67,8 +93,6 @@ namespace glabels
 
 		public ObjectEditor()
 		{
-			prefs = new Prefs();
-
 			/* Load the user interface. */
 			Gtk.Builder builder = new Gtk.Builder();
 			try
@@ -102,41 +126,175 @@ namespace glabels
 			title_label.set_use_markup( true );
 			title_label.set_sensitive( false );
 
+			line_fill_page_box = builder.get_object( "line_fill_page_box" ) as Gtk.Box;
+			pos_size_page_box  = builder.get_object( "pos_size_page_box" )  as Gtk.Box;
+			shadow_page_box    = builder.get_object( "shadow_page_box" )    as Gtk.Box;
+
 			/* Line widgets. */
-			line_width_spin = builder.get_object( "line_width_spin" ) as Gtk.SpinButton;
-			line_color_box  = builder.get_object( "line_color_box" )  as Gtk.Box;
+			line_width_spin         = builder.get_object( "line_width_spin" )         as Gtk.SpinButton;
+			line_color_box          = builder.get_object( "line_color_box" )          as Gtk.Box;
+
 			line_color_button = new ColorButton( _("No line"), Color.none(), Color.black() );
 			line_color_box.pack_start( line_color_button, true, true, 0 );
 
 			/* Fill widgets. */
-			fill_color_box  = builder.get_object( "fill_color_box" )  as Gtk.Box;
-			fill_color_button = new ColorButton( _("No fill"), Color.none(), Color.black() );
+			fill_color_box          = builder.get_object( "fill_color_box" )          as Gtk.Box;
+
+			fill_color_button       = new ColorButton( _("No fill"), Color.none(), Color.black() );
 			fill_color_box.pack_start( fill_color_button, true, true, 0 );
 
 			/* Position widgets. */
-			pos_x_spin        = builder.get_object( "pos_x_spin" )        as Gtk.SpinButton;
-			pos_y_spin        = builder.get_object( "pos_y_spin" )        as Gtk.SpinButton;
-			pos_x_units_label = builder.get_object( "pos_x_units_label" ) as Gtk.Label;
-			pos_y_units_label = builder.get_object( "pos_y_units_label" ) as Gtk.Label;
+			pos_x_spin              = builder.get_object( "pos_x_spin" )              as Gtk.SpinButton;
+			pos_y_spin              = builder.get_object( "pos_y_spin" )              as Gtk.SpinButton;
+			pos_x_units_label       = builder.get_object( "pos_x_units_label" )       as Gtk.Label;
+			pos_y_units_label       = builder.get_object( "pos_y_units_label" )       as Gtk.Label;
 
 			/* Size widgets. */
-			size_w_spin        = builder.get_object( "size_w_spin" )        as Gtk.SpinButton;
-			size_h_spin        = builder.get_object( "size_h_spin" )        as Gtk.SpinButton;
-			size_w_units_label = builder.get_object( "size_w_units_label" ) as Gtk.Label;
-			size_h_units_label = builder.get_object( "size_h_units_label" ) as Gtk.Label;
+			size_w_spin             = builder.get_object( "size_w_spin" )             as Gtk.SpinButton;
+			size_h_spin             = builder.get_object( "size_h_spin" )             as Gtk.SpinButton;
+			size_w_units_label      = builder.get_object( "size_w_units_label" )      as Gtk.Label;
+			size_h_units_label      = builder.get_object( "size_h_units_label" )      as Gtk.Label;
+			size_aspect_check       = builder.get_object( "size_aspect_check" )       as Gtk.CheckButton;
+			size_reset_image_button = builder.get_object( "size_reset_image_button" ) as Gtk.Button;
 
 			/* Shadow widgets. */
-			shadow_enable_check  = builder.get_object( "shadow_enable_check" )  as Gtk.CheckButton;
-			shadow_controls_grid = builder.get_object( "shadow_controls_grid" ) as Gtk.Grid;
-			shadow_x_spin        = builder.get_object( "shadow_x_spin" )        as Gtk.SpinButton;
-			shadow_y_spin        = builder.get_object( "shadow_y_spin" )        as Gtk.SpinButton;
-			shadow_x_units_label = builder.get_object( "shadow_x_units_label" ) as Gtk.Label;
-			shadow_y_units_label = builder.get_object( "shadow_y_units_label" ) as Gtk.Label;
-			shadow_color_box     = builder.get_object( "shadow_color_box" )  as Gtk.Box;
-			shadow_opacity_spin  = builder.get_object( "shadow_opacity_spin" )  as Gtk.SpinButton;
-			shadow_color_button  = new ColorButton( _("Default"), Color.black(), Color.black() );
+			shadow_enable_check     = builder.get_object( "shadow_enable_check" )     as Gtk.CheckButton;
+			shadow_controls_grid    = builder.get_object( "shadow_controls_grid" )    as Gtk.Grid;
+			shadow_x_spin           = builder.get_object( "shadow_x_spin" )           as Gtk.SpinButton;
+			shadow_y_spin           = builder.get_object( "shadow_y_spin" )           as Gtk.SpinButton;
+			shadow_x_units_label    = builder.get_object( "shadow_x_units_label" )    as Gtk.Label;
+			shadow_y_units_label    = builder.get_object( "shadow_y_units_label" )    as Gtk.Label;
+			shadow_color_box        = builder.get_object( "shadow_color_box" )        as Gtk.Box;
+			shadow_opacity_spin     = builder.get_object( "shadow_opacity_spin" )     as Gtk.SpinButton;
+
+			shadow_color_button = new ColorButton( _("Default"), Color.black(), Color.black() );
 			shadow_color_box.pack_start(shadow_color_button, true, true, 0 );
 
+			notebook.hide();
+			notebook.set_no_show_all( true );
+
+			prefs = new Prefs();
+			on_prefs_changed();
+			prefs.changed.connect( on_prefs_changed );
+		}
+
+
+		public void set_label( Label label )
+		{
+			this.label = label;
+
+			on_size_changed();
+			on_merge_changed();
+			on_selection_changed();
+
+			label.size_changed.connect( on_size_changed );
+			label.merge_changed.connect( on_merge_changed );
+			label.selection_changed.connect( on_selection_changed );
+		}
+
+
+		private void on_prefs_changed()
+		{
+			pos_x_units_label.set_text( prefs.units.name );
+			pos_y_units_label.set_text( prefs.units.name );
+			size_w_units_label.set_text( prefs.units.name );
+			size_h_units_label.set_text( prefs.units.name );
+			shadow_x_units_label.set_text( prefs.units.name );
+			shadow_y_units_label.set_text( prefs.units.name );
+
+			int    precision = UnitsUtil.get_precision( prefs.units );
+			pos_x_spin.set_digits( precision );
+			pos_y_spin.set_digits( precision );
+			size_w_spin.set_digits( precision );
+			size_h_spin.set_digits( precision );
+			shadow_x_spin.set_digits( precision );
+			shadow_y_spin.set_digits( precision );
+
+			double step_size = UnitsUtil.get_step_size( prefs.units );
+			pos_x_spin.set_increments( step_size, 10*step_size );
+			pos_y_spin.set_increments( step_size, 10*step_size );
+			size_w_spin.set_increments( step_size, 10*step_size );
+			size_h_spin.set_increments( step_size, 10*step_size );
+			shadow_x_spin.set_increments( step_size, 10*step_size );
+			shadow_y_spin.set_increments( step_size, 10*step_size );
+
+			double wh_max = double.max( w_max*prefs.units.units_per_point, h_max*prefs.units.units_per_point );
+			pos_x_spin.set_range( 0, 2*wh_max );
+			pos_y_spin.set_range( 0, 2*wh_max );
+			size_w_spin.set_range( 0, 2*wh_max );
+			size_h_spin.set_range( 0, 2*wh_max );
+			shadow_x_spin.set_range( 0, 2*wh_max );
+			shadow_y_spin.set_range( 0, 2*wh_max );
+
+			pos_x_spin.set_value( x * prefs.units.units_per_point );
+			pos_y_spin.set_value( y * prefs.units.units_per_point );
+			size_w_spin.set_value( w * prefs.units.units_per_point );
+			size_h_spin.set_value( h * prefs.units.units_per_point );
+			shadow_x_spin.set_value( shadow_x * prefs.units.units_per_point );
+			shadow_y_spin.set_value( shadow_y * prefs.units.units_per_point );
+
+		}
+
+
+		private void on_selection_changed()
+		{
+			if ( label.is_selection_atomic() )
+			{
+				LabelObject object = label.get_1st_selected_object();
+
+				if ( object is LabelObjectBox  )
+				{
+					title_image.set_from_icon_name( "glabels-box", Gtk.IconSize.LARGE_TOOLBAR );
+					title_label.set_text( "<b>%s</b>".printf( _("Box object properties") ) );
+
+					line_fill_page_box.show_all();
+					pos_size_page_box.show_all();
+					shadow_page_box.show_all();
+
+					size_reset_image_button.hide();
+				}
+				else
+				{
+					assert_not_reached();
+				}
+
+				title_image.set_sensitive( true );
+				title_label.set_use_markup( true );
+				title_label.set_sensitive( true );
+					
+				notebook.show();
+			}
+			else
+			{
+				title_image.set_from_icon_name( "glabels-object-properties", Gtk.IconSize.LARGE_TOOLBAR );
+				title_image.set_sensitive( false );
+
+				title_label.set_text( "<b>%s</b>".printf( _("Object properties") ) );
+				title_label.set_use_markup( true );
+				title_label.set_sensitive( false );
+
+				notebook.hide();
+			}
+		}
+
+
+		private void on_size_changed()
+		{
+			label.get_size( out w_max, out h_max );
+
+			double wh_max = double.max( w_max*prefs.units.units_per_point, h_max*prefs.units.units_per_point );
+
+			pos_x_spin.set_range( 0, 2*wh_max );
+			pos_y_spin.set_range( 0, 2*wh_max );
+			size_w_spin.set_range( 0, 2*wh_max );
+			size_h_spin.set_range( 0, 2*wh_max );
+			shadow_x_spin.set_range( 0, 2*wh_max );
+			shadow_y_spin.set_range( 0, 2*wh_max );
+		}
+
+
+		private void on_merge_changed()
+		{
 		}
 
 
diff --git a/glabels/units_util.vala b/glabels/units_util.vala
index 36edb13..eb4bc81 100644
--- a/glabels/units_util.vala
+++ b/glabels/units_util.vala
@@ -37,14 +37,14 @@ namespace glabels
 			switch (units.id)
 			{
 			case "pt":
-                return 0.1;     /* points */
+				return 0.1;     /* points */
 			case "in":
-                return 0.001;   /* inches */
+				return 0.001;   /* inches */
 			case "mm":
-                return 0.1;     /* mm */
+				return 0.1;     /* mm */
 			default:
-                warning( "Illegal units" );    /* Should not happen */
-                return 1.0;
+				warning( "Illegal units" );    /* Should not happen */
+				return 1.0;
 			}
 		}
 
@@ -58,14 +58,14 @@ namespace glabels
 			switch (units.id)
 			{
 			case "pt":
-                return 1;       /* points */
+				return 1;       /* points */
 			case "in":
-                return 3;       /* inches */
+				return 3;       /* inches */
 			case "mm":
-                return 1;       /* mm */
+				return 1;       /* mm */
 			default:
-                warning( "Illegal units" );    /* Should not happen */
-                return 1;
+				warning( "Illegal units" );    /* Should not happen */
+				return 1;
 			}
 		}
 
diff --git a/glabels/window.vala b/glabels/window.vala
index 26baf8e..71b13d4 100644
--- a/glabels/window.vala
+++ b/glabels/window.vala
@@ -161,6 +161,8 @@ namespace glabels
 			content_hbox.pack_start( mini_preview, true, true, 0 );
 */
 
+			object_editor.set_label( label );
+
 			view = new View( label );
 			content_hbox.pack_start( view, true, true, 0 );
 			view.show_all();



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]