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");
173 g_signal_handlers_block_by_func (G_OBJECT (editor->priv->shadow_enable_check),
174 shadow_enable_check_toggled_cb, editor);
177 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->shadow_enable_check), state);
178 gtk_widget_set_sensitive (editor->priv->shadow_controls_table, state);
181 g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->shadow_enable_check),
182 shadow_enable_check_toggled_cb, editor);
185 gl_debug (DEBUG_EDITOR, "END");
190 gl_object_editor_set_shadow_offset (glObjectEditor *editor,
194 gl_debug (DEBUG_EDITOR, "START");
197 g_signal_handlers_block_by_func (G_OBJECT (editor->priv->shadow_x_spin),
198 gl_object_editor_changed_cb, editor);
199 g_signal_handlers_block_by_func (G_OBJECT (editor->priv->shadow_y_spin),
200 gl_object_editor_changed_cb, editor);
203 /* save a copy in internal units */
204 editor->priv->shadow_x = x;
205 editor->priv->shadow_y = y;
207 /* convert internal units to displayed units */
208 gl_debug (DEBUG_EDITOR, "internal x,y = %g, %g", x, y);
209 x *= editor->priv->units_per_point;
210 y *= editor->priv->units_per_point;
211 gl_debug (DEBUG_EDITOR, "display x,y = %g, %g", x, y);
213 /* Set widget values */
214 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->shadow_x_spin), x);
215 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->shadow_y_spin), y);
218 g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->shadow_x_spin),
219 gl_object_editor_changed_cb, editor);
220 g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->shadow_y_spin),
221 gl_object_editor_changed_cb, editor);
224 gl_debug (DEBUG_EDITOR, "END");
229 gl_object_editor_set_shadow_color (glObjectEditor *editor,
231 glColorNode *color_node)
233 gl_debug (DEBUG_EDITOR, "START");
235 if (color_node == NULL)
241 g_signal_handlers_block_by_func (G_OBJECT (editor->priv->shadow_color_combo),
242 gl_object_editor_changed_cb, editor);
243 g_signal_handlers_block_by_func (G_OBJECT (editor->priv->shadow_color_radio),
244 shadow_color_radio_toggled_cb, editor);
245 g_signal_handlers_block_by_func (G_OBJECT (editor->priv->shadow_key_radio),
246 shadow_color_radio_toggled_cb, editor);
247 g_signal_handlers_block_by_func (G_OBJECT (editor->priv->shadow_key_combo),
248 gl_object_editor_changed_cb, editor);
251 gtk_widget_set_sensitive (editor->priv->shadow_key_radio, merge_flag);
253 if ( color_node->color == GL_COLOR_NONE )
255 gl_color_combo_set_to_default (GL_COLOR_COMBO(editor->priv->shadow_color_combo));
259 gl_color_combo_set_color (GL_COLOR_COMBO(editor->priv->shadow_color_combo),
263 if (!color_node->field_flag || !merge_flag)
265 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->shadow_color_radio), TRUE);
266 gtk_widget_set_sensitive (editor->priv->shadow_color_combo, TRUE);
267 gtk_widget_set_sensitive (editor->priv->shadow_key_combo, FALSE);
272 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->shadow_key_radio), TRUE);
273 gtk_widget_set_sensitive (editor->priv->shadow_color_combo, FALSE);
274 gtk_widget_set_sensitive (editor->priv->shadow_key_combo, TRUE);
276 gl_field_button_set_key (GL_FIELD_BUTTON (editor->priv->shadow_key_combo),
281 g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->shadow_color_combo),
282 gl_object_editor_changed_cb, editor);
283 g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->shadow_color_radio),
284 shadow_color_radio_toggled_cb, editor);
285 g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->shadow_key_radio),
286 shadow_color_radio_toggled_cb, editor);
287 g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->shadow_key_combo),
288 gl_object_editor_changed_cb, editor);
291 gl_debug (DEBUG_EDITOR, "END");
296 gl_object_editor_set_shadow_opacity (glObjectEditor *editor,
299 gl_debug (DEBUG_EDITOR, "START");
302 g_signal_handlers_block_by_func (G_OBJECT (editor->priv->shadow_opacity_spin),
303 gl_object_editor_changed_cb, editor);
306 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->shadow_opacity_spin), alpha * 100.0);
309 g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->shadow_opacity_spin),
310 gl_object_editor_changed_cb, editor);
313 gl_debug (DEBUG_EDITOR, "END");
317 /*****************************************************************************/
318 /* Set maximum shadow offset. */
319 /*****************************************************************************/
321 gl_object_editor_set_max_shadow_offset (glObjectEditor *editor,
327 gl_debug (DEBUG_EDITOR, "START");
330 g_signal_handlers_block_by_func (G_OBJECT (editor->priv->shadow_x_spin),
331 gl_object_editor_changed_cb, editor);
332 g_signal_handlers_block_by_func (G_OBJECT (editor->priv->shadow_y_spin),
333 gl_object_editor_changed_cb, editor);
336 /* save a copy in internal units */
337 editor->priv->shadow_x_max = x_max;
338 editor->priv->shadow_y_max = y_max;
340 /* convert internal units to displayed units */
341 gl_debug (DEBUG_EDITOR, "internal x_max,y_max = %g, %g", x_max, y_max);
342 x_max *= editor->priv->units_per_point;
343 y_max *= editor->priv->units_per_point;
344 gl_debug (DEBUG_EDITOR, "display x_max,y_max = %g, %g", x_max, y_max);
346 /* Set widget values */
347 tmp = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->shadow_x_spin));
348 gtk_spin_button_set_range (GTK_SPIN_BUTTON (editor->priv->shadow_x_spin), -x_max, x_max);
349 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->shadow_x_spin), tmp);
350 tmp = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->shadow_y_spin));
351 gtk_spin_button_set_range (GTK_SPIN_BUTTON (editor->priv->shadow_y_spin), -y_max, y_max);
352 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->shadow_y_spin), tmp);
355 g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->shadow_x_spin),
356 gl_object_editor_changed_cb, editor);
357 g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->shadow_y_spin),
358 gl_object_editor_changed_cb, editor);
361 gl_debug (DEBUG_EDITOR, "END");
365 /*****************************************************************************/
366 /* Query shadow parameters. */
367 /*****************************************************************************/
369 gl_object_editor_get_shadow_state (glObjectEditor *editor)
373 gl_debug (DEBUG_EDITOR, "START");
375 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->shadow_enable_check));
377 gl_debug (DEBUG_EDITOR, "END");
384 gl_object_editor_get_shadow_offset (glObjectEditor *editor,
388 gl_debug (DEBUG_EDITOR, "START");
390 /* Get values from widgets */
391 *x = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->shadow_x_spin));
392 *y = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->shadow_y_spin));
394 /* convert everything back to our internal units (points) */
395 *x /= editor->priv->units_per_point;
396 *y /= editor->priv->units_per_point;
398 /* save a copy in internal units */
399 editor->priv->shadow_x = *x;
400 editor->priv->shadow_y = *y;
402 gl_debug (DEBUG_EDITOR, "END");
407 gl_object_editor_get_shadow_color (glObjectEditor *editor)
411 glColorNode *color_node;
413 gl_debug (DEBUG_EDITOR, "START");
415 color_node = gl_color_node_new_default ();
417 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->shadow_key_radio))) {
418 color_node->field_flag = TRUE;
420 gl_field_button_get_key (GL_FIELD_BUTTON (editor->priv->shadow_key_combo));
422 color_node->field_flag = FALSE;
423 color_node->key = NULL;
424 color = gl_color_combo_get_color (GL_COLOR_COMBO(editor->priv->shadow_color_combo),
428 color_node->color = color;
432 gl_debug (DEBUG_EDITOR, "END");
439 gl_object_editor_get_shadow_opacity (glObjectEditor *editor)
443 gl_debug (DEBUG_EDITOR, "START");
445 alpha = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->shadow_opacity_spin));
447 gl_debug (DEBUG_EDITOR, "END");
449 return alpha / 100.0;
453 /*****************************************************************************/
454 /* PRIVATE. Prefs changed callback. Update units related items. */
455 /*****************************************************************************/
457 shadow_prefs_changed_cb (glObjectEditor *editor)
460 const gchar *units_string;
464 gl_debug (DEBUG_EDITOR, "START");
467 g_signal_handlers_block_by_func (G_OBJECT (editor->priv->shadow_x_spin),
468 gl_object_editor_changed_cb, editor);
469 g_signal_handlers_block_by_func (G_OBJECT (editor->priv->shadow_y_spin),
470 gl_object_editor_changed_cb, editor);
473 /* Get new configuration information */
474 units = gl_prefs_model_get_units (gl_prefs);
475 units_string = lgl_units_get_name (units);
476 editor->priv->units_per_point = lgl_units_get_units_per_point (units);
477 climb_rate = gl_units_util_get_step_size (units);
478 digits = gl_units_util_get_precision (units);
480 /* Update characteristics of x_spin/y_spin */
481 gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->shadow_x_spin),
483 gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->shadow_y_spin),
485 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->shadow_x_spin),
486 climb_rate, 10.0*climb_rate);
487 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->shadow_y_spin),
488 climb_rate, 10.0*climb_rate);
490 /* Update units_labels */
491 gtk_label_set_text (GTK_LABEL(editor->priv->shadow_x_units_label),
493 gtk_label_set_text (GTK_LABEL(editor->priv->shadow_y_units_label),
496 /* Update values of x_spin/y_spin */
497 gl_object_editor_set_shadow_offset (editor,
498 editor->priv->shadow_x,
499 editor->priv->shadow_y);
500 gl_object_editor_set_max_shadow_offset (editor,
501 editor->priv->shadow_x_max,
502 editor->priv->shadow_y_max);
505 g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->shadow_x_spin),
506 gl_object_editor_changed_cb, editor);
507 g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->shadow_y_spin),
508 gl_object_editor_changed_cb, editor);
511 gl_debug (DEBUG_EDITOR, "END");
515 /*--------------------------------------------------------------------------*/
516 /* PRIVATE. shadow enable check callback. */
517 /*--------------------------------------------------------------------------*/
519 shadow_enable_check_toggled_cb (glObjectEditor *editor)
523 gl_debug (DEBUG_EDITOR, "START");
525 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->shadow_enable_check));
527 gtk_widget_set_sensitive (editor->priv->shadow_controls_table, state);
529 gl_object_editor_changed_cb (editor);
531 gl_debug (DEBUG_EDITOR, "END");
535 /*--------------------------------------------------------------------------*/
536 /* PRIVATE. shadow color radio callback. */
537 /*--------------------------------------------------------------------------*/
539 shadow_color_radio_toggled_cb (glObjectEditor *editor)
541 gl_debug (DEBUG_EDITOR, "START");
543 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->shadow_color_radio))) {
544 gtk_widget_set_sensitive (editor->priv->shadow_color_combo, TRUE);
545 gtk_widget_set_sensitive (editor->priv->shadow_key_combo, FALSE);
547 gtk_widget_set_sensitive (editor->priv->shadow_color_combo, FALSE);
548 gtk_widget_set_sensitive (editor->priv->shadow_key_combo, TRUE);
552 gl_object_editor_changed_cb (editor);
554 gl_debug (DEBUG_EDITOR, "END");
560 * Local Variables: -- emacs
562 * c-basic-offset: 8 -- emacs
563 * tab-width: 8 -- emacs
564 * indent-tabs-mode: nil -- emacs