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++

experiment: Try to delay complex operations in the text tool while resizing.

Wolthera van Hövell tot Westerflierd568705c9aa0
diff --git a/libs/flake/commands/KoShapeResizeCommand.cpp b/libs/flake/commands/KoShapeResizeCommand.cpp
index 40dd42ed87..43188f2dee 100644
--- a/libs/flake/commands/KoShapeResizeCommand.cpp
+++ b/libs/flake/commands/KoShapeResizeCommand.cpp
@@ -10,6 +10,8 @@
#include "kis_command_ids.h"
#include "kis_assert.h"
+#include <KoSvgTextShape.h>
+
struct Q_DECL_HIDDEN KoShapeResizeCommand::Private
{
@@ -47,6 +49,13 @@ KoShapeResizeCommand::KoShapeResizeCommand(const QList<KoShape*> &shapes,
Q_FOREACH (KoShape *shape, m_d->shapes) {
m_d->oldSizes << shape->size();
m_d->oldTransforms << shape->transformation();
+
+ Q_FOREACH(KoShape *dependee, shape->dependees()) {
+ KoSvgTextShape* text = dynamic_cast<KoSvgTextShape*>(dependee);
+ if (text) {
+ text->setRelayoutBlocked(true);
+ }
+ }
}
}
@@ -144,6 +153,20 @@ bool KoShapeResizeCommand::mergeWith(const KUndo2Command *command)
void KoShapeResizeCommand::replaceResizeAction(qreal scaleX, qreal scaleY, const QPointF &absoluteStillPoint)
{
+ QMap<KoSvgTextShape *, QRectF> textUpdates;
+ Q_FOREACH(KoShape *shape, m_d->shapes) {
+ KoSvgTextShape* text = dynamic_cast<KoSvgTextShape*>(shape);
+ if (!text) {
+ Q_FOREACH(KoShape *dependee, shape->dependees()) {
+ text = dynamic_cast<KoSvgTextShape*>(dependee);
+
+ }
+ }
+ if (text) {
+ text->setRelayoutBlocked(true);
+ textUpdates.insert(text, text->boundingRect());
+ }
+ }
const QMap<KoShape*, QRectF> undoUpdates = undoNoUpdate();
m_d->scaleX = scaleX;
@@ -156,6 +179,14 @@ void KoShapeResizeCommand::replaceResizeAction(qreal scaleX, qreal scaleY, const
for (auto it = undoUpdates.begin(); it != undoUpdates.end(); ++it) {
KIS_SAFE_ASSERT_RECOVER_NOOP(redoUpdates.contains(it.key()));
+ if (textUpdates.keys().contains(dynamic_cast<KoSvgTextShape*>(it.key()))) continue;
it.key()->updateAbsolute(it.value() | redoUpdates[it.key()]);
}
+
+ for (auto it = textUpdates.begin(); it != textUpdates.end(); ++it) {
+ it.key()->setRelayoutBlocked(false);
+ it.key()->processComplexOperationsIfNecessary();
+ it.key()->updateAbsolute( it.value()| it.key()->boundingRect());
+ }
+
}
diff --git a/libs/flake/text/KoSvgTextLoader.cpp b/libs/flake/text/KoSvgTextLoader.cpp
index fc0c54a670..179b0e36a8 100644
--- a/libs/flake/text/KoSvgTextLoader.cpp
+++ b/libs/flake/text/KoSvgTextLoader.cpp
@@ -34,7 +34,7 @@ KoSvgTextLoader::~KoSvgTextLoader()
d->shape->d->updateShapeGroup();
d->shape->cleanUp();
d->shape->d->isLoading = false;
- d->shape->relayout();
+ d->shape->d->updateTextWrappingAreas();
}
void KoSvgTextLoader::enterNodeSubtree()
diff --git a/libs/flake/text/KoSvgTextShape.cpp b/libs/flake/text/KoSvgTextShape.cpp
index dad17aa43e..be74472d6c 100644
--- a/libs/flake/text/KoSvgTextShape.cpp
+++ b/libs/flake/text/KoSvgTextShape.cpp
@@ -178,6 +178,8 @@ KoShape *KoSvgTextShape::cloneShape() const
void KoSvgTextShape::shapeChanged(ChangeType type, KoShape *shape)
{
if (d->isLoading) {
+ this->notifyChanged();
+ d->dirty = true;
return;
}
KoShape::shapeChanged(type, shape);
@@ -212,7 +214,7 @@ void KoSvgTextShape::shapeChanged(ChangeType type, KoShape *shape)
d->updateTextWrappingAreas();
// NotifyChanged ensures that boundingRect() is called on this shape.
this->notifyChanged();
- if (d->shapesSubtract.contains(shape)) {
+ if (d->shapesSubtract.contains(shape) || d->textPaths.contains(shape)) {
// Shape subtract will otherwise only
// update it's own bounding rect.
this->update();
@@ -1936,6 +1938,17 @@ QList<QPainterPath> KoSvgTextShape::generateTextAreas(const QList<KoShape *> sha
return Private::generateShapes(shapesInside, shapesSubtract, props);
}
+bool KoSvgTextShape::processComplexOperationsIfNecessary()
+{
+ if (d->dirty) {
+ d->shapeGroup->setTransformation(this->absoluteTransformation());
+ d->updateTextWrappingAreas();
+ notifyChanged();
+ return true;
+ }
+ return false;
+}
+
void KoSvgTextShape::paint(QPainter &painter) const
{
painter.save();
@@ -2283,7 +2296,11 @@ void KoSvgTextShape::addShapeContours(QList<KoShape *> shapes, const bool inside
}
}
notifyChanged(); // notify shape manager that our geometry has changed
- d->updateTextWrappingAreas();
+ if (!d->isLoading) {
+ d->updateTextWrappingAreas();
+ } else {
+ d->dirty = true;
+ }
d->updateInternalShapesList();
shapeChangedPriv(ContentChanged);
update();
@@ -2312,7 +2329,11 @@ void KoSvgTextShape::removeShapesFromContours(QList<KoShape *> shapes, bool call
}
if (callUpdate) {
notifyChanged(); // notify shape manager that our geometry has changed
- d->updateTextWrappingAreas();
+ if (!d->isLoading) {
+ d->updateTextWrappingAreas();
+ } else {
+ d->dirty = true;
+ }
d->updateInternalShapesList();
shapeChangedPriv(ContentChanged);
update();
@@ -2326,7 +2347,11 @@ void KoSvgTextShape::moveShapeInsideToIndex(KoShape *shapeInside, const int inde
// Update.
d->shapesInside.move(oldIndex, index);
- d->updateTextWrappingAreas();
+ if (!d->isLoading) {
+ d->updateTextWrappingAreas();
+ } else {
+ d->dirty = true;
+ }
d->updateInternalShapesList();
shapeChangedPriv(ContentChanged);
update();
@@ -2505,6 +2530,7 @@ QMap<QString, QString> KoSvgTextShape::shapeTypeSpecificStyles(SvgSavingContext
void KoSvgTextShape::relayout() const
{
d->relayout();
+ d->dirty = false;
}
KoSvgTextShapeFactory::KoSvgTextShapeFactory()
diff --git a/libs/flake/text/KoSvgTextShape.h b/libs/flake/text/KoSvgTextShape.h
index 90beadc2e4..8de4b563e4 100644
--- a/libs/flake/text/KoSvgTextShape.h
+++ b/libs/flake/text/KoSvgTextShape.h
@@ -656,6 +656,8 @@ public:
*/
static QList<QPainterPath> generateTextAreas(const QList<KoShape*> shapesInside, const QList<KoShape*> shapesSubtract, const KoSvgTextProperties &props);
+
+ bool processComplexOperationsIfNecessary();
protected:
void shapeChanged(ChangeType type, KoShape *shape) override;
diff --git a/libs/flake/text/KoSvgTextShape_p.h b/libs/flake/text/KoSvgTextShape_p.h
index 66390e4119..5cde7eed5d 100644
--- a/libs/flake/text/KoSvgTextShape_p.h
+++ b/libs/flake/text/KoSvgTextShape_p.h
@@ -563,6 +563,7 @@ public:
KisForest<KoSvgTextContentElement> textData;
bool isLoading = false; ///< Turned on when loading in text data, blocks updates to shape listeners.
+ bool dirty = false; ///< Enabled when updates come in while isLoading is enabled.
bool disableFontMatching = false; ///< Turn off font matching, which should speed up relayout slightly.
diff --git a/libs/flake/text/KoSvgTextShape_p_layout.cpp b/libs/flake/text/KoSvgTextShape_p_layout.cpp
index 4a20cdcb3b..8b4a0b299c 100644
--- a/libs/flake/text/KoSvgTextShape_p_layout.cpp
+++ b/libs/flake/text/KoSvgTextShape_p_layout.cpp
@@ -114,9 +114,8 @@ void KoSvgTextShape::Private::updateTextWrappingAreas()
{
KoSvgTextProperties rootProperties = textData.empty()? KoSvgTextProperties::defaultProperties(): textData.childBegin()->properties;
currentTextWrappingAreas = getShapes(shapesInside, shapesSubtract, rootProperties);
- if (!isLoading) {
- relayout();
- }
+ relayout();
+ dirty = false;
}
QList<QPainterPath> KoSvgTextShape::Private::generateShapes(const QList<KoShape *> shapesInside, const QList<KoShape *> shapesSubtract, const KoSvgTextProperties &properties)