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 , TextPathHandle , InShapeOffset , TypeSetting
}
 
enum class  HighlightItem {
  None = 0 , InlineSizeStartHandle , InlineSizeEndHandle , MoveBorder ,
  TypeSettingHandle
}
 

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 slotMoveTextSelection (int index)
 slotMoveTextSelection Move the start of the selection in typesetting mode by image 1 pix.
 
void slotShapeSelectionChanged ()
 selectionChanged called when the canvas selection is changed.
 
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 slotUpdateTypeSettingMode ()
 slotUpdateTypeSettingMode Enable typesetting mode from the tool options.
 
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.
 
void updateTextPathHelper ()
 

Private Member Functions

void addMappedAction (KisSignalMapper *mapper, const QString &actionName, const int value, QActionGroup *group=nullptr)
 
qreal grabSensitivityInPt () const
 
bool nodeEditable ()
 nodeEditable
 
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
 
SvgTextOnPathDecorationHelper m_textOnPathHelper
 
QScopedPointer< KoSvgTextShapeOutlineHelperm_textOutlineHelper
 
QScopedPointer< KisSignalMapperm_textTypeSignalsMapper
 
QScopedPointer< KisSignalMapperm_typeSettingMovementMapper
 

Friends

class SvgChangeTextPathInfoStrategy
 
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 35 of file SvgTextTool.h.

Member Enumeration Documentation

◆ DragMode

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

Definition at line 204 of file SvgTextTool.h.

◆ HighlightItem

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

Definition at line 214 of file SvgTextTool.h.

Constructor & Destructor Documentation

◆ SvgTextTool()

SvgTextTool::SvgTextTool ( KoCanvasBase * canvas)
explicit

Definition at line 100 of file SvgTextTool.cpp.

105{
106 // TODO: figure out whether we should use system config for this, Windows and GTK have values for it, but Qt and MacOS don't(?).
107 const int cursorFlashLimit = 5000;
108 const bool enableCursorWithSelection = QApplication::style()->styleHint(QStyle::SH_BlinkCursorWhenTextSelected);
109 m_textCursor.setCaretSetting(QApplication::style()->pixelMetric(QStyle::PM_TextCursorWidth)
110 , qApp->cursorFlashTime()
111 , cursorFlashLimit
112 , enableCursorWithSelection);
113 connect(&m_textCursor, SIGNAL(updateCursorDecoration(QRectF)), this, SLOT(slotUpdateCursorDecoration(QRectF)));
114
115 Q_FOREACH(const QString name, SvgTextShortCuts::possibleActions()) {
116 QAction *a = action(name);
118 dbgTools << "registered" << name << a->shortcut();
119 }
120 }
121
122 const QStringList extraActions = {
123 "svg_insert_special_character",
124 "svg_paste_rich_text",
125 "svg_paste_plain_text",
126 "svg_remove_transforms_from_range",
127 "svg_clear_formatting"
128 };
129 connect(&m_textCursor, SIGNAL(sigOpenGlyphPalette()), this, SLOT(showGlyphPalette()));
130 Q_FOREACH (const QString name, extraActions) {
131 QAction *a = action(name);
132 if (a) {
134 qWarning() << "could not register" << name << a->shortcut();
135 }
136 }
137 }
138
140 QActionGroup *textTypeActions = new QActionGroup(this);
141 addMappedAction(m_textTypeSignalsMapper.data(), "text_type_preformatted", KoSvgTextShape::PreformattedText, textTypeActions);
142 addMappedAction(m_textTypeSignalsMapper.data(), "text_type_inline_wrap", KoSvgTextShape::InlineWrap, textTypeActions);
143 addMappedAction(m_textTypeSignalsMapper.data(), "text_type_pre_positioned", KoSvgTextShape::PrePositionedText, textTypeActions);
144
146 QActionGroup *typeSettingActions = new QActionGroup(this);
147 addMappedAction(m_typeSettingMovementMapper.data(), "svg_type_setting_move_selection_start_down_1_px", Qt::Key_Down, typeSettingActions);
148 addMappedAction(m_typeSettingMovementMapper.data(), "svg_type_setting_move_selection_start_up_1_px", Qt::Key_Up, typeSettingActions);
149 addMappedAction(m_typeSettingMovementMapper.data(), "svg_type_setting_move_selection_start_left_1_px", Qt::Key_Left, typeSettingActions);
150 addMappedAction(m_typeSettingMovementMapper.data(), "svg_type_setting_move_selection_start_right_1_px", Qt::Key_Right, typeSettingActions);
151
152 m_textOutlineHelper->setDrawBoundingRect(false);
153 m_textOutlineHelper->setDrawTextWrappingArea(true);
154
155 connect(&m_textCursor, SIGNAL(selectionChanged()), this, SLOT(updateTextPathHelper()));
156
157 m_base_cursor = QCursor(QPixmap(":/tool_text_basic.xpm"), 7, 7);
158 m_text_inline_horizontal = QCursor(QPixmap(":/tool_text_inline_horizontal.xpm"), 7, 7);
159 m_text_inline_vertical = QCursor(QPixmap(":/tool_text_inline_vertical.xpm"), 7, 7);
160 m_text_on_path = QCursor(QPixmap(":/tool_text_on_path.xpm"), 7, 7);
161 m_text_in_shape = QCursor(QPixmap(":/tool_text_in_shape.xpm"), 7, 7);
162 m_ibeam_horizontal = QCursor(QPixmap(":/tool_text_i_beam_horizontal.xpm"), 11, 11);
163 m_ibeam_vertical = QCursor(QPixmap(":/tool_text_i_beam_vertical.xpm"), 11, 11);
164 m_ibeam_horizontal_done = QCursor(QPixmap(":/tool_text_i_beam_horizontal_done.xpm"), 5, 11);
165}
The KisSignalMapper class bundles signals from identifiable senders.
The KoSvgTextShapeOutlineHelper class helper class that draws the text outlines and contour mode butt...
@ 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.
void selectionChanged(bool hasSelection)
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
void updateTextPathHelper()
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
QScopedPointer< KisSignalMapper > m_typeSettingMovementMapper
SvgTextCursor m_textCursor
QScopedPointer< KoSvgTextShapeOutlineHelper > m_textOutlineHelper
void addMappedAction(KisSignalMapper *mapper, const QString &actionName, const int value, QActionGroup *group=nullptr)
#define dbgTools
Definition kis_debug.h:48
const char * name(StandardAction id)
void setCaretSetting(int cursorWidth=1, int cursorFlash=1000, int cursorFlashLimit=5000, bool drawCursorInAdditionToSelection=false)
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(), addMappedAction(), 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_textOutlineHelper, m_textTypeSignalsMapper, m_typeSettingMovementMapper, SvgTextShortCuts::possibleActions(), KoSvgTextShape::PreformattedText, KoSvgTextShape::PrePositionedText, SvgTextCursor::registerPropertyAction(), KoToolBase::selectionChanged(), SvgTextCursor::setCaretSetting(), showGlyphPalette(), slotUpdateCursorDecoration(), and updateTextPathHelper().

◆ ~SvgTextTool()

SvgTextTool::~SvgTextTool ( )
override

Definition at line 167 of file SvgTextTool.cpp.

168{
169 if(m_editor) {
170 m_editor->close();
171 }
172 if(m_glyphPalette) {
173 m_glyphPalette->close();
174 }
175}
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 177 of file SvgTextTool.cpp.

