From 707e434808fb1cacc3c7b7ecb37683e9c0d8ddd8 Mon Sep 17 00:00:00 2001 From: johanengelen Date: Fri, 14 Dec 2007 18:46:47 +0000 Subject: [PATCH] Add default grid settings to Inkscape preferences. --- src/display/canvas-axonomgrid.cpp | 18 +++++----- src/display/canvas-grid.cpp | 18 +++++----- src/preferences-skeleton.h | 23 ++++++++++++ src/ui/dialog/inkscape-preferences.cpp | 50 ++++++++++++++++++++++++++ src/ui/dialog/inkscape-preferences.h | 28 ++++++++++++++- src/ui/widget/color-picker.h | 2 +- src/ui/widget/preferences-widget.cpp | 17 +++++++++ src/ui/widget/preferences-widget.h | 18 ++++++++++ 8 files changed, 154 insertions(+), 20 deletions(-) diff --git a/src/display/canvas-axonomgrid.cpp b/src/display/canvas-axonomgrid.cpp index b4d27084a..79b830791 100644 --- a/src/display/canvas-axonomgrid.cpp +++ b/src/display/canvas-axonomgrid.cpp @@ -38,12 +38,10 @@ #include "desktop.h" #include "document.h" +#include "prefs-utils.h" #define SAFE_SETPIXEL //undefine this when it is certain that setpixel is never called with invalid params -#define DEFAULTGRIDCOLOR 0x0000FF20 -#define DEFAULTGRIDEMPCOLOR 0x0000FF50 - enum Dim3 { X=0, Y, Z }; #ifndef M_PI @@ -197,14 +195,16 @@ attach_all(Gtk::Table &table, Gtk::Widget const *const arr[], unsigned size, int CanvasAxonomGrid::CanvasAxonomGrid (SPNamedView * nv, Inkscape::XML::Node * in_repr, SPDocument * in_doc) : CanvasGrid(nv, in_repr, in_doc, GRID_AXONOMETRIC), table(1, 1) { - origin[NR::X] = origin[NR::Y] = 0.0; - color = DEFAULTGRIDCOLOR; - empcolor = DEFAULTGRIDEMPCOLOR; - empspacing = 5; + origin[NR::X] = prefs_get_double_attribute ("options.grids.axonom", "origin_x", 0.0); + origin[NR::Y] = prefs_get_double_attribute ("options.grids.axonom", "origin_y", 0.0); + 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); - angle_deg[X] = angle_deg[Z] = 30; + 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); angle_deg[Y] =0; - lengthy = sp_units_get_pixels(1.0, *(gridunit)); angle_rad[X] = deg_to_rad(angle_deg[X]); tan_angle[X] = tan(angle_rad[X]); diff --git a/src/display/canvas-grid.cpp b/src/display/canvas-grid.cpp index d4a78f265..da16bb85e 100644 --- a/src/display/canvas-grid.cpp +++ b/src/display/canvas-grid.cpp @@ -29,15 +29,13 @@ #include "desktop.h" #include "../document.h" +#include "prefs-utils.h" #include "canvas-grid.h" #include "canvas-axonomgrid.h" namespace Inkscape { -#define DEFAULTGRIDCOLOR 0x0000FF20 -#define DEFAULTGRIDEMPCOLOR 0x0000FF40 - static gchar const *const grid_name[] = { N_("Rectangular grid"), N_("Axonometric grid") @@ -393,13 +391,15 @@ attach_all(Gtk::Table &table, Gtk::Widget const *const arr[], unsigned size, int CanvasXYGrid::CanvasXYGrid (SPNamedView * nv, Inkscape::XML::Node * in_repr, SPDocument * in_doc) : CanvasGrid(nv, in_repr, in_doc, GRID_RECTANGULAR), table(1, 1) { - origin[NR::X] = origin[NR::Y] = 0.0; - color = DEFAULTGRIDCOLOR; - empcolor = DEFAULTGRIDEMPCOLOR; - empspacing = 5; - spacing[NR::X] = spacing[NR::Y] = 1.0; + origin[NR::X] = prefs_get_double_attribute ("options.grids.xy", "origin_x", 0.0); + origin[NR::Y] = prefs_get_double_attribute ("options.grids.xy", "origin_y", 0.0); + color = prefs_get_int_attribute("options.grids.xy", "color", 0x0000ff20); + empcolor = prefs_get_int_attribute("options.grids.xy", "empcolor", 0x0000ff40); + 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); - render_dotted = false; + 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 d73819746..cd504fa17 100644 --- a/src/preferences-skeleton.h +++ b/src/preferences-skeleton.h @@ -245,6 +245,29 @@ static char const preferences_skeleton[] = " masks=\"65535\"/>\n" // 0x0000ffff " \n" " \n" +" " +" \n" +" \n" +" \n" " \n" "\n" " " diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp index 4fd467896..f7a6072fd 100644 --- a/src/ui/dialog/inkscape-preferences.cpp +++ b/src/ui/dialog/inkscape-preferences.cpp @@ -38,6 +38,7 @@ #include "ui/widget/style-swatch.h" #include "display/nr-filter-gaussian.h" #include "color-profile-fns.h" +#include "display/canvas-grid.h" namespace Inkscape { namespace UI { @@ -104,6 +105,7 @@ InkscapePreferences::InkscapePreferences() initPageSelecting(); initPageImportExport(); initPageCMS(); + initPageGrids(); initPageMisc(); signalPresent().connect(sigc::mem_fun(*this, &InkscapePreferences::_presentPages)); @@ -787,6 +789,54 @@ void InkscapePreferences::initPageCMS() this->AddPage(_page_cms, _("Color Management"), PREFS_PAGE_CMS); } +void InkscapePreferences::initPageGrids() +{ + _page_grids.add_group_header( _("Default grid settings")); + + _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_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); + _grids_xy.add_line( false, _("Origin Y"), _grids_xy_origin_y, "", _("Y coordinate of grid origin"), false); + _grids_xy_spacing_x.init("options.grids.xy", "spacing_x", -10000.0, 10000.0, 0.1, 1.0, 1.0, false, false); + _grids_xy_spacing_y.init("options.grids.xy", "spacing_y", -10000.0, 10000.0, 0.1, 1.0, 1.0, false, false); + _grids_xy.add_line( false, _("Spacing X"), _grids_xy_spacing_x, "", _("Distance between vertical grid lines"), false); + _grids_xy.add_line( false, _("Spacing Y"), _grids_xy_spacing_y, "", _("Distance between horizontal grid lines"), false); + + _grids_xy_color.init(_("Grid line color"), "options.grids.xy", "color", 0x0000ff20); + _grids_xy.add_line( false, _("Grid line color"), _grids_xy_color, "", _("Selects the color used for normal grid lines."), false); + _grids_xy_empcolor.init(_("Major grid line color"), "options.grids.xy", "empcolor", 0x0000ff40); + _grids_xy.add_line( false, _("Major grid line color"), _grids_xy_empcolor, "", _("Selects the color used for major (highlighted) grid lines."), false); + _grids_xy_empspacing.init("options.grids.xy", "empspacing", 1.0, 1000.0, 1.0, 5.0, 5.0, true, false); + _grids_xy.add_line( false, _("Major grid line every"), _grids_xy_empspacing, "", "", false); + _grids_xy_dotted.init( _("Show dots instead of lines"), "options.grids.xy", "dotted", false); + _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_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); + _grids_axonom.add_line( false, _("Origin Y"), _grids_axonom_origin_y, "", _("Y coordinate of grid origin"), false); + _grids_axonom_spacing_y.init("options.grids.axonom", "spacing_y", -10000.0, 10000.0, 0.1, 1.0, 1.0, false, false); + _grids_axonom.add_line( false, _("Spacing Y"), _grids_axonom_spacing_y, "", _("Base length of z-axis"), false); + _grids_axonom_angle_x.init("options.grids.axonom", "angle_x", -360.0, 360.0, 1.0, 10.0, 30.0, false, false); + _grids_axonom_angle_z.init("options.grids.axonom", "angle_z", -360.0, 360.0, 1.0, 10.0, 30.0, false, false); + _grids_axonom.add_line( false, _("Angle X"), _grids_axonom_angle_x, "", _("Angle of x-axis"), false); + _grids_axonom.add_line( false, _("Angle Z"), _grids_axonom_angle_z, "", _("Angle of z-axis"), false); + _grids_axonom_color.init(_("Grid line color"), "options.grids.axonom", "color", 0x0000ff20); + _grids_axonom.add_line( false, _("Grid line color"), _grids_axonom_color, "", _("Selects the color used for normal grid lines."), false); + _grids_axonom_empcolor.init(_("Major grid line color"), "options.grids.axonom", "empcolor", 0x0000ff40); + _grids_axonom.add_line( false, _("Major grid line color"), _grids_axonom_empcolor, "", _("Selects the color used for major (highlighted) grid lines."), false); + _grids_axonom_empspacing.init("options.grids.axonom", "empspacing", 1.0, 1000.0, 1.0, 5.0, 5.0, true, false); + _grids_axonom.add_line( false, _("Major grid line every"), _grids_axonom_empspacing, "", "", false); + + this->AddPage(_page_grids, _("Grids"), PREFS_PAGE_GRIDS); +} + void InkscapePreferences::initPageMisc() { _misc_comment.init( _("Add label comments to printing output"), "printing.debug", "show-label-comments", false); diff --git a/src/ui/dialog/inkscape-preferences.h b/src/ui/dialog/inkscape-preferences.h index 0fe9a9bcc..7cca51dd2 100644 --- a/src/ui/dialog/inkscape-preferences.h +++ b/src/ui/dialog/inkscape-preferences.h @@ -25,6 +25,7 @@ #include #include #include +#include #include "ui/widget/preferences-widget.h" #include #include @@ -65,6 +66,7 @@ enum { PREFS_PAGE_SELECTING, PREFS_PAGE_IMPORTEXPORT, PREFS_PAGE_CMS, + PREFS_PAGE_GRIDS, PREFS_PAGE_MISC }; @@ -103,7 +105,7 @@ protected: DialogPage _page_mouse, _page_scrolling, _page_steps, _page_tools, _page_windows, _page_clones, _page_mask, _page_transforms, _page_filters, _page_select, - _page_importexport, _page_cms, _page_misc; + _page_importexport, _page_cms, _page_grids, _page_misc; DialogPage _page_selector, _page_node, _page_zoom, _page_shapes, _page_pencil, _page_pen, _page_calligraphy, _page_text, _page_gradient, _page_connector, _page_dropper; DialogPage _page_rectangle, _page_3dbox, _page_ellipse, _page_star, _page_spiral, _page_paintbucket; @@ -174,6 +176,29 @@ protected: PrefCheckButton _cms_proof_blackpoint; PrefCheckButton _cms_proof_preserveblack; + Gtk::Notebook _grids_notebook; + DialogPage _grids_xy, _grids_axonom; + // CanvasXYGrid properties: + //_grids_xy_units; + PrefSpinButton _grids_xy_origin_x; + PrefSpinButton _grids_xy_origin_y; + PrefSpinButton _grids_xy_spacing_x; + PrefSpinButton _grids_xy_spacing_y; + PrefColorPicker _grids_xy_color; + PrefColorPicker _grids_xy_empcolor; + PrefSpinButton _grids_xy_empspacing; + PrefCheckButton _grids_xy_dotted; + // CanvasAxonomGrid properties: + //_grids_axonom_units; + PrefSpinButton _grids_axonom_origin_x; + PrefSpinButton _grids_axonom_origin_y; + PrefSpinButton _grids_axonom_spacing_y; + PrefSpinButton _grids_axonom_angle_x; + PrefSpinButton _grids_axonom_angle_z; + PrefColorPicker _grids_axonom_color; + PrefColorPicker _grids_axonom_empcolor; + PrefSpinButton _grids_axonom_empspacing; + PrefEntryButtonHBox _importexport_ocal_url; PrefEntry _importexport_ocal_username; PrefEntry _importexport_ocal_password; @@ -205,6 +230,7 @@ protected: void initPageSelecting(); void initPageImportExport(); void initPageCMS(); + void initPageGrids(); void initPageMisc(); void _presentPages(); diff --git a/src/ui/widget/color-picker.h b/src/ui/widget/color-picker.h index 0349c75e5..9ac38b84b 100644 --- a/src/ui/widget/color-picker.h +++ b/src/ui/widget/color-picker.h @@ -58,7 +58,7 @@ protected: ColorPreview _preview; Gtk::Tooltips _tt; - const Glib::ustring _title; + /*const*/ Glib::ustring _title; sigc::signal _changed_signal; guint32 _rgba; bool _undo; diff --git a/src/ui/widget/preferences-widget.cpp b/src/ui/widget/preferences-widget.cpp index 243fe029d..29f86745e 100644 --- a/src/ui/widget/preferences-widget.cpp +++ b/src/ui/widget/preferences-widget.cpp @@ -339,6 +339,23 @@ void PrefEntry::on_changed() } } +void PrefColorPicker::init(const Glib::ustring& label, const std::string& prefs_path, const std::string& attr, + guint32 default_rgba) +{ + _prefs_path = prefs_path; + _attr = attr; + _title = label; + this->setRgba32( prefs_get_int_attribute (_prefs_path.c_str(), _attr.c_str(), (int)default_rgba) ); +} + +void PrefColorPicker::on_changed (guint32 rgba) +{ + if (this->is_visible()) //only take action if the user toggled it + { + prefs_set_int_attribute (_prefs_path.c_str(), _attr.c_str(), (int) rgba); + } +} + } // namespace Widget } // namespace UI } // namespace Inkscape diff --git a/src/ui/widget/preferences-widget.h b/src/ui/widget/preferences-widget.h index 72f010f13..f754cde1b 100644 --- a/src/ui/widget/preferences-widget.h +++ b/src/ui/widget/preferences-widget.h @@ -27,6 +27,8 @@ #include //#include +#include "ui/widget/color-picker.h" + namespace Inkscape { namespace UI { namespace Widget { @@ -128,6 +130,22 @@ protected: void onFileChanged(); }; +class PrefColorPicker : public ColorPicker +{ +public: + PrefColorPicker() : ColorPicker("", "", 0, false) {}; + virtual ~PrefColorPicker() {}; + + void init(const Glib::ustring& label, const std::string& prefs_path, const std::string& attr, + guint32 default_rgba); + +protected: + std::string _prefs_path; + std::string _attr; + virtual void on_changed (guint32 rgba); +}; + + class DialogPage : public Gtk::Table { public: -- 2.30.2