Krita Source Code Documentation
Loading...
Searching...
No Matches
SvgTextTool Class Reference

#include <SvgTextTool.h>

+ Inheritance diagram for SvgTextTool:

Public Member Functions

void activate (const QSet< KoShape * > &shapes) override
 reimplemented from KoToolBase
 
void copy () const override
 reimplemented from superclass
 
void deactivate () override
 reimplemented from KoToolBase
 
QRectF decorationsRect () const override
 reimplemented from KoToolBase
 
void deleteSelection () override
 reimplemented from superclass
 
void deselect () override
 deselect the tool should clear the selection if it has one.
 
void focusInEvent (QFocusEvent *event) override
 
void focusOutEvent (QFocusEvent *event) override
 
bool hasSelection () override
 reimplemented from superclass
 
void inputMethodEvent (QInputMethodEvent *event) override
 
QVariant inputMethodQuery (Qt::InputMethodQuery query) const override
 
void keyPressEvent (QKeyEvent *event) override
 
void keyReleaseEvent (QKeyEvent *event) override
 
void mouseDoubleClickEvent (KoPointerEvent *event) override
 reimplemented from superclass
 
void mouseMoveEvent (KoPointerEvent *event) override
 reimplemented from KoToolBase
 
void mousePressEvent (KoPointerEvent *event) override
 reimplemented from KoToolBase
 
void mouseReleaseEvent (KoPointerEvent *event) override
 reimplemented from KoToolBase
 
void mouseTripleClickEvent (KoPointerEvent *event) override
 reimplemented from KoToolBase
 
void paint (QPainter &gc, const KoViewConverter &converter) override
 reimplemented from KoToolBase
 
bool paste () override
 reimplemented from superclass
 
KisPopupWidgetInterfacepopupWidget () override
 
void requestStrokeCancellation () override
 
void requestStrokeEnd () override
 
bool selectAll () override
 selectAll select all data the tool can select.
 
KoToolSelectionselection () override
 reimplemented from superclass
 
 SvgTextTool (KoCanvasBase *canvas)
 
 ~SvgTextTool () override
 
- Public Member Functions inherited from KoToolBase
QAction * action (const QString &name) const
 
KoCanvasBasecanvas () const
 Returns the canvas the tool is working on.
 
QCursor cursor () const
 return the last emitted cursor
 
virtual void customMoveEvent (KoPointerEvent *event)
 
virtual void customPressEvent (KoPointerEvent *event)
 
virtual void customReleaseEvent (KoPointerEvent *event)
 
virtual void cut ()
 
int decorationThickness () const
 decorationThickness The minimum thickness for tool decoration lines, this is derived from the screen magnification, thus the HiDPI settings. Note: to use this effectively, also set the pen to isCosmetic(true);
 
virtual void dragLeaveEvent (QDragLeaveEvent *event)
 
virtual void dragMoveEvent (QDragMoveEvent *event, const QPointF &point)
 
virtual void dropEvent (QDropEvent *event, const QPointF &point)
 
virtual void explicitUserStrokeEndRequest ()
 explicitUserStrokeEndRequest is called by the input manager when the user presses Enter key or any equivalent. This callback comes before requestStrokeEnd(), which comes from a different source.
 
KoToolFactoryBasefactory () const
 
bool isInTextMode () const
 
bool isOpacityPresetMode () const
 
 KoToolBase (KoCanvasBase *canvas)
 
bool maskSyntheticEvents () const
 
QList< QPointer< QWidget > > optionWidgets ()
 
virtual QMenu * popupActionsMenu ()
 
Q_INVOKABLE QString toolId () const
 
virtual bool wantsAutoScroll () const
 
 ~KoToolBase () override
 

Protected Member Functions

virtual QWidget * createOptionWidget () override
 reimplemented from KoToolBase
 
KoSelectionkoSelection () const
 
KoSvgTextShapeselectedShape () const
 
- Protected Member Functions inherited from KoToolBase
virtual QList< QPointer< QWidget > > createOptionWidgets ()
 
int grabSensitivity () const
 Convenience function to get the current grab sensitivity.
 
qreal handleDocRadius () const
 
QRectF handleGrabRect (const QPointF &position) const
 
QRectF handlePaintRect (const QPointF &position) const
 
int handleRadius () const
 Convenience function to get the current handle radius.
 
bool isActivated () const
 
 KoToolBase (KoToolBasePrivate &dd)
 
KoPointerEventlastDeliveredPointerEvent () const
 
void setAbstractResource (KoAbstractCanvasResourceInterfaceSP abstractResource)
 
void setConverter (KoDerivedResourceConverterSP converter)
 
void setIsOpacityPresetMode (bool value)
 
void setMaskSyntheticEvents (bool value)
 
void setTextMode (bool value)
 
QHash< int, KoAbstractCanvasResourceInterfaceSPtoolAbstractResources ()
 
QHash< int, KoDerivedResourceConverterSPtoolConverters ()
 
void useCursor (const QCursor &cursor)
 

Private Types

enum class  DragMode {
  None = 0 , Create , Select , InlineSizeHandle ,
  Move
}
 
enum class  HighlightItem { None = 0 , InlineSizeStartHandle , InlineSizeEndHandle , MoveBorder }
 

Private Slots

QString generateDefs (const KoSvgTextProperties &properties=KoSvgTextProperties())
 generateDefs This generates a defs section with the appropriate css and css strings assigned.
 
void insertRichText (KoSvgTextShape *richText, bool replaceLastGlyph=false)
 insertRichText Insert a rich text shape, used by the glyph palette..
 
KoSvgTextProperties propertiesForNewText () const
 propertiesForNewText get the text properties that should be used for new text.
 
void showEditor ()
 
void showGlyphPalette ()
 showGlyphPalette Shows the glyph palette dialog.
 
void slotConvertType (int index)
 slotConvertType
 
void slotShapeSelectionChanged ()
 selectionChanged called when the canvas selection is changed.
 
void slotTextEditorClosed ()
 
void slotTextTypeUpdated ()
 slotTextTypeUpdated Update the text type in the tool options.
 
void slotUpdateCursorDecoration (QRectF updateRect)
 updateCursor update the canvas decorations in a particular update rect for the text cursor.
 
void slotUpdateTextPasteBehaviour ()
 slotUpdateTextPasteBehaviour update the default text paste behaviour.
 
void slotUpdateVisualCursor ()
 slotUpdateVisualCursor update the visual cursor mode on the text cursor.
 
void textUpdated (KoSvgTextShape *shape, const QString &svg, const QString &defs)
 
void updateGlyphPalette ()
 updateGlyphPalette update the glyph palette dialog from the current selection.
 

Private Member Functions

qreal grabSensitivityInPt () const
 
KoSvgText::WritingMode writingMode () const
 

Private Attributes

QCursor m_base_cursor
 
KisSignalAutoConnectionsStore m_canvasConnections
 
DragMode m_dragging {DragMode::None}
 
QPointer< SvgTextEditorm_editor
 
QPointer< GlyphPaletteDialogm_glyphPalette
 
HighlightItem m_highlightItem {HighlightItem::None}
 
QPainterPath m_hoveredShapeHighlightRect
 
QCursor m_ibeam_horizontal
 
QCursor m_ibeam_horizontal_done
 
QCursor m_ibeam_vertical
 
std::unique_ptr< KoInteractionStrategym_interactionStrategy
 
QPointF m_lastMousePos
 
QScopedPointer< SvgTextToolOptionsManagerm_optionManager
 
bool m_strategyAddingCommand {false}
 
QCursor m_text_in_shape
 
QCursor m_text_inline_horizontal
 
QCursor m_text_inline_vertical
 
QCursor m_text_on_path
 
SvgTextCursor m_textCursor
 
QScopedPointer< KisSignalMapperm_textTypeSignalsMapper
 

Friends

class SvgCreateTextStrategy
 

Additional Inherited Members

- Public Slots inherited from KoToolBase
virtual void canvasResourceChanged (int key, const QVariant &res)
 
virtual void documentResourceChanged (int key, const QVariant &res)
 
virtual void repaintDecorations ()
 
virtual void requestRedoDuringStroke ()
 
virtual void requestUndoDuringStroke ()
 
void setStatusText (const QString &statusText)
 
void updateOptionsWidgetIcons ()
 
- Signals inherited from KoToolBase
void activateTool (const QString &id)
 
void cursorChanged (const QCursor &cursor)
 
void selectionChanged (bool hasSelection)
 
void statusTextChanged (const QString &statusText)
 
void textModeChanged (bool inTextMode)
 
- Protected Attributes inherited from KoToolBase
KoToolBasePrivated_ptr
 

Detailed Description

Definition at line 32 of file SvgTextTool.h.

Member Enumeration Documentation

◆ DragMode

enum class SvgTextTool::DragMode
strongprivate
Enumerator
None 
Create 
Select 
InlineSizeHandle 
Move 

Definition at line 177 of file SvgTextTool.h.

◆ HighlightItem

enum class SvgTextTool::HighlightItem
strongprivate
Enumerator
None 
InlineSizeStartHandle 
InlineSizeEndHandle 
MoveBorder 

Definition at line 184 of file SvgTextTool.h.

Constructor & Destructor Documentation

◆ SvgTextTool()

SvgTextTool::SvgTextTool ( KoCanvasBase * canvas)
explicit

Definition at line 90 of file SvgTextTool.cpp.

94{
95 // TODO: figure out whether we should use system config for this, Windows and GTK have values for it, but Qt and MacOS don't(?).
96 int cursorFlashLimit = 5000;
97 m_textCursor.setCaretSetting(QApplication::style()->pixelMetric(QStyle::PM_TextCursorWidth)
98 , qApp->cursorFlashTime()
99 , cursorFlashLimit);
100 connect(&m_textCursor, SIGNAL(updateCursorDecoration(QRectF)), this, SLOT(slotUpdateCursorDecoration(QRectF)));
101
102 Q_FOREACH(const QString name, SvgTextShortCuts::possibleActions()) {
103 QAction *a = action(name);
105 dbgTools << "registered" << name << a->shortcut();
106 }
107 }
108
109 const QStringList extraActions = {
110 "svg_insert_special_character",
111 "svg_paste_rich_text",
112 "svg_paste_plain_text"
113 };
114 connect(&m_textCursor, SIGNAL(sigOpenGlyphPalette()), this, SLOT(showGlyphPalette()));
115 Q_FOREACH (const QString name, extraActions) {
116 QAction *a = action(name);
117 if (a) {
119 qWarning() << "could not register" << name << a->shortcut();
120 }
121 }
122 }
123
125 const QMap<QString, int> convertActions {
126 {"text_type_preformatted", KoSvgTextShape::PreformattedText},
127 {"text_type_inline_wrap", KoSvgTextShape::InlineWrap},
128 {"text_type_pre_positioned", KoSvgTextShape::PrePositionedText}
129 };
130 Q_FOREACH(const QString name, convertActions.keys()) {
131 QAction *a = action(name);
132 connect(a, SIGNAL(triggered()), m_textTypeSignalsMapper.data(), SLOT(map()));
133 m_textTypeSignalsMapper->setMapping(a, convertActions.value(name));
134 }
135
136 m_base_cursor = QCursor(QPixmap(":/tool_text_basic.xpm"), 7, 7);
137 m_text_inline_horizontal = QCursor(QPixmap(":/tool_text_inline_horizontal.xpm"), 7, 7);
138 m_text_inline_vertical = QCursor(QPixmap(":/tool_text_inline_vertical.xpm"), 7, 7);
139 m_text_on_path = QCursor(QPixmap(":/tool_text_on_path.xpm"), 7, 7);
140 m_text_in_shape = QCursor(QPixmap(":/tool_text_in_shape.xpm"), 7, 7);
141 m_ibeam_horizontal = QCursor(QPixmap(":/tool_text_i_beam_horizontal.xpm"), 11, 11);
142 m_ibeam_vertical = QCursor(QPixmap(":/tool_text_i_beam_vertical.xpm"), 11, 11);
143 m_ibeam_horizontal_done = QCursor(QPixmap(":/tool_text_i_beam_horizontal_done.xpm"), 5, 11);
144}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
The KisSignalMapper class bundles signals from identifiable senders.
@ PreformattedText
Text-on-Path falls under this or PrePositionedText depending on collapse of lines.
@ InlineWrap
Uses inline size to wrap and preserves spaces.
KoCanvasBase * canvas() const
Returns the canvas the tool is working on.
QAction * action(const QString &name) const
static QStringList possibleActions()
The SvgTextToolOptionsManager class.
QScopedPointer< KisSignalMapper > m_textTypeSignalsMapper
QScopedPointer< SvgTextToolOptionsManager > m_optionManager
QCursor m_base_cursor
QCursor m_text_inline_horizontal
QCursor m_ibeam_horizontal
QCursor m_ibeam_horizontal_done
void showGlyphPalette()
showGlyphPalette Shows the glyph palette dialog.
QCursor m_text_inline_vertical
QCursor m_ibeam_vertical
QCursor m_text_in_shape
void slotUpdateCursorDecoration(QRectF updateRect)
updateCursor update the canvas decorations in a particular update rect for the text cursor.
QCursor m_text_on_path
SvgTextCursor m_textCursor
#define dbgTools
Definition kis_debug.h:48
const char * name(StandardAction id)
void setCaretSetting(int cursorWidth=1, int cursorFlash=1000, int cursorFlashLimit=5000)
setCaretSetting Set the caret settings for the cursor. Qt has some standard functionality associated,...
bool registerPropertyAction(QAction *action, const QString &name)
Register an action.

References KoToolBase::action(), connect(), dbgTools, KoSvgTextShape::InlineWrap, m_base_cursor, m_ibeam_horizontal, m_ibeam_horizontal_done, m_ibeam_vertical, m_text_in_shape, m_text_inline_horizontal, m_text_inline_vertical, m_text_on_path, m_textCursor, m_textTypeSignalsMapper, SvgTextShortCuts::possibleActions(), KoSvgTextShape::PreformattedText, KoSvgTextShape::PrePositionedText, SvgTextCursor::registerPropertyAction(), SvgTextCursor::setCaretSetting(), showGlyphPalette(), and slotUpdateCursorDecoration().

◆ ~SvgTextTool()

SvgTextTool::~SvgTextTool ( )
override

Definition at line 146 of file SvgTextTool.cpp.

147{
148 if(m_editor) {
149 m_editor->close();
150 }
151 if(m_glyphPalette) {
152 m_glyphPalette->close();
153 }
154}
QPointer< GlyphPaletteDialog > m_glyphPalette
QPointer< SvgTextEditor > m_editor

References m_editor, and m_glyphPalette.

Member Function Documentation

◆ activate()

void SvgTextTool::activate ( const QSet< KoShape * > & shapes)
overridevirtual

reimplemented from KoToolBase

Reimplemented from KoToolBase.

Definition at line 156 of file SvgTextTool.cpp.

157{
158 KoToolBase::activate(shapes);
159 m_canvasConnections.addConnection(canvas()->selectedShapesProxy(), SIGNAL(selectionChanged()), this, SLOT(slotShapeSelectionChanged()));
160
161 const KisCanvas2 *canvas2 = qobject_cast<const KisCanvas2 *>(this->canvas());
162 if (canvas2) {
164 QDockWidget *docker = canvas2->viewManager()->mainWindow()->dockWidget("TextProperties");
165 if (docker && m_optionManager) {
166 m_optionManager->setTextPropertiesOpen(docker->isVisible());
167 }
168 }
169
170 connect(m_textTypeSignalsMapper.data(), SIGNAL(mapped(int)), this, SLOT(slotConvertType(int)));
171
174
176}
KisViewManager * viewManager() const
QDockWidget * dockWidget(const QString &id)
void addConnection(Sender sender, Signal signal, Receiver receiver, Method method, Qt::ConnectionType type=Qt::AutoConnection)
void setTextPropertiesInterface(KoSvgTextPropertiesInterface *interface)
setTextPropertiesInterface set the text properties interface. This should be done on tool activation....
KisMainWindow * mainWindow() const
KisTextPropertiesManager * textPropertyManager() const
void selectionChanged(bool hasSelection)
virtual void repaintDecorations()
void useCursor(const QCursor &cursor)
virtual void activate(const QSet< KoShape * > &shapes)
KisSignalAutoConnectionsStore m_canvasConnections
void slotShapeSelectionChanged()
selectionChanged called when the canvas selection is changed.
void slotConvertType(int index)
slotConvertType
KoSvgTextPropertiesInterface * textPropertyInterface()

References KoToolBase::activate(), KisSignalAutoConnectionsStore::addConnection(), KoToolBase::canvas(), connect(), KisMainWindow::dockWidget(), m_base_cursor, m_canvasConnections, m_optionManager, m_textCursor, m_textTypeSignalsMapper, KisViewManager::mainWindow(), KoToolBase::repaintDecorations(), KoToolBase::selectionChanged(), KisTextPropertiesManager::setTextPropertiesInterface(), slotConvertType(), slotShapeSelectionChanged(), SvgTextCursor::textPropertyInterface(), KisViewManager::textPropertyManager(), KoToolBase::useCursor(), and KisCanvas2::viewManager().

◆ copy()

void SvgTextTool::copy ( ) const
overridevirtual

reimplemented from superclass

Reimplemented from KoToolBase.

Definition at line 449 of file SvgTextTool.cpp.

450{
452}
void copy() const
copy copies plain text into the clipboard between anchor and pos.

References SvgTextCursor::copy(), and m_textCursor.

◆ createOptionWidget()

QWidget * SvgTextTool::createOptionWidget ( )
overrideprotectedvirtual

reimplemented from KoToolBase

Reimplemented from KoToolBase.

Definition at line 214 of file SvgTextTool.cpp.

