Commit dc14cb27 authored by Ivan Yossi's avatar Ivan Yossi 👌

Add letter-spacing edit option to TextEditor

BUG:364167
parent ad31625e
......@@ -276,7 +276,7 @@ bool KoSvgTextShapeMarkupConverter::convertFromHtml(const QString &htmlText, QSt
if (attributes.hasAttribute("style")) {
QString filteredStyles;
QStringList svgStyles = QString("font-family font-size font-weight font-variant word-spacing text-decoration font-style font-size-adjust font-stretch direction").split(" ");
QStringList svgStyles = QString("font-family font-size font-weight font-variant word-spacing text-decoration font-style font-size-adjust font-stretch direction letter-spacing").split(" ");
QStringList styles = attributes.value("style").toString().split(";");
for(int i=0; i<styles.size(); i++) {
QStringList style = QString(styles.at(i)).split(":");
......@@ -1245,6 +1245,8 @@ QTextFormat KoSvgTextShapeMarkupConverter::formatDifference(QTextFormat test, QT
// Some props must not be removed as default state gets in the way.
if (it.key() == 0x2023) { // TextUnderlineStyle
continue;
} else if (it.key() == 0x2033) { // FontLetterSpacingType
continue;
}
diff.clearProperty(it.key());
}
......
......@@ -319,6 +319,12 @@ void SvgTextEditor::checkFormat()
spnLineHeight->setValue(double(blockFormat.lineHeight()));
}
}
{
QDoubleSpinBox* spnLetterSpacing = qobject_cast<QDoubleSpinBox*>(qobject_cast<QWidgetAction*>(actionCollection()->action("svg_letter_spacing"))->defaultWidget());
KisSignalsBlocker b(spnLetterSpacing);
spnLetterSpacing->setValue(format.fontLetterSpacing());
}
}
void SvgTextEditor::undo()
......@@ -658,6 +664,24 @@ void SvgTextEditor::setLineHeight(double lineHeightPercentage)
m_textEditorWidget.richTextEdit->setTextCursor(oldCursor);
}
void SvgTextEditor::setLetterSpacing(double letterSpacing)
{
QTextCursor cursor = setTextSelection();
if (m_textEditorWidget.textTab->currentIndex() == Richtext) {
QTextCharFormat format;
format.setFontLetterSpacingType(QFont::AbsoluteSpacing);
format.setFontLetterSpacing(letterSpacing);
m_textEditorWidget.richTextEdit->mergeCurrentCharFormat(format);
m_textEditorWidget.richTextEdit->setTextCursor(cursor);
}
else {
if (cursor.hasSelection()) {
QString selectionModified = "<tspan style=\"letter-spacing:" + QString::number(letterSpacing) + "\">" + cursor.selectedText() + "</tspan>";
cursor.removeSelectedText();
cursor.insertText(selectionModified);
}
}
}
void SvgTextEditor::alignLeft()
{
......@@ -1126,6 +1150,17 @@ void SvgTextEditor::createActions()
actionCollection()->addAction("svg_line_height", lineHeight);
m_richTextActions << lineHeight;
actionRegistry->propertizeAction("svg_line_height", lineHeight);
QWidgetAction *letterSpacing = new QWidgetAction(this);
QDoubleSpinBox *spnletterSpacing = new QDoubleSpinBox();
spnletterSpacing->setToolTip(i18n("Letter Spacing"));
spnletterSpacing->setRange(-20.0, 20.0);
spnletterSpacing->setSingleStep(0.5);
connect(spnletterSpacing, SIGNAL(valueChanged(double)), SLOT(setLetterSpacing(double)));
letterSpacing->setDefaultWidget(spnletterSpacing);
actionCollection()->addAction("svg_letter_spacing", letterSpacing);
m_richTextActions << letterSpacing;
actionRegistry->propertizeAction("svg_letter_spacing", letterSpacing);
}
void SvgTextEditor::enableRichTextActions(bool enable)
......
......@@ -111,6 +111,7 @@ private Q_SLOTS:
void decreaseTextSize();
void setLineHeight(double lineHeightPercentage);
void setLetterSpacing(double letterSpacing);
void alignLeft();
void alignRight();
void alignCenter();
......
......@@ -94,6 +94,7 @@
<Action name="svg_align_right"/>
<Action name="svg_line_height">
</Action>
<Action name="svg_letter_spacing"></Action>
</ToolBar>
......
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