2 * object-editor-position-page.c
3 * Copyright (C) 2003-2009 Jim Evins <evins@snaught.com>.
5 * This file is part of gLabels.
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.
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.
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/>.
23 #include "object-editor.h"
25 #include <glib/gi18n.h>
30 #include "builder-util.h"
31 #include "units-util.h"
33 #include "object-editor-private.h"
38 /*===========================================*/
40 /*===========================================*/
43 /*===========================================*/
44 /* Private data types */
45 /*===========================================*/
48 /*===========================================*/
50 /*===========================================*/
53 /*===========================================*/
54 /* Local function prototypes */
55 /*===========================================*/
58 /*--------------------------------------------------------------------------*/
59 /* PRIVATE. Prepare position page. */
60 /*--------------------------------------------------------------------------*/
62 gl_object_editor_prepare_position_page (glObjectEditor *editor)
65 const gchar *units_string;
69 gl_debug (DEBUG_EDITOR, "START");
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,
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);
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);
98 gtk_widget_show_all (editor->priv->pos_page_vbox);
100 /* Connect signals */
101 g_signal_connect_swapped (G_OBJECT (editor->priv->pos_x_spin),
103 G_CALLBACK (gl_object_editor_changed_cb),
105 g_signal_connect_swapped (G_OBJECT (editor->priv->pos_y_spin),
107 G_CALLBACK (gl_object_editor_changed_cb),
110 gl_debug (DEBUG_EDITOR, "END");
114 /*****************************************************************************/
116 /*****************************************************************************/
118 gl_object_editor_set_position (glObjectEditor *editor,
122 gl_debug (DEBUG_EDITOR, "START");
124 editor->priv->stop_signals = TRUE;
126 /* save a copy in internal units */
130 /* convert internal units to displayed units */
131 gl_debug (DEBUG_EDITOR, "internal x,y = %g, %g", x, y);
132 x *= editor->priv->units_per_point;
133 y *= editor->priv->units_per_point;
134 gl_debug (DEBUG_EDITOR, "display x,y = %g, %g", x, y);
136 /* Set widget values */
137 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->pos_x_spin), x);
138 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->pos_y_spin), y);
140 editor->priv->stop_signals = FALSE;
142 gl_debug (DEBUG_EDITOR, "END");
146 /*****************************************************************************/
147 /* Set maximum position. */
148 /*****************************************************************************/
150 gl_object_editor_set_max_position (glObjectEditor *editor,
156 gl_debug (DEBUG_EDITOR, "START");
158 editor->priv->stop_signals = TRUE;
160 /* save a copy in internal units */
161 editor->priv->x_max = x_max;
162 editor->priv->y_max = y_max;
164 /* convert internal units to displayed units */
165 gl_debug (DEBUG_EDITOR, "internal x_max,y_max = %g, %g", x_max, y_max);
166 x_max *= editor->priv->units_per_point;
167 y_max *= editor->priv->units_per_point;
168 gl_debug (DEBUG_EDITOR, "display x_max,y_max = %g, %g", x_max, y_max);
170 /* Set widget values */
171 tmp = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->pos_x_spin));
172 gtk_spin_button_set_range (GTK_SPIN_BUTTON (editor->priv->pos_x_spin),
174 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->pos_x_spin), tmp);
175 tmp = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->pos_y_spin));
176 gtk_spin_button_set_range (GTK_SPIN_BUTTON (editor->priv->pos_y_spin),
178 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->pos_y_spin), tmp);
180 editor->priv->stop_signals = FALSE;
182 gl_debug (DEBUG_EDITOR, "END");
186 /*****************************************************************************/
187 /* Query position. */
188 /*****************************************************************************/
190 gl_object_editor_get_position (glObjectEditor *editor,
194 gl_debug (DEBUG_EDITOR, "START");
196 /* Get values from widgets */
197 *x = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->pos_x_spin));
198 *y = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->pos_y_spin));
200 /* convert everything back to our internal units (points) */
201 *x /= editor->priv->units_per_point;
202 *y /= editor->priv->units_per_point;
204 /* save a copy in internal units */
205 editor->priv->x = *x;
206 editor->priv->y = *y;
208 gl_debug (DEBUG_EDITOR, "END");
212 /*****************************************************************************/
213 /* PRIVATE. Prefs changed callback. Update units related items. */
214 /*****************************************************************************/
216 position_prefs_changed_cb (glObjectEditor *editor)
219 const gchar *units_string;
223 gl_debug (DEBUG_EDITOR, "START");
225 /* Get new configuration information */
226 units = gl_prefs_model_get_units (gl_prefs);
227 units_string = lgl_units_get_name (units);
228 editor->priv->units_per_point = lgl_units_get_units_per_point (units);
229 climb_rate = gl_units_util_get_step_size (units);
230 digits = gl_units_util_get_precision (units);
232 /* Update characteristics of x_spin/y_spin */
233 editor->priv->stop_signals = TRUE;
234 gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->pos_x_spin),
236 gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->pos_y_spin),
238 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->pos_x_spin),
239 climb_rate, 10.0*climb_rate);
240 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->pos_y_spin),
241 climb_rate, 10.0*climb_rate);
242 editor->priv->stop_signals = FALSE;
244 /* Update units_labels */
245 gtk_label_set_text (GTK_LABEL(editor->priv->pos_x_units_label),
247 gtk_label_set_text (GTK_LABEL(editor->priv->pos_y_units_label),
250 /* Update values of x_spin/y_spin */
251 gl_object_editor_set_position (editor,
254 gl_object_editor_set_max_position (editor,
256 editor->priv->y_max);
258 gl_debug (DEBUG_EDITOR, "END");
264 * Local Variables: -- emacs
266 * c-basic-offset: 8 -- emacs
267 * tab-width: 8 -- emacs
268 * indent-tabs-mode: nil -- emacs