[krita/rempt/T1004-recreate-the-text-tool] /: Implement "Split Shapes" operation

Dmitry Kazakov null at kde.org
Thu Jun 22 13:02:55 UTC 2017


Git commit 24275d4a15b44a5d9d0c1dec104ef297497e6c63 by Dmitry Kazakov.
Committed on 22/06/2017 at 13:02.
Pushed by dkazakov into branch 'rempt/T1004-recreate-the-text-tool'.

Implement "Split Shapes" operation

Now if the shape has multiple subpaths, it can be split into
multiple separate shapes.

CC:kimageshop at kde.org

M  +10   -0    krita/data/actions/InteractionTool.action
M  +2    -0    libs/flake/KoPathShape.cpp
M  +53   -1    plugins/tools/defaulttool/defaulttool/DefaultTool.cpp
M  +1    -0    plugins/tools/defaulttool/defaulttool/DefaultTool.h

https://commits.kde.org/krita/24275d4a15b44a5d9d0c1dec104ef297497e6c63

diff --git a/krita/data/actions/InteractionTool.action b/krita/data/actions/InteractionTool.action
index 3852938cfd8..bc0fc211c75 100644
--- a/krita/data/actions/InteractionTool.action
+++ b/krita/data/actions/InteractionTool.action
@@ -287,6 +287,16 @@
       <isCheckable>false</isCheckable>
     </Action>
 
+    <Action name="object_split">
+      <text>Split</text>
+      <toolTip>Split objects with multiple subpaths into multiple objects</toolTip>
+      <shortcut></shortcut>
+      <icon></icon>
+      <whatsThis></whatsThis>
+      <statusTip></statusTip>
+      <isCheckable>false</isCheckable>
+    </Action>
+
 
   </Actions>
 </ActionCollection>
diff --git a/libs/flake/KoPathShape.cpp b/libs/flake/KoPathShape.cpp
index 8bdde8dd049..8ad9e0e9a0b 100644
--- a/libs/flake/KoPathShape.cpp
+++ b/libs/flake/KoPathShape.cpp
@@ -1293,7 +1293,9 @@ bool KoPathShape::separate(QList<KoPathShape*> & separatedPaths)
         if (! shape) continue;
 
         shape->setStroke(stroke());
+        shape->setBackground(background());
         shape->setShapeId(shapeId());
+        shape->setZIndex(zIndex());
 
         KoSubpath *newSubpath = new KoSubpath();
 
diff --git a/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp b/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp
index 20807c71846..6b324ff1435 100644
--- a/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp
+++ b/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp
@@ -450,6 +450,10 @@ void DefaultTool::setupActions()
     addMappedAction(booleanSignalsMapper, "object_intersect", BooleanIntersection);
     addMappedAction(booleanSignalsMapper, "object_subtract", BooleanSubtraction);
 
+    QAction *actionSplit = actionRegistry->makeQAction("object_split", this);
+    addAction("object_split", actionSplit);
+    connect(actionSplit, SIGNAL(triggered()), this, SLOT(selectionSplitShapes()));
+
     m_contextMenu.reset(new QMenu());
 }
 
@@ -1210,6 +1214,41 @@ void DefaultTool::selectionBooleanOp(int booleanOp)
     canvas()->addCommand(cmd);
 }
 
+void DefaultTool::selectionSplitShapes()
+{
+    KoSelection *selection = koSelection();
+    if (!selection) return;
+
+    QList<KoShape *> editableShapes = selection->selectedEditableShapes();
+    if (editableShapes.isEmpty()) {
+        return;
+    }
+
+    KUndo2Command *cmd = new KUndo2Command(kundo2_i18n("Split Shapes"));
+
+    new KoKeepShapesSelectedCommand(editableShapes, {}, selection, false, cmd);
+    QList<KoShape*> newShapes;
+
+    Q_FOREACH (KoShape *shape, editableShapes) {
+        KoPathShape *pathShape = dynamic_cast<KoPathShape*>(shape);
+        if (!pathShape) return;
+
+        QList<KoPathShape*> splitShapes;
+        if (pathShape->separate(splitShapes)) {
+            QList<KoShape*> normalShapes = implicitCastList<KoShape*>(splitShapes);
+
+            KoShapeContainer *parent = shape->parent();
+            canvas()->shapeController()->addShapesDirect(normalShapes, parent, cmd);
+            canvas()->shapeController()->removeShape(shape, cmd);
+            newShapes << normalShapes;
+        }
+    }
+
+    new KoKeepShapesSelectedCommand({}, newShapes, selection, true, cmd);
+
+    canvas()->addCommand(cmd);
+}
+
 void DefaultTool::selectionAlign(int _align)
 {
     KoShapeAlignCommand::Align align =
@@ -1495,6 +1534,17 @@ void DefaultTool::updateActions()
     action("object_intersect")->setEnabled(multipleSelected);
     action("object_subtract")->setEnabled(multipleSelected);
 
+    bool hasShapesWithMultipleSegments = false;
+    Q_FOREACH (KoShape *shape, editableShapes) {
+        KoPathShape *pathShape = dynamic_cast<KoPathShape *>(shape);
+        if (pathShape && pathShape->subpathCount() > 1) {
+            hasShapesWithMultipleSegments = true;
+            break;
+        }
+    }
+    action("object_split")->setEnabled(hasShapesWithMultipleSegments);
+
+
     const bool distributionEnabled = editableShapes.size() > 2;
 
     action("object_distribute_horizontal_left")->setEnabled(distributionEnabled);
@@ -1563,12 +1613,14 @@ QMenu* DefaultTool::popupActionsMenu()
 
         if (action("object_unite")->isEnabled() ||
             action("object_intersect")->isEnabled() ||
-            action("object_subtract")->isEnabled()) {
+            action("object_subtract")->isEnabled() ||
+            action("object_split")->isEnabled()) {
 
             QMenu *transform = m_contextMenu->addMenu(i18n("Logical Operations"));
             transform->addAction(action("object_unite"));
             transform->addAction(action("object_intersect"));
             transform->addAction(action("object_subtract"));
+            transform->addAction(action("object_split"));
         }
     }
 
diff --git a/plugins/tools/defaulttool/defaulttool/DefaultTool.h b/plugins/tools/defaulttool/defaulttool/DefaultTool.h
index bd1b33d0368..69cb23269a6 100644
--- a/plugins/tools/defaulttool/defaulttool/DefaultTool.h
+++ b/plugins/tools/defaulttool/defaulttool/DefaultTool.h
@@ -108,6 +108,7 @@ private Q_SLOTS:
 
     void selectionTransform(int transformAction);
     void selectionBooleanOp(int booleanOp);
+    void selectionSplitShapes();
 
     void slotActivateEditFillGradient(bool value);
     void slotActivateEditStrokeGradient(bool value);


More information about the kimageshop mailing list