]> git.sur5r.net Git - glabels/blob - src/object-editor-line-page.c
Imported Upstream version 3.0.0
[glabels] / src / object-editor-line-page.c
1 /*
2  *  object-editor-line-page.c
3  *  Copyright (C) 2003-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
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 static void line_radio_toggled_cb               (glObjectEditor        *editor);
59
60
61 /*--------------------------------------------------------------------------*/
62 /* PRIVATE.  Prepare line page.                                             */
63 /*--------------------------------------------------------------------------*/
64 void
65 gl_object_editor_prepare_line_page (glObjectEditor *editor)
66 {
67         gl_debug (DEBUG_EDITOR, "START");
68
69         /* Extract widgets from XML tree. */
70         gl_builder_util_get_widgets (editor->priv->builder,
71                                      "line_page_vbox",   &editor->priv->line_page_vbox,
72                                      "line_width_spin",  &editor->priv->line_width_spin,
73                                      "line_color_hbox",  &editor->priv->line_color_hbox,
74                                      "line_key_hbox",    &editor->priv->line_key_hbox,
75                                      "line_key_radio",   &editor->priv->line_key_radio,
76                                      "line_color_radio", &editor->priv->line_color_radio,
77                                      NULL);
78
79         editor->priv->line_color_combo = gl_color_combo_new (_("No Line"),
80                                                              GL_COLOR_NO_LINE,
81                                                              gl_prefs_model_get_default_line_color (gl_prefs));
82         gtk_box_pack_start (GTK_BOX (editor->priv->line_color_hbox),
83                             editor->priv->line_color_combo,
84                             FALSE, FALSE, 0);
85
86         editor->priv->line_key_combo = gl_field_button_new (NULL);
87         gtk_box_pack_start (GTK_BOX (editor->priv->line_key_hbox),
88                             editor->priv->line_key_combo,
89                             TRUE, TRUE, 0);
90
91         /* Modify widgets based on configuration */
92         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->line_color_radio), TRUE);
93         gtk_widget_set_sensitive (editor->priv->line_color_combo, TRUE);
94     gtk_widget_set_sensitive (editor->priv->line_key_combo, FALSE);     
95         gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->line_width_spin),
96                                    gl_prefs_model_get_default_line_width (gl_prefs));
97         gl_color_combo_set_color (GL_COLOR_COMBO(editor->priv->line_color_combo),
98                                   gl_prefs_model_get_default_line_color (gl_prefs));
99
100         /* Un-hide */
101         gtk_widget_show_all (editor->priv->line_page_vbox);
102
103         /* Connect signals */
104         g_signal_connect_swapped (G_OBJECT (editor->priv->line_width_spin),
105                                   "value-changed",
106                                   G_CALLBACK (gl_object_editor_changed_cb),
107                                   G_OBJECT (editor));
108         g_signal_connect_swapped (G_OBJECT (editor->priv->line_color_combo),
109                                   "color_changed",
110                                   G_CALLBACK (gl_object_editor_changed_cb),
111                                   G_OBJECT (editor));
112         g_signal_connect_swapped (G_OBJECT (editor->priv->line_key_combo),
113                                   "changed",
114                                   G_CALLBACK (gl_object_editor_changed_cb),
115                                   G_OBJECT (editor));
116         g_signal_connect_swapped (G_OBJECT (editor->priv->line_color_radio),
117                                   "toggled",
118                                   G_CALLBACK (line_radio_toggled_cb),
119                                   G_OBJECT (editor));                             
120         g_signal_connect_swapped (G_OBJECT (editor->priv->line_key_radio),
121                                   "toggled",
122                                   G_CALLBACK (line_radio_toggled_cb),
123                                   G_OBJECT (editor));
124
125         gl_debug (DEBUG_EDITOR, "END");
126 }
127
128
129 /*****************************************************************************/
130 /* Set line width.                                                           */
131 /*****************************************************************************/
132 void
133 gl_object_editor_set_line_width (glObjectEditor      *editor,
134                                  gdouble              width)
135 {
136         gl_debug (DEBUG_EDITOR, "START");
137
138
139         g_signal_handlers_block_by_func (G_OBJECT (editor->priv->line_width_spin),
140                                          gl_object_editor_changed_cb, editor);
141
142
143         /* Set widget values */
144         gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->line_width_spin),
145                                    width);
146
147
148         g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->line_width_spin),
149                                            gl_object_editor_changed_cb, editor);
150
151
152         gl_debug (DEBUG_EDITOR, "END");
153 }
154
155
156 /*****************************************************************************/
157 /* Query line width.                                                         */
158 /*****************************************************************************/
159 gdouble
160 gl_object_editor_get_line_width (glObjectEditor      *editor)
161 {
162         gdouble w;
163  
164         gl_debug (DEBUG_EDITOR, "START");
165
166         w = gtk_spin_button_get_value (GTK_SPIN_BUTTON(editor->priv->line_width_spin));
167
168         gl_debug (DEBUG_EDITOR, "END");
169
170         return w;
171 }
172
173
174 /*****************************************************************************/
175 /* Set line color.                                                           */
176 /*****************************************************************************/
177 void
178 gl_object_editor_set_line_color (glObjectEditor      *editor,
179                                  gboolean             merge_flag,
180                                  glColorNode         *color_node)
181 {
182         gl_debug (DEBUG_EDITOR, "START");
183
184         if (color_node == NULL)
185         {
186                 return;
187         }
188
189
190         g_signal_handlers_block_by_func (G_OBJECT (editor->priv->line_color_combo),
191                                          gl_object_editor_changed_cb, editor);
192         g_signal_handlers_block_by_func (G_OBJECT (editor->priv->line_color_radio),
193                                          line_radio_toggled_cb, editor);
194         g_signal_handlers_block_by_func (G_OBJECT (editor->priv->line_key_radio),
195                                          line_radio_toggled_cb, editor);
196         g_signal_handlers_block_by_func (G_OBJECT (editor->priv->line_key_combo),
197                                          gl_object_editor_changed_cb, editor);
198
199
200         gl_debug (DEBUG_EDITOR, "color field %s(%d) / %X", color_node->key, color_node->field_flag, color_node->color);
201         gtk_widget_set_sensitive (editor->priv->line_key_radio, merge_flag);
202
203         if ( color_node->color == GL_COLOR_NONE ) {
204
205                 gl_color_combo_set_to_default (GL_COLOR_COMBO(editor->priv->line_color_combo));
206
207         } else {
208
209                 gl_color_combo_set_color (GL_COLOR_COMBO(editor->priv->line_color_combo),
210                                            color_node->color);
211
212         }       
213         
214         if (!color_node->field_flag || !merge_flag) {
215                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
216                                                   (editor->priv->line_color_radio), TRUE); 
217                 gtk_widget_set_sensitive (editor->priv->line_color_combo, TRUE);
218                 gtk_widget_set_sensitive (editor->priv->line_key_combo, FALSE);
219                 
220         } else {
221                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
222                                                   (editor->priv->line_key_radio), TRUE); 
223                 gtk_widget_set_sensitive (editor->priv->line_color_combo, FALSE);
224                 gtk_widget_set_sensitive (editor->priv->line_key_combo, TRUE);
225                 
226                 gl_field_button_set_key (GL_FIELD_BUTTON (editor->priv->line_key_combo),
227                                          color_node->key);
228         }
229
230
231         g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->line_color_combo),
232                                            gl_object_editor_changed_cb, editor);
233         g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->line_color_radio),
234                                            line_radio_toggled_cb, editor);
235         g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->line_key_radio),
236                                            line_radio_toggled_cb, editor);
237         g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->line_key_combo),
238                                            gl_object_editor_changed_cb, editor);
239
240
241         gl_debug (DEBUG_EDITOR, "END");
242 }
243
244
245 /*****************************************************************************/
246 /* Query line color.                                                         */
247 /*****************************************************************************/
248 glColorNode*
249 gl_object_editor_get_line_color (glObjectEditor      *editor)
250 {
251         guint        color;
252         gboolean     is_default;
253         glColorNode *color_node;
254  
255         gl_debug (DEBUG_EDITOR, "START");
256
257         color_node = gl_color_node_new_default ();
258         
259         if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->line_key_radio))) {
260                 color_node->field_flag = TRUE;
261                 color_node->key = 
262                         gl_field_button_get_key (GL_FIELD_BUTTON (editor->priv->line_key_combo));
263         } else {
264                 color_node->field_flag = FALSE;
265                 color_node->key = NULL;
266                 color = gl_color_combo_get_color (GL_COLOR_COMBO(editor->priv->line_color_combo),
267                                                   &is_default);
268
269                 if (!is_default) {
270                         color_node->color = color;
271                 }
272         }
273         
274         gl_debug (DEBUG_EDITOR, "END");
275
276         return color_node;
277 }
278
279
280 /*--------------------------------------------------------------------------*/
281 /* PRIVATE.  line color radio callback.                                     */
282 /*--------------------------------------------------------------------------*/
283 static void
284 line_radio_toggled_cb (glObjectEditor *editor)
285 {
286         gl_debug (DEBUG_EDITOR, "START");
287         
288         if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->line_color_radio))) {
289                 gtk_widget_set_sensitive (editor->priv->line_color_combo, TRUE);
290                 gtk_widget_set_sensitive (editor->priv->line_key_combo, FALSE);
291         } else {
292                 gtk_widget_set_sensitive (editor->priv->line_color_combo, FALSE);
293                 gtk_widget_set_sensitive (editor->priv->line_key_combo, TRUE);
294                 
295         }
296  
297         gl_object_editor_changed_cb (editor);
298  
299         gl_debug (DEBUG_EDITOR, "END");
300 }
301
302
303
304 /*
305  * Local Variables:       -- emacs
306  * mode: C                -- emacs
307  * c-basic-offset: 8      -- emacs
308  * tab-width: 8           -- emacs
309  * indent-tabs-mode: nil  -- emacs
310  * End:                   -- emacs
311  */