]> git.sur5r.net Git - glabels/blob - src/object-editor-shadow-page.c
Removed non-existent filenames from po/POTFILES.in
[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 "combo-util.h"
33 #include "builder-util.h"
34
35 #include "object-editor-private.h"
36
37 #include "debug.h"
38
39
40 /*===========================================*/
41 /* Private macros                            */
42 /*===========================================*/
43
44
45 /*===========================================*/
46 /* Private data types                        */
47 /*===========================================*/
48
49
50 /*===========================================*/
51 /* Private globals                           */
52 /*===========================================*/
53
54
55 /*===========================================*/
56 /* Local function prototypes                 */
57 /*===========================================*/
58
59 static void shadow_enable_check_toggled_cb (glObjectEditor        *editor);
60 static void shadow_color_radio_toggled_cb  (glObjectEditor        *editor);
61
62
63 /*--------------------------------------------------------------------------*/
64 /* PRIVATE.  Prepare shadow page.                                         */
65 /*--------------------------------------------------------------------------*/
66 void
67 gl_object_editor_prepare_shadow_page (glObjectEditor *editor)
68 {
69         const gchar  *units_string;
70         gdouble       climb_rate;
71         gint          digits;
72
73         gl_debug (DEBUG_EDITOR, "START");
74
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,
89                                      NULL);
90
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);
96
97         gl_combo_util_add_text_model ( GTK_COMBO_BOX(editor->priv->shadow_key_combo));
98
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 ();
104
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);
114
115         /* Un-hide */
116         gtk_widget_show_all (editor->priv->shadow_page_vbox);
117
118         /* Connect signals */
119         g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_enable_check),
120                                   "toggled",
121                                   G_CALLBACK (shadow_enable_check_toggled_cb),
122                                   G_OBJECT (editor));                             
123         g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_x_spin),
124                                   "changed",
125                                   G_CALLBACK (gl_object_editor_changed_cb),
126                                   G_OBJECT (editor));
127         g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_y_spin),
128                                   "changed",
129                                   G_CALLBACK (gl_object_editor_changed_cb),
130                                   G_OBJECT (editor));
131         g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_color_combo),
132                                   "color_changed",
133                                   G_CALLBACK (gl_object_editor_changed_cb),
134                                   G_OBJECT (editor));
135         g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_key_combo),
136                                   "changed",
137                                   G_CALLBACK (gl_object_editor_changed_cb),
138                                   G_OBJECT (editor));
139         g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_color_radio),
140                                   "toggled",
141                                   G_CALLBACK (shadow_color_radio_toggled_cb),
142                                   G_OBJECT (editor));                             
143         g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_key_radio),
144                                   "toggled",
145                                   G_CALLBACK (shadow_color_radio_toggled_cb),
146                                   G_OBJECT (editor));                             
147         g_signal_connect_swapped (G_OBJECT (editor->priv->shadow_opacity_spin),
148                                   "changed",
149                                   G_CALLBACK (gl_object_editor_changed_cb),
150                                   G_OBJECT (editor));
151
152         gl_debug (DEBUG_EDITOR, "END");
153 }
154
155
156 /*****************************************************************************/
157 /* Set shadow parameters.                                                    */
158 /*****************************************************************************/
159 void
160 gl_object_editor_set_shadow_state (glObjectEditor      *editor,
161                                    gboolean             state)
162 {
163         gl_debug (DEBUG_EDITOR, "START");
164
165         editor->priv->stop_signals = TRUE;
166
167         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->shadow_enable_check),
168                                       state);
169         gtk_widget_set_sensitive (editor->priv->shadow_controls_table, state);
170
171         editor->priv->stop_signals = FALSE;
172
173         gl_debug (DEBUG_EDITOR, "END");
174 }
175
176
177 void
178 gl_object_editor_set_shadow_offset (glObjectEditor      *editor,
179                                     gdouble              x,
180                                     gdouble              y)
181 {
182         gl_debug (DEBUG_EDITOR, "START");
183
184         editor->priv->stop_signals = TRUE;
185
186         /* save a copy in internal units */
187         editor->priv->shadow_x = x;
188         editor->priv->shadow_y = y;
189
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);
195
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);
199
200         editor->priv->stop_signals = FALSE;
201
202         gl_debug (DEBUG_EDITOR, "END");
203 }
204
205
206 void
207 gl_object_editor_set_shadow_color (glObjectEditor      *editor,
208                                    gboolean             merge_flag,
209                                    glColorNode         *color_node)
210 {
211         gl_debug (DEBUG_EDITOR, "START");
212
213         editor->priv->stop_signals = TRUE;
214
215         gtk_widget_set_sensitive (editor->priv->shadow_key_radio, merge_flag);
216
217         if ( color_node->color == GL_COLOR_NONE ) {
218
219                 gl_color_combo_set_to_default (GL_COLOR_COMBO(editor->priv->shadow_color_combo));
220
221         } else {
222
223                 gl_color_combo_set_color (GL_COLOR_COMBO(editor->priv->shadow_color_combo),
224                                           color_node->color);
225
226         }
227         
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);
233                 
234         } else {
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);
239                 
240                 gl_combo_util_set_active_text (GTK_COMBO_BOX (editor->priv->shadow_key_combo),
241                                                color_node->key);
242         }
243         
244         editor->priv->stop_signals = FALSE;
245
246         gl_debug (DEBUG_EDITOR, "END");
247 }
248
249
250 void
251 gl_object_editor_set_shadow_opacity (glObjectEditor      *editor,
252                                      gdouble              alpha)
253 {
254         gl_debug (DEBUG_EDITOR, "START");
255
256         editor->priv->stop_signals = TRUE;
257
258         gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->shadow_opacity_spin),
259                                    alpha * 100.0);
260
261         editor->priv->stop_signals = FALSE;
262
263         gl_debug (DEBUG_EDITOR, "END");
264 }
265
266
267 /*****************************************************************************/
268 /* Set maximum shadow offset.                                                */
269 /*****************************************************************************/
270 void
271 gl_object_editor_set_max_shadow_offset (glObjectEditor      *editor,
272                                         gdouble              x_max,
273                                         gdouble              y_max)
274 {
275         gdouble tmp;
276
277         gl_debug (DEBUG_EDITOR, "START");
278
279         if (editor->priv->shadow_page_vbox)
280         {
281
282                 editor->priv->stop_signals = TRUE;
283
284                 /* save a copy in internal units */
285                 editor->priv->shadow_x_max = x_max;
286                 editor->priv->shadow_y_max = y_max;
287
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);
293
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),
297                                            -x_max, x_max);
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),
301                                            -y_max, y_max);
302                 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->shadow_y_spin), tmp);
303
304                 editor->priv->stop_signals = FALSE;
305
306         }
307
308         gl_debug (DEBUG_EDITOR, "END");
309 }
310
311
312 /*****************************************************************************/
313 /* Query shadow parameters.                                                  */
314 /*****************************************************************************/
315 gboolean
316 gl_object_editor_get_shadow_state (glObjectEditor      *editor)
317 {
318         gboolean state;
319
320         gl_debug (DEBUG_EDITOR, "START");
321
322         state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->shadow_enable_check));
323
324         gl_debug (DEBUG_EDITOR, "END");
325
326         return state;
327 }
328
329
330 void
331 gl_object_editor_get_shadow_offset (glObjectEditor      *editor,
332                                     gdouble             *x,
333                                     gdouble             *y)
334 {
335         gl_debug (DEBUG_EDITOR, "START");
336
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));
340
341         /* convert everything back to our internal units (points) */
342         *x /= editor->priv->units_per_point;
343         *y /= editor->priv->units_per_point;
344
345         /* save a copy in internal units */
346         editor->priv->shadow_x = *x;
347         editor->priv->shadow_y = *y;
348
349         gl_debug (DEBUG_EDITOR, "END");
350 }
351
352
353 glColorNode*
354 gl_object_editor_get_shadow_color (glObjectEditor      *editor)
355 {
356         guint        color;
357         gboolean     is_default;
358         glColorNode *color_node;
359  
360         gl_debug (DEBUG_EDITOR, "START");
361
362         color_node = gl_color_node_new_default ();
363         
364         if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->shadow_key_radio))) {
365                 color_node->field_flag = TRUE;
366                 color_node->key = 
367                         gtk_combo_box_get_active_text (GTK_COMBO_BOX (editor->priv->shadow_key_combo));
368         } else {
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),
372                                                   &is_default);
373
374                 if (!is_default) {
375                         color_node->color = color;
376                 }
377         }
378
379         gl_debug (DEBUG_EDITOR, "END");
380
381         return color_node;
382 }
383
384
385 gdouble
386 gl_object_editor_get_shadow_opacity (glObjectEditor      *editor)
387 {
388         gdouble alpha;
389
390         gl_debug (DEBUG_EDITOR, "START");
391
392         alpha = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->shadow_opacity_spin));
393
394         gl_debug (DEBUG_EDITOR, "END");
395
396         return alpha / 100.0;
397 }
398
399
400 /*****************************************************************************/
401 /* PRIVATE. Prefs changed callback.  Update units related items.            */
402 /*****************************************************************************/
403 void
404 shadow_prefs_changed_cb (glObjectEditor *editor)
405 {
406         const gchar  *units_string;
407         gdouble       climb_rate;
408         gint          digits;
409
410         gl_debug (DEBUG_EDITOR, "START");
411
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 ();
417
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),
421                                     digits);
422         gtk_spin_button_set_digits (GTK_SPIN_BUTTON(editor->priv->shadow_y_spin),
423                                     digits);
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;
429
430         /* Update units_labels */
431         gtk_label_set_text (GTK_LABEL(editor->priv->shadow_x_units_label),
432                             units_string);
433         gtk_label_set_text (GTK_LABEL(editor->priv->shadow_y_units_label),
434                             units_string);
435
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);
443
444         gl_debug (DEBUG_EDITOR, "END");
445 }
446
447
448 /*--------------------------------------------------------------------------*/
449 /* PRIVATE.  shadow enable check callback.                                  */
450 /*--------------------------------------------------------------------------*/
451 static void
452 shadow_enable_check_toggled_cb (glObjectEditor *editor)
453 {
454         gboolean state;
455
456         if (editor->priv->stop_signals) return;
457
458         gl_debug (DEBUG_EDITOR, "START");
459
460         state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->shadow_enable_check));
461
462         gtk_widget_set_sensitive (editor->priv->shadow_controls_table, state);
463
464         /* Emit our "changed" signal */
465         g_signal_emit (G_OBJECT (editor), gl_object_editor_signals[CHANGED], 0);
466
467         gl_debug (DEBUG_EDITOR, "END");
468 }
469
470
471 /*--------------------------------------------------------------------------*/
472 /* PRIVATE.  shadow color radio callback.                                   */
473 /*--------------------------------------------------------------------------*/
474 static void
475 shadow_color_radio_toggled_cb (glObjectEditor *editor)
476 {
477         if (editor->priv->stop_signals) return;
478
479         gl_debug (DEBUG_EDITOR, "START");
480         
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);
484         } else {
485                 gtk_widget_set_sensitive (editor->priv->shadow_color_combo, FALSE);
486                 gtk_widget_set_sensitive (editor->priv->shadow_key_combo, TRUE);
487                 
488         }
489  
490         /* Emit our "changed" signal */
491         g_signal_emit (G_OBJECT (editor), gl_object_editor_signals[CHANGED], 0);
492  
493         gl_debug (DEBUG_EDITOR, "END");
494 }
495
496
497
498 /*
499  * Local Variables:       -- emacs
500  * mode: C                -- emacs
501  * c-basic-offset: 8      -- emacs
502  * tab-width: 8           -- emacs
503  * indent-tabs-mode: nil  -- emacs
504  * End:                   -- emacs
505  */