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++
Make text conversion functions into shortcut-actions and implement them in Shape Select Tool.
Wolthera van Hövell tot Westerflierdb66e20fd56a
diff --git a/krita/data/actions/InteractionTool.action b/krita/data/actions/InteractionTool.actionindex daf1943a73..196531128c 100644--- a/krita/data/actions/InteractionTool.action+++ b/krita/data/actions/InteractionTool.action@@ -297,6 +297,35 @@<isCheckable>false</isCheckable></Action>-+<Action name="text_type_preformatted">+ <text>Convert Text To Preformatted</text>+ <iconText>Preformatted</iconText>+ <toolTip>The text will not wrap and preserves spaces and new lines. A line break is inserted so the lines from wrapping or positioning remain separated.</toolTip>+ <shortcut></shortcut>+ <icon></icon>+ <whatsThis></whatsThis>+ <statusTip></statusTip>+ <isCheckable>true</isCheckable>+</Action>+<Action name="text_type_inline_wrap">+ <text>Convert Text To Inline Wrapped</text>+ <iconText>Inline Wrapped</iconText>+ <toolTip>Text wraps inside a fixed length, spaces and new lines are preserved. New lines are not removed.</toolTip>+ <shortcut></shortcut>+ <icon></icon>+ <whatsThis></whatsThis>+ <statusTip></statusTip>+ <isCheckable>true</isCheckable>+</Action>+<Action name="text_type_pre_positioned">+ <text>Convert Text To Pre-positioned</text>+ <iconText>Pre-positioned</iconText>+ <toolTip>Text uses SVG 1.1 character transforms to position each line. Spaces and new lines are collapsed. This is for backward compatibility with SVG 1.1.</toolTip>+ <shortcut></shortcut>+ <icon></icon>+ <whatsThis></whatsThis>+ <statusTip></statusTip>+ <isCheckable>true</isCheckable>+</Action></Actions></ActionCollection>diff --git a/libs/flake/CMakeLists.txt b/libs/flake/CMakeLists.txtindex f24b749ec1..f05b1dc680 100644--- a/libs/flake/CMakeLists.txt+++ b/libs/flake/CMakeLists.txt@@ -171,6 +171,7 @@ set(kritaflake_SRCScommands/KoAddRemoveShapeCommands.cppcommands/KoShapePaintOrderCommand.cppcommands/KoShapeMergeTextPropertiesCommand.cpp+ commands/KoSvgConvertTextTypeCommand.cpphtml/HtmlSavingContext.cpphtml/HtmlWriter.cppdiff --git a/plugins/tools/svgtexttool/SvgConvertTextTypeCommand.cpp b/libs/flake/commands/KoSvgConvertTextTypeCommand.cppsimilarity index 67%rename from plugins/tools/svgtexttool/SvgConvertTextTypeCommand.cpprename to libs/flake/commands/KoSvgConvertTextTypeCommand.cppindex 3ce2f12f0a..ffe01a0ff6 100644--- a/plugins/tools/svgtexttool/SvgConvertTextTypeCommand.cpp+++ b/libs/flake/commands/KoSvgConvertTextTypeCommand.cpp@@ -3,9 +3,9 @@** SPDX-License-Identifier: GPL-3.0-or-later*/-#include "SvgConvertTextTypeCommand.h"+#include "KoSvgConvertTextTypeCommand.h"-SvgConvertTextTypeCommand::SvgConvertTextTypeCommand(KoSvgTextShape *shape, ConversionType type, int pos, KUndo2Command *parent)+KoSvgConvertTextTypeCommand::KoSvgConvertTextTypeCommand(KoSvgTextShape *shape, KoSvgTextShape::TextType type, int pos, KUndo2Command *parent): KUndo2Command(parent), m_shape(shape), m_conversionType(type)@@ -14,17 +14,17 @@ SvgConvertTextTypeCommand::SvgConvertTextTypeCommand(KoSvgTextShape *shape, ConvsetText(kundo2_i18n("Convert Text Type"));}-void SvgConvertTextTypeCommand::redo()+void KoSvgConvertTextTypeCommand::redo(){QRectF updateRect = m_shape->boundingRect();m_textData = m_shape->getMemento();const int oldIndex = qMax(0, m_shape->indexForPos(m_pos));- if (m_conversionType == ToPreFormatted) {+ if (m_conversionType == KoSvgTextShape::PreformattedText) {m_shape->convertCharTransformsToPreformatted(false);- } else if (m_conversionType == ToInlineSize) {+ } else if (m_conversionType == KoSvgTextShape::InlineWrap) {m_shape->convertCharTransformsToPreformatted(true);- } else if (m_conversionType == ToCharTransforms) {+ } else if (m_conversionType == KoSvgTextShape::PrePositionedText) {m_shape->setCharacterTransformsFromLayout();}@@ -33,7 +33,7 @@ void SvgConvertTextTypeCommand::redo()m_shape->notifyCursorPosChanged(pos, pos);}-void SvgConvertTextTypeCommand::undo()+void KoSvgConvertTextTypeCommand::undo(){QRectF updateRect = m_shape->boundingRect();m_shape->setMemento(m_textData, m_pos, m_pos);diff --git a/plugins/tools/svgtexttool/SvgConvertTextTypeCommand.h b/libs/flake/commands/KoSvgConvertTextTypeCommand.hsimilarity index 55%rename from plugins/tools/svgtexttool/SvgConvertTextTypeCommand.hrename to libs/flake/commands/KoSvgConvertTextTypeCommand.hindex b574639fcc..df7eaab7a6 100644--- a/plugins/tools/svgtexttool/SvgConvertTextTypeCommand.h+++ b/libs/flake/commands/KoSvgConvertTextTypeCommand.h@@ -7,7 +7,7 @@#define SVGCONVERTTEXTTYPECOMMAND_H#include <kundo2command.h>-#include "kritatoolsvgtext_export.h"+#include "kritaflake_export.h"#include <KoSvgTextShape.h>/**@@ -19,17 +19,12 @@* for each new text chunk, and finally, assigns an inline-size if* necessary.*/-class KRITATOOLSVGTEXT_EXPORT SvgConvertTextTypeCommand : public KUndo2Command+class KRITAFLAKE_EXPORT KoSvgConvertTextTypeCommand : public KUndo2Command{public:- enum ConversionType {- ToPreFormatted, ///< Apply whitespace, convert whitespace rule to pre-wrapped, insert newlines at chunk starts and remove character transforms. Removes InlineSize.- ToInlineSize, ///< Same as ToPreFormatted, except adds an inline-size.- ToCharTransforms ///< This applies SVG 1.1 char transforms and sets whitespace to normal.- };- SvgConvertTextTypeCommand(KoSvgTextShape *shape, ConversionType type, int pos, KUndo2Command *parent = 0);- ~SvgConvertTextTypeCommand() override = default;+ KoSvgConvertTextTypeCommand(KoSvgTextShape *shape, KoSvgTextShape::TextType type, int pos, KUndo2Command *parent = 0);+ ~KoSvgConvertTextTypeCommand() override = default;void redo() override;@@ -42,7 +37,7 @@ private:KoSvgTextShape *m_shape;KoSvgTextShapeMementoSP m_textData;- ConversionType m_conversionType;+ KoSvgTextShape::TextType m_conversionType;int m_pos;};diff --git a/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp b/plugins/tools/defaulttool/defaulttool/DefaultTool.cppindex 1cfb1e9916..1560e4e347 100644--- a/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp+++ b/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp@@ -41,6 +41,7 @@#include <commands/KoShapeDistributeCommand.h>#include <commands/KoKeepShapesSelectedCommand.h>#include <commands/KoShapeMergeTextPropertiesCommand.h>+#include <commands/KoSvgConvertTextTypeCommand.h>#include <KoSnapGuide.h>#include <KoStrokeConfigWidget.h>#include "kis_action_registry.h"@@ -520,6 +521,33 @@ void DefaultTool::slotResetMeshGradientState()m_selectedMeshHandle = KoShapeMeshGradientHandles::Handle();}+void DefaultTool::slotChangeTextType(int index)+{+ QList<KoShape *> shapes = koSelection()->selectedShapes();++ if (shapes.isEmpty()) return;++ const KoSvgTextShape::TextType type = KoSvgTextShape::TextType(index);+ KUndo2Command *parentCommand = new KUndo2Command();+ bool convertableShape = false;+ new KoKeepShapesSelectedCommand({shapes}, {}, canvas()->selectedShapesProxy(), KisCommandUtils::FlipFlopCommand::State::INITIALIZING, parentCommand);+ Q_FOREACH(KoShape *shape, shapes) {+ KoSvgTextShape *textShape = dynamic_cast<KoSvgTextShape*>(shape);+ if (textShape && textShape->textType() != type) {+ KoSvgConvertTextTypeCommand *cmd = new KoSvgConvertTextTypeCommand(textShape, type, 0, parentCommand);+ if (!convertableShape) {+ convertableShape = true;+ parentCommand->setText(cmd->text());+ }+ }+ }++ new KoKeepShapesSelectedCommand({}, {shapes}, canvas()->selectedShapesProxy(), KisCommandUtils::FlipFlopCommand::State::FINALIZING, parentCommand);+ if (convertableShape) {+ canvas()->addCommand(parentCommand);+ }+}+bool DefaultTool::wantsAutoScroll() const{return true;@@ -570,6 +598,11 @@ void DefaultTool::setupActions()addMappedAction(m_booleanSignalsMapper, "object_intersect", BooleanIntersection);addMappedAction(m_booleanSignalsMapper, "object_subtract", BooleanSubtraction);+ m_textTypeSignalsMapper = new KisSignalMapper(this);+ addMappedAction(m_textTypeSignalsMapper, "text_type_preformatted", KoSvgTextShape::PreformattedText);+ addMappedAction(m_textTypeSignalsMapper, "text_type_inline_wrap", KoSvgTextShape::InlineWrap);+ addMappedAction(m_textTypeSignalsMapper, "text_type_pre_positioned", KoSvgTextShape::PrePositionedText);+m_contextMenu.reset(new QMenu());}@@ -1194,6 +1227,7 @@ void DefaultTool::activate(const QSet<KoShape *> &shapes)connect(m_distributeSignalsMapper, SIGNAL(mapped(int)), SLOT(selectionDistribute(int)));connect(m_transformSignalsMapper, SIGNAL(mapped(int)), SLOT(selectionTransform(int)));connect(m_booleanSignalsMapper, SIGNAL(mapped(int)), SLOT(selectionBooleanOp(int)));+ connect(m_textTypeSignalsMapper, SIGNAL(mapped(int)), SLOT(slotChangeTextType(int)));m_mouseWasInsideHandles = false;m_lastHandle = KoFlake::NoHandle;@@ -1241,6 +1275,7 @@ void DefaultTool::deactivate()disconnect(m_distributeSignalsMapper, 0, this, 0);disconnect(m_transformSignalsMapper, 0, this, 0);disconnect(m_booleanSignalsMapper, 0, this, 0);+ disconnect(m_textTypeSignalsMapper, 0, this, 0);const KisCanvas2 *canvas2 = qobject_cast<const KisCanvas2 *>(this->canvas());if (canvas2) {@@ -1847,6 +1882,27 @@ void DefaultTool::updateDistinctiveActions(const QList<KoShape*> &editableShapes}}action("object_ungroup")->setEnabled(hasGroupShape);++ bool enablePreformatted = false;+ bool enablePrePositioned = false;+ bool enableInlineWrapped = false;+ Q_FOREACH (KoShape *shape, editableShapes) {+ KoSvgTextShape *textShape = dynamic_cast<KoSvgTextShape *>(shape);+ if (textShape) {+ if (textShape->textType() != KoSvgTextShape::PreformattedText && !enablePreformatted) {+ enablePreformatted = true;+ }+ if (textShape && textShape->textType() != KoSvgTextShape::PrePositionedText && !enablePrePositioned) {+ enablePrePositioned = true;+ }+ if (textShape && textShape->textType() != KoSvgTextShape::PrePositionedText && !enableInlineWrapped) {+ enableInlineWrapped = true;+ }+ }+ }+ action("text_type_preformatted")->setEnabled(enablePreformatted);+ action("text_type_pre_positioned")->setEnabled(enablePrePositioned);+ action("text_type_inline_wrap")->setEnabled(enableInlineWrapped);}diff --git a/plugins/tools/defaulttool/defaulttool/DefaultTool.h b/plugins/tools/defaulttool/defaulttool/DefaultTool.hindex c64fb19b47..9c5e87101e 100644--- a/plugins/tools/defaulttool/defaulttool/DefaultTool.h+++ b/plugins/tools/defaulttool/defaulttool/DefaultTool.h@@ -120,6 +120,8 @@ private Q_SLOTS:void slotActivateEditFillMeshGradient(bool value);void slotResetMeshGradientState();+ void slotChangeTextType(int index);+protected Q_SLOTS:/// Update actions on selection changevoid updateActions();@@ -201,6 +203,7 @@ private:KisSignalMapper *m_distributeSignalsMapper {0};KisSignalMapper *m_transformSignalsMapper {0};KisSignalMapper *m_booleanSignalsMapper {0};+ KisSignalMapper *m_textTypeSignalsMapper {0};DefaultToolTextPropertiesInterface *m_textPropertyInterface{0};};diff --git a/plugins/tools/defaulttool/defaulttool/DefaultToolFactory.cpp b/plugins/tools/defaulttool/defaulttool/DefaultToolFactory.cppindex 974e7057f5..c714deb10a 100644--- a/plugins/tools/defaulttool/defaulttool/DefaultToolFactory.cpp+++ b/plugins/tools/defaulttool/defaulttool/DefaultToolFactory.cpp@@ -73,6 +73,10 @@ QList<QAction *> DefaultToolFactory::createActionsImpl()actions << actionRegistry->makeQAction("object_subtract", this);actions << actionRegistry->makeQAction("object_split", this);+ actions << actionRegistry->makeQAction("text_type_preformatted", this);+ actions << actionRegistry->makeQAction("text_type_pre_positioned", this);+ actions << actionRegistry->makeQAction("text_type_inline_wrap", this);+return actions;}diff --git a/plugins/tools/svgtexttool/CMakeLists.txt b/plugins/tools/svgtexttool/CMakeLists.txtindex 42c6a20778..64c5160db2 100644--- a/plugins/tools/svgtexttool/CMakeLists.txt+++ b/plugins/tools/svgtexttool/CMakeLists.txt@@ -22,7 +22,6 @@ set (SvgTextTool_SRCSSvgTextTool.cppSvgTextToolFactory.cppSvgTextShapeManagerBlocker.cpp- SvgConvertTextTypeCommand.cppSvgTextShortCuts.cppSvgTextToolOptionsData.cppSvgTextToolOptionsModel.cppdiff --git a/plugins/tools/svgtexttool/SvgTextTool.cpp b/plugins/tools/svgtexttool/SvgTextTool.cppindex 7ec2625d56..8950bd9fdd 100644--- a/plugins/tools/svgtexttool/SvgTextTool.cpp+++ b/plugins/tools/svgtexttool/SvgTextTool.cpp@@ -19,7 +19,7 @@#include "SvgTextChangeCommand.h"#include "SvgTextEditor.h"#include "SvgTextRemoveCommand.h"-#include "SvgConvertTextTypeCommand.h"+#include "KoSvgConvertTextTypeCommand.h"#include "SvgTextShortCuts.h"#include "SvgTextToolOptionsModel.h"@@ -121,6 +121,18 @@ SvgTextTool::SvgTextTool(KoCanvasBase *canvas)}}+ m_textTypeSignalsMapper.reset(new KisSignalMapper(this));+ const QMap<QString, int> convertActions {+ {"text_type_preformatted", KoSvgTextShape::PreformattedText},+ {"text_type_inline_wrap", KoSvgTextShape::InlineWrap},+ {"text_type_pre_positioned", KoSvgTextShape::PrePositionedText}+ };+ Q_FOREACH(const QString name, convertActions.keys()) {+ QAction *a = action(name);+ connect(a, SIGNAL(triggered()), m_textTypeSignalsMapper.data(), SLOT(map()));+ m_textTypeSignalsMapper->setMapping(a, convertActions.value(name));+ }+m_base_cursor = QCursor(QPixmap(":/tool_text_basic.xpm"), 7, 7);m_text_inline_horizontal = QCursor(QPixmap(":/tool_text_inline_horizontal.xpm"), 7, 7);m_text_inline_vertical = QCursor(QPixmap(":/tool_text_inline_vertical.xpm"), 7, 7);@@ -155,6 +167,8 @@ void SvgTextTool::activate(const QSet<KoShape *> &shapes)}}+ connect(m_textTypeSignalsMapper.data(), SIGNAL(mapped(int)), this, SLOT(slotConvertType(int)));+useCursor(m_base_cursor);slotShapeSelectionChanged();@@ -171,6 +185,7 @@ void SvgTextTool::deactivate()canvas2->viewManager()->textPropertyManager()->setTextPropertiesInterface(nullptr);}// Exiting text editing mode is handled by requestStrokeEnd+ disconnect(m_textTypeSignalsMapper.data(), 0, this, 0);m_hoveredShapeHighlightRect = QPainterPath();@@ -502,15 +517,10 @@ void SvgTextTool::slotUpdateCursorDecoration(QRectF updateRect)void SvgTextTool::slotConvertType(int index) {if (selectedShape()) {if (index == selectedShape()->textType()) return;- SvgConvertTextTypeCommand::ConversionType type = SvgConvertTextTypeCommand::ToPreFormatted;- if (index == KoSvgTextShape::InlineWrap) {- type = SvgConvertTextTypeCommand::ToInlineSize;- } else if (index == KoSvgTextShape::PrePositionedText) {- type = SvgConvertTextTypeCommand::ToCharTransforms;- }+ KoSvgTextShape::TextType type = KoSvgTextShape::TextType(index);KUndo2Command *parentCommand = new KUndo2Command();new KoKeepShapesSelectedCommand({selectedShape()}, {}, canvas()->selectedShapesProxy(), KisCommandUtils::FlipFlopCommand::State::INITIALIZING, parentCommand);- SvgConvertTextTypeCommand *cmd = new SvgConvertTextTypeCommand(selectedShape(), type, m_textCursor.getPos(), parentCommand);+ KoSvgConvertTextTypeCommand *cmd = new KoSvgConvertTextTypeCommand(selectedShape(), type, m_textCursor.getPos(), parentCommand);parentCommand->setText(cmd->text());new KoKeepShapesSelectedCommand({}, {selectedShape()}, canvas()->selectedShapesProxy(), KisCommandUtils::FlipFlopCommand::State::FINALIZING, parentCommand);canvas()->addCommand(parentCommand);@@ -531,10 +541,21 @@ void SvgTextTool::slotUpdateTextPasteBehaviour()void SvgTextTool::slotTextTypeUpdated(){KoSvgTextShape *shape = selectedShape();- if (shape && m_optionManager) {- m_optionManager->convertToTextType(int(shape->textType()));- } else {- m_optionManager->convertToTextType(-1);+ if (m_optionManager) {+ if (shape) {+ m_optionManager->convertToTextType(int(shape->textType()));+ action("text_type_preformatted")->setEnabled(true);+ action("text_type_pre_positioned")->setEnabled(true);+ action("text_type_inline_wrap")->setEnabled(true);+ action("text_type_preformatted")->setChecked(shape->textType() == KoSvgTextShape::PreformattedText);+ action("text_type_pre_positioned")->setChecked(shape->textType() == KoSvgTextShape::PrePositionedText);+ action("text_type_inline_wrap")->setChecked(shape->textType() == KoSvgTextShape::InlineWrap);+ } else {+ m_optionManager->convertToTextType(-1);+ action("text_type_preformatted")->setEnabled(false);+ action("text_type_pre_positioned")->setEnabled(false);+ action("text_type_inline_wrap")->setEnabled(false);+ }}}diff --git a/plugins/tools/svgtexttool/SvgTextTool.h b/plugins/tools/svgtexttool/SvgTextTool.hindex 5299a31253..b253347095 100644--- a/plugins/tools/svgtexttool/SvgTextTool.h+++ b/plugins/tools/svgtexttool/SvgTextTool.h@@ -14,6 +14,7 @@#include <QPointer>#include <kis_signal_auto_connection.h>+#include <KisSignalMapper.h>#include "SvgTextCursor.h"#include "SvgTextToolOptionsManager.h"@@ -196,6 +197,8 @@ private:HighlightItem m_highlightItem {HighlightItem::None};bool m_strategyAddingCommand {false};+ QScopedPointer<KisSignalMapper> m_textTypeSignalsMapper;+SvgTextCursor m_textCursor;KisSignalAutoConnectionsStore m_canvasConnections;diff --git a/plugins/tools/svgtexttool/SvgTextToolFactory.cpp b/plugins/tools/svgtexttool/SvgTextToolFactory.cppindex 956dd98ea4..afc4e4a866 100644--- a/plugins/tools/svgtexttool/SvgTextToolFactory.cpp+++ b/plugins/tools/svgtexttool/SvgTextToolFactory.cpp@@ -43,6 +43,9 @@ QList<QAction *> SvgTextToolFactory::createActionsImpl()actions << KisActionRegistry::instance()->makeQAction("svg_insert_special_character", this);actions << KisActionRegistry::instance()->makeQAction("svg_paste_rich_text", this);actions << KisActionRegistry::instance()->makeQAction("svg_paste_plain_text", this);+ actions << KisActionRegistry::instance()->makeQAction("text_type_preformatted", this);+ actions << KisActionRegistry::instance()->makeQAction("text_type_pre_positioned", this);+ actions << KisActionRegistry::instance()->makeQAction("text_type_inline_wrap", this);return actions;}diff --git a/plugins/tools/svgtexttool/SvgTextToolOptions.qml b/plugins/tools/svgtexttool/SvgTextToolOptions.qmlindex 2f5e3c4831..e88b92fcfc 100644--- a/plugins/tools/svgtexttool/SvgTextToolOptions.qml+++ b/plugins/tools/svgtexttool/SvgTextToolOptions.qml@@ -269,7 +269,7 @@ Control {}Button {id: btnPrepositioned;- text: i18nc("@label:button", "Prepositioned");+ text: i18nc("@label:button", "Pre-positioned");property int type: SvgTextToolOptionsManager.PrePositionedText;Layout.fillWidth: true;ButtonGroup.group: textType;