Krita Source Code Documentation
Loading...
Searching...
No Matches
SvgInlineSizeChangeCommand.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2023 Alvin <alvin@alvinhc.com>
3 *
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 */
6
9
10#include <QRegularExpression>
11
12#include <klocalizedstring.h>
13
14#include "KoSvgText.h"
15#include "KoSvgTextProperties.h"
16#include "KoSvgTextShape.h"
18
19#include "kis_assert.h"
20#include "kis_command_ids.h"
21
23 : SvgInlineSizeChangeCommand(shape, inlineSize, SvgInlineSizeHelper::getInlineSizePt(shape), 0, 0, QPointF(), QPointF(), parent)
24{
25}
26
28 double inlineSize,
29 double oldInlineSize,
30 int anchor,
31 int oldAnchor,
32 QPointF movePos,
33 QPointF oldPos,
34 KUndo2Command *parent)
35 : KUndo2Command(parent)
36 , m_shape(shape)
37 , m_inlineSize(inlineSize)
38 , m_oldInlineSize(oldInlineSize)
39 , m_anchor(anchor)
40 , m_oldAnchor(oldAnchor)
41 , m_originalPos(oldPos)
42 , m_movePos(movePos)
43{
44 setText(kundo2_i18n("Adjust text auto wrap"));
45}
46
47void SvgInlineSizeChangeCommand::applyInlineSize(double inlineSize, int anchor, QPointF pos, bool undo)
48{
49 QRectF updateRect = m_shape->boundingRect();
50
53 inlineSizeProp.customValue = inlineSize;
54 inlineSizeProp.isAuto = false;
56 properties.setProperty(KoSvgTextProperties::TextAnchorId, QVariant(anchor));
57
58 if (undo) {
59 m_shape->setPropertiesAtPos(-1, properties);
61 } else {
63 m_shape->setPropertiesAtPos(-1, properties);
64 }
65
67}
68
73
78
83
85{
86 const SvgInlineSizeChangeCommand *other = dynamic_cast<const SvgInlineSizeChangeCommand *>(otherCommand);
87
88 if (!other || other->m_shape != m_shape) {
89 return false;
90 }
91
93 m_anchor = other->m_anchor;
94 m_movePos = other->m_movePos;
95
96 return true;
97}
void setText(const KUndo2MagicString &text)
virtual void updateAbsolute(const QRectF &rect) const
Definition KoShape.cpp:616
void setAbsolutePosition(const QPointF &newPosition, KoFlake::AnchorPosition anchor=KoFlake::Center)
Definition KoShape.cpp:668
@ TextAnchorId
KoSvgText::TextAnchor.
@ InlineSizeId
KoSvgText::AutoValue.
void setProperty(PropertyId id, const QVariant &value)
QVariant propertyOrDefault(PropertyId id) const
QRectF boundingRect() const override
Get the bounding box of the shape.
KoSvgTextProperties propertiesForPos(const int pos, bool inherited=false) const
Return the properties at a given position.
void setPropertiesAtPos(int pos, KoSvgTextProperties properties)
setPropertiesAtPos will set the properties at pos.
void applyInlineSize(double inlineSize, int anchor, QPointF pos, bool undo=false)
bool mergeWith(const KUndo2Command *other) override
SvgInlineSizeChangeCommand(KoSvgTextShape *shape, double inlineSize, KUndo2Command *parent=nullptr)
KUndo2MagicString kundo2_i18n(const char *text)
@ TopLeft
Definition KoFlake.h:86
QVariant fromAutoValue(const KoSvgText::AutoValue &value)
Definition KoSvgText.h:493