Commit 3540f1ae authored by Dmitry Kazakov's avatar Dmitry Kazakov

Properly fix font resetting when all the text in the editor removed

When removing the last block of the text, we should make sure that the
cursor has the format set (it is automatically reset to the default).

BUG:409243
parent b7872b8a
......@@ -231,7 +231,8 @@ void SvgTextEditor::switchTextEditorTab(bool convertData)
//then connect the cursor change to the checkformat();
connect(m_textEditorWidget.richTextEdit, SIGNAL(cursorPositionChanged()), this, SLOT(checkFormat()));
connect(m_textEditorWidget.richTextEdit, SIGNAL(textChanged()), this, SLOT(slotFixUpEmptyTextBlock()));
checkFormat();
if (m_shape && convertData) {
QTextDocument *doc = m_textEditorWidget.richTextEdit->document();
......@@ -270,11 +271,6 @@ void SvgTextEditor::checkFormat()
QTextCharFormat format = m_textEditorWidget.richTextEdit->textCursor().charFormat();
QTextBlockFormat blockFormat = m_textEditorWidget.richTextEdit->textCursor().blockFormat();
/**
* Make sure that when we remove the very last symbol, the last used font will not change
*/
m_textEditorWidget.richTextEdit->document()->setDefaultFont(format.font());
// checkboxes do not emit signals on manual switching, so we
// can avoid blocking them
......@@ -332,6 +328,33 @@ void SvgTextEditor::checkFormat()
}
}
void SvgTextEditor::slotFixUpEmptyTextBlock()
{
if (m_textEditorWidget.richTextEdit->document()->isEmpty()) {
QTextCursor cursor = m_textEditorWidget.richTextEdit->textCursor();
QTextCharFormat format = cursor.blockCharFormat();
{
FontSizeAction *fontSizeAction = qobject_cast<FontSizeAction*>(actionCollection()->action("svg_font_size"));
KisFontComboBoxes* fontComboBox = qobject_cast<KisFontComboBoxes*>(qobject_cast<QWidgetAction*>(actionCollection()->action("svg_font"))->defaultWidget());
format.setFont(fontComboBox->currentFont(fontSizeAction->fontSize()));
}
{
KoColorPopupAction *fgColorPopup = qobject_cast<KoColorPopupAction*>(actionCollection()->action("svg_format_textcolor"));
format.setForeground(fgColorPopup->currentColor());
}
{
//KoColorPopupAction *bgColorPopup = qobject_cast<KoColorPopupAction*>(actionCollection()->action("svg_background_color"));
//format.setBackground(bgColorPopup->currentColor());
}
KisSignalsBlocker b(m_textEditorWidget.richTextEdit);
cursor.setBlockCharFormat(format);
}
}
void SvgTextEditor::undo()
{
m_currentEditor->undo();
......@@ -1003,9 +1026,15 @@ void SvgTextEditor::applySettings()
for (int i=0; i<selectedWritingSystems.size(); i++) {
writingSystems.append((QFontDatabase::WritingSystem)QString(selectedWritingSystems.at(i)).toInt());
}
qobject_cast<KisFontComboBoxes*>(qobject_cast<QWidgetAction*>(actionCollection()->action("svg_font"))->defaultWidget())->refillComboBox(writingSystems);
{
FontSizeAction *fontSizeAction = qobject_cast<FontSizeAction*>(actionCollection()->action("svg_font_size"));
KisFontComboBoxes* fontComboBox = qobject_cast<KisFontComboBoxes*>(qobject_cast<QWidgetAction*>(actionCollection()->action("svg_font"))->defaultWidget());
const QFont oldFont = fontComboBox->currentFont(fontSizeAction->fontSize());
fontComboBox->refillComboBox(writingSystems);
fontComboBox->setCurrentFont(oldFont);
}
m_page->setUpdatesEnabled(true);
}
......
......@@ -71,6 +71,8 @@ private Q_SLOTS:
*/
void checkFormat();
void slotFixUpEmptyTextBlock();
void save();
void undo();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment