diff options
| author | Ted Gould <ted@gould.cx> | 2008-10-27 18:03:09 +0000 |
|---|---|---|
| committer | Ted Gould <ted@canonical.com> | 2008-10-27 18:03:09 +0000 |
| commit | 7dbe11bc23efa5f51a9b84e7d0f6dd16e63e0902 (patch) | |
| tree | 7d3a2b95b84a03a19cb132cdf88bea0ab6dc4773 /src/ui/widget | |
| parent | Merging from trunk (diff) | |
| download | inkscape-7dbe11bc23efa5f51a9b84e7d0f6dd16e63e0902.tar.gz inkscape-7dbe11bc23efa5f51a9b84e7d0f6dd16e63e0902.zip | |
From trunk
(bzr r6885)
Diffstat (limited to 'src/ui/widget')
| -rw-r--r-- | src/ui/widget/dock-item.cpp | 10 | ||||
| -rw-r--r-- | src/ui/widget/dock.cpp | 15 | ||||
| -rw-r--r-- | src/ui/widget/dock.h | 8 | ||||
| -rw-r--r-- | src/ui/widget/panel.cpp | 115 | ||||
| -rw-r--r-- | src/ui/widget/panel.h | 2 | ||||
| -rw-r--r-- | src/ui/widget/preferences-widget.cpp | 99 | ||||
| -rw-r--r-- | src/ui/widget/preferences-widget.h | 30 | ||||
| -rw-r--r-- | src/ui/widget/registered-widget.cpp | 8 | ||||
| -rw-r--r-- | src/ui/widget/style-swatch.cpp | 202 | ||||
| -rw-r--r-- | src/ui/widget/style-swatch.h | 45 |
10 files changed, 233 insertions, 301 deletions
diff --git a/src/ui/widget/dock-item.cpp b/src/ui/widget/dock-item.cpp index e61b8080e..12a0686f0 100644 --- a/src/ui/widget/dock-item.cpp +++ b/src/ui/widget/dock-item.cpp @@ -12,7 +12,7 @@ #include "dock-item.h" #include "desktop.h" #include "inkscape.h" -#include "prefs-utils.h" +#include "preferences.h" #include "ui/widget/dock.h" #include "widgets/icon.h" @@ -37,11 +37,11 @@ DockItem::DockItem(Dock& dock, const Glib::ustring& name, const Glib::ustring& l _gdl_dock_item(0), _dock_item_action_area(0) { - + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); GdlDockItemBehavior gdl_dock_behavior = - (prefs_get_int_attribute_limited ("options.dock", "cancenterdock", 1, 0, 1) == 0 ? - GDL_DOCK_ITEM_BEH_CANT_DOCK_CENTER - : GDL_DOCK_ITEM_BEH_NORMAL); + (prefs->getBool("/options/dock/cancenterdock", true) ? + GDL_DOCK_ITEM_BEH_NORMAL : + GDL_DOCK_ITEM_BEH_CANT_DOCK_CENTER); if (!icon_name.empty()) { Gtk::Widget *icon = sp_icon_get_icon(icon_name, Inkscape::ICON_SIZE_MENU); diff --git a/src/ui/widget/dock.cpp b/src/ui/widget/dock.cpp index 563ed8e98..3608c3551 100644 --- a/src/ui/widget/dock.cpp +++ b/src/ui/widget/dock.cpp @@ -1,7 +1,7 @@ -/** - * \brief A desktop dock pane to dock dialogs. - * - * Author: +/** @file + * @brief A desktop dock pane to dock dialogs. + */ +/* Author: * Gustav Broberg <broberg@kth.se> * * Copyright (C) 2007 Authors @@ -10,7 +10,7 @@ */ #include "inkscape.h" -#include "prefs-utils.h" +#include "preferences.h" #include "desktop.h" #include "dock.h" @@ -74,8 +74,9 @@ Dock::Dock(Gtk::Orientation orientation) _scrolled_window->set_size_request(0); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); GdlSwitcherStyle gdl_switcher_style = - static_cast<GdlSwitcherStyle>(prefs_get_int_attribute_limited("options.dock", "switcherstyle", + static_cast<GdlSwitcherStyle>(prefs->getIntLimited("/options/dock/switcherstyle", GDL_SWITCHER_STYLE_BOTH, 0, 4)); g_object_set (GDL_DOCK_OBJECT(_gdl_dock)->master, @@ -84,7 +85,7 @@ Dock::Dock(Gtk::Orientation orientation) NULL); GdlDockBarStyle gdl_dock_bar_style = - static_cast<GdlDockBarStyle>(prefs_get_int_attribute_limited("options.dock", "dockbarstyle", + static_cast<GdlDockBarStyle>(prefs->getIntLimited("/options/dock/dockbarstyle", GDL_DOCK_BAR_BOTH, 0, 3)); gdl_dock_bar_set_style(_gdl_dock_bar, gdl_dock_bar_style); diff --git a/src/ui/widget/dock.h b/src/ui/widget/dock.h index dd501f186..c49d71268 100644 --- a/src/ui/widget/dock.h +++ b/src/ui/widget/dock.h @@ -1,7 +1,7 @@ -/** - * \brief A desktop dock pane to dock dialogs, a custom wrapper around gdl-dock. - * - * Author: +/** @file + * @brief A desktop dock pane to dock dialogs, a custom wrapper around gdl-dock. + */ +/* Author: * Gustav Broberg <broberg@kth.se> * * Copyright (C) 2007 Authors diff --git a/src/ui/widget/panel.cpp b/src/ui/widget/panel.cpp index 9333ffc35..9811cc89c 100644 --- a/src/ui/widget/panel.cpp +++ b/src/ui/widget/panel.cpp @@ -26,7 +26,7 @@ #include "panel.h" #include "icon-size.h" -#include "prefs-utils.h" +#include "preferences.h" #include "desktop-handles.h" #include "inkscape.h" #include "dialogs/eek-preview.h" @@ -94,50 +94,40 @@ void Panel::_init() Glib::ustring tmp("<"); _anchor = Gtk::ANCHOR_CENTER; - guint panel_size = 0; - if (_prefs_path) { - panel_size = prefs_get_int_attribute_limited( _prefs_path, "panel_size", 1, 0, static_cast<long long>(PREVIEW_SIZE_HUGE) ); - } - - guint panel_mode = 0; - if (_prefs_path) { - panel_mode = prefs_get_int_attribute_limited( _prefs_path, "panel_mode", 1, 0, 10 ); - } - - guint panel_wrap = 0; - if (_prefs_path) { - panel_wrap = prefs_get_int_attribute_limited( _prefs_path, "panel_wrap", 0, 0, 1 ); - } - - guint panel_ratio = 100; - if (_prefs_path) { - panel_ratio = prefs_get_int_attribute_limited( _prefs_path, "panel_ratio", 100, 0, 500 ); + guint panel_size = 0, panel_mode = 0, panel_ratio = 100; + bool panel_wrap = 0; + if (!_prefs_path.empty()) { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + panel_wrap = prefs->getBool(_prefs_path + "/panel_wrap"); + panel_size = prefs->getIntLimited(_prefs_path + "/panel_size", 1, 0, PREVIEW_SIZE_HUGE); + panel_mode = prefs->getIntLimited(_prefs_path + "/panel_mode", 1, 0, 10); + panel_ratio = prefs->getIntLimited(_prefs_path + "/panel_ratio", 100, 0, 500 ); } _menu = new Gtk::Menu(); { - Gtk::RadioMenuItem::Group group; - Glib::ustring one_label(_("List")); - Glib::ustring two_label(_("Grid")); - Gtk::RadioMenuItem *one = manage(new Gtk::RadioMenuItem(group, one_label)); - Gtk::RadioMenuItem *two = manage(new Gtk::RadioMenuItem(group, two_label)); - - if (panel_mode == 0) { - one->set_active(true); - } else if (panel_mode == 1) { - two->set_active(true); - } - - _menu->append(*one); - _non_horizontal.push_back(one); - _menu->append(*two); - _non_horizontal.push_back(two); - Gtk::MenuItem* sep = manage(new Gtk::SeparatorMenuItem()); - _menu->append(*sep); - _non_horizontal.push_back(sep); - one->signal_activate().connect(sigc::bind<int, int>(sigc::mem_fun(*this, &Panel::_bounceCall), PANEL_SETTING_MODE, 0)); - two->signal_activate().connect(sigc::bind<int, int>(sigc::mem_fun(*this, &Panel::_bounceCall), PANEL_SETTING_MODE, 1)); + Gtk::RadioMenuItem::Group group; + Glib::ustring one_label(_("List")); + Glib::ustring two_label(_("Grid")); + Gtk::RadioMenuItem *one = manage(new Gtk::RadioMenuItem(group, one_label)); + Gtk::RadioMenuItem *two = manage(new Gtk::RadioMenuItem(group, two_label)); + + if (panel_mode == 0) { + one->set_active(true); + } else if (panel_mode == 1) { + two->set_active(true); + } + + _menu->append(*one); + _non_horizontal.push_back(one); + _menu->append(*two); + _non_horizontal.push_back(two); + Gtk::MenuItem* sep = manage(new Gtk::SeparatorMenuItem()); + _menu->append(*sep); + _non_horizontal.push_back(sep); + one->signal_activate().connect(sigc::bind<int, int>(sigc::mem_fun(*this, &Panel::_bounceCall), PANEL_SETTING_MODE, 0)); + two->signal_activate().connect(sigc::bind<int, int>(sigc::mem_fun(*this, &Panel::_bounceCall), PANEL_SETTING_MODE, 1)); } { @@ -336,21 +326,14 @@ void Panel::present() void Panel::restorePanelPrefs() { - guint panel_size = 0; - if (_prefs_path) { - panel_size = prefs_get_int_attribute_limited(_prefs_path, "panel_size", 1, 0, static_cast<long long>(PREVIEW_SIZE_HUGE)); - } - guint panel_mode = 0; - if (_prefs_path) { - panel_mode = prefs_get_int_attribute_limited(_prefs_path, "panel_mode", 1, 0, 10); - } - guint panel_wrap = 0; - if (_prefs_path) { - panel_wrap = prefs_get_int_attribute_limited(_prefs_path, "panel_wrap", 0, 0, 1 ); - } - guint panel_ratio = 100; - if (_prefs_path) { - panel_ratio = prefs_get_int_attribute_limited(_prefs_path, "panel_ratio", 000, 0, 500 ); + guint panel_size = 0, panel_mode = 0, panel_ratio = 100; + bool panel_wrap = 0; + if (!_prefs_path.empty()) { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + panel_wrap = prefs->getBool(_prefs_path + "/panel_wrap"); + panel_size = prefs->getIntLimited(_prefs_path + "/panel_size", 1, 0, PREVIEW_SIZE_HUGE); + panel_mode = prefs->getIntLimited(_prefs_path + "/panel_mode", 1, 0, 10); + panel_ratio = prefs->getIntLimited(_prefs_path + "/panel_ratio", 000, 0, 500 ); } _bounceCall(PANEL_SETTING_SIZE, panel_size); _bounceCall(PANEL_SETTING_MODE, panel_mode); @@ -375,8 +358,9 @@ void Panel::_bounceCall(int i, int j) _menu->set_active(0); switch (i) { case PANEL_SETTING_SIZE: - if (_prefs_path) { - prefs_set_int_attribute(_prefs_path, "panel_size", j); + if (!_prefs_path.empty()) { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setInt(_prefs_path + "/panel_size", j); } if (_fillable) { ViewType curr_type = _fillable->getPreviewType(); @@ -413,8 +397,9 @@ void Panel::_bounceCall(int i, int j) } break; case PANEL_SETTING_MODE: - if (_prefs_path) { - prefs_set_int_attribute (_prefs_path, "panel_mode", j); + if (!_prefs_path.empty()) { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setInt(_prefs_path + "/panel_mode", j); } if (_fillable) { ::PreviewSize curr_size = _fillable->getPreviewSize(); @@ -436,8 +421,9 @@ void Panel::_bounceCall(int i, int j) } break; case PANEL_SETTING_SHAPE: - if (_prefs_path) { - prefs_set_int_attribute (_prefs_path, "panel_ratio", j); + if (!_prefs_path.empty()) { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setInt(_prefs_path + "/panel_ratio", j); } if ( _fillable ) { ViewType curr_type = _fillable->getPreviewType(); @@ -446,8 +432,9 @@ void Panel::_bounceCall(int i, int j) } break; case PANEL_SETTING_WRAP: - if (_prefs_path) { - prefs_set_int_attribute (_prefs_path, "panel_wrap", j ? 1 : 0); + if (!_prefs_path.empty()) { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setBool(_prefs_path + "/panel_wrap", j); } if ( _fillable ) { _fillable->setWrap(j); @@ -468,7 +455,7 @@ void Panel::_wrapToggled(Gtk::CheckMenuItem* toggler) gchar const *Panel::getPrefsPath() const { - return _prefs_path; + return _prefs_path.data(); } Glib::ustring const &Panel::getLabel() const diff --git a/src/ui/widget/panel.h b/src/ui/widget/panel.h index 1062ee58e..d42548f16 100644 --- a/src/ui/widget/panel.h +++ b/src/ui/widget/panel.h @@ -92,7 +92,7 @@ protected: /** Tooltips object for all descendants to use */ Gtk::Tooltips _tooltips; - const gchar *_prefs_path; + Glib::ustring const _prefs_path; bool _menu_desired; Gtk::AnchorType _anchor; diff --git a/src/ui/widget/preferences-widget.cpp b/src/ui/widget/preferences-widget.cpp index b11ca2e93..72df1baab 100644 --- a/src/ui/widget/preferences-widget.cpp +++ b/src/ui/widget/preferences-widget.cpp @@ -128,13 +128,12 @@ void DialogPage::set_tip(Gtk::Widget& widget, Glib::ustring const &tip) } void PrefCheckButton::init(Glib::ustring const &label, Glib::ustring const &prefs_path, - Glib::ustring const &attr, bool default_value) + bool default_value) { _prefs_path = prefs_path; - _attr = attr; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); this->set_label(label); - this->set_active( prefs->getBool(_prefs_path, _attr, default_value) ); + this->set_active( prefs->getBool(_prefs_path, default_value) ); } void PrefCheckButton::on_toggled() @@ -142,15 +141,14 @@ void PrefCheckButton::on_toggled() if (this->is_visible()) //only take action if the user toggled it { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setBool(_prefs_path, _attr, this->get_active()); + prefs->setBool(_prefs_path, this->get_active()); } } void PrefRadioButton::init(Glib::ustring const &label, Glib::ustring const &prefs_path, - Glib::ustring const &attr, Glib::ustring const &string_value, bool default_value, PrefRadioButton* group_member) + Glib::ustring const &string_value, bool default_value, PrefRadioButton* group_member) { _prefs_path = prefs_path; - _attr = attr; _value_type = VAL_STRING; _string_value = string_value; (void)default_value; @@ -161,7 +159,7 @@ void PrefRadioButton::init(Glib::ustring const &label, Glib::ustring const &pref this->set_group(rbg); } Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - Glib::ustring val = prefs->getString(_prefs_path, _attr); + Glib::ustring val = prefs->getString(_prefs_path); if ( !val.empty() ) this->set_active(val == _string_value); else @@ -169,10 +167,9 @@ void PrefRadioButton::init(Glib::ustring const &label, Glib::ustring const &pref } void PrefRadioButton::init(Glib::ustring const &label, Glib::ustring const &prefs_path, - Glib::ustring const &attr, int int_value, bool default_value, PrefRadioButton* group_member) + int int_value, bool default_value, PrefRadioButton* group_member) { _prefs_path = prefs_path; - _attr = attr; _value_type = VAL_INT; _int_value = int_value; this->set_label(label); @@ -183,9 +180,9 @@ void PrefRadioButton::init(Glib::ustring const &label, Glib::ustring const &pref } Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (default_value) - this->set_active( prefs->getInt(_prefs_path, _attr, int_value) == _int_value ); + this->set_active( prefs->getInt(_prefs_path, int_value) == _int_value ); else - this->set_active( prefs->getInt(_prefs_path, _attr, int_value + 1) == _int_value ); + this->set_active( prefs->getInt(_prefs_path, int_value + 1) == _int_value ); } void PrefRadioButton::on_toggled() @@ -196,30 +193,29 @@ void PrefRadioButton::on_toggled() if (this->is_visible() && this->get_active() ) //only take action if toggled by user (to active) { if ( _value_type == VAL_STRING ) - prefs->setString(_prefs_path, _attr, _string_value); + prefs->setString(_prefs_path, _string_value); else if ( _value_type == VAL_INT ) - prefs->setInt(_prefs_path, _attr, _int_value); + prefs->setInt(_prefs_path, _int_value); } } -void PrefSpinButton::init(Glib::ustring const &prefs_path, Glib::ustring const &attr, +void PrefSpinButton::init(Glib::ustring const &prefs_path, double lower, double upper, double step_increment, double page_increment, double default_value, bool is_int, bool is_percent) { _prefs_path = prefs_path; - _attr = attr; _is_int = is_int; _is_percent = is_percent; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); double value; if (is_int) { if (is_percent) { - value = 100 * prefs->getDoubleLimited(prefs_path, attr, default_value, lower/100.0, upper/100.0); + value = 100 * prefs->getDoubleLimited(prefs_path, default_value, lower/100.0, upper/100.0); } else { - value = (double) prefs->getIntLimited(prefs_path, attr, (int) default_value, (int) lower, (int) upper); + value = (double) prefs->getIntLimited(prefs_path, (int) default_value, (int) lower, (int) upper); } } else { - value = prefs->getDoubleLimited(prefs_path, attr, default_value, lower, upper); + value = prefs->getDoubleLimited(prefs_path, default_value, lower, upper); } this->set_range (lower, upper); @@ -243,12 +239,12 @@ void PrefSpinButton::on_value_changed() { if (_is_int) { if (_is_percent) { - prefs->setDouble(_prefs_path, _attr, this->get_value()/100.0); + prefs->setDouble(_prefs_path, this->get_value()/100.0); } else { - prefs->setInt(_prefs_path, _attr, (int) this->get_value()); + prefs->setInt(_prefs_path, (int) this->get_value()); } } else { - prefs->setDouble(_prefs_path, _attr, this->get_value()); + prefs->setDouble(_prefs_path, this->get_value()); } } } @@ -273,7 +269,7 @@ void ZoomCorrRuler::set_size(int x, int y) // The following two functions are borrowed from 2geom's toy-framework-2; if they are useful in // other locations, we should perhaps make them (or adapted versions of them) publicly available static void -draw_text(cairo_t *cr, Geom::Point loc, const char* txt, bool bottom = "false", +draw_text(cairo_t *cr, Geom::Point loc, const char* txt, bool bottom = false, double fontsize = ZoomCorrRuler::textsize, std::string fontdesc = "Sans") { PangoLayout* layout = pango_cairo_create_layout (cr); pango_layout_set_text(layout, txt, -1); @@ -306,7 +302,7 @@ draw_number(cairo_t *cr, Geom::Point pos, double num) { void ZoomCorrRuler::draw_marks(Cairo::RefPtr<Cairo::Context> cr, double dist, int major_interval) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - const double zoomcorr = prefs->getDouble("options.zoomcorrection", "value", 1.0); + const double zoomcorr = prefs->getDouble("/options/zoomcorrection/value", 1.0); double mark = 0; int i = 0; while (mark <= _drawing_width) { @@ -347,7 +343,7 @@ ZoomCorrRuler::redraw() { cr->line_to (_drawing_width, _height); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - Glib::ustring abbr = prefs->getString("options.zoomcorrection", "unit"); + Glib::ustring abbr = prefs->getString("/options/zoomcorrection/unit"); if (abbr == "cm") { draw_marks(cr, 0.1, 10); } else if (abbr == "ft") { @@ -383,7 +379,7 @@ ZoomCorrRulerSlider::on_slider_value_changed() { freeze = true; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setDouble("options.zoomcorrection", "value", _slider.get_value() / 100.0); + prefs->setDouble("/options/zoomcorrection/value", _slider.get_value() / 100.0); _sb.set_value(_slider.get_value()); _ruler.redraw(); freeze = false; @@ -397,7 +393,7 @@ ZoomCorrRulerSlider::on_spinbutton_value_changed() { freeze = true; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setDouble("options.zoomcorrection", "value", _sb.get_value() / 100.0); + prefs->setDouble("/options/zoomcorrection/value", _sb.get_value() / 100.0); _slider.set_value(_sb.get_value()); _ruler.redraw(); freeze = false; @@ -412,7 +408,7 @@ ZoomCorrRulerSlider::on_unit_changed() { return; } Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setString("options.zoomcorrection", "unit", _unit.getUnitAbbr()); + prefs->setString("/options/zoomcorrection/unit", _unit.getUnitAbbr()); double conv = _unit.getConversion(_unit.getUnitAbbr(), "px"); _ruler.set_unit_conversion(conv); if (_ruler.is_visible()) { @@ -425,7 +421,7 @@ ZoomCorrRulerSlider::init(int ruler_width, int ruler_height, double lower, doubl double step_increment, double page_increment, double default_value) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - double value = prefs->getDoubleLimited("options.zoomcorrection", "value", default_value, lower, upper) * 100.0; + double value = prefs->getDoubleLimited("/options/zoomcorrection/value", default_value, lower, upper) * 100.0; freeze = false; @@ -449,7 +445,7 @@ ZoomCorrRulerSlider::init(int ruler_width, int ruler_height, double lower, doubl _unit.set_data("sensitive", GINT_TO_POINTER(0)); _unit.setUnitType(UNIT_TYPE_LINEAR); _unit.set_data("sensitive", GINT_TO_POINTER(1)); - _unit.setUnit(prefs->getString("options.zoomcorrection", "unit")); + _unit.setUnit(prefs->getString("/options/zoomcorrection/unit")); Gtk::Table *table = Gtk::manage(new Gtk::Table()); Gtk::Alignment *alignment1 = Gtk::manage(new Gtk::Alignment(0.5,1,0,0)); @@ -465,14 +461,13 @@ ZoomCorrRulerSlider::init(int ruler_width, int ruler_height, double lower, doubl this->pack_start(*table, Gtk::PACK_EXPAND_WIDGET); } -void PrefCombo::init(Glib::ustring const &prefs_path, Glib::ustring const &attr, +void PrefCombo::init(Glib::ustring const &prefs_path, Glib::ustring labels[], int values[], int num_items, int default_value) { _prefs_path = prefs_path; - _attr = attr; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); int row = 0; - int value = prefs->getInt(_prefs_path, _attr, default_value); + int value = prefs->getInt(_prefs_path, default_value); for (int i = 0 ; i < num_items; ++i) { @@ -489,22 +484,21 @@ void PrefCombo::on_changed() if (this->is_visible()) //only take action if user changed value { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setInt(_prefs_path, _attr, _values[this->get_active_row_number()]); + prefs->setInt(_prefs_path, _values[this->get_active_row_number()]); } } -void PrefEntryButtonHBox::init(Glib::ustring const &prefs_path, Glib::ustring const &attr, +void PrefEntryButtonHBox::init(Glib::ustring const &prefs_path, bool visibility, Glib::ustring const &default_string) { _prefs_path = prefs_path; - _attr = attr; _default_string = default_string; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); relatedEntry = new Gtk::Entry(); relatedButton = new Gtk::Button(_("Reset")); relatedEntry->set_invisible_char('*'); relatedEntry->set_visibility(visibility); - relatedEntry->set_text(prefs->getString(_prefs_path, _attr)); + relatedEntry->set_text(prefs->getString(_prefs_path)); this->pack_start(*relatedEntry); this->pack_start(*relatedButton); relatedButton->signal_clicked().connect( @@ -518,7 +512,7 @@ void PrefEntryButtonHBox::onRelatedEntryChangedCallback() if (this->is_visible()) //only take action if user changed value { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setString(_prefs_path, _attr, relatedEntry->get_text()); + prefs->setString(_prefs_path, relatedEntry->get_text()); } } @@ -527,18 +521,17 @@ void PrefEntryButtonHBox::onRelatedButtonClickedCallback() if (this->is_visible()) //only take action if user changed value { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setString(_prefs_path, _attr, _default_string); + prefs->setString(_prefs_path, _default_string); relatedEntry->set_text(_default_string); } } -void PrefFileButton::init(Glib::ustring const &prefs_path, Glib::ustring const &attr) +void PrefFileButton::init(Glib::ustring const &prefs_path) { _prefs_path = prefs_path; - _attr = attr; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - select_filename(Glib::filename_from_utf8(prefs->getString(_prefs_path, _attr))); + select_filename(Glib::filename_from_utf8(prefs->getString(_prefs_path))); signal_selection_changed().connect(sigc::mem_fun(*this, &PrefFileButton::onFileChanged)); } @@ -546,18 +539,16 @@ void PrefFileButton::init(Glib::ustring const &prefs_path, Glib::ustring const & void PrefFileButton::onFileChanged() { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setString(_prefs_path, _attr, Glib::filename_to_utf8(get_filename())); + prefs->setString(_prefs_path, Glib::filename_to_utf8(get_filename())); } -void PrefEntry::init(Glib::ustring const &prefs_path, Glib::ustring const &attr, - bool visibility) +void PrefEntry::init(Glib::ustring const &prefs_path, bool visibility) { _prefs_path = prefs_path; - _attr = attr; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); this->set_invisible_char('*'); this->set_visibility(visibility); - this->set_text(prefs->getString(_prefs_path, _attr)); + this->set_text(prefs->getString(_prefs_path)); } void PrefEntry::on_changed() @@ -565,18 +556,17 @@ void PrefEntry::on_changed() if (this->is_visible()) //only take action if user changed value { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setString(_prefs_path, _attr, this->get_text()); + prefs->setString(_prefs_path, this->get_text()); } } -void PrefColorPicker::init(Glib::ustring const &label, Glib::ustring const &prefs_path, Glib::ustring const &attr, +void PrefColorPicker::init(Glib::ustring const &label, Glib::ustring const &prefs_path, guint32 default_rgba) { _prefs_path = prefs_path; - _attr = attr; _title = label; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - this->setRgba32( prefs->getInt(_prefs_path, _attr, (int)default_rgba) ); + this->setRgba32( prefs->getInt(_prefs_path, (int)default_rgba) ); } void PrefColorPicker::on_changed (guint32 rgba) @@ -584,17 +574,16 @@ void PrefColorPicker::on_changed (guint32 rgba) if (this->is_visible()) //only take action if the user toggled it { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setInt(_prefs_path, _attr, (int) rgba); + prefs->setInt(_prefs_path, (int) rgba); } } -void PrefUnit::init(Glib::ustring const &prefs_path, Glib::ustring const &attr) +void PrefUnit::init(Glib::ustring const &prefs_path) { _prefs_path = prefs_path; - _attr = attr; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); setUnitType(UNIT_TYPE_LINEAR); - setUnit(prefs->getString(_prefs_path, _attr)); + setUnit(prefs->getString(_prefs_path)); } void PrefUnit::on_changed() @@ -602,7 +591,7 @@ void PrefUnit::on_changed() if (this->is_visible()) //only take action if user changed value { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setString(_prefs_path, _attr, getUnitAbbr()); + prefs->setString(_prefs_path, getUnitAbbr()); } } diff --git a/src/ui/widget/preferences-widget.h b/src/ui/widget/preferences-widget.h index da07db5d9..dbc319c1a 100644 --- a/src/ui/widget/preferences-widget.h +++ b/src/ui/widget/preferences-widget.h @@ -39,25 +39,23 @@ namespace Widget { class PrefCheckButton : public Gtk::CheckButton { public: - void init(Glib::ustring const &label, Glib::ustring const &prefs_path, Glib::ustring const &attr, + void init(Glib::ustring const &label, Glib::ustring const &prefs_path, bool default_value); protected: Glib::ustring _prefs_path; - Glib::ustring _attr; void on_toggled(); }; class PrefRadioButton : public Gtk::RadioButton { public: - void init(Glib::ustring const &label, Glib::ustring const &prefs_path, Glib::ustring const &attr, + void init(Glib::ustring const &label, Glib::ustring const &prefs_path, int int_value, bool default_value, PrefRadioButton* group_member); - void init(Glib::ustring const &label, Glib::ustring const &prefs_path, Glib::ustring const &attr, + void init(Glib::ustring const &label, Glib::ustring const &prefs_path, Glib::ustring const &string_value, bool default_value, PrefRadioButton* group_member); sigc::signal<void, bool> changed_signal; protected: Glib::ustring _prefs_path; - Glib::ustring _attr; Glib::ustring _string_value; int _value_type; enum @@ -72,12 +70,11 @@ protected: class PrefSpinButton : public Gtk::SpinButton { public: - void init(Glib::ustring const &prefs_path, Glib::ustring const &attr, + void init(Glib::ustring const &prefs_path, double lower, double upper, double step_increment, double page_increment, double default_value, bool is_int, bool is_percent); protected: Glib::ustring _prefs_path; - Glib::ustring _attr; bool _is_int; bool _is_percent; void on_value_changed(); @@ -128,11 +125,10 @@ private: class PrefCombo : public Gtk::ComboBoxText { public: - void init(Glib::ustring const &prefs_path, Glib::ustring const &attr, + void init(Glib::ustring const &prefs_path, Glib::ustring labels[], int values[], int num_items, int default_value); protected: Glib::ustring _prefs_path; - Glib::ustring _attr; std::vector<int> _values; void on_changed(); }; @@ -140,22 +136,19 @@ protected: class PrefEntry : public Gtk::Entry { public: - void init(Glib::ustring const &prefs_path, Glib::ustring const &attr, - bool mask); + void init(Glib::ustring const &prefs_path, bool mask); protected: Glib::ustring _prefs_path; - Glib::ustring _attr; void on_changed(); }; class PrefEntryButtonHBox : public Gtk::HBox { public: - void init(Glib::ustring const &prefs_path, Glib::ustring const &attr, + void init(Glib::ustring const &prefs_path, bool mask, Glib::ustring const &default_string); protected: Glib::ustring _prefs_path; - Glib::ustring _attr; Glib::ustring _default_string; Gtk::Button *relatedButton; Gtk::Entry *relatedEntry; @@ -166,11 +159,10 @@ protected: class PrefFileButton : public Gtk::FileChooserButton { public: - void init(Glib::ustring const &prefs_path, Glib::ustring const &attr); + void init(Glib::ustring const &prefs_path); protected: Glib::ustring _prefs_path; - Glib::ustring _attr; void onFileChanged(); }; @@ -180,22 +172,20 @@ public: PrefColorPicker() : ColorPicker("", "", 0, false) {}; virtual ~PrefColorPicker() {}; - void init(Glib::ustring const &abel, Glib::ustring const &prefs_path, Glib::ustring const &attr, + void init(Glib::ustring const &abel, Glib::ustring const &prefs_path, guint32 default_rgba); protected: Glib::ustring _prefs_path; - Glib::ustring _attr; virtual void on_changed (guint32 rgba); }; class PrefUnit : public UnitMenu { public: - void init(Glib::ustring const &prefs_path, Glib::ustring const &attr); + void init(Glib::ustring const &prefs_path); protected: Glib::ustring _prefs_path; - Glib::ustring _attr; void on_changed(); }; diff --git a/src/ui/widget/registered-widget.cpp b/src/ui/widget/registered-widget.cpp index 2cc6e3c62..95ddec286 100644 --- a/src/ui/widget/registered-widget.cpp +++ b/src/ui/widget/registered-widget.cpp @@ -155,6 +155,8 @@ RegisteredScalarUnit::RegisteredScalarUnit (const Glib::ustring& label, const Gl { init_parent(key, wr, repr_in, doc_in); + setProgrammatically = false; + initScalar (-1e6, 1e6); setUnit (rum.getUnitMenu()->getUnitAbbr()); setDigits (2); @@ -203,6 +205,8 @@ RegisteredScalar::RegisteredScalar ( const Glib::ustring& label, const Glib::ust { init_parent(key, wr, repr_in, doc_in); + setProgrammatically = false; + setRange (-1e6, 1e6); setDigits (2); setIncrements(0.1, 1.0); @@ -249,6 +253,8 @@ RegisteredText::RegisteredText ( const Glib::ustring& label, const Glib::ustring { init_parent(key, wr, repr_in, doc_in); + setProgrammatically = false; + setText(""); _activate_connection = signal_activate().connect (sigc::mem_fun (*this, &RegisteredText::on_activate)); } @@ -597,6 +603,8 @@ RegisteredRandom::RegisteredRandom ( const Glib::ustring& label, const Glib::ust { init_parent(key, wr, repr_in, doc_in); + setProgrammatically = false; + setRange (-1e6, 1e6); setDigits (2); setIncrements(0.1, 1.0); diff --git a/src/ui/widget/style-swatch.cpp b/src/ui/widget/style-swatch.cpp index 807c21de5..47f6292e3 100644 --- a/src/ui/widget/style-swatch.cpp +++ b/src/ui/widget/style-swatch.cpp @@ -1,10 +1,11 @@ -/** - * \brief Static style swatch (fill, stroke, opacity) - * - * Author: +/** @file + * @brief Static style swatch (fill, stroke, opacity) + */ +/* Authors: * buliabyak@gmail.com + * Krzysztof Kosiński <tweenk.pl@gmail.com> * - * Copyright (C) 2005 author + * Copyright (C) 2005-2008 Authors * * Released under GNU GPL. Read the file 'COPYING' for more information. */ @@ -26,10 +27,10 @@ #include "sp-radial-gradient-fns.h" #include "sp-pattern.h" #include "xml/repr.h" -#include "xml/node-event-vector.h" #include "widgets/widget-sizes.h" #include "helper/units.h" #include "helper/action.h" +#include "preferences.h" #include "inkscape.h" enum { @@ -37,74 +38,80 @@ enum { SS_STROKE }; -static void style_swatch_attr_changed( Inkscape::XML::Node *repr, gchar const *name, - gchar const */*old_value*/, gchar const */*new_value*/, - bool /*is_interactive*/, gpointer data) -{ - Inkscape::UI::Widget::StyleSwatch *ss = (Inkscape::UI::Widget::StyleSwatch *) data; - - if (!strcmp (name, "style")) { // FIXME: watching only for the style attr, no CSS attrs - SPCSSAttr *css = sp_repr_css_attr_inherited(repr, "style"); - ss->setStyle (css); - } -} - +namespace Inkscape { +namespace UI { +namespace Widget { -static Inkscape::XML::NodeEventVector style_swatch_repr_events = -{ - NULL, /* child_added */ - NULL, /* child_removed */ - style_swatch_attr_changed, - NULL, /* content_changed */ - NULL /* order_changed */ +/** + * @brief Watches whether the tool uses the current style + */ +class StyleSwatch::ToolObserver : public Inkscape::Preferences::Observer { +public: + ToolObserver(Glib::ustring const &path, StyleSwatch &ss) : + Observer(path), + _style_swatch(ss) + {} + virtual void notify(Inkscape::Preferences::Entry const &val); +private: + StyleSwatch &_style_swatch; }; +/** + * @brief Watches for changes in the observed style pref + */ +class StyleSwatch::StyleObserver : public Inkscape::Preferences::Observer { +public: + StyleObserver(Glib::ustring const &path, StyleSwatch &ss) : + Observer(path), + _style_swatch(ss) + { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + this->notify(prefs->getEntry(path)); + } + virtual void notify(Inkscape::Preferences::Entry const &val) { + SPCSSAttr *css = val.getInheritedStyle(); + _style_swatch.setStyle(css); + sp_repr_css_attr_unref(css); + } +private: + StyleSwatch &_style_swatch; +}; -static void style_swatch_tool_attr_changed( Inkscape::XML::Node */*repr*/, gchar const *name, - gchar const */*old_value*/, gchar const *new_value, - bool /*is_interactive*/, gpointer data) +void StyleSwatch::ToolObserver::notify(Inkscape::Preferences::Entry const &val) { - Inkscape::UI::Widget::StyleSwatch *ss = (Inkscape::UI::Widget::StyleSwatch *) data; + bool usecurrent = val.getBool(); - if (!strcmp (name, "usecurrent")) { // FIXME: watching only for the style attr, no CSS attrs - if (!strcmp (new_value, "1")) { - ss->setWatched (inkscape_get_repr(INKSCAPE, "desktop"), inkscape_get_repr(INKSCAPE, ss->_tool_path)); - } else { - ss->setWatched (inkscape_get_repr(INKSCAPE, ss->_tool_path), NULL); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + if (_style_swatch._style_obs) delete _style_swatch._style_obs; + + if (usecurrent) { + _style_swatch._style_obs = new StyleObserver("/desktop/style", _style_swatch); + + // If desktop's last-set style is empty, a tool uses its own fixed style even if set to use + // last-set (so long as it's empty). To correctly show this, we get the tool's style + // if the desktop's style is empty. + SPCSSAttr *css = prefs->getStyle("/desktop/style"); + if (!css->attributeList()) { + SPCSSAttr *css2 = prefs->getInheritedStyle(_style_swatch._tool_path + "/style"); + _style_swatch.setStyle(css2); + sp_repr_css_attr_unref(css2); } - // UGLY HACK: we have to reconnect to the watched tool repr again, retrieving it from the stored - // tool_path, because the actual repr keeps shifting with each change, no idea why - ss->setWatchedTool(ss->_tool_path, false); + sp_repr_css_attr_unref(css); + } else { + _style_swatch._style_obs = new StyleObserver(_style_swatch._tool_path + "/style", _style_swatch); } + prefs->addObserver(*_style_swatch._style_obs); } -static Inkscape::XML::NodeEventVector style_swatch_tool_repr_events = -{ - NULL, /* child_added */ - NULL, /* child_removed */ - style_swatch_tool_attr_changed, - NULL, /* content_changed */ - NULL /* order_changed */ -}; - -namespace Inkscape { -namespace UI { -namespace Widget { - StyleSwatch::StyleSwatch(SPCSSAttr *css, gchar const *main_tip) : - _tool_path(NULL), - _desktop(0), - _verb_t(0), - _css (NULL), - - _watched(NULL), - _watched_tool(NULL), - + _desktop(NULL), + _verb_t(NULL), + _css(NULL), + _tool_obs(NULL), + _style_obs(NULL), _table(2, 6), - _sw_unit(NULL), - _tooltips () { _label[SS_FILL].set_markup(_("Fill:")); @@ -185,72 +192,33 @@ StyleSwatch::~StyleSwatch() delete _color_preview[i]; } - if (_watched) { - sp_repr_remove_listener_by_data(_watched, this); - Inkscape::GC::release(_watched); - _watched = NULL; - } - - if (_watched_tool) { - sp_repr_remove_listener_by_data(_watched_tool, this); - Inkscape::GC::release(_watched_tool); - _watched_tool = NULL; - _tool_path = NULL; - } -} - -void -StyleSwatch::setWatched(Inkscape::XML::Node *watched, Inkscape::XML::Node *secondary) -{ - if (_watched) { - sp_repr_remove_listener_by_data(_watched, this); - Inkscape::GC::release(_watched); - _watched = NULL; - } - - if (watched) { - _watched = watched; - Inkscape::GC::anchor(_watched); - sp_repr_add_listener(_watched, &style_swatch_repr_events, this); - sp_repr_synthesize_events(_watched, &style_swatch_repr_events, this); - - // If desktop's last-set style is empty, a tool uses its own fixed style even if set to use - // last-set (so long as it's empty). To correctly show this, we're passed the second repr, - // that of the tool prefs node, from which we now setStyle if the watched repr's style is - // empty. - if (secondary) { - SPCSSAttr *css = sp_repr_css_attr_inherited(watched, "style"); - if (!css->attributeList()) { // is css empty? - SPCSSAttr *css_secondary = sp_repr_css_attr_inherited(secondary, "style"); - this->setStyle (css_secondary); - } - } - } + if (_style_obs) delete _style_obs; + if (_tool_obs) delete _tool_obs; } void StyleSwatch::setWatchedTool(const char *path, bool synthesize) { - if (_watched_tool) { - sp_repr_remove_listener_by_data(_watched_tool, this); - Inkscape::GC::release(_watched_tool); - _watched_tool = NULL; - _tool_path = NULL; + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + + if (_tool_obs) { + delete _tool_obs; + _tool_obs = NULL; } if (path) { - _tool_path = (char *) path; - Inkscape::XML::Node *watched_tool = inkscape_get_repr(INKSCAPE, path); - if (watched_tool) { - _watched_tool = watched_tool; - Inkscape::GC::anchor(_watched_tool); - sp_repr_add_listener(_watched_tool, &style_swatch_tool_repr_events, this); - if (synthesize) { - sp_repr_synthesize_events(_watched_tool, &style_swatch_tool_repr_events, this); - } - } + _tool_path = path; + _tool_obs = new ToolObserver(_tool_path + "/usecurrent", *this); + prefs->addObserver(*_tool_obs); + } else { + _tool_path = ""; + } + + // hack until there is a real synthesize events function for prefs, + // which shouldn't be hard to write once there is sufficient need for it + if (synthesize && _tool_obs) { + _tool_obs->notify(prefs->getEntry(_tool_path + "/usecurrent")); } - } diff --git a/src/ui/widget/style-swatch.h b/src/ui/widget/style-swatch.h index 5efd561f3..dfbbe13d3 100644 --- a/src/ui/widget/style-swatch.h +++ b/src/ui/widget/style-swatch.h @@ -1,10 +1,11 @@ -/** - * \brief Static style swatch (fill, stroke, opacity) - * - * Author: +/** @file + * @brief Static style swatch (fill, stroke, opacity) + */ +/* Authors: * buliabyak@gmail.com + * Krzysztof Kosiński <tweenk.pl@gmail.com> * - * Copyright (C) 2005 author + * Copyright (C) 2005-2008 Authors * * Released under GNU GPL. Read the file 'COPYING' for more information. */ @@ -20,22 +21,16 @@ #include <glibmm/i18n.h> -#include <desktop.h> -#include <verbs.h> - +#include "desktop.h" +#include "verbs.h" #include "button.h" +#include "preferences.h" class SPUnit; class SPStyle; class SPCSSAttr; namespace Inkscape { -namespace XML { -class Node; -} -} - -namespace Inkscape { namespace UI { namespace Widget { @@ -50,40 +45,32 @@ public: void setStyle(SPCSSAttr *attr); SPCSSAttr *getStyle(); - void setWatched (Inkscape::XML::Node *watched, Inkscape::XML::Node *secondary); void setWatchedTool (const char *path, bool synthesize); void setClickVerb(sp_verb_t verb_t); void setDesktop(SPDesktop *desktop); bool on_click(GdkEventButton *event); - char *_tool_path; +private: + class ToolObserver; + class StyleObserver; -protected: SPDesktop *_desktop; - sp_verb_t _verb_t; - SPCSSAttr *_css; - - Inkscape::XML::Node *_watched; - Inkscape::XML::Node *_watched_tool; + ToolObserver *_tool_obs; + StyleObserver *_style_obs; + Glib::ustring _tool_path; Gtk::EventBox _swatch; - Gtk::Table _table; - Gtk::Label _label[2]; - Gtk::EventBox _place[2]; Gtk::EventBox _opacity_place; - Gtk::Label _value[2]; Gtk::Label _opacity_value; - Gtk::Widget *_color_preview[2]; Glib::ustring __color[2]; - Gtk::HBox _stroke; Gtk::EventBox _stroke_width_place; Gtk::Label _stroke_width; @@ -91,6 +78,8 @@ protected: SPUnit *_sw_unit; Gtk::Tooltips _tooltips; + +friend class ToolObserver; }; |
