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 "combo-util.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_combo", &editor->priv->shadow_key_combo,
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 gl_combo_util_add_text_model ( GTK_COMBO_BOX(editor->priv->shadow_key_combo));
101 /* Get configuration information */
102 units = gl_prefs_model_get_units (gl_prefs);
103 units_string = lgl_units_get_name (units);
104 editor->priv->units_per_point = lgl_units_get_units_per_point (units);
105 climb_rate = gl_units_util_get_step_size (units);
106 digits = gl_units_util_get_precision (units);
108 /* Modify widgets based on configuration */
109 gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->shadow_x_spin), digits);
110 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->shadow_x_spin),
111 climb_rate, 10.0*climb_rate);
112 gtk_label_set_text (GTK_LABEL(editor->priv->shadow_x_units_label), units_string);
113 gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->shadow_y_spin), digits);
114 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->shadow_y_spin),
115 climb_rate, 10.0*climb_rate);
116 gtk_label_set_text (GTK_LABEL(editor->priv->shadow_y_units_label), units_string);
119 gtk_widget_show_all (editor->priv->shadow_page_vbox);
121 /* Connect signals */
122 g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_enable_check),
124 G_CALLBACK (shadow_enable_check_toggled_cb),
126 g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_x_spin),
128 G_CALLBACK (gl_object_editor_changed_cb),
130 g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_y_spin),
132 G_CALLBACK (gl_object_editor_changed_cb),
134 g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_color_combo),
136 G_CALLBACK (gl_object_editor_changed_cb),
138 g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_key_combo),
140 G_CALLBACK (gl_object_editor_changed_cb),
142 g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_color_radio),
144 G_CALLBACK (shadow_color_radio_toggled_cb),
146 g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_key_radio),
148 G_CALLBACK (shadow_color_radio_toggled_cb),
150 g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_opacity_spin),
152 G_CALLBACK (gl_object_editor_changed_cb),
155 gl_debug (DEBUG_EDITOR, "END");
159 /*****************************************************************************/
160 /* Set shadow parameters. */
161 /*****************************************************************************/
163 gl_object_editor_set_shadow_state (glObjectEditor *editor,
166 gl_debug (DEBUG_EDITOR, "START");
168 editor->priv->stop_signals = TRUE;
170 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->shadow_enable_check),
172 gtk_widget_set_sensitive (editor->priv->shadow_controls_table, state);
174 editor->priv->stop_signals = FALSE;
176 gl_debug (DEBUG_EDITOR, "END");
181 gl_object_editor_set_shadow_offset (glObjectEditor *editor,
185 gl_debug (DEBUG_EDITOR, "START");
187 editor->priv->stop_signals = TRUE;
189 /* save a copy in internal units */
190 editor->priv->shadow_x = x;
191 editor->priv->shadow_y = y;
193 /* convert internal units to displayed units */
194 gl_debug (DEBUG_EDITOR, "internal x,y = %g, %g", x, y);
195 x *= editor->priv->units_per_point;
196 y *= editor->priv->units_per_point;
197 gl_debug (DEBUG_EDITOR, "display x,y = %g, %g", x, y);
199 /* Set widget values */
200 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->shadow_x_spin), x);
201 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->shadow_y_spin), y);
203 editor->priv->stop_signals = FALSE;
205 gl_debug (DEBUG_EDITOR, "END");
210 gl_object_editor_set_shadow_color (glObjectEditor *editor,
212 glColorNode *color_node)
214 gl_debug (DEBUG_EDITOR, "START");
216 editor->priv->stop_signals = TRUE;
218 gtk_widget_set_sensitive (editor->priv->shadow_key_radio, merge_flag);
220 if ( color_node->color == GL_COLOR_NONE ) {
222 gl_color_combo_set_to_default (GL_COLOR_COMBO(editor->priv->shadow_color_combo));
226 gl_color_combo_set_color (GL_COLOR_COMBO(editor->priv->shadow_color_combo),
231 if (!color_node->field_flag || !merge_flag) {
232 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
233 (editor->priv->shadow_color_radio), TRUE);
234 gtk_widget_set_sensitive (editor->priv->shadow_color_combo, TRUE);
235 gtk_widget_set_sensitive (editor->priv->shadow_key_combo, FALSE);
238 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
239 (editor->priv->shadow_key_radio), TRUE);
240 gtk_widget_set_sensitive (editor->priv->shadow_color_combo, FALSE);
241 gtk_widget_set_sensitive (editor->priv->shadow_key_combo, TRUE);
243 gl_combo_util_set_active_text (GTK_COMBO_BOX (editor->priv->shadow_key_combo),
247 editor->priv->stop_signals = FALSE;
249 gl_debug (DEBUG_EDITOR, "END");
254 gl_object_editor_set_shadow_opacity (glObjectEditor *editor,
257 gl_debug (DEBUG_EDITOR, "START");
259 editor->priv->stop_signals = TRUE;
261 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->shadow_opacity_spin),
264 editor->priv->stop_signals = FALSE;
266 gl_debug (DEBUG_EDITOR, "END");
270 /*****************************************************************************/
271 /* Set maximum shadow offset. */
272 /*****************************************************************************/
274 gl_object_editor_set_max_shadow_offset (glObjectEditor *editor,
280 gl_debug (DEBUG_EDITOR, "START");
282 if (editor->priv->shadow_page_vbox)
285 editor->priv->stop_signals = TRUE;
287 /* save a copy in internal units */
288 editor->priv->shadow_x_max = x_max;
289 editor->priv->shadow_y_max = y_max;
291 /* convert internal units to displayed units */
292 gl_debug (DEBUG_EDITOR, "internal x_max,y_max = %g, %g", x_max, y_max);
293 x_max *= editor->priv->units_per_point;
294 y_max *= editor->priv->units_per_point;
295 gl_debug (DEBUG_EDITOR, "display x_max,y_max = %g, %g", x_max, y_max);
297 /* Set widget values */
298 tmp = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->shadow_x_spin));
299 gtk_spin_button_set_range (GTK_SPIN_BUTTON (editor->priv->shadow_x_spin),
301 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->shadow_x_spin), tmp);
302 tmp = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->shadow_y_spin));
303 gtk_spin_button_set_range (GTK_SPIN_BUTTON (editor->priv->shadow_y_spin),
305 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->shadow_y_spin), tmp);
307 editor->priv->stop_signals = FALSE;
311 gl_debug (DEBUG_EDITOR, "END");
315 /*****************************************************************************/
316 /* Query shadow parameters. */
317 /*****************************************************************************/
319 gl_object_editor_get_shadow_state (glObjectEditor *editor)
323 gl_debug (DEBUG_EDITOR, "START");
325 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->shadow_enable_check));
327 gl_debug (DEBUG_EDITOR, "END");
334 gl_object_editor_get_shadow_offset (glObjectEditor *editor,
338 gl_debug (DEBUG_EDITOR, "START");
340 /* Get values from widgets */
341 *x = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->shadow_x_spin));
342 *y = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->shadow_y_spin));
344 /* convert everything back to our internal units (points) */
345 *x /= editor->priv->units_per_point;
346 *y /= editor->priv->units_per_point;
348 /* save a copy in internal units */
349 editor->priv->shadow_x = *x;
350 editor->priv->shadow_y = *y;
352 gl_debug (DEBUG_EDITOR, "END");
357 gl_object_editor_get_shadow_color (glObjectEditor *editor)
361 glColorNode *color_node;
363 gl_debug (DEBUG_EDITOR, "START");
365 color_node = gl_color_node_new_default ();
367 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->shadow_key_radio))) {
368 color_node->field_flag = TRUE;
370 gtk_combo_box_get_active_text (GTK_COMBO_BOX (editor->priv->shadow_key_combo));
372 color_node->field_flag = FALSE;
373 color_node->key = NULL;
374 color = gl_color_combo_get_color (GL_COLOR_COMBO(editor->priv->shadow_color_combo),
378 color_node->color = color;
382 gl_debug (DEBUG_EDITOR, "END");
389 gl_object_editor_get_shadow_opacity (glObjectEditor *editor)
393 gl_debug (DEBUG_EDITOR, "START");
395 alpha = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->shadow_opacity_spin));
397 gl_debug (DEBUG_EDITOR, "END");
399 return alpha / 100.0;
403 /*****************************************************************************/
404 /* PRIVATE. Prefs changed callback. Update units related items. */
405 /*****************************************************************************/
407 shadow_prefs_changed_cb (glObjectEditor *editor)
410 const gchar *units_string;
414 gl_debug (DEBUG_EDITOR, "START");
416 /* Get new configuration information */
417 units = gl_prefs_model_get_units (gl_prefs);
418 units_string = lgl_units_get_name (units);
419 editor->priv->units_per_point = lgl_units_get_units_per_point (units);
420 climb_rate = gl_units_util_get_step_size (units);
421 digits = gl_units_util_get_precision (units);
423 /* Update characteristics of x_spin/y_spin */
424 editor->priv->stop_signals = TRUE;
425 gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->shadow_x_spin),
427 gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->shadow_y_spin),
429 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->shadow_x_spin),
430 climb_rate, 10.0*climb_rate);
431 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->shadow_y_spin),
432 climb_rate, 10.0*climb_rate);
433 editor->priv->stop_signals = FALSE;
435 /* Update units_labels */
436 gtk_label_set_text (GTK_LABEL(editor->priv->shadow_x_units_label),
438 gtk_label_set_text (GTK_LABEL(editor->priv->shadow_y_units_label),
441 /* Update values of x_spin/y_spin */
442 gl_object_editor_set_shadow_offset (editor,
443 editor->priv->shadow_x,
444 editor->priv->shadow_y);
445 gl_object_editor_set_max_shadow_offset (editor,
446 editor->priv->shadow_x_max,
447 editor->priv->shadow_y_max);
449 gl_debug (DEBUG_EDITOR, "END");
453 /*--------------------------------------------------------------------------*/
454 /* PRIVATE. shadow enable check callback. */
455 /*--------------------------------------------------------------------------*/
457 shadow_enable_check_toggled_cb (glObjectEditor *editor)
461 if (editor->priv->stop_signals) return;
463 gl_debug (DEBUG_EDITOR, "START");
465 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->shadow_enable_check));
467 gtk_widget_set_sensitive (editor->priv->shadow_controls_table, state);
469 /* Emit our "changed" signal */
470 g_signal_emit (G_OBJECT (editor), gl_object_editor_signals[CHANGED], 0);
472 gl_debug (DEBUG_EDITOR, "END");
476 /*--------------------------------------------------------------------------*/
477 /* PRIVATE. shadow color radio callback. */
478 /*--------------------------------------------------------------------------*/
480 shadow_color_radio_toggled_cb (glObjectEditor *editor)
482 if (editor->priv->stop_signals) return;
484 gl_debug (DEBUG_EDITOR, "START");
486 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->shadow_color_radio))) {
487 gtk_widget_set_sensitive (editor->priv->shadow_color_combo, TRUE);
488 gtk_widget_set_sensitive (editor->priv->shadow_key_combo, FALSE);
490 gtk_widget_set_sensitive (editor->priv->shadow_color_combo, FALSE);
491 gtk_widget_set_sensitive (editor->priv->shadow_key_combo, TRUE);
495 /* Emit our "changed" signal */
496 g_signal_emit (G_OBJECT (editor), gl_object_editor_signals[CHANGED], 0);
498 gl_debug (DEBUG_EDITOR, "END");
504 * Local Variables: -- emacs
506 * c-basic-offset: 8 -- emacs
507 * tab-width: 8 -- emacs
508 * indent-tabs-mode: nil -- emacs