Code

Add default grid settings to Inkscape preferences.
authorjohanengelen <johanengelen@users.sourceforge.net>
Fri, 14 Dec 2007 18:46:47 +0000 (18:46 +0000)
committerjohanengelen <johanengelen@users.sourceforge.net>
Fri, 14 Dec 2007 18:46:47 +0000 (18:46 +0000)
src/display/canvas-axonomgrid.cpp
src/display/canvas-grid.cpp
src/preferences-skeleton.h
src/ui/dialog/inkscape-preferences.cpp
src/ui/dialog/inkscape-preferences.h
src/ui/widget/color-picker.h
src/ui/widget/preferences-widget.cpp
src/ui/widget/preferences-widget.h

index b4d27084afa4c8c4100c8cff21ef84217e2331d8..79b83079183468a0616fd37a828975f61f20a327 100644 (file)
 #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]);
index d4a78f265ca95e5c88c0d33a68afa798afd20995..da16bb85ee0053c13b07421597477b9c3b61e094 100644 (file)
 #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);
 
index d7381974615d08f83f56dcd3ef1abb1642f8024d..cd504fa17b20503c8eef14866e2f51d6a6333a1f 100644 (file)
@@ -245,6 +245,29 @@ static char const preferences_skeleton[] =
 "           masks=\"65535\"/>\n" // 0x0000ffff
 "    <group id=\"svgoutput\" usenamedcolors=\"0\" numericprecision=\"8\" minimumexponent=\"-8\" inlineattrs=\"0\" indent=\"2\"/>\n"
 "    <group id=\"forkgradientvectors\" value=\"1\"/>\n"
+"    <group id=\"grids\">"
+"      <group id=\"xy\" "
+"             units=\"px\"\n"
+"             origin_x=\"0.0\"\n"
+"             origin_y=\"0.0\"\n"
+"             spacing_x=\"1.0\"\n"
+"             spacing_y=\"1.0\"\n"
+"             color=\"65312\"\n"  // 0x0000FF20
+"             empcolor=\"65344\"\n" // 0x0000FF40
+"             empspacing=\"5\"\n"
+"             dotted=\"0\"/>\n"
+"      <group id=\"axonom\" "
+"             units=\"mm\"\n"
+"             origin_x=\"0.0\"\n"
+"             origin_y=\"0.0\"\n"
+"             spacing_y=\"1.0\"\n"
+"             angle_x=\"30.0\"\n"
+"             angle_z=\"30.0\"\n"
+"             color=\"65312\"\n"  // 0x0000FF20
+"             empcolor=\"65344\"\n" // 0x0000FF40
+"             empspacing=\"5\"\n"
+"             dotted=\"0\"/>\n"
+"    </group>\n"
 "  </group>\n"
 "\n"
 "  <group id=\"extensions\">"
index 4fd4678967950196626900801405a44617c2be0a..f7a6072fd0cb8838cf5177cbd9ee568fc15c844e 100644 (file)
@@ -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);
index 0fe9a9bcc6cb54bb3e48df0907966e0f27ae0fb7..7cca51dd2da4e5991b63a2e3b576e5b942184936 100644 (file)
@@ -25,6 +25,7 @@
 #include <gtkmm/treeview.h>
 #include <gtkmm/radiobutton.h>
 #include <gtkmm/frame.h>
+#include <gtkmm/notebook.h>
 #include "ui/widget/preferences-widget.h"
 #include <sigc++/sigc++.h>
 #include <glibmm/i18n.h>
@@ -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();
index 0349c75e5452be1b3ac1a98a247151676fb15789..9ac38b84bf75be514e424d6c92b0061351026833 100644 (file)
@@ -58,7 +58,7 @@ protected:
     ColorPreview        _preview;
     Gtk::Tooltips       _tt;
 
-    const Glib::ustring _title;
+    /*const*/ Glib::ustring _title;
     sigc::signal<void,guint32> _changed_signal;
     guint32             _rgba;
     bool                _undo;
index 243fe029dfa4137e31debf5b8df99f9b68ca6932..29f86745e59ed57d40dca4fc66203ef8b421548e 100644 (file)
@@ -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
index 72f010f13e8a48d893b8da07ae6e5c96f8f2de25..f754cde1b1c491c3181d8595a5fc3f4d6679ebeb 100644 (file)
@@ -27,6 +27,8 @@
 #include <sigc++/sigc++.h>
 //#include <glibmm/i18n.h>
 
+#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: