Connect a new function gimp_rectangle_options_string_current_updates()

2007-10-09  Martin Nordholts  <martinn@svn.gnome.org>

	* app/tools/gimprectangleoptions.[ch]: Connect a new function
	gimp_rectangle_options_string_current_updates() that updates the
	Fixed: Aspect entry with a 'Current' string when aspect of the
	current pending rectangle is used, and sets sensitivity FALSE on
	aspect ratio changing buttons when that string is shown. Prevents
	the confusion mentioned in bug #479999.

	A new Rectangle Options property 'use-string-current' has been
	added that should be refactored away from the options object along
	with references to option widgets.

	* app/tools/gimprectangleselecttool.c
	(gimp_rect_select_tool_update_option_defaults): Set default Fixed:
	Aspect ratio to that of the pending rectangle, and always have
	default Fixed: Size as 100x100.

	* app/tools/gimpcroptool.c
	(gimp_crop_tool_update_option_defaults): Always have default
	Fixed: Size 100x100.

	* libgimpwidgets/gimpnumberpairentry.[ch]
	(gimp_number_pair_entry_class_init): Add a new property
	'default-text' that contains text to be shown instead of numbers
	when default numbers are to be shown.
	(gimp_number_pair_entry_get_default_text)
	(gimp_number_pair_entry_set_default_text): Getter and setter for
	it.

	* libgimpwidgets/gimpwidgets.def: Updated.

svn path=/trunk/; revision=23788
This commit is contained in:
Martin Nordholts 2007-10-09 20:54:07 +00:00 committed by Martin Nordholts
parent 54bd29176c
commit d583686878
8 changed files with 199 additions and 20 deletions

View File

@ -1,3 +1,35 @@
2007-10-09 Martin Nordholts <martinn@svn.gnome.org>
* app/tools/gimprectangleoptions.[ch]: Connect a new function
gimp_rectangle_options_string_current_updates() that updates the
Fixed: Aspect entry with a 'Current' string when aspect of the
current pending rectangle is used, and sets sensitivity FALSE on
aspect ratio changing buttons when that string is shown. Prevents
the confusion mentioned in bug #479999.
A new Rectangle Options property 'use-string-current' has been
added that should be refactored away from the options object along
with references to option widgets.
* app/tools/gimprectangleselecttool.c
(gimp_rect_select_tool_update_option_defaults): Set default Fixed:
Aspect ratio to that of the pending rectangle, and always have
default Fixed: Size as 100x100.
* app/tools/gimpcroptool.c
(gimp_crop_tool_update_option_defaults): Always have default
Fixed: Size 100x100.
* libgimpwidgets/gimpnumberpairentry.[ch]
(gimp_number_pair_entry_class_init): Add a new property
'default-text' that contains text to be shown instead of numbers
when default numbers are to be shown.
(gimp_number_pair_entry_get_default_text)
(gimp_number_pair_entry_set_default_text): Getter and setter for
it.
* libgimpwidgets/gimpwidgets.def: Updated.
2007-10-09 Sven Neumann <sven@gimp.org>
* libgimpwidgets/gimppropwidgets.c

View File

