Code

more precise simplification control
[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 PrefCheckButton::init(const Glib::ustring& label, const std::string& prefs_path, const std::string& attr, 
125                            bool default_value)
127     _prefs_path = prefs_path;
128     _attr = attr;
129     this->set_label(label);
130     this->set_active( prefs_get_int_attribute (_prefs_path.c_str(), _attr.c_str(), (int)default_value) );
133 void PrefCheckButton::on_toggled()
135     if (this->is_visible()) //only take action if the user toggled it
136     {    
137         prefs_set_int_attribute (_prefs_path.c_str(), _attr.c_str(), (int) this->get_active());
138     }
141 void PrefRadioButton::init(const Glib::ustring& label, const std::string& prefs_path, const std::string& attr, 
142                            const std::string& string_value, bool default_value, PrefRadioButton* group_member)
144     _value_type = VAL_STRING;
145     _prefs_path = prefs_path;
146     _attr = attr;
147     _string_value = string_value;
148     this->set_label(label);
149     if (group_member)
150     {   
151         Gtk::RadioButtonGroup rbg = group_member->get_group();
152         this->set_group(rbg);
153     }
154     const gchar* val = prefs_get_string_attribute( _prefs_path.c_str(), _attr.c_str() );
155     if ( val )
156         this->set_active( std::string( val ) == _string_value);
157     else
158         this->set_active( false );
161 void PrefRadioButton::init(const Glib::ustring& label, const std::string& prefs_path, const std::string& attr, 
162                            int int_value, bool default_value, PrefRadioButton* group_member)
164     _value_type = VAL_INT;
165     _prefs_path = prefs_path;
166     _attr = attr;
167     _int_value = int_value;
168     this->set_label(label);
169     if (group_member)
170     {   
171         Gtk::RadioButtonGroup rbg = group_member->get_group();
172         this->set_group(rbg);
173     }
174     if (default_value)
175         this->set_active( prefs_get_int_attribute( _prefs_path.c_str(), _attr.c_str(), int_value ) == _int_value);
176     else
177         this->set_active( prefs_get_int_attribute( _prefs_path.c_str(), _attr.c_str(), int_value + 1 )== _int_value);
180 void PrefRadioButton::on_toggled()
182     this->changed_signal.emit(this->get_active());
183     if (this->is_visible() && this->get_active() ) //only take action if toggled by user (to active)
184     {    
185         if ( _value_type == VAL_STRING )
186                 prefs_set_string_attribute ( _prefs_path.c_str(), _attr.c_str(), _string_value.c_str());
187         else if ( _value_type == VAL_INT )
188                 prefs_set_int_attribute ( _prefs_path.c_str(), _attr.c_str(), _int_value);
189     }
192 void PrefSpinButton::init(const std::string& prefs_path, const std::string& attr,
193               double lower, double upper, double step_increment, double page_increment, 
194               double default_value, bool is_int, bool is_percent)
196     _prefs_path = prefs_path;
197     _attr = attr;
198     _is_int = is_int;
199     _is_percent = is_percent;
201     double value; 
202     if (is_int)
203         if (is_percent)
204             value = 100 * prefs_get_double_attribute_limited (prefs_path.c_str(), attr.c_str(), default_value, lower/100.0, upper/100.0);
205         else
206             value = (double) prefs_get_int_attribute_limited (prefs_path.c_str(), attr.c_str(), (int) default_value, (int) lower, (int) upper);
207     else
208         value = prefs_get_double_attribute_limited (prefs_path.c_str(), attr.c_str(), default_value, lower, upper);
210     this->set_range (lower, upper);
211     this->set_increments (step_increment, page_increment);
212     this->set_numeric();
213     this->set_value (value);
214     this->set_width_chars(6);
215     if (is_int) 
216         this->set_digits(0);
217     else if (step_increment < 0.1)
218         this->set_digits(4);
219     else
220         this->set_digits(2);
224 void PrefSpinButton::on_value_changed()
226     if (this->is_visible()) //only take action if user changed value
227     {    
228         if (_is_int)
229             if (_is_percent)
230                 prefs_set_double_attribute(_prefs_path.c_str(), _attr.c_str(), this->get_value()/100.0);
231             else
232                 prefs_set_int_attribute(_prefs_path.c_str(), _attr.c_str(), (int) this->get_value());
233         else
234             prefs_set_double_attribute (_prefs_path.c_str(), _attr.c_str(), this->get_value());
235     }
238 void PrefCombo::init(const std::string& prefs_path, const std::string& attr,
239                      Glib::ustring labels[], int values[], int num_items, int default_value)
241     _prefs_path = prefs_path;
242     _attr = attr;
243     int row = 0;
244     int value = prefs_get_int_attribute (_prefs_path.c_str(), _attr.c_str(), default_value);
246     for (int i = 0 ; i < num_items; ++i)
247     {
248         this->append_text(labels[i]);
249         _values.push_back(values[i]);
250         if (value == values[i])
251             row = i;
252     }
253     this->set_active(row);
256 void PrefCombo::on_changed()
258     if (this->is_visible()) //only take action if user changed value
259     {    
260         prefs_set_int_attribute (_prefs_path.c_str(), _attr.c_str(), _values[this->get_active_row_number()]);
261         std::cout << "combo set: " << _prefs_path << " " << _attr << " " << _values[this->get_active_row_number()] << std::endl;
262     }
265 } // namespace Widget
266 } // namespace UI
267 } // namespace Inkscape
269 /*
270   Local Variables:
271   mode:c++
272   c-file-style:"stroustrup"
273   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
274   indent-tabs-mode:nil
275   fill-column:99
276   End:
277 */
278 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :