added parameter "gboolean property_is_pixel" which indicates that the

2007-10-14  Michael Natterer  <mitch@gimp.org>

	* libgimpwidgets/gimppropwidgets.[ch] (gimp_prop_size_entry_new):
	added parameter "gboolean property_is_pixel" which indicates that
	the stored property value is always in pixels and not in the
	selected unit.

	* app/tools/gimptextoptions.c
	* app/widgets/gimpstrokeeditor.c: pass FALSE to keep the old
	behavior.

	* app/tools/gimprectangleoptions.c (gimp_rectangle_options_gui):
	added property "fixed-unit" which is used for all fixed values
	now. Perhaps we need separate units for width/height/size. Enable
	the unit menu on the "Width" and "Height" size entries of the
	"Fixed" section and configure them to store the value in
	pixels. This was the easy part, some other widgets still need unit
	support.

	* app/tools/gimprectangletool.c (gimp_rectangle_tool_start): set
	the image's resolution on the size entries changed above.


svn path=/trunk/; revision=23821
This commit is contained in:
Michael Natterer 2007-10-14 18:51:58 +00:00 committed by Michael Natterer
parent ba1b9b5825
commit 0a824ddba0
8 changed files with 105 additions and 26 deletions

View File

@ -1,3 +1,25 @@
2007-10-14 Michael Natterer <mitch@gimp.org>
* libgimpwidgets/gimppropwidgets.[ch] (gimp_prop_size_entry_new):
added parameter "gboolean property_is_pixel" which indicates that
the stored property value is always in pixels and not in the
selected unit.
* app/tools/gimptextoptions.c
* app/widgets/gimpstrokeeditor.c: pass FALSE to keep the old
behavior.
* app/tools/gimprectangleoptions.c (gimp_rectangle_options_gui):
added property "fixed-unit" which is used for all fixed values
now. Perhaps we need separate units for width/height/size. Enable
the unit menu on the "Width" and "Height" size entries of the
"Fixed" section and configure them to store the value in
pixels. This was the easy part, some other widgets still need unit
support.
* app/tools/gimprectangletool.c (gimp_rectangle_tool_start): set
the image's resolution on the size entries changed above.
2007-10-14 Raphaël Quinet <raphael@gimp.org>
* app/tools/gimpaligntool.[ch]: Re-wrote the cursor handling

View File

