]> git.sur5r.net Git - glabels/blob - src/object-editor-shadow-page.c
Update po files to allow me to push this branch.
[glabels] / src / object-editor-shadow-page.c
1 /*
2  *  object-editor-shadow-page.c
3  *  Copyright (C) 2006-2009  Jim Evins <evins@snaught.com>.
4  *
5  *  This file is part of gLabels.
6  *
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.
11  *
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.
16  *
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/>.
19  */
20
21 #include <config.h>
22
23 #include "object-editor.h"
24
25 #include <glib/gi18n.h>
26 #include <gtk/gtk.h>
27 #include <math.h>
28
29 #include "prefs.h"
30 #include "color-combo.h"
31 #include "color.h"
32 #include "field-button.h"
33 #include "builder-util.h"
34 #include "units-util.h"
35
36 #include "object-editor-private.h"
37
38 #include "debug.h"
39
40
41 /*===========================================*/
42 /* Private macros                            */
43 /*===========================================*/
44
45
46 /*===========================================*/
47 /* Private data types                        */
48 /*===========================================*/
49
50
51 /*===========================================*/
52 /* Private globals                           */
53 /*===========================================*/
54
55
56 /*===========================================*/
57 /* Local function prototypes                 */
58 /*===========================================*/
59
60 static void shadow_enable_check_toggled_cb (glObjectEditor        *editor);
61 static void shadow_color_radio_toggled_cb  (glObjectEditor        *editor);
62
63
64 /*--------------------------------------------------------------------------*/
65 /* PRIVATE.  Prepare shadow page.                                         */
66 /*--------------------------------------------------------------------------*/
67 void
68 gl_object_editor_prepare_shadow_page (glObjectEditor *editor)
69 {
70         lglUnits      units;
71         const gchar  *units_string;
72         gdouble       climb_rate;
73         gint          digits;
74
75         gl_debug (DEBUG_EDITOR, "START");
76
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,
91                                      NULL);
92
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);
98
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,
102                             TRUE, TRUE, 0);
103
104
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);
111
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);
121
122         /* Un-hide */
123         gtk_widget_show_all (editor->priv->shadow_page_vbox);
124
125         /* Connect signals */
126         g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_enable_check),
127                                   "toggled",
128                                   G_CALLBACK (shadow_enable_check_toggled_cb),
129                                   G_OBJECT (editor));                             
130         g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_x_spin),
131                                   "changed",
132                                   G_CALLBACK (gl_object_editor_changed_cb),
133                                   G_OBJECT (editor));
134         g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_y_spin),
135                                   "changed",
136                                   G_CALLBACK (gl_object_editor_changed_cb),
137                                   G_OBJECT (editor));
138         g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_color_combo),
139                                   "color_changed",
140                                   G_CALLBACK (gl_object_editor_changed_cb),
141                                   G_OBJECT (editor));
142         g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_key_combo),
143                                   "changed",
144                                   G_CALLBACK (gl_object_editor_changed_cb),
145                                   G_OBJECT (editor));
146         g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_color_radio),
147                                   "toggled",
148                                   G_CALLBACK (shadow_color_radio_toggled_cb),
149                                   G_OBJECT (editor));                             
150         g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_key_radio),
151                                   "toggled",
152                                   G_CALLBACK (shadow_color_radio_toggled_cb),
153                                   G_OBJECT (editor));                             
154         g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_opacity_spin),
155                                   "changed",
156                                   G_CALLBACK (gl_object_editor_changed_cb),
157                                   G_OBJECT (editor));
158
159         gl_debug (DEBUG_EDITOR, "END");
160 }
161
162
163 /*****************************************************************************/
164 /* Set shadow parameters.                                                    */
165 /*****************************************************************************/
166 void
167 gl_object_editor_set_shadow_state (glObjectEditor      *editor,
168                                    gboolean             state)
169 {
170         gl_debug (DEBUG_EDITOR, "START");
171
172         editor->priv->stop_signals = TRUE;
173
174         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->shadow_enable_check),
175                                       state);
176         gtk_widget_set_sensitive (editor->priv->shadow_controls_table, state);
177
178         editor->priv->stop_signals = FALSE;
179
180         gl_debug (DEBUG_EDITOR, "END");
181 }
182
183
184 void
185 gl_object_editor_set_shadow_offset (glObjectEditor      *editor,
186                                     gdouble              x,
187                                     gdouble              y)
188 {
189         gl_debug (DEBUG_EDITOR, "START");
190
191         editor->priv->stop_signals = TRUE;
192
193         /* save a copy in internal units */
194         editor->priv->shadow_x = x;
195         editor->priv->shadow_y = y;
196
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);
202
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);
206
207         editor->priv->stop_signals = FALSE;
208
209         gl_debug (DEBUG_EDITOR, "END");
210 }
211
212
213 void
214 gl_object_editor_set_shadow_color (glObjectEditor      *editor,
215                                    gboolean             merge_flag,
216                                    glColorNode         *color_node)
217 {
218         gl_debug (DEBUG_EDITOR, "START");
219
220         if (color_node == NULL)
221         {
222                 return;
223         }
224
225         editor->priv->stop_signals = TRUE;
226
227         gtk_widget_set_sensitive (editor->priv->shadow_key_radio, merge_flag);
228
229         if ( color_node->color == GL_COLOR_NONE ) {
230
231                 gl_color_combo_set_to_default (GL_COLOR_COMBO(editor->priv->shadow_color_combo));
232
233         } else {
234
235                 gl_color_combo_set_color (GL_COLOR_COMBO(editor->priv->shadow_color_combo),
236                                           color_node->color);
237
238         }
239         
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);
245                 
246         } else {
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);
251                 
252                 gl_field_button_set_key (GL_FIELD_BUTTON (editor->priv->shadow_key_combo),
253                                          color_node->key);
254         }
255         
256         editor->priv->stop_signals = FALSE;
257
258         gl_debug (DEBUG_EDITOR, "END");
259 }
260
261
262 void
263 gl_object_editor_set_shadow_opacity (glObjectEditor      *editor,
264                                      gdouble              alpha)
265 {
266         gl_debug (DEBUG_EDITOR, "START");
267
268         editor->priv->stop_signals = TRUE;
269
270         gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->shadow_opacity_spin),
271                                    alpha * 100.0);
272
273         editor->priv->stop_signals = FALSE;
274
275         gl_debug (DEBUG_EDITOR, "END");
276 }
277
278
279 /*****************************************************************************/
280 /* Set maximum shadow offset.                                                */
281 /*****************************************************************************/
282 void
283 gl_object_editor_set_max_shadow_offset (glObjectEditor      *editor,
284                                         gdouble              x_max,
285                                         gdouble              y_max)
286 {
287         gdouble tmp;
288
289         gl_debug (DEBUG_EDITOR, "START");
290
291         if (editor->priv->shadow_page_vbox)
292         {
293
294                 editor->priv->stop_signals = TRUE;
295
296                 /* save a copy in internal units */
297                 editor->priv->shadow_x_max = x_max;
298                 editor->priv->shadow_y_max = y_max;
299
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);
305
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),
309                                            -x_max, x_max);
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),
313                                            -y_max, y_max);
314                 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->shadow_y_spin), tmp);
315
316                 editor->priv->stop_signals = FALSE;
317
318         }
319
320         gl_debug (DEBUG_EDITOR, "END");
321 }
322
323
324 /*****************************************************************************/
325 /* Query shadow parameters.                                                  */
326 /*****************************************************************************/
327 gboolean
328 gl_object_editor_get_shadow_state (glObjectEditor      *editor)
329 {
330         gboolean state;
331
332         gl_debug (DEBUG_EDITOR, "START");
333
334         state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->shadow_enable_check));
335
336         gl_debug (DEBUG_EDITOR, "END");
337
338         return state;
339 }
340
341
342 void
343 gl_object_editor_get_shadow_offset (glObjectEditor      *editor,
344                                     gdouble             *x,
345                                     gdouble             *y)
346 {
347         gl_debug (DEBUG_EDITOR, "START");
348
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));
352
353         /* convert everything back to our internal units (points) */
354         *x /= editor->priv->units_per_point;
355         *y /= editor->priv->units_per_point;
356
357         /* save a copy in internal units */
358         editor->priv->shadow_x = *x;
359         editor->priv->shadow_y = *y;
360
361         gl_debug (DEBUG_EDITOR, "END");
362 }
363
364
365 glColorNode*
366 gl_object_editor_get_shadow_color (glObjectEditor      *editor)
367 {
368         guint        color;
369         gboolean     is_default;
370         glColorNode *color_node;
371  
372         gl_debug (DEBUG_EDITOR, "START");
373
374         color_node = gl_color_node_new_default ();
375         
376         if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->shadow_key_radio))) {
377                 color_node->field_flag = TRUE;
378                 color_node->key = 
379                         gl_field_button_get_key (GL_FIELD_BUTTON (editor->priv->shadow_key_combo));
380         } else {
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),
384                                                   &is_default);
385
386                 if (!is_default) {
387                         color_node->color = color;
388                 }
389         }
390
391         gl_debug (DEBUG_EDITOR, "END");
392
393         return color_node;
394 }
395
396
397 gdouble
398 gl_object_editor_get_shadow_opacity (glObjectEditor      *editor)
399 {
400         gdouble alpha;
401
402         gl_debug (DEBUG_EDITOR, "START");
403
404         alpha = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->shadow_opacity_spin));
405
406         gl_debug (DEBUG_EDITOR, "END");
407
408         return alpha / 100.0;
409 }
410
411
412 /*****************************************************************************/
413 /* PRIVATE. Prefs changed callback.  Update units related items.            */
414 /*****************************************************************************/
415 void
416 shadow_prefs_changed_cb (glObjectEditor *editor)
417 {
418         lglUnits      units;
419         const gchar  *units_string;
420         gdouble       climb_rate;
421         gint          digits;
422
423         gl_debug (DEBUG_EDITOR, "START");
424
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);
431
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),
435                                     digits);
436         gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->shadow_y_spin),
437                                     digits);
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;
443
444         /* Update units_labels */
445         gtk_label_set_text (GTK_LABEL(editor->priv->shadow_x_units_label),
446                             units_string);
447         gtk_label_set_text (GTK_LABEL(editor->priv->shadow_y_units_label),
448                             units_string);
449
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);
457
458         gl_debug (DEBUG_EDITOR, "END");
459 }
460
461
462 /*--------------------------------------------------------------------------*/
463 /* PRIVATE.  shadow enable check callback.                                  */
464 /*--------------------------------------------------------------------------*/
465 static void
466 shadow_enable_check_toggled_cb (glObjectEditor *editor)
467 {
468         gboolean state;
469
470         if (editor->priv->stop_signals) return;
471
472         gl_debug (DEBUG_EDITOR, "START");
473
474         state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->shadow_enable_check));
475
476         gtk_widget_set_sensitive (editor->priv->shadow_controls_table, state);
477
478         gl_object_editor_changed_cb (editor);
479
480         gl_debug (DEBUG_EDITOR, "END");
481 }
482
483
484 /*--------------------------------------------------------------------------*/
485 /* PRIVATE.  shadow color radio callback.                                   */
486 /*--------------------------------------------------------------------------*/
487 static void
488 shadow_color_radio_toggled_cb (glObjectEditor *editor)
489 {
490         if (editor->priv->stop_signals) return;
491
492         gl_debug (DEBUG_EDITOR, "START");
493         
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);
497         } else {
498                 gtk_widget_set_sensitive (editor->priv->shadow_color_combo, FALSE);
499                 gtk_widget_set_sensitive (editor->priv->shadow_key_combo, TRUE);
500                 
501         }
502  
503         gl_object_editor_changed_cb (editor);
504  
505         gl_debug (DEBUG_EDITOR, "END");
506 }
507
508
509
510 /*
511  * Local Variables:       -- emacs
512  * mode: C                -- emacs
513  * c-basic-offset: 8      -- emacs
514  * tab-width: 8           -- emacs
515  * indent-tabs-mode: nil  -- emacs
516  * End:                   -- emacs
517  */