Code

Add global snapping toggle
authordvlierop2 <dvlierop2@users.sourceforge.net>
Wed, 12 Dec 2007 20:34:36 +0000 (20:34 +0000)
committerdvlierop2 <dvlierop2@users.sourceforge.net>
Wed, 12 Dec 2007 20:34:36 +0000 (20:34 +0000)
src/attributes.cpp
src/attributes.h
src/snap.cpp
src/snap.h
src/sp-namedview.cpp
src/ui/dialog/document-properties.cpp
src/ui/dialog/document-properties.h

index a23621c1037de087874aa9d3f9239d21d2b2c8dc..3777c68a1b2d67e92cb7024f527b756c39df8c9a 100644 (file)
@@ -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"},
index 4f222bba117829f915fdacbb1aa8ed1b8b453c82..0962827f8dacbf0e6fb4ec1f4fc82add8f398f25 100644 (file)
@@ -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,
index 1ff5d3d059b5d5f69aa693955148a958c778ccfb..9faa4fae6f22fcd4b7ba67fe89cad42444b1f8f5 100644 (file)
@@ -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<NR::Point, bool> 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);
     }
index 9547064a9663e931a48e1a92b1e982b5f4a3329b..1f2b85974fe237a028d9160203e2959bb95bf68a 100644 (file)
@@ -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<NR::Point, bool> _snapTransformed(Inkscape::Snapper::PointType type,
                                                 std::vector<NR::Point> const &points,
index 86da7a93a40f5634bc83fceca8d909ca99ec56ec..7705a21ec9b3098bb4bd14d5d955eecfbfeee99d 100644 (file)
@@ -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);
index 03a9c7dc8af22f039fa0c6eb8cbe227c0f4cb096..4fc01cc8f7482cd22cfdc7fdce8fd41af8e802c6 100644 (file)
@@ -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 (_("<b>What snaps</b>"));
+    label_g->set_markup (_("<b>Global snapping toggle</b>"));
+    Gtk::Label *label_w = manage (new Gtk::Label);
+    label_w->set_markup (_("<b>What snaps</b>"));    
     Gtk::Label *label_o = manage (new Gtk::Label);
     label_o->set_markup (_("<b>Snap to objects</b>"));
     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
 
index a6fe48ffa0ea475f22b0a64b4c160f7ef5cf2041..b4076fbe743d094bf32fc80feb49b3e82ba45ff2 100644 (file)
@@ -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;