178{
179 KoToolBase::activate(shapes);
180 m_canvasConnections.addConnection(canvas()->selectedShapesProxy(), SIGNAL(selectionChanged()), this, SLOT(slotShapeSelectionChanged()));
181
182 KisCanvas2 *canvas2 = qobject_cast<KisCanvas2 *>(this->canvas());
183 if (canvas2) {
184 canvas2->setCurrentShapeManagerOwnerShape(nullptr);
186 QDockWidget *docker = canvas2->viewManager()->mainWindow()->dockWidget("TextProperties");
187 if (docker && m_optionManager) {
188 m_optionManager->setTextPropertiesOpen(docker->isVisible());
189 }
190 }
191
192 connect(m_textTypeSignalsMapper.data(), SIGNAL(mapped(int)), this, SLOT(slotConvertType(int)));
193 connect(m_typeSettingMovementMapper.data(), SIGNAL(mapped(int)), this, SLOT(slotMoveTextSelection(int)));
194
197
199}
void setCurrentShapeManagerOwnerShape(KoShape *source) override
sets the group shape that is supposed to be "entered"
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
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 slotMoveTextSelection(int index)
slotMoveTextSelection Move the start of the selection in typesetting mode by image 1 pix.
void slotConvertType(int index)
slotConvertType
KoSvgTextPropertiesInterface * textPropertyInterface()

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

◆ addMappedAction()

void SvgTextTool::addMappedAction ( KisSignalMapper * mapper,
const QString & actionName,
const int value,
QActionGroup * group = nullptr )
private

Definition at line 1137 of file SvgTextTool.cpp.

1138{
1139 QAction *a = action(actionName);
1140 if (a) {
1141 connect(a, SIGNAL(triggered()), mapper, SLOT(map()));
1142 mapper->setMapping(a, value);
1143 m_textCursor.registerPropertyAction(a, actionName);
1144 if (group && !a->actionGroup()) {
1145 group->addAction(a);
1146 }
1147 }
1148}
float value(const T *src, size_t ch)
void setMapping(QObject *sender, int id)

References KoToolBase::action(), m_textCursor, SvgTextCursor::registerPropertyAction(), KisSignalMapper::setMapping(), and value().

◆ copy()

void SvgTextTool::copy ( ) const
overridevirtual

reimplemented from superclass

Reimplemented from KoToolBase.

Definition at line 473 of file SvgTextTool.cpp.

474{
476}
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 238 of file SvgTextTool.cpp.

239{
240 KisQQuickWidget *optionWidget = new KisQQuickWidget();
241 optionWidget->setMinimumWidth(100);
242 optionWidget->setMinimumHeight(100);
243
244 optionWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
245 optionWidget->setSource(QUrl("qrc:/SvgTextToolOptions.qml"));
246
247 m_optionManager->optionsModel()->setConfigName(this->toolId());
248 m_optionManager->setShowDebug(debugEnabled());
249 if (optionWidget->errors().isEmpty()) {
250 optionWidget->rootObject()->setProperty("manager", QVariant::fromValue(m_optionManager.data()));
251 optionWidget->connectMinimumHeightToRootObject();
252 } else {
253 qWarning() << optionWidget->errors();
254 }
255
256
257 connect(m_optionManager.data(), SIGNAL(openTextEditor()), SLOT(showEditor()));
258 connect(m_optionManager.data(), SIGNAL(openGlyphPalette()), SLOT(showGlyphPalette()));
259
260 connect(m_optionManager.data(), SIGNAL(convertTextType(int)), SLOT(slotConvertType(int)));
261 connect(m_optionManager.data(), SIGNAL(typeSettingModeChanged()), SLOT(slotUpdateTypeSettingMode()));
262 connect(m_optionManager->optionsModel(), SIGNAL(useVisualBidiCursorChanged(bool)), this, SLOT(slotUpdateVisualCursor()));
263 connect(m_optionManager->optionsModel(), SIGNAL(pasteRichtTextByDefaultChanged(bool)), this, SLOT(slotUpdateTextPasteBehaviour()));
264 const KisCanvas2 *canvas2 = qobject_cast<const KisCanvas2 *>(this->canvas());
265 if (canvas2 && canvas2->viewManager()->mainWindow()) {
266 QDockWidget *docker = canvas2->viewManager()->mainWindow()->dockWidget("TextProperties");
267 m_optionManager->setShowTextPropertyButton((docker));
268 if (docker) {
269 optionWidget->setPalette(docker->palette());
270 m_optionManager->setTextPropertiesOpen(docker->isVisible());
272 docker->setVisible(!docker->isVisible());
273 });
274 // Once we have docker toggling actions, we should revisit this.
275 }
276 }
280
281
282 return optionWidget;
283}
static bool debugEnabled()
Linethickness.
The KisQQuickWidget class.
void connectMinimumHeightToRootObject()
connectMinimumHeightToRootObject By default we scale rootObject to widget, but in some situations we ...
Q_INVOKABLE QString toolId() const
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()
void slotUpdateTypeSettingMode()
slotUpdateTypeSettingMode Enable typesetting mode from the tool options.

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

◆ deactivate()

void SvgTextTool::deactivate ( )
overridevirtual

reimplemented from KoToolBase

Reimplemented from KoToolBase.

Definition at line 201 of file SvgTextTool.cpp.

202{
205 m_textCursor.setShape(nullptr);
206 const KisCanvas2 *canvas2 = qobject_cast<const KisCanvas2 *>(this->canvas());
207 if (canvas2) {
209 }
210 // Exiting text editing mode is handled by requestStrokeEnd
211 disconnect(m_textTypeSignalsMapper.data(), 0, this, 0);
212 disconnect(m_typeSettingMovementMapper.data(), 0, this, 0);
213
214 m_hoveredShapeHighlightRect = QPainterPath();
215
217}
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, m_typeSettingMovementMapper, 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 652 of file SvgTextTool.cpp.

653{
654 QRectF rect;
655 KoSvgTextShape *const shape = selectedShape();
656 if (shape) {
657 rect |= shape->boundingRect();
658
659 const QPointF anchor = shape->absoluteTransformation().map(QPointF());
660 rect |= kisGrowRect(QRectF(anchor, anchor), handleRadius());
661
662 qreal pxlToPt = canvas()->viewConverter()->viewToDocumentX(1.0);
664
665 if (std::optional<InlineSizeInfo> info = InlineSizeInfo::fromShape(shape, length * pxlToPt)) {
666 rect |= kisGrowRect(info->boundingRect(), handleRadius() * 2);
667 }
668
669 if (canvas()->snapGuide()->isSnapping()) {
671 }
672 }
673
674 rect |= m_hoveredShapeHighlightRect.boundingRect();
675
676 rect |= m_textOutlineHelper->decorationRect();
677 rect |= m_textOnPathHelper.decorationRect(canvas()->viewConverter()->documentToView());
678
679 return rect;
680}
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:330
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
QRectF decorationRect(const QTransform documentToView) const
decorationRect
KoSvgTextShape * selectedShape() const
SvgTextOnPathDecorationHelper m_textOnPathHelper
T kisGrowRect(const T &rect, U offset)
Definition kis_global.h:186

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

◆ deleteSelection()

void SvgTextTool::deleteSelection ( )
overridevirtual

reimplemented from superclass

Reimplemented from KoToolBase.

Definition at line 478 of file SvgTextTool.cpp.

479{
481}
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 500 of file SvgTextTool.cpp.

501{
503}
void deselectText()
Deselect all text. This effectively makes anchor the same as pos.

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 1087 of file SvgTextTool.cpp.

1088{
1090 event->accept();
1091}
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 1093 of file SvgTextTool.cpp.

1094{
1096 event->accept();
1097}
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 384 of file SvgTextTool.cpp.

385{
386 QStringList propStrings;
387 QMap<QString, QString> paraProps = properties.convertParagraphProperties();
388 for (auto it = paraProps.constBegin(); it != paraProps.constEnd(); it++) {
389 propStrings.append(QString("%1: %2;").arg(it.key()).arg(it.value()));
390 }
391 paraProps = properties.convertToSvgTextAttributes();
392 for (auto it = paraProps.constBegin(); it != paraProps.constEnd(); it++) {
393 propStrings.append(QString("%1: %2;").arg(it.key()).arg(it.value()));
394 }
395
396 return QString("<defs>\n <style>\n text {\n %1\n }\n </style>\n</defs>").arg(propStrings.join("\n "));
397}
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 1125 of file SvgTextTool.cpp.

1126{
1127 const int sensitivity = grabSensitivity();
1128 return canvas()->viewConverter()->viewToDocumentX(sensitivity);
1129}
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 488 of file SvgTextTool.cpp.

489{
490 return m_textCursor.hasSelection();
491}
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 233 of file SvgTextTool.cpp.

234{
236}
void inputMethodEvent(QInputMethodEvent *event)
Process an input method event. This is used by IME like virtual keyboards.

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 224 of file SvgTextTool.cpp.

225{
226 if (canvas()) {
227 return m_textCursor.inputMethodQuery(query);
228 } else {
229 return KoToolBase::inputMethodQuery(query);
230 }
231}
virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const
QVariant inputMethodQuery(Qt::InputMethodQuery query) const
Process an input method query and return the requested result.

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 375 of file SvgTextTool.cpp.

376{
377 if (replaceLastGlyph) {
380 }
381 m_textCursor.insertRichText(richText, true);
382}
The SvgTextCursor class.
void setPos(int pos, int anchor)
Set the pos and the anchor.
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.
void insertRichText(KoSvgTextShape *insert, bool inheritPropertiesIfPossible=false)
Insert rich text at getPos();.

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 1057 of file SvgTextTool.cpp.

1058{
1060 && (event->key() == Qt::Key_Control || event->key() == Qt::Key_Alt || event->key() == Qt::Key_Shift
1061 || event->key() == Qt::Key_Meta)) {
1062 m_interactionStrategy->handleMouseMove(m_lastMousePos, event->modifiers());
1063 event->accept();
1064 return;
1065 } else if (event->key() == Qt::Key_Escape) {
1067 } else if (selectedShape()) {
1069 }
1070
1071 event->ignore();
1072}
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 1074 of file SvgTextTool.cpp.

1075{
1076 m_textCursor.updateModifiers(event->modifiers());
1078 && (event->key() == Qt::Key_Control || event->key() == Qt::Key_Alt || event->key() == Qt::Key_Shift
1079 || event->key() == Qt::Key_Meta)) {
1080 m_interactionStrategy->handleMouseMove(m_lastMousePos, event->modifiers());
1081 event->accept();
1082 } else {
1083 event->ignore();
1084 }
1085}
void updateModifiers(const Qt::KeyboardModifiers modifiers)

References m_interactionStrategy, m_lastMousePos, m_textCursor, and SvgTextCursor::updateModifiers().

◆ koSelection()

KoSelection * SvgTextTool::koSelection ( ) const
protected

Definition at line 285 of file SvgTextTool.cpp.

286{
288 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(canvas()->selectedShapesProxy(), 0);
289
290 return canvas()->selectedShapesProxy()->selection();
291}
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 1099 of file SvgTextTool.cpp.

1100{
1101 if (canvas()->shapeManager()->shapeAt(event->point) != selectedShape()) {
1102 event->ignore(); // allow the event to be used by another
1103 return;
1104 } else {
1105 m_textCursor.setPosToPoint(event->point, true);
1108 }
1109 const QRectF updateRect = std::exchange(m_hoveredShapeHighlightRect, QPainterPath()).boundingRect();
1110 canvas()->updateCanvas(kisGrowRect(updateRect, 100));
1111 event->accept();
1112}
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 906 of file SvgTextTool.cpp.

907{
908 m_lastMousePos = event->point;
909 m_hoveredShapeHighlightRect = QPainterPath();
911
913 m_interactionStrategy->handleMouseMove(event->point, event->modifiers());
916 if (c && c->draggingInlineSize() && !c->hasWrappingShape()) {
917 if (this->writingMode() == KoSvgText::HorizontalTB) {
919 } else {
921 }
922 } else {
924 }
925 } else if (m_dragging == DragMode::Select && this->selectedShape()) {
927 // Todo: replace with something a little less hacky.
928 if (selectedShape->writingMode() == KoSvgText::HorizontalTB) {
930 } else {
932 }
933 } else if (m_dragging != DragMode::InShapeOffset) {
934 useCursor(Qt::ArrowCursor);
935 }
936 event->accept();
937 } else {
939
941 QCursor cursor = m_base_cursor;
942 if (selectedShape) {
944 const qreal sensitivity = grabSensitivityInPt();
945
948 if (handle != SvgTextCursor::NoHandle) {
951 }
952
954 if (std::optional<InlineSizeInfo> info = InlineSizeInfo::fromShape(selectedShape)) {
955 const QPolygonF zone = info->endLineGrabRect(sensitivity);
956 const QPolygonF startZone = info->startLineGrabRect(sensitivity);
957 if (zone.containsPoint(event->point, Qt::OddEvenFill)) {
959 cursor = lineToCursor(info->baselineLine(), canvas());
960 } else if (startZone.containsPoint(event->point, Qt::OddEvenFill)){
962 cursor = lineToCursor(info->baselineLine(), canvas());
963 }
964 }
965 }
966
968 const QPolygonF textOutline = selectedShape->absoluteTransformation().map(selectedShape->outlineRect());
969 const QPolygonF moveBorderRegion = selectedShape->absoluteTransformation().map(kisGrowRect(selectedShape->outlineRect(),
970 sensitivity * 2));
971 if (moveBorderRegion.containsPoint(event->point, Qt::OddEvenFill) && !textOutline.containsPoint(event->point, Qt::OddEvenFill)) {
973 cursor = Qt::SizeAllCursor;
974 }
975 }
976 }
977
978 QString shapeType;
979 bool isHorizontal = true;
980 const KoSvgTextShape *hoveredShape = dynamic_cast<KoSvgTextShape *>(canvas()->shapeManager()->shapeAt(event->point));
981 const KoPathShape *hoveredFlowShape = dynamic_cast<KoPathShape *>(canvas()->shapeManager()->shapeAt(event->point));
982 QPainterPath hoverPath = KisToolUtils::shapeHoverInfoCrossLayer(canvas(), event->point, shapeType, &isHorizontal);
983
984 bool textAreasHovered = false;
985 if (m_textOnPathHelper.hitTest(event->point, canvas()->viewConverter()->viewToDocument()) ) {
986 cursor = Qt::ArrowCursor;
987 } else if(std::optional<QPointF> offsetVector = SvgChangeTextPaddingMarginStrategy::hitTest(selectedShape, event->point, grabSensitivityInPt())) {
988 cursor = lineToCursor(QLineF(QPointF(0, 0), offsetVector.value()).normalVector(), canvas());
989 textAreasHovered = true;
990 } else if (selectedShape && selectedShape == hoveredShape && m_highlightItem == HighlightItem::None) {
993 } else {
995 }
996 } else if (hoveredShape && m_highlightItem == HighlightItem::None) {
997 if (!hoveredShape->textWrappingAreas().isEmpty()) {
998 Q_FOREACH(QPainterPath path, hoveredShape->textWrappingAreas()) {
999 m_hoveredShapeHighlightRect.addPath(hoveredShape->absoluteTransformation().map(path));
1000 }
1001 } else {
1002 m_hoveredShapeHighlightRect.addRect(hoveredShape->boundingRect());
1003 }
1004 if (hoveredShape->writingMode() == KoSvgText::HorizontalTB) {
1006 } else {
1008 }
1009 } else if (hoveredFlowShape) {
1010 m_hoveredShapeHighlightRect.addPath(hoveredFlowShape->absoluteTransformation().map(hoveredFlowShape->outline()));
1011 if (hoveredFlowShape->segmentAtPoint(event->point, handleGrabRect(event->point)).isValid()) {
1013 } else {
1015 }
1016 } else if (!hoverPath.isEmpty() && shapeType == KoSvgTextShape_SHAPEID && m_highlightItem == HighlightItem::None) {
1017 m_hoveredShapeHighlightRect = hoverPath;
1018 if (isHorizontal) {
1020 } else {
1022 }
1023 }
1024 m_textOutlineHelper->setTextAreasHovered(textAreasHovered);
1026 event->ignore();
1027 }
1028
1030}
#define KoSvgTextShape_SHAPEID
static Qt::CursorShape lineToCursor(const QLineF line, const KoCanvasBase *const canvas)
virtual KoShapeManager * shapeManager() const =0
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
KoPathSegment segmentAtPoint(const QPointF &point, const QRectF &grabRoi) const
QPainterPath outline() const override
reimplemented
Qt::KeyboardModifiers modifiers() const
KoShape * shapeAt(const QPointF &position, KoFlake::ShapeSelection selection=KoFlake::ShapeOnTop, bool omitHiddenShapes=true)
QList< QPainterPath > textWrappingAreas() const
textWrappingAreas The text wrapping areas are computed from shapesInside() and shapesSubtract(),...
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
static std::optional< QPointF > hitTest(KoSvgTextShape *shape, const QPointF &mousePos, const qreal grabSensitivityInPts)
hitTest Tests whether the current mouse position is over a text wrapping area, and if so,...
bool hitTest(QPointF mouseInPts, const QTransform viewToDocument)
hitTest
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
void setTypeSettingHandleHovered(TypeSettingModeHandle hovered=TypeSettingModeHandle::NoHandle)
Set a given typesetting handle as hovered, so it will be drawn as such.
TypeSettingModeHandle
Handles used by type setting mode.
QCursor cursorTypeForTypeSetting() const
Return appropriate typeSetting cursor;.
TypeSettingModeHandle typeSettingHandleAtPos(const QRectF regionOfInterest)
Get typeSettingMode handle for text;.

References KoShape::absoluteTransformation(), KoSvgTextShape::boundingRect(), KoToolBase::canvas(), Create, KoToolBase::cursor(), SvgTextCursor::cursorTypeForTypeSetting(), SvgCreateTextStrategy::draggingInlineSize(), grabSensitivityInPt(), KoToolBase::handleGrabRect(), SvgCreateTextStrategy::hasWrappingShape(), SvgChangeTextPaddingMarginStrategy::hitTest(), SvgTextOnPathDecorationHelper::hitTest(), KoSvgText::HorizontalTB, InlineSizeEndHandle, InlineSizeStartHandle, InShapeOffset, 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, m_textCursor, m_textOnPathHelper, m_textOutlineHelper, KoPointerEvent::modifiers(), MoveBorder, SvgTextCursor::NoHandle, None, KoPathShape::outline(), KoSvgTextShape::outlineRect(), KoPointerEvent::point, KoToolBase::repaintDecorations(), KoPathShape::segmentAtPoint(), Select, selectedShape(), SvgTextCursor::setTypeSettingHandleHovered(), KoShapeManager::shapeAt(), KisToolUtils::shapeHoverInfoCrossLayer(), KoCanvasBase::shapeManager(), KoSvgTextShape::textWrappingAreas(), TypeSettingHandle, SvgTextCursor::typeSettingHandleAtPos(), SvgTextCursor::updateModifiers(), KoToolBase::useCursor(), KoSvgTextShape::writingMode(), and writingMode().

◆ mousePressEvent()

void SvgTextTool::mousePressEvent ( KoPointerEvent * event)
overridevirtual

reimplemented from KoToolBase

Implements KoToolBase.

Definition at line 776 of file SvgTextTool.cpp.

777{
778 // When using touch drawing, we only ever receive move events after the
779 // finger has pressed down. We have to issue an artificial move here so that
780 // the tool's state is updated properly to handle the press.
781 if (event->isTouchEvent()) {
782 mouseMoveEvent(event);
783 }
784
785 if (!nodeEditable()) {
786 event->accept();
787 return;
788 }
789
791
792 if (selectedShape) {
793 if (m_textOutlineHelper->contourModeButtonHovered(event->point)) {
794 m_textOutlineHelper->toggleTextContourMode(selectedShape);
795 event->accept();
796 KoToolManager::instance()->switchToolRequested("InteractionTool");
797 return;
798 }
799
802 if (handle != SvgTextCursor::NoHandle) {
807 }
808 event->accept();
809 return;
810 }
814 m_textOutlineHelper->setDrawTextWrappingArea(false);
815 event->accept();
816 return;
817 } else if (m_textOnPathHelper.hitTest(event->point, canvas()->viewConverter()->viewToDocument())) {
821 event->accept();
822 return;
826 event->accept();
827 return;
831 event->accept();
832 return;
836 event->accept();
837 return;
838 }
839 }
840
841 KoSvgTextShape *hoveredShape = dynamic_cast<KoSvgTextShape *>(canvas()->shapeManager()->shapeAt(event->point));
842 KoPathShape *hoveredFlowShape = dynamic_cast<KoPathShape *>(canvas()->shapeManager()->shapeAt(event->point));
843 QString shapeType;
844 QPainterPath hoverPath = KisToolUtils::shapeHoverInfoCrossLayer(canvas(), event->point, shapeType);
845 bool crossLayerPossible = !hoverPath.isEmpty() && shapeType == KoSvgTextShape_SHAPEID;
846
847 if (!selectedShape && !hoveredShape && !hoveredFlowShape && !crossLayerPossible) {
848 QPointF point = canvas()->snapGuide()->snap(event->point, event->modifiers());
849 m_interactionStrategy.reset(new SvgCreateTextStrategy(this, point));
851 event->accept();
852 } else if (hoveredShape) {
853 if (hoveredShape != selectedShape) {
855 canvas()->shapeManager()->selection()->select(hoveredShape);
856 m_hoveredShapeHighlightRect = QPainterPath();
857 }
858 m_interactionStrategy.reset(new SvgSelectTextStrategy(this, &m_textCursor, event->point, event->modifiers()));
860 event->accept();
861 } else if (hoveredFlowShape) {
862 QPointF point = canvas()->snapGuide()->snap(event->point, event->modifiers());
863 m_interactionStrategy.reset(new SvgCreateTextStrategy(this, point, hoveredFlowShape));
865 event->accept();
866 } else if (crossLayerPossible) {
868 m_interactionStrategy.reset(new SvgSelectTextStrategy(this, &m_textCursor, event->point, event->modifiers()));
870 m_hoveredShapeHighlightRect = QPainterPath();
871 } else {
873 }
874 event->accept();
875 } else { // if there's a selected shape but no hovered shape...
877 event->accept();
878 }
879
881}
bool isTouchEvent() const
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
void switchToolRequested(const QString &id)
static KoToolManager * instance()
Return the toolmanager singleton.
void mouseMoveEvent(KoPointerEvent *event) override
reimplemented from KoToolBase
bool nodeEditable()
nodeEditable
friend class SvgChangeTextPathInfoStrategy
Definition SvgTextTool.h:40
friend class SvgCreateTextStrategy
Definition SvgTextTool.h:39
The SvgTextTypeSettingStrategy class This class encompasses the typesetting mode.
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,...
bool setDominantBaselineFromHandle(const TypeSettingModeHandle handle)
setDominantBaselineFromHandle Set the dominant baseline from a given handle.
void setDrawTypeSettingHandle(bool draw)

References KoToolBase::canvas(), Create, KoSelection::deselectAll(), SvgTextCursor::getPos(), grabSensitivityInPt(), KoToolBase::handleGrabRect(), SvgChangeTextPaddingMarginStrategy::hitTest(), SvgTextOnPathDecorationHelper::hitTest(), InlineSizeEndHandle, InlineSizeHandle, InlineSizeStartHandle, InShapeOffset, KoToolManager::instance(), KoPointerEvent::isTouchEvent(), KoSvgTextShape_SHAPEID, m_dragging, m_highlightItem, m_hoveredShapeHighlightRect, m_interactionStrategy, m_textCursor, m_textOnPathHelper, m_textOutlineHelper, KoPointerEvent::modifiers(), mouseMoveEvent(), Move, MoveBorder, nodeEditable(), SvgTextCursor::NoHandle, KoPointerEvent::point, KoToolBase::repaintDecorations(), KoSelection::select(), Select, selectedShape(), KoShapeManager::selection, KisToolUtils::selectShapeCrossLayer(), SvgTextCursor::setDominantBaselineFromHandle(), SvgTextCursor::setDrawTypeSettingHandle(), SvgTextOnPathDecorationHelper::setStrategyActive(), KoShapeManager::shapeAt(), KisToolUtils::shapeHoverInfoCrossLayer(), KoCanvasBase::shapeManager(), KoSnapGuide::snap(), KoCanvasBase::snapGuide, SvgChangeTextPathInfoStrategy, SvgCreateTextStrategy, KoToolManager::switchToolRequested(), TextPathHandle, TypeSetting, TypeSettingHandle, and SvgTextCursor::typeSettingHandleAtPos().

◆ mouseReleaseEvent()

void SvgTextTool::mouseReleaseEvent ( KoPointerEvent * event)
overridevirtual

reimplemented from KoToolBase

Implements KoToolBase.

Definition at line 1032 of file SvgTextTool.cpp.

1033{
1035 m_interactionStrategy->finishInteraction(event->modifiers());
1036 KUndo2Command *const command = m_interactionStrategy->createCommand();
1037 if (command) {
1039 canvas()->addCommand(command);
1041 }
1042 m_interactionStrategy = nullptr;
1045 }
1047 m_textOutlineHelper->setDrawTextWrappingArea(true);
1050 event->accept();
1051 } else {
1053 }
1054 event->accept();
1055}
virtual void addCommand(KUndo2Command *command)=0
bool m_strategyAddingCommand

References KoCanvasBase::addCommand(), KoToolBase::canvas(), m_base_cursor, m_dragging, m_interactionStrategy, m_strategyAddingCommand, m_textCursor, m_textOnPathHelper, m_textOutlineHelper, KoPointerEvent::modifiers(), None, Select, SvgTextCursor::setDrawTypeSettingHandle(), SvgTextOnPathDecorationHelper::setStrategyActive(), and KoToolBase::useCursor().

◆ mouseTripleClickEvent()

void SvgTextTool::mouseTripleClickEvent ( KoPointerEvent * event)
overridevirtual

reimplemented from KoToolBase

Reimplemented from KoToolBase.

Definition at line 1114 of file SvgTextTool.cpp.

1115{
1116 if (canvas()->shapeManager()->shapeAt(event->point) == selectedShape()) {
1117 // TODO: Consider whether we want to use sentence based selection instead:
1118 // QTextBoundaryFinder allows us to find sentences if necessary.
1121 event->accept();
1122 }
1123}

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

◆ nodeEditable()

bool SvgTextTool::nodeEditable ( )
private

nodeEditable

See also
nodeEditable in KisTool.
Returns
whether the current Node is editable. If not, it'll display an oncanvas message.

Definition at line 638 of file SvgTextTool.cpp.

639{
641 if (!node->isEditable(true)) {
642 KisCanvas2 * kiscanvas = static_cast<KisCanvas2*>(canvas());
643 if (kiscanvas) {
644 QString message = KisToolUtils::nodeEditableMessage(node);
645 kiscanvas->viewManager()->showFloatingMessage(message, KisIconUtils::loadIcon("object-locked"));
646 }
647 return false;
648 }
649 return true;
650}
void showFloatingMessage(const QString &message, const QIcon &icon, int timeout=4500, KisFloatingMessage::Priority priority=KisFloatingMessage::Medium, int alignment=Qt::AlignCenter|Qt::TextWordWrap)
shows a floating message in the top right corner of the canvas
QPointer< KoCanvasResourceProvider > resourceManager
QIcon loadIcon(const QString &name)
QString nodeEditableMessage(KisNodeSP node, bool blockedNoIndirectPainting)
nodeEditableMessage
bool isEditable(bool checkVisibility=true) const

References KoToolBase::canvas(), KoCanvasResource::CurrentKritaNode, KisBaseNode::isEditable(), KisIconUtils::loadIcon(), KisToolUtils::nodeEditableMessage(), KoCanvasBase::resourceManager, KisViewManager::showFloatingMessage(), and KisCanvas2::viewManager().

◆ paint()

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

reimplemented from KoToolBase

Implements KoToolBase.

Definition at line 682 of file SvgTextTool.cpp.

683{
684 if (!isActivated()) return;
685
687 m_interactionStrategy->paint(gc, converter);
688 }
689
690 KoSvgTextShape *shape = selectedShape();
691 if (shape) {
692 KisHandlePainterHelper handlePainter =
694
697 QPainterPath path;
698 path.addRect(shape->outlineRect());
699 handlePainter.drawPath(path);
700 }
701
702 qreal pxlToPt = canvas()->viewConverter()->viewToDocumentX(1.0);
704 if (std::optional<InlineSizeInfo> info = InlineSizeInfo::fromShape(shape, length * pxlToPt)) {
706 handlePainter.drawConnectionLine(info->baselineLineLocal());
707
711 }
713 handlePainter.drawHandleLine(info->startLineLocal());
714 handlePainter.drawHandleLine(info->startLineDashes(), INLINE_SIZE_HANDLE_THICKNESS, dashPattern, INLINE_SIZE_DASHES_PATTERN_A);
715
720 }
721 handlePainter.drawHandleLine(info->endLineLocal());
722 handlePainter.drawHandleLine(info->endLineDashes(), INLINE_SIZE_HANDLE_THICKNESS, dashPattern, INLINE_SIZE_DASHES_PATTERN_A);
723 }
724
727 } else {
729 }
730 handlePainter.drawHandleCircle(QPointF(), KoToolBase::handleRadius() * 0.75);
731 }
732
733 m_textOutlineHelper->setDecorationThickness(decorationThickness());
734 m_textOutlineHelper->setHandleRadius(handleRadius());
735 m_textOutlineHelper->paint(&gc, converter);
738 m_textOnPathHelper.paint(&gc, converter);
739 gc.setTransform(converter.documentToView(), true);
740 {
742 if (!m_hoveredShapeHighlightRect.isEmpty()) {
744 QPainterPath path;
745 path.addPath(m_hoveredShapeHighlightRect);
746 handlePainter.drawPath(path);
747 }
748 }
749 if (shape) {
750 m_textCursor.paintDecorations(gc, qApp->palette().color(QPalette::Highlight), decorationThickness(), handleRadius());
751 }
753 gc.save();
754 canvas()->snapGuide()->paint(gc, converter);
755 gc.restore();
756 }
757
758 // Paint debug outline
759 if (debugEnabled() && shape) {
760 gc.save();
761 using Element = KoSvgTextShape::DebugElement;
762 KoSvgTextShape::DebugElements el{};
763 if (m_optionManager->showCharacterDebug()) {
764 el |= Element::CharBbox;
765 }
766 if (m_optionManager->showLineDebug()) {
767 el |= Element::LineBox;
768 }
769
770 gc.setTransform(shape->absoluteTransformation(), true);
771 shape->paintDebug(gc, el);
772 gc.restore();
773 }
774}
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:977
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 paint(QPainter *painter, const KoViewConverter &converter)
paint Paint the handles for the text path.
void paintDecorations(QPainter &gc, QColor selectionColor, int decorationThickness=1, qreal handleRadius=5.0)
Paint all decorations and blinkingcursors.

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, InShapeOffset, KoToolBase::isActivated(), length(), m_dragging, m_highlightItem, m_hoveredShapeHighlightRect, m_interactionStrategy, m_optionManager, m_textCursor, m_textOnPathHelper, m_textOutlineHelper, Move, MoveBorder, KoSvgTextShape::outlineRect(), KoSnapGuide::paint(), SvgTextOnPathDecorationHelper::paint(), KoSvgTextShape::paintDebug(), SvgTextCursor::paintDecorations(), KisHandleStyle::partiallyHighlightedPrimaryHandles(), KisHandleStyle::primarySelection(), KisHandleStyle::secondarySelection(), selectedShape(), SvgTextOnPathDecorationHelper::setDecorationThickness(), SvgTextOnPathDecorationHelper::setHandleRadius(), KisHandlePainterHelper::setHandleStyle(), KoCanvasBase::snapGuide, TypeSetting, KoCanvasBase::viewConverter(), and KoViewConverter::viewToDocumentX().

◆ paste()

bool SvgTextTool::paste ( )
overridevirtual

reimplemented from superclass

Reimplemented from KoToolBase.

Definition at line 483 of file SvgTextTool.cpp.

484{
485 return m_textCursor.paste();
486}
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 219 of file SvgTextTool.cpp.

220{
221 return nullptr;
222}

◆ propertiesForNewText

KoSvgTextProperties SvgTextTool::propertiesForNewText ( ) const
privateslot

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

Definition at line 399 of file SvgTextTool.cpp.

400{
401 const bool useCurrent = m_optionManager->optionsModel()->useCurrentTextProperties();
402 const QString presetName = m_optionManager->optionsModel()->cssStylePresetName();
403
405 if (useCurrent || presetName.isEmpty()) {
407 props = textData.commonProperties;
408 } else {
410 QVector<KoResourceSP> res = model->resourcesForName(presetName);
411 if (res.first()) {
412 KoCssStylePresetSP style = res.first().staticCast<KoCssStylePreset>();
413 qreal dpi = 72;
414 KisCanvas2 *canvas2 = qobject_cast<KisCanvas2 *>(this->canvas());
415 if (canvas2) {
416 dpi = canvas2->image()->xRes() * 72.0;
417 }
418 if (style) {
419 props = style->properties(dpi, true);
420 }
421 }
422 }
423
424 QColor fontColor = (canvas()->resourceManager()->isUsingOtherColor()
425 ? canvas()->resourceManager()->backgroundColor()
426 : canvas()->resourceManager()->foregroundColor()).toQColor();
428 bg->setColor(fontColor);
430 props.setProperty(KoSvgTextProperties::FillId, QVariant::fromValue(bgProp));
431 return props;
432}
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)
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 524 of file SvgTextTool.cpp.

525{
531}

◆ 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 510 of file SvgTextTool.cpp.

511{
512 if (!isActivated()) return;
516 m_interactionStrategy->cancelInteraction();
517 m_interactionStrategy = nullptr;
518 useCursor(Qt::ArrowCursor);
520 }
521 }
522}

References KoToolBase::isActivated(), SvgTextCursor::isAddingCommand, m_dragging, m_interactionStrategy, m_strategyAddingCommand, m_textCursor, m_textOnPathHelper, None, SvgTextOnPathDecorationHelper::setStrategyActive(), 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 493 of file SvgTextTool.cpp.

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

◆ selectedShape()

KoSvgTextShape * SvgTextTool::selectedShape ( ) const
protected

Definition at line 293 of file SvgTextTool.cpp.

294{
296 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(canvas()->selectedShapesProxy(), 0);
297
299 if (shapes.isEmpty()) return 0;
300
301 KoSvgTextShape *textShape = dynamic_cast<KoSvgTextShape*>(shapes.first());
302
303 return textShape;
304}
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 505 of file SvgTextTool.cpp.

506{
507 return &m_textCursor;
508}

References m_textCursor.

◆ showEditor

void SvgTextTool::showEditor ( )
privateslot

Definition at line 306 of file SvgTextTool.cpp.

307{
308 KoSvgTextShape *shape = selectedShape();
309 if (!shape) return;
310
311 if (!m_editor) {
312 m_editor = new SvgTextEditor(QApplication::activeWindow());
313 m_editor->setWindowTitle(i18nc("@title:window", "Krita - Edit Text"));
314 m_editor->setWindowModality(Qt::ApplicationModal);
315 m_editor->setAttribute( Qt::WA_QuitOnClose, false );
316
317 connect(m_editor, SIGNAL(textUpdated(KoSvgTextShape*,QString,QString)), SLOT(textUpdated(KoSvgTextShape*,QString,QString)));
318
319 m_editor->activateWindow(); // raise on creation only
320 }
321 if (!m_editor->isVisible()) {
322 m_editor->setInitialShape(shape);
323#ifdef Q_OS_ANDROID
324 // for window manager
325 m_editor->setWindowFlags(Qt::Dialog);
326 m_editor->menuBar()->setNativeMenuBar(false);
327#endif
328 m_editor->show();
329 }
330}
void textUpdated(KoSvgTextShape *shape, const QString &svg, const QString &defs)

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

◆ showGlyphPalette

void SvgTextTool::showGlyphPalette ( )
privateslot

showGlyphPalette Shows the glyph palette dialog.

Definition at line 338 of file SvgTextTool.cpp.

339{
340 if (!m_glyphPalette) {
341 m_glyphPalette = new GlyphPaletteDialog(QApplication::activeWindow());
342 m_glyphPalette->setAttribute( Qt::WA_QuitOnClose, false );
343
344 connect(&m_textCursor, SIGNAL(selectionChanged()), this, SLOT(updateGlyphPalette()));
345 connect(m_glyphPalette, SIGNAL(signalInsertRichText(KoSvgTextShape*, bool)), this, SLOT(insertRichText(KoSvgTextShape*, bool)));
346
347 m_glyphPalette->activateWindow();
348 }
349 if (!m_glyphPalette->isVisible()) {
350 m_glyphPalette->show();
352 }
353}
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 insertRichText(), m_glyphPalette, m_textCursor, KoToolBase::selectionChanged(), and updateGlyphPalette().

◆ slotConvertType

void SvgTextTool::slotConvertType ( int index)
privateslot

slotConvertType

Parameters
index

Definition at line 540 of file SvgTextTool.cpp.

540 {
541 KoSvgTextShape *shape = selectedShape();
542 if (shape) {
543 if (index == shape->textType()) return;
545 KUndo2Command *parentCommand = new KUndo2Command();
548 KoSvgConvertTextTypeCommand *cmd = new KoSvgConvertTextTypeCommand(shape, type, m_textCursor.getPos(), parentCommand);
549 parentCommand->setText(cmd->text());
553 canvas()->addCommand(parentCommand);
555 }
556}
void setText(const KUndo2MagicString &text)
The SvgConvertTextTypeCommand class This command allows textshapes to be converted between preformatt...
static void removeContourShapesFromFlow(KoSvgTextShape *textShape, KUndo2Command *parent, bool textInShape, bool textPaths)
removeContourShapesFromFlow Create a command to remove all contour shapes of a certain type from the ...
@ TextInShape
Uses shape-inside to wrap and preserves spaces.
TextType textType() const
textType This enum gives an indication of what kind of text this shape is. The different text types a...

References KoCanvasBase::addCommand(), KoToolBase::canvas(), KisCommandUtils::FlipFlopCommand::FINALIZING, SvgTextCursor::getPos(), KisCommandUtils::FlipFlopCommand::INITIALIZING, KoSvgTextShape::InlineWrap, m_textCursor, KoSvgTextRemoveShapeCommand::removeContourShapesFromFlow(), selectedShape(), KoCanvasBase::selectedShapesProxy(), KUndo2Command::setText(), slotTextTypeUpdated(), KoSvgTextShape::TextInShape, and KoSvgTextShape::textType().

◆ slotMoveTextSelection

void SvgTextTool::slotMoveTextSelection ( int index)
privateslot

slotMoveTextSelection Move the start of the selection in typesetting mode by image 1 pix.

Parameters
index– Qt key for a direction.

Definition at line 603 of file SvgTextTool.cpp.

604{
605 KoSvgTextShape *shape = selectedShape();
606 if (!shape) return;
607 QPointF offset;
608 // test type setting mode.
609 if (index == Qt::Key_Down) {
610 offset = QPointF(0, 1);
611 } else if (index == Qt::Key_Up) {
612 offset = QPointF(0, -1);
613 } else if (index == Qt::Key_Right) {
614 offset = QPointF(-1, 0);
615 } else if (index == Qt::Key_Left) {
616 offset = QPointF(1, 0);
617 } else {
618 return;
619 }
620 const KisCanvas2 *canvas2 = qobject_cast<const KisCanvas2 *>(this->canvas());
621 if (canvas2) {
622 offset = canvas2->coordinatesConverter()->imageToDocumentTransform().map(offset);
623 }
624 KUndo2Command *parentCommand = new KUndo2Command();
628 parentCommand->setText(cmd->text());
629 canvas()->addCommand(parentCommand);
630}
KisCoordinatesConverter * coordinatesConverter
int getAnchor()
Get the current selection anchor. This is the same as position, unless there's a selection.

References KoCanvasBase::addCommand(), KoToolBase::canvas(), KisCanvas2::coordinatesConverter, KisCommandUtils::FlipFlopCommand::FINALIZING, SvgTextCursor::getAnchor(), SvgTextCursor::getPos(), KisCoordinatesConverter::imageToDocumentTransform(), KisCommandUtils::FlipFlopCommand::INITIALIZING, m_textCursor, SvgTextChangeTransformsOnRange::OffsetAll, selectedShape(), KoCanvasBase::selectedShapesProxy(), and KUndo2Command::setText().

◆ slotShapeSelectionChanged

void SvgTextTool::slotShapeSelectionChanged ( )
privateslot

selectionChanged called when the canvas selection is changed.

Definition at line 434 of file SvgTextTool.cpp.

435{
437 if (shapes.size() == 1) {
438 KoSvgTextShape *textShape = selectedShape();
439 if (!textShape) {
441 return;
442 }
443 } else if (shapes.size() > 1) {
444 KoSvgTextShape *foundTextShape = nullptr;
445
446 Q_FOREACH (KoShape *shape, shapes) {
447 KoSvgTextShape *textShape = dynamic_cast<KoSvgTextShape*>(shape);
448 if (textShape) {
449 foundTextShape = textShape;
450 break;
451 }
452 }
453
455 if (foundTextShape) {
456 koSelection()->select(foundTextShape);
457 }
458 return;
459 }
460 KoSvgTextShape *const shape = selectedShape();
461 if (shape != m_textCursor.shape()) {
462 m_textCursor.setShape(shape);
464 if (shape) {
465 setTextMode(true);
466 } else {
467 setTextMode(false);
468 }
469 }
471}
void setTextMode(bool value)
void setShape(KoSvgTextShape *shape)
setShape Set the shape for which to draw the text path.
KoSvgTextShape * shape

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

◆ slotTextTypeUpdated

void SvgTextTool::slotTextTypeUpdated ( )
privateslot

slotTextTypeUpdated Update the text type in the tool options.

Definition at line 568 of file SvgTextTool.cpp.

569{
570 KoSvgTextShape *shape = selectedShape();
571 QActionGroup *typeConvertGroup = action("text_type_preformatted")->actionGroup();
572 if (typeConvertGroup) {
573 typeConvertGroup->setExclusive(true);
574 Q_FOREACH (QAction *a, typeConvertGroup->actions()) {
575 a->setCheckable(true);
576 }
577 }
578 if (m_optionManager) {
579 if (shape) {
580 m_optionManager->convertToTextType(int(shape->textType()));
581 if (typeConvertGroup) {
582 typeConvertGroup->setEnabled(true);
583 }
584 action("text_type_preformatted")->setChecked(shape->textType() == KoSvgTextShape::PreformattedText);
585 action("text_type_pre_positioned")->setChecked(shape->textType() == KoSvgTextShape::PrePositionedText);
586 action("text_type_inline_wrap")->setChecked(shape->textType() == KoSvgTextShape::InlineWrap);
587
588 } else {
589 m_optionManager->convertToTextType(-1);
590 if (typeConvertGroup) {
591 typeConvertGroup->setEnabled(false);
592 }
593 }
594 const bool enableTypeSetting = (m_optionManager->typeSettingMode() && shape && (shape->textType() == KoSvgTextShape::PreformattedText ||shape->textType() == KoSvgTextShape::PrePositionedText));
595 QActionGroup *svgTypeSettingGroup = action("svg_type_setting_move_selection_start_down_1_px")->actionGroup();
596 if (svgTypeSettingGroup) {
597 svgTypeSettingGroup->setEnabled(enableTypeSetting);
598 }
600 }
601}
void updateTypeSettingDecorFromShape()
Update the type setting decorations.

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