215{
216 KisQQuickWidget *optionWidget = new KisQQuickWidget();
217 optionWidget->setMinimumWidth(100);
218 optionWidget->setMinimumHeight(100);
219
220 optionWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
221 optionWidget->setSource(QUrl("qrc:/SvgTextToolOptions.qml"));
222
223 m_optionManager->setShowDebug(debugEnabled());
224 if (optionWidget->errors().isEmpty()) {
225 optionWidget->rootObject()->setProperty("manager", QVariant::fromValue(m_optionManager.data()));
226 optionWidget->connectMinimumHeightToRootObject();
227 } else {
228 qWarning() << optionWidget->errors();
229 }
230
231
232 connect(m_optionManager.data(), SIGNAL(openTextEditor()), SLOT(showEditor()));
233 connect(m_optionManager.data(), SIGNAL(openGlyphPalette()), SLOT(showGlyphPalette()));
234
235 connect(m_optionManager.data(), SIGNAL(convertTextType(int)), SLOT(slotConvertType(int)));
236 connect(m_optionManager->optionsModel(), SIGNAL(useVisualBidiCursorChanged(bool)), this, SLOT(slotUpdateVisualCursor()));
237 connect(m_optionManager->optionsModel(), SIGNAL(pasteRichtTextByDefaultChanged(bool)), this, SLOT(slotUpdateTextPasteBehaviour()));
238 const KisCanvas2 *canvas2 = qobject_cast<const KisCanvas2 *>(this->canvas());
239 if (canvas2 && canvas2->viewManager()->mainWindow()) {
240 QDockWidget *docker = canvas2->viewManager()->mainWindow()->dockWidget("TextProperties");
241 m_optionManager->setShowTextPropertyButton((docker));
242 if (docker) {
243 optionWidget->setPalette(docker->palette());
244 m_optionManager->setTextPropertiesOpen(docker->isVisible());
246 docker->setVisible(!docker->isVisible());
247 });
248 // Once we have docker toggling actions, we should revisit this.
249 }
250 }
254
255
256 return optionWidget;
257}
static bool debugEnabled()
Linethickness.
The KisQQuickWidget class.
void connectMinimumHeightToRootObject()
connectMinimumHeightToRootObject By default we scale rootObject to widget, but in some situations we ...
void openTextPropertiesDocker(bool open)
void slotTextTypeUpdated()
slotTextTypeUpdated Update the text type in the tool options.
void slotUpdateVisualCursor()
slotUpdateVisualCursor update the visual cursor mode on the text cursor.
void slotUpdateTextPasteBehaviour()
slotUpdateTextPasteBehaviour update the default text paste behaviour.
void showEditor()

References KoToolBase::canvas(), connect(), KisQQuickWidget::connectMinimumHeightToRootObject(), debugEnabled(), KisMainWindow::dockWidget(), m_optionManager, KisViewManager::mainWindow(), SvgTextToolOptionsManager::openTextPropertiesDocker(), showEditor(), showGlyphPalette(), slotConvertType(), slotTextTypeUpdated(), slotUpdateTextPasteBehaviour(), slotUpdateVisualCursor(), and KisCanvas2::viewManager().

◆ deactivate()

void SvgTextTool::deactivate ( )
overridevirtual

reimplemented from KoToolBase

Reimplemented from KoToolBase.

Definition at line 178 of file SvgTextTool.cpp.

179{
182 m_textCursor.setShape(nullptr);
183 const KisCanvas2 *canvas2 = qobject_cast<const KisCanvas2 *>(this->canvas());
184 if (canvas2) {
186 }
187 // Exiting text editing mode is handled by requestStrokeEnd
188 disconnect(m_textTypeSignalsMapper.data(), 0, this, 0);
189
190 m_hoveredShapeHighlightRect = QPainterPath();
191
193}
virtual void deactivate()
QPainterPath m_hoveredShapeHighlightRect
void setShape(KoSvgTextShape *textShape)
setShape

References KoToolBase::canvas(), KisSignalAutoConnectionsStore::clear(), KoToolBase::deactivate(), m_canvasConnections, m_hoveredShapeHighlightRect, m_textCursor, m_textTypeSignalsMapper, KoToolBase::repaintDecorations(), SvgTextCursor::setShape(), KisTextPropertiesManager::setTextPropertiesInterface(), KisViewManager::textPropertyManager(), and KisCanvas2::viewManager().

◆ decorationsRect()

QRectF SvgTextTool::decorationsRect ( ) const
overridevirtual

reimplemented from KoToolBase

Reimplemented from KoToolBase.

Definition at line 562 of file SvgTextTool.cpp.

563{
564 QRectF rect;
565 KoSvgTextShape *const shape = selectedShape();
566 if (shape) {
567 rect |= shape->boundingRect();
568
569 const QPointF anchor = shape->absoluteTransformation().map(QPointF());
570 rect |= kisGrowRect(QRectF(anchor, anchor), handleRadius());
571
572 qreal pxlToPt = canvas()->viewConverter()->viewToDocumentX(1.0);
574
575 if (std::optional<InlineSizeInfo> info = InlineSizeInfo::fromShape(shape, length * pxlToPt)) {
576 rect |= kisGrowRect(info->boundingRect(), handleRadius() * 2);
577 }
578
579 if (canvas()->snapGuide()->isSnapping()) {
581 }
582 }
583
584 rect |= m_hoveredShapeHighlightRect.boundingRect();
585
586 return rect;
587}
qreal length(const QPointF &vec)
Definition Ellipse.cc:82
constexpr double INLINE_SIZE_DASHES_PATTERN_A
constexpr int INLINE_SIZE_DASHES_PATTERN_LENGTH
Size of the hidden part of the inline-size handle dashes.
constexpr double INLINE_SIZE_DASHES_PATTERN_B
Size of the visible part of the inline-size handle dashes.
KoSnapGuide * snapGuide
virtual const KoViewConverter * viewConverter() const =0
QTransform absoluteTransformation() const
Definition KoShape.cpp:382
QRectF boundingRect()
returns the bounding rect of the guide
QRectF boundingRect() const override
Get the bounding box of the shape.
int handleRadius() const
Convenience function to get the current handle radius.
virtual qreal viewToDocumentX(qreal viewX) const
KoSvgTextShape * selectedShape() const
T kisGrowRect(const T &rect, U offset)
Definition kis_global.h:186

References KoShape::absoluteTransformation(), KoSnapGuide::boundingRect(), KoSvgTextShape::boundingRect(), KoToolBase::canvas(), KoToolBase::handleRadius(), INLINE_SIZE_DASHES_PATTERN_A, INLINE_SIZE_DASHES_PATTERN_B, INLINE_SIZE_DASHES_PATTERN_LENGTH, kisGrowRect(), length(), m_hoveredShapeHighlightRect, selectedShape(), KoCanvasBase::snapGuide, KoCanvasBase::viewConverter(), and KoViewConverter::viewToDocumentX().

◆ deleteSelection()

void SvgTextTool::deleteSelection ( )
overridevirtual

reimplemented from superclass

Reimplemented from KoToolBase.

Definition at line 454 of file SvgTextTool.cpp.

455{
457}
void removeSelection()
removeSelection if there's a selection, creates a text-removal command.

References m_textCursor, and SvgTextCursor::removeSelection().

◆ deselect()

void SvgTextTool::deselect ( )
overridevirtual

deselect the tool should clear the selection if it has one.

Reimplemented from KoToolBase.

Definition at line 476 of file SvgTextTool.cpp.

477{
479}

References SvgTextCursor::deselectText(), and m_textCursor.

◆ focusInEvent()

void SvgTextTool::focusInEvent ( QFocusEvent * event)
overridevirtual

This passes on the focusInEven from the canvas widget, which can be used to activate animating decorations (like a cursor blink effect in the text tool).

Reimplemented from KoToolBase.

Definition at line 936 of file SvgTextTool.cpp.

937{
939 event->accept();
940}
void focusIn()
Turns on blinking cursor.

References SvgTextCursor::focusIn(), and m_textCursor.

◆ focusOutEvent()

void SvgTextTool::focusOutEvent ( QFocusEvent * event)
overridevirtual

This passes on the focusInEven from the canvas widget, which can be used to deactivate animating decorations (like a cursor blink effect in the text tool).

Reimplemented from KoToolBase.

Definition at line 942 of file SvgTextTool.cpp.

943{
945 event->accept();
946}
void focusOut()
Stops blinking cursor.

References SvgTextCursor::focusOut(), and m_textCursor.

◆ generateDefs

QString SvgTextTool::generateDefs ( const KoSvgTextProperties & properties = KoSvgTextProperties())
privateslot

generateDefs This generates a defs section with the appropriate css and css strings assigned.

Definition at line 361 of file SvgTextTool.cpp.

362{
363 QStringList propStrings;
364 QMap<QString, QString> paraProps = properties.convertParagraphProperties();
365 for (auto it = paraProps.constBegin(); it != paraProps.constEnd(); it++) {
366 propStrings.append(QString("%1: %2;").arg(it.key()).arg(it.value()));
367 }
368 paraProps = properties.convertToSvgTextAttributes();
369 for (auto it = paraProps.constBegin(); it != paraProps.constEnd(); it++) {
370 propStrings.append(QString("%1: %2;").arg(it.key()).arg(it.value()));
371 }
372
373 return QString("<defs>\n <style>\n text {\n %1\n }\n </style>\n</defs>").arg(propStrings.join("\n "));
374}
QMap< QString, QString > convertToSvgTextAttributes() const
QMap< QString, QString > convertParagraphProperties() const
convertParagraphProperties some properties only apply to the root shape, so we write those separately...

References KoSvgTextProperties::convertParagraphProperties(), and KoSvgTextProperties::convertToSvgTextAttributes().

◆ grabSensitivityInPt()

