]> git.sur5r.net Git - glabels/blob - src/object-editor-line-page.c
Theme friendly, glabels specific, action icons.
[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                                   "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         editor->priv->stop_signals = TRUE;
139
140         /* Set widget values */
141         gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->line_width_spin),
142                                    width);
143
144         editor->priv->stop_signals = FALSE;
145
146         gl_debug (DEBUG_EDITOR, "END");
147 }
148
149
150 /*****************************************************************************/
151 /* Query line width.                                                         */
152 /*****************************************************************************/
153 gdouble
154 gl_object_editor_get_line_width (glObjectEditor      *editor)
155 {
156         gdouble w;
157  
158         gl_debug (DEBUG_EDITOR, "START");
159
160         w = gtk_spin_button_get_value (GTK_SPIN_BUTTON(editor->priv->line_width_spin));
161
162         gl_debug (DEBUG_EDITOR, "END");
163
164         return w;
165 }
166
167
168 /*****************************************************************************/
169 /* Set line color.                                                           */
170 /*****************************************************************************/
171 void
172 gl_object_editor_set_line_color (glObjectEditor      *editor,
173                                  gboolean             merge_flag,
174                                  glColorNode         *color_node)
175 {
176         gl_debug (DEBUG_EDITOR, "START");
177
178         if (color_node == NULL)
179         {
180                 return;
181         }
182
183         editor->priv->stop_signals = TRUE;
184
185         gl_debug (DEBUG_EDITOR, "color field %s(%d) / %X", color_node->key, color_node->field_flag, color_node->color);
186         gtk_widget_set_sensitive (editor->priv->line_key_radio, merge_flag);
187
188         if ( color_node->color == GL_COLOR_NONE ) {
189
190                 gl_color_combo_set_to_default (GL_COLOR_COMBO(editor->priv->line_color_combo));
191
192         } else {
193
194                 gl_color_combo_set_color (GL_COLOR_COMBO(editor->priv->line_color_combo),
195                                            color_node->color);
196
197         }       
198         
199         if (!color_node->field_flag || !merge_flag) {
200                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
201                                                   (editor->priv->line_color_radio), TRUE); 
202                 gtk_widget_set_sensitive (editor->priv->line_color_combo, TRUE);
203                 gtk_widget_set_sensitive (editor->priv->line_key_combo, FALSE);
204                 
205         } else {
206                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
207                                                   (editor->priv->line_key_radio), TRUE); 
208                 gtk_widget_set_sensitive (editor->priv->line_color_combo, FALSE);
209                 gtk_widget_set_sensitive (editor->priv->line_key_combo, TRUE);
210                 
211                 gl_field_button_set_key (GL_FIELD_BUTTON (editor->priv->line_key_combo),
212                                          color_node->key);
213         }
214
215         editor->priv->stop_signals = FALSE;
216
217         gl_debug (DEBUG_EDITOR, "END");
218 }
219
220
221 /*****************************************************************************/
222 /* Query line color.                                                         */
223 /*****************************************************************************/
224 glColorNode*
225 gl_object_editor_get_line_color (glObjectEditor      *editor)
226 {
227         guint        color;
228         gboolean     is_default;
229         glColorNode *color_node;
230  
231         gl_debug (DEBUG_EDITOR, "START");
232
233         color_node = gl_color_node_new_default ();
234         
235         if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->line_key_radio))) {
236                 color_node->field_flag = TRUE;
237                 color_node->key = 
238                         gl_field_button_get_key (GL_FIELD_BUTTON (editor->priv->line_key_combo));
239         } else {
240                 color_node->field_flag = FALSE;
241                 color_node->key = NULL;
242                 color = gl_color_combo_get_color (GL_COLOR_COMBO(editor->priv->line_color_combo),
243                                                   &is_default);
244
245                 if (!is_default) {
246                         color_node->color = color;
247                 }
248         }
249         
250         gl_debug (DEBUG_EDITOR, "END");
251
252         return color_node;
253 }
254
255
256 /*--------------------------------------------------------------------------*/
257 /* PRIVATE.  line color radio callback.                                     */
258 /*--------------------------------------------------------------------------*/
259 static void
260 line_radio_toggled_cb (glObjectEditor *editor)
261 {
262         if (editor->priv->stop_signals) return;
263
264         gl_debug (DEBUG_EDITOR, "START");
265         
266         if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->line_color_radio))) {
267                 gtk_widget_set_sensitive (editor->priv->line_color_combo, TRUE);
268                 gtk_widget_set_sensitive (editor->priv->line_key_combo, FALSE);
269         } else {
270                 gtk_widget_set_sensitive (editor->priv->line_color_combo, FALSE);
271                 gtk_widget_set_sensitive (editor->priv->line_key_combo, TRUE);
272                 
273         }
274  
275         gl_object_editor_changed_cb (editor);
276  
277         gl_debug (DEBUG_EDITOR, "END");
278 }
279
280
281
282 /*
283  * Local Variables:       -- emacs
284  * mode: C                -- emacs
285  * c-basic-offset: 8      -- emacs
286  * tab-width: 8           -- emacs
287  * indent-tabs-mode: nil  -- emacs
288  * End:                   -- emacs
289  */