Krita Source Code Documentation
Loading...
Searching...
No Matches
SvgTextRemoveCommand.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2023 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 */
7
8#include <klocalizedstring.h>
9#include "kis_command_ids.h"
10
11#include "KoSvgTextShape.h"
14 int endIndex, int pos,
15 int anchor,
16 int length,
17 bool allowCleanUp,
18 KUndo2Command *parent)
19 : KUndo2Command(parent)
20 , m_shape(shape)
21 , m_index(endIndex)
22 , m_originalPos(pos)
23 , m_anchor(anchor)
24 , m_length(length)
25 , m_allowCleanUp(allowCleanUp)
26{
27 Q_ASSERT(shape);
28 setText(kundo2_i18n("Remove Text"));
29}
30
32{
33 QRectF updateRect = m_shape->boundingRect();
34
36
37 int idx = m_index - m_length;
39 m_index = idx + m_length;
40
41 if (m_allowCleanUp) {
43 }
45
46 int pos = qMax(0, m_shape->posForIndex(idx, false, false));
48}
49
56
61
63{
64 const SvgTextRemoveCommand *command = dynamic_cast<const SvgTextRemoveCommand*>(other);
65
66
67 if (!command || command->m_shape != m_shape) {
68 return false;
69 }
70 int oldIndex = m_index;
71 int otherOldIndex = command->m_index;
72
73 if (oldIndex - m_length == otherOldIndex) {
74 m_length += command->m_length;
75 return true;
76 } else if (otherOldIndex - command->m_length == oldIndex - m_length) {
77 return true;
78 } else {
79 return false;
80 }
81 return true;
82}
qreal length(const QPointF &vec)
Definition Ellipse.cc:82
void setText(const KUndo2MagicString &text)
virtual void updateAbsolute(const QRectF &rect) const
Definition KoShape.cpp:616
void notifyCursorPosChanged(int pos, int anchor)
Notify that the cursor position has changed.
KoSvgTextShapeMementoSP getMemento()
Get a memento holding the current textdata and layout info.
void setMemento(const KoSvgTextShapeMementoSP memento)
Set the text data and layout info, reset listening cursors to 0.
QRectF boundingRect() const override
Get the bounding box of the shape.
void cleanUp()
Cleans up the internal text data. Used by undo commands.
int posForIndex(int index, bool firstIndex=false, bool skipSynthetic=false) const
posForIndex Get the cursor position for a given index in a string.
bool removeText(int &index, int &length)
removeText Where insert text explicitly uses a cursorposition, remove text uses a string index....
void redo() override
redo the command
int id() const override
void undo() override
revert the actions done in redo
KoSvgTextShapeMementoSP m_textData
SvgTextRemoveCommand(KoSvgTextShape *shape, int endIndex, int pos, int anchor, int length, bool allowCleanUp=true, KUndo2Command *parent=0)
SvgTextRemoveCommand Remove text from shape.
bool mergeWith(const KUndo2Command *other) override
KUndo2MagicString kundo2_i18n(const char *text)