Code

Merge and cleanup of GSoC C++-ification project.
[inkscape.git] / src / ui / tool / multi-path-manipulator.cpp
index a455567e834ca2378f587ab7c1fc6966115bfd15..ef1c764bbb35c0f35161a42093fa59e2c0c1dad8 100644 (file)
@@ -3,6 +3,7 @@
  */
 /* Authors:
  *   Krzysztof KosiƄski <tweenk.pl@gmail.com>
+ *   Abhishek Sharma
  *
  * Copyright (C) 2009 Authors
  * Released under GNU GPL, read the file 'COPYING' for more information
@@ -220,11 +221,29 @@ void MultiPathManipulator::invertSelectionInSubpaths()
 void MultiPathManipulator::setNodeType(NodeType type)
 {
     if (_selection.empty()) return;
+
+    // When all selected nodes are already cusp, retract their handles
+    bool retract_handles = (type == NODE_CUSP);
+
     for (ControlPointSelection::iterator i = _selection.begin(); i != _selection.end(); ++i) {
         Node *node = dynamic_cast<Node*>(*i);
-        if (node) node->setType(type);
+        if (node) {
+            retract_handles &= (node->type() == NODE_CUSP);
+            node->setType(type);
+        }
+    }
+
+    if (retract_handles) {
+        for (ControlPointSelection::iterator i = _selection.begin(); i != _selection.end(); ++i) {
+            Node *node = dynamic_cast<Node*>(*i);
+            if (node) {
+                node->front()->retract();
+                node->back()->retract();
+            }
+        }
     }
-    _done(_("Change node type"));
+
+    _done(retract_handles ? _("Retract handles") : _("Change node type"));
 }
 
 void MultiPathManipulator::setSegmentType(SegmentType type)
@@ -244,6 +263,12 @@ void MultiPathManipulator::insertNodes()
     _done(_("Add nodes"));
 }
 
+void MultiPathManipulator::duplicateNodes()
+{
+    invokeForAll(&PathManipulator::duplicateNodes);
+    _done(_("Duplicate nodes"));
+}
+
 void MultiPathManipulator::joinNodes()
 {
     invokeForAll(&PathManipulator::hideDragPoint);
@@ -513,6 +538,12 @@ bool MultiPathManipulator::event(GdkEvent *event)
                 return true;
             }
             break;
+        case GDK_d:
+        case GDK_D:
+            if (held_only_shift(event->key)) {
+                duplicateNodes();
+                return true;
+            }
         case GDK_j:
         case GDK_J:
             if (held_only_shift(event->key)) {
@@ -591,6 +622,20 @@ bool MultiPathManipulator::event(GdkEvent *event)
                 return true;
             }
             break;
+        case GDK_l:
+        case GDK_L:
+            if (held_only_shift(event->key)) {
+                // Shift+L - make segments linear
+                setSegmentType(SEGMENT_STRAIGHT);
+                return true;
+            }
+        case GDK_u:
+        case GDK_U:
+            if (held_only_shift(event->key)) {
+                // Shift+L - make segments curves
+                setSegmentType(SEGMENT_CUBIC_BEZIER);
+                return true;
+            }
         default:
             break;
         }
@@ -662,9 +707,9 @@ void MultiPathManipulator::_commit(CommitEvent cps)
     _selection.signal_update.emit();
     invokeForAll(&PathManipulator::writeXML);
     if (key) {
-        SPDocumentUndo::maybe_done(sp_desktop_document(_desktop), key, SP_VERB_CONTEXT_NODE, reason);
+        DocumentUndo::maybeDone(sp_desktop_document(_desktop), key, SP_VERB_CONTEXT_NODE, reason);
     } else {
-        SPDocumentUndo::done(sp_desktop_document(_desktop), SP_VERB_CONTEXT_NODE, reason);
+        DocumentUndo::done(sp_desktop_document(_desktop), SP_VERB_CONTEXT_NODE, reason);
     }
     signal_coords_changed.emit();
 }
@@ -673,7 +718,7 @@ void MultiPathManipulator::_commit(CommitEvent cps)
 void MultiPathManipulator::_done(gchar const *reason) {
     invokeForAll(&PathManipulator::update);
     invokeForAll(&PathManipulator::writeXML);
-    SPDocumentUndo::done(sp_desktop_document(_desktop), SP_VERB_CONTEXT_NODE, reason);
+    DocumentUndo::done(sp_desktop_document(_desktop), SP_VERB_CONTEXT_NODE, reason);
     signal_coords_changed.emit();
 }
 
@@ -714,4 +759,4 @@ guint32 MultiPathManipulator::_getOutlineColor(ShapeRole role)
   fill-column:99
   End:
 */
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :