1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
4 * (GLABELS) Label and Business Card Creation program for GNOME
6 * object-editor.c: object properties editor module
8 * Copyright (C) 2003 Jim Evins <evins@snaught.com>.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "object-editor.h"
28 #include <glib/gi18n.h>
29 #include <gtk/gtklabel.h>
30 #include <gtk/gtkspinbutton.h>
35 #include "object-editor-private.h"
39 /*===========================================*/
41 /*===========================================*/
43 #define LENGTH(x,y) sqrt( (x)*(x) + (y)*(y) )
44 #define ANGLE(x,y) ( (180.0/G_PI)*atan2( -(y), (x) ) )
45 #define COMP_X(l,a) ( (l) * cos( (G_PI/180.0)*(a) ) )
46 #define COMP_Y(l,a) ( -(l) * sin( (G_PI/180.0)*(a) ) )
49 /*===========================================*/
50 /* Private data types */
51 /*===========================================*/
53 /*===========================================*/
55 /*===========================================*/
57 /*===========================================*/
58 /* Local function prototypes */
59 /*===========================================*/
63 /*--------------------------------------------------------------------------*/
64 /* PRIVATE. Prepare line size page. */
65 /*--------------------------------------------------------------------------*/
67 gl_object_editor_prepare_lsize_page (glObjectEditor *editor)
69 const gchar *units_string;
73 gl_debug (DEBUG_EDITOR, "START");
75 /* Extract widgets from XML tree. */
76 editor->priv->lsize_page_vbox =
77 glade_xml_get_widget (editor->priv->gui, "lsize_page_vbox");
78 editor->priv->lsize_r_spin =
79 glade_xml_get_widget (editor->priv->gui, "lsize_r_spin");
80 editor->priv->lsize_theta_spin =
81 glade_xml_get_widget (editor->priv->gui, "lsize_theta_spin");
82 editor->priv->lsize_r_units_label =
83 glade_xml_get_widget (editor->priv->gui, "lsize_r_units_label");
85 /* Get configuration information */
86 units_string = gl_prefs_get_units_string ();
87 editor->priv->units_per_point = gl_prefs_get_units_per_point ();
88 climb_rate = gl_prefs_get_units_step_size ();
89 digits = gl_prefs_get_units_precision ();
91 /* Modify widgets based on configuration */
92 gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->lsize_r_spin), digits);
93 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->lsize_r_spin),
94 climb_rate, 10.0*climb_rate);
95 gtk_label_set_text (GTK_LABEL(editor->priv->lsize_r_units_label), units_string);
98 gtk_widget_show_all (editor->priv->lsize_page_vbox);
100 /* Connect signals */
101 g_signal_connect_swapped (G_OBJECT (editor->priv->lsize_r_spin),
103 G_CALLBACK (gl_object_editor_changed_cb),
105 g_signal_connect_swapped (G_OBJECT (editor->priv->lsize_theta_spin),
107 G_CALLBACK (gl_object_editor_changed_cb),
110 gl_debug (DEBUG_EDITOR, "END");
113 /*****************************************************************************/
115 /*****************************************************************************/
117 gl_object_editor_set_lsize (glObjectEditor *editor,
123 gl_debug (DEBUG_EDITOR, "START");
125 editor->priv->stop_signals = TRUE;
127 /* save a copy in internal units */
128 editor->priv->dx = dx;
129 editor->priv->dy = dy;
131 /* convert internal units to displayed units */
132 gl_debug (DEBUG_EDITOR, "internal dx,dy = %g, %g", dx, dy);
133 dx *= editor->priv->units_per_point;
134 dy *= editor->priv->units_per_point;
135 gl_debug (DEBUG_EDITOR, "display dx,dy = %g, %g", dx, dy);
138 theta = ANGLE (dx, dy);
140 /* Set widget values */
141 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->lsize_r_spin), r);
142 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->lsize_theta_spin),
145 editor->priv->stop_signals = FALSE;
147 gl_debug (DEBUG_EDITOR, "END");
150 /*****************************************************************************/
151 /* Set maximum line size. */
152 /*****************************************************************************/
154 gl_object_editor_set_max_lsize (glObjectEditor *editor,
160 gl_debug (DEBUG_EDITOR, "START");
162 if (editor->priv->lsize_page_vbox)
165 editor->priv->stop_signals = TRUE;
167 /* save a copy in internal units */
168 editor->priv->dx_max = dx_max;
169 editor->priv->dy_max = dy_max;
171 /* convert internal units to displayed units */
172 gl_debug (DEBUG_EDITOR, "internal dx_max,dy_max = %g, %g", dx_max, dy_max);
173 dx_max *= editor->priv->units_per_point;
174 dy_max *= editor->priv->units_per_point;
175 gl_debug (DEBUG_EDITOR, "display dx_max,dy_max = %g, %g", dx_max, dy_max);
177 /* Set widget values */
178 tmp = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->lsize_r_spin));
179 gtk_spin_button_set_range (GTK_SPIN_BUTTON (editor->priv->lsize_r_spin),
180 0.0, 2.0*LENGTH (dx_max, dy_max));
181 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->lsize_r_spin), tmp);
183 editor->priv->stop_signals = FALSE;
187 gl_debug (DEBUG_EDITOR, "END");
190 /*****************************************************************************/
191 /* Query line size. */
192 /*****************************************************************************/
194 gl_object_editor_get_lsize (glObjectEditor *editor,
200 gl_debug (DEBUG_EDITOR, "START");
202 /* Get values from widgets */
203 r = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->lsize_r_spin));
204 theta = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->lsize_theta_spin));
206 /* convert everything back to our internal units (points) */
207 r /= editor->priv->units_per_point;
209 *dx = COMP_X (r, theta);
210 *dy = COMP_Y (r, theta);
212 /* save a copy in internal units */
213 editor->priv->dx = *dx;
214 editor->priv->dy = *dy;
216 gl_debug (DEBUG_EDITOR, "END");
219 /*****************************************************************************/
220 /* PRIVATE. Prefs changed callback. Update units related items. */
221 /*****************************************************************************/
223 lsize_prefs_changed_cb (glObjectEditor *editor)
225 const gchar *units_string;
229 gl_debug (DEBUG_EDITOR, "START");
231 /* Get new configuration information */
232 units_string = gl_prefs_get_units_string ();
233 editor->priv->units_per_point = gl_prefs_get_units_per_point ();
234 climb_rate = gl_prefs_get_units_step_size ();
235 digits = gl_prefs_get_units_precision ();
237 /* Update characteristics of r_spin */
238 editor->priv->stop_signals = TRUE;
239 gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->lsize_r_spin),
241 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->lsize_r_spin),
242 climb_rate, 10.0*climb_rate);
243 editor->priv->stop_signals = FALSE;
245 /* Update r_units_label */
246 gtk_label_set_text (GTK_LABEL(editor->priv->lsize_r_units_label),
249 /* Update values of r_spin/theta_spin */
250 gl_object_editor_set_lsize (editor,
253 gl_object_editor_set_max_lsize (editor,
254 editor->priv->dx_max,
255 editor->priv->dy_max);
257 gl_debug (DEBUG_EDITOR, "END");