From: johanengelen Date: Sun, 16 Dec 2007 18:09:15 +0000 (+0000) Subject: add default unit to grid preferences. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=1f8c5954acb3f152aeb1411b098ebc5fed99e6b0;p=inkscape.git add default unit to grid preferences. --- diff --git a/src/display/canvas-axonomgrid.cpp b/src/display/canvas-axonomgrid.cpp index 79b830791..febab42e4 100644 --- a/src/display/canvas-axonomgrid.cpp +++ b/src/display/canvas-axonomgrid.cpp @@ -200,7 +200,7 @@ CanvasAxonomGrid::CanvasAxonomGrid (SPNamedView * nv, Inkscape::XML::Node * in_r color = prefs_get_int_attribute("options.grids.axonom", "color", 0x0000ff20); empcolor = prefs_get_int_attribute("options.grids.axonom", "empcolor", 0x0000ff40); empspacing = prefs_get_int_attribute("options.grids.axonom", "empspacing", 5); - gridunit = &sp_unit_get_by_id(SP_UNIT_MM); + gridunit = sp_unit_get_by_abbreviation( prefs_get_string_attribute("options.grids.axonom", "units") ); lengthy = prefs_get_double_attribute ("options.grids.axonom", "spacing_y", 1.0); angle_deg[X] = prefs_get_double_attribute ("options.grids.axonom", "angle_x", 30.0); angle_deg[Z] = prefs_get_double_attribute ("options.grids.axonom", "angle_z", 30.0); @@ -218,13 +218,23 @@ CanvasAxonomGrid::CanvasAxonomGrid (SPNamedView * nv, Inkscape::XML::Node * in_r table.set_spacings(2); vbox.pack_start(table, false, false, 0); + Inkscape::UI::Widget::ScalarUnit * sutemp; _rumg.init (_("Grid _units:"), "units", _wr, repr, doc); _rsu_ox.init (_("_Origin X:"), _("X coordinate of grid origin"), "originx", _rumg, _wr, repr, doc); + sutemp = _rsu_ox.getSU(); + sutemp->setDigits(4); + sutemp->setIncrements(0.1, 1.0); _rsu_oy.init (_("O_rigin Y:"), _("Y coordinate of grid origin"), "originy", _rumg, _wr, repr, doc); + sutemp = _rsu_oy.getSU(); + sutemp->setDigits(4); + sutemp->setIncrements(0.1, 1.0); _rsu_sy.init (_("Spacing _Y:"), _("Base length of z-axis"), "spacingy", _rumg, _wr, repr, doc); + sutemp = _rsu_sy.getSU(); + sutemp->setDigits(4); + sutemp->setIncrements(0.1, 1.0); _rsu_ax.init (_("Angle X:"), _("Angle of x-axis"), "gridanglex", _rumg, _wr, repr, doc); _rsu_az.init (_("Angle Z:"), _("Angle of z-axis"), diff --git a/src/display/canvas-grid.cpp b/src/display/canvas-grid.cpp index da16bb85e..7d9d009f0 100644 --- a/src/display/canvas-grid.cpp +++ b/src/display/canvas-grid.cpp @@ -398,7 +398,7 @@ CanvasXYGrid::CanvasXYGrid (SPNamedView * nv, Inkscape::XML::Node * in_repr, SPD empspacing = prefs_get_int_attribute("options.grids.xy", "empspacing", 5); spacing[NR::X] = prefs_get_double_attribute ("options.grids.xy", "spacing_x", 0.0); spacing[NR::Y] = prefs_get_double_attribute ("options.grids.xy", "spacing_y", 0.0); - gridunit = &sp_unit_get_by_id(SP_UNIT_PX); + gridunit = sp_unit_get_by_abbreviation( prefs_get_string_attribute("options.grids.xy", "units") ); render_dotted = prefs_get_int_attribute ("options.grids.xy", "dotted", 0) == 1; snapper = new CanvasXYGridSnapper(this, namedview, 0); diff --git a/src/preferences-skeleton.h b/src/preferences-skeleton.h index cd504fa17..b013d52b6 100644 --- a/src/preferences-skeleton.h +++ b/src/preferences-skeleton.h @@ -265,8 +265,7 @@ static char const preferences_skeleton[] = " angle_z=\"30.0\"\n" " color=\"65312\"\n" // 0x0000FF20 " empcolor=\"65344\"\n" // 0x0000FF40 -" empspacing=\"5\"\n" -" dotted=\"0\"/>\n" +" empspacing=\"5\"/>\n" " \n" " \n" "\n" diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp index f7a6072fd..dfbfdcf58 100644 --- a/src/ui/dialog/inkscape-preferences.cpp +++ b/src/ui/dialog/inkscape-preferences.cpp @@ -796,7 +796,8 @@ void InkscapePreferences::initPageGrids() _page_grids.add_line( false, "", _grids_notebook, "", "", false); _grids_notebook.append_page(_grids_xy, CanvasGrid::getName( GRID_RECTANGULAR )); _grids_notebook.append_page(_grids_axonom, CanvasGrid::getName( GRID_AXONOMETRIC )); - //_grids_xy.add_line( false, _("Grid units"), _grids_xy_units, "", "", false); + _grids_xy_units.init("options.grids.xy", "units"); + _grids_xy.add_line( false, _("Grid units"), _grids_xy_units, "", "", false); _grids_xy_origin_x.init("options.grids.xy", "origin_x", -10000.0, 10000.0, 0.1, 1.0, 0.0, false, false); _grids_xy_origin_y.init("options.grids.xy", "origin_y", -10000.0, 10000.0, 0.1, 1.0, 0.0, false, false); _grids_xy.add_line( false, _("Origin X"), _grids_xy_origin_x, "", _("X coordinate of grid origin"), false); @@ -816,7 +817,8 @@ void InkscapePreferences::initPageGrids() _grids_xy.add_line( false, "", _grids_xy_dotted, "", _("If set, displays dots at gridpoints instead of gridlines"), false); // CanvasAxonomGrid properties: - //_grids_axonom.add_line( false, _("Grid units"), _grids_axonom_units, "", "", false); + _grids_axonom_units.init("options.grids.axonom", "units"); + _grids_axonom.add_line( false, _("Grid units"), _grids_axonom_units, "", "", false); _grids_axonom_origin_x.init("options.grids.axonom", "origin_x", -10000.0, 10000.0, 0.1, 1.0, 0.0, false, false); _grids_axonom_origin_y.init("options.grids.axonom", "origin_y", -10000.0, 10000.0, 0.1, 1.0, 0.0, false, false); _grids_axonom.add_line( false, _("Origin X"), _grids_axonom_origin_x, "", _("X coordinate of grid origin"), false); diff --git a/src/ui/dialog/inkscape-preferences.h b/src/ui/dialog/inkscape-preferences.h index 7cca51dd2..4b62f3947 100644 --- a/src/ui/dialog/inkscape-preferences.h +++ b/src/ui/dialog/inkscape-preferences.h @@ -179,7 +179,7 @@ protected: Gtk::Notebook _grids_notebook; DialogPage _grids_xy, _grids_axonom; // CanvasXYGrid properties: - //_grids_xy_units; + PrefUnit _grids_xy_units; PrefSpinButton _grids_xy_origin_x; PrefSpinButton _grids_xy_origin_y; PrefSpinButton _grids_xy_spacing_x; @@ -189,7 +189,7 @@ protected: PrefSpinButton _grids_xy_empspacing; PrefCheckButton _grids_xy_dotted; // CanvasAxonomGrid properties: - //_grids_axonom_units; + PrefUnit _grids_axonom_units; PrefSpinButton _grids_axonom_origin_x; PrefSpinButton _grids_axonom_origin_y; PrefSpinButton _grids_axonom_spacing_y; diff --git a/src/ui/widget/preferences-widget.cpp b/src/ui/widget/preferences-widget.cpp index 29f86745e..7b94512cf 100644 --- a/src/ui/widget/preferences-widget.cpp +++ b/src/ui/widget/preferences-widget.cpp @@ -356,6 +356,23 @@ void PrefColorPicker::on_changed (guint32 rgba) } } +void PrefUnit::init(const std::string& prefs_path, const std::string& attr) +{ + _prefs_path = prefs_path; + _attr = attr; + setUnitType(UNIT_TYPE_LINEAR); + gchar const * prefval = prefs_get_string_attribute(_prefs_path.c_str(), _attr.c_str()); + setUnit(prefval); +} + +void PrefUnit::on_changed() +{ + if (this->is_visible()) //only take action if user changed value + { + prefs_set_string_attribute(_prefs_path.c_str(), _attr.c_str(), getUnitAbbr().c_str()); + } +} + } // namespace Widget } // namespace UI } // namespace Inkscape diff --git a/src/ui/widget/preferences-widget.h b/src/ui/widget/preferences-widget.h index f754cde1b..2df0b9937 100644 --- a/src/ui/widget/preferences-widget.h +++ b/src/ui/widget/preferences-widget.h @@ -28,6 +28,7 @@ //#include #include "ui/widget/color-picker.h" +#include "ui/widget/unit-menu.h" namespace Inkscape { namespace UI { @@ -145,6 +146,15 @@ protected: virtual void on_changed (guint32 rgba); }; +class PrefUnit : public UnitMenu +{ +public: + void init(const std::string& prefs_path, const std::string& attr); +protected: + std::string _prefs_path; + std::string _attr; + void on_changed(); +}; class DialogPage : public Gtk::Table {