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

#include <KoSvgTextAddRemoveShapeCommands.h>

+ Inheritance diagram for KoSvgTextAddRemoveShapeCommandImpl:

Classes

struct  Private
 

Public Types

enum  ContourType { Unknown , Inside , Subtract , TextPath }
 
- Public Types inherited from KisCommandUtils::FlipFlopCommand
enum  State { INITIALIZING , FINALIZING }
 

Public Member Functions

 KoSvgTextAddRemoveShapeCommandImpl (KoSvgTextShape *textShape, KoShape *shape, ContourType type, State state, int startPos, int endPos, KUndo2Command *parent=nullptr)
 
void partA () override
 
void partB () override
 
 ~KoSvgTextAddRemoveShapeCommandImpl ()
 
- Public Member Functions inherited from KisCommandUtils::FlipFlopCommand
 FlipFlopCommand (bool finalizing=false, KUndo2Command *parent=0)
 
 FlipFlopCommand (State initialState, KUndo2Command *parent=0)
 
void redo () override
 
void undo () override
 
- Public Member Functions inherited from KUndo2Command
QString actionText () const
 
virtual bool canAnnihilateWith (const KUndo2Command *other) const
 
const KUndo2Command * child (int index) const
 
int childCount () const
 
virtual QTime endTime () const
 
KUndo2CommandExtraData * extraData () const
 
bool hasParent () const
 
virtual int id () const
 
virtual bool isMerged () const
 
 KUndo2Command (const KUndo2MagicString &text, KUndo2Command *parent=0)
 
 KUndo2Command (KUndo2Command *parent=0)
 
virtual QVector< KUndo2Command * > mergeCommandsVector () const
 
virtual bool mergeWith (const KUndo2Command *other)
 
virtual void redoMergedCommands ()
 
void setEndTime ()
 
virtual void setEndTime (const QTime &time)
 
void setExtraData (KUndo2CommandExtraData *data)
 
void setText (const KUndo2MagicString &text)
 
void setTime ()
 
virtual void setTime (const QTime &time)
 
virtual void setTimedID (int timedID)
 
KUndo2MagicString text () const
 
virtual QTime time () const
 
virtual int timedId () const
 
virtual bool timedMergeWith (KUndo2Command *other)
 
virtual void undoMergedCommands ()
 
virtual ~KUndo2Command ()
 

Private Attributes

QScopedPointer< Private > d
 

Additional Inherited Members

- Protected Member Functions inherited from KisCommandUtils::FlipFlopCommand
State getState () const
 
bool isFirstRedo () const
 

Detailed Description

Definition at line 16 of file KoSvgTextAddRemoveShapeCommands.h.

Member Enumeration Documentation

◆ ContourType

Constructor & Destructor Documentation

◆ KoSvgTextAddRemoveShapeCommandImpl()

KoSvgTextAddRemoveShapeCommandImpl::KoSvgTextAddRemoveShapeCommandImpl ( KoSvgTextShape * textShape,
KoShape * shape,
ContourType type,
State state,
int startPos,
int endPos,
KUndo2Command * parent = nullptr )

Definition at line 37 of file KoSvgTextAddRemoveShapeCommands.cpp.

39 , d(new Private(textShape, shape, startPos, endPos))
40{
41 d->removeCommand = state == FINALIZING;
42
43 if (type == Unknown) {
44 if (d->textShape->shapesInside().contains(shape)) {
45 d->type = Inside;
46 } else if (d->textShape->shapesSubtract().contains(shape)) {
47 d->type = Subtract;
48 } else if (d->textShape->shapeInContours(shape)){
49 d->type = TextPath;
50 KoSvgTextNodeIndex idx = textShape->nodeForTextPath(shape);
51 QPair<int, int> range = textShape->findRangeForNodeIndex(idx);
52 d->startPos = range.first;
53 d->endPos = range.second;
54 } else {
55 d->type = Unknown;
56 }
57 } else {
58 d->type = type;
59 }
60}
The KoSvgTextNodeIndex class.
QPair< int, int > findRangeForNodeIndex(const KoSvgTextNodeIndex &node) const
findRangeForNodeIndex Find the start and end cursor position for a given nodeIndex.
KoSvgTextNodeIndex nodeForTextPath(KoShape *textPath) const
nodeForTextPath TextPaths are set on toplevel content elements. This function allows for searching wh...

References d, KisCommandUtils::FlipFlopCommand::FINALIZING, KoSvgTextShape::findRangeForNodeIndex(), Inside, KoSvgTextShape::nodeForTextPath(), Subtract, TextPath, and Unknown.

◆ ~KoSvgTextAddRemoveShapeCommandImpl()

KoSvgTextAddRemoveShapeCommandImpl::~KoSvgTextAddRemoveShapeCommandImpl ( )

Definition at line 62 of file KoSvgTextAddRemoveShapeCommands.cpp.

63{
64
65}

Member Function Documentation

◆ partA()

void KoSvgTextAddRemoveShapeCommandImpl::partA ( )
overridevirtual

Reimplemented from KisCommandUtils::FlipFlopCommand.

Definition at line 105 of file KoSvgTextAddRemoveShapeCommands.cpp.

106{
107 if (!d->removeCommand) {
108 d->memento = d->textShape->getMemento();
109 d->oldTextPaths = d->textShape->textPathsAtRange(d->startPos, d->endPos);
110 d->originalShapeParent = d->shape->parent();
111 }
112
113 KoShapeBulkActionLock lock(QList<KoShape*>({d->textShape, d->shape}));
114
115 KoShapeContainer *oldParent = d->shape->parent();
116 const QTransform oldParentTransform = oldParent ? oldParent->absoluteTransformation() : QTransform();
117 const QTransform absoluteTf = d->textShape->absoluteTransformation().inverted() * oldParentTransform;
118
119 if (d->type == Inside) {
120 d->textShape->addShapeContours({d->shape}, true);
121 } else if (d->type == Subtract) {
122 d->textShape->addShapeContours({d->shape}, false);
123 } else if (d->type == TextPath) {
124 d->textShape->setTextPathOnRange(d->shape, d->startPos, d->endPos);
125 }
126
127 if (d->removeCommand) {
128 Q_FOREACH(KoShape *path, d->oldTextPaths) {
129 if (!d->textShape->shapeInContours(path)) {
130 d->textShape->addTextPathAtEnd(path);
131 }
132 }
133 d->textShape->setMemento(d->memento);
134 } else {
135 d->textShape->relayout();
136 }
137 d->shape->applyAbsoluteTransformation(absoluteTf);
138
140}
static void bulkShapesUpdate(const UpdatesList &updates)
KoShapeContainer * parent() const
Definition KoShape.cpp:857
QTransform absoluteTransformation() const
Definition KoShape.cpp:330

References KoShape::absoluteTransformation(), KoShapeBulkActionLock::bulkShapesUpdate(), d, Inside, KoShape::parent(), Subtract, TextPath, and KoShapeBulkActionLock::unlock().

◆ partB()

void KoSvgTextAddRemoveShapeCommandImpl::partB ( )
overridevirtual

Reimplemented from KisCommandUtils::FlipFlopCommand.

Definition at line 68 of file KoSvgTextAddRemoveShapeCommands.cpp.

69{
70 if (d->removeCommand) {
71 d->memento = d->textShape->getMemento();
72 d->oldTextPaths = d->textShape->textPathsAtRange(d->startPos, d->endPos);
73 }
74
75 KoShapeBulkActionLock lock(QList<KoShape*>({d->textShape, d->shape}));
76
77 KoShapeContainer *newParent = d->originalShapeParent.has_value() ? d->originalShapeParent.value() : d->textShape->parent();
78 const QTransform newParentTransform = newParent ? newParent->absoluteTransformation() : QTransform();
79 const QTransform absoluteTf = newParentTransform.inverted() * d->textShape->absoluteTransformation();
80
81 d->textShape->removeShapesFromContours({d->shape}, true);
82 // by this time d->shape->parent() is set to nullptr
83
84 if (newParent) {
85 // set new parent if exists
86 d->shape->setParent(newParent);
87 }
88
89 if (!d->removeCommand) {
90 Q_FOREACH(KoShape *path, d->oldTextPaths) {
91 if (!d->textShape->shapeInContours(path)) {
92 d->textShape->addTextPathAtEnd(path);
93 }
94 }
95 d->textShape->setMemento(d->memento);
96 } else {
97 d->textShape->relayout();
98 }
99 d->shape->applyAbsoluteTransformation(absoluteTf);
100
102}

References KoShape::absoluteTransformation(), KoShapeBulkActionLock::bulkShapesUpdate(), d, KoShape::parent(), and KoShapeBulkActionLock::unlock().

Member Data Documentation

◆ d

QScopedPointer<Private> KoSvgTextAddRemoveShapeCommandImpl::d
private

Definition at line 32 of file KoSvgTextAddRemoveShapeCommands.h.


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