[glabels/vala] Initial hookup of selected object to object editor.
- From: Jim Evins <jimevins src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glabels/vala] Initial hookup of selected object to object editor.
- Date: Sun, 18 Mar 2012 13:59:43 +0000 (UTC)
commit 928e6f3f9edf19b60329d02633184e4bc20350a2
Author: Jim Evins <evins snaught com>
Date: Sun Mar 18 09:59:07 2012 -0400
Initial hookup of selected object to object editor.
glabels/color_button.vala | 18 +-
glabels/object_editor.vala | 384 ++++++++++++++++++++++++++++++++++++++++----
2 files changed, 360 insertions(+), 42 deletions(-)
---
diff --git a/glabels/color_button.vala b/glabels/color_button.vala
index a8c2d8c..9e8bd62 100644
--- a/glabels/color_button.vala
+++ b/glabels/color_button.vala
@@ -39,7 +39,7 @@ namespace glabels
private Color default_color;
private ColorSwatch swatch;
- private Gtk.Label label;
+ private Gtk.Label key_label;
private ColorMenu menu;
@@ -58,9 +58,9 @@ namespace glabels
swatch = new ColorSwatch( SWATCH_W, SWATCH_H, color );
hbox.pack_start( swatch, true, true, 0 );
- label = new Gtk.Label( "" );
- label.hide();
- hbox.pack_start( label, true, true, 0 );
+ key_label = new Gtk.Label( "" );
+ key_label.hide();
+ hbox.pack_start( key_label, true, true, 0 );
Gtk.Arrow arrow = new Gtk.Arrow( Gtk.ArrowType.DOWN, Gtk.ShadowType.IN );
hbox.pack_end( arrow, false, false, 0 );
@@ -202,12 +202,12 @@ namespace glabels
if ( color_node.field_flag )
{
swatch.hide();
- label.show();
+ key_label.show();
}
else
{
swatch.show();
- label.hide();
+ key_label.hide();
}
}
@@ -220,14 +220,14 @@ namespace glabels
if ( color_node.field_flag )
{
swatch.hide();
- label.show();
- label.set_label( "$(%s)".printf( color_node.key ) );
+ key_label.show();
+ key_label.set_label( "$(%s)".printf( color_node.key ) );
}
else
{
swatch.show();
swatch.set_color( color_node.color );
- label.hide();
+ key_label.hide();
}
color_changed( color_node, is_default );
diff --git a/glabels/object_editor.vala b/glabels/object_editor.vala
index cb462cf..3ecf97a 100644
--- a/glabels/object_editor.vala
+++ b/glabels/object_editor.vala
@@ -20,6 +20,7 @@
using GLib;
+using libglabels;
namespace glabels
{
@@ -27,26 +28,28 @@ namespace glabels
class ObjectEditor : Gtk.Box
{
private Prefs prefs;
+ private Units units;
private Label label;
+ private LabelObject? object;
- public double line_width { get; set; }
- public ColorNode line_color_node { get; set; }
+ private double line_width;
+ private ColorNode line_color_node;
- public ColorNode fill_color_node { get; set; }
+ private ColorNode fill_color_node;
- public double x { get; set; }
- public double y { get; set; }
+ private double x;
+ private double y;
- public double w { get; set; }
- public double h { get; set; }
+ private double w;
+ private double h;
- 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 bool shadow_enable;
+ private double shadow_x;
+ private double shadow_y;
+ private ColorNode shadow_color_node;
+ private double shadow_opacity;
private double w_max;
@@ -126,10 +129,12 @@ namespace glabels
title_label.set_use_markup( true );
title_label.set_sensitive( false );
+ /* Notebook pages. */
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;
@@ -137,18 +142,29 @@ namespace glabels
line_color_button = new ColorButton( _("No line"), Color.none(), Color.black() );
line_color_box.pack_start( line_color_button, true, true, 0 );
+ line_width_spin.value_changed.connect( on_line_width_spin_changed );
+ line_color_button.color_changed.connect( on_line_color_button_changed );
+
+
/* 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.pack_start( fill_color_button, true, true, 0 );
+ fill_color_button.color_changed.connect( on_fill_color_button_changed );
+
+
/* 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.value_changed.connect( on_pos_x_spin_changed );
+ pos_y_spin.value_changed.connect( on_pos_y_spin_changed );
+
+
/* 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;
@@ -157,6 +173,10 @@ namespace glabels
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;
+ size_w_spin.value_changed.connect( on_size_w_spin_changed );
+ size_h_spin.value_changed.connect( on_size_h_spin_changed );
+
+
/* 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;
@@ -170,6 +190,13 @@ namespace glabels
shadow_color_button = new ColorButton( _("Default"), Color.black(), Color.black() );
shadow_color_box.pack_start(shadow_color_button, true, true, 0 );
+ shadow_enable_check.toggled.connect( on_shadow_enable_check_changed );
+ shadow_x_spin.value_changed.connect( on_shadow_x_spin_changed );
+ shadow_y_spin.value_changed.connect( on_shadow_y_spin_changed );
+ shadow_color_button.color_changed.connect( on_shadow_color_button_changed );
+ shadow_opacity_spin.value_changed.connect( on_shadow_opacity_spin_changed );
+
+
notebook.hide();
notebook.set_no_show_all( true );
@@ -183,11 +210,11 @@ namespace glabels
{
this.label = label;
- on_size_changed();
+ on_label_size_changed();
on_merge_changed();
on_selection_changed();
- label.size_changed.connect( on_size_changed );
+ label.size_changed.connect( on_label_size_changed );
label.merge_changed.connect( on_merge_changed );
label.selection_changed.connect( on_selection_changed );
}
@@ -195,14 +222,16 @@ namespace glabels
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 );
+ units = prefs.units;
+
+ pos_x_units_label.set_text( units.name );
+ pos_y_units_label.set_text( units.name );
+ size_w_units_label.set_text( units.name );
+ size_h_units_label.set_text( units.name );
+ shadow_x_units_label.set_text( units.name );
+ shadow_y_units_label.set_text( units.name );
+
+ int precision = UnitsUtil.get_precision( units );
pos_x_spin.set_digits( precision );
pos_y_spin.set_digits( precision );
size_w_spin.set_digits( precision );
@@ -210,7 +239,7 @@ namespace glabels
shadow_x_spin.set_digits( precision );
shadow_y_spin.set_digits( precision );
- double step_size = UnitsUtil.get_step_size( prefs.units );
+ double step_size = UnitsUtil.get_step_size( 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 );
@@ -218,7 +247,7 @@ namespace glabels
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 );
+ double wh_max = double.max( w_max*units.units_per_point, h_max*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 );
@@ -226,12 +255,12 @@ namespace glabels
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 );
+ pos_x_spin.set_value( x * units.units_per_point );
+ pos_y_spin.set_value( y * units.units_per_point );
+ size_w_spin.set_value( w * units.units_per_point );
+ size_h_spin.set_value( h * units.units_per_point );
+ shadow_x_spin.set_value( shadow_x * units.units_per_point );
+ shadow_y_spin.set_value( shadow_y * units.units_per_point );
}
@@ -240,7 +269,7 @@ namespace glabels
{
if ( label.is_selection_atomic() )
{
- LabelObject object = label.get_1st_selected_object();
+ object = label.get_1st_selected_object();
if ( object is LabelObjectBox )
{
@@ -258,6 +287,19 @@ namespace glabels
assert_not_reached();
}
+ load_line_width_spin();
+ load_line_color_button();
+ load_fill_color_button();
+ load_pos_x_spin();
+ load_pos_y_spin();
+ load_size_w_spin();
+ load_size_h_spin();
+ load_shadow_enable_check();
+ load_shadow_x_spin();
+ load_shadow_y_spin();
+ load_shadow_color_button();
+ load_shadow_opacity_spin();
+
title_image.set_sensitive( true );
title_label.set_use_markup( true );
title_label.set_sensitive( true );
@@ -266,6 +308,8 @@ namespace glabels
}
else
{
+ object = null;
+
title_image.set_from_icon_name( "glabels-object-properties", Gtk.IconSize.LARGE_TOOLBAR );
title_image.set_sensitive( false );
@@ -278,11 +322,11 @@ namespace glabels
}
- private void on_size_changed()
+ private void on_label_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 );
+ double wh_max = double.max( w_max*units.units_per_point, h_max*units.units_per_point );
pos_x_spin.set_range( 0, 2*wh_max );
pos_y_spin.set_range( 0, 2*wh_max );
@@ -295,6 +339,280 @@ namespace glabels
private void on_merge_changed()
{
+ if ( label.merge is MergeNone )
+ {
+ line_color_button.clear_keys();
+ fill_color_button.clear_keys();
+ shadow_color_button.clear_keys();
+ }
+ else
+ {
+ List<string> key_list = label.merge.get_key_list();
+ line_color_button.set_keys( key_list );
+ fill_color_button.set_keys( key_list );
+ shadow_color_button.set_keys( key_list );
+ }
+ }
+
+
+ private void on_line_width_spin_changed()
+ {
+ if ( object != null )
+ {
+ line_width = line_width_spin.get_value();
+ object.line_width = line_width;
+ }
+ }
+
+
+ private void load_line_width_spin()
+ {
+ GLib.SignalHandler.block_by_func( (void*)line_width_spin, (void*)on_line_width_spin_changed, this );
+
+ line_width = object.line_width;
+ line_width_spin.set_value( line_width );
+
+ GLib.SignalHandler.unblock_by_func( (void*)line_width_spin, (void*)on_line_width_spin_changed, this );
+ }
+
+
+ private void on_line_color_button_changed()
+ {
+ if ( object != null )
+ {
+ bool is_default;
+
+ line_color_node = line_color_button.get_color_node( out is_default );
+ object.line_color_node = line_color_node;
+ }
+ }
+
+
+ private void load_line_color_button()
+ {
+ GLib.SignalHandler.block_by_func( (void*)line_color_button, (void*)on_line_color_button_changed, this );
+
+ line_color_node = object.line_color_node;
+ line_color_button.set_color_node( line_color_node );
+
+ GLib.SignalHandler.unblock_by_func( (void*)line_color_button, (void*)on_line_color_button_changed, this );
+ }
+
+
+ private void on_fill_color_button_changed()
+ {
+ if ( object != null )
+ {
+ bool is_default;
+
+ fill_color_node = fill_color_button.get_color_node( out is_default );
+ object.fill_color_node = fill_color_node;
+ }
+ }
+
+
+ private void load_fill_color_button()
+ {
+ GLib.SignalHandler.block_by_func( (void*)fill_color_button, (void*)on_fill_color_button_changed, this );
+
+ fill_color_node = object.fill_color_node;
+ fill_color_button.set_color_node( fill_color_node );
+
+ GLib.SignalHandler.unblock_by_func( (void*)fill_color_button, (void*)on_fill_color_button_changed, this );
+ }
+
+
+ private void on_pos_x_spin_changed()
+ {
+ if ( object != null )
+ {
+ x = pos_x_spin.get_value() * units.points_per_unit;
+ object.x0 = x;
+ }
+ }
+
+
+ private void load_pos_x_spin()
+ {
+ GLib.SignalHandler.block_by_func( (void*)pos_x_spin, (void*)on_pos_x_spin_changed, this );
+
+ x = object.x0;
+ pos_x_spin.set_value( x * units.units_per_point );
+
+ GLib.SignalHandler.unblock_by_func( (void*)pos_x_spin, (void*)on_pos_x_spin_changed, this );
+ }
+
+
+ private void on_pos_y_spin_changed()
+ {
+ if ( object != null )
+ {
+ y = pos_y_spin.get_value() * units.points_per_unit;
+ object.y0 = y;
+ }
+ }
+
+
+ private void load_pos_y_spin()
+ {
+ GLib.SignalHandler.block_by_func( (void*)pos_y_spin, (void*)on_pos_y_spin_changed, this );
+
+ y = object.y0;
+ pos_y_spin.set_value( y * units.units_per_point );
+
+ GLib.SignalHandler.unblock_by_func( (void*)pos_y_spin, (void*)on_pos_y_spin_changed, this );
+ }
+
+
+ private void on_size_w_spin_changed()
+ {
+ if ( object != null )
+ {
+ w = size_w_spin.get_value() * units.points_per_unit;
+ object.w = w;
+ }
+ }
+
+
+ private void load_size_w_spin()
+ {
+ GLib.SignalHandler.block_by_func( (void*)size_w_spin, (void*)on_size_w_spin_changed, this );
+
+ w = object.w;
+ size_w_spin.set_value( w * units.units_per_point );
+
+ GLib.SignalHandler.unblock_by_func( (void*)size_w_spin, (void*)on_size_w_spin_changed, this );
+ }
+
+
+ private void on_size_h_spin_changed()
+ {
+ if ( object != null )
+ {
+ h = size_h_spin.get_value() * units.points_per_unit;
+ object.h = h;
+ }
+ }
+
+
+ private void load_size_h_spin()
+ {
+ GLib.SignalHandler.block_by_func( (void*)size_h_spin, (void*)on_size_h_spin_changed, this );
+
+ h = object.h;
+ size_h_spin.set_value( h * units.units_per_point );
+
+ GLib.SignalHandler.unblock_by_func( (void*)size_h_spin, (void*)on_size_h_spin_changed, this );
+ }
+
+
+ private void on_shadow_enable_check_changed()
+ {
+ if ( object != null )
+ {
+ shadow_enable = shadow_enable_check.get_active();
+ shadow_controls_grid.set_sensitive( shadow_enable );
+
+ object.shadow_state = shadow_enable;
+ }
+ }
+
+
+ private void load_shadow_enable_check()
+ {
+ GLib.SignalHandler.block_by_func( (void*)shadow_enable_check, (void*)on_shadow_enable_check_changed, this );
+
+ shadow_enable = object.shadow_state;
+ shadow_enable_check.set_active( shadow_enable );
+ shadow_controls_grid.set_sensitive( shadow_enable );
+
+ GLib.SignalHandler.unblock_by_func( (void*)shadow_enable_check, (void*)on_shadow_enable_check_changed, this );
+ }
+
+
+ private void on_shadow_x_spin_changed()
+ {
+ if ( object != null )
+ {
+ shadow_x = shadow_x_spin.get_value() * units.points_per_unit;
+ object.shadow_x = shadow_x;
+ }
+ }
+
+
+ private void load_shadow_x_spin()
+ {
+ GLib.SignalHandler.block_by_func( (void*)shadow_x_spin, (void*)on_shadow_x_spin_changed, this );
+
+ shadow_x = object.shadow_x;
+ shadow_x_spin.set_value( shadow_x * units.units_per_point );
+
+ GLib.SignalHandler.unblock_by_func( (void*)shadow_x_spin, (void*)on_shadow_x_spin_changed, this );
+ }
+
+
+ private void on_shadow_y_spin_changed()
+ {
+ if ( object != null )
+ {
+ shadow_y = shadow_y_spin.get_value() * units.points_per_unit;
+ object.shadow_y = shadow_y;
+ }
+ }
+
+
+ private void load_shadow_y_spin()
+ {
+ GLib.SignalHandler.block_by_func( (void*)shadow_y_spin, (void*)on_shadow_y_spin_changed, this );
+
+ shadow_y = object.shadow_y;
+ shadow_y_spin.set_value( shadow_y * units.units_per_point );
+
+ GLib.SignalHandler.unblock_by_func( (void*)shadow_y_spin, (void*)on_shadow_y_spin_changed, this );
+ }
+
+
+ private void on_shadow_color_button_changed()
+ {
+ if ( object != null )
+ {
+ bool is_default;
+
+ shadow_color_node = fill_color_button.get_color_node( out is_default );
+ object.shadow_color_node = shadow_color_node;
+ }
+ }
+
+
+ private void load_shadow_color_button()
+ {
+ GLib.SignalHandler.block_by_func( (void*)shadow_color_button, (void*)on_shadow_color_button_changed, this );
+
+ shadow_color_node = object.shadow_color_node;
+ shadow_color_button.set_color_node( shadow_color_node );
+
+ GLib.SignalHandler.unblock_by_func( (void*)shadow_color_button, (void*)on_shadow_color_button_changed, this );
+ }
+
+
+ private void on_shadow_opacity_spin_changed()
+ {
+ if ( object != null )
+ {
+ shadow_opacity = shadow_opacity_spin.get_value();
+ object.shadow_opacity = shadow_opacity;
+ }
+ }
+
+
+ private void load_shadow_opacity_spin()
+ {
+ GLib.SignalHandler.block_by_func( (void*)shadow_opacity_spin, (void*)on_shadow_opacity_spin_changed, this );
+
+ shadow_opacity = object.shadow_opacity;
+ shadow_opacity_spin.set_value( shadow_opacity );
+
+ GLib.SignalHandler.unblock_by_func( (void*)shadow_opacity_spin, (void*)on_shadow_opacity_spin_changed, this );
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]