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

#include <SvgChangeTextPaddingMarginStrategy.h>

+ Inheritance diagram for SvgChangeTextPaddingMarginStrategy:

Public Member Functions

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

Static Public Member Functions

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, will return the angle vector at that point.
 

Private Attributes

bool m_isPadding
 
QPointF m_lastMousePos
 
KoPathShapem_referenceShape
 
KoSvgTextShapem_shape
 

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 SvgChangeTextPaddingMarginStrategy.h.

Constructor & Destructor Documentation

◆ SvgChangeTextPaddingMarginStrategy()

SvgChangeTextPaddingMarginStrategy::SvgChangeTextPaddingMarginStrategy ( SvgTextTool * tool,
KoSvgTextShape * shape,
const QPointF & clicked )

Definition at line 19 of file SvgChangeTextPaddingMarginStrategy.cpp.

21 , m_shape(shape)
22 , m_lastMousePos(clicked)
23{
26
29
30 const QPointF padding(shapePadding+2, shapePadding+2);
31 const QPointF margin(shapeMargin+2, shapeMargin+2);
32
33 qreal minDistance = std::numeric_limits<qreal>::max();
34 KoPathShape *candidate = nullptr;
35 bool isPadding = false;
36 Q_FOREACH(KoShape *shape, m_shape->shapesSubtract()) {
37 KoPathShape *path = dynamic_cast<KoPathShape*>(shape);
38 if (!path) continue;
39 const QPointF mp = shape->documentToShape(clicked);
40 const QRectF marginRect(mp - margin, mp + margin);
41
42 Q_FOREACH(KoPathSegment segment, path->segmentsAt(marginRect)) {
43 const qreal nearestT = segment.nearestPoint(mp);
44 const QPointF nearestP = segment.pointAt(nearestT);
45 const qreal distance = kisDistance(mp, nearestP) - shapeMargin;
46 if (distance < minDistance) {
47 candidate = path;
48 minDistance = distance;
49 }
50 }
51 }
52
53 Q_FOREACH(KoShape *shape, m_shape->shapesInside()) {
54 KoPathShape *path = dynamic_cast<KoPathShape*>(shape);
55 if (!path) continue;
56 const QPointF mp = shape->documentToShape(clicked);
57 const QRectF paddingRect(mp - padding, mp + padding);
58
59 qDebug() << "segments" << path->segmentsAt(paddingRect).size() << paddingRect;
60 Q_FOREACH(KoPathSegment segment, path->segmentsAt(paddingRect)) {
61 const qreal nearestT = segment.nearestPoint(mp);
62 const QPointF nearestP = segment.pointAt(nearestT);
63 const qreal distance = kisDistance(mp, nearestP) - shapePadding;
64 if (distance < minDistance) {
65 candidate = path;
66 minDistance = distance;
67 isPadding = true;
68 }
69 }
70 }
71
72 m_referenceShape = candidate;
73 m_isPadding = isPadding;
74}
float value(const T *src, size_t ch)
qreal distance(const QPointF &p1, const QPointF &p2)
KoInteractionStrategy(KoToolBase *parent)
constructor
A KoPathSegment consist of two neighboring KoPathPoints.
QPointF pointAt(qreal t) const
Returns point at given t.
qreal nearestPoint(const QPointF &point) const
The position of a path point within a path shape.
Definition KoPathShape.h:63
QPointF documentToShape(const QPointF &point) const
Transforms point from document coordinates to shape coordinates.
Definition KoShape.cpp:1016
static const KoSvgTextProperties & defaultProperties()
QVariant propertyOrDefault(PropertyId id) const
void inheritFrom(const KoSvgTextProperties &parentProperties, bool resolve=false)
QList< KoShape * > shapesInside
QList< KoShape * > shapesSubtract
KoSvgTextProperties textProperties() const
qreal kisDistance(const QPointF &pt1, const QPointF &pt2)
Definition kis_global.h:190

References KoSvgTextProperties::defaultProperties(), distance(), KoShape::documentToShape(), KoSvgTextProperties::inheritFrom(), kisDistance(), m_isPadding, m_referenceShape, m_shape, KoPathSegment::nearestPoint(), KoPathSegment::pointAt(), KoSvgTextProperties::propertyOrDefault(), KoSvgTextProperties::ShapeMarginId, KoSvgTextProperties::ShapePaddingId, KoSvgTextShape::shapesInside, KoSvgTextShape::shapesSubtract, KoSvgTextShape::textProperties(), and value().

◆ ~SvgChangeTextPaddingMarginStrategy()

SvgChangeTextPaddingMarginStrategy::~SvgChangeTextPaddingMarginStrategy ( )

Definition at line 76 of file SvgChangeTextPaddingMarginStrategy.cpp.

77{
78
79}

Member Function Documentation

◆ createCommand()

KUndo2Command * SvgChangeTextPaddingMarginStrategy::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 164 of file SvgChangeTextPaddingMarginStrategy.cpp.

165{
166 if (!(m_referenceShape && m_shape)) return nullptr;
169 return new SvgTextMergePropertiesRangeCommand(m_shape, props, -1, -1);
170}
QLineF getLine(QPointF mousePos, KoPathShape *referenceShape, bool isPadding)
KoSvgTextProperties getProperties(bool isPadding, QLineF line, KoSvgTextProperties previous=KoSvgTextProperties())
The SvgTextMergePropertiesRangeCommand class This sets properties on a specific range in a single tex...

References getLine(), getProperties(), m_isPadding, m_lastMousePos, m_referenceShape, and m_shape.

◆ finishInteraction()

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

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

Implements KoInteractionStrategy.

Definition at line 172 of file SvgChangeTextPaddingMarginStrategy.cpp.

173{
174 Q_UNUSED(modifiers);
175}

◆ handleMouseMove()

void SvgChangeTextPaddingMarginStrategy::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 158 of file SvgChangeTextPaddingMarginStrategy.cpp.

159{
160 Q_UNUSED(modifiers);
161 m_lastMousePos = mouseLocation;
162}

References m_lastMousePos.

◆ hitTest()

std::optional< QPointF > SvgChangeTextPaddingMarginStrategy::hitTest ( KoSvgTextShape * shape,
const QPointF & mousePos,
const qreal grabSensitivityInPts )
static

hitTest Tests whether the current mouse position is over a text wrapping area, and if so, will return the angle vector at that point.

Parameters
shape– shape to test for.
mousePos– mousePos to test against.
grabSensitivityInPts– grabSensitivity in Points
Returns
– std::optional containing the angle vector.

Definition at line 81 of file SvgChangeTextPaddingMarginStrategy.cpp.

82{
83 if (!shape) return std::nullopt;
84 const QList<QPainterPath> textAreas = shape->textWrappingAreas();
85 if (textAreas.isEmpty()) return std::nullopt;
86
87 const QPointF grab(grabSensitivityInPts, grabSensitivityInPts);
88 const QRectF grabRect(mousePos-grab, mousePos+grab);
89
90 Q_FOREACH(const QPainterPath area, shape->textWrappingAreas()) {
92 if (!s) continue;
94 KoPathSegment segment = s->segmentAtPoint(mousePos, grabRect);
95 if (segment.isValid()) {
96 qreal nearest = segment.nearestPoint(s->documentToShape(mousePos));
97 return std::make_optional(segment.angleVectorAtParam(nearest));
98 }
99 }
100
101 return std::nullopt;
102}
QPointF angleVectorAtParam(qreal t)
angleVectorAtParam Calculates the angle vector at t.
bool isValid() const
Returns if segment is valid, e.g. has two valid points.
KoPathSegment segmentAtPoint(const QPointF &point, const QRectF &grabRoi) const
static KoPathShape * createShapeFromPainterPath(const QPainterPath &path)
Creates path shape from given QPainterPath.
QTransform absoluteTransformation() const
Definition KoShape.cpp:335
void setTransformation(const QTransform &matrix)
Definition KoShape.cpp:374
QList< QPainterPath > textWrappingAreas() const
textWrappingAreas The text wrapping areas are computed from shapesInside() and shapesSubtract(),...

References KoShape::absoluteTransformation(), KoPathSegment::angleVectorAtParam(), KoPathShape::createShapeFromPainterPath(), KoShape::documentToShape(), KoPathSegment::isValid(), KoPathSegment::nearestPoint(), KoPathShape::segmentAtPoint(), KoShape::setTransformation(), and KoSvgTextShape::textWrappingAreas().

◆ paint()

void SvgChangeTextPaddingMarginStrategy::paint ( QPainter & painter,
const KoViewConverter & converter )
overridevirtual

Reimplement this if the action needs to draw a "blob" on the canvas; that is, a transient decoration like a rubber band.

Reimplemented from KoInteractionStrategy.

Definition at line 137 of file SvgChangeTextPaddingMarginStrategy.cpp.

138{
139 if (!(m_referenceShape && m_shape)) return;
140 painter.save();
141 KisHandlePainterHelper handlePainter =
144
145 const QLineF line = getLine(m_lastMousePos, m_referenceShape, m_isPadding);
146 const QTransform lineTf = m_referenceShape->absoluteTransformation() * m_shape->absoluteTransformation().inverted();
147 handlePainter.drawConnectionLine(lineTf.map(line));
148
151 Q_FOREACH(QPainterPath area, areas) {
152 handlePainter.drawPath(area);
153 }
154
155 painter.restore();
156}
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)
static KisHandleStyle & selectedPrimaryHandles()
uint handleRadius() const
Convenience function to get the global handle radius.
static KisHandlePainterHelper createHandlePainterHelperView(QPainter *painter, KoShape *shape, const KoViewConverter &converter, qreal handleRadius=0.0, int decorationThickness=1)
Definition KoShape.cpp:982
static QList< QPainterPath > generateTextAreas(const QList< KoShape * > shapesInside, const QList< KoShape * > shapesSubtract, const KoSvgTextProperties &props)
generateTextAreas Generates text areas with the given shapes and properties. This is used to paint pr...

References KoShape::absoluteTransformation(), KoShape::createHandlePainterHelperView(), KoInteractionStrategy::decorationThickness(), KisHandlePainterHelper::drawConnectionLine(), KisHandlePainterHelper::drawPath(), KoSvgTextShape::generateTextAreas(), getLine(), getProperties(), KoInteractionStrategy::handleRadius(), m_isPadding, m_lastMousePos, m_referenceShape, m_shape, KisHandleStyle::selectedPrimaryHandles(), KisHandlePainterHelper::setHandleStyle(), KoSvgTextShape::shapesInside, KoSvgTextShape::shapesSubtract, and KoSvgTextShape::textProperties().

Member Data Documentation

◆ m_isPadding

bool SvgChangeTextPaddingMarginStrategy::m_isPadding
private

Definition at line 37 of file SvgChangeTextPaddingMarginStrategy.h.

◆ m_lastMousePos

QPointF SvgChangeTextPaddingMarginStrategy::m_lastMousePos
private

Definition at line 38 of file SvgChangeTextPaddingMarginStrategy.h.

◆ m_referenceShape

KoPathShape* SvgChangeTextPaddingMarginStrategy::m_referenceShape
private

Definition at line 36 of file SvgChangeTextPaddingMarginStrategy.h.

◆ m_shape

KoSvgTextShape* SvgChangeTextPaddingMarginStrategy::m_shape
private

Definition at line 35 of file SvgChangeTextPaddingMarginStrategy.h.


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