]> git.sur5r.net Git - glabels/blob - src/object-editor-position-page.c
Updated Spanish translation
[glabels] / src / object-editor-position-page.c
1 /*
2  *  object-editor-position-page.c
3  *  Copyright (C) 2003-2009  Jim Evins <evins@snaught.com>.
4  *
5  *  This file is part of gLabels.
6  *
7  *  gLabels is free software: you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation, either version 3 of the License, or
10  *  (at your option) any later version.
11  *
12  *  gLabels is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with gLabels.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21 #include <config.h>
22
23 #include "object-editor.h"
24
25 #include <glib/gi18n.h>
26 #include <gtk/gtk.h>
27 #include <math.h>
28
29 #include "prefs.h"
30 #include "builder-util.h"
31 #include "units-util.h"
32
33 #include "object-editor-private.h"
34
35 #include "debug.h"
36
37
38 /*===========================================*/
39 /* Private macros                            */
40 /*===========================================*/
41
42
43 /*===========================================*/
44 /* Private data types                        */
45 /*===========================================*/
46
47
48 /*===========================================*/
49 /* Private globals                           */
50 /*===========================================*/
51
52
53 /*===========================================*/
54 /* Local function prototypes                 */
55 /*===========================================*/
56
57
58 /*--------------------------------------------------------------------------*/
59 /* PRIVATE.  Prepare position page.                                         */
60 /*--------------------------------------------------------------------------*/
61 void
62 gl_object_editor_prepare_position_page (glObjectEditor *editor)
63 {
64         lglUnits      units;
65         const gchar  *units_string;
66         gdouble       climb_rate;
67         gint          digits;
68
69         gl_debug (DEBUG_EDITOR, "START");
70
71         /* Extract widgets from XML tree. */
72         gl_builder_util_get_widgets (editor->priv->builder,
73                                      "pos_page_vbox",     &editor->priv->pos_page_vbox,
74                                      "pos_x_spin",        &editor->priv->pos_x_spin,
75                                      "pos_y_spin",        &editor->priv->pos_y_spin,
76                                      "pos_x_units_label", &editor->priv->pos_x_units_label,
77                                      "pos_y_units_label", &editor->priv->pos_y_units_label,
78                                      NULL);
79
80         /* Get configuration information */
81         units = gl_prefs_model_get_units (gl_prefs);
82         units_string = lgl_units_get_name (units);
83         editor->priv->units_per_point = lgl_units_get_units_per_point (units);
84         climb_rate = gl_units_util_get_step_size (units);
85         digits = gl_units_util_get_precision (units);
86
87         /* Modify widgets based on configuration */
88         gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->pos_x_spin), digits);
89         gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->pos_x_spin),
90                                         climb_rate, 10.0*climb_rate);
91         gtk_label_set_text (GTK_LABEL(editor->priv->pos_x_units_label), units_string);
92         gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->pos_y_spin), digits);
93         gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->pos_y_spin),
94                                         climb_rate, 10.0*climb_rate);
95         gtk_label_set_text (GTK_LABEL(editor->priv->pos_y_units_label), units_string);
96
97         /* Un-hide */
98         gtk_widget_show_all (editor->priv->pos_page_vbox);
99
100         /* Connect signals */
101         g_signal_connect_swapped (G_OBJECT (editor->priv->pos_x_spin),
102                                   "value-changed",
103                                   G_CALLBACK (gl_object_editor_changed_cb),
104                                   G_OBJECT (editor));
105         g_signal_connect_swapped (G_OBJECT (editor->priv->pos_y_spin),
106                                   "value-changed",
107                                   G_CALLBACK (gl_object_editor_changed_cb),
108                                   G_OBJECT (editor));
109
110         gl_debug (DEBUG_EDITOR, "END");
111 }
112
113
114 /*****************************************************************************/
115 /* Set position.                                                             */
116 /*****************************************************************************/
117 void
118 gl_object_editor_set_position (glObjectEditor      *editor,
119                                  gdouble                x,
120                                  gdouble                y)
121 {
122         gl_debug (DEBUG_EDITOR, "START");
123
124
125         g_signal_handlers_block_by_func (G_OBJECT (editor->priv->pos_x_spin),
126                                          gl_object_editor_changed_cb, editor);
127         g_signal_handlers_block_by_func (G_OBJECT (editor->priv->pos_y_spin),
128                                          gl_object_editor_changed_cb, editor);
129
130
131         /* save a copy in internal units */
132         editor->priv->x = x;
133         editor->priv->y = y;
134
135         /* convert internal units to displayed units */
136         gl_debug (DEBUG_EDITOR, "internal x,y = %g, %g", x, y);
137         x *= editor->priv->units_per_point;
138         y *= editor->priv->units_per_point;
139         gl_debug (DEBUG_EDITOR, "display x,y = %g, %g", x, y);
140
141         /* Set widget values */
142         gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->pos_x_spin), x);
143         gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->pos_y_spin), y);
144
145
146         g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->pos_x_spin),
147                                            gl_object_editor_changed_cb, editor);
148         g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->pos_y_spin),
149                                            gl_object_editor_changed_cb, editor);
150
151
152         gl_debug (DEBUG_EDITOR, "END");
153 }
154
155
156 /*****************************************************************************/
157 /* Set maximum position.                                                     */
158 /*****************************************************************************/
159 void
160 gl_object_editor_set_max_position (glObjectEditor      *editor,
161                                      gdouble                x_max,
162                                      gdouble                y_max)
163 {
164         gdouble tmp;
165
166         gl_debug (DEBUG_EDITOR, "START");
167
168
169         g_signal_handlers_block_by_func (G_OBJECT (editor->priv->pos_x_spin),
170                                          gl_object_editor_changed_cb, editor);
171         g_signal_handlers_block_by_func (G_OBJECT (editor->priv->pos_y_spin),
172                                          gl_object_editor_changed_cb, editor);
173
174
175         /* save a copy in internal units */
176         editor->priv->x_max = x_max;
177         editor->priv->y_max = y_max;
178
179         /* convert internal units to displayed units */
180         gl_debug (DEBUG_EDITOR, "internal x_max,y_max = %g, %g", x_max, y_max);
181         x_max *= editor->priv->units_per_point;
182         y_max *= editor->priv->units_per_point;
183         gl_debug (DEBUG_EDITOR, "display x_max,y_max = %g, %g", x_max, y_max);
184
185         /* Set widget values */
186         tmp = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->pos_x_spin));
187         gtk_spin_button_set_range (GTK_SPIN_BUTTON (editor->priv->pos_x_spin), -x_max, 2.0*x_max);
188         gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->pos_x_spin), tmp);
189         tmp = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->pos_y_spin));
190         gtk_spin_button_set_range (GTK_SPIN_BUTTON (editor->priv->pos_y_spin), -y_max, 2.0*y_max);
191         gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->pos_y_spin), tmp);
192
193
194         g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->pos_x_spin),
195                                            gl_object_editor_changed_cb, editor);
196         g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->pos_y_spin),
197                                            gl_object_editor_changed_cb, editor);
198
199
200         gl_debug (DEBUG_EDITOR, "END");
201 }
202
203
204 /*****************************************************************************/
205 /* Query position.                                                           */
206 /*****************************************************************************/
207 void
208 gl_object_editor_get_position (glObjectEditor      *editor,
209                                  gdouble               *x,
210                                  gdouble               *y)
211 {
212         gl_debug (DEBUG_EDITOR, "START");
213
214         /* Get values from widgets */
215         *x = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->pos_x_spin));
216         *y = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->pos_y_spin));
217
218         /* convert everything back to our internal units (points) */
219         *x /= editor->priv->units_per_point;
220         *y /= editor->priv->units_per_point;
221
222         /* save a copy in internal units */
223         editor->priv->x = *x;
224         editor->priv->y = *y;
225
226         gl_debug (DEBUG_EDITOR, "END");
227 }
228
229
230 /*****************************************************************************/
231 /* PRIVATE. Prefs changed callback.  Update units related items.            */
232 /*****************************************************************************/
233 void
234 position_prefs_changed_cb (glObjectEditor *editor)
235 {
236         lglUnits      units;
237         const gchar  *units_string;
238         gdouble       climb_rate;
239         gint          digits;
240
241         gl_debug (DEBUG_EDITOR, "START");
242
243
244         g_signal_handlers_block_by_func (G_OBJECT (editor->priv->pos_x_spin),
245                                          gl_object_editor_changed_cb, editor);
246         g_signal_handlers_block_by_func (G_OBJECT (editor->priv->pos_y_spin),
247                                          gl_object_editor_changed_cb, editor);
248
249
250         /* Get new configuration information */
251         units = gl_prefs_model_get_units (gl_prefs);
252         units_string = lgl_units_get_name (units);
253         editor->priv->units_per_point = lgl_units_get_units_per_point (units);
254         climb_rate = gl_units_util_get_step_size (units);
255         digits = gl_units_util_get_precision (units);
256
257         /* Update characteristics of x_spin/y_spin */
258         gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->pos_x_spin), digits);
259         gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->pos_y_spin), digits);
260         gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->pos_x_spin),
261                                         climb_rate, 10.0*climb_rate);
262         gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->pos_y_spin),
263                                         climb_rate, 10.0*climb_rate);
264
265
266         /* Update units_labels */
267         gtk_label_set_text (GTK_LABEL(editor->priv->pos_x_units_label),
268                             units_string);
269         gtk_label_set_text (GTK_LABEL(editor->priv->pos_y_units_label),
270                             units_string);
271
272         /* Update values of x_spin/y_spin */
273         gl_object_editor_set_position (editor, editor->priv->x, editor->priv->y);
274         gl_object_editor_set_max_position (editor, editor->priv->x_max, editor->priv->y_max);
275
276
277         g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->pos_x_spin),
278                                            gl_object_editor_changed_cb, editor);
279         g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->pos_y_spin),
280                                            gl_object_editor_changed_cb, editor);
281
282
283         gl_debug (DEBUG_EDITOR, "END");
284 }
285
286
287
288 /*
289  * Local Variables:       -- emacs
290  * mode: C                -- emacs
291  * c-basic-offset: 8      -- emacs
292  * tab-width: 8           -- emacs
293  * indent-tabs-mode: nil  -- emacs
294  * End:                   -- emacs
295  */