qreal SvgTextTool::grabSensitivityInPt ( ) const
private

Definition at line 974 of file SvgTextTool.cpp.

975{
976 const int sensitivity = grabSensitivity();
977 return canvas()->viewConverter()->viewToDocumentX(sensitivity);
978}
int grabSensitivity() const
Convenience function to get the current grab sensitivity.

References KoToolBase::canvas(), KoToolBase::grabSensitivity(), KoCanvasBase::viewConverter(), and KoViewConverter::viewToDocumentX().

◆ hasSelection()

bool SvgTextTool::hasSelection ( )
overridevirtual

reimplemented from superclass

Reimplemented from KoToolBase.

Definition at line 464 of file SvgTextTool.cpp.

465{
466 return m_textCursor.hasSelection();
467}
bool hasSelection() override
return true if the tool currently has something selected that can be copied or deleted.

References SvgTextCursor::hasSelection(), and m_textCursor.

◆ inputMethodEvent()

void SvgTextTool::inputMethodEvent ( QInputMethodEvent * event)
overridevirtual

Text entry of complex text, like CJK, can be made more interactive if a tool implements this and the InputMethodQuery() methods. Reimplementing this only provides the user with a more responsive text experience, since the default implementation forwards the typed text as key pressed events.

Parameters
eventthe input method event.

Reimplemented from KoToolBase.

Definition at line 209 of file SvgTextTool.cpp.

210{
212}
void inputMethodEvent(QInputMethodEvent *event)

References SvgTextCursor::inputMethodEvent(), and m_textCursor.

◆ inputMethodQuery()

QVariant SvgTextTool::inputMethodQuery ( Qt::InputMethodQuery query) const
overridevirtual

This method is used to query a set of properties of the tool to be able to support complex input method operations as support for surrounding text and reconversions. Default implementation returns simple defaults, for tools that want to provide a more responsive text entry experience for CJK languages it would be good to reimplement.

Parameters
queryspecifies which property is queried.
converterthe view converter for the current canvas.

Reimplemented from KoToolBase.

Definition at line 200 of file SvgTextTool.cpp.

201{
202 if (canvas()) {
203 return m_textCursor.inputMethodQuery(query);
204 } else {
205 return KoToolBase::inputMethodQuery(query);
206 }
207}
virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const
QVariant inputMethodQuery(Qt::InputMethodQuery query) const

References KoToolBase::canvas(), KoToolBase::inputMethodQuery(), SvgTextCursor::inputMethodQuery(), and m_textCursor.

◆ insertRichText

void SvgTextTool::insertRichText ( KoSvgTextShape * richText,
bool replaceLastGlyph = false )
privateslot

insertRichText Insert a rich text shape, used by the glyph palette..

Parameters
richText– rich text shape.
replaceLastGlyph– whether to replace the last glyph or to fully insert.

Definition at line 345 of file SvgTextTool.cpp.

346{
347 if (replaceLastGlyph) {
350 }
352}
The SvgTextCursor class.
void setPos(int pos, int anchor)
Set the pos and the anchor.
void insertRichText(KoSvgTextShape *insert)
Insert rich text at getPos();.
void moveCursor(MoveMode mode, bool moveAnchor=true)
Move the cursor, and, if you don't want a selection, move the anchor.
int getPos()
Get the current position.

References SvgTextCursor::getPos(), SvgTextCursor::insertRichText(), m_textCursor, SvgTextCursor::moveCursor(), SvgTextCursor::MoveNextChar, SvgTextCursor::MovePreviousChar, and SvgTextCursor::setPos().

◆ keyPressEvent()

void SvgTextTool::keyPressEvent ( QKeyEvent * event)
overridevirtual

Called when a key is pressed. Implementors should call event->ignore() if they do not actually use the event. Default implementation ignores this event.

Parameters
eventstate and reason of this key press

Reimplemented from KoToolBase.

Definition at line 907 of file SvgTextTool.cpp.

908{
910 && (event->key() == Qt::Key_Control || event->key() == Qt::Key_Alt || event->key() == Qt::Key_Shift
911 || event->key() == Qt::Key_Meta)) {
912 m_interactionStrategy->handleMouseMove(m_lastMousePos, event->modifiers());
913 event->accept();
914 return;
915 } else if (event->key() == Qt::Key_Escape) {
917 } else if (selectedShape()) {
919 }
920
921 event->ignore();
922}
std::unique_ptr< KoInteractionStrategy > m_interactionStrategy
void requestStrokeEnd() override
QPointF m_lastMousePos
void keyPressEvent(QKeyEvent *event)
Handle the cursor-related key events.

References SvgTextCursor::keyPressEvent(), m_interactionStrategy, m_lastMousePos, m_textCursor, requestStrokeEnd(), and selectedShape().

◆ keyReleaseEvent()

void SvgTextTool::keyReleaseEvent ( QKeyEvent * event)
overridevirtual

Called when a key is released Implementors should call event->ignore() if they do not actually use the event. Default implementation ignores this event.

Parameters
eventstate and reason of this key release

Reimplemented from KoToolBase.

Definition at line 924 of file SvgTextTool.cpp.

925{
927 && (event->key() == Qt::Key_Control || event->key() == Qt::Key_Alt || event->key() == Qt::Key_Shift
928 || event->key() == Qt::Key_Meta)) {
929 m_interactionStrategy->handleMouseMove(m_lastMousePos, event->modifiers());
930 event->accept();
931 } else {
932 event->ignore();
933 }
934}

References m_interactionStrategy, and m_lastMousePos.

◆ koSelection()

KoSelection * SvgTextTool::koSelection ( ) const
protected

Definition at line 259 of file SvgTextTool.cpp.

260{
262 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(canvas()->selectedShapesProxy(), 0);
263
264 return canvas()->selectedShapesProxy()->selection();
265}
virtual KoSelectedShapesProxy * selectedShapesProxy() const =0
selectedShapesProxy() is a special interface for keeping a persistent connections to selectionChanged...
virtual KoSelection * selection()=0
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
Definition kis_assert.h:129

References KoToolBase::canvas(), KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE, KoCanvasBase::selectedShapesProxy(), and KoSelectedShapesProxy::selection().

◆ mouseDoubleClickEvent()

void SvgTextTool::mouseDoubleClickEvent ( KoPointerEvent * event)
overridevirtual

reimplemented from superclass

Reimplemented from KoToolBase.

Definition at line 948 of file SvgTextTool.cpp.

949{
950 if (canvas()->shapeManager()->shapeAt(event->point) != selectedShape()) {
951 event->ignore(); // allow the event to be used by another
952 return;
953 } else {
954 m_textCursor.setPosToPoint(event->point, true);
957 }
958 const QRectF updateRect = std::exchange(m_hoveredShapeHighlightRect, QPainterPath()).boundingRect();
959 canvas()->updateCanvas(kisGrowRect(updateRect, 100));
960 event->accept();
961}
virtual void updateCanvas(const QRectF &rc)=0
QPointF point
The point in document coordinates.
void setPosToPoint(QPointF point, bool moveAnchor=true)
Set the pos from a point. This currently does a search inside the text shape.

References KoToolBase::canvas(), kisGrowRect(), m_hoveredShapeHighlightRect, m_textCursor, SvgTextCursor::moveCursor(), SvgTextCursor::MoveWordLeft, SvgTextCursor::MoveWordRight, KoPointerEvent::point, selectedShape(), SvgTextCursor::setPosToPoint(), and KoCanvasBase::updateCanvas().

◆ mouseMoveEvent()

void SvgTextTool::mouseMoveEvent ( KoPointerEvent * event)
overridevirtual

reimplemented from KoToolBase

Implements KoToolBase.

Definition at line 760 of file SvgTextTool.cpp.

