From kde-commits Fri Jun 30 20:45:55 2017 From: =?utf-8?q?Wolthera_van_H=C3=B6vell_tot_Westerflier?= Date: Fri, 30 Jun 2017 20:45:55 +0000 To: kde-commits Subject: [krita/rempt/T1004-recreate-the-text-tool] plugins/tools/svgtexttool: Add a rich text editor tab, at Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=149885556727973 Git commit 55084c1111bbd990094b9fbb51e97c1b0b0ef83c by Wolthera van H=C3=B6= vell tot Westerflier. Committed on 30/06/2017 at 20:45. Pushed by woltherav into branch 'rempt/T1004-recreate-the-text-tool'. Add a rich text editor tab, attach some functions, and other stuff. Don't code when traveling, this ends with attempting to do 5 things at once= ... M +256 -70 plugins/tools/svgtexttool/SvgTextEditor.cpp M +27 -5 plugins/tools/svgtexttool/SvgTextEditor.h M +209 -90 plugins/tools/svgtexttool/WdgSvgTextEditor.ui https://commits.kde.org/krita/55084c1111bbd990094b9fbb51e97c1b0b0ef83c diff --git a/plugins/tools/svgtexttool/SvgTextEditor.cpp b/plugins/tools/sv= gtexttool/SvgTextEditor.cpp index c1275c4341b..a6a9d1cbf90 100644 --- a/plugins/tools/svgtexttool/SvgTextEditor.cpp +++ b/plugins/tools/svgtexttool/SvgTextEditor.cpp @@ -24,12 +24,17 @@ #include #include #include +#include +#include +#include = #include = #include "KoSvgTextShape.h" #include "KoSvgTextShapeMarkupConverter.h" +#include = +#include #include #include = @@ -41,24 +46,64 @@ SvgTextEditor::SvgTextEditor(QWidget *parent, Qt::Windo= wFlags flags) widget.setupUi(m_page); setMainWidget(m_page); = - BasicXMLSyntaxHighlighter *hl =3D new BasicXMLSyntaxHighlighter(widget= .textEdit); + BasicXMLSyntaxHighlighter *hl =3D new BasicXMLSyntaxHighlighter(widget= .svgTextEdit); Q_UNUSED(hl); = connect(this, SIGNAL(okClicked()), SLOT(save())); - connect(widget.bnUndo, SIGNAL(clicked()), widget.textEdit, SLOT(undo()= )); - connect(widget.bnRedo, SIGNAL(clicked()), widget.textEdit, SLOT(redo()= )); - connect(widget.bnCopy, SIGNAL(clicked()), widget.textEdit, SLOT(copy()= )); - connect(widget.bnCut, SIGNAL(clicked()), widget.textEdit, SLOT(cut())); - connect(widget.bnPaste, SIGNAL(clicked()), widget.textEdit, SLOT(paste= ())); - - connect(widget.bnBold, SIGNAL(clicked()), this, SLOT(setTextBold())); - connect(widget.bnItalic, SIGNAL(clicked()), this, SLOT(setTextItalic()= )); - connect(widget.bnUnderline, SIGNAL(clicked()), this, SLOT(setTextUnder= line())); - connect(widget.bnStrikethrough, SIGNAL(clicked()), this, SLOT(setTextS= trikeThrough())); + connect(widget.bnUndo, SIGNAL(clicked()), widget.svgTextEdit, SLOT(und= o())); + connect(widget.bnRedo, SIGNAL(clicked()), widget.svgTextEdit, SLOT(red= o())); + connect(widget.bnCopy, SIGNAL(clicked()), widget.svgTextEdit, SLOT(cop= y())); + connect(widget.bnCut, SIGNAL(clicked()), widget.svgTextEdit, SLOT(cut(= ))); + connect(widget.bnPaste, SIGNAL(clicked()), widget.svgTextEdit, SLOT(pa= ste())); + connect(widget.textTab, SIGNAL(currentChanged(int)), this, SLOT(switch= TextEditorTab())); + switchTextEditorTab(); + + //make actions here// + QAction *makeBold =3D new QAction(KisIconUtils::loadIcon("format-text-= bold"), "Bold"); + connect(makeBold, SIGNAL(triggered(bool)), this, SLOT(setTextBold())); + QAction *makeWeightLight =3D new QAction("Light"); + connect(makeWeightLight, SIGNAL(triggered(bool)), this, SLOT(setTextWe= ightLight())); + QAction *makeWeightNormal =3D new QAction("Normal"); + connect(makeWeightNormal, SIGNAL(triggered(bool)), this, SLOT(setTextW= eightNormal())); + QAction *makeWeightDemi =3D new QAction("Demi-Bold"); + connect(makeWeightDemi, SIGNAL(triggered(bool)), this, SLOT(setTextWei= ghtDemi())); + QAction *makeWeightBlack =3D new QAction("Black"); + connect(makeWeightBlack, SIGNAL(triggered(bool)), this, SLOT(setTextWe= ightBlack())); + widget.bnBold->setDefaultAction(makeBold); + QList textWeightActions; + textWeightActions.append(makeWeightLight); + textWeightActions.append(makeWeightNormal); + textWeightActions.append(makeWeightDemi); + textWeightActions.append(makeBold); + textWeightActions.append(makeWeightBlack); + QMenu *textWeight =3D new QMenu(); + textWeight->addActions(textWeightActions); + widget.bnBold->setMenu(textWeight); + + QAction *makeItalic =3D new QAction(KisIconUtils::loadIcon("format-tex= t-italic"), "Italic"); + connect(makeItalic, SIGNAL(triggered(bool)), this, SLOT(setTextItalic(= ))); + widget.bnItalic->setDefaultAction(makeItalic); + + QAction *makeUnderline =3D new QAction(KisIconUtils::loadIcon("format-= text-underline"), "Underline"); + connect(makeUnderline, SIGNAL(triggered(bool)), this, SLOT(setTextUnde= rline())); + widget.bnUnderline->setDefaultAction(makeUnderline); + QAction *makeStrike =3D new QAction(KisIconUtils::loadIcon("format-tex= t-strikethrough"), "Strikethrough"); + connect(makeStrike, SIGNAL(triggered(bool)), this, SLOT(setTextStriket= hrough())); + QAction *makeOverline =3D new QAction("Overline"); + connect(makeOverline, SIGNAL(triggered(bool)), this, SLOT(setTextOverl= ine())); + QList textDecorActions; + textDecorActions.append(makeUnderline); + textDecorActions.append(makeStrike); + textDecorActions.append(makeOverline); + QMenu *textDecoration =3D new QMenu(); + textDecoration->addActions(textDecorActions); + widget.bnUnderline->setMenu(textDecoration); + widget.bnStrikethrough->setDefaultAction(makeStrike); + connect(widget.bnTextFgColor, SIGNAL(changed(KoColor)), this, SLOT(set= TextFill())); connect(widget.bnTextBgColor, SIGNAL(changed(KoColor)), this, SLOT(set= TextStroke())); - connect(widget.bnSuperscript, SIGNAL(clicked()), this, SLOT(setSupersc= ript())); - connect(widget.bnSubscript, SIGNAL(clicked()), this, SLOT(setSubscript= ())); + //connect(widget.bnSuperscript, SIGNAL(clicked()), this, SLOT(setSuper= script())); + //connect(widget.bnSubscript, SIGNAL(clicked()), this, SLOT(setSubscri= pt())); connect(widget.fontComboBox, SIGNAL(currentFontChanged(const QFont)), = this, SLOT(setFont())); connect(widget.fontSize, SIGNAL(editingFinished()), this, SLOT(setSize= ())); } @@ -75,8 +120,8 @@ void SvgTextEditor::setShape(KoSvgTextShape *shape) QString svg; QString styles; if (converter.convertToSvg(&svg, &styles)) { - //widget.textEdit->setPlainText(QString("%1\n%2").arg(defs).ar= g(svg)); - widget.textEdit->setPlainText(svg); + //widget.svgTextEdit->setPlainText(QString("%1\n%2").arg(defs)= .arg(svg)); + widget.svgTextEdit->setPlainText(svg); } else { qWarning() << "Could not get svg text from the shape:" << conv= erter.errors() << converter.warnings(); @@ -88,69 +133,209 @@ void SvgTextEditor::setShape(KoSvgTextShape *shape) void SvgTextEditor::save() { // We don't do defs or styles yet... - emit textUpdated(widget.textEdit->document()->toPlainText(), ""); + emit textUpdated(widget.svgTextEdit->document()->toPlainText(), ""); hide(); } = -void SvgTextEditor::setTextBold() +void SvgTextEditor::switchTextEditorTab() { - QTextCursor cursor =3D widget.textEdit->textCursor(); - if (cursor.hasSelection()) { - QString selectionModified =3D ""= + cursor.selectedText() + ""; - cursor.removeSelectedText(); - cursor.insertText(selectionModified); + if (widget.textTab->currentIndex() =3D=3D Richtext) { + //first, make buttons checkable + widget.bnBold->setCheckable(true); + widget.bnItalic->setCheckable(true); + widget.bnUnderline->setCheckable(true); + //then connec the cursor change to the checkformat(); + connect(widget.richTextEdit, SIGNAL(cursorPositionChanged()), this= , SLOT(checkFormat())); + + //implement svg to richtext here. + } else { + //first, make buttons uncheckable + widget.bnBold->setCheckable(false); + widget.bnItalic->setCheckable(false); + widget.bnUnderline->setCheckable(false); + disconnect(widget.richTextEdit, SIGNAL(cursorPositionChanged()), t= his, SLOT(checkFormat())); + + //implement richtext to svg here. } } = -void SvgTextEditor::setTextItalic() +void SvgTextEditor::checkFormat() { - QTextCursor cursor =3D widget.textEdit->textCursor(); - if (cursor.hasSelection()) { - QString selectionModified =3D "" + cursor.selectedText() + ""; - cursor.removeSelectedText(); - cursor.insertText(selectionModified); + QTextCharFormat format =3D widget.richTextEdit->textCursor().charForma= t(); + if (format.fontWeight()>QFont::Normal) { + widget.bnBold->setChecked(true); + } else { + widget.bnBold->setChecked(false); } + widget.bnItalic->setChecked(format.fontItalic()); + widget.bnUnderline->setChecked(format.fontUnderline()); + //widget.fontComboBox->setCurrentFont(format.font()); + widget.fontSize->setValue(format.fontPointSize()); + KoColor color(format.foreground().color(), KoColorSpaceRegistry::insta= nce()->rgb8()); + widget.bnTextFgColor->setColor(color); } = -void SvgTextEditor::setTextUnderline() +void SvgTextEditor::setTextBold(QFont::Weight weight) { - QTextCursor cursor =3D widget.textEdit->textCursor(); - if (cursor.hasSelection()) { - QString selectionModified =3D "" + cursor.selectedText() + ""; - cursor.removeSelectedText(); - cursor.insertText(selectionModified); + if (widget.textTab->currentIndex() =3D=3D Richtext) { + QTextCharFormat format; + if (widget.richTextEdit->textCursor().charFormat().fontWeight()>QF= ont::Normal && weight=3D=3DQFont::Bold) { + format.setFontWeight(QFont::Normal); + } else { + format.setFontWeight(weight); + } + widget.richTextEdit->mergeCurrentCharFormat(format); + } else { + QTextCursor cursor =3D widget.svgTextEdit->textCursor(); + if (cursor.hasSelection()) { + QString selectionModified =3D "" + cursor.selectedText() + ""; + cursor.removeSelectedText(); + cursor.insertText(selectionModified); + } } } = -void SvgTextEditor::setTextStrikeThrough() +void SvgTextEditor::setTextWeightLight() { - QTextCursor cursor =3D widget.textEdit->textCursor(); - if (cursor.hasSelection()) { - QString selectionModified =3D "" + cursor.selectedText() + ""; - cursor.removeSelectedText(); - cursor.insertText(selectionModified); + if (widget.richTextEdit->textCursor().charFormat().fontWeight()textCursor().charFormat().fontWeight()>QFont:= :Normal + && widget.richTextEdit->textCursor().charFormat().fontWeight()= textCursor().charFormat().fontWeight()>QFont:= :Normal) { + setTextBold(QFont::Normal); + } else { + setTextBold(QFont::Black); + } +} + +void SvgTextEditor::setTextItalic(QFont::Style style) +{ + QTextCursor cursor =3D widget.svgTextEdit->textCursor(); + QString fontStyle =3D "inherit"; + if (style =3D=3D QFont::StyleItalic) { + fontStyle =3D "italic"; + } else if(style =3D=3D QFont::StyleOblique) { + fontStyle =3D "oblique"; + } + if (widget.textTab->currentIndex() =3D=3D Richtext) { + QTextCharFormat format; + format.setFontItalic(!widget.richTextEdit->textCursor().charFormat= ().fontItalic()); + widget.richTextEdit->mergeCurrentCharFormat(format); + } else { + if (cursor.hasSelection()) { + QString selectionModified =3D "" + cursor.selectedText() + ""; + cursor.removeSelectedText(); + cursor.insertText(selectionModified); + } } } = +void SvgTextEditor::setTextDecoration(KoSvgText::TextDecoration decor) +{ + QTextCursor cursor =3D widget.svgTextEdit->textCursor(); + QTextCharFormat currentFormat =3D widget.richTextEdit->textCursor().ch= arFormat(); + QTextCharFormat format; + QString textDecoration =3D "inherit"; + if (decor =3D=3D KoSvgText::DecorationUnderline) { + textDecoration =3D "underline"; + if (currentFormat.fontUnderline()) { + format.setFontUnderline(false); + } else { + format.setFontUnderline(true); + } + format.setFontOverline(false); + format.setFontStrikeOut(false); + } else if (decor =3D=3D KoSvgText::DecorationLineThrough) { + textDecoration =3D "line-through"; + format.setFontUnderline(false); + format.setFontOverline(false); + if (currentFormat.fontStrikeOut()) { + format.setFontStrikeOut(false); + } else { + format.setFontStrikeOut(true); + } + } else if (decor =3D=3D KoSvgText::DecorationOverline) { + textDecoration =3D "overline"; + format.setFontUnderline(false); + if (currentFormat.fontOverline()) { + format.setFontOverline(false); + } else { + format.setFontOverline(true); + } + format.setFontStrikeOut(false); + } + if (widget.textTab->currentIndex() =3D=3D Richtext) { + widget.richTextEdit->mergeCurrentCharFormat(format); + } else { + if (cursor.hasSelection()) { + QString selectionModified =3D "" + cursor.selectedText() + ""; + cursor.removeSelectedText(); + cursor.insertText(selectionModified); + } + } +} + +void SvgTextEditor::setTextUnderline() +{ + setTextDecoration(); +} + +void SvgTextEditor::setTextOverline() +{ + setTextDecoration(KoSvgText::DecorationOverline); +} + +void SvgTextEditor::setTextStrikethrough() +{ + setTextDecoration(KoSvgText::DecorationLineThrough); +} + void SvgTextEditor::setTextFill() { KoColor c =3D widget.bnTextFgColor->color(); QColor color =3D c.toQColor(); - QTextCursor cursor =3D widget.textEdit->textCursor(); + QTextEdit t; + if (widget.textTab->currentIndex() =3D=3D Richtext) { + QTextCharFormat format; + format.setForeground(QBrush(color)); + widget.richTextEdit->mergeCurrentCharFormat(format); + } else { + QTextCursor cursor =3D widget.svgTextEdit->textCursor(); if (cursor.hasSelection()) { - QString selectionModified =3D "" = + cursor.selectedText() + ""; + QString selectionModified =3D "= " + cursor.selectedText() + ""; cursor.removeSelectedText(); cursor.insertText(selectionModified); } + } } = void SvgTextEditor::setTextStroke() { KoColor c =3D widget.bnTextBgColor->color(); QColor color =3D c.toQColor(); - QTextCursor cursor =3D widget.textEdit->textCursor(); + QTextCursor cursor =3D widget.svgTextEdit->textCursor(); if (cursor.hasSelection()) { - QString selectionModified =3D "= " + cursor.selectedText() + ""; + QString selectionModified =3D "" + cursor.selectedText() + ""; cursor.removeSelectedText(); cursor.insertText(selectionModified); } @@ -159,31 +344,43 @@ void SvgTextEditor::setTextStroke() void SvgTextEditor::setFont() { QString fontName =3D widget.fontComboBox->currentFont().family(); - QTextCursor cursor =3D widget.textEdit->textCursor(); - if (cursor.hasSelection()) { - QString selectionModified =3D "" + cursor.selectedText() + ""; - cursor.removeSelectedText(); - cursor.insertText(selectionModified); + if (widget.textTab->currentIndex() =3D=3D Richtext) { + QTextCharFormat format; + format.setFontFamily(fontName); + widget.richTextEdit->mergeCurrentCharFormat(format); + } else { + QTextCursor cursor =3D widget.svgTextEdit->textCursor(); + if (cursor.hasSelection()) { + QString selectionModified =3D "" + cursor.selectedText() + ""; + cursor.removeSelectedText(); + cursor.insertText(selectionModified); + } } } = void SvgTextEditor::setSize() { QString fontSize =3D QString::number(widget.fontSize->value()); - QTextCursor cursor =3D widget.textEdit->textCursor(); - if (cursor.hasSelection()) { - QString selectionModified =3D "" + cursor.selectedText() + ""; - cursor.removeSelectedText(); - cursor.insertText(selectionModified); + if (widget.textTab->currentIndex() =3D=3D Richtext) { + QTextCharFormat format; + format.setFontPointSize((qreal)widget.fontSize->value()); + widget.richTextEdit->mergeCurrentCharFormat(format); + } else { + QTextCursor cursor =3D widget.svgTextEdit->textCursor(); + if (cursor.hasSelection()) { + QString selectionModified =3D "" + cursor.selectedText() + ""; + cursor.removeSelectedText(); + cursor.insertText(selectionModified); + } } } = -void SvgTextEditor::setSubscript() +void SvgTextEditor::setBaseline(KoSvgText::BaselineShiftMode) { - QString fontSize =3D QString::number(widget.fontSize->value()); - QTextCursor cursor =3D widget.textEdit->textCursor(); + + QTextCursor cursor =3D widget.svgTextEdit->textCursor(); if (cursor.hasSelection()) { - QString selectionModified =3D "" + cursor.selectedText() + ""; + QString selectionModified =3D "" + cursor.selectedText() + ""; cursor.removeSelectedText(); cursor.insertText(selectionModified); } @@ -194,18 +391,7 @@ void SvgTextEditor::wheelEvent(QWheelEvent *event) if (event->modifiers() & Qt::ControlModifier) { int numDegrees =3D event->delta() / 8; int numSteps =3D numDegrees / 7; - widget.textEdit->zoomOut(numSteps); + widget.svgTextEdit->zoomOut(numSteps); event->accept(); } } - -void SvgTextEditor::setSuperscript() -{ - QString fontSize =3D QString::number(widget.fontSize->value()); - QTextCursor cursor =3D widget.textEdit->textCursor(); - if (cursor.hasSelection()) { - QString selectionModified =3D "" + cursor.selectedText() + ""; - cursor.removeSelectedText(); - cursor.insertText(selectionModified); - } -} diff --git a/plugins/tools/svgtexttool/SvgTextEditor.h b/plugins/tools/svgt= exttool/SvgTextEditor.h index b9145ff9c63..d68e6421e53 100644 --- a/plugins/tools/svgtexttool/SvgTextEditor.h +++ b/plugins/tools/svgtexttool/SvgTextEditor.h @@ -27,6 +27,7 @@ = #include #include +#include //for the enums = class KoSvgTextShape; class KisFileNameRequester; @@ -38,22 +39,43 @@ public: SvgTextEditor(QWidget *parent =3D 0, Qt::WindowFlags flags =3D 0); ~SvgTextEditor(); = + //tiny enum to keep track of the tab on which editor something happens= while keeping the code readable. + enum Editor { + Richtext, // 0 + SVGsource // 1 + }; + void setShape(KoSvgTextShape *shape); = private Q_SLOTS: = void save(); + /** + * switch the text editor tab. + */ + void switchTextEditorTab(); + /** + * in rich text, check the current format, and toggle the given button= s. + */ + void checkFormat(); + + void setTextBold(QFont::Weight weight =3D QFont::Bold); + void setTextWeightLight(); + void setTextWeightNormal(); + void setTextWeightDemi(); + void setTextWeightBlack(); = - void setTextBold(); - void setTextItalic(); + void setTextItalic(QFont::Style style =3D QFont::StyleOblique); + void setTextDecoration(KoSvgText::TextDecoration decor =3D KoSvgText::= DecorationUnderline); void setTextUnderline(); - void setTextStrikeThrough(); + void setTextOverline(); + void setTextStrikethrough(); + void setTextFill(); void setTextStroke(); void setFont(); void setSize(); - void setSuperscript(); - void setSubscript(); + void setBaseline(KoSvgText::BaselineShiftMode baseline); = Q_SIGNALS: = diff --git a/plugins/tools/svgtexttool/WdgSvgTextEditor.ui b/plugins/tools/= svgtexttool/WdgSvgTextEditor.ui index e312d1c1466..87c48dc66b8 100644 --- a/plugins/tools/svgtexttool/WdgSvgTextEditor.ui +++ b/plugins/tools/svgtexttool/WdgSvgTextEditor.ui @@ -61,6 +61,9 @@ .. + + QToolButton::MenuButtonPopup + @@ -89,6 +92,9 @@ .. + + QToolButton::MenuButtonPopup + @@ -188,85 +194,167 @@ Paragraph - + - - - ... - - - - .. - - - - - - - ... - - - - .. - - - - - - - ... - - - - .. - - - - - - - ... - - - - .. - - - - - - - ... - - - - .. - - - - - - - ... - - - - .. - - + + + + + Align text to the left. + + + ... + + + + .. + + + + + + + Align text to the center. + + + ... + + + + .. + + + + + + + Align text to the right. + + + ... + + + + .. + + + + + + + Align text justified. + + + ... + + + + .. + + + + + + + Indent less + + + ... + + + + + + + + + + Indent more. + + + ... + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + - - - Qt::Horizontal - - - - 40 - 20 - - - + + + + + Line-height + + + + + + + The difference at which a new line is started. + + + + + + x + + + + + + + Letter-spacing + + + + + + + Spacing between + + + + + + + <html><head/><body><p>Whether = on not to use the internal kerning tables of a font.</p></body>= </html> + + + Use Kerning tables if possible. + + + + + + + Adjust the spacing between words. + + + + + + + Word-spacing + + + + @@ -298,7 +386,8 @@ ... - + + .. @@ -311,7 +400,8 @@ ... - + + .. @@ -324,7 +414,8 @@ ... - + + .. @@ -337,7 +428,8 @@ ... - + + .. @@ -350,7 +442,8 @@ ... - + + .. @@ -370,16 +463,42 @@ - - - - 0 - 0 - - - - false + + + 0 + + + Rich text + + + + + + + svgTextEdit + richTextEdit + + + + SVG source + + + + + + + 0 + 0 + + + + false + + + + +