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 "Put Text On Path" action to the shape selection tool.
Wolthera van Hövell tot Westerflier46ec20c87c8f
diff --git a/krita/data/actions/InteractionTool.action b/krita/data/actions/InteractionTool.actionindex 52e0801a76..834bf2a7d3 100644--- a/krita/data/actions/InteractionTool.action+++ b/krita/data/actions/InteractionTool.action@@ -348,6 +348,16 @@<isCheckable>false</isCheckable></Action>+<Action name="put_text_on_path">+ <text>Put Text On Path</text>+ <toolTip>Make the first selected text flow onto the first selected path.</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>diff --git a/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp b/plugins/tools/defaulttool/defaulttool/DefaultTool.cppindex 4c0157c009..8256e2b01a 100644--- a/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp+++ b/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp@@ -598,6 +598,51 @@ void DefaultTool::slotAddShapesToFlow()selection->select(textShape);}+void DefaultTool::slotPutTextOnPath()+{+ KoSvgTextShape *textShape = nullptr;+ KoPathShape *textPath = nullptr;+ 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 if (KoPathShape *path = dynamic_cast<KoPathShape*>(shape)){+ textPath = path;+ }+ if (textShape && textPath) {+ break;+ }+ }+ if (!(textShape && textPath)) return;++ KUndo2Command *parentCommand = new KUndo2Command(kundo2_i18n("Put Text On Path"));++ new KoKeepShapesSelectedCommand(selectedShapes, {}, canvas()->selectedShapesProxy(), false, parentCommand);+ if (textShape->textType() != KoSvgTextShape::InlineWrap) {+ new KoSvgConvertTextTypeCommand(textShape, KoSvgTextShape::PreformattedText, 0, parentCommand);+ }++ /// This will always remove all previous text paths.+ /// While Krita's layout engine can handle multiple of them, the interaction+ /// hasn't been fully verified yet. So if someone implements multiple textpaths,+ /// they will also need to check if the cursor interaction makes sense.+ KoSvgTextRemoveShapeCommand::removeContourShapesFromFlow(textShape, parentCommand, true, true);+ new KoSvgTextSetTextPathOnRangeCommand(textShape, textPath, 0, textShape->posForIndex(textShape->plainText().size()), parentCommand);++ new KoKeepShapesSelectedCommand({}, {textShape}, canvas()->selectedShapesProxy(), true, parentCommand);++ canvas()->addCommand(parentCommand);+ selection->deselectAll();+ selection->select(textShape);+}+void DefaultTool::slotSubtractShapesFromFlow(){KoSvgTextShape *textShape = nullptr;@@ -1438,6 +1483,9 @@ void DefaultTool::activate(const QSet<KoShape *> &shapes)QAction *actionTextSubtract = action("subtract_shape_from_flow_area");connect(actionTextSubtract, SIGNAL(triggered()), this, SLOT(slotSubtractShapesFromFlow()), Qt::UniqueConnection);+ QAction *actionTextOnPath = action("put_text_on_path");+ connect(actionTextOnPath, SIGNAL(triggered()), this, SLOT(slotPutTextOnPath()), Qt::UniqueConnection);+QAction *actionTextRemoveFlow = action("remove_shapes_from_text_flow");connect(actionTextRemoveFlow, SIGNAL(triggered()), this, SLOT(slotRemoveShapesFromFlow()), Qt::UniqueConnection);@@ -1497,6 +1545,8 @@ void DefaultTool::deactivate()disconnect(actionTextInside, 0, this, 0);QAction *actionTextSubtract = action("subtract_shape_from_flow_area");disconnect(actionTextSubtract, 0, this, 0);+ QAction *actionTextOnPath = action("put_text_on_path");+ disconnect(actionTextOnPath, 0, this, 0);QAction *actionTextRemoveFlow = action("remove_shapes_from_text_flow");disconnect(actionTextRemoveFlow, 0, this, 0);QAction *actionTextFlowToggle = action("flow_shape_type_toggle");@@ -2097,6 +2147,7 @@ void DefaultTool::updateActions()action("add_shape_to_flow_area")->setEnabled(editContours);action("subtract_shape_from_flow_area")->setEnabled(editContours);+ action("put_text_on_path")->setEnabled(editContours);action("remove_shapes_from_text_flow")->setEnabled(editFlowShapes);action("flow_shape_type_toggle")->setEnabled(editFlowShapes);action("flow_shape_order_back")->setEnabled(shapesInside);@@ -2232,6 +2283,7 @@ QMenu* DefaultTool::popupActionsMenu()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("put_text_on_path"));text->addSeparator();text->addAction(action("text_type_preformatted"));text->addAction(action("text_type_inline_wrap"));diff --git a/plugins/tools/defaulttool/defaulttool/DefaultTool.h b/plugins/tools/defaulttool/defaulttool/DefaultTool.hindex a66cf9e3e7..c1eaf3f2ac 100644--- a/plugins/tools/defaulttool/defaulttool/DefaultTool.h+++ b/plugins/tools/defaulttool/defaulttool/DefaultTool.h@@ -124,6 +124,7 @@ private Q_SLOTS:void slotChangeTextType(int index);void slotAddShapesToFlow();+ void slotPutTextOnPath();void slotSubtractShapesFromFlow();void slotRemoveShapesFromFlow();void slotToggleFlowShapeType();diff --git a/plugins/tools/defaulttool/defaulttool/DefaultToolFactory.cpp b/plugins/tools/defaulttool/defaulttool/DefaultToolFactory.cppindex 2059f1ee48..643ad10344 100644--- a/plugins/tools/defaulttool/defaulttool/DefaultToolFactory.cpp+++ b/plugins/tools/defaulttool/defaulttool/DefaultToolFactory.cpp@@ -79,6 +79,7 @@ QList<QAction *> DefaultToolFactory::createActionsImpl()actions << actionRegistry->makeQAction("add_shape_to_flow_area", this);actions << actionRegistry->makeQAction("subtract_shape_from_flow_area", this);+ actions << actionRegistry->makeQAction("put_text_on_path", this);actions << actionRegistry->makeQAction("remove_shapes_from_text_flow", this);actions << actionRegistry->makeQAction("flow_shape_type_toggle", this);