761{
762 m_lastMousePos = event->point;
763 m_hoveredShapeHighlightRect = QPainterPath();
764
765
767 m_interactionStrategy->handleMouseMove(event->point, event->modifiers());
770 if (c && c->draggingInlineSize()) {
771 if (this->writingMode() == KoSvgText::HorizontalTB) {
773 } else {
775 }
776 } else {
778 }
779 } else if (m_dragging == DragMode::Select && this->selectedShape()) {
781 // Todo: replace with something a little less hacky.
782 if (selectedShape->writingMode() == KoSvgText::HorizontalTB) {
784 } else {
786 }
787 }
788 event->accept();
789 } else {
792 QCursor cursor = m_base_cursor;
793 if (selectedShape) {
795 const qreal sensitivity = grabSensitivityInPt();
796
797 if (std::optional<InlineSizeInfo> info = InlineSizeInfo::fromShape(selectedShape)) {
798 const QPolygonF zone = info->endLineGrabRect(sensitivity);
799 const QPolygonF startZone = info->startLineGrabRect(sensitivity);
800 if (zone.containsPoint(event->point, Qt::OddEvenFill)) {
802 cursor = lineToCursor(info->baselineLine(), canvas());
803 } else if (startZone.containsPoint(event->point, Qt::OddEvenFill)){
805 cursor = lineToCursor(info->baselineLine(), canvas());
806 }
807 }
808
810 const QPolygonF textOutline = selectedShape->absoluteTransformation().map(selectedShape->outlineRect());
811 const QPolygonF moveBorderRegion = selectedShape->absoluteTransformation().map(kisGrowRect(selectedShape->outlineRect(),
812 sensitivity * 2));
813 if (moveBorderRegion.containsPoint(event->point, Qt::OddEvenFill) && !textOutline.containsPoint(event->point, Qt::OddEvenFill)) {
815 cursor = Qt::SizeAllCursor;
816 }
817 }
818 }
819
820 QString shapeType;
821 bool isHorizontal = true;
822 const KoSvgTextShape *hoveredShape = dynamic_cast<KoSvgTextShape *>(canvas()->shapeManager()->shapeAt(event->point));
823 QPainterPath hoverPath = KisToolUtils::shapeHoverInfoCrossLayer(canvas(), event->point, shapeType, &isHorizontal);
824 if (selectedShape && selectedShape == hoveredShape && m_highlightItem == HighlightItem::None) {
827 } else {
829 }
830 } else if (hoveredShape) {
831 if (!hoveredShape->shapesInside().isEmpty()) {
832 QPainterPath paths;
833 Q_FOREACH(KoShape *s, hoveredShape->shapesInside()) {
834 KoPathShape *path = dynamic_cast<KoPathShape *>(s);
835 if (path) {
836 paths.addPath(hoveredShape->absoluteTransformation().map(path->absoluteTransformation().map(path->outline())));
837 }
838 }
839 if (!paths.isEmpty()) {
841 }
842 } else {
843 m_hoveredShapeHighlightRect.addRect(hoveredShape->boundingRect());
844 }
845 if (hoveredShape->writingMode() == KoSvgText::HorizontalTB) {
847 } else {
849 }
850 } else if (!hoverPath.isEmpty() && shapeType == KoSvgTextShape_SHAPEID && m_highlightItem == HighlightItem::None) {
851 m_hoveredShapeHighlightRect = hoverPath;
852 if (isHorizontal) {
854 } else {
856 }
857 }
858#if 0
861 KoPathShape *shape = dynamic_cast<KoPathShape *>(canvas()->shapeManager()->shapeAt(event->point));
862 if (shape) {
863 if (shape->subpathCount() > 0) {
864 if (shape->isClosedSubpath(0)) {
866 }
867 }
868 KoPathSegment segment = segmentAtPoint(event->point, shape, handleGrabRect(event->point));
869 if (segment.isValid()) {
871 }
872 m_hoveredShapeHighlightRect.addPath(shape->absoluteTransformation().map(shape->outline()));
873 } else {
874 m_hoveredShapeHighlightRect = QPainterPath();
875 }
876 }
877#endif
879 event->ignore();
880 }
881
883}
#define KoSvgTextShape_SHAPEID
static Qt::CursorShape lineToCursor(const QLineF line, const KoCanvasBase *const canvas)
virtual KoShapeManager * shapeManager() const =0
A KoPathSegment consist of two neighboring KoPathPoints.
bool isValid() const
Returns if segment is valid, e.g. has two valid points.
The position of a path point within a path shape.
Definition KoPathShape.h:63
bool isClosedSubpath(int subpathIndex) const
Checks if a subpath is closed.
QPainterPath outline() const override
reimplemented
int subpathCount() const
Returns the number of subpaths in the path.
Qt::KeyboardModifiers modifiers() const
KoShape * shapeAt(const QPointF &position, KoFlake::ShapeSelection selection=KoFlake::ShapeOnTop, bool omitHiddenShapes=true)
QList< KoShape * > shapesInside
KoSvgText::WritingMode writingMode() const
writingMode There's a number of places we need to check the writing mode to provide proper controls.
QRectF outlineRect() const override
QCursor cursor() const
return the last emitted cursor
QRectF handleGrabRect(const QPointF &position) const
DragMode m_dragging
qreal grabSensitivityInPt() const
HighlightItem m_highlightItem
KoSvgText::WritingMode writingMode() const
QPainterPath shapeHoverInfoCrossLayer(KoCanvasBase *canvas, const QPointF &point, QString &shapeType, bool *isHorizontal, bool skipCurrentShapes)
shapeHoverInfoCrossLayer get hover info of shapes on all layers.
@ HorizontalTB
Definition KoSvgText.h:38

References KoShape::absoluteTransformation(), KoSvgTextShape::boundingRect(), KoToolBase::canvas(), Create, KoToolBase::cursor(), SvgCreateTextStrategy::draggingInlineSize(), grabSensitivityInPt(), KoToolBase::handleGrabRect(), KoSvgText::HorizontalTB, InlineSizeEndHandle, InlineSizeStartHandle, KoPathShape::isClosedSubpath(), KoPathSegment::isValid(), kisGrowRect(), KoSvgTextShape_SHAPEID, lineToCursor(), m_base_cursor, m_dragging, m_highlightItem, m_hoveredShapeHighlightRect, m_ibeam_horizontal, m_ibeam_horizontal_done, m_ibeam_vertical, m_interactionStrategy, m_lastMousePos, m_text_in_shape, m_text_inline_horizontal, m_text_inline_vertical, m_text_on_path, KoPointerEvent::modifiers(), MoveBorder, None, KoPathShape::outline(), KoSvgTextShape::outlineRect(), KoPointerEvent::point, KoToolBase::repaintDecorations(), Select, selectedShape(), KoShapeManager::shapeAt(), KisToolUtils::shapeHoverInfoCrossLayer(), KoCanvasBase::shapeManager(), KoSvgTextShape::shapesInside, KoPathShape::subpathCount(), KoToolBase::useCursor(), KoSvgTextShape::writingMode(), and writingMode().

◆ mousePressEvent()

void SvgTextTool::mousePressEvent ( KoPointerEvent * event)
overridevirtual

reimplemented from KoToolBase

Implements KoToolBase.

Definition at line 678 of file SvgTextTool.cpp.

679{
681
682 if (selectedShape) {
686 event->accept();
687 return;
691 event->accept();
692 return;
696 event->accept();
697 return;
698 }
699 }
700
701 KoSvgTextShape *hoveredShape = dynamic_cast<KoSvgTextShape *>(canvas()->shapeManager()->shapeAt(event->point));
702 QString shapeType;
703 QPainterPath hoverPath = KisToolUtils::shapeHoverInfoCrossLayer(canvas(), event->point, shapeType);
704 bool crossLayerPossible = !hoverPath.isEmpty() && shapeType == KoSvgTextShape_SHAPEID;
705
706 if (!selectedShape && !hoveredShape && !crossLayerPossible) {
707 QPointF point = canvas()->snapGuide()->snap(event->point, event->modifiers());
708 m_interactionStrategy.reset(new SvgCreateTextStrategy(this, point));
710 event->accept();
711 } else if (hoveredShape) {
712 if (hoveredShape != selectedShape) {
714 canvas()->shapeManager()->selection()->select(hoveredShape);
715 m_hoveredShapeHighlightRect = QPainterPath();
716 }
719 event->accept();
720 } else if (crossLayerPossible) {
724 m_hoveredShapeHighlightRect = QPainterPath();
725 } else {
727 }
728 event->accept();
729 } else { // if there's a selected shape but no hovered shape...
731 event->accept();
732 }
733
735}
void deselectAll()
clear the selections list
void select(KoShape *shape)
KoSelection * selection
QPointF snap(const QPointF &mousePosition, Qt::KeyboardModifiers modifiers)
snaps the mouse position, returns if mouse was snapped
friend class SvgCreateTextStrategy
Definition SvgTextTool.h:36
bool selectShapeCrossLayer(KoCanvasBase *canvas, const QPointF &point, const QString &shapeType, bool skipCurrentShapes)
selectShapeCrossLayer Tries to select a shape under the cursor regardless of which layer it is on,...

References KoToolBase::canvas(), Create, KoSelection::deselectAll(), InlineSizeEndHandle, InlineSizeHandle, InlineSizeStartHandle, KoSvgTextShape_SHAPEID, m_dragging, m_highlightItem, m_hoveredShapeHighlightRect, m_interactionStrategy, m_textCursor, KoPointerEvent::modifiers(), Move, MoveBorder, KoPointerEvent::point, KoToolBase::repaintDecorations(), KoSelection::select(), Select, selectedShape(), KoShapeManager::selection, KisToolUtils::selectShapeCrossLayer(), KoShapeManager::shapeAt(), KisToolUtils::shapeHoverInfoCrossLayer(), KoCanvasBase::shapeManager(), KoSnapGuide::snap(), KoCanvasBase::snapGuide, and SvgCreateTextStrategy.

◆ mouseReleaseEvent()

void SvgTextTool::mouseReleaseEvent ( KoPointerEvent * event)
overridevirtual

reimplemented from KoToolBase

Implements KoToolBase.

Definition at line 885 of file SvgTextTool.cpp.

886{
888 m_interactionStrategy->finishInteraction(event->modifiers());
889 KUndo2Command *const command = m_interactionStrategy->createCommand();
890 if (command) {
892 canvas()->addCommand(command);
894 }
895 m_interactionStrategy = nullptr;
898 }
900 event->accept();
901 } else {
903 }
904 event->accept();
905}
virtual void addCommand(KUndo2Command *command)=0
bool m_strategyAddingCommand

