Krita Source Code Documentation
Loading...
Searching...
No Matches
KoShapeMergeTextPropertiesCommand.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2024 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
7
8#include <KoSvgTextShape.h>
10#include <kis_command_ids.h>
12
14 Private(const QList<KoShape*> &list) : shapes(list) { }
16 QMap<KoShape*, KoSvgTextShapeMementoSP> mementos;
18 QSet<KoSvgTextProperties::PropertyId> removeProperties;
19
20};
21
22KoShapeMergeTextPropertiesCommand::KoShapeMergeTextPropertiesCommand(const QList<KoShape *> &shapes, const KoSvgTextProperties &props, const QSet<KoSvgTextProperties::PropertyId> removeProperties, KUndo2Command *parent)
23 : KUndo2Command(parent),
24 d(new Private(shapes))
25{
26 setText(kundo2_i18n("Change Text Shape Properties"));
27 d->newProperties = props;
28 d->removeProperties = removeProperties;
29}
30
32{
33 for(auto it = d->shapes.begin(); it!= d->shapes.end(); it++) {
34 KoSvgTextShape *shape = dynamic_cast<KoSvgTextShape*>(*it);
35 if (shape) {
36 d->mementos.insert(*it, shape->getMemento());
37 const QRectF oldDirtyRect = shape->boundingRect();
38 shape->mergePropertiesIntoRange(-1, -1, d->newProperties, d->removeProperties);
39 shape->updateAbsolute(oldDirtyRect | shape->boundingRect());
40 }
41 }
42}
43
45{
46 for(auto it = d->shapes.begin(); it!= d->shapes.end(); it++) {
47 KoSvgTextShape *shape = dynamic_cast<KoSvgTextShape*>(*it);
48 if (shape && d->mementos.contains(*it)) {
49 const QRectF oldDirtyRect = shape->boundingRect();
50 shape->setMemento(d->mementos.value(*it));
51 shape->updateAbsolute(oldDirtyRect | shape->boundingRect());
52 }
53 }
54 d->mementos.clear();
55}
56
61
63{
64 const KoShapeMergeTextPropertiesCommand *command = dynamic_cast<const KoShapeMergeTextPropertiesCommand*>(other);
65
66 if (!command || !KritaUtils::compareListsUnordered(command->d->shapes, d->shapes)) {
67 return false;
68 }
69
78 Q_FOREACH(KoSvgTextProperties::PropertyId p, command->d->removeProperties) {
79 d->newProperties.removeProperty(p);
80 d->removeProperties.insert(p);
81 }
82
83 Q_FOREACH(KoSvgTextProperties::PropertyId p, command->d->newProperties.properties()) {
84 d->newProperties.setProperty(p, command->d->newProperties.property(p));
85 d->removeProperties.remove(p);
86 }
87
88 return true;
89}
const Params2D p
void setText(const KUndo2MagicString &text)
The KoShapeMergeTextPropertiesCommand class This sets text properties on given text shapes....
bool mergeWith(const KUndo2Command *command) override
KoShapeMergeTextPropertiesCommand(const QList< KoShape * > &shapes, const KoSvgTextProperties &props, const QSet< KoSvgTextProperties::PropertyId > removeProperties=QSet< KoSvgTextProperties::PropertyId >(), KUndo2Command *parent=nullptr)
virtual void updateAbsolute(const QRectF &rect) const
Definition KoShape.cpp:616
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 mergePropertiesIntoRange(const int startPos, const int endPos, const KoSvgTextProperties properties, const QSet< KoSvgTextProperties::PropertyId > removeProperties=QSet< KoSvgTextProperties::PropertyId >())
mergePropertiesIntoRange Merge given properties into the given range. This will first split the nodes...
KUndo2MagicString kundo2_i18n(const char *text)
@ KoShapeMergeTextPropertiesCommandId
bool compareListsUnordered(const QList< T > &a, const QList< T > &b)
QSet< KoSvgTextProperties::PropertyId > removeProperties
QMap< KoShape *, KoSvgTextShapeMementoSP > mementos