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

#include <SvgChangeTextPathInfoStrategy.h>

+ Inheritance diagram for SvgChangeTextPathInfoStrategy:

Public Member Functions

void cancelInteraction () override
 
KUndo2CommandcreateCommand () override
 
void finishInteraction (Qt::KeyboardModifiers modifiers) override
 
void handleMouseMove (const QPointF &mouseLocation, Qt::KeyboardModifiers modifiers) override
 
 SvgChangeTextPathInfoStrategy (SvgTextTool *tool, KoSvgTextShape *shape, const QPointF &clicked, int textCursorPos)
 
 ~SvgChangeTextPathInfoStrategy () override=default
 
- Public Member Functions inherited from KoInteractionStrategy
 KoInteractionStrategy (KoToolBase *parent)
 constructor
 
virtual void paint (QPainter &painter, const KoViewConverter &converter)
 
KoToolBasetool () const
 
virtual ~KoInteractionStrategy ()
 Destructor.
 

Private Attributes

QPointF m_currentMousePos
 
KoSvgText::TextOnPathInfo m_oldInfo
 
KoSvgTextShapem_shape
 
int m_textCursorPos
 

Additional Inherited Members

- Protected Member Functions inherited from KoInteractionStrategy
uint decorationThickness () const
 
uint grabSensitivity () const
 Convenience function to get the global grab sensitivity.
 
uint handleRadius () const
 Convenience function to get the global handle radius.
 
 KoInteractionStrategy (KoInteractionStrategyPrivate &)
 constructor
 
- Protected Attributes inherited from KoInteractionStrategy
KoInteractionStrategyPrivated_ptr
 

Detailed Description

Definition at line 17 of file SvgChangeTextPathInfoStrategy.h.

Constructor & Destructor Documentation

◆ SvgChangeTextPathInfoStrategy()

SvgChangeTextPathInfoStrategy::SvgChangeTextPathInfoStrategy ( SvgTextTool * tool,
KoSvgTextShape * shape,
const QPointF & clicked,
int textCursorPos )

Definition at line 16 of file SvgChangeTextPathInfoStrategy.cpp.

18 , m_shape(shape)
19 , m_currentMousePos(clicked)
20 , m_textCursorPos(textCursorPos)
21{
23 m_oldInfo = *(index.textPathInfo());
24
25}
KoInteractionStrategy(KoToolBase *parent)
constructor
The KoSvgTextNodeIndex class.
KoSvgText::TextOnPathInfo * textPathInfo()
textPathInfo the text path info for this node as a pointer.
KoSvgTextNodeIndex topLevelNodeForPos(int pos) const
topLevelNodeForPos Get, if possible, an index for the child element of the root at pos....

References m_oldInfo, m_shape, m_textCursorPos, KoSvgTextNodeIndex::textPathInfo(), and KoSvgTextShape::topLevelNodeForPos().

◆ ~SvgChangeTextPathInfoStrategy()

SvgChangeTextPathInfoStrategy::~SvgChangeTextPathInfoStrategy ( )
overridedefault

Member Function Documentation

◆ cancelInteraction()

void SvgChangeTextPathInfoStrategy::cancelInteraction ( )
overridevirtual

This method will undo frames based interactions by calling createCommand() and unexecuting that.

Reimplemented from KoInteractionStrategy.

Definition at line 92 of file SvgChangeTextPathInfoStrategy.cpp.

References m_oldInfo, m_shape, m_textCursorPos, KoToolBase::repaintDecorations(), KoInteractionStrategy::tool(), and KUndo2Command::undo().

◆ createCommand()

KUndo2Command * SvgChangeTextPathInfoStrategy::createCommand ( )
overridevirtual

For interactions that are undo-able this method should be implemented to return such a command. Implementations should return 0 otherwise.

Returns
a command, or 0.

Implements KoInteractionStrategy.

Definition at line 40 of file SvgChangeTextPathInfoStrategy.cpp.

41{
42 SvgTextTool *const tool = qobject_cast<SvgTextTool *>(this->tool());
44 KoShape *shape = index.textPath();
45 if (!shape) {
46 return nullptr;
47 }
48
49 KoPathShape *path = dynamic_cast<KoPathShape*>(shape);
51
52 const qreal grab = tool->grabSensitivityInPt()*4;
53 QRectF roi = QRect(0, 0, grab, grab);
54 roi.moveCenter(m_currentMousePos);
55 KoPathSegment segment = path->segmentAtPoint(m_currentMousePos, roi);
56
57 if (!segment.isValid()) {
58 return nullptr;
59 }
60
61 QList<KoPathSegment> segments = path->segmentsAt(path->outlineRect().adjusted(-grab, -grab, grab, grab));
62
63 double length = 0;
64 Q_FOREACH(KoPathSegment s, segments) {
65 if (s == segment) {
66 const QPointF mouseInShape = path->documentToShape(m_currentMousePos);
67 const qreal t = segment.nearestPoint(mouseInShape);
68 info.startOffset = length + (t * segment.length());
69
70 const QLineF l = QLineF(segment.pointAt(t), mouseInShape).unitVector();
71 const QVector2D p1(l.p2()-l.p1());
72 const QVector2D tangent = QVector2D(segment.angleVectorAtParam(t));
73 const QVector2D normal(-tangent.y(), tangent.x());
74 float dot = QVector2D::dotProduct(p1, normal);
75 if (dot <= 0) {
77 } else {
79 }
80 }
81 length += s.length();
82 }
84 info.startOffset = length - info.startOffset;
85 }
86
88 cmd->setText(kundo2_i18n("Change Text On Path Position"));
89 return cmd;
90}
qreal length(const QPointF &vec)
Definition Ellipse.cc:82
QPointF p1
void setText(const KUndo2MagicString &text)
A KoPathSegment consist of two neighboring KoPathPoints.
qreal length(qreal error=0.005) const
QPointF pointAt(qreal t) const
Returns point at given t.
QPointF angleVectorAtParam(qreal t)
angleVectorAtParam Calculates the angle vector at t.
qreal nearestPoint(const QPointF &point) const
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
KoShape * textPath()
textPath
KUndo2MagicString kundo2_i18n(const char *text)
@ TextPathSideRight
Definition KoSvgText.h:301
@ TextPathSideLeft
Definition KoSvgText.h:302

References KoPathSegment::angleVectorAtParam(), KoPathSegment::isValid(), kundo2_i18n(), length(), KoPathSegment::length(), m_currentMousePos, m_shape, m_textCursorPos, KoPathSegment::nearestPoint(), p1, KoPathSegment::pointAt(), KUndo2Command::setText(), KoSvgText::TextOnPathInfo::side, KoSvgText::TextOnPathInfo::startOffset, KoSvgTextNodeIndex::textPath(), KoSvgText::TextPathSideLeft, KoSvgText::TextPathSideRight, KoInteractionStrategy::tool(), and KoSvgTextShape::topLevelNodeForPos().

◆ finishInteraction()

void SvgChangeTextPathInfoStrategy::finishInteraction ( Qt::KeyboardModifiers modifiers)
overridevirtual

Override to make final changes to the data on the end of an interaction.

Implements KoInteractionStrategy.

Definition at line 101 of file SvgChangeTextPathInfoStrategy.cpp.

102{
103
104}

◆ handleMouseMove()

void SvgChangeTextPathInfoStrategy::handleMouseMove ( const QPointF & mouseLocation,
Qt::KeyboardModifiers modifiers )
overridevirtual

Extending classes should implement this method to update the selectedShapes based on the new mouse position.

Parameters
mouseLocationthe new location in pt
modifiersOR-ed set of keys pressed.

Implements KoInteractionStrategy.

Definition at line 27 of file SvgChangeTextPathInfoStrategy.cpp.

28{
29 Q_UNUSED(modifiers)
30
31 m_currentMousePos = mouseLocation;
32
34 if (cmd) {
35 cmd->redo();
36 }
38}
virtual void redo()

References createCommand(), m_currentMousePos, KUndo2Command::redo(), KoToolBase::repaintDecorations(), and KoInteractionStrategy::tool().

Member Data Documentation

◆ m_currentMousePos

QPointF SvgChangeTextPathInfoStrategy::m_currentMousePos
private

Definition at line 29 of file SvgChangeTextPathInfoStrategy.h.

◆ m_oldInfo

KoSvgText::TextOnPathInfo SvgChangeTextPathInfoStrategy::m_oldInfo
private

Definition at line 31 of file SvgChangeTextPathInfoStrategy.h.

◆ m_shape

KoSvgTextShape* SvgChangeTextPathInfoStrategy::m_shape
private

Definition at line 28 of file SvgChangeTextPathInfoStrategy.h.

◆ m_textCursorPos

int SvgChangeTextPathInfoStrategy::m_textCursorPos
private

Definition at line 30 of file SvgChangeTextPathInfoStrategy.h.


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