Code

patch 1750206 by Bruno Dilly - bdilly
[inkscape.git] / src / ui / widget / preferences-widget.cpp
1 /**
2  * \brief Inkscape Preferences dialog
3  *
4  * Authors:
5  *   Marco Scholten
6  *
7  * Copyright (C) 2004, 2006 Authors
8  *
9  * Released under GNU GPL.  Read the file 'COPYING' for more information.
10  */ 
12 #ifdef HAVE_CONFIG_H
13 # include <config.h>
14 #endif
16 #include <gtkmm/frame.h>
17 #include <gtkmm/alignment.h>
18 #include <gtkmm/box.h>
20 #include "prefs-utils.h"
21 #include "ui/widget/preferences-widget.h"
22 #include "verbs.h"
23 #include "selcue.h"
24 #include <iostream>
25 #include "enums.h"
26 #include "inkscape.h"
27 #include "desktop-handles.h"
28 #include "message-stack.h"
29 #include "style.h"
30 #include "selection.h"
31 #include "selection-chemistry.h"
32 #include "xml/repr.h"
34 using namespace Inkscape::UI::Widget;
36 namespace Inkscape {
37 namespace UI {
38 namespace Widget {
40 DialogPage::DialogPage()
41 {
42     this->set_border_width(12);
43     this->set_col_spacings(12);
44     this->set_row_spacings(6);
45 }
47 void DialogPage::add_line(bool indent, const Glib::ustring label, Gtk::Widget& widget, const Glib::ustring suffix, const Glib::ustring& tip, bool expand_widget)
48 {
49     int start_col; 
50     int row = this->property_n_rows();
51     Gtk::Widget* w;
52     if (expand_widget)
53     {   
54         w = &widget;
55     }
56     else
57     {
58         Gtk::HBox* hb = Gtk::manage(new Gtk::HBox());
59         hb->set_spacing(12);
60         hb->pack_start(widget,false,false);
61         w = (Gtk::Widget*) hb;
62     }
63     if (label != "")
64     {
65         Gtk::Label* label_widget;
66         label_widget = Gtk::manage(new Gtk::Label(label , Gtk::ALIGN_LEFT , Gtk::ALIGN_CENTER, true));
67         label_widget->set_mnemonic_widget(widget);
68         if (indent)
69         {
70             Gtk::Alignment* alignment = Gtk::manage(new Gtk::Alignment());
71             alignment->set_padding(0, 0, 12, 0);
72             alignment->add(*label_widget);
73             this->attach(*alignment , 0, 1, row, row + 1, Gtk::FILL, Gtk::AttachOptions(), 0, 0);
74         }
75         else
76             this->attach(*label_widget , 0, 1, row, row + 1, Gtk::FILL, Gtk::AttachOptions(), 0, 0);
77         start_col = 1;
78     }
79     else
80         start_col = 0;
82     if (start_col == 0 && indent) //indent this widget
83     {
84         Gtk::Alignment* alignment = Gtk::manage(new Gtk::Alignment());
85         alignment->set_padding(0, 0, 12, 0);
86         alignment->add(*w);
87         this->attach(*alignment, start_col, 2, row, row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::AttachOptions(),  0, 0);
88     } 
89     else
90     {
91         this->attach(*w, start_col, 2, row, row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::AttachOptions(),  0, 0);
92     }
94     if (suffix != "")
95     {
96         Gtk::Label* suffix_widget = Gtk::manage(new Gtk::Label(suffix , Gtk::ALIGN_LEFT , Gtk::ALIGN_CENTER, true));
97         if (expand_widget)
98             this->attach(*suffix_widget, 2, 3, row, row + 1, Gtk::FILL,  Gtk::AttachOptions(), 0, 0);
99         else
100             ((Gtk::HBox*)w)->pack_start(*suffix_widget,false,false);
101     }
102     
103     if (tip != "")
104     {
105         _tooltips.set_tip (widget, tip);
106     }
110 void DialogPage::add_group_header(Glib::ustring name)
112     int row = this->property_n_rows();
113     if (name != "")
114     {
115         Gtk::Label* label_widget = Gtk::manage(new Gtk::Label(Glib::ustring(/*"<span size='large'>*/"<b>") + name + 
116                                                Glib::ustring("</b>"/*</span>"*/) , Gtk::ALIGN_LEFT , Gtk::ALIGN_CENTER, true));
117         label_widget->set_use_markup(true);
118         this->attach(*label_widget , 0, 4, row, row + 1, Gtk::FILL, Gtk::AttachOptions(), 0, 0);
119         if (row != 1) 
120             this->set_row_spacing(row - 1, 18);
121     }
124 void DialogPage::set_tip(Gtk::Widget& widget, const Glib::ustring& tip)
126     _tooltips.set_tip (widget, tip);
129 void PrefCheckButton::init(const Glib::ustring& label, const std::string& prefs_path, const std::string& attr, 
130                            bool default_value)
132     _prefs_path = prefs_path;
133     _attr = attr;
134     this->set_label(label);
135     this->set_active( prefs_get_int_attribute (_prefs_path.c_str(), _attr.c_str(), (int)default_value) );
138 void PrefCheckButton::on_toggled()
140     if (this->is_visible()) //only take action if the user toggled it
141     {    
142         prefs_set_int_attribute (_prefs_path.c_str(), _attr.c_str(), (int) this->get_active());
143     }
146 void PrefRadioButton::init(const Glib::ustring& label, const std::string& prefs_path, const std::string& attr, 
147                            const std::string& string_value, bool default_value, PrefRadioButton* group_member)
149     _value_type = VAL_STRING;
150     _prefs_path = prefs_path;
151     _attr = attr;
152     _string_value = string_value;
153     this->set_label(label);
154     if (group_member)
155     {   
156         Gtk::RadioButtonGroup rbg = group_member->get_group();
157         this->set_group(rbg);
158     }
159     const gchar* val = prefs_get_string_attribute( _prefs_path.c_str(), _attr.c_str() );
160     if ( val )
161         this->set_active( std::string( val ) == _string_value);
162     else
163         this->set_active( false );
166 void PrefRadioButton::init(const Glib::ustring& label, const std::string& prefs_path, const std::string& attr, 
167                            int int_value, bool default_value, PrefRadioButton* group_member)
169     _value_type = VAL_INT;
170     _prefs_path = prefs_path;
171     _attr = attr;
172     _int_value = int_value;
173     this->set_label(label);
174     if (group_member)
175     {   
176         Gtk::RadioButtonGroup rbg = group_member->get_group();
177         this->set_group(rbg);
178     }
179     if (default_value)
180         this->set_active( prefs_get_int_attribute( _prefs_path.c_str(), _attr.c_str(), int_value ) == _int_value);
181     else
182         this->set_active( prefs_get_int_attribute( _prefs_path.c_str(), _attr.c_str(), int_value + 1 )== _int_value);
185 void PrefRadioButton::on_toggled()
187     this->changed_signal.emit(this->get_active());
188     if (this->is_visible() && this->get_active() ) //only take action if toggled by user (to active)
189     {    
190         if ( _value_type == VAL_STRING )
191                 prefs_set_string_attribute ( _prefs_path.c_str(), _attr.c_str(), _string_value.c_str());
192         else if ( _value_type == VAL_INT )
193                 prefs_set_int_attribute ( _prefs_path.c_str(), _attr.c_str(), _int_value);
194     }
197 void PrefSpinButton::init(const std::string& prefs_path, const std::string& attr,
198               double lower, double upper, double step_increment, double page_increment, 
199               double default_value, bool is_int, bool is_percent)
201     _prefs_path = prefs_path;
202     _attr = attr;
203     _is_int = is_int;
204     _is_percent = is_percent;
206     double value; 
207     if (is_int)
208         if (is_percent)
209             value = 100 * prefs_get_double_attribute_limited (prefs_path.c_str(), attr.c_str(), default_value, lower/100.0, upper/100.0);
210         else
211             value = (double) prefs_get_int_attribute_limited (prefs_path.c_str(), attr.c_str(), (int) default_value, (int) lower, (int) upper);
212     else
213         value = prefs_get_double_attribute_limited (prefs_path.c_str(), attr.c_str(), default_value, lower, upper);
215     this->set_range (lower, upper);
216     this->set_increments (step_increment, page_increment);
217     this->set_numeric();
218     this->set_value (value);
219     this->set_width_chars(6);
220     if (is_int) 
221         this->set_digits(0);
222     else if (step_increment < 0.1)
223         this->set_digits(4);
224     else
225         this->set_digits(2);
229 void PrefSpinButton::on_value_changed()
231     if (this->is_visible()) //only take action if user changed value
232     {    
233         if (_is_int)
234             if (_is_percent)
235                 prefs_set_double_attribute(_prefs_path.c_str(), _attr.c_str(), this->get_value()/100.0);
236             else
237                 prefs_set_int_attribute(_prefs_path.c_str(), _attr.c_str(), (int) this->get_value());
238         else
239             prefs_set_double_attribute (_prefs_path.c_str(), _attr.c_str(), this->get_value());
240     }
243 void PrefCombo::init(const std::string& prefs_path, const std::string& attr,
244                      Glib::ustring labels[], int values[], int num_items, int default_value)
246     _prefs_path = prefs_path;
247     _attr = attr;
248     int row = 0;
249     int value = prefs_get_int_attribute (_prefs_path.c_str(), _attr.c_str(), default_value);
251     for (int i = 0 ; i < num_items; ++i)
252     {
253         this->append_text(labels[i]);
254         _values.push_back(values[i]);
255         if (value == values[i])
256             row = i;
257     }
258     this->set_active(row);
261 void PrefCombo::on_changed()
263     if (this->is_visible()) //only take action if user changed value
264     {    
265         prefs_set_int_attribute (_prefs_path.c_str(), _attr.c_str(), _values[this->get_active_row_number()]);
266     }
269 } // namespace Widget
270 } // namespace UI
271 } // namespace Inkscape
273 /*
274   Local Variables:
275   mode:c++
276   c-file-style:"stroustrup"
277   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
278   indent-tabs-mode:nil
279   fill-column:99
280   End:
281 */
282 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :