Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++

Make internal shape painter forward updates to KoSvgTextShape

Wolthera van Hövell tot Westerflier46440c898a8f
diff --git a/libs/flake/svg/KoShapePainter.cpp b/libs/flake/svg/KoShapePainter.cpp
index 27707e9b28..b45700c07b 100644
--- a/libs/flake/svg/KoShapePainter.cpp
+++ b/libs/flake/svg/KoShapePainter.cpp
@@ -60,8 +60,9 @@ public:
return m_selectedShapesProxy.data();
}
- void updateCanvas(const QRectF&) override
+ void updateCanvas(const QRectF&rect) override
{
+ m_updateFunc(rect);
}
KoToolProxy *toolProxy() const override
@@ -96,9 +97,14 @@ public:
void setCursor(const QCursor &) override {}
+ void setUpdateFunction(std::function<void(const QRectF&)> function) {
+ m_updateFunc = function;
+ }
+
private:
QScopedPointer<KoShapeManager> m_shapeManager;
QScopedPointer<KoSelectedShapesProxySimple> m_selectedShapesProxy;
+ std::function<void(const QRectF&)> m_updateFunc;
};
class Q_DECL_HIDDEN KoShapePainter::Private
@@ -209,3 +215,8 @@ KoShapeManager *KoShapePainter::internalShapeManager() const
{
return d->canvas->shapeManager();
}
+
+void KoShapePainter::setUpdateFunction(std::function<void (const QRectF &)> function)
+{
+ d->canvas->setUpdateFunction(function);
+}
diff --git a/libs/flake/svg/KoShapePainter.h b/libs/flake/svg/KoShapePainter.h
index 603450fc47..571292d72c 100644
--- a/libs/flake/svg/KoShapePainter.h
+++ b/libs/flake/svg/KoShapePainter.h
@@ -70,6 +70,8 @@ public:
*/
KoShapeManager *internalShapeManager() const;
+ void setUpdateFunction(std::function<void(const QRectF&)> function);
+
private:
class Private;
QScopedPointer<Private> d;
diff --git a/libs/flake/text/KoSvgTextShape.cpp b/libs/flake/text/KoSvgTextShape.cpp
index 02ddc80f11..28c06bca4b 100644
--- a/libs/flake/text/KoSvgTextShape.cpp
+++ b/libs/flake/text/KoSvgTextShape.cpp
@@ -42,6 +42,7 @@
#include <QtMath>
#include <FlakeDebug.h>
+#include <functional>
// Memento pointer to hold data for Undo commands.
@@ -131,7 +132,9 @@ KoSvgTextShape::KoSvgTextShape()
, d(new Private)
{
setShapeId(KoSvgTextShape_SHAPEID);
+ d->shapeGroup->setTransformation(this->transformation());
d->textData.insert(d->textData.childBegin(), KoSvgTextContentElement());
+ d->internalShapesPainter->setUpdateFunction(std::bind(&KoSvgTextShape::updateAbsolute, this, std::placeholders::_1));
}
KoSvgTextShape::KoSvgTextShape(const KoSvgTextShape &rhs)
@@ -139,6 +142,8 @@ KoSvgTextShape::KoSvgTextShape(const KoSvgTextShape &rhs)
, d(new Private(*rhs.d))
{
setShapeId(KoSvgTextShape_SHAPEID);
+ d->shapeGroup->setTransformation(this->transformation());
+ d->internalShapesPainter->setUpdateFunction(std::bind(&KoSvgTextShape::updateAbsolute, this, std::placeholders::_1));
Q_FOREACH(KoShape *shape, d->shapeGroup->shapes()) {
shape->addDependee(this);
}
@@ -174,11 +179,12 @@ void KoSvgTextShape::shapeChanged(ChangeType type, KoShape *shape)
|| type == ShearChanged
|| type == SizeChanged
|| type == GenericMatrixChange
- || type == ParameterChanged)) {
+ || type == ParameterChanged
+ || type == ParentChanged)) {
// update shape. relayout.
//TODO: also handle type == Deleted. Need to figure out the order of operations though.
relayout();
- this->updateAbsolute(boundingRect());
+ this->notifyChanged();
qDebug() << "child updated";
}
if ((!shape || shape == this)) {
@@ -186,6 +192,7 @@ void KoSvgTextShape::shapeChanged(ChangeType type, KoShape *shape)
if ((type == ContentChanged)) {
relayout();
} else {
+ qDebug() << "update transform";
d->shapeGroup->setTransformation(this->transformation());
}
}
@@ -1820,7 +1827,7 @@ void KoSvgTextShape::paint(QPainter &painter) const
{
painter.save();
- painter.setTransform(this->absoluteTransformation().inverted()*painter.transform());
+ painter.setTransform(d->shapeGroup->absoluteTransformation().inverted()*painter.transform());
d->internalShapesPainter->paint(painter);
painter.restore();
@@ -2030,15 +2037,19 @@ KoSvgTextShape::TextType KoSvgTextShape::textType() const
void KoSvgTextShape::setShapesInside(QList<KoShape *> shapesInside)
{
Q_FOREACH(KoShape *shape, d->shapesInside) {
- shape->removeDependee(this);
- delete shape;
+ if (shape) {
+ shape->removeDependee(this);
+ }
+ d->shapeGroup->removeShape(shape);
}
d->shapesInside = shapesInside;
- d->updateShapeGroup();
- Q_FOREACH(KoShape *shape, d->shapeGroup->shapes()) {
+ Q_FOREACH(KoShape *shape, d->shapesInside) {
+ d->shapeGroup->addShape(shape);
shape->addDependee(this);
}
+ d->updateInternalShapesList();
shapeChangedPriv(ContentChanged);
+ update();
}
QList<KoShape *> KoSvgTextShape::shapesInside() const
@@ -2049,15 +2060,19 @@ QList<KoShape *> KoSvgTextShape::shapesInside() const
void KoSvgTextShape::setShapesSubtract(QList<KoShape *> shapesSubtract)
{
Q_FOREACH(KoShape *shape, d->shapesSubtract) {
- shape->removeDependee(this);
- delete shape;
+ if (shape) {
+ shape->removeDependee(this);
+ }
+ d->shapeGroup->removeShape(shape);
}
d->shapesSubtract = shapesSubtract;
- d->updateShapeGroup();
- Q_FOREACH(KoShape *shape, d->shapeGroup->shapes()) {
+ Q_FOREACH(KoShape *shape, d->shapesSubtract) {
+ d->shapeGroup->addShape(shape);
shape->addDependee(this);
}
+ d->updateInternalShapesList();
shapeChangedPriv(ContentChanged);
+ update();
}
QList<KoShape *> KoSvgTextShape::shapesSubtract() const
diff --git a/libs/flake/text/KoSvgTextShape_p.h b/libs/flake/text/KoSvgTextShape_p.h
index 4b60ab430a..4ce9a80dbc 100644
--- a/libs/flake/text/KoSvgTextShape_p.h
+++ b/libs/flake/text/KoSvgTextShape_p.h
@@ -17,8 +17,6 @@
#include "KoCssTextUtils.h"
#include <KoShapeGroup.h>
-#include <commands/KoShapeGroupCommand.h>
-#include <commands/KoShapeUngroupCommand.h>
#include <kis_assert.h>
#include <KisForest.h>
@@ -515,16 +513,18 @@ public:
}
void updateShapeGroup() {
- QList<KoShape*> total = shapesInside;
- total.append(shapesSubtract);
- total.append(textPaths);
- KUndo2Command *parentCmd = new KUndo2Command();
- if (!shapeGroup->shapes().isEmpty()) {
- qWarning() << "shapes are not empty, might leak!";
- new KoShapeUngroupCommand(shapeGroup.data(), shapeGroup->shapes(), QList<KoShape*>(), parentCmd);
+ Q_FOREACH(KoShape *shape, shapeGroup->shapes()) {
+ shapeGroup->removeShape(shape);
+ }
+ Q_FOREACH(KoShape *shape, shapesInside) {
+ shapeGroup->addShape(shape);
+ }
+ Q_FOREACH(KoShape *shape, shapesSubtract) {
+ shapeGroup->addShape(shape);
+ }
+ Q_FOREACH(KoShape *shape, textPaths) {
+ shapeGroup->addShape(shape);
}
- new KoShapeGroupCommand(shapeGroup.data(), total, false, parentCmd);
- parentCmd->redo();
updateInternalShapesList();
}
void updateInternalShapesList() {
diff --git a/plugins/tools/svgtexttool/SvgCreateTextStrategy.cpp b/plugins/tools/svgtexttool/SvgCreateTextStrategy.cpp
index 43946e4b03..d19c26923b 100644
--- a/plugins/tools/svgtexttool/SvgCreateTextStrategy.cpp
+++ b/plugins/tools/svgtexttool/SvgCreateTextStrategy.cpp
@@ -149,11 +149,11 @@ KUndo2Command *SvgCreateTextStrategy::createCommand()
QList<QPointF> newPos {QPointF()};
QList<KoShape*> shapes{m_flowShape};
new KoShapeMoveCommand(shapes, pos, newPos, KoFlake::TopLeft, parentCommand);
- new SvgChangeTextContoursCommand(textShape, shapes, parentCommand);
if (m_flowShape->parent()) {
// text is not a shape container, but we do need to remove the shape from the canvas properly.
tool->canvas()->shapeController()->removeShape(m_flowShape, parentCommand);
}
+ new SvgChangeTextContoursCommand(textShape, shapes, parentCommand);
}
new KoKeepShapesSelectedCommand({}, {textShape}, tool->canvas()->selectedShapesProxy(), true, parentCommand);