@ -337,8 +337,8 @@ gimp_crop_tool_update_option_defaults (GimpCropTool *crop_tool,
if (tool->display != NULL && !ignore_pending)
{
/* There is a pending rectangle and we should not ignore it, so
* set default Fixed: Aspect ratio and Fixed: Size to the same
* as the current pending rectangle width/height.
* set default Fixed: Aspect ratio to the same as the current
* pending rectangle width/height.
*/
gimp_rectangle_tool_pending_size_set (rectangle_tool,
@ -346,16 +346,14 @@ gimp_crop_tool_update_option_defaults (GimpCropTool *crop_tool,
"default-aspect-numerator",
"default-aspect-denominator");
gimp_rectangle_tool_pending_size_set (rectangle_tool,
G_OBJECT (rectangle_options),
"default-fixed-size-width",
"default-fixed-size-height");
g_object_set (G_OBJECT (rectangle_options),
"use-string-current", TRUE,
NULL);
}
else
{
/* There is no pending rectangle, set default Fixed: Aspect
* ratio to that of the current image/layer, and the size to
* 100x100.
* ratio to that of the current image/layer.
*/
gimp_rectangle_tool_constraint_size_set (rectangle_tool,
@ -364,8 +362,7 @@ gimp_crop_tool_update_option_defaults (GimpCropTool *crop_tool,
"default-aspect-denominator");
g_object_set (G_OBJECT (rectangle_options),
"default-fixed-size-width", 100.0,
"default-fixed-size-height", 100.0,
"use-string-current", FALSE,
NULL);
}
}

View File

@ -53,6 +53,9 @@ static void gimp_rectangle_options_unparent_fixed_rule_widgets (GimpRectangl
static void gimp_rectangle_options_fixed_rule_changed (GtkWidget *combo_box,
GimpRectangleOptionsPrivate *private);
static void gimp_rectangle_options_string_current_updates (GimpNumberPairEntry *entry,
GParamSpec *param,
GimpRectangleOptions *rectangle_options);
static void gimp_rectangle_options_setup_ratio_completion (GimpRectangleOptions *rectangle_options,
GtkWidget *entry,
GtkListStore *history);
@ -302,6 +305,13 @@ gimp_rectangle_options_iface_base_init (GimpRectangleOptionsInterface *iface)
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
g_object_interface_install_property (iface,
g_param_spec_boolean ("use-string-current",
NULL, NULL,
FALSE,
GIMP_PARAM_READWRITE |
GIMP_PARAM_STATIC_STRINGS));
g_object_interface_install_property (iface,
gimp_param_spec_unit ("unit",
NULL, NULL,
@ -454,6 +464,9 @@ gimp_rectangle_options_install_properties (GObjectClass *klass)
g_object_class_override_property (klass,
GIMP_RECTANGLE_OPTIONS_PROP_CENTER_Y,
"center-y");
g_object_class_override_property (klass,
GIMP_RECTANGLE_OPTIONS_PROP_USE_STRING_CURRENT,
"use-string-current");
g_object_class_override_property (klass,
GIMP_RECTANGLE_OPTIONS_PROP_UNIT,
"unit");
@ -547,6 +560,9 @@ gimp_rectangle_options_set_property (GObject *object,
case GIMP_RECTANGLE_OPTIONS_PROP_CENTER_Y:
private->center_y = g_value_get_double (value);
break;
case GIMP_RECTANGLE_OPTIONS_PROP_USE_STRING_CURRENT:
private->use_string_current = g_value_get_boolean (value);
break;
case GIMP_RECTANGLE_OPTIONS_PROP_UNIT:
private->unit = g_value_get_int (value);
break;
@ -645,6 +661,9 @@ gimp_rectangle_options_get_property (GObject *object,
case GIMP_RECTANGLE_OPTIONS_PROP_CENTER_Y:
g_value_set_double (value, private->center_y);
break;
case GIMP_RECTANGLE_OPTIONS_PROP_USE_STRING_CURRENT:
g_value_set_boolean (value, private->use_string_current);
break;
case GIMP_RECTANGLE_OPTIONS_PROP_UNIT:
g_value_set_int (value, private->unit);
break;
@ -782,6 +801,30 @@ gimp_rectangle_options_fixed_rule_changed (GtkWidget *combo_bo
}
}
static void
gimp_rectangle_options_string_current_updates (GimpNumberPairEntry *entry,
GParamSpec *param,
GimpRectangleOptions *rectangle_options)
{
GimpRectangleOptionsPrivate *private;
gboolean use_string_current;
gboolean user_override;
private = GIMP_RECTANGLE_OPTIONS_GET_PRIVATE (rectangle_options);
user_override = gimp_number_pair_entry_get_user_override (entry);
g_object_get (rectangle_options,
"use-string-current", &use_string_current,
NULL);
gimp_number_pair_entry_set_default_text (entry,
use_string_current ? _("Current") : NULL);
gtk_widget_set_sensitive (private->aspect_button_box,
! use_string_current || user_override);
}
GtkWidget *
gimp_rectangle_options_gui (GimpToolOptions *tool_options)
{
@ -868,6 +911,12 @@ gimp_rectangle_options_gui (GimpToolOptions *tool_options)
":/",
TRUE,
0.001, GIMP_MAX_IMAGE_SIZE);
g_signal_connect (entry, "notify::user-override",
G_CALLBACK (gimp_rectangle_options_string_current_updates),
config);
g_signal_connect_swapped (config, "notify::use-string-current",
G_CALLBACK (gimp_rectangle_options_string_current_updates),
entry);
gimp_rectangle_options_setup_ratio_completion (GIMP_RECTANGLE_OPTIONS (tool_options),
entry,

View File

@ -43,6 +43,7 @@ typedef enum
GIMP_RECTANGLE_OPTIONS_PROP_DEFAULT_ASPECT_NUMERATOR,
GIMP_RECTANGLE_OPTIONS_PROP_DEFAULT_ASPECT_DENOMINATOR,
GIMP_RECTANGLE_OPTIONS_PROP_OVERRIDDEN_FIXED_ASPECT,
GIMP_RECTANGLE_OPTIONS_PROP_USE_STRING_CURRENT,
GIMP_RECTANGLE_OPTIONS_PROP_FIXED_RULE_ACTIVE,
GIMP_RECTANGLE_OPTIONS_PROP_FIXED_RULE,
GIMP_RECTANGLE_OPTIONS_PROP_FIXED_CENTER,
@ -110,6 +111,12 @@ struct _GimpRectangleOptionsPrivate
GimpUnit unit;
/* options gui */
/* This gboolean is not part of the actual rectangle tool options,
* and should be refactored out along with the pointers to widgets.
*/
gboolean use_string_current;
GtkWidget *auto_shrink_button;
GtkWidget *second_row_hbox;

View File

@ -612,18 +612,22 @@ gimp_rect_select_tool_update_option_defaults (GimpRectSelectTool *rect_select_to
gimp_rectangle_tool_pending_size_set (rectangle_tool,
G_OBJECT (rectangle_options),
"default-fixed-size-width",
"default-fixed-size-height");
"default-aspect-numerator",
"default-aspect-denominator");
g_object_set (G_OBJECT (rectangle_options),
"use-string-current", TRUE,
NULL);
}
else
{
/* There is no pending rectangle, set default Fixed: Size to
* 100x100.
*/
g_object_set (G_OBJECT (rectangle_options),
"default-aspect-numerator", 1.0,
"default-aspect-denominator", 1.0,
NULL);
g_object_set (G_OBJECT (rectangle_options),
"default-fixed-size-width", 100.0,
"default-fixed-size-height", 100.0,
"use-string-current", FALSE,
NULL);
}
}

View File

@ -56,6 +56,7 @@ enum
PROP_DEFAULT_RIGHT_NUMBER,
PROP_USER_OVERRIDE,
PROP_SEPARATORS,
PROP_DEFAULT_TEXT,
PROP_ALLOW_SIMPLIFICATION,
PROP_MIN_VALID_VALUE,
PROP_MAX_VALID_VALUE,
@ -96,6 +97,9 @@ typedef struct
gunichar *separators;
glong num_separators;
/* A string to be shown in the entry when in automatic mode */
gchar *default_text;
/* Whether or to not to divide the numbers with the greatest common
* divisor when input ends in '='.
*/
@ -230,6 +234,12 @@ gimp_number_pair_entry_class_init (GimpNumberPairEntryClass *klass)
NULL,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class, PROP_DEFAULT_TEXT,
g_param_spec_string ("default-text",
"Default text",
"String to show when in automatic mode",
NULL,
GIMP_PARAM_READWRITE));
g_object_class_install_property (object_class, PROP_ALLOW_SIMPLIFICATION,
g_param_spec_boolean ("allow-simplification",
"Allow simplification",
@ -282,6 +292,7 @@ gimp_number_pair_entry_init (GimpNumberPairEntry *entry)
priv->user_override = FALSE;
priv->font_italic = FALSE;
priv->separators = NULL;
priv->default_text = NULL;
priv->num_separators = 0;
priv->allow_simplification = FALSE;
priv->min_valid_value = G_MINDOUBLE;
@ -570,6 +581,59 @@ gimp_number_pair_entry_get_values (GimpNumberPairEntry *entry,
*right = priv->right_number;
}
/**
* gimp_number_pair_entry_set_default_text:
* @entry: A #GimpNumberPairEntry widget.
* @string: Default string.
*
* Causes the entry to show a given string when in automatic mode,
* instead of the default numbers. The only thing this does is making
* the #GimpNumberPairEntry showing this string, the internal state
* and API calls are not affected.
*
* Set the default string to %NULL to display default values as
* normal.
*
* Since: GIMP 2.4
*/
void gimp_number_pair_entry_set_default_text (GimpNumberPairEntry *entry,
const gchar *string)
{
GimpNumberPairEntryPrivate *priv;
g_return_if_fail (GIMP_IS_NUMBER_PAIR_ENTRY (entry));
priv = GIMP_NUMBER_PAIR_ENTRY_GET_PRIVATE (entry);
g_free (priv->default_text);
priv->default_text = g_strdup (string);
gimp_number_pair_entry_update_text (entry);
g_object_notify (G_OBJECT (entry), "default-text");
}
/**
* gimp_number_pair_entry_get_default_text:
* @entry: A #GimpNumberPairEntry widget.
* @string: A string to be shown.
*
* Returns the string manully set to be shown, or %NULL if values are
* shown in a normal fashion.
*
* Since: GIMP 2.4
*/
const gchar * gimp_number_pair_entry_get_default_text (GimpNumberPairEntry *entry)
{
GimpNumberPairEntryPrivate *priv;
g_return_val_if_fail (GIMP_IS_NUMBER_PAIR_ENTRY (entry), NULL);
priv = GIMP_NUMBER_PAIR_ENTRY_GET_PRIVATE (entry);
return priv->default_text;
}
/**
* gimp_number_pair_entry_set_aspect:
* @entry: A #GimpNumberPairEntry widget.
@ -864,9 +928,21 @@ gimp_number_pair_entry_update_text (GimpNumberPairEntry *entry)
GimpNumberPairEntryPrivate *priv = GIMP_NUMBER_PAIR_ENTRY_GET_PRIVATE (entry);
gchar *buffer;
buffer = gimp_number_pair_entry_strdup_number_pair_string (entry,
priv->left_number,
priv->right_number);
if (! priv->user_override &&
priv->default_text != NULL)
{
/* Instead of the numbers, show the string explicitly set by a
* client to show when in automatic mode.
*/
buffer = g_strdup (priv->default_text);
}
else
{
buffer = gimp_number_pair_entry_strdup_number_pair_string (entry,
priv->left_number,
priv->right_number);
}
g_signal_handlers_block_by_func (entry,
gimp_number_pair_entry_changed, NULL);
@ -1024,6 +1100,10 @@ gimp_number_pair_entry_set_property (GObject *object,
else
priv->separators = NULL;
break;
case PROP_DEFAULT_TEXT:
gimp_number_pair_entry_set_default_text (entry,
g_value_get_string (value));
break;
case PROP_ALLOW_SIMPLIFICATION:
priv->allow_simplification = g_value_get_boolean (value);
break;
@ -1082,6 +1162,9 @@ gimp_number_pair_entry_get_property (GObject *object,
case PROP_ALLOW_SIMPLIFICATION:
g_value_set_boolean (value, priv->allow_simplification);
break;
case PROP_DEFAULT_TEXT:
g_value_set_string (value, priv->default_text);
break;
case PROP_MIN_VALID_VALUE:
g_value_set_double (value, priv->min_valid_value);
break;

View File

@ -78,6 +78,11 @@ void gimp_number_pair_entry_set_values (GimpNumberPairEntry *e
void gimp_number_pair_entry_get_values (GimpNumberPairEntry *entry,
gdouble *left,
gdouble *right);
void gimp_number_pair_entry_set_default_text (GimpNumberPairEntry *entry,
const gchar *string);
const gchar * gimp_number_pair_entry_get_default_text (GimpNumberPairEntry *entry);
void gimp_number_pair_entry_set_ratio (GimpNumberPairEntry *entry,
gdouble ratio);
gdouble gimp_number_pair_entry_get_ratio (GimpNumberPairEntry *entry);

View File

@ -177,6 +177,7 @@ EXPORTS
gimp_memsize_entry_set_value
gimp_menu_item_update
gimp_number_pair_entry_get_aspect
gimp_number_pair_entry_get_default_text
gimp_number_pair_entry_get_default_values
gimp_number_pair_entry_get_ratio
gimp_number_pair_entry_get_type
@ -184,6 +185,7 @@ EXPORTS
gimp_number_pair_entry_get_values
gimp_number_pair_entry_new
gimp_number_pair_entry_set_aspect
gimp_number_pair_entry_set_default_text
gimp_number_pair_entry_set_default_values
gimp_number_pair_entry_set_ratio
gimp_number_pair_entry_set_user_override