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"
35 #include "object-editor-private.h"
40 /*===========================================*/
42 /*===========================================*/
45 /*===========================================*/
46 /* Private data types */
47 /*===========================================*/
50 /*===========================================*/
52 /*===========================================*/
55 /*===========================================*/
56 /* Local function prototypes */
57 /*===========================================*/
59 static void shadow_enable_check_toggled_cb (glObjectEditor *editor);
60 static void shadow_color_radio_toggled_cb (glObjectEditor *editor);
63 /*--------------------------------------------------------------------------*/
64 /* PRIVATE. Prepare shadow page. */
65 /*--------------------------------------------------------------------------*/
67 gl_object_editor_prepare_shadow_page (glObjectEditor *editor)
69 const gchar *units_string;
73 gl_debug (DEBUG_EDITOR, "START");
75 /* Extract widgets from XML tree. */
76 gl_builder_util_get_widgets (editor->priv->builder,
77 "shadow_page_vbox", &editor->priv->shadow_page_vbox,
78 "shadow_enable_check", &editor->priv->shadow_enable_check,
79 "shadow_controls_table", &editor->priv->shadow_controls_table,
80 "shadow_x_spin", &editor->priv->shadow_x_spin,
81 "shadow_y_spin", &editor->priv->shadow_y_spin,
82 "shadow_x_units_label", &editor->priv->shadow_x_units_label,
83 "shadow_y_units_label", &editor->priv->shadow_y_units_label,
84 "shadow_color_radio", &editor->priv->shadow_color_radio,
85 "shadow_key_radio", &editor->priv->shadow_key_radio,
86 "shadow_color_hbox", &editor->priv->shadow_color_hbox,
87 "shadow_key_combo", &editor->priv->shadow_key_combo,
88 "shadow_opacity_spin", &editor->priv->shadow_opacity_spin,
91 editor->priv->shadow_color_combo = gl_color_combo_new (_("Default"),
92 GL_COLOR_SHADOW_DEFAULT,
93 GL_COLOR_SHADOW_DEFAULT);
94 gtk_container_add (GTK_CONTAINER (editor->priv->shadow_color_hbox),
95 editor->priv->shadow_color_combo);
97 gl_combo_util_add_text_model ( GTK_COMBO_BOX(editor->priv->shadow_key_combo));
99 /* Get configuration information */
100 units_string = gl_prefs_get_units_string ();
101 editor->priv->units_per_point = gl_prefs_get_units_per_point ();
102 climb_rate = gl_prefs_get_units_step_size ();
103 digits = gl_prefs_get_units_precision ();
105 /* Modify widgets based on configuration */
106 gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->shadow_x_spin), digits);
107 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->shadow_x_spin),
108 climb_rate, 10.0*climb_rate);
109 gtk_label_set_text (GTK_LABEL(editor->priv->shadow_x_units_label), units_string);
110 gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->shadow_y_spin), digits);
111 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->shadow_y_spin),
112 climb_rate, 10.0*climb_rate);
113 gtk_label_set_text (GTK_LABEL(editor->priv->shadow_y_units_label), units_string);
116 gtk_widget_show_all (editor->priv->shadow_page_vbox);
118 /* Connect signals */
119 g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_enable_check),
121 G_CALLBACK (shadow_enable_check_toggled_cb),
123 g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_x_spin),
125 G_CALLBACK (gl_object_editor_changed_cb),
127 g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_y_spin),
129 G_CALLBACK (gl_object_editor_changed_cb),
131 g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_color_combo),
133 G_CALLBACK (gl_object_editor_changed_cb),
135 g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_key_combo),
137 G_CALLBACK (gl_object_editor_changed_cb),
139 g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_color_radio),
141 G_CALLBACK (shadow_color_radio_toggled_cb),
143 g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_key_radio),
145 G_CALLBACK (shadow_color_radio_toggled_cb),
147 g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_opacity_spin),
149 G_CALLBACK (gl_object_editor_changed_cb),
152 gl_debug (DEBUG_EDITOR, "END");
156 /*****************************************************************************/
157 /* Set shadow parameters. */
158 /*****************************************************************************/
160 gl_object_editor_set_shadow_state (glObjectEditor *editor,
163 gl_debug (DEBUG_EDITOR, "START");
165 editor->priv->stop_signals = TRUE;
167 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->shadow_enable_check),
169 gtk_widget_set_sensitive (editor->priv->shadow_controls_table, state);
171 editor->priv->stop_signals = FALSE;
173 gl_debug (DEBUG_EDITOR, "END");
178 gl_object_editor_set_shadow_offset (glObjectEditor *editor,
182 gl_debug (DEBUG_EDITOR, "START");
184 editor->priv->stop_signals = TRUE;
186 /* save a copy in internal units */
187 editor->priv->shadow_x = x;
188 editor->priv->shadow_y = y;
190 /* convert internal units to displayed units */
191 gl_debug (DEBUG_EDITOR, "internal x,y = %g, %g", x, y);
192 x *= editor->priv->units_per_point;
193 y *= editor->priv->units_per_point;
194 gl_debug (DEBUG_EDITOR, "display x,y = %g, %g", x, y);
196 /* Set widget values */
197 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->shadow_x_spin), x);
198 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->shadow_y_spin), y);
200 editor->priv->stop_signals = FALSE;
202 gl_debug (DEBUG_EDITOR, "END");
207 gl_object_editor_set_shadow_color (glObjectEditor *editor,
209 glColorNode *color_node)
211 gl_debug (DEBUG_EDITOR, "START");
213 editor->priv->stop_signals = TRUE;
215 gtk_widget_set_sensitive (editor->priv->shadow_key_radio, merge_flag);
217 if ( color_node->color == GL_COLOR_NONE ) {
219 gl_color_combo_set_to_default (GL_COLOR_COMBO(editor->priv->shadow_color_combo));
223 gl_color_combo_set_color (GL_COLOR_COMBO(editor->priv->shadow_color_combo),
228 if (!color_node->field_flag) {
229 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
230 (editor->priv->shadow_color_radio), TRUE);
231 gtk_widget_set_sensitive (editor->priv->shadow_color_combo, TRUE);
232 gtk_widget_set_sensitive (editor->priv->shadow_key_combo, FALSE);
235 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
236 (editor->priv->shadow_key_radio), TRUE);
237 gtk_widget_set_sensitive (editor->priv->shadow_color_combo, FALSE);
238 gtk_widget_set_sensitive (editor->priv->shadow_key_combo, TRUE);
240 gl_combo_util_set_active_text (GTK_COMBO_BOX (editor->priv->shadow_key_combo),
244 editor->priv->stop_signals = FALSE;
246 gl_debug (DEBUG_EDITOR, "END");
251 gl_object_editor_set_shadow_opacity (glObjectEditor *editor,
254 gl_debug (DEBUG_EDITOR, "START");
256 editor->priv->stop_signals = TRUE;
258 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->shadow_opacity_spin),
261 editor->priv->stop_signals = FALSE;
263 gl_debug (DEBUG_EDITOR, "END");
267 /*****************************************************************************/
268 /* Set maximum shadow offset. */
269 /*****************************************************************************/
271 gl_object_editor_set_max_shadow_offset (glObjectEditor *editor,
277 gl_debug (DEBUG_EDITOR, "START");
279 if (editor->priv->shadow_page_vbox)
282 editor->priv->stop_signals = TRUE;
284 /* save a copy in internal units */
285 editor->priv->shadow_x_max = x_max;
286 editor->priv->shadow_y_max = y_max;
288 /* convert internal units to displayed units */
289 gl_debug (DEBUG_EDITOR, "internal x_max,y_max = %g, %g", x_max, y_max);
290 x_max *= editor->priv->units_per_point;
291 y_max *= editor->priv->units_per_point;
292 gl_debug (DEBUG_EDITOR, "display x_max,y_max = %g, %g", x_max, y_max);
294 /* Set widget values */
295 tmp = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->shadow_x_spin));
296 gtk_spin_button_set_range (GTK_SPIN_BUTTON (editor->priv->shadow_x_spin),
298 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->shadow_x_spin), tmp);
299 tmp = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->shadow_y_spin));
300 gtk_spin_button_set_range (GTK_SPIN_BUTTON (editor->priv->shadow_y_spin),
302 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->shadow_y_spin), tmp);
304 editor->priv->stop_signals = FALSE;
308 gl_debug (DEBUG_EDITOR, "END");
312 /*****************************************************************************/
313 /* Query shadow parameters. */
314 /*****************************************************************************/
316 gl_object_editor_get_shadow_state (glObjectEditor *editor)
320 gl_debug (DEBUG_EDITOR, "START");
322 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->shadow_enable_check));
324 gl_debug (DEBUG_EDITOR, "END");
331 gl_object_editor_get_shadow_offset (glObjectEditor *editor,
335 gl_debug (DEBUG_EDITOR, "START");
337 /* Get values from widgets */
338 *x = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->shadow_x_spin));
339 *y = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->shadow_y_spin));
341 /* convert everything back to our internal units (points) */
342 *x /= editor->priv->units_per_point;
343 *y /= editor->priv->units_per_point;
345 /* save a copy in internal units */
346 editor->priv->shadow_x = *x;
347 editor->priv->shadow_y = *y;
349 gl_debug (DEBUG_EDITOR, "END");
354 gl_object_editor_get_shadow_color (glObjectEditor *editor)
358 glColorNode *color_node;
360 gl_debug (DEBUG_EDITOR, "START");
362 color_node = gl_color_node_new_default ();
364 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->shadow_key_radio))) {
365 color_node->field_flag = TRUE;
367 gtk_combo_box_get_active_text (GTK_COMBO_BOX (editor->priv->shadow_key_combo));
369 color_node->field_flag = FALSE;
370 color_node->key = NULL;
371 color = gl_color_combo_get_color (GL_COLOR_COMBO(editor->priv->shadow_color_combo),
375 color_node->color = color;
379 gl_debug (DEBUG_EDITOR, "END");
386 gl_object_editor_get_shadow_opacity (glObjectEditor *editor)
390 gl_debug (DEBUG_EDITOR, "START");
392 alpha = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->shadow_opacity_spin));
394 gl_debug (DEBUG_EDITOR, "END");
396 return alpha / 100.0;
400 /*****************************************************************************/
401 /* PRIVATE. Prefs changed callback. Update units related items. */
402 /*****************************************************************************/
404 shadow_prefs_changed_cb (glObjectEditor *editor)
406 const gchar *units_string;
410 gl_debug (DEBUG_EDITOR, "START");
412 /* Get new configuration information */
413 units_string = gl_prefs_get_units_string ();
414 editor->priv->units_per_point = gl_prefs_get_units_per_point ();
415 climb_rate = gl_prefs_get_units_step_size ();
416 digits = gl_prefs_get_units_precision ();
418 /* Update characteristics of x_spin/y_spin */
419 editor->priv->stop_signals = TRUE;
420 gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->shadow_x_spin),
422 gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->shadow_y_spin),
424 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->shadow_x_spin),
425 climb_rate, 10.0*climb_rate);
426 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(editor->priv->shadow_y_spin),
427 climb_rate, 10.0*climb_rate);
428 editor->priv->stop_signals = FALSE;
430 /* Update units_labels */
431 gtk_label_set_text (GTK_LABEL(editor->priv->shadow_x_units_label),
433 gtk_label_set_text (GTK_LABEL(editor->priv->shadow_y_units_label),
436 /* Update values of x_spin/y_spin */
437 gl_object_editor_set_shadow_offset (editor,
438 editor->priv->shadow_x,
439 editor->priv->shadow_y);
440 gl_object_editor_set_max_shadow_offset (editor,
441 editor->priv->shadow_x_max,
442 editor->priv->shadow_y_max);
444 gl_debug (DEBUG_EDITOR, "END");
448 /*--------------------------------------------------------------------------*/
449 /* PRIVATE. shadow enable check callback. */
450 /*--------------------------------------------------------------------------*/
452 shadow_enable_check_toggled_cb (glObjectEditor *editor)
456 if (editor->priv->stop_signals) return;
458 gl_debug (DEBUG_EDITOR, "START");
460 state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->shadow_enable_check));
462 gtk_widget_set_sensitive (editor->priv->shadow_controls_table, state);
464 /* Emit our "changed" signal */
465 g_signal_emit (G_OBJECT (editor), gl_object_editor_signals[CHANGED], 0);
467 gl_debug (DEBUG_EDITOR, "END");
471 /*--------------------------------------------------------------------------*/
472 /* PRIVATE. shadow color radio callback. */
473 /*--------------------------------------------------------------------------*/
475 shadow_color_radio_toggled_cb (glObjectEditor *editor)
477 if (editor->priv->stop_signals) return;
479 gl_debug (DEBUG_EDITOR, "START");
481 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->shadow_color_radio))) {
482 gtk_widget_set_sensitive (editor->priv->shadow_color_combo, TRUE);
483 gtk_widget_set_sensitive (editor->priv->shadow_key_combo, FALSE);
485 gtk_widget_set_sensitive (editor->priv->shadow_color_combo, FALSE);
486 gtk_widget_set_sensitive (editor->priv->shadow_key_combo, TRUE);
490 /* Emit our "changed" signal */
491 g_signal_emit (G_OBJECT (editor), gl_object_editor_signals[CHANGED], 0);
493 gl_debug (DEBUG_EDITOR, "END");
499 * Local Variables: -- emacs
501 * c-basic-offset: 8 -- emacs
502 * tab-width: 8 -- emacs
503 * indent-tabs-mode: nil -- emacs