References KoCanvasBase::addCommand(), KoToolBase::canvas(), m_base_cursor, m_dragging, m_interactionStrategy, m_strategyAddingCommand, KoPointerEvent::modifiers(), None, Select, and KoToolBase::useCursor().

◆ mouseTripleClickEvent()

void SvgTextTool::mouseTripleClickEvent ( KoPointerEvent * event)
overridevirtual

reimplemented from KoToolBase

Reimplemented from KoToolBase.

Definition at line 963 of file SvgTextTool.cpp.

964{
965 if (canvas()->shapeManager()->shapeAt(event->point) == selectedShape()) {
966 // TODO: Consider whether we want to use sentence based selection instead:
967 // QTextBoundaryFinder allows us to find sentences if necessary.
970 event->accept();
971 }
972}

References KoToolBase::canvas(), m_textCursor, SvgTextCursor::moveCursor(), SvgTextCursor::ParagraphEnd, SvgTextCursor::ParagraphStart, KoPointerEvent::point, and selectedShape().

◆ paint()

void SvgTextTool::paint ( QPainter & gc,
const KoViewConverter & converter )
overridevirtual

reimplemented from KoToolBase

Implements KoToolBase.

Definition at line 589 of file SvgTextTool.cpp.

590{
591 if (!isActivated()) return;
592
594 m_interactionStrategy->paint(gc, converter);
595 }
596
597 KoSvgTextShape *shape = selectedShape();
598 if (shape) {
599 KisHandlePainterHelper handlePainter =
601
604 QPainterPath path;
605 path.addRect(shape->outlineRect());
606 handlePainter.drawPath(path);
607 }
608
609
610 qreal pxlToPt = canvas()->viewConverter()->viewToDocumentX(1.0);
612 if (std::optional<InlineSizeInfo> info = InlineSizeInfo::fromShape(shape, length * pxlToPt)) {
614 handlePainter.drawConnectionLine(info->baselineLineLocal());
615
619 }
621 handlePainter.drawHandleLine(info->startLineLocal());
622 handlePainter.drawHandleLine(info->startLineDashes(), INLINE_SIZE_HANDLE_THICKNESS, dashPattern, INLINE_SIZE_DASHES_PATTERN_A);
623
628 }
629 handlePainter.drawHandleLine(info->endLineLocal());
630 handlePainter.drawHandleLine(info->endLineDashes(), INLINE_SIZE_HANDLE_THICKNESS, dashPattern, INLINE_SIZE_DASHES_PATTERN_A);
631 }
632
635 } else {
637 }
638 handlePainter.drawHandleCircle(QPointF(), KoToolBase::handleRadius() * 0.75);
639 }
640
641 gc.setTransform(converter.documentToView(), true);
642 {
644 if (!m_hoveredShapeHighlightRect.isEmpty()) {
646 QPainterPath path;
647 path.addPath(m_hoveredShapeHighlightRect);
648 handlePainter.drawPath(path);
649 }
650 }
651 if (shape) {
652 m_textCursor.paintDecorations(gc, qApp->palette().color(QPalette::Highlight), decorationThickness());
653 }
655 gc.save();
656 canvas()->snapGuide()->paint(gc, converter);
657 gc.restore();
658 }
659
660 // Paint debug outline
661 if (debugEnabled() && shape) {
662 gc.save();
663 using Element = KoSvgTextShape::DebugElement;
664 KoSvgTextShape::DebugElements el{};
665 if (m_optionManager->showCharacterDebug()) {
666 el |= Element::CharBbox;
667 }
668 if (m_optionManager->showLineDebug()) {
669 el |= Element::LineBox;
670 }
671
672 gc.setTransform(shape->absoluteTransformation(), true);
673 shape->paintDebug(gc, el);
674 gc.restore();
675 }
676}
constexpr double INLINE_SIZE_HANDLE_THICKNESS
Total amount of trailing dashes on inline-size handles.
The KisHandlePainterHelper class is a special helper for painting handles around objects....
void drawPath(const QPainterPath &path)
void drawConnectionLine(const QLineF &line)
void setHandleStyle(const KisHandleStyle &style)
void drawHandleLine(const QLineF &line, qreal width=1.0, QVector< qreal > dashPattern={}, qreal dashOffset=0.0)
void drawHandleCircle(const QPointF &center, qreal radius)
static KisHandleStyle & highlightedPrimaryHandlesWithSolidOutline()
static KisHandleStyle & highlightedPrimaryHandles()
static KisHandleStyle & partiallyHighlightedPrimaryHandles()
static KisHandleStyle & secondarySelection()
static KisHandleStyle & primarySelection()
static KisHandlePainterHelper createHandlePainterHelperView(QPainter *painter, KoShape *shape, const KoViewConverter &converter, qreal handleRadius=0.0, int decorationThickness=1)
Definition KoShape.cpp:1177
void paint(QPainter &painter, const KoViewConverter &converter)
paints the guide
void paintDebug(QPainter &painter, DebugElements elements) const
bool isActivated() const
int decorationThickness() const
decorationThickness The minimum thickness for tool decoration lines, this is derived from the screen ...
virtual QPointF documentToView(const QPointF &documentPoint) const
void paintDecorations(QPainter &gc, QColor selectionColor, int decorationThickness=1)

References KoShape::absoluteTransformation(), KoToolBase::canvas(), Create, KoShape::createHandlePainterHelperView(), debugEnabled(), KoToolBase::decorationThickness(), KoViewConverter::documentToView(), KisHandlePainterHelper::drawConnectionLine(), KisHandlePainterHelper::drawHandleCircle(), KisHandlePainterHelper::drawHandleLine(), KisHandlePainterHelper::drawPath(), KoToolBase::handleRadius(), KisHandleStyle::highlightedPrimaryHandles(), KisHandleStyle::highlightedPrimaryHandlesWithSolidOutline(), INLINE_SIZE_DASHES_PATTERN_A, INLINE_SIZE_DASHES_PATTERN_B, INLINE_SIZE_DASHES_PATTERN_LENGTH, INLINE_SIZE_HANDLE_THICKNESS, InlineSizeEndHandle, InlineSizeHandle, InlineSizeStartHandle, KoToolBase::isActivated(), length(), m_dragging, m_highlightItem, m_hoveredShapeHighlightRect, m_interactionStrategy, m_optionManager, m_textCursor, Move, MoveBorder, KoSvgTextShape::outlineRect(), KoSnapGuide::paint(), KoSvgTextShape::paintDebug(), SvgTextCursor::paintDecorations(), KisHandleStyle::partiallyHighlightedPrimaryHandles(), KisHandleStyle::primarySelection(), KisHandleStyle::secondarySelection(), selectedShape(), KisHandlePainterHelper::setHandleStyle(), KoCanvasBase::snapGuide, KoCanvasBase::viewConverter(), and KoViewConverter::viewToDocumentX().

◆ paste()

bool SvgTextTool::paste ( )
overridevirtual

reimplemented from superclass

Reimplemented from KoToolBase.

Definition at line 459 of file SvgTextTool.cpp.

460{
461 return m_textCursor.paste();
462}
bool paste()
paste pastes plain text in the clipboard at pos. Uses pasteRichTextByDefault to determine whether to ...

References m_textCursor, and SvgTextCursor::paste().

◆ popupWidget()

KisPopupWidgetInterface * SvgTextTool::popupWidget ( )
overridevirtual
Returns
a widget with useful controls to be popped up on top of the canvas. Will not be called if popupActionsMenu() does not return null.

Reimplemented from KoToolBase.

Definition at line 195 of file SvgTextTool.cpp.

196{
197 return nullptr;
198}

◆ propertiesForNewText

KoSvgTextProperties SvgTextTool::propertiesForNewText ( ) const
privateslot

propertiesForNewText get the text properties that should be used for new text.

Definition at line 376 of file SvgTextTool.cpp.

377{
378 const bool useCurrent = m_optionManager->optionsModel()->useCurrentTextProperties();
379 const QString presetName = m_optionManager->optionsModel()->cssStylePresetName();
380
382 if (useCurrent || presetName.isEmpty()) {
384 props = textData.commonProperties;
385 } else {
387 QVector<KoResourceSP> res = model->resourcesForName(presetName);
388 if (res.first()) {
389 KoCssStylePresetSP style = res.first().staticCast<KoCssStylePreset>();
390 qreal dpi = 72;
391 KisCanvas2 *canvas2 = qobject_cast<KisCanvas2 *>(this->canvas());
392 if (canvas2) {
393 dpi = canvas2->image()->xRes() * 72.0;
394 }
395 if (style) {
396 props = style->properties(dpi, true);
397 }
398 }
399 }
400
401 QColor fontColor = (canvas()->resourceManager()->isUsingOtherColor()
402 ? canvas()->resourceManager()->backgroundColor()
403 : canvas()->resourceManager()->foregroundColor()).toQColor();
405 bg->setColor(fontColor);
407 props.setProperty(KoSvgTextProperties::FillId, QVariant::fromValue(bgProp));
408 return props;
409}
The KisAllresourcesModel class provides access to the cache database for a particular resource type....
QVector< KoResourceSP > resourcesForName(const QString &name) const
KisImageWSP image() const
double xRes() const
static KisAllResourcesModel * resourceModel(const QString &resourceType)
QPointer< KoCanvasResourceProvider > resourceManager
A simple solid color shape background.
The KoCssStylePreset class.
@ FillId
KoSvgText::BackgroundProperty.
void setProperty(PropertyId id, const QVariant &value)
@ SvgTextPropertyData
KoSvgTextPropertyDataStruct.
const QString CssStyles
The KoSvgTextPropertyData struct.
KoSvgTextProperties commonProperties
The properties common between all the selected text.
BackgroundProperty is a special wrapper around KoShapeBackground for managing it in KoSvgTextProperti...
Definition KoSvgText.h:714

