Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.
C++
Add commands to add and remove shapes to a text contour inside the shape selection tool.
Wolthera van Hövell tot Westerflier89be06db17cf
diff --git a/krita/data/actions/InteractionTool.action b/krita/data/actions/InteractionTool.actionindex 196531128c..078a9d5f3c 100644--- a/krita/data/actions/InteractionTool.action+++ b/krita/data/actions/InteractionTool.action@@ -327,5 +327,35 @@<statusTip></statusTip><isCheckable>true</isCheckable></Action>- </Actions>++<Action name="add_shape_to_flow_area">+ <text>Flow Text in Shape</text>+ <toolTip>Make the first selected text flow in shape.</toolTip>+ <shortcut></shortcut>+ <icon></icon>+ <whatsThis></whatsThis>+ <statusTip></statusTip>+ <isCheckable>false</isCheckable>+</Action>++<Action name="subtract_shape_from_flow_area">+ <text>Subtract Shape from Text Flow Area</text>+ <toolTip>Make shapes part of the subtracted shapes of the first selected text.</toolTip>+ <shortcut></shortcut>+ <icon></icon>+ <whatsThis></whatsThis>+ <statusTip></statusTip>+ <isCheckable>false</isCheckable>+</Action>++<Action name="remove_shapes_from_text_flow">+ <text>Remove Shapes from Text Flow</text>+ <toolTip>Remove shapes from text flow and add them to the layer.</toolTip>+ <shortcut></shortcut>+ <icon></icon>+ <whatsThis></whatsThis>+ <statusTip></statusTip>+ <isCheckable>false</isCheckable>+</Action>+</Actions></ActionCollection>diff --git a/libs/flake/CMakeLists.txt b/libs/flake/CMakeLists.txtindex b2a49240f6..92b65febab 100644--- a/libs/flake/CMakeLists.txt+++ b/libs/flake/CMakeLists.txt@@ -172,6 +172,8 @@ set(kritaflake_SRCScommands/KoShapePaintOrderCommand.cppcommands/KoShapeMergeTextPropertiesCommand.cppcommands/KoSvgConvertTextTypeCommand.cpp+ commands/KoSvgChangeTextContoursCommand.cpp+ commands/KoSvgTextAddRemoveShapeCommands.cpphtml/HtmlSavingContext.cpphtml/HtmlWriter.cppdiff --git a/libs/flake/commands/KoSvgChangeTextContoursCommand.cpp b/libs/flake/commands/KoSvgChangeTextContoursCommand.cppnew file mode 100644index 0000000000..dd4f9b6e33--- /dev/null+++ b/libs/flake/commands/KoSvgChangeTextContoursCommand.cpp@@ -0,0 +1,67 @@+/*+ * SPDX-FileCopyrightText: 2025 Wolthera van Hövell tot Westerflier <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */++#include <KoShape.h>+#include <KoSvgTextShape.h>++#include "KoSvgChangeTextContoursCommand.h"++struct KoSvgChangeTextContoursCommand::Private {+ Private(KoSvgTextShape *_text, QList<KoShape*> _shapes, bool _inside)+ : textShape(_text)+ , newShapes(_shapes)+ , memento(textShape->getMemento())+ , inside(_inside)+ {+ oldShapes = inside? textShape->shapesInside(): textShape->shapesSubtract();+ }+ ~Private()+ {++ }+ KoSvgTextShape *textShape;+ QList<KoShape*> oldShapes;+ QList<KoShape*> newShapes;+ KoSvgTextShapeMementoSP memento;+ bool inside;+};++KoSvgChangeTextContoursCommand::KoSvgChangeTextContoursCommand(KoSvgTextShape *textShape, QList<KoShape*> shapes, bool inside, KUndo2Command *parent)+ : KUndo2Command(parent)+ , d(new Private(textShape, shapes, inside))+{+ setText(kundo2_i18n("Change Text Contours"));+}++KoSvgChangeTextContoursCommand::~KoSvgChangeTextContoursCommand()+{++}++void KoSvgChangeTextContoursCommand::redo()+{+ QRectF updateRect = d->textShape->boundingRect();+ if (d->inside) {+ d->textShape->setShapesInside(d->newShapes);+ } else {+ d->textShape->setShapesSubtract(d->newShapes);+ }+ updateRect |= d->textShape->boundingRect();+ d->textShape->updateAbsolute(updateRect);+}++void KoSvgChangeTextContoursCommand::undo()+{+ QRectF updateRect = d->textShape->boundingRect();+ if (d->inside) {+ d->textShape->setShapesInside(d->oldShapes);+ } else {+ d->textShape->setShapesSubtract(d->oldShapes);+ }+ d->textShape->setMemento(d->memento);+ updateRect |= d->textShape->boundingRect();+ d->textShape->updateAbsolute(updateRect);+}diff --git a/libs/flake/commands/KoSvgChangeTextContoursCommand.h b/libs/flake/commands/KoSvgChangeTextContoursCommand.hnew file mode 100644index 0000000000..b01896b81b--- /dev/null+++ b/libs/flake/commands/KoSvgChangeTextContoursCommand.h@@ -0,0 +1,35 @@+/*+ * SPDX-FileCopyrightText: 2025 Wolthera van Hövell tot Westerflier <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+#ifndef KOSVGCHANGETEXTCONTOURSCOMMAND_H+#define KOSVGCHANGETEXTCONTOURSCOMMAND_H++#include <kundo2command.h>+#include <kritaflake_export.h>++class KoSvgTextShape;+class KoShape;++/**+ * @brief The KoSvgChangeTextContoursCommand class+ * This replaces the given shapes on the text shape.+ *+ * bool inside indicates whether it will set on shapesInside or shapesSubtract.+ */++class KRITAFLAKE_EXPORT KoSvgChangeTextContoursCommand : public KUndo2Command+{+public:+ KoSvgChangeTextContoursCommand(KoSvgTextShape *textShape, QList<KoShape*> shapes, bool inside, KUndo2Command *parent = nullptr);+ ~KoSvgChangeTextContoursCommand();++ void redo() override;+ void undo() override;+private:+ struct Private;+ QScopedPointer<Private> d;+};++#endif // KOSVGCHANGETEXTCONTOURSCOMMAND_Hdiff --git a/libs/flake/commands/KoSvgTextAddRemoveShapeCommands.cpp b/libs/flake/commands/KoSvgTextAddRemoveShapeCommands.cppnew file mode 100644index 0000000000..041cab3d78--- /dev/null+++ b/libs/flake/commands/KoSvgTextAddRemoveShapeCommands.cpp@@ -0,0 +1,108 @@+/*+ * SPDX-FileCopyrightText: 2025 Wolthera van Hövell tot Westerflier <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+#include "KoSvgTextAddRemoveShapeCommands.h"++#include <KoSvgTextShape.h>+#include <KoShapeContainer.h>++struct KoSvgTextAddRemoveShapeCommandImpl::Private {+ Private(KoSvgTextShape *_text, KoShape *_shape)+ : textShape(_text)+ , shape(_shape)+ , memento(textShape->getMemento())+ {++ }++ ~Private() {}+ KoSvgTextShape *textShape;+ KoShape* shape;+ KoSvgTextShapeMementoSP memento;+ KoSvgTextAddRemoveShapeCommandImpl::ContourType type;+ bool removeCommand;+};++KoSvgTextAddRemoveShapeCommandImpl::KoSvgTextAddRemoveShapeCommandImpl(KoSvgTextShape *textShape, KoShape* shape, ContourType type, State state, KUndo2Command *parent)+ : KisCommandUtils::FlipFlopCommand(state, parent)+ , d(new Private(textShape, shape))+{+ if (type == Unknown) {+ if (d->textShape->shapesInside().contains(shape)) {+ d->type = Inside;+ } else if (d->textShape->shapesSubtract().contains(shape)) {+ d->type = Subtract;+ } else if (d->textShape->shapeInContours(shape)){+ d->type = TextPath;+ } else {+ d->type = Unknown;+ }+ } else {+ d->type = type;+ }+}++KoSvgTextAddRemoveShapeCommandImpl::~KoSvgTextAddRemoveShapeCommandImpl()+{++}++void KoSvgTextAddRemoveShapeCommandImpl::partB()+{+ QRectF updateRect = d->textShape->boundingRect();+ updateRect |= d->shape->boundingRect();+ d->textShape->removeShapesFromContours({d->shape}, true);+ if (!d->removeCommand) {+ d->textShape->setMemento(d->memento);+ } else {+ d->textShape->relayout();+ }+ updateRect |= d->textShape->boundingRect();+ updateRect |= d->shape->boundingRect();+ d->textShape->updateAbsolute(updateRect);+ d->shape->updateAbsolute(updateRect);+}++void KoSvgTextAddRemoveShapeCommandImpl::partA()+{+ QRectF updateRect = d->textShape->boundingRect();+ updateRect |= d->shape->boundingRect();+ if (d->type == Inside) {+ d->textShape->addShapeContours({d->shape}, true);+ } else if (d->type == Subtract) {+ d->textShape->addShapeContours({d->shape}, false);+ }+ if (d->removeCommand) {+ d->textShape->setMemento(d->memento);+ } else {+ d->textShape->relayout();+ }+ updateRect |= d->textShape->boundingRect();+ updateRect |= d->shape->boundingRect();+ d->shape->updateAbsolute(updateRect);+ d->textShape->updateAbsolute(updateRect);+}++KoSvgTextAddShapeCommand::KoSvgTextAddShapeCommand(KoSvgTextShape *textShape, KoShape *shape, bool inside, KUndo2Command *parentCommand)+ : KoSvgTextAddRemoveShapeCommandImpl(textShape, shape, (inside? Inside: Subtract), INITIALIZING, parentCommand)+{++}++KoSvgTextAddShapeCommand::~KoSvgTextAddShapeCommand()+{++}++KoSvgTextRemoveShapeCommand::KoSvgTextRemoveShapeCommand(KoSvgTextShape *textShape, KoShape *shape, KUndo2Command *parentCommand)+: KoSvgTextAddRemoveShapeCommandImpl(textShape, shape, Unknown, FINALIZING, parentCommand)+{++}++KoSvgTextRemoveShapeCommand::~KoSvgTextRemoveShapeCommand()+{++}diff --git a/libs/flake/commands/KoSvgTextAddRemoveShapeCommands.h b/libs/flake/commands/KoSvgTextAddRemoveShapeCommands.hnew file mode 100644index 0000000000..b1b3a21d83--- /dev/null+++ b/libs/flake/commands/KoSvgTextAddRemoveShapeCommands.h@@ -0,0 +1,47 @@+/*+ * SPDX-FileCopyrightText: 2025 Wolthera van Hövell tot Westerflier <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+#ifndef KOSVGTEXTADDREMOVESHAPECOMMANDS_H+#define KOSVGTEXTADDREMOVESHAPECOMMANDS_H++#include "kis_command_utils.h"+#include <kundo2command.h>+#include <kritaflake_export.h>++class KoSvgTextShape;+class KoShape;++class KRITAFLAKE_EXPORT KoSvgTextAddRemoveShapeCommandImpl : public KisCommandUtils::FlipFlopCommand+{+public:+ enum ContourType {+ Unknown,+ Inside,+ Subtract,+ TextPath+ };++ KoSvgTextAddRemoveShapeCommandImpl(KoSvgTextShape *textShape, KoShape *shape, ContourType type, State state, KUndo2Command *parent = nullptr);+ ~KoSvgTextAddRemoveShapeCommandImpl();+ void partA() override;+ void partB() override;+private:+ struct Private;+ QScopedPointer<Private> d;+};++class KRITAFLAKE_EXPORT KoSvgTextAddShapeCommand : public KoSvgTextAddRemoveShapeCommandImpl {+public:+ KoSvgTextAddShapeCommand(KoSvgTextShape *textShape, KoShape *shape, bool inside, KUndo2Command *parentCommand = 0);+ ~KoSvgTextAddShapeCommand();+};++class KRITAFLAKE_EXPORT KoSvgTextRemoveShapeCommand : public KoSvgTextAddRemoveShapeCommandImpl {+public:+ KoSvgTextRemoveShapeCommand(KoSvgTextShape *textShape, KoShape *shape, KUndo2Command *parentCommand = 0);+ ~KoSvgTextRemoveShapeCommand();+};++#endif // KOSVGTEXTADDREMOVESHAPECOMMANDS_Hdiff --git a/libs/flake/text/KoSvgTextShape.cpp b/libs/flake/text/KoSvgTextShape.cppindex 9324e497aa..a50c94eb0c 100644--- a/libs/flake/text/KoSvgTextShape.cpp+++ b/libs/flake/text/KoSvgTextShape.cpp@@ -56,7 +56,8 @@ public:const QMap<int, int> &logicalToVisualCursorPos,const QString &plainText,const bool &isBidi,- const QPointF &initialTextPosition)+ const QPointF &initialTextPosition,+ const QList<KoShape*> textPaths): KoSvgTextShapeMemento(), textData(textData), result(result)@@ -66,10 +67,13 @@ public:, plainText(plainText), isBidi(isBidi), initialTextPosition(initialTextPosition)+ , textPaths(textPaths){}- ~KoSvgTextShapeMementoImpl() {}+ ~KoSvgTextShapeMementoImpl() {+ qDeleteAll(textPaths);+ }private:friend class KoSvgTextShape;@@ -83,6 +87,8 @@ private:QString plainText;bool isBidi = false;QPointF initialTextPosition = QPointF();++ QList<KoShape *> textPaths;};struct KoSvgTextNodeIndex::Private {@@ -1766,7 +1772,8 @@ KoSvgTextShapeMementoSP KoSvgTextShape::getMemento()d->logicalToVisualCursorPos,d->plainText,d->isBidi,- d->initialTextPosition));+ d->initialTextPosition,+ d->textPaths));}void KoSvgTextShape::setMementoImpl(const KoSvgTextShapeMementoSP memento)@@ -1781,6 +1788,15 @@ void KoSvgTextShape::setMementoImpl(const KoSvgTextShapeMementoSP memento)d->plainText = impl->plainText;d->isBidi = impl->isBidi;d->initialTextPosition = impl->initialTextPosition;+ d->textPaths = impl->textPaths;+ Q_FOREACH(KoShape * shape, d->textPaths) {+ if (!shape->hasDependee(this)) {+ shape->addDependee(this);+ }+ if (!d->shapeGroup->shapes().contains(shape)) {+ d->shapeGroup->addShape(shape);+ }+ }}}@@ -2057,16 +2073,34 @@ KoSvgTextShape::TextType KoSvgTextShape::textType() constvoid KoSvgTextShape::setShapesInside(QList<KoShape *> shapesInside){- Q_FOREACH(KoShape *shape, d->shapesInside) {- if (shape) {- shape->removeDependee(this);+ removeShapesFromContours(d->shapesInside, false);+ addShapeContours(shapesInside, true);+}++void KoSvgTextShape::addShapeContours(QList<KoShape *> shapes, const bool inside)+{+ Q_FOREACH(KoShape *shape, shapes) {+ if (d->textPaths.contains(shape)) {+ d->removeTextPathId(d->textData.childBegin(), shape->name());+ d->cleanUp(d->textData);+ d->textPaths.removeAll(shape);+ }++ if (inside) {+ if (d->shapesSubtract.contains(shape)) {+ d->shapesSubtract.removeAll(shape);+ }+ d->shapesInside.append(shape);+ } else {+ if (d->shapesInside.contains(shape)) {+ d->shapesInside.removeAll(shape);+ }+ d->shapesSubtract.append(shape);+ }+ if (!d->shapeGroup->shapes().contains(shape)) {+ d->shapeGroup->addShape(shape);+ shape->addDependee(this);}- d->shapeGroup->removeShape(shape);- }- d->shapesInside = shapesInside;- Q_FOREACH(KoShape *shape, d->shapesInside) {- d->shapeGroup->addShape(shape);- shape->addDependee(this);}d->updateTextWrappingAreas();d->updateInternalShapesList();@@ -2074,28 +2108,42 @@ void KoSvgTextShape::setShapesInside(QList<KoShape *> shapesInside)update();}-QList<KoShape *> KoSvgTextShape::shapesInside() const+bool KoSvgTextShape::shapeInContours(KoShape *shape){- return d->shapesInside;+ return (shape->parent() == d->shapeGroup.data());}-void KoSvgTextShape::setShapesSubtract(QList<KoShape *> shapesSubtract)+void KoSvgTextShape::removeShapesFromContours(QList<KoShape *> shapes, bool callUpdate){- Q_FOREACH(KoShape *shape, d->shapesSubtract) {+ Q_FOREACH(KoShape *shape, shapes) {if (shape) {+ d->removeTextPathId(d->textData.childBegin(), shape->name());+ d->cleanUp(d->textData);shape->removeDependee(this);+ d->shapesInside.removeAll(shape);+ d->shapesSubtract.removeAll(shape);+ d->textPaths.removeAll(shape);+}d->shapeGroup->removeShape(shape);}- d->shapesSubtract = shapesSubtract;- Q_FOREACH(KoShape *shape, d->shapesSubtract) {- d->shapeGroup->addShape(shape);- shape->addDependee(this);+ if (callUpdate) {+ d->updateTextWrappingAreas();+ d->updateInternalShapesList();+ shapeChangedPriv(ContentChanged);+ update();}- d->updateTextWrappingAreas();- d->updateInternalShapesList();- shapeChangedPriv(ContentChanged);- update();+}++QList<KoShape *> KoSvgTextShape::shapesInside() const+{+ return d->shapesInside;+}++void KoSvgTextShape::setShapesSubtract(QList<KoShape *> shapesSubtract)+{+ removeShapesFromContours(d->shapesSubtract, false);+ addShapeContours(shapesSubtract, false);}QList<QPainterPath> KoSvgTextShape::textWrappingAreas() constdiff --git a/libs/flake/text/KoSvgTextShape.h b/libs/flake/text/KoSvgTextShape.hindex 2510ec258b..3b330d41f3 100644--- a/libs/flake/text/KoSvgTextShape.h+++ b/libs/flake/text/KoSvgTextShape.h@@ -97,6 +97,30 @@ public:*/void setShapesInside(QList<KoShape*> shapesInside);+ /**+ * @brief addShapesContours+ * Add shapes to the contours that make up the wrapping area.+ * @param shapes -- shapes to add.+ * @param inside -- whether to add to shapesInside or shapesSubtract.+ * If a shape is already in one list, adding them will cause them to be+ * moved to the other list.+ */+ void addShapeContours(QList<KoShape*> shapes, const bool inside = true);+ /**+ * @brief shapeInContours+ * @param shape+ * @return whether a shape is in any contour.+ */+ bool shapeInContours(KoShape *shape);++ /**+ * @brief removeShapesFromContours+ * Remove list of shapes from any of the internal lists.+ * @param shapes -- shapes to remove.+ * @param update -- whether to call an update.+ */+ void removeShapesFromContours(QList<KoShape*> shapes, bool callUpdate = true);+/*** @brief shapesInside* @return the list of shapes that make up the content area.diff --git a/libs/flake/text/KoSvgTextShape_p.h b/libs/flake/text/KoSvgTextShape_p.hindex bc5eec6fce..3327860490 100644--- a/libs/flake/text/KoSvgTextShape_p.h+++ b/libs/flake/text/KoSvgTextShape_p.h@@ -1245,6 +1245,19 @@ public:}static KoSvgTextNodeIndex createTextNodeIndex(KisForest<KoSvgTextContentElement>::child_iterator textElement);++ /**+ * @brief removeTextPathId+ * Remove the text path id with the given name from the toplevel elements.+ */+ static void removeTextPathId(KisForest<KoSvgTextContentElement>::child_iterator parent, const QString &name) {+ for (auto it = childBegin(parent); it != childEnd(parent); it++) {+ if (it->textPathId == name) {+ it->textPathId = QString();+ break;+ }+ }+ }};#endif // KO_SVG_TEXT_SHAPE_P_Hdiff --git a/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp b/plugins/tools/defaulttool/defaulttool/DefaultTool.cppindex b995e8903d..e30fd9013c 100644--- a/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp+++ b/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp@@ -42,6 +42,8 @@#include <commands/KoKeepShapesSelectedCommand.h>#include <commands/KoShapeMergeTextPropertiesCommand.h>#include <commands/KoSvgConvertTextTypeCommand.h>+#include <commands/KoSvgTextAddRemoveShapeCommands.h>+#include <KoSnapGuide.h>#include <KoStrokeConfigWidget.h>#include "kis_action_registry.h"@@ -553,6 +555,120 @@ void DefaultTool::slotChangeTextType(int index)}}+void DefaultTool::slotAddShapesToFlow()+{+ KoSvgTextShape *textShape = nullptr;+ QList<KoShape*> shapes;+ KoSelection *selection = koSelection();+ if (!selection) return;++ QList<KoShape *> selectedShapes = selection->selectedEditableShapes();+ std::sort(selectedShapes.begin(), selectedShapes.end(), KoShape::compareShapeZIndex);+ if (selectedShapes.isEmpty()) return;++ Q_FOREACH(KoShape *shape, selectedShapes) {+ KoSvgTextShape *text = dynamic_cast<KoSvgTextShape*>(shape);+ if (text && !textShape) {+ textShape = text;+ } else {+ shapes.append(shape);+ }+ }+ if (!textShape) return;+ if (shapes.isEmpty()) return;++ KUndo2Command *parentCommand = new KUndo2Command(kundo2_i18n("Add shapes to text flow."));++ new KoKeepShapesSelectedCommand(selectedShapes, {}, canvas()->selectedShapesProxy(), false, parentCommand);+ Q_FOREACH(KoShape *shape, shapes) {+ QPointF pos = shape->absolutePosition(KoFlake::TopLeft);+ QList<KoShape*> shapes{shape};++ if(shape->parent()) {+ canvas()->shapeController()->removeShape(shape, parentCommand);+ }+ new KoSvgTextAddShapeCommand(textShape, shape, true, parentCommand);++ pos = shape->absolutePosition(KoFlake::TopLeft) - pos;+ new KoShapeMoveCommand(shapes, pos, parentCommand);+ }+ new KoKeepShapesSelectedCommand({}, {textShape}, canvas()->selectedShapesProxy(), true, parentCommand);++ canvas()->addCommand(parentCommand);+ selection->deselectAll();+ selection->select(textShape);+}++void DefaultTool::slotSubtractShapesFromFlow()+{+ KoSvgTextShape *textShape = nullptr;+ QList<KoShape*> shapes;+ KoSelection *selection = koSelection();+ if (!selection) return;++ QList<KoShape *> selectedShapes = selection->selectedEditableShapes();+ std::sort(selectedShapes.begin(), selectedShapes.end(), KoShape::compareShapeZIndex);+ if (selectedShapes.isEmpty()) return;++ Q_FOREACH(KoShape *shape, selectedShapes) {+ KoSvgTextShape *text = dynamic_cast<KoSvgTextShape*>(shape);+ if (text && !textShape) {+ textShape = text;+ } else {+ shapes.append(shape);+ }+ }+ if (!textShape) return;+ if (shapes.isEmpty()) return;++ KUndo2Command *parentCommand = new KUndo2Command(kundo2_i18n("Subtract shapes from text flow."));++ new KoKeepShapesSelectedCommand(selectedShapes, {}, canvas()->selectedShapesProxy(), false, parentCommand);+ Q_FOREACH(KoShape *shape, shapes) {+ QPointF pos = shape->absolutePosition(KoFlake::TopLeft);+ QList<KoShape*> shapes{shape};++ if (shape->parent()) {+ canvas()->shapeController()->removeShape(shape, parentCommand);+ }+ new KoSvgTextAddShapeCommand(textShape, shape, false, parentCommand);++ pos = shape->absolutePosition(KoFlake::TopLeft) - pos;+ new KoShapeMoveCommand(shapes, pos, parentCommand);+ }+ new KoKeepShapesSelectedCommand({}, {textShape}, canvas()->selectedShapesProxy(), true, parentCommand);++ canvas()->addCommand(parentCommand);+ selection->deselectAll();+ selection->select(textShape);+}++void DefaultTool::slotRemoveShapesFromFlow()+{+ KoSvgTextShape *textShape = canvas()->textShapeManagerEnabled();+ if (!textShape) return;+ KoSelection *selection = koSelection();+ if (!selection) return;++ QList<KoShape *> selectedShapes = selection->selectedEditableShapes();+ std::sort(selectedShapes.begin(), selectedShapes.end(), KoShape::compareShapeZIndex);+ if (selectedShapes.isEmpty()) return;++ KUndo2Command *parentCommand = new KUndo2Command(kundo2_i18n("Remove shapes from text flow."));++ new KoKeepShapesSelectedCommand(selectedShapes, {}, canvas()->selectedShapesProxy(), false, parentCommand);+ Q_FOREACH(KoShape *shape, selectedShapes) {+ if (!textShape->shapeInContours(shape)) continue;+ QPointF pos = shape->absolutePosition(KoFlake::TopLeft);+ new KoSvgTextRemoveShapeCommand(textShape, shape, parentCommand);+ canvas()->shapeController()->addShape(shape, textShape->parent(), parentCommand);+ pos = shape->absolutePosition(KoFlake::TopLeft) - pos;+ QList<KoShape*> shapes{shape};+ new KoShapeMoveCommand(shapes, pos, parentCommand);+ }+ canvas()->addCommand(parentCommand);+}+bool DefaultTool::wantsAutoScroll() const{return true;@@ -916,6 +1032,7 @@ void DefaultTool::mousePressEvent(KoPointerEvent *event)if (KoSvgTextShape *shape = m_textOutlineHelper->contourModeButtonHovered(event->point)) {m_textOutlineHelper->toggleTextContourMode(shape);+ updateActions();event->accept();updateCursor();return;@@ -1247,6 +1364,15 @@ void DefaultTool::activate(const QSet<KoShape *> &shapes)connect(m_booleanSignalsMapper, SIGNAL(mapped(int)), SLOT(selectionBooleanOp(int)));connect(m_textTypeSignalsMapper, SIGNAL(mapped(int)), SLOT(slotChangeTextType(int)));+ QAction *actionTextInside = action("add_shape_to_flow_area");+ connect(actionTextInside, SIGNAL(triggered()), this, SLOT(slotAddShapesToFlow()), Qt::UniqueConnection);++ QAction *actionTextSubtract = action("subtract_shape_from_flow_area");+ connect(actionTextSubtract, SIGNAL(triggered()), this, SLOT(slotSubtractShapesFromFlow()), Qt::UniqueConnection);++ QAction *actionTextRemoveFlow = action("remove_shapes_from_text_flow");+ connect(actionTextRemoveFlow, SIGNAL(triggered()), this, SLOT(slotRemoveShapesFromFlow()), Qt::UniqueConnection);+m_mouseWasInsideHandles = false;m_lastHandle = KoFlake::NoHandle;useCursor(Qt::ArrowCursor);@@ -1295,6 +1421,13 @@ void DefaultTool::deactivate()disconnect(m_booleanSignalsMapper, 0, this, 0);disconnect(m_textTypeSignalsMapper, 0, this, 0);+ QAction *actionTextInside = action("add_shape_to_flow_area");+ disconnect(actionTextInside, 0, this, 0);+ QAction *actionTextSubtract = action("subtract_shape_from_flow_area");+ disconnect(actionTextSubtract, 0, this, 0);+ QAction *actionTextRemoveFlow = action("remove_shapes_from_text_flow");+ disconnect(actionTextRemoveFlow, 0, this, 0);+const KisCanvas2 *canvas2 = qobject_cast<const KisCanvas2 *>(this->canvas());if (canvas2) {canvas2->viewManager()->textPropertyManager()->setTextPropertiesInterface(nullptr);@@ -1867,6 +2000,22 @@ void DefaultTool::updateActions()action("object_distribute_vertical_bottom")->setEnabled(distributionEnabled);action("object_distribute_vertical_gaps")->setEnabled(distributionEnabled);+ bool textShape = false;+ bool otherShapes = false;+ Q_FOREACH(KoShape *shape, editableShapes) {+ KoSvgTextShape *text = dynamic_cast<KoSvgTextShape *>(shape);+ if (text && !textShape) {+ textShape = true;+ } else {+ otherShapes = true;+ }+ if (textShape && otherShapes) break;+ }+ const bool editContours = textShape && otherShapes;+ action("add_shape_to_flow_area")->setEnabled(editContours);+ action("subtract_shape_from_flow_area")->setEnabled(editContours);+ action("remove_shapes_from_text_flow")->setEnabled((canvas()->textShapeManagerEnabled()));+updateDistinctiveActions(editableShapes);Q_EMIT selectionChanged(editableShapes.size());@@ -1981,6 +2130,12 @@ QMenu* DefaultTool::popupActionsMenu()}m_contextMenu->addSeparator();m_contextMenu->addAction(action("convert_shapes_to_vector_selection"));++ m_contextMenu->addSeparator();+ QMenu *text = m_contextMenu->addMenu(i18n("Text"));+ text->addAction(action("add_shape_to_flow_area"));+ text->addAction(action("subtract_shape_from_flow_area"));+ text->addAction(action("remove_shapes_from_text_flow"));}return m_contextMenu.data();@@ -2034,7 +2189,8 @@ QList<KoSvgTextProperties> DefaultToolTextPropertiesInterface::getSelectedProperQList<KoSvgTextProperties> props = QList<KoSvgTextProperties>();if (!d->parent->selection()->hasSelection()) return props;- for (auto it = d->shapes.begin(); it != d->shapes.end(); it++) {+ QList<KoShape*> shapes = d->shapes;+ for (auto it = shapes.begin(); it != shapes.end(); it++) {KoSvgTextShape *textShape = dynamic_cast<KoSvgTextShape*>(*it);if (!textShape) continue;KoSvgTextProperties p = textShape->textProperties();@@ -2093,12 +2249,14 @@ void DefaultToolTextPropertiesInterface::clearSelection()void DefaultToolTextPropertiesInterface::slotSelectionChanged(){Q_FOREACH(KoShape *shape, d->shapes) {+ if (!shape) continue;shape->removeShapeChangeListener(this);}QList<KoShape*> shapes = d->parent->canvas()->selectedShapesProxy()->selection()->selectedEditableShapes();d->shapes = shapes;Q_FOREACH(KoShape *shape, d->shapes) {+ if (!shape) continue;shape->addShapeChangeListener(this);}d->compressor.start();diff --git a/plugins/tools/defaulttool/defaulttool/DefaultTool.h b/plugins/tools/defaulttool/defaulttool/DefaultTool.hindex 8f9eb4ff22..9e8abfd88d 100644--- a/plugins/tools/defaulttool/defaulttool/DefaultTool.h+++ b/plugins/tools/defaulttool/defaulttool/DefaultTool.h@@ -122,6 +122,9 @@ private Q_SLOTS:void slotResetMeshGradientState();void slotChangeTextType(int index);+ void slotAddShapesToFlow();+ void slotSubtractShapesFromFlow();+ void slotRemoveShapesFromFlow();protected Q_SLOTS:/// Update actions on selection changediff --git a/plugins/tools/defaulttool/defaulttool/DefaultToolFactory.cpp b/plugins/tools/defaulttool/defaulttool/DefaultToolFactory.cppindex c714deb10a..c3da521492 100644--- a/plugins/tools/defaulttool/defaulttool/DefaultToolFactory.cpp+++ b/plugins/tools/defaulttool/defaulttool/DefaultToolFactory.cpp@@ -77,6 +77,10 @@ QList<QAction *> DefaultToolFactory::createActionsImpl()actions << actionRegistry->makeQAction("text_type_pre_positioned", this);actions << actionRegistry->makeQAction("text_type_inline_wrap", this);+ actions << actionRegistry->makeQAction("add_shape_to_flow_area", this);+ actions << actionRegistry->makeQAction("subtract_shape_from_flow_area", this);+ actions << actionRegistry->makeQAction("remove_shapes_from_text_flow", this);+return actions;}diff --git a/plugins/tools/svgtexttool/CMakeLists.txt b/plugins/tools/svgtexttool/CMakeLists.txtindex 892b017092..6650debdce 100644--- a/plugins/tools/svgtexttool/CMakeLists.txt+++ b/plugins/tools/svgtexttool/CMakeLists.txt@@ -29,7 +29,6 @@ set (SvgTextTool_SRCSSvgTextChangeTransformsOnRange.cppSvgTextTypeSettingStrategy.cppSvgTextRemoveTransformsFromRange.cpp- SvgChangeTextContoursCommand.cppglyphpalette/GlyphPaletteDialog.cppglyphpalette/GlyphPaletteProxyModel.cppdiff --git a/plugins/tools/svgtexttool/SvgChangeTextContoursCommand.cpp b/plugins/tools/svgtexttool/SvgChangeTextContoursCommand.cppdeleted file mode 100644index 05f42050c3..0000000000--- a/plugins/tools/svgtexttool/SvgChangeTextContoursCommand.cpp+++ /dev/null@@ -1,36 +0,0 @@-/*- * SPDX-FileCopyrightText: 2025 Wolthera van Hövell tot Westerflier <[email protected]>- *- * SPDX-License-Identifier: GPL-3.0-or-later- */--#include <KoShape.h>-#include <KoSvgTextShape.h>--#include "SvgChangeTextContoursCommand.h"---SvgChangeTextContoursCommand::SvgChangeTextContoursCommand(KoSvgTextShape *textShape, QList<KoShape*> shapes, KUndo2Command *parent)- : KUndo2Command(parent)- , m_textShape(textShape)- , m_newShapes(shapes)-{- setText(kundo2_i18n("Change Text Contours"));- m_oldShapes = m_textShape->shapesInside();-}--void SvgChangeTextContoursCommand::redo()-{- QRectF updateRect = m_textShape->boundingRect();- m_textShape->setShapesInside(m_newShapes);- updateRect |= m_textShape->boundingRect();- m_textShape->updateAbsolute(updateRect);-}--void SvgChangeTextContoursCommand::undo()-{- QRectF updateRect = m_textShape->boundingRect();- m_textShape->setShapesInside(m_oldShapes);- updateRect |= m_textShape->boundingRect();- m_textShape->updateAbsolute(updateRect);-}diff --git a/plugins/tools/svgtexttool/SvgChangeTextContoursCommand.h b/plugins/tools/svgtexttool/SvgChangeTextContoursCommand.hdeleted file mode 100644index 3eea833e59..0000000000--- a/plugins/tools/svgtexttool/SvgChangeTextContoursCommand.h+++ /dev/null@@ -1,29 +0,0 @@-/*- * SPDX-FileCopyrightText: 2025 Wolthera van Hövell tot Westerflier <[email protected]>- *- * SPDX-License-Identifier: GPL-3.0-or-later- */-#ifndef SVGCHANGETEXTCONTOURSCOMMAND_H-#define SVGCHANGETEXTCONTOURSCOMMAND_H--#include <kundo2command.h>--class KoSvgTextShape;-class KoShape;--// TODO: This only supports shapeInside for now.--class SvgChangeTextContoursCommand : public KUndo2Command-{-public:- SvgChangeTextContoursCommand(KoSvgTextShape *textShape, QList<KoShape*> shapes, KUndo2Command *parent = nullptr);-- void redo() override;- void undo() override;-private:- KoSvgTextShape *m_textShape;- QList<KoShape*> m_oldShapes;- QList<KoShape*> m_newShapes;-};--#endif // SVGCHANGETEXTCONTOURSCOMMAND_Hdiff --git a/plugins/tools/svgtexttool/SvgCreateTextStrategy.cpp b/plugins/tools/svgtexttool/SvgCreateTextStrategy.cppindex d19c26923b..05b6d02fb4 100644--- a/plugins/tools/svgtexttool/SvgCreateTextStrategy.cpp+++ b/plugins/tools/svgtexttool/SvgCreateTextStrategy.cpp@@ -21,7 +21,7 @@#include "KoSnapGuide.h"#include "commands/KoKeepShapesSelectedCommand.h"#include "commands/KoShapeMoveCommand.h"-#include "SvgChangeTextContoursCommand.h"+#include "KoSvgChangeTextContoursCommand.h"#include "kis_global.h"#include "kundo2command.h"@@ -153,7 +153,7 @@ KUndo2Command *SvgCreateTextStrategy::createCommand()// text is not a shape container, but we do need to remove the shape from the canvas properly.tool->canvas()->shapeController()->removeShape(m_flowShape, parentCommand);}- new SvgChangeTextContoursCommand(textShape, shapes, parentCommand);+ new KoSvgChangeTextContoursCommand(textShape, shapes, true, parentCommand);}new KoKeepShapesSelectedCommand({}, {textShape}, tool->canvas()->selectedShapesProxy(), true, parentCommand);