From bf636b2d4c218554f044262c6a5733212ebc2e54 Mon Sep 17 00:00:00 2001 From: Lucid Sunlight Date: Wed, 18 Nov 2020 13:00:37 +0700 Subject: [PATCH 1/4] Don't switch to the same editor tab again If we do, we're converting the contents of the other tab to the current tab, and reverting all changes we've made (even if we saved). BUG:424213 --- plugins/tools/svgtexttool/SvgTextEditor.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/tools/svgtexttool/SvgTextEditor.cpp b/plugins/tools/svgtexttool/SvgTextEditor.cpp index 21cd79e8ae..921b013aa9 100644 --- a/plugins/tools/svgtexttool/SvgTextEditor.cpp +++ b/plugins/tools/svgtexttool/SvgTextEditor.cpp @@ -425,7 +425,8 @@ void SvgTextEditor::switchTextEditorTab(bool convertData) disconnect(m_currentEditor->document(), SIGNAL(modificationChanged(bool)), this, SLOT(setModified(bool))); } - if (isRichTextEditorActive()) { + // do not switch to the same tab again, otherwise we're losing current changes + if (m_currentEditor != m_textEditorWidget.richTextEdit && isRichTextEditorActive()) { //first, make buttons checkable enableRichTextActions(true); enableSvgTextActions(false); @@ -444,7 +445,7 @@ void SvgTextEditor::switchTextEditorTab(bool convertData) doc->clearUndoRedoStacks(); } m_currentEditor = m_textEditorWidget.richTextEdit; - } else if (isSvgSourceEditorActive()) { + } else if (m_currentEditor != m_textEditorWidget.svgTextEdit && isSvgSourceEditorActive()) { //first, make buttons uncheckable enableRichTextActions(false); enableSvgTextActions(true); -- GitLab From 03411445d93e5668e238ea0d24437752783b2f27 Mon Sep 17 00:00:00 2001 From: Lucid Sunlight Date: Wed, 18 Nov 2020 13:09:21 +0700 Subject: [PATCH 2/4] Rename `is*EditorActive` to `is*EditorTabActive` We're technically checking which tab is active, not editor. --- plugins/tools/svgtexttool/SvgTextEditor.cpp | 44 ++++++++++----------- plugins/tools/svgtexttool/SvgTextEditor.h | 4 +- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/plugins/tools/svgtexttool/SvgTextEditor.cpp b/plugins/tools/svgtexttool/SvgTextEditor.cpp index 921b013aa9..74a7d6ab57 100644 --- a/plugins/tools/svgtexttool/SvgTextEditor.cpp +++ b/plugins/tools/svgtexttool/SvgTextEditor.cpp @@ -398,7 +398,7 @@ void SvgTextEditor::setInitialShape(KoSvgTextShape *shape) void SvgTextEditor::save() { if (m_shape) { - if (isRichTextEditorActive()) { + if (isRichTextEditorTabActive()) { QString svg; QString styles = m_textEditorWidget.svgStylesEdit->document()->toPlainText(); KoSvgTextShapeMarkupConverter converter(m_shape); @@ -408,7 +408,7 @@ void SvgTextEditor::save() } m_textEditorWidget.richTextEdit->document()->setModified(false); emit textUpdated(m_shape, svg, styles, true); - } else if (isSvgSourceEditorActive()) { + } else if (isSvgSourceEditorTabActive()) { emit textUpdated(m_shape, m_textEditorWidget.svgTextEdit->document()->toPlainText(), m_textEditorWidget.svgStylesEdit->document()->toPlainText(), false); m_textEditorWidget.svgTextEdit->document()->setModified(false); } @@ -426,7 +426,7 @@ void SvgTextEditor::switchTextEditorTab(bool convertData) } // do not switch to the same tab again, otherwise we're losing current changes - if (m_currentEditor != m_textEditorWidget.richTextEdit && isRichTextEditorActive()) { + if (m_currentEditor != m_textEditorWidget.richTextEdit && isRichTextEditorTabActive()) { //first, make buttons checkable enableRichTextActions(true); enableSvgTextActions(false); @@ -445,7 +445,7 @@ void SvgTextEditor::switchTextEditorTab(bool convertData) doc->clearUndoRedoStacks(); } m_currentEditor = m_textEditorWidget.richTextEdit; - } else if (m_currentEditor != m_textEditorWidget.svgTextEdit && isSvgSourceEditorActive()) { + } else if (m_currentEditor != m_textEditorWidget.svgTextEdit && isSvgSourceEditorTabActive()) { //first, make buttons uncheckable enableRichTextActions(false); enableSvgTextActions(true); @@ -676,7 +676,7 @@ void SvgTextEditor::insertCharacter(const QChar &c) void SvgTextEditor::setTextBold(QFont::Weight weight) { - if (isRichTextEditorActive()) { + if (isRichTextEditorTabActive()) { QTextCharFormat format; QTextCursor oldCursor = setTextSelection(); if (m_textEditorWidget.richTextEdit->textCursor().charFormat().fontWeight() > QFont::Normal && weight==QFont::Bold) { @@ -686,7 +686,7 @@ void SvgTextEditor::setTextBold(QFont::Weight weight) } m_textEditorWidget.richTextEdit->mergeCurrentCharFormat(format); m_textEditorWidget.richTextEdit->setTextCursor(oldCursor); - } else if (isSvgSourceEditorActive()) { + } else if (isSvgSourceEditorTabActive()) { QTextCursor cursor = m_textEditorWidget.svgTextEdit->textCursor(); if (cursor.hasSelection()) { QString selectionModified = "" + cursor.selectedText() + ""; @@ -745,13 +745,13 @@ void SvgTextEditor::setTextItalic(QFont::Style style) } - if (isRichTextEditorActive()) { + if (isRichTextEditorTabActive()) { QTextCharFormat format; QTextCursor origCursor = setTextSelection(); format.setFontItalic(!m_textEditorWidget.richTextEdit->textCursor().charFormat().fontItalic()); m_textEditorWidget.richTextEdit->mergeCurrentCharFormat(format); m_textEditorWidget.richTextEdit->setTextCursor(origCursor); - } else if (isSvgSourceEditorActive()) { + } else if (isSvgSourceEditorTabActive()) { if (cursor.hasSelection()) { QString selectionModified = "" + cursor.selectedText() + ""; cursor.removeSelectedText(); @@ -801,9 +801,9 @@ void SvgTextEditor::setTextDecoration(KoSvgText::TextDecoration decor) format.setFontStrikeOut(false); } - if (isRichTextEditorActive()) { + if (isRichTextEditorTabActive()) { m_textEditorWidget.richTextEdit->mergeCurrentCharFormat(format); - } else if (isSvgSourceEditorActive()) { + } else if (isSvgSourceEditorTabActive()) { if (cursor.hasSelection()) { QString selectionModified = "" + cursor.selectedText() + ""; cursor.removeSelectedText(); @@ -899,13 +899,13 @@ void SvgTextEditor::setLineHeight(double lineHeightPercentage) void SvgTextEditor::setLetterSpacing(double letterSpacing) { QTextCursor cursor = setTextSelection(); - if (isRichTextEditorActive()) { + if (isRichTextEditorTabActive()) { QTextCharFormat format; format.setFontLetterSpacingType(QFont::AbsoluteSpacing); format.setFontLetterSpacing(letterSpacing); m_textEditorWidget.richTextEdit->mergeCurrentCharFormat(format); m_textEditorWidget.richTextEdit->setTextCursor(cursor); - } else if (isSvgSourceEditorActive()) { + } else if (isSvgSourceEditorTabActive()) { if (cursor.hasSelection()) { QString selectionModified = "" + cursor.selectedText() + ""; cursor.removeSelectedText(); @@ -1068,13 +1068,13 @@ void SvgTextEditor::slotToolbarToggled(bool) void SvgTextEditor::setFontColor(const KoColor &c) { QColor color = c.toQColor(); - if (isRichTextEditorActive()) { + if (isRichTextEditorTabActive()) { QTextCursor oldCursor = setTextSelection(); QTextCharFormat format; format.setForeground(QBrush(color)); m_textEditorWidget.richTextEdit->mergeCurrentCharFormat(format); m_textEditorWidget.richTextEdit->setTextCursor(oldCursor); - } else if (isSvgSourceEditorActive()) { + } else if (isSvgSourceEditorTabActive()) { QTextCursor cursor = m_textEditorWidget.svgTextEdit->textCursor(); if (cursor.hasSelection()) { QString selectionModified = "" + cursor.selectedText() + ""; @@ -1126,11 +1126,11 @@ void SvgTextEditor::setFont(const QString &fontName) QTextCharFormat format; //This disables the style being set from the font-comboboxes too, so we need to rethink how we use that. format.setFontFamily(font.family()); - if (isRichTextEditorActive()) { + if (isRichTextEditorTabActive()) { QTextCursor oldCursor = setTextSelection(); m_textEditorWidget.richTextEdit->mergeCurrentCharFormat(format); m_textEditorWidget.richTextEdit->setTextCursor(oldCursor); - } else if (isSvgSourceEditorActive()) { + } else if (isSvgSourceEditorTabActive()) { QTextCursor cursor = m_textEditorWidget.svgTextEdit->textCursor(); if (cursor.hasSelection()) { QString selectionModified = "" + cursor.selectedText() + ""; @@ -1144,13 +1144,13 @@ void SvgTextEditor::setFont(const QString &fontName) void SvgTextEditor::setFontSize(qreal fontSize) { - if (isRichTextEditorActive()) { + if (isRichTextEditorTabActive()) { QTextCursor oldCursor = setTextSelection(); QTextCharFormat format; format.setFontPointSize(fontSize); m_textEditorWidget.richTextEdit->mergeCurrentCharFormat(format); m_textEditorWidget.richTextEdit->setTextCursor(oldCursor); - } else if (isSvgSourceEditorActive()) { + } else if (isSvgSourceEditorTabActive()) { QTextCursor cursor = m_textEditorWidget.svgTextEdit->textCursor(); if (cursor.hasSelection()) { QString selectionModified = "" + cursor.selectedText() + ""; @@ -1177,13 +1177,13 @@ void SvgTextEditor::setKerning(bool enable) { d->kerning = enable; - if (isRichTextEditorActive()) { + if (isRichTextEditorTabActive()) { QTextCharFormat format; QTextCursor origCursor = setTextSelection(); format.setFontKerning(enable); m_textEditorWidget.richTextEdit->mergeCurrentCharFormat(format); m_textEditorWidget.richTextEdit->setTextCursor(origCursor); - } else if (isSvgSourceEditorActive()) { + } else if (isSvgSourceEditorTabActive()) { QTextCursor cursor = m_textEditorWidget.svgTextEdit->textCursor(); if (cursor.hasSelection()) { @@ -1460,13 +1460,13 @@ void SvgTextEditor::enableSvgTextActions(bool enable) } } -bool SvgTextEditor::isRichTextEditorActive() { +bool SvgTextEditor::isRichTextEditorTabActive() { return m_currentEditorMode == EditorMode::RichText || (m_currentEditorMode == EditorMode::Both && m_textEditorWidget.textTab->currentIndex() == Editor::Richtext); } -bool SvgTextEditor::isSvgSourceEditorActive() { +bool SvgTextEditor::isSvgSourceEditorTabActive() { return m_currentEditorMode == EditorMode::SvgSource || (m_currentEditorMode == EditorMode::Both && m_textEditorWidget.textTab->currentIndex() == Editor::SVGsource); diff --git a/plugins/tools/svgtexttool/SvgTextEditor.h b/plugins/tools/svgtexttool/SvgTextEditor.h index b6efafe2d0..6a563b708d 100644 --- a/plugins/tools/svgtexttool/SvgTextEditor.h +++ b/plugins/tools/svgtexttool/SvgTextEditor.h @@ -153,8 +153,8 @@ private: void createActions(); void enableRichTextActions(bool enable); void enableSvgTextActions(bool enable); - bool isRichTextEditorActive(); - bool isSvgSourceEditorActive(); + bool isRichTextEditorTabActive(); + bool isSvgSourceEditorTabActive(); Ui_WdgSvgTextEditor m_textEditorWidget; EditorMode m_currentEditorMode {EditorMode::Both}; -- GitLab From 03cbf8119d4365da9742a6ee7996b9983f786e30 Mon Sep 17 00:00:00 2001 From: Lucid Sunlight Date: Wed, 18 Nov 2020 13:09:45 +0700 Subject: [PATCH 3/4] Remove unused variable --- plugins/tools/svgtexttool/SvgTextEditor.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugins/tools/svgtexttool/SvgTextEditor.cpp b/plugins/tools/svgtexttool/SvgTextEditor.cpp index 74a7d6ab57..e1e385cf6f 100644 --- a/plugins/tools/svgtexttool/SvgTextEditor.cpp +++ b/plugins/tools/svgtexttool/SvgTextEditor.cpp @@ -454,8 +454,6 @@ void SvgTextEditor::switchTextEditorTab(bool convertData) // Convert the rich text to svg and styles strings if (m_shape && convertData) { QString svg; - QString styles; - if (!converter.convertDocumentToSvg(m_textEditorWidget.richTextEdit->document(), &svg)) { qWarning()<<"new converter docToSVG doesn't work!"; } -- GitLab From 6759a183e28773e4972be7346c2aff797a0200f3 Mon Sep 17 00:00:00 2001 From: Lucid Sunlight Date: Wed, 18 Nov 2020 13:51:28 +0700 Subject: [PATCH 4/4] Consistently use fully named `Editor` and `EditorMode` enum variants First two variants can and were used interchangeably, but let's be explicit about it. --- plugins/tools/svgtexttool/SvgTextEditor.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/tools/svgtexttool/SvgTextEditor.cpp b/plugins/tools/svgtexttool/SvgTextEditor.cpp index e1e385cf6f..e454cc8838 100644 --- a/plugins/tools/svgtexttool/SvgTextEditor.cpp +++ b/plugins/tools/svgtexttool/SvgTextEditor.cpp @@ -364,12 +364,12 @@ void SvgTextEditor::setInitialShape(KoSvgTextShape *shape) m_textEditorWidget.richTextEdit->setDocument(doc); KisSignalsBlocker b(m_textEditorWidget.textTab); - m_textEditorWidget.textTab->setCurrentIndex(Richtext); + m_textEditorWidget.textTab->setCurrentIndex(Editor::Richtext); doc->clearUndoRedoStacks(); switchTextEditorTab(false); } else { KisSignalsBlocker b(m_textEditorWidget.textTab); - m_textEditorWidget.textTab->setCurrentIndex(SvgSource); + m_textEditorWidget.textTab->setCurrentIndex(Editor::SVGsource); switchTextEditorTab(false); } } @@ -1023,13 +1023,13 @@ void SvgTextEditor::setSettings() cfg.writeEntry("selectedWritingSystems", writingSystems.join(',')); if (textSettings.radioRichText->isChecked()) { - cfg.writeEntry("EditorMode", (int)Richtext); + cfg.writeEntry("EditorMode", (int)EditorMode::RichText); } else if (textSettings.radioSvgSource->isChecked()) { - cfg.writeEntry("EditorMode", (int)SvgSource); + cfg.writeEntry("EditorMode", (int)EditorMode::SvgSource); } else if (textSettings.radioBoth->isChecked()) { - cfg.writeEntry("EditorMode", (int)Both); + cfg.writeEntry("EditorMode", (int)EditorMode::Both); } cfg.writeEntry("colorEditorBackground", textSettings.colorEditorBackground->color()); -- GitLab