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 separate actions for paste rich/plain text in svg text tool.
Wolthera van Hövell tot Westerflier9e50d818a4cf
diff --git a/plugins/tools/svgtexttool/SvgTextCursor.cpp b/plugins/tools/svgtexttool/SvgTextCursor.cppindex 7e0a63e37b..ea1efcb2c4 100644--- a/plugins/tools/svgtexttool/SvgTextCursor.cpp+++ b/plugins/tools/svgtexttool/SvgTextCursor.cpp@@ -419,13 +419,19 @@ void SvgTextCursor::copy() const}bool SvgTextCursor::paste()+{+ bool success = d->pasteRichText? pasteRichText(): pastePlainText();+ return success;+}++bool SvgTextCursor::pasteRichText(){bool success = false;if (d->shape) {QClipboard *cb = QApplication::clipboard();const QMimeData *mimeData = cb->mimeData();KoSvgPaste shapePaste;- if (d->pasteRichText && shapePaste.hasShapes()) {+ if (shapePaste.hasShapes()) {QList<KoShape*> shapes = shapePaste.fetchShapes(d->shape->boundingRect(), 72.0);while (shapes.size() > 0) {KoSvgTextShape *textShape = dynamic_cast<KoSvgTextShape*>(shapes.takeFirst());@@ -434,7 +440,7 @@ bool SvgTextCursor::paste()success = true;}}- } else if (d->pasteRichText && mimeData->hasHtml()) {+ } else if (mimeData->hasHtml()) {QString html = mimeData->html();KoSvgTextShape *insert = new KoSvgTextShape();KoSvgTextShapeMarkupConverter converter(insert);@@ -447,14 +453,25 @@ bool SvgTextCursor::paste()}}- if (mimeData->hasText() && !success) {- insertText(mimeData->text());- success = true;+ if (!success) {+ success = pastePlainText();}}return success;}+bool SvgTextCursor::pastePlainText()+{+ bool success = false;+ QClipboard *cb = QApplication::clipboard();+ const QMimeData *mimeData = cb->mimeData();+ if (mimeData->hasText()) {+ insertText(mimeData->text());+ success = true;+ }+ return success;+}+void SvgTextCursor::deselectText(){setPos(d->pos, d->pos);@@ -1239,6 +1256,14 @@ bool SvgTextCursor::registerPropertyAction(QAction *action, const QString &name)d->actions.append(action);connect(action, SIGNAL(triggered(bool)), this, SIGNAL(sigOpenGlyphPalette()));return true;+ } else if (name == "svg_paste_rich_text") {+ d->actions.append(action);+ connect(action, SIGNAL(triggered(bool)), this, SLOT(pasteRichText()));+ return true;+ } else if (name == "svg_paste_plain_text") {+ d->actions.append(action);+ connect(action, SIGNAL(triggered(bool)), this, SLOT(pastePlainText()));+ return true;}return false;}diff --git a/plugins/tools/svgtexttool/SvgTextCursor.h b/plugins/tools/svgtexttool/SvgTextCursor.hindex 7a64543dab..d47e3fbf46 100644--- a/plugins/tools/svgtexttool/SvgTextCursor.h+++ b/plugins/tools/svgtexttool/SvgTextCursor.h@@ -161,10 +161,14 @@ public:void copy() const;/*** @brief paste- * @return pastes plain text in the clipboard at pos.+ * pastes plain text in the clipboard at pos.+ * Uses pasteRichTextByDefault to determine whether+ * to try and paste rich text.+ * @return true when successfull.*/bool paste();+void deselectText();void paintDecorations(QPainter &gc, QColor selectionColor, int decorationThickness = 1);@@ -197,6 +201,7 @@ public:/// Stops blinking cursor.void focusOut();+ /// Register an action.bool registerPropertyAction(QAction *action, const QString &name);KoSvgTextPropertiesInterface *textPropertyInterface();@@ -216,6 +221,19 @@ private Q_SLOTS:void toggleProperty(KoSvgTextProperties::PropertyId property);void propertyAction();+ /**+ * @brief pasteRichText+ * @return try to paste rich text at pos.+ */+ bool pasteRichText();++ /**+ * @brief pastePlainText+ * Explicitely paste plaintext at pos.+ * @return true when successfull.+ */+ bool pastePlainText();+private:/**diff --git a/plugins/tools/svgtexttool/SvgTextTool.action b/plugins/tools/svgtexttool/SvgTextTool.actionindex 77fe862e93..1c0be477a5 100644--- a/plugins/tools/svgtexttool/SvgTextTool.action+++ b/plugins/tools/svgtexttool/SvgTextTool.action@@ -202,5 +202,25 @@<isCheckable>true</isCheckable><text>Kerning</text></Action>- </Actions>+ <Action name="svg_paste_rich_text">+ <iconText>Paste Rich Text</iconText>+ <shortcut></shortcut>+ <toolTip>Try to paste styled text if possible.</toolTip>+ <icon>edit-paste</icon>+ <whatsThis/>+ <statusTip/>+ <isCheckable>false</isCheckable>+ <text>Paste Rich Text</text>+ </Action>+ <Action name="svg_paste_plain_text">+ <iconText>Paste Plain Text</iconText>+ <shortcut></shortcut>+ <toolTip>Paste text without styling.</toolTip>+ <icon>edit-paste</icon>+ <whatsThis/>+ <statusTip/>+ <isCheckable>false</isCheckable>+ <text>Paste Plain Text</text>+ </Action>+ </Actions></ActionCollection>diff --git a/plugins/tools/svgtexttool/SvgTextTool.cpp b/plugins/tools/svgtexttool/SvgTextTool.cppindex 82d4b40114..7ec2625d56 100644--- a/plugins/tools/svgtexttool/SvgTextTool.cpp+++ b/plugins/tools/svgtexttool/SvgTextTool.cpp@@ -106,11 +106,19 @@ SvgTextTool::SvgTextTool(KoCanvasBase *canvas)}}- const QString glyphName = "svg_insert_special_character";- QAction *glyphAction = action(glyphName);- if (glyphAction) {- m_textCursor.registerPropertyAction(glyphAction, glyphName);- connect(&m_textCursor, SIGNAL(sigOpenGlyphPalette()), this, SLOT(showGlyphPalette()));+ const QStringList extraActions = {+ "svg_insert_special_character",+ "svg_paste_rich_text",+ "svg_paste_plain_text"+ };+ connect(&m_textCursor, SIGNAL(sigOpenGlyphPalette()), this, SLOT(showGlyphPalette()));+ Q_FOREACH (const QString name, extraActions) {+ QAction *a = action(name);+ if (a) {+ if(!m_textCursor.registerPropertyAction(a, name)) {+ qWarning() << "could not register" << name << a->shortcut();+ }+ }}m_base_cursor = QCursor(QPixmap(":/tool_text_basic.xpm"), 7, 7);diff --git a/plugins/tools/svgtexttool/SvgTextToolFactory.cpp b/plugins/tools/svgtexttool/SvgTextToolFactory.cppindex a5b06c252a..956dd98ea4 100644--- a/plugins/tools/svgtexttool/SvgTextToolFactory.cpp+++ b/plugins/tools/svgtexttool/SvgTextToolFactory.cpp@@ -41,6 +41,8 @@ QList<QAction *> SvgTextToolFactory::createActionsImpl()actions << KisActionRegistry::instance()->makeQAction(name, this);}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);return actions;}