References KoToolBase::canvas(), KoSvgTextPropertyData::commonProperties, ResourceType::CssStyles, KoSvgTextProperties::FillId, KisCanvas2::image(), m_optionManager, KoCanvasBase::resourceManager, KisResourceModelProvider::resourceModel(), KisAllResourcesModel::resourcesForName(), KoSvgTextProperties::setProperty(), KoCanvasResource::SvgTextPropertyData, and KisImage::xRes().

◆ requestStrokeCancellation()

void SvgTextTool::requestStrokeCancellation ( )
overridevirtual

Called when the user requested the cancellation of the current stroke. If you tool supports cancelling, override this method and do the needed work there

Doing nothing, since these signals come on undo/redo actions in the mainland undo stack, which we manipulate while editing text

Reimplemented from KoToolBase.

Definition at line 501 of file SvgTextTool.cpp.

502{
508}

◆ requestStrokeEnd()

void SvgTextTool::requestStrokeEnd ( )
overridevirtual

Called when the image decided that the stroke should better be ended. If you tool supports long strokes, override this method and do the needed work there

Reimplemented from KoToolBase.

Definition at line 486 of file SvgTextTool.cpp.

487{
488 if (!isActivated()) return;
492 m_interactionStrategy->cancelInteraction();
493 m_interactionStrategy = nullptr;
494 useCursor(Qt::ArrowCursor);
495 } else if (isInTextMode()) {
497 }
498 }
499}
bool isInTextMode() const

References KoToolBase::canvas(), KoSelection::deselectAll(), KoToolBase::isActivated(), SvgTextCursor::isAddingCommand, KoToolBase::isInTextMode(), m_dragging, m_interactionStrategy, m_strategyAddingCommand, m_textCursor, None, KoShapeManager::selection, KoCanvasBase::shapeManager(), and KoToolBase::useCursor().

◆ selectAll()

bool SvgTextTool::selectAll ( )
overridevirtual

selectAll select all data the tool can select.

Returns
true if something happened, false if nothing happened.

Reimplemented from KoToolBase.

Definition at line 469 of file SvgTextTool.cpp.

References m_textCursor, SvgTextCursor::moveCursor(), SvgTextCursor::ParagraphEnd, and SvgTextCursor::ParagraphStart.

◆ selectedShape()

KoSvgTextShape * SvgTextTool::selectedShape ( ) const
protected

Definition at line 267 of file SvgTextTool.cpp.

268{
270 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(canvas()->selectedShapesProxy(), 0);
271
273 if (shapes.isEmpty()) return 0;
274
275 KoSvgTextShape *textShape = dynamic_cast<KoSvgTextShape*>(shapes.first());
276
277 return textShape;
278}
const QList< KoShape * > selectedEditableShapes() const
KoSelection * koSelection() const

References KoToolBase::canvas(), KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE, koSelection(), and KoSelection::selectedEditableShapes().

◆ selection()

KoToolSelection * SvgTextTool::selection ( )
overridevirtual

reimplemented from superclass

Reimplemented from KoToolBase.

Definition at line 481 of file SvgTextTool.cpp.

482{
483 return &m_textCursor;
484}

References m_textCursor.

◆ showEditor

void SvgTextTool::showEditor ( )
privateslot

Definition at line 280 of file SvgTextTool.cpp.

281{
282 KoSvgTextShape *shape = selectedShape();
283 if (!shape) return;
284
285 if (!m_editor) {
286 m_editor = new SvgTextEditor(QApplication::activeWindow());
287 m_editor->setWindowTitle(i18nc("@title:window", "Krita - Edit Text"));
288 m_editor->setWindowModality(Qt::ApplicationModal);
289 m_editor->setAttribute( Qt::WA_QuitOnClose, false );
290
291 connect(m_editor, SIGNAL(textUpdated(KoSvgTextShape*,QString,QString)), SLOT(textUpdated(KoSvgTextShape*,QString,QString)));
292 connect(m_editor, SIGNAL(textEditorClosed()), SLOT(slotTextEditorClosed()));
293
294 m_editor->activateWindow(); // raise on creation only
295 }
296 if (!m_editor->isVisible()) {
297 m_editor->setInitialShape(shape);
298#ifdef Q_OS_ANDROID
299 // for window manager
300 m_editor->setWindowFlags(Qt::Dialog);
301 m_editor->menuBar()->setNativeMenuBar(false);
302#endif
303 m_editor->show();
304 }
305}
void slotTextEditorClosed()
void textUpdated(KoSvgTextShape *shape, const QString &svg, const QString &defs)

References connect(), m_editor, selectedShape(), slotTextEditorClosed(), and textUpdated().

◆ showGlyphPalette

void SvgTextTool::showGlyphPalette ( )
privateslot

showGlyphPalette Shows the glyph palette dialog.

Definition at line 313 of file SvgTextTool.cpp.

314{
315 if (!m_glyphPalette) {
316 m_glyphPalette = new GlyphPaletteDialog(QApplication::activeWindow());
317 m_glyphPalette->setAttribute( Qt::WA_QuitOnClose, false );
318
319 connect(&m_textCursor, SIGNAL(selectionChanged()), this, SLOT(updateGlyphPalette()));
320 connect(m_glyphPalette, SIGNAL(signalInsertRichText(KoSvgTextShape*, bool)), this, SLOT(insertRichText(KoSvgTextShape*, bool)));
321
322 m_glyphPalette->activateWindow();
323 }
324 if (!m_glyphPalette->isVisible()) {
325 m_glyphPalette->show();
327 }
328}
The GlyphPaletteDialog class.
void updateGlyphPalette()
updateGlyphPalette update the glyph palette dialog from the current selection.
void insertRichText(KoSvgTextShape *richText, bool replaceLastGlyph=false)
insertRichText Insert a rich text shape, used by the glyph palette..

References connect(), insertRichText(), m_glyphPalette, m_textCursor, KoToolBase::selectionChanged(), and updateGlyphPalette().

◆ slotConvertType

void SvgTextTool::slotConvertType ( int index)
privateslot

slotConvertType

Parameters
index

Definition at line 517 of file SvgTextTool.cpp.

517 {
518 if (selectedShape()) {
519 if (index == selectedShape()->textType()) return;
521 KUndo2Command *parentCommand = new KUndo2Command();
524 parentCommand->setText(cmd->text());
526 canvas()->addCommand(parentCommand);
528 }
529}
void setText(const KUndo2MagicString &text)
The SvgConvertTextTypeCommand class This command allows textshapes to be converted between preformatt...

References KoCanvasBase::addCommand(), KoToolBase::canvas(), KisCommandUtils::FlipFlopCommand::FINALIZING, SvgTextCursor::getPos(), KisCommandUtils::FlipFlopCommand::INITIALIZING, m_textCursor, selectedShape(), KoCanvasBase::selectedShapesProxy(), KUndo2Command::setText(), and slotTextTypeUpdated().

◆ slotShapeSelectionChanged

void SvgTextTool::slotShapeSelectionChanged ( )
privateslot

selectionChanged called when the canvas selection is changed.

Definition at line 411 of file SvgTextTool.cpp.

412{
414 if (shapes.size() == 1) {
415 KoSvgTextShape *textShape = selectedShape();
416 if (!textShape) {
418 return;
419 }
420 } else if (shapes.size() > 1) {
421 KoSvgTextShape *foundTextShape = nullptr;
422
423 Q_FOREACH (KoShape *shape, shapes) {
424 KoSvgTextShape *textShape = dynamic_cast<KoSvgTextShape*>(shape);
425 if (textShape) {
426 foundTextShape = textShape;
427 break;
428 }
429 }
430
432 if (foundTextShape) {
433 koSelection()->select(foundTextShape);
434 }
435 return;
436 }
437 KoSvgTextShape *const shape = selectedShape();
438 if (shape != m_textCursor.shape()) {
439 m_textCursor.setShape(shape);
440 if (shape) {
441 setTextMode(true);
442 } else {
443 setTextMode(false);
444 }
445 }
447}
void setTextMode(bool value)
KoSvgTextShape * shape

References KoSelection::deselectAll(), koSelection(), m_textCursor, KoSelection::select(), KoSelection::selectedEditableShapes(), selectedShape(), SvgTextCursor::setShape(), KoToolBase::setTextMode(), SvgTextCursor::shape, and slotTextTypeUpdated().

◆ slotTextEditorClosed

void SvgTextTool::slotTextEditorClosed ( )
privateslot

Definition at line 354 of file SvgTextTool.cpp.

355{
356 // change tools to the shape selection tool when we close the text editor to allow moving and further editing of the object.
357 // most of the time when we edit text, the shape selection tool is where we left off anyway
358 KoToolManager::instance()->switchToolRequested("InteractionTool");
359}
void switchToolRequested(const QString &id)
static KoToolManager * instance()
Return the toolmanager singleton.

