From: Jim Evins Date: Sun, 14 Dec 2003 00:37:35 +0000 (+0000) Subject: Track changes in prefered units and update widgets appropriately. This addresses... X-Git-Tag: glabels-2_3_0~522 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=d8c8689edc8700b670853f040d4aab1c41138a33;p=glabels Track changes in prefered units and update widgets appropriately. This addresses bug #852974. git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@372 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- diff --git a/glabels2/src/object-editor-lsize-page.c b/glabels2/src/object-editor-lsize-page.c index 866cfb8f..6cbaf2f0 100644 --- a/glabels2/src/object-editor-lsize-page.c +++ b/glabels2/src/object-editor-lsize-page.c @@ -133,6 +133,10 @@ gl_object_editor_set_lsize (glObjectEditor *editor, gl_object_editor_changed_cb, editor); + /* save a copy in internal units */ + editor->priv->dx = dx; + editor->priv->dy = dy; + /* convert internal units to displayed units */ gl_debug (DEBUG_EDITOR, "internal dx,dy = %g, %g", dx, dy); dx *= editor->priv->units_per_point; @@ -173,6 +177,10 @@ gl_object_editor_set_max_lsize (glObjectEditor *editor, gl_object_editor_changed_cb, editor); + /* save a copy in internal units */ + editor->priv->dx_max = dx_max; + editor->priv->dy_max = dy_max; + /* convert internal units to displayed units */ gl_debug (DEBUG_EDITOR, "internal dx_max,dy_max = %g, %g", dx_max, dy_max); dx_max *= editor->priv->units_per_point; @@ -214,6 +222,55 @@ gl_object_editor_get_lsize (glObjectEditor *editor, *dx = COMP_X (r, theta); *dy = COMP_Y (r, theta); + /* save a copy in internal units */ + editor->priv->dx = *dx; + editor->priv->dy = *dy; + + gl_debug (DEBUG_EDITOR, "END"); +} + +/*****************************************************************************/ +/* PRIVATE. Prefs changed callback. Update units related items. */ +/*****************************************************************************/ +void +lsize_prefs_changed_cb (glObjectEditor *editor) +{ + const gchar *units_string; + gdouble climb_rate; + gint digits; + + gl_debug (DEBUG_EDITOR, "START"); + + /* Get new configuration information */ + units_string = gl_prefs_get_units_string (); + editor->priv->units_per_point = gl_prefs_get_units_per_point (); + climb_rate = gl_prefs_get_units_step_size (); + digits = gl_prefs_get_units_precision (); + + /* Update characteristics of r_spin */ + g_signal_handlers_block_by_func (G_OBJECT(editor->priv->lsize_r_spin), + gl_object_editor_changed_cb, + editor); + gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->lsize_r_spin), + digits); + gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->lsize_r_spin), + climb_rate, 10.0*climb_rate); + g_signal_handlers_unblock_by_func (G_OBJECT(editor->priv->lsize_r_spin), + gl_object_editor_changed_cb, + editor); + + /* Update r_units_label */ + gtk_label_set_text (GTK_LABEL(editor->priv->lsize_r_units_label), + units_string); + + /* Update values of r_spin/theta_spin */ + gl_object_editor_set_lsize (editor, + editor->priv->dx, + editor->priv->dy); + gl_object_editor_set_max_lsize (editor, + editor->priv->dx_max, + editor->priv->dy_max); + gl_debug (DEBUG_EDITOR, "END"); } diff --git a/glabels2/src/object-editor-position-page.c b/glabels2/src/object-editor-position-page.c index 5e1be495..edf80300 100644 --- a/glabels2/src/object-editor-position-page.c +++ b/glabels2/src/object-editor-position-page.c @@ -130,6 +130,10 @@ gl_object_editor_set_position (glObjectEditor *editor, gl_object_editor_changed_cb, editor); + /* save a copy in internal units */ + editor->priv->x = x; + editor->priv->y = y; + /* convert internal units to displayed units */ gl_debug (DEBUG_EDITOR, "internal x,y = %g, %g", x, y); x *= editor->priv->units_per_point; @@ -169,6 +173,10 @@ gl_object_editor_set_max_position (glObjectEditor *editor, gl_object_editor_changed_cb, editor); + /* save a copy in internal units */ + editor->priv->x_max = x_max; + editor->priv->y_max = y_max; + /* convert internal units to displayed units */ gl_debug (DEBUG_EDITOR, "internal x_max,y_max = %g, %g", x_max, y_max); x_max *= editor->priv->units_per_point; @@ -213,6 +221,67 @@ gl_object_editor_get_position (glObjectEditor *editor, *x /= editor->priv->units_per_point; *y /= editor->priv->units_per_point; + /* save a copy in internal units */ + editor->priv->x = *x; + editor->priv->y = *y; + + gl_debug (DEBUG_EDITOR, "END"); +} + +/*****************************************************************************/ +/* PRIVATE. Prefs changed callback. Update units related items. */ +/*****************************************************************************/ +void +position_prefs_changed_cb (glObjectEditor *editor) +{ + const gchar *units_string; + gdouble climb_rate; + gint digits; + + gl_debug (DEBUG_EDITOR, "START"); + + /* Get new configuration information */ + units_string = gl_prefs_get_units_string (); + editor->priv->units_per_point = gl_prefs_get_units_per_point (); + climb_rate = gl_prefs_get_units_step_size (); + digits = gl_prefs_get_units_precision (); + + /* Update characteristics of x_spin/y_spin */ + g_signal_handlers_block_by_func (G_OBJECT(editor->priv->pos_x_spin), + gl_object_editor_changed_cb, + editor); + g_signal_handlers_block_by_func (G_OBJECT(editor->priv->pos_y_spin), + gl_object_editor_changed_cb, + editor); + gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->pos_x_spin), + digits); + gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->pos_y_spin), + digits); + gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->pos_x_spin), + climb_rate, 10.0*climb_rate); + gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->pos_y_spin), + climb_rate, 10.0*climb_rate); + g_signal_handlers_unblock_by_func (G_OBJECT(editor->priv->pos_x_spin), + gl_object_editor_changed_cb, + editor); + g_signal_handlers_unblock_by_func (G_OBJECT(editor->priv->pos_y_spin), + gl_object_editor_changed_cb, + editor); + + /* Update units_labels */ + gtk_label_set_text (GTK_LABEL(editor->priv->pos_x_units_label), + units_string); + gtk_label_set_text (GTK_LABEL(editor->priv->pos_y_units_label), + units_string); + + /* Update values of x_spin/y_spin */ + gl_object_editor_set_position (editor, + editor->priv->x, + editor->priv->y); + gl_object_editor_set_max_position (editor, + editor->priv->x_max, + editor->priv->y_max); + gl_debug (DEBUG_EDITOR, "END"); } diff --git a/glabels2/src/object-editor-private.h b/glabels2/src/object-editor-private.h index 46d90f5c..f3672d20 100644 --- a/glabels2/src/object-editor-private.h +++ b/glabels2/src/object-editor-private.h @@ -43,6 +43,10 @@ struct _glObjectEditorPrivate { GtkWidget *pos_y_spin; GtkWidget *pos_x_units_label; GtkWidget *pos_y_units_label; + gdouble x; + gdouble y; + gdouble x_max; + gdouble y_max; GtkWidget *size_page_vbox; GtkWidget *size_w_spin; @@ -52,6 +56,10 @@ struct _glObjectEditorPrivate { GtkWidget *size_aspect_checkbutton; GtkWidget *size_reset_image_button; gdouble size_aspect_ratio; + gdouble w; + gdouble h; + gdouble w_max; + gdouble h_max; gdouble w_base; gdouble h_base; @@ -59,6 +67,10 @@ struct _glObjectEditorPrivate { GtkWidget *lsize_r_spin; GtkWidget *lsize_theta_spin; GtkWidget *lsize_r_units_label; + gdouble dx; + gdouble dy; + gdouble dx_max; + gdouble dy_max; GtkWidget *fill_page_vbox; GtkWidget *fill_color_combo; @@ -141,6 +153,10 @@ void gl_object_editor_prepare_data_page (glObjectEditor *editor); void gl_object_editor_changed_cb (glObjectEditor *editor); +void lsize_prefs_changed_cb (glObjectEditor *editor); +void size_prefs_changed_cb (glObjectEditor *editor); +void position_prefs_changed_cb (glObjectEditor *editor); + G_END_DECLS #endif diff --git a/glabels2/src/object-editor-size-page.c b/glabels2/src/object-editor-size-page.c index 83178a48..817524cd 100644 --- a/glabels2/src/object-editor-size-page.c +++ b/glabels2/src/object-editor-size-page.c @@ -227,6 +227,8 @@ h_spin_cb (glObjectEditor *editor) static void size_reset_cb (glObjectEditor *editor) { + gdouble w_base, h_base; + g_signal_handlers_block_by_func (G_OBJECT (editor->priv->size_w_spin), G_CALLBACK (h_spin_cb), editor); @@ -234,10 +236,13 @@ size_reset_cb (glObjectEditor *editor) G_CALLBACK (h_spin_cb), editor); + w_base *= editor->priv->units_per_point; + h_base *= editor->priv->units_per_point; + gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->size_w_spin), - editor->priv->w_base); + w_base); gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->size_h_spin), - editor->priv->h_base); + h_base); g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->size_w_spin), G_CALLBACK (h_spin_cb), @@ -266,6 +271,10 @@ gl_object_editor_set_size (glObjectEditor *editor, h_spin_cb, editor); + /* save a copy in internal units */ + editor->priv->w = w; + editor->priv->h = h; + /* convert internal units to displayed units */ gl_debug (DEBUG_EDITOR, "internal w,h = %g, %g", w, h); w *= editor->priv->units_per_point; @@ -308,6 +317,10 @@ gl_object_editor_set_max_size (glObjectEditor *editor, h_spin_cb, editor); + /* save a copy in internal units */ + editor->priv->w_max = w_max; + editor->priv->h_max = h_max; + /* convert internal units to displayed units */ gl_debug (DEBUG_EDITOR, "internal w_max,h_max = %g, %g", w_max, h_max); w_max *= editor->priv->units_per_point; @@ -342,9 +355,6 @@ gl_object_editor_set_base_size (glObjectEditor *editor, gdouble w_base, gdouble h_base) { - w_base *= editor->priv->units_per_point; - h_base *= editor->priv->units_per_point; - gl_debug (DEBUG_EDITOR, "Setting w_base = %g", w_base); gl_debug (DEBUG_EDITOR, "Setting h_base = %g", h_base); @@ -371,6 +381,67 @@ gl_object_editor_get_size (glObjectEditor *editor, *w /= editor->priv->units_per_point; *h /= editor->priv->units_per_point; + /* save a copy in internal units */ + editor->priv->w = *w; + editor->priv->h = *h; + + gl_debug (DEBUG_EDITOR, "END"); +} + +/*****************************************************************************/ +/* PRIVATE. Prefs changed callback. Update units related items. */ +/*****************************************************************************/ +void +size_prefs_changed_cb (glObjectEditor *editor) +{ + const gchar *units_string; + gdouble climb_rate; + gint digits; + + gl_debug (DEBUG_EDITOR, "START"); + + /* Get new configuration information */ + units_string = gl_prefs_get_units_string (); + editor->priv->units_per_point = gl_prefs_get_units_per_point (); + climb_rate = gl_prefs_get_units_step_size (); + digits = gl_prefs_get_units_precision (); + + /* Update characteristics of w_spin/h_spin */ + g_signal_handlers_block_by_func (G_OBJECT(editor->priv->size_w_spin), + w_spin_cb, + editor); + g_signal_handlers_block_by_func (G_OBJECT(editor->priv->size_h_spin), + h_spin_cb, + editor); + gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->size_w_spin), + digits); + gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->size_h_spin), + digits); + gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->size_w_spin), + climb_rate, 10.0*climb_rate); + gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->size_h_spin), + climb_rate, 10.0*climb_rate); + g_signal_handlers_unblock_by_func (G_OBJECT(editor->priv->size_w_spin), + w_spin_cb, + editor); + g_signal_handlers_unblock_by_func (G_OBJECT(editor->priv->size_h_spin), + h_spin_cb, + editor); + + /* Update units_labels */ + gtk_label_set_text (GTK_LABEL(editor->priv->size_w_units_label), + units_string); + gtk_label_set_text (GTK_LABEL(editor->priv->size_h_units_label), + units_string); + + /* Update values of w_spin/h_spin */ + gl_object_editor_set_size (editor, + editor->priv->w, + editor->priv->h); + gl_object_editor_set_max_size (editor, + editor->priv->w_max, + editor->priv->h_max); + gl_debug (DEBUG_EDITOR, "END"); } diff --git a/glabels2/src/object-editor.c b/glabels2/src/object-editor.c index 0b28c9e5..e3cc464a 100644 --- a/glabels2/src/object-editor.c +++ b/glabels2/src/object-editor.c @@ -65,6 +65,8 @@ static void gl_object_notebook_construct_valist (glObjectEditor *editor, glObjectEditorOption first_option, va_list args); +static void prefs_changed_cb (glObjectEditor *editor); + /*****************************************************************************/ /* Boilerplate object stuff. */ @@ -174,6 +176,9 @@ gl_object_editor_finalize (GObject *object) g_free (editor->priv); + g_signal_handlers_disconnect_by_func (G_OBJECT(gl_prefs), + prefs_changed_cb, editor); + G_OBJECT_CLASS (parent_class)->finalize (object); gl_debug (DEBUG_EDITOR, "END"); @@ -308,6 +313,10 @@ gl_object_notebook_construct_valist (glObjectEditor *editor, gtk_widget_show (editor->priv->notebook); } + g_signal_connect_swapped (G_OBJECT (gl_prefs), "changed", + G_CALLBACK (prefs_changed_cb), + editor); + gl_debug (DEBUG_EDITOR, "END"); } @@ -469,3 +478,28 @@ gl_object_editor_construct_color_combo (gchar *name, return color_combo; } + +/*--------------------------------------------------------------------------*/ +/* PRIVATE. Prefs changed callback. Update units related items. */ +/*--------------------------------------------------------------------------*/ +static void +prefs_changed_cb (glObjectEditor *editor) +{ + + gl_debug (DEBUG_EDITOR, "START"); + + if (editor->priv->lsize_r_spin) { + lsize_prefs_changed_cb (editor); + } + + if (editor->priv->size_w_spin) { + size_prefs_changed_cb (editor); + } + + if (editor->priv->pos_x_spin) { + position_prefs_changed_cb (editor); + } + + gl_debug (DEBUG_EDITOR, "END"); +} + diff --git a/glabels2/src/wdgt-media-select.c b/glabels2/src/wdgt-media-select.c index ff7376b8..0dbe82c2 100644 --- a/glabels2/src/wdgt-media-select.c +++ b/glabels2/src/wdgt-media-select.c @@ -69,6 +69,8 @@ static void page_size_entry_changed_cb (GtkEntry *entry, gpointer user_data); static void template_entry_changed_cb (GtkEntry *entry, gpointer user_data); +static void prefs_changed_cb (glPrefsModel *gl_prefs, + gpointer user_data); static void details_update (glWdgtMediaSelect *media_select, gchar *name); @@ -159,6 +161,9 @@ gl_wdgt_media_select_finalize (GObject *object) media_select = GL_WDGT_MEDIA_SELECT (object); + g_signal_handlers_disconnect_by_func (G_OBJECT(gl_prefs), + prefs_changed_cb, media_select); + G_OBJECT_CLASS (parent_class)->finalize (object); gl_debug (DEBUG_MEDIA_SELECT, "END"); @@ -319,6 +324,9 @@ gl_wdgt_media_select_construct (glWdgtMediaSelect *media_select) g_signal_connect (G_OBJECT (media_select->template_entry), "changed", G_CALLBACK (template_entry_changed_cb), media_select); + g_signal_connect (G_OBJECT (gl_prefs), "changed", + G_CALLBACK (prefs_changed_cb), + media_select); g_free (page_size_name); @@ -392,6 +400,29 @@ template_entry_changed_cb (GtkEntry *entry, gl_debug (DEBUG_MEDIA_SELECT, "END"); } +/*--------------------------------------------------------------------------*/ +/* PRIVATE. modify widget due to change in prefs */ +/*--------------------------------------------------------------------------*/ +static void +prefs_changed_cb (glPrefsModel *gl_prefs, + gpointer user_data) +{ + glWdgtMediaSelect *media_select = GL_WDGT_MEDIA_SELECT (user_data); + gchar *name; + + gl_debug (DEBUG_MEDIA_SELECT, "START"); + + /* Update mini_preview canvas & details with template */ + name = gtk_editable_get_chars (GTK_EDITABLE (media_select->template_entry), 0, -1); + if ( strlen(name) ) { + gl_debug (DEBUG_MEDIA_SELECT, "name = \"%s\"", name); + details_update (media_select, name); + } + g_free (name); + + gl_debug (DEBUG_MEDIA_SELECT, "END"); +} + /*--------------------------------------------------------------------------*/ /* PRIVATE. update "details" widgets from new template. */ /*--------------------------------------------------------------------------*/