◆ 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 533 of file SvgTextTool.cpp.

534{
535 if (canvas()) {
536 canvas()->updateCanvas(updateRect);
537 }
538}

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

◆ slotUpdateTextPasteBehaviour

void SvgTextTool::slotUpdateTextPasteBehaviour ( )
privateslot

slotUpdateTextPasteBehaviour update the default text paste behaviour.

Definition at line 563 of file SvgTextTool.cpp.

564{
565 m_textCursor.setPasteRichTextByDefault(m_optionManager->optionsModel()->pasteRichtTextByDefault());
566}
void setPasteRichTextByDefault(const bool pasteRichText=true)
setPasteRichText

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

◆ slotUpdateTypeSettingMode

void SvgTextTool::slotUpdateTypeSettingMode ( )
privateslot

slotUpdateTypeSettingMode Enable typesetting mode from the tool options.

Definition at line 632 of file SvgTextTool.cpp.

633{
636}
void setTypeSettingModeActive(bool activate)
Set type setting mode active.

References m_optionManager, m_textCursor, SvgTextCursor::setTypeSettingModeActive(), and slotTextTypeUpdated().

◆ slotUpdateVisualCursor

void SvgTextTool::slotUpdateVisualCursor ( )
privateslot

slotUpdateVisualCursor update the visual cursor mode on the text cursor.

Definition at line 558 of file SvgTextTool.cpp.

559{
560 m_textCursor.setVisualMode(m_optionManager->optionsModel()->useVisualBidiCursor());
561}
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 332 of file SvgTextTool.cpp.

333{
334 SvgTextChangeCommand *cmd = new SvgTextChangeCommand(shape, svg, defs);
335 canvas()->addCommand(cmd);
336}

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

◆ updateGlyphPalette

void SvgTextTool::updateGlyphPalette ( )
privateslot

updateGlyphPalette update the glyph palette dialog from the current selection.

Definition at line 355 of file SvgTextTool.cpp.

356{
357 if (m_glyphPalette && m_glyphPalette->isVisible()) {
358 QString grapheme = QString();
359 if (m_textCursor.shape()) {
360 int pos = m_textCursor.getPos();
361 int pos2 = pos > 0? m_textCursor.shape()->posLeft(pos, false): m_textCursor.shape()->posRight(pos, false);
362 int start = m_textCursor.shape()->indexForPos(qMin(pos, pos2));
363 int end = m_textCursor.shape()->indexForPos(qMax(pos, pos2));
364 grapheme = m_textCursor.shape()->plainText().mid(start, end-start);
365 }
366 m_glyphPalette->setGlyphModelFromProperties(m_textCursor.currentTextProperties(), grapheme);
367 }
368}
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.

◆ updateTextPathHelper

void SvgTextTool::updateTextPathHelper ( )
privateslot

Definition at line 370 of file SvgTextTool.cpp.

371{
373}
void setPos(int pos)
setPos the the position of the cursor, where the text path is sought. A single text shape can have mu...

References SvgTextCursor::getPos(), m_textCursor, m_textOnPathHelper, and SvgTextOnPathDecorationHelper::setPos().

◆ writingMode()

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

Definition at line 1131 of file SvgTextTool.cpp.

1132{
1135}
@ 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

◆ SvgChangeTextPathInfoStrategy

friend class SvgChangeTextPathInfoStrategy
friend

Definition at line 40 of file SvgTextTool.h.

◆ SvgCreateTextStrategy

friend class SvgCreateTextStrategy
friend

Definition at line 39 of file SvgTextTool.h.

Member Data Documentation

◆ m_base_cursor

QCursor SvgTextTool::m_base_cursor
private

Definition at line 242 of file SvgTextTool.h.

◆ m_canvasConnections

KisSignalAutoConnectionsStore SvgTextTool::m_canvasConnections
private

Definition at line 238 of file SvgTextTool.h.

◆ m_dragging

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

Definition at line 226 of file SvgTextTool.h.

◆ m_editor

QPointer<SvgTextEditor> SvgTextTool::m_editor
private

Definition at line 223 of file SvgTextTool.h.

◆ m_glyphPalette

QPointer<GlyphPaletteDialog> SvgTextTool::m_glyphPalette
private

Definition at line 224 of file SvgTextTool.h.

◆ m_highlightItem

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

Definition at line 228 of file SvgTextTool.h.

◆ m_hoveredShapeHighlightRect

QPainterPath SvgTextTool::m_hoveredShapeHighlightRect
private

Definition at line 240 of file SvgTextTool.h.

◆ m_ibeam_horizontal

QCursor SvgTextTool::m_ibeam_horizontal
private

Definition at line 248 of file SvgTextTool.h.

◆ m_ibeam_horizontal_done

QCursor SvgTextTool::m_ibeam_horizontal_done
private

Definition at line 249 of file SvgTextTool.h.

◆ m_ibeam_vertical

QCursor SvgTextTool::m_ibeam_vertical
private

Definition at line 247 of file SvgTextTool.h.

◆ m_interactionStrategy

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

Definition at line 227 of file SvgTextTool.h.

◆ m_lastMousePos

QPointF SvgTextTool::m_lastMousePos
private

Definition at line 225 of file SvgTextTool.h.

◆ m_optionManager

QScopedPointer<SvgTextToolOptionsManager> SvgTextTool::m_optionManager
private

Definition at line 222 of file SvgTextTool.h.

◆ m_strategyAddingCommand

bool SvgTextTool::m_strategyAddingCommand {false}
private

Definition at line 229 of file SvgTextTool.h.

229{false};

◆ m_text_in_shape

QCursor SvgTextTool::m_text_in_shape
private

Definition at line 246 of file SvgTextTool.h.

◆ m_text_inline_horizontal

QCursor SvgTextTool::m_text_inline_horizontal
private

Definition at line 243 of file SvgTextTool.h.

◆ m_text_inline_vertical

QCursor SvgTextTool::m_text_inline_vertical
private

Definition at line 244 of file SvgTextTool.h.

◆ m_text_on_path

QCursor SvgTextTool::m_text_on_path
private

Definition at line 245 of file SvgTextTool.h.

◆ m_textCursor

SvgTextCursor SvgTextTool::m_textCursor
private

Definition at line 235 of file SvgTextTool.h.

◆ m_textOnPathHelper

SvgTextOnPathDecorationHelper SvgTextTool::m_textOnPathHelper
private

Definition at line 236 of file SvgTextTool.h.

◆ m_textOutlineHelper

QScopedPointer<KoSvgTextShapeOutlineHelper> SvgTextTool::m_textOutlineHelper
private

Definition at line 237 of file SvgTextTool.h.

◆ m_textTypeSignalsMapper

QScopedPointer<KisSignalMapper> SvgTextTool::m_textTypeSignalsMapper
private

Definition at line 231 of file SvgTextTool.h.

◆ m_typeSettingMovementMapper

QScopedPointer<KisSignalMapper> SvgTextTool::m_typeSettingMovementMapper
private

Definition at line 232 of file SvgTextTool.h.


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