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++
Use StyleHints to enable drawing text cursor while there's a selection.
Wolthera van Hövell tot Westerfliere83c84340294
diff --git a/plugins/tools/svgtexttool/SvgTextCursor.cpp b/plugins/tools/svgtexttool/SvgTextCursor.cppindex 599418c58c..041b5ea919 100644--- a/plugins/tools/svgtexttool/SvgTextCursor.cpp+++ b/plugins/tools/svgtexttool/SvgTextCursor.cpp@@ -152,6 +152,7 @@ struct Q_DECL_HIDDEN SvgTextCursor::Private {QLineF cursorCaret;QLineF anchorCaret;int cursorWidth = 1;+ bool drawCursorInAdditionToSelection = false;QPainterPath selection;QRectF oldSelectionRect;@@ -232,11 +233,12 @@ void SvgTextCursor::setShape(KoSvgTextShape *textShape)updateSelection();}-void SvgTextCursor::setCaretSetting(int cursorWidth, int cursorFlash, int cursorFlashLimit)+void SvgTextCursor::setCaretSetting(int cursorWidth, int cursorFlash, int cursorFlashLimit, bool drawCursorInAdditionToSelection){d->cursorFlash.setInterval(cursorFlash/2);d->cursorFlashLimit.setInterval(cursorFlashLimit);d->cursorWidth = cursorWidth;+ d->drawCursorInAdditionToSelection = drawCursorInAdditionToSelection;connect(&d->cursorFlash, SIGNAL(timeout()), this, SLOT(blinkCursor()));connect(&d->cursorFlashLimit, SIGNAL(timeout()), this, SLOT(stopBlinkCursor()));}@@ -742,21 +744,22 @@ void SvgTextCursor::paintDecorations(QPainter &gc, QColor selectionColor, int deQBrush brush(selectionColor);gc.fillPath(d->selection, brush);gc.restore();- } else {- if (d->cursorVisible) {- QPen pen;- pen.setCosmetic(true);- QColor c = d->cursorColor.isValid()? d->cursorColor: Qt::black;- pen.setColor(bgColorForCaret(c));- pen.setWidth((d->cursorWidth + 2) * decorationThickness);- gc.setPen(pen);- gc.drawPath(d->cursorShape);- pen.setColor(c);- pen.setWidth(d->cursorWidth * decorationThickness);- gc.setPen(pen);- gc.drawPath(d->cursorShape);+ }++ if ( (d->drawCursorInAdditionToSelection || d->pos == d->anchor)+ && d->cursorVisible) {+ QPen pen;+ pen.setCosmetic(true);+ QColor c = d->cursorColor.isValid()? d->cursorColor: Qt::black;+ pen.setColor(bgColorForCaret(c));+ pen.setWidth((d->cursorWidth + 2) * decorationThickness);+ gc.setPen(pen);+ gc.drawPath(d->cursorShape);+ pen.setColor(c);+ pen.setWidth(d->cursorWidth * decorationThickness);+ gc.setPen(pen);+ gc.drawPath(d->cursorShape);- }}if (d->preEditCommand) {diff --git a/plugins/tools/svgtexttool/SvgTextCursor.h b/plugins/tools/svgtexttool/SvgTextCursor.hindex 099a77f0cd..9b2b7848c9 100644--- a/plugins/tools/svgtexttool/SvgTextCursor.h+++ b/plugins/tools/svgtexttool/SvgTextCursor.h@@ -105,7 +105,7 @@ public:* @param cursorFlash - the total time it takes for a cursor to hide reapear.* @param cursorFlashLimit - maximum amount of time a cursor is allowed to flash.*/- void setCaretSetting(int cursorWidth = 1, int cursorFlash = 1000, int cursorFlashLimit = 5000);+ void setCaretSetting(int cursorWidth = 1, int cursorFlash = 1000, int cursorFlashLimit = 5000, bool drawCursorInAdditionToSelection = false);/*** @brief setVisualModediff --git a/plugins/tools/svgtexttool/SvgTextTool.cpp b/plugins/tools/svgtexttool/SvgTextTool.cppindex 5d1888cfd9..cc1aef7063 100644--- a/plugins/tools/svgtexttool/SvgTextTool.cpp+++ b/plugins/tools/svgtexttool/SvgTextTool.cpp@@ -99,10 +99,12 @@ SvgTextTool::SvgTextTool(KoCanvasBase *canvas), m_optionManager(new SvgTextToolOptionsManager(this)){// TODO: figure out whether we should use system config for this, Windows and GTK have values for it, but Qt and MacOS don't(?).- int cursorFlashLimit = 5000;+ const int cursorFlashLimit = 5000;+ const bool enableCursorWithSelection = QApplication::style()->styleHint(QStyle::SH_BlinkCursorWhenTextSelected);m_textCursor.setCaretSetting(QApplication::style()->pixelMetric(QStyle::PM_TextCursorWidth), qApp->cursorFlashTime()- , cursorFlashLimit);+ , cursorFlashLimit+ , enableCursorWithSelection);connect(&m_textCursor, SIGNAL(updateCursorDecoration(QRectF)), this, SLOT(slotUpdateCursorDecoration(QRectF)));Q_FOREACH(const QString name, SvgTextShortCuts::possibleActions()) {