2 * object-editor-shadow-page.c
3 * Copyright (C) 2006-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 "color-combo.h"
32 #include "field-button.h"
33 #include "builder-util.h"
34 #include "units-util.h"
36 #include "object-editor-private.h"
41 /*===========================================*/
43 /*===========================================*/
46 /*===========================================*/
47 /* Private data types */
48 /*===========================================*/
51 /*===========================================*/
53 /*===========================================*/
56 /*===========================================*/
57 /* Local function prototypes */
58 /*===========================================*/
60 static void shadow_enable_check_toggled_cb (glObjectEditor *editor);
61 static void shadow_color_radio_toggled_cb (glObjectEditor *editor);
64 /*--------------------------------------------------------------------------*/
65 /* PRIVATE. Prepare shadow page. */
66 /*--------------------------------------------------------------------------*/
68 gl_object_editor_prepare_shadow_page (glObjectEditor *editor)
71 const gchar *units_string;
75 gl_debug (DEBUG_EDITOR, "START");
77 /* Extract widgets from XML tree. */
78 gl_builder_util_get_widgets (editor->priv->builder,
79 "shadow_page_vbox", &editor->priv->shadow_page_vbox,
80 "shadow_enable_check", &editor->priv->shadow_enable_check,
81 "shadow_controls_table", &editor->priv->shadow_controls_table,
82 "shadow_x_spin", &editor->priv->shadow_x_spin,
83 "shadow_y_spin", &editor->priv->shadow_y_spin,
84 "shadow_x_units_label", &editor->priv->shadow_x_units_label,
85 "shadow_y_units_label", &editor->priv->shadow_y_units_label,
86 "shadow_color_radio", &editor->priv->shadow_color_radio,
87 "shadow_key_radio", &editor->priv->shadow_key_radio,
88 "shadow_color_hbox", &editor->priv->shadow_color_hbox,
89 "shadow_key_hbox", &editor->priv->shadow_key_hbox,
90 "shadow_opacity_spin", &editor->priv->shadow_opacity_spin,
93 editor->priv->shadow_color_combo = gl_color_combo_new (_("Default"),
94 GL_COLOR_SHADOW_DEFAULT,
95 GL_COLOR_SHADOW_DEFAULT);
96 gtk_container_add (GTK_CONTAINER (editor->priv->shadow_color_hbox),
97 editor->priv->shadow_color_combo);
99 editor->priv->shadow_key_combo = gl_field_button_new (NULL);
100 gtk_box_pack_start (GTK_BOX (editor->priv->shadow_key_hbox),
101 editor->priv->shadow_key_combo,
105 /* Get configuration information */
106 units = gl_prefs_model_get_units (gl_prefs);
107 units_string = lgl_units_get_name (units);
108 editor->priv->units_per_point = lgl_units_get_units_per_point (units);
109 climb_rate = gl_units_util_get_step_size (units);
110 digits = gl_units_util_get_precision (units);
112 /* Modify widgets based on configuration */
113 gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->shadow_x_spin), digits);
114 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->shadow_x_spin),
115 climb_rate, 10.0*climb_rate);
116 gtk_label_set_text (GTK_LABEL(editor->priv->shadow_x_units_label), units_string);
117 gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->shadow_y_spin), digits);
118 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->shadow_y_spin),
119 climb_rate, 10.0*climb_rate);
120 gtk_label_set_text (GTK_LABEL(editor->priv->shadow_y_units_label), units_string);
123 gtk_widget_show_all (editor->priv->shadow_page_vbox);
125 /* Connect signals */
126 g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_enable_check),
128 G_CALLBACK (shadow_enable_check_toggled_cb),
130 g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_x_spin),
132 G_CALLBACK (gl_object_editor_changed_cb),
134 g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_y_spin),
136 G_CALLBACK (gl_object_editor_changed_cb),
138 g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_color_combo),
140 G_CALLBACK (gl_object_editor_changed_cb),
142 g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_key_combo),
144 G_CALLBACK (gl_object_editor_changed_cb),
146 g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_color_radio),
148 G_CALLBACK (shadow_color_radio_toggled_cb),
150 g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_key_radio),
152 G_CALLBACK (shadow_color_radio_toggled_cb),
154 g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_opacity_spin),
156 G_CALLBACK (gl_object_editor_changed_cb),
159 gl_debug (DEBUG_EDITOR, "END");
163 /*****************************************************************************/
164 /* Set shadow parameters. */
165 /*****************************************************************************/
167 gl_object_editor_set_shadow_state (glObjectEditor *editor,
170 gl_debug (DEBUG_EDITOR, "START");
172 editor->priv->stop_signals = TRUE;
174 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->shadow_enable_check),
176 gtk_widget_set_sensitive (editor->priv->shadow_controls_table, state);
178 editor->priv->stop_signals = FALSE;
180 gl_debug (DEBUG_EDITOR, "END");
185 gl_object_editor_set_shadow_offset (glObjectEditor *editor,
189 gl_debug (DEBUG_EDITOR, "START");
191 editor->priv->stop_signals = TRUE;
193 /* save a copy in internal units */
194 editor->priv->shadow_x = x;
195 editor->priv->shadow_y = y;
197 /* convert internal units to displayed units */
198 gl_debug (DEBUG_EDITOR, "internal x,y = %g, %g", x, y);
199 x *= editor->priv->units_per_point;
200 y *= editor->priv->units_per_point;
201 gl_debug (DEBUG_EDITOR, "display x,y = %g, %g", x, y);
203 /* Set widget values */
204 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->shadow_x_spin), x);
205 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->shadow_y_spin), y);
207 editor->priv->stop_signals = FALSE;
209 gl_debug (DEBUG_EDITOR, "END");
214 gl_object_editor_set_shadow_color (glObjectEditor *editor,
216 glColorNode *color_node)
218 gl_debug (DEBUG_EDITOR, "START");
220 if (color_node == NULL)
225 editor->priv->stop_signals = TRUE;
227 gtk_widget_set_sensitive (editor->priv->shadow_key_radio, merge_flag);
229 if ( color_node->color == GL_COLOR_NONE ) {
231 gl_color_combo_set_to_default (GL_COLOR_COMBO(editor->priv->shadow_color_combo));
235 gl_color_combo_set_color (GL_COLOR_COMBO(editor->priv->shadow_color_combo),
240 if (!color_node->field_flag || !merge_flag) {
241 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
242 (editor->priv->shadow_color_radio), TRUE);
243 gtk_widget_set_sensitive (editor->priv->shadow_color_combo, TRUE);
244 gtk_widget_set_sensitive (editor->priv->shadow_key_combo, FALSE);
247 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
248 (editor->priv->shadow_key_radio), TRUE);
249 gtk_widget_set_sensitive (editor->priv->shadow_color_combo, FALSE);
250 gtk_widget_set_sensitive (editor->priv->shadow_key_combo, TRUE);
252 gl_field_button_set_key (GL_FIELD_BUTTON (editor->priv->shadow_key_combo),
256 editor->priv->stop_signals = FALSE;
258 gl_debug (DEBUG_EDITOR, "END");
263 gl_object_editor_set_shadow_opacity (glObjectEditor *editor,
266 gl_debug (DEBUG_EDITOR, "START");
268 editor->priv->stop_signals = TRUE;
270 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->shadow_opacity_spin),
273 editor->priv->stop_signals = FALSE;
275 gl_debug (DEBUG_EDITOR, "END");
279 /*****************************************************************************/
280 /* Set maximum shadow offset. */
281 /*****************************************************************************/
283 gl_object_editor_set_max_shadow_offset (glObjectEditor *editor,
289 gl_debug (DEBUG_EDITOR, "START");
291 if (editor->priv->shadow_page_vbox)
294 editor->priv->stop_signals = TRUE;
296 /* save a copy in internal units */
297 editor->priv->shadow_x_max = x_max;
298 editor->priv->shadow_y_max = y_max;
300 /* convert internal units to displayed units */
301 gl_debug (DEBUG_EDITOR, "internal x_max,y_max = %g, %g", x_max, y_max);
302 x_max *= editor->priv->units_per_point;
303 y_max *= editor->priv->units_per_point;
304 gl_debug (DEBUG_EDITOR, "display x_max,y_max = %g, %g", x_max, y_max);
306 /* Set widget values */
307 tmp = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->shadow_x_spin));
308 gtk_spin_button_set_range (GTK_SPIN_BUTTON (editor->priv->shadow_x_spin),
310 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->shadow_x_spin), tmp);
311 tmp = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->shadow_y_spin));
312 gtk_spin_button_set_range (GTK_SPIN_BUTTON (editor->priv->shadow_y_spin),
314 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->shadow_y_spin), tmp);
316 editor->priv->stop_signals = FALSE;
320 gl_debug (DEBUG_EDITOR, "END");
324 /*****************************************************************************/
325 /* Query shadow parameters. */
326 /*****************************************************************************/
328 gl_object_editor_get_shadow_state (glObjectEditor *editor)
332 gl_debug (DEBUG_EDITOR, "START");
334 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->shadow_enable_check));
336 gl_debug (DEBUG_EDITOR, "END");
343 gl_object_editor_get_shadow_offset (glObjectEditor *editor,
347 gl_debug (DEBUG_EDITOR, "START");
349 /* Get values from widgets */
350 *x = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->shadow_x_spin));
351 *y = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->shadow_y_spin));
353 /* convert everything back to our internal units (points) */
354 *x /= editor->priv->units_per_point;
355 *y /= editor->priv->units_per_point;
357 /* save a copy in internal units */
358 editor->priv->shadow_x = *x;
359 editor->priv->shadow_y = *y;
361 gl_debug (DEBUG_EDITOR, "END");
366 gl_object_editor_get_shadow_color (glObjectEditor *editor)
370 glColorNode *color_node;
372 gl_debug (DEBUG_EDITOR, "START");
374 color_node = gl_color_node_new_default ();
376 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->shadow_key_radio))) {
377 color_node->field_flag = TRUE;
379 gl_field_button_get_key (GL_FIELD_BUTTON (editor->priv->shadow_key_combo));
381 color_node->field_flag = FALSE;
382 color_node->key = NULL;
383 color = gl_color_combo_get_color (GL_COLOR_COMBO(editor->priv->shadow_color_combo),
387 color_node->color = color;
391 gl_debug (DEBUG_EDITOR, "END");
398 gl_object_editor_get_shadow_opacity (glObjectEditor *editor)
402 gl_debug (DEBUG_EDITOR, "START");
404 alpha = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->shadow_opacity_spin));
406 gl_debug (DEBUG_EDITOR, "END");
408 return alpha / 100.0;
412 /*****************************************************************************/
413 /* PRIVATE. Prefs changed callback. Update units related items. */
414 /*****************************************************************************/
416 shadow_prefs_changed_cb (glObjectEditor *editor)
419 const gchar *units_string;
423 gl_debug (DEBUG_EDITOR, "START");
425 /* Get new configuration information */
426 units = gl_prefs_model_get_units (gl_prefs);
427 units_string = lgl_units_get_name (units);
428 editor->priv->units_per_point = lgl_units_get_units_per_point (units);
429 climb_rate = gl_units_util_get_step_size (units);
430 digits = gl_units_util_get_precision (units);
432 /* Update characteristics of x_spin/y_spin */
433 editor->priv->stop_signals = TRUE;
434 gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->shadow_x_spin),
436 gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->shadow_y_spin),
438 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->shadow_x_spin),
439 climb_rate, 10.0*climb_rate);
440 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->shadow_y_spin),
441 climb_rate, 10.0*climb_rate);
442 editor->priv->stop_signals = FALSE;
444 /* Update units_labels */
445 gtk_label_set_text (GTK_LABEL(editor->priv->shadow_x_units_label),
447 gtk_label_set_text (GTK_LABEL(editor->priv->shadow_y_units_label),
450 /* Update values of x_spin/y_spin */
451 gl_object_editor_set_shadow_offset (editor,
452 editor->priv->shadow_x,
453 editor->priv->shadow_y);
454 gl_object_editor_set_max_shadow_offset (editor,
455 editor->priv->shadow_x_max,
456 editor->priv->shadow_y_max);
458 gl_debug (DEBUG_EDITOR, "END");
462 /*--------------------------------------------------------------------------*/
463 /* PRIVATE. shadow enable check callback. */
464 /*--------------------------------------------------------------------------*/
466 shadow_enable_check_toggled_cb (glObjectEditor *editor)
470 if (editor->priv->stop_signals) return;
472 gl_debug (DEBUG_EDITOR, "START");
474 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->shadow_enable_check));
476 gtk_widget_set_sensitive (editor->priv->shadow_controls_table, state);
478 gl_object_editor_changed_cb (editor);
480 gl_debug (DEBUG_EDITOR, "END");
484 /*--------------------------------------------------------------------------*/
485 /* PRIVATE. shadow color radio callback. */
486 /*--------------------------------------------------------------------------*/
488 shadow_color_radio_toggled_cb (glObjectEditor *editor)
490 if (editor->priv->stop_signals) return;
492 gl_debug (DEBUG_EDITOR, "START");
494 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->shadow_color_radio))) {
495 gtk_widget_set_sensitive (editor->priv->shadow_color_combo, TRUE);
496 gtk_widget_set_sensitive (editor->priv->shadow_key_combo, FALSE);
498 gtk_widget_set_sensitive (editor->priv->shadow_color_combo, FALSE);
499 gtk_widget_set_sensitive (editor->priv->shadow_key_combo, TRUE);
503 gl_object_editor_changed_cb (editor);
505 gl_debug (DEBUG_EDITOR, "END");
511 * Local Variables: -- emacs
513 * c-basic-offset: 8 -- emacs
514 * tab-width: 8 -- emacs
515 * indent-tabs-mode: nil -- emacs