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"
19
20#include "kis_assert.h"
21#include "kis_command_ids.h"
22
24 : SvgInlineSizeChangeCommand(shape, inlineSize, SvgInlineSizeHelper::getInlineSizePt(shape), 0, 0, QPointF(), QPointF(), parent)
25{
26}
27
29 double inlineSize,
30 double oldInlineSize,
31 int anchor,
32 int oldAnchor,
33 QPointF movePos,
34 QPointF oldPos,
35 KUndo2Command *parent)
36 : KUndo2Command(parent)
37 , m_shape(shape)
38 , m_inlineSize(inlineSize)
39 , m_oldInlineSize(oldInlineSize)
40 , m_anchor(anchor)
41 , m_oldAnchor(oldAnchor)
42 , m_originalPos(oldPos)
43 , m_movePos(movePos)
44{
45 setText(kundo2_i18n("Adjust text auto wrap"));
46}
47
48void SvgInlineSizeChangeCommand::applyInlineSize(double inlineSize, int anchor, QPointF pos, bool undo)
49{
51
54 inlineSizeProp.customValue = inlineSize;
55 inlineSizeProp.isAuto = false;
57 properties.setProperty(KoSvgTextProperties::TextAnchorId, QVariant(anchor));
58
59 if (undo) {
60 m_shape->setPropertiesAtPos(-1, properties);
62 } else {
64 m_shape->setPropertiesAtPos(-1, properties);
65 }
66
68}
69
74
79
84
86{
87 const SvgInlineSizeChangeCommand *other = dynamic_cast<const SvgInlineSizeChangeCommand *>(otherCommand);
88
89 if (!other || other->m_shape != m_shape) {
90 return false;
91 }
92
94 m_anchor = other->m_anchor;
95 m_movePos = other->m_movePos;
96
97 return true;
98}
void setText(const KUndo2MagicString &text)
static void bulkShapesUpdate(const UpdatesList &updates)
void setAbsolutePosition(const QPointF &newPosition, KoFlake::AnchorPosition anchor=KoFlake::Center)
Definition KoShape.cpp:588
@ TextAnchorId
KoSvgText::TextAnchor.
@ InlineSizeId
KoSvgText::AutoValue.
void setProperty(PropertyId id, const QVariant &value)
QVariant propertyOrDefault(PropertyId id) const
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