From 8478a25e1cca8a736fba0f2510a9bce5c02fa574 Mon Sep 17 00:00:00 2001 From: dvlierop2 Date: Wed, 12 Dec 2007 20:34:36 +0000 Subject: [PATCH] Add global snapping toggle --- src/attributes.cpp | 1 + src/attributes.h | 1 + src/snap.cpp | 14 ++++++++++---- src/snap.h | 9 +++++++++ src/sp-namedview.cpp | 7 ++++++- src/ui/dialog/document-properties.cpp | 20 ++++++++++++++++++-- src/ui/dialog/document-properties.h | 2 +- 7 files changed, 46 insertions(+), 8 deletions(-) diff --git a/src/attributes.cpp b/src/attributes.cpp index a23621c10..3777c68a1 100644 --- a/src/attributes.cpp +++ b/src/attributes.cpp @@ -84,6 +84,7 @@ static SPStyleProp const props[] = { {SP_ATTR_INKSCAPE_WINDOW_HEIGHT, "inkscape:window-height"}, {SP_ATTR_INKSCAPE_WINDOW_X, "inkscape:window-x"}, {SP_ATTR_INKSCAPE_WINDOW_Y, "inkscape:window-y"}, + {SP_ATTR_INKSCAPE_SNAP_GLOBAL, "inkscape:snap-global"}, {SP_ATTR_INKSCAPE_SNAP_BBOX, "inkscape:snap-bbox"}, {SP_ATTR_INKSCAPE_SNAP_NODES, "inkscape:snap-nodes"}, {SP_ATTR_INKSCAPE_SNAP_GUIDE, "inkscape:snap-guide"}, diff --git a/src/attributes.h b/src/attributes.h index 4f222bba1..0962827f8 100644 --- a/src/attributes.h +++ b/src/attributes.h @@ -85,6 +85,7 @@ enum SPAttributeEnum { SP_ATTR_INKSCAPE_WINDOW_HEIGHT, SP_ATTR_INKSCAPE_WINDOW_X, SP_ATTR_INKSCAPE_WINDOW_Y, + SP_ATTR_INKSCAPE_SNAP_GLOBAL, SP_ATTR_INKSCAPE_SNAP_BBOX, SP_ATTR_INKSCAPE_SNAP_NODES, SP_ATTR_INKSCAPE_SNAP_GUIDE, diff --git a/src/snap.cpp b/src/snap.cpp index 1ff5d3d05..9faa4fae6 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -44,9 +44,9 @@ SnapManager::SnapManager(SPNamedView const *v) : guide(v, 0), object(v, 0), _named_view(v), - _include_item_center(false) -{ - + _include_item_center(false), + _snap_enabled_globally(true) +{ } @@ -92,6 +92,10 @@ SnapManager::getGridSnappers() const bool SnapManager::SomeSnapperMightSnap() const { + if (!_snap_enabled_globally) { + return false; + } + SnapperList const s = getSnappers(); SnapperList::const_iterator i = s.begin(); while (i != s.end() && (*i)->ThisSnapperMightSnap() == false) { @@ -327,7 +331,9 @@ std::pair SnapManager::_snapTransformed( ** appropriate transformation with `true'; otherwise we return the original scale with `false'. */ - /* Quick check to see if we have any snappers that are enabled */ + /* Quick check to see if we have any snappers that are enabled + ** Also used to globally disable all snapping + */ if (SomeSnapperMightSnap() == false) { return std::make_pair(transformation, false); } diff --git a/src/snap.h b/src/snap.h index 9547064a9..1f2b85974 100644 --- a/src/snap.h +++ b/src/snap.h @@ -140,6 +140,14 @@ public: bool getIncludeItemCenter() const { return _include_item_center; } + + void setSnapEnabledGlobally(bool enabled) { + _snap_enabled_globally = enabled; + } + + bool getSnapEnabledGlobally() const { + return _snap_enabled_globally; + } protected: SPNamedView const *_named_view; @@ -156,6 +164,7 @@ private: bool _include_item_center; //If true, snapping nodes will also snap the item's center bool _intersectionGG; bool _intersectionLS; + bool _snap_enabled_globally; //Toggles ALL snapping std::pair _snapTransformed(Inkscape::Snapper::PointType type, std::vector const &points, diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp index 86da7a93a..7705a21ec 100644 --- a/src/sp-namedview.cpp +++ b/src/sp-namedview.cpp @@ -154,7 +154,8 @@ static void sp_namedview_build(SPObject *object, SPDocument *document, Inkscape: sp_object_read_attr(object, "inkscape:window-height"); sp_object_read_attr(object, "inkscape:window-x"); sp_object_read_attr(object, "inkscape:window-y"); - sp_object_read_attr(object, "inkscape:snap-bbox"); + sp_object_read_attr(object, "inkscape:snap-global"); + sp_object_read_attr(object, "inkscape:snap-bbox"); sp_object_read_attr(object, "inkscape:snap-nodes"); sp_object_read_attr(object, "inkscape:snap-guide"); sp_object_read_attr(object, "inkscape:snap-center"); @@ -357,6 +358,10 @@ static void sp_namedview_set(SPObject *object, unsigned int key, const gchar *va nv->window_y = value ? atoi(value) : -1; // -1 means not set object->requestModified(SP_OBJECT_MODIFIED_FLAG); break; + case SP_ATTR_INKSCAPE_SNAP_GLOBAL: + nv->snap_manager.setSnapEnabledGlobally(value ? sp_str_to_bool(value) : TRUE); + object->requestModified(SP_OBJECT_MODIFIED_FLAG); + break; case SP_ATTR_INKSCAPE_SNAP_BBOX: nv->snap_manager.setSnapModeBBox(value ? sp_str_to_bool(value) : FALSE); object->requestModified(SP_OBJECT_MODIFIED_FLAG); diff --git a/src/ui/dialog/document-properties.cpp b/src/ui/dialog/document-properties.cpp index 03a9c7dc8..4fc01cc8f 100644 --- a/src/ui/dialog/document-properties.cpp +++ b/src/ui/dialog/document-properties.cpp @@ -254,6 +254,9 @@ DocumentProperties::build_snap() { _page_snap.show(); //General options + _rcbsg.init (_("Enable snapping"), + _("When disabled, nothing will snap"), + "inkscape:snap-global", _wr); _rcbsnbb.init (_("_Bounding box corners"), _("Snap bounding box corners to grid lines, to guides, and to other bounding boxes (Snapping of bounding boxes is only available in the selector tool)"), "inkscape:snap-bbox", _wr); @@ -303,9 +306,17 @@ DocumentProperties::build_snap() slaves.push_back(_rcbsnbbp._button); slaves.push_back(_rcbsnbbn._button); _rcbsnbb.setSlaveButton(slaves); + + slaves.clear(); + slaves.push_back(_rcbsnn._button); + slaves.push_back(_rcbsnbb._button); + + _rcbsg.setSlaveButton(slaves); Gtk::Label *label_g = manage (new Gtk::Label); - label_g->set_markup (_("What snaps")); + label_g->set_markup (_("Global snapping toggle")); + Gtk::Label *label_w = manage (new Gtk::Label); + label_w->set_markup (_("What snaps")); Gtk::Label *label_o = manage (new Gtk::Label); label_o->set_markup (_("Snap to objects")); Gtk::Label *label_gr = manage (new Gtk::Label); @@ -315,7 +326,10 @@ DocumentProperties::build_snap() Gtk::Widget *const array[] = { - label_g, 0, + label_g, 0, + 0, _rcbsg._button, + 0, 0, + label_w, 0, 0, _rcbsnn._button, 0, _rcbsnbb._button, 0, 0, @@ -494,6 +508,8 @@ DocumentProperties::update() _rsu_sn.setValue (nv->gridtolerance); _rsu_gusn.setValue (nv->guidetolerance); + + _rcbsg.setActive (nv->snap_manager.getSnapEnabledGlobally()); //-----------------------------------------------------------grids page diff --git a/src/ui/dialog/document-properties.h b/src/ui/dialog/document-properties.h index a6fe48ffa..b4076fbe7 100644 --- a/src/ui/dialog/document-properties.h +++ b/src/ui/dialog/document-properties.h @@ -77,7 +77,7 @@ protected: RegisteredUnitMenu _rum_gusn; RegisteredColorPicker _rcp_gui, _rcp_hgui; //--------------------------------------------------------------- - RegisteredCheckButton _rcbsnbb, _rcbsnn, _rcbsnop; + RegisteredCheckButton _rcbsg, _rcbsnbb, _rcbsnn, _rcbsnop; RegisteredCheckButton _rcbsnon, _rcbsnbbp, _rcbsnbbn; RegisteredUnitMenu _rumso; ToleranceSlider _rsu_sno, _rsu_sn, _rsu_gusn; -- 2.30.2