@ -280,6 +280,14 @@ gimp_rectangle_options_iface_base_init (GimpRectangleOptionsInterface *iface)
GIMP_CONFIG_PARAM_FLAGS |
GIMP_PARAM_STATIC_STRINGS));
g_object_interface_install_property (iface,
gimp_param_spec_unit ("fixed-unit",
NULL, NULL,
TRUE, TRUE,
GIMP_UNIT_PIXEL,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
g_object_interface_install_property (iface,
g_param_spec_double ("center-x",
NULL, NULL,
@ -441,6 +449,9 @@ gimp_rectangle_options_install_properties (GObjectClass *klass)
g_object_class_override_property (klass,
GIMP_RECTANGLE_OPTIONS_PROP_OVERRIDDEN_FIXED_SIZE,
"overridden-fixed-size");
g_object_class_override_property (klass,
GIMP_RECTANGLE_OPTIONS_PROP_FIXED_UNIT,
"fixed-unit");
g_object_class_override_property (klass,
GIMP_RECTANGLE_OPTIONS_PROP_FIXED_CENTER,
"fixed-center");
@ -540,6 +551,9 @@ gimp_rectangle_options_set_property (GObject *object,
case GIMP_RECTANGLE_OPTIONS_PROP_OVERRIDDEN_FIXED_SIZE:
private->overridden_fixed_size = g_value_get_boolean (value);
break;
case GIMP_RECTANGLE_OPTIONS_PROP_FIXED_UNIT:
private->fixed_unit = g_value_get_int (value);
break;
case GIMP_RECTANGLE_OPTIONS_PROP_CENTER_X:
private->center_x = g_value_get_double (value);
break;
@ -641,6 +655,9 @@ gimp_rectangle_options_get_property (GObject *object,
case GIMP_RECTANGLE_OPTIONS_PROP_OVERRIDDEN_FIXED_SIZE:
g_value_set_boolean (value, private->overridden_fixed_size);
break;
case GIMP_RECTANGLE_OPTIONS_PROP_FIXED_UNIT:
g_value_set_int (value, private->fixed_unit);
break;
case GIMP_RECTANGLE_OPTIONS_PROP_CENTER_X:
g_value_set_double (value, private->center_x);
break;
@ -846,11 +863,9 @@ gimp_rectangle_options_gui (GimpToolOptions *tool_options)
/* Fixed width entry */
private->fixed_width_entry =
gimp_prop_size_entry_new (config, "desired-fixed-width", "unit", "%a",
gimp_prop_size_entry_new (config,
"desired-fixed-width", TRUE, "fixed-unit", "%a",
GIMP_SIZE_ENTRY_UPDATE_SIZE, 300);
gimp_size_entry_show_unit_menu (GIMP_SIZE_ENTRY (private->fixed_width_entry),
FALSE);
gtk_table_set_col_spacing (GTK_TABLE (private->fixed_width_entry), 1, 0);
gtk_box_pack_start (GTK_BOX (vbox2), private->fixed_width_entry,
FALSE, FALSE, 0);
gtk_size_group_add_widget (size_group, private->fixed_width_entry);
@ -858,11 +873,9 @@ gimp_rectangle_options_gui (GimpToolOptions *tool_options)
/* Fixed height entry */
private->fixed_height_entry =
gimp_prop_size_entry_new (config, "desired-fixed-height", "unit", "%a",
gimp_prop_size_entry_new (config,
"desired-fixed-height", TRUE, "fixed-unit", "%a",
GIMP_SIZE_ENTRY_UPDATE_SIZE, 300);
gimp_size_entry_show_unit_menu (GIMP_SIZE_ENTRY (private->fixed_height_entry),
FALSE);
gtk_table_set_col_spacing (GTK_TABLE (private->fixed_height_entry), 1, 0);
gtk_box_pack_start (GTK_BOX (vbox2), private->fixed_height_entry,
FALSE, FALSE, 0);
gtk_size_group_add_widget (size_group, private->fixed_height_entry);
@ -922,18 +935,16 @@ gimp_rectangle_options_gui (GimpToolOptions *tool_options)
gtk_widget_show (table);
/* X */
entry = gimp_prop_size_entry_new (config, "x0", "unit", "%a",
entry = gimp_prop_size_entry_new (config, "x0", TRUE, "unit", "%a",
GIMP_SIZE_ENTRY_UPDATE_SIZE, 300);
gtk_table_set_col_spacing (GTK_TABLE (entry), 1, 0);
gimp_size_entry_show_unit_menu (GIMP_SIZE_ENTRY (entry), FALSE);
gimp_table_attach_aligned (GTK_TABLE (table), 0, row++,
_("X:"), 0.0, 0.5,
entry, 1, TRUE);
/* Y */
entry = gimp_prop_size_entry_new (config, "y0", "unit", "%a",
entry = gimp_prop_size_entry_new (config, "y0", TRUE, "unit", "%a",
GIMP_SIZE_ENTRY_UPDATE_SIZE, 300);
gtk_table_set_col_spacing (GTK_TABLE (entry), 1, 0);
gimp_size_entry_show_unit_menu (GIMP_SIZE_ENTRY (entry), FALSE);
gimp_table_attach_aligned (GTK_TABLE (table), 0, row++,
_("Y:"), 0.0, 0.5,
@ -941,10 +952,9 @@ gimp_rectangle_options_gui (GimpToolOptions *tool_options)
/* Width */
private->width_entry = gimp_prop_size_entry_new (config,
"width", "unit", "%a",
"width", TRUE, "unit", "%a",
GIMP_SIZE_ENTRY_UPDATE_SIZE,
300);
gtk_table_set_col_spacing (GTK_TABLE (private->width_entry), 1, 0);
gimp_size_entry_show_unit_menu (GIMP_SIZE_ENTRY (private->width_entry),
FALSE);
gimp_table_attach_aligned (GTK_TABLE (table), 0, row,
@ -954,10 +964,9 @@ gimp_rectangle_options_gui (GimpToolOptions *tool_options)
/* Height */
private->height_entry = gimp_prop_size_entry_new (config,
"height", "unit", "%a",
"height", TRUE, "unit", "%a",
GIMP_SIZE_ENTRY_UPDATE_SIZE,
300);
gtk_table_set_col_spacing (GTK_TABLE (private->height_entry), 1, 0);
gimp_size_entry_show_unit_menu (GIMP_SIZE_ENTRY (private->height_entry),
FALSE);
gimp_table_attach_aligned (GTK_TABLE (table), 0, row,

View File

@ -47,6 +47,7 @@ typedef enum
GIMP_RECTANGLE_OPTIONS_PROP_FIXED_RULE_ACTIVE,
GIMP_RECTANGLE_OPTIONS_PROP_FIXED_RULE,
GIMP_RECTANGLE_OPTIONS_PROP_FIXED_CENTER,
GIMP_RECTANGLE_OPTIONS_PROP_FIXED_UNIT,
GIMP_RECTANGLE_OPTIONS_PROP_CENTER_X,
GIMP_RECTANGLE_OPTIONS_PROP_CENTER_Y,
GIMP_RECTANGLE_OPTIONS_PROP_UNIT,
@ -104,6 +105,8 @@ struct _GimpRectangleOptionsPrivate
gboolean fixed_rule_active;
GimpRectangleToolFixedRule fixed_rule;
GimpUnit fixed_unit;
gboolean fixed_center;
gdouble center_x;
gdouble center_y;

View File

@ -1940,6 +1940,14 @@ gimp_rectangle_tool_start (GimpRectangleTool *rectangle,
gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), tool->display);
if (options_private->fixed_width_entry)
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (options_private->fixed_width_entry),
0, display->image->xresolution, FALSE);
if (options_private->fixed_height_entry)
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (options_private->fixed_height_entry),
0, display->image->yresolution, FALSE);
if (options_private->auto_shrink_button)
{
g_signal_connect_swapped (options_private->auto_shrink_button, "clicked",

View File

@ -429,7 +429,7 @@ gimp_text_options_gui (GimpToolOptions *tool_options)
hbox, 2, FALSE);
entry = gimp_prop_size_entry_new (config,
"font-size", "font-size-unit", "%a",
"font-size", FALSE, "font-size-unit", "%a",
GIMP_SIZE_ENTRY_UPDATE_SIZE, 72.0);
gimp_table_attach_aligned (GTK_TABLE (table), 0, row++,
_("Size:"), 0.0, 0.5,

View File

@ -186,7 +186,8 @@ gimp_stroke_editor_constructor (GType type,
gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
gtk_widget_show (label);
size = gimp_prop_size_entry_new (G_OBJECT (editor->options), "width", "unit",
size = gimp_prop_size_entry_new (G_OBJECT (editor->options),
"width", FALSE, "unit",
"%a", GIMP_SIZE_ENTRY_UPDATE_SIZE,
editor->resolution);
gimp_size_entry_set_pixel_digits (GIMP_SIZE_ENTRY (size), 1);

View File

@ -2603,6 +2603,8 @@ static void gimp_prop_size_entry_notify_unit (GObject *config,
* gimp_prop_size_entry_new:
* @config: Object to which property is attached.
* @property_name: Name of int or double property.
* @property_is_pixel: When %TRUE, the property value is in pixels,
* and in the selected unit otherwise.
* @unit_property_name: Name of unit property.
* @unit_format: A printf-like unit-format string as is used with
* gimp_unit_menu_new().
@ -2623,6 +2625,7 @@ static void gimp_prop_size_entry_notify_unit (GObject *config,
GtkWidget *
gimp_prop_size_entry_new (GObject *config,
const gchar *property_name,
gboolean property_is_pixel,
const gchar *unit_property_name,
const gchar *unit_format,
GimpSizeEntryUpdatePolicy update_policy,
@ -2695,14 +2698,25 @@ gimp_prop_size_entry_new (GObject *config,
gimp_size_entry_set_value_boundaries (GIMP_SIZE_ENTRY (sizeentry), 0,
lower, upper);
gimp_size_entry_set_value (GIMP_SIZE_ENTRY (sizeentry), 0, value);
g_object_set_data (G_OBJECT (sizeentry), "value-is-pixel",
GINT_TO_POINTER (property_is_pixel ? TRUE : FALSE));
if (property_is_pixel)
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (sizeentry), 0, value);
else
gimp_size_entry_set_value (GIMP_SIZE_ENTRY (sizeentry), 0, value);
g_object_set_data (G_OBJECT (sizeentry), "gimp-config-param-spec",
param_spec);
g_signal_connect (sizeentry, "value-changed",
G_CALLBACK (gimp_prop_size_entry_callback),
config);
if (property_is_pixel)
g_signal_connect (sizeentry, "refval-changed",
G_CALLBACK (gimp_prop_size_entry_callback),
config);
else
g_signal_connect (sizeentry, "value-changed",
G_CALLBACK (gimp_prop_size_entry_callback),
config);
connect_notify (config, property_name,
G_CALLBACK (gimp_prop_size_entry_notify),
@ -2732,6 +2746,7 @@ gimp_prop_size_entry_callback (GimpSizeEntry *sizeentry,
GParamSpec *param_spec;
GParamSpec *unit_param_spec;
gdouble value;
gboolean value_is_pixel;
GimpUnit unit_value;
param_spec = g_object_get_data (G_OBJECT (sizeentry),
@ -2742,7 +2757,14 @@ gimp_prop_size_entry_callback (GimpSizeEntry *sizeentry,
unit_param_spec = g_object_get_data (G_OBJECT (sizeentry),
"gimp-config-param-spec-unit");
value = gimp_size_entry_get_value (sizeentry, 0);
value_is_pixel = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (sizeentry),
"value-is-pixel"));
if (value_is_pixel)
value = gimp_size_entry_get_refval (sizeentry, 0);
else
value = gimp_size_entry_get_value (sizeentry, 0);
unit_value = gimp_size_entry_get_unit (sizeentry);
if (unit_param_spec)
@ -2784,7 +2806,9 @@ gimp_prop_size_entry_notify (GObject *config,
GParamSpec *param_spec,
GimpSizeEntry *sizeentry)
{
gdouble value;
gdouble value;
gdouble entry_value;
gboolean value_is_pixel;
if (G_IS_PARAM_SPEC_INT (param_spec))
{
@ -2803,13 +2827,24 @@ gimp_prop_size_entry_notify (GObject *config,
NULL);
}
if (value != gimp_size_entry_get_value (sizeentry, 0))
value_is_pixel = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (sizeentry),
"value-is-pixel"));
if (value_is_pixel)
entry_value = gimp_size_entry_get_refval (sizeentry, 0);
else
entry_value = gimp_size_entry_get_value (sizeentry, 0);
if (value != entry_value)
{
g_signal_handlers_block_by_func (sizeentry,
gimp_prop_size_entry_callback,
config);
gimp_size_entry_set_value (sizeentry, 0, value);
if (value_is_pixel)
gimp_size_entry_set_refval (sizeentry, 0, value);
else
gimp_size_entry_set_value (sizeentry, 0, value);
g_signal_handlers_unblock_by_func (sizeentry,
gimp_prop_size_entry_callback,

View File

@ -165,6 +165,7 @@ GtkWidget * gimp_prop_path_editor_new (GObject *config,
GtkWidget * gimp_prop_size_entry_new (GObject *config,
const gchar *property_name,
gboolean property_is_pixel,
const gchar *unit_property_name,
const gchar *unit_format,
GimpSizeEntryUpdatePolicy update_policy,