References KoToolManager::instance(), and KoToolManager::switchToolRequested().

◆ slotTextTypeUpdated

void SvgTextTool::slotTextTypeUpdated ( )
privateslot

slotTextTypeUpdated Update the text type in the tool options.

Definition at line 541 of file SvgTextTool.cpp.

542{
543 KoSvgTextShape *shape = selectedShape();
544 if (m_optionManager) {
545 if (shape) {
546 m_optionManager->convertToTextType(int(shape->textType()));
547 action("text_type_preformatted")->setEnabled(true);
548 action("text_type_pre_positioned")->setEnabled(true);
549 action("text_type_inline_wrap")->setEnabled(true);
550 action("text_type_preformatted")->setChecked(shape->textType() == KoSvgTextShape::PreformattedText);
551 action("text_type_pre_positioned")->setChecked(shape->textType() == KoSvgTextShape::PrePositionedText);
552 action("text_type_inline_wrap")->setChecked(shape->textType() == KoSvgTextShape::InlineWrap);
553 } else {
554 m_optionManager->convertToTextType(-1);
555 action("text_type_preformatted")->setEnabled(false);
556 action("text_type_pre_positioned")->setEnabled(false);
557 action("text_type_inline_wrap")->setEnabled(false);
558 }
559 }
560}
TextType textType() const
textType This enum gives an indication of what kind of text this shape is. The different text types a...

References KoToolBase::action(), KoSvgTextShape::InlineWrap, m_optionManager, KoSvgTextShape::PreformattedText, KoSvgTextShape::PrePositionedText, selectedShape(), and KoSvgTextShape::textType().

◆ slotUpdateCursorDecoration

void SvgTextTool::slotUpdateCursorDecoration ( QRectF updateRect)
privateslot

updateCursor update the canvas decorations in a particular update rect for the text cursor.

Parameters
updateRectthe rect to update in.

Definition at line 510 of file SvgTextTool.cpp.

511{
512 if (canvas()) {
513 canvas()->updateCanvas(updateRect);
514 }
515}

References KoToolBase::canvas(), and KoCanvasBase::updateCanvas().

◆ slotUpdateTextPasteBehaviour

void SvgTextTool::slotUpdateTextPasteBehaviour ( )
privateslot

slotUpdateTextPasteBehaviour update the default text paste behaviour.

Definition at line 536 of file SvgTextTool.cpp.

537{
538 m_textCursor.setPasteRichTextByDefault(m_optionManager->optionsModel()->pasteRichtTextByDefault());
539}
void setPasteRichTextByDefault(const bool pasteRichText=true)
setPasteRichText

References m_optionManager, m_textCursor, and SvgTextCursor::setPasteRichTextByDefault().

◆ slotUpdateVisualCursor

void SvgTextTool::slotUpdateVisualCursor ( )
privateslot

slotUpdateVisualCursor update the visual cursor mode on the text cursor.

Definition at line 531 of file SvgTextTool.cpp.

532{
533 m_textCursor.setVisualMode(m_optionManager->optionsModel()->useVisualBidiCursor());
534}
void setVisualMode(const bool visualMode=true)
setVisualMode set whether the navigation mode is visual or logical. This right now primarily affects ...

References m_optionManager, m_textCursor, and SvgTextCursor::setVisualMode().

◆ textUpdated

void SvgTextTool::textUpdated ( KoSvgTextShape * shape,
const QString & svg,
const QString & defs )
privateslot

Definition at line 307 of file SvgTextTool.cpp.

308{
309 SvgTextChangeCommand *cmd = new SvgTextChangeCommand(shape, svg, defs);
310 canvas()->addCommand(cmd);
311}

References KoCanvasBase::addCommand(), and KoToolBase::canvas().

◆ updateGlyphPalette

void SvgTextTool::updateGlyphPalette ( )
privateslot

updateGlyphPalette update the glyph palette dialog from the current selection.

Definition at line 330 of file SvgTextTool.cpp.

331{
332 if (m_glyphPalette && m_glyphPalette->isVisible()) {
333 QString grapheme = QString();
334 if (m_textCursor.shape()) {
335 int pos = m_textCursor.getPos();
336 int pos2 = pos > 0? m_textCursor.shape()->posLeft(pos, false): m_textCursor.shape()->posRight(pos, false);
337 int start = m_textCursor.shape()->indexForPos(qMin(pos, pos2));
338 int end = m_textCursor.shape()->indexForPos(qMax(pos, pos2));
339 grapheme = m_textCursor.shape()->plainText().mid(start, end-start);
340 }
341 m_glyphPalette->setGlyphModelFromProperties(m_textCursor.currentTextProperties(), grapheme);
342 }
343}
int posLeft(int pos, bool visual=false)
int indexForPos(int pos) const
indexForPos get the string index for a given cursor position.
int posRight(int pos, bool visual=false)
QPair< KoSvgTextProperties, KoSvgTextProperties > currentTextProperties() const
currentTextProperties

References SvgTextCursor::currentTextProperties(), SvgTextCursor::getPos(), KoSvgTextShape::indexForPos(), m_glyphPalette, m_textCursor, KoSvgTextShape::plainText, KoSvgTextShape::posLeft(), KoSvgTextShape::posRight(), and SvgTextCursor::shape.

◆ writingMode()

KoSvgText::WritingMode SvgTextTool::writingMode ( ) const
private

Definition at line 980 of file SvgTextTool.cpp.

981{
984}
@ WritingModeId
KoSvgText::WritingMode.
QVariant propertyOrDefault(PropertyId id) const
KoSvgTextProperties propertiesForNewText() const
propertiesForNewText get the text properties that should be used for new text.

References propertiesForNewText(), KoSvgTextProperties::propertyOrDefault(), and KoSvgTextProperties::WritingModeId.

Friends And Related Symbol Documentation

◆ SvgCreateTextStrategy

friend class SvgCreateTextStrategy
friend

Definition at line 36 of file SvgTextTool.h.

Member Data Documentation

◆ m_base_cursor

QCursor SvgTextTool::m_base_cursor
private

Definition at line 208 of file SvgTextTool.h.

◆ m_canvasConnections

KisSignalAutoConnectionsStore SvgTextTool::m_canvasConnections
private

Definition at line 204 of file SvgTextTool.h.

◆ m_dragging

DragMode SvgTextTool::m_dragging {DragMode::None}
private

Definition at line 195 of file SvgTextTool.h.

◆ m_editor

QPointer<SvgTextEditor> SvgTextTool::m_editor
private

Definition at line 192 of file SvgTextTool.h.

◆ m_glyphPalette

QPointer<GlyphPaletteDialog> SvgTextTool::m_glyphPalette
private

Definition at line 193 of file SvgTextTool.h.

◆ m_highlightItem

HighlightItem SvgTextTool::m_highlightItem {HighlightItem::None}
private

Definition at line 197 of file SvgTextTool.h.

◆ m_hoveredShapeHighlightRect

QPainterPath SvgTextTool::m_hoveredShapeHighlightRect
private

Definition at line 206 of file SvgTextTool.h.

◆ m_ibeam_horizontal

QCursor SvgTextTool::m_ibeam_horizontal
private

Definition at line 214 of file SvgTextTool.h.

◆ m_ibeam_horizontal_done

QCursor SvgTextTool::m_ibeam_horizontal_done
private

Definition at line 215 of file SvgTextTool.h.

◆ m_ibeam_vertical

QCursor SvgTextTool::m_ibeam_vertical
private

Definition at line 213 of file SvgTextTool.h.

◆ m_interactionStrategy

std::unique_ptr<KoInteractionStrategy> SvgTextTool::m_interactionStrategy
private

Definition at line 196 of file SvgTextTool.h.

◆ m_lastMousePos

QPointF SvgTextTool::m_lastMousePos
private

Definition at line 194 of file SvgTextTool.h.

◆ m_optionManager

QScopedPointer<SvgTextToolOptionsManager> SvgTextTool::m_optionManager
private

Definition at line 191 of file SvgTextTool.h.

◆ m_strategyAddingCommand

bool SvgTextTool::m_strategyAddingCommand {false}
private

Definition at line 198 of file SvgTextTool.h.

198{false};

◆ m_text_in_shape

QCursor SvgTextTool::m_text_in_shape
private

Definition at line 212 of file SvgTextTool.h.

◆ m_text_inline_horizontal

QCursor SvgTextTool::m_text_inline_horizontal
private

Definition at line 209 of file SvgTextTool.h.

◆ m_text_inline_vertical

QCursor SvgTextTool::m_text_inline_vertical
private

Definition at line 210 of file SvgTextTool.h.

◆ m_text_on_path

QCursor SvgTextTool::m_text_on_path
private

Definition at line 211 of file SvgTextTool.h.

◆ m_textCursor

SvgTextCursor SvgTextTool::m_textCursor
private

Definition at line 203 of file SvgTextTool.h.

◆ m_textTypeSignalsMapper

QScopedPointer<KisSignalMapper> SvgTextTool::m_textTypeSignalsMapper
private

Definition at line 200 of file SvgTextTool.h.


The documentation for this class was generated from the following files: