Skip to content

armgit / krita

Public Imported from GitHub
0

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++

Implement clear formatting action for text.

Wolthera van Hövell tot Westerflier7d99ce6a6458
diff --git a/libs/flake/text/KoSvgTextProperties.h b/libs/flake/text/KoSvgTextProperties.h
index 6bca73bbbc..95585e4eb0 100644
--- a/libs/flake/text/KoSvgTextProperties.h
+++ b/libs/flake/text/KoSvgTextProperties.h
@@ -119,6 +119,8 @@ public:
KraTextVersionId, ///< Int, used for handling incorrectly saved files.
KraTextStyleType, ///< string, used to identify the style preset type (character or paragraph).
KraTextStyleResolution, ///< Int, used to scale style presets to be pixel-relative.
+
+ LastPropertyId ///< Last Property ID, used for iteration.
};
KoSvgTextProperties();
diff --git a/plugins/tools/svgtexttool/SvgTextCursor.cpp b/plugins/tools/svgtexttool/SvgTextCursor.cpp
index fcf14ac4aa..268b911a69 100644
--- a/plugins/tools/svgtexttool/SvgTextCursor.cpp
+++ b/plugins/tools/svgtexttool/SvgTextCursor.cpp
@@ -1263,6 +1263,19 @@ void SvgTextCursor::propertyAction()
mergePropertiesIntoSelection(properties);
}
+void SvgTextCursor::clearFormattingAction()
+{
+ KoSvgTextProperties props;
+
+ QSet<KoSvgTextProperties::PropertyId> ids;
+
+ for (int i = 0; i < int(KoSvgTextProperties::LastPropertyId); i++) {
+ ids.insert(KoSvgTextProperties::PropertyId(i));
+ }
+
+ mergePropertiesIntoSelection(props, ids);
+}
+
bool SvgTextCursor::hasSelection()
{
return d->pos != d->anchor;
@@ -1578,6 +1591,10 @@ bool SvgTextCursor::registerPropertyAction(QAction *action, const QString &name)
d->actions.append(action);
connect(action, SIGNAL(triggered(bool)), this, SLOT(removeTransformsFromRange()));
return true;
+ } else if (name == "svg_clear_formatting") {
+ d->actions.append(action);
+ connect(action, SIGNAL(triggered(bool)), this, SLOT(clearFormattingAction()));
+ return true;
} else if (action) {
d->actions.append(action);
return true;
diff --git a/plugins/tools/svgtexttool/SvgTextCursor.h b/plugins/tools/svgtexttool/SvgTextCursor.h
index 09810f7e47..099a77f0cd 100644
--- a/plugins/tools/svgtexttool/SvgTextCursor.h
+++ b/plugins/tools/svgtexttool/SvgTextCursor.h
@@ -277,6 +277,7 @@ private Q_SLOTS:
void canvasResourceChanged(int key, const QVariant &value);
void toggleProperty(KoSvgTextProperties::PropertyId property);
void propertyAction();
+ void clearFormattingAction();
/**
* @brief pasteRichText
diff --git a/plugins/tools/svgtexttool/SvgTextTool.action b/plugins/tools/svgtexttool/SvgTextTool.action
index 31b5f929a1..149c6cf369 100644
--- a/plugins/tools/svgtexttool/SvgTextTool.action
+++ b/plugins/tools/svgtexttool/SvgTextTool.action
@@ -277,5 +277,16 @@
<statusTip/>
<isCheckable>false</isCheckable>
</Action>
+
+<Action name="svg_clear_formatting">
+ <iconText>Clear Formatting</iconText>
+ <text>Clear Formatting</text>
+ <shortcut>edit-clear</shortcut>
+ <toolTip>Remove all set text properties from the selection.</toolTip>
+ <icon></icon>
+ <whatsThis/>
+ <statusTip/>
+ <isCheckable>false</isCheckable>
+</Action>
</Actions>
</ActionCollection>
diff --git a/plugins/tools/svgtexttool/SvgTextTool.cpp b/plugins/tools/svgtexttool/SvgTextTool.cpp
index 449e4da975..5d1888cfd9 100644
--- a/plugins/tools/svgtexttool/SvgTextTool.cpp
+++ b/plugins/tools/svgtexttool/SvgTextTool.cpp
@@ -116,7 +116,8 @@ SvgTextTool::SvgTextTool(KoCanvasBase *canvas)
"svg_insert_special_character",
"svg_paste_rich_text",
"svg_paste_plain_text",
- "svg_remove_transforms_from_range"
+ "svg_remove_transforms_from_range",
+ "svg_clear_formatting"
};
connect(&m_textCursor, SIGNAL(sigOpenGlyphPalette()), this, SLOT(showGlyphPalette()));
Q_FOREACH (const QString name, extraActions) {
diff --git a/plugins/tools/svgtexttool/SvgTextToolFactory.cpp b/plugins/tools/svgtexttool/SvgTextToolFactory.cpp
index b46c0951d3..dc357572df 100644
--- a/plugins/tools/svgtexttool/SvgTextToolFactory.cpp
+++ b/plugins/tools/svgtexttool/SvgTextToolFactory.cpp
@@ -52,6 +52,7 @@ QList<QAction *> SvgTextToolFactory::createActionsImpl()
actions << KisActionRegistry::instance()->makeQAction("svg_type_setting_move_selection_start_left_1_px", this);
actions << KisActionRegistry::instance()->makeQAction("svg_type_setting_move_selection_start_right_1_px", this);
actions << KisActionRegistry::instance()->makeQAction("svg_remove_transforms_from_range", this);
+ actions << KisActionRegistry::instance()->makeQAction("svg_clear_formatting", this);
return actions;
}