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

Remove KoTosContainer

Dmitry Kazakov7c9118514c22
diff --git a/libs/flake/CMakeLists.txt b/libs/flake/CMakeLists.txt
index ec49b57705..011e658449 100644
--- a/libs/flake/CMakeLists.txt
+++ b/libs/flake/CMakeLists.txt
@@ -107,8 +107,6 @@ set(kritaflake_SRCS
KoViewConverter.cpp
KoViewTransformStillPoint.cpp
KoTextShapeDataBase.cpp
- KoTosContainer.cpp
- KoTosContainerModel.cpp
KoClipMaskApplicatorBase.cpp
${__per_arch_alpha_applicator_factory_objs}
KoClipMaskPainter.cpp
diff --git a/libs/flake/KoPathShape.cpp b/libs/flake/KoPathShape.cpp
index a43beab258..c8f4f12206 100644
--- a/libs/flake/KoPathShape.cpp
+++ b/libs/flake/KoPathShape.cpp
@@ -57,13 +57,13 @@ QRectF KoPathShape::Private::handleRect(const QPointF &p, qreal radius) const
KoPathShape::KoPathShape()
- : KoTosContainer()
+ : KoShape()
, d(new Private)
{
}
KoPathShape::KoPathShape(const KoPathShape &rhs)
- : KoTosContainer(rhs)
+ : KoShape(rhs)
, d(new Private(*rhs.d))
{
// local data cannot be shared via QSharedData because
diff --git a/libs/flake/KoPathShape.h b/libs/flake/KoPathShape.h
index 153801a52c..9645aadd2f 100644
--- a/libs/flake/KoPathShape.h
+++ b/libs/flake/KoPathShape.h
@@ -15,7 +15,7 @@
#include <QMetaType>
#include <QTransform>
-#include "KoTosContainer.h"
+#include "KoShape.h"
#define KoPathShapeId "KoPathShape"
@@ -59,7 +59,7 @@ typedef QList<KoSubpath *> KoSubpathList;
* generated. See the outline method. The reason for storing it like that is that
* it is the points that are modified by the user and not the segments.
*/
-class KRITAFLAKE_EXPORT KoPathShape : public KoTosContainer
+class KRITAFLAKE_EXPORT KoPathShape : public KoShape
{
public:
/**
diff --git a/libs/flake/KoTosContainer.cpp b/libs/flake/KoTosContainer.cpp
deleted file mode 100644
index 67d3191fe1..0000000000
--- a/libs/flake/KoTosContainer.cpp
+++ /dev/null
@@ -1,236 +0,0 @@
-/* This file is part of the KDE project
- * SPDX-FileCopyrightText: 2010 Thomas Zander <[email protected]>
- * SPDX-FileCopyrightText: 2010 KO GmbH <[email protected]>
- * SPDX-FileCopyrightText: 2010 Thorsten Zachmann <[email protected]>
- *
- * SPDX-License-Identifier: LGPL-2.0-or-later
- */
-
-#include "KoTosContainer.h"
-
-#include "KoTosContainer_p.h"
-#include "KoShapeRegistry.h"
-#include "KoShapeFactoryBase.h"
-#include "KoShapeLoadingContext.h"
-#include "KoTextShapeDataBase.h"
-#include "KoTosContainerModel.h"
-#include "KoXmlNS.h"
-
-#include <FlakeDebug.h>
-
-#include <QTextCursor>
-#include <QTextDocument>
-
-KoTosContainer::Private::Private()
- : QSharedData()
- , resizeBehavior(KoTosContainer::IndependentSizes)
-{
-}
-
-KoTosContainer::Private::Private(const Private &rhs)
- : QSharedData()
- , resizeBehavior(rhs.resizeBehavior)
- , preferredTextRect(rhs.preferredTextRect)
- , alignment(rhs.alignment)
-{
-}
-
-KoTosContainer::Private::~Private()
-{
-}
-
-
-KoTosContainer::KoTosContainer()
- : KoShapeContainer()
- , d(new Private)
-{
-}
-
-KoTosContainer::KoTosContainer(const KoTosContainer &rhs)
- : KoShapeContainer(rhs)
- , d(rhs.d)
-{
-}
-
-KoTosContainer::~KoTosContainer()
-{
- delete textShape();
-}
-
-void KoTosContainer::paintComponent(QPainter &) const
-{
-}
-
-bool KoTosContainer::loadText(const QDomElement &element)
-{
- Q_UNUSED(element);
- return false;
-}
-
-
-void KoTosContainer::setPlainText(const QString &text)
-{
- KoShape *textShape = this->textShape();
- if (textShape == 0) {
- warnFlake << "No text shape present in KoTosContainer";
- return;
- }
- KoTextShapeDataBase *shapeData = qobject_cast<KoTextShapeDataBase*>(textShape->userData());
- Q_ASSERT(shapeData->document());
- shapeData->document()->setPlainText(text);
-}
-
-void KoTosContainer::setResizeBehavior(ResizeBehavior resizeBehavior)
-{
- if (d->resizeBehavior == resizeBehavior) {
- return;
- }
- d->resizeBehavior = resizeBehavior;
- if (model()) {
- model()->containerChanged(this, KoShape::SizeChanged);
- }
-}
-
-KoTosContainer::ResizeBehavior KoTosContainer::resizeBehavior() const
-{
- return d->resizeBehavior;
-}
-
-void KoTosContainer::setTextAlignment(Qt::Alignment alignment)
-{
- KoShape *textShape = this->textShape();
- if (textShape == 0) {
- warnFlake << "No text shape present in KoTosContainer";
- return;
- }
-
- // vertical
- KoTextShapeDataBase *shapeData = qobject_cast<KoTextShapeDataBase*>(textShape->userData());
- shapeData->setVerticalAlignment(alignment);
-
- // horizontal
- Q_ASSERT(shapeData->document());
- QTextBlockFormat bf;
- bf.setAlignment(alignment & Qt::AlignHorizontal_Mask);
-
- QTextCursor cursor(shapeData->document());
- cursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
- cursor.mergeBlockFormat(bf);
-
- d->alignment = alignment;
-}
-
-Qt::Alignment KoTosContainer::textAlignment() const
-{
- KoShape *textShape = this->textShape();
- if (textShape == 0) {
- warnFlake << "No text shape present in KoTosContainer";
- return Qt::AlignTop;
- }
-
- // vertical
- KoTextShapeDataBase *shapeData = qobject_cast<KoTextShapeDataBase*>(textShape->userData());
- // the model makes sure it contains a shape that has a KoTextShapeDataBase set so no need to check that
- Qt::Alignment answer = shapeData->verticalAlignment() & Qt::AlignVertical_Mask;
-
- // horizontal
- Q_ASSERT(shapeData->document());
- QTextCursor cursor(shapeData->document());
- answer = answer | (cursor.blockFormat().alignment() & Qt::AlignHorizontal_Mask);
-
- return answer;
-}
-
-void KoTosContainer::setPreferredTextRect(const QRectF &rect)
-{
- d->preferredTextRect = rect;
- KoShape *textShape = this->textShape();
- //debugFlake << rect << textShape << d->resizeBehavior;
- if (d->resizeBehavior == TextFollowsPreferredTextRect && textShape) {
- //debugFlake << rect;
- textShape->setPosition(rect.topLeft());
- textShape->setSize(rect.size());
- }
-}
-
-QRectF KoTosContainer::preferredTextRect() const
-{
- return d->preferredTextRect;
-}
-
-KoShape *KoTosContainer::createTextShape(KoDocumentResourceManager *documentResources)
-{
- if (!documentResources) {
- warnFlake << "KoDocumentResourceManager not found";
- return 0;
- }
-
- delete textShape();
- delete model();
-
- setModel(new KoTosContainerModel());
-
- QSet<KoShape*> delegates;
- delegates << this;
- KoShape *textShape = 0;
- KoShapeFactoryBase *factory = KoShapeRegistry::instance()->get("TextShapeID");
- if (factory) { // not installed, that's too bad, but allowed
- textShape = factory->createDefaultShape(documentResources);
- Q_ASSERT(textShape); // would be a bug in the text shape;
- if (d->resizeBehavior == TextFollowsPreferredTextRect) {
- textShape->setSize(d->preferredTextRect.size());
- } else {
- textShape->setSize(size());
- }
- if (d->resizeBehavior == TextFollowsPreferredTextRect) {
- textShape->setPosition(d->preferredTextRect.topLeft());
- } else {
- textShape->setPosition(QPointF(0, 0));
- }
- textShape->setSelectable(false);
- textShape->setRunThrough(runThrough());
- KoTextShapeDataBase *shapeData = qobject_cast<KoTextShapeDataBase*>(textShape->userData());
- Q_ASSERT(shapeData); // would be a bug in kotext
- // TODO check if that is correct depending on the resize mode
- shapeData->setVerticalAlignment(Qt::AlignVCenter);
- addShape(textShape);
- // textShape->setZIndex(zIndex() + 1); // not needed as there as the text shape is the only sub shape
- delegates << textShape;
- } else {
- warnFlake << "Text shape factory not found";
- }
- setToolDelegates(delegates);
- return textShape;
-}
-
-KoShape *KoTosContainer::textShape() const
-{
- const QList<KoShape*> subShapes = shapes();
- return subShapes.isEmpty() ? 0 : subShapes.at(0);
-}
-
-void KoTosContainer::shapeChanged(ChangeType type, KoShape *shape)
-{
- Q_UNUSED(shape);
- if (model() == 0) {
- return;
- }
-
- if (type == SizeChanged || type == ContentChanged) {
- model()->containerChanged(this, type);
- }
- // TODO is this needed?
-#if 0
- Q_FOREACH (KoShape *shape, model()->shapes())
- shape->notifyChanged();
-#endif
-}
-
-void KoTosContainer::setRunThrough(short int runThrough)
-{
- KoShape::setRunThrough(runThrough);
- KoShape *textShape = this->textShape();
- if (textShape) {
- textShape->setRunThrough(runThrough);
- }
-}
diff --git a/libs/flake/KoTosContainer.h b/libs/flake/KoTosContainer.h
deleted file mode 100644
index 61f89e74a1..0000000000
--- a/libs/flake/KoTosContainer.h
+++ /dev/null
@@ -1,110 +0,0 @@
-/* This file is part of the KDE project
- * SPDX-FileCopyrightText: 2010 Thomas Zander <[email protected]>
- * SPDX-FileCopyrightText: 2010 KO GmbH <[email protected]>
- * SPDX-FileCopyrightText: 2010 Thorsten Zachmann <[email protected]>
- *
- * SPDX-License-Identifier: LGPL-2.0-or-later
- */
-
-#ifndef KOTOSCONTAINER_H
-#define KOTOSCONTAINER_H
-
-#include "KoShapeContainer.h"
-
-#include "kritaflake_export.h"
-
-class KoDocumentResourceManager;
-
-
-/**
- * Container that is used to wrap a shape with a text on top.
- * Path shapes inherit from this class to make it possible to have text associated
- * with them.
- */
-class KRITAFLAKE_EXPORT KoTosContainer : public KoShapeContainer
-{
-public:
- KoTosContainer();
- ~KoTosContainer() override;
-
- // reimplemented
- void paintComponent(QPainter &painter) const override;
-
- // reimplemented
- virtual bool loadText(const QDomElement &element);
-
-
- /// different kinds of resizing behavior to determine how to treat text overflow
- enum ResizeBehavior {
- TextFollowsSize, ///< Text area is same size as content, extra text will be clipped
- FollowTextSize, ///< Content shape will get resized if text grows/shrinks
- IndependentSizes, ///< The text can get bigger than the content
- TextFollowsPreferredTextRect ///< The size/position of the text area will follow the preferredTextRect property
- };
-
- /**
- * Set the behavior that is used to resize the text or content.
- * In order to determine what to do when there is too much text to fit or suddenly less
- * text the user can define the wanted behavior using the ResizeBehavior
- * @param resizeBehavior the new ResizeBehavior
- */
- void setResizeBehavior(ResizeBehavior resizeBehavior);
-
- /**
- * Returns the current ResizeBehavior.
- */
- ResizeBehavior resizeBehavior() const;
-
- /** Sets the alignment of the text. */
- void setTextAlignment(Qt::Alignment alignment);
-
- /** Returns the alignment of all text */
- Qt::Alignment textAlignment() const;
-
- /**
- * Set some plain text to be displayed on the shape.
- * @param text the full text.
- */
- void setPlainText(const QString &text);
-
- /**
- * Add text the current shape with the specified document resource manager.
- *
- * @param documentResources
- * @return The created text shape or 0 in case it failed
- */
- KoShape *createTextShape(KoDocumentResourceManager *documentResources = 0);
-
- void setRunThrough(short int runThrough) override;
-
-protected:
- KoTosContainer(const KoTosContainer &rhs);
-
- /**
- * Set the current preferred text rectangle. This rect contains the coordinates of
- * the embedded text shape relative to the content shape. This value is ignored if
- * resizeBehavior is not TextFollowsPreferredTextRect.
- * @param rect the new preferred text rectangle
- */
- void setPreferredTextRect(const QRectF &rect);
-
- /**
- * Returns the current preferred text rectangle.
- */
- QRectF preferredTextRect() const;
-
- /**
- * Returns the text shape
- *
- * @returns textshape if set or 0 in case it is not yet set
- */
- KoShape *textShape() const;
-
- void shapeChanged(ChangeType type, KoShape *shape = 0) override;
-
-private:
- class Private;
- QSharedDataPointer<Private> d;
-};
-
-#endif
diff --git a/libs/flake/KoTosContainerModel.cpp b/libs/flake/KoTosContainerModel.cpp
deleted file mode 100644
index 030567e336..0000000000
--- a/libs/flake/KoTosContainerModel.cpp
+++ /dev/null
@@ -1,96 +0,0 @@
-/* This file is part of the KDE project
- SPDX-FileCopyrightText: 2010 Thorsten Zachmann <[email protected]>
-
- SPDX-License-Identifier: LGPL-2.0-or-later
-*/
-
-#include "KoTosContainerModel.h"
-
-#include "KoTextShapeDataBase.h"
-#include "KoTosContainer.h"
-
-#include <FlakeDebug.h>
-#include <QSizeF>
-
-KoTosContainerModel::KoTosContainerModel()
-: m_textShape(0)
-{
-}
-
-KoTosContainerModel::~KoTosContainerModel()
-{
-}
-
-void KoTosContainerModel::add(KoShape *shape)
-{
- // make sure shape is a text shape
- KoTextShapeDataBase *shapeData = qobject_cast<KoTextShapeDataBase*>(shape->userData());
- Q_ASSERT(shapeData != 0);
- if (shapeData) {
- delete m_textShape;
- m_textShape = shape;
- }
-}
-
-void KoTosContainerModel::remove(KoShape *shape)
-{
- Q_ASSERT(m_textShape == 0 || shape == m_textShape);
- if (shape == m_textShape) {
- m_textShape = 0;
- }
-}
-
-void KoTosContainerModel::setClipped(const KoShape *shape, bool clipping)
-{
- Q_UNUSED(shape);
- Q_UNUSED(clipping);
-}
-
-bool KoTosContainerModel::isClipped(const KoShape *shape) const
-{
- Q_UNUSED(shape);
- return false;
-}
-
-void KoTosContainerModel::setInheritsTransform(const KoShape *shape, bool inherit)
-{
- Q_UNUSED(shape);
- Q_UNUSED(inherit);
-}
-
-bool KoTosContainerModel::inheritsTransform(const KoShape *shape) const
-{
- Q_UNUSED(shape);
- return true;
-}
-
-int KoTosContainerModel::count() const
-{
- return m_textShape != 0 ? 1 : 0;
-}
-
-QList<KoShape*> KoTosContainerModel::shapes() const
-{
- QList<KoShape*> shapes;
- if (m_textShape) {
- shapes << m_textShape;
- }
- return shapes;
-}
-
-void KoTosContainerModel::containerChanged(KoShapeContainer *container, KoShape::ChangeType type)
-{
- debugFlake << "change type:" << type << KoShape::SizeChanged << KoShape::ContentChanged;
- if (type != KoShape::SizeChanged && type != KoShape::ContentChanged) {
- return;
- }
- KoTosContainer *tosContainer = dynamic_cast<KoTosContainer*>(container);
- debugFlake << "tosContainer" << tosContainer;
- if (tosContainer) {
- debugFlake << "behaviour" << tosContainer->resizeBehavior() << KoTosContainer::TextFollowsPreferredTextRect;
- }
- if ( m_textShape && tosContainer && tosContainer->resizeBehavior() != KoTosContainer::TextFollowsPreferredTextRect ) {
- debugFlake << "change type setSize";
- m_textShape->setSize(tosContainer->size());
- }
-}
diff --git a/libs/flake/KoTosContainerModel.h b/libs/flake/KoTosContainerModel.h
deleted file mode 100644
index 78f23337e7..0000000000
--- a/libs/flake/KoTosContainerModel.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/* This file is part of the KDE project
- SPDX-FileCopyrightText: 2010 Thorsten Zachmann <[email protected]>
-
- SPDX-License-Identifier: LGPL-2.0-or-later
-*/
-#ifndef KOTOSCONTAINERMODEL_H
-#define KOTOSCONTAINERMODEL_H
-
-#include "KoShapeContainerModel.h"
-
-class KoTosContainerModel : public KoShapeContainerModel
-{
-public:
- KoTosContainerModel();
- ~KoTosContainerModel() override;
-
- void add(KoShape *shape) override;
- void remove(KoShape *shape) override;
- void setClipped(const KoShape *shape, bool clipping) override;
- bool isClipped(const KoShape *shape) const override;
- void setInheritsTransform(const KoShape *shape, bool inherit) override;
- bool inheritsTransform(const KoShape *shape) const override;
- int count() const override;
- QList<KoShape*> shapes() const override;
- void containerChanged(KoShapeContainer *container, KoShape::ChangeType type) override;
-
-private:
- KoShape *m_textShape;
-};
-
-#endif /* KOTOSCONTAINERMODEL_H */
diff --git a/libs/flake/KoTosContainer_p.h b/libs/flake/KoTosContainer_p.h
deleted file mode 100644
index 6f3954571e..0000000000
--- a/libs/flake/KoTosContainer_p.h
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * SPDX-License-Identifier: GPL-3.0-or-later
- */
-
-#ifndef KOTOSCONTAINER_P_H
-#define KOTOSCONTAINER_P_H
-
-#include "kritaflake_export.h"
-#include "KoShapeContainer_p.h"
-
-#include "KoTosContainer.h"
-#include <QSharedData>
-#include <QRectF>
-
-class KoTosContainer::Private : public QSharedData
-{
-public:
-
- explicit Private();
- explicit Private(const Private &rhs);
-
- virtual ~Private();
-
- KoTosContainer::ResizeBehavior resizeBehavior;
- QRectF preferredTextRect;
- Qt::Alignment alignment;
-};
-
-#endif // KOTOSCONTAINER_P_H
diff --git a/libs/ui/KisReferenceImage.cpp b/libs/ui/KisReferenceImage.cpp
index 9c4df4f60f..63cb344a92 100644
--- a/libs/ui/KisReferenceImage.cpp
+++ b/libs/ui/KisReferenceImage.cpp
@@ -22,7 +22,6 @@
#include <kundo2command.h>
#include <KoStore.h>
#include <KoStoreDevice.h>
-#include <KoTosContainer_p.h>
#include <krita_utils.h>
#include <kis_coordinates_converter.h>
#include <kis_dom_utils.h>
@@ -152,7 +151,7 @@ KisReferenceImage::KisReferenceImage()
}
KisReferenceImage::KisReferenceImage(const KisReferenceImage &rhs)
- : KoTosContainer(rhs)
+ : KoShape(rhs)
, d(rhs.d)
{}
diff --git a/libs/ui/KisReferenceImage.h b/libs/ui/KisReferenceImage.h
index ed4002c3eb..38f3c5129f 100644
--- a/libs/ui/KisReferenceImage.h
+++ b/libs/ui/KisReferenceImage.h
@@ -10,7 +10,7 @@
#include <QSharedDataPointer>
#include <KoColor.h>
-#include <KoTosContainer.h>
+#include <KoShape.h>
#include <kis_types.h>
#include <kritaui_export.h>
#include <kundo2command.h>
@@ -26,7 +26,7 @@ class KisCanvas2;
/**
* @brief The KisReferenceImage class represents a single reference image
*/
-class KRITAUI_EXPORT KisReferenceImage : public KoTosContainer
+class KRITAUI_EXPORT KisReferenceImage : public KoShape
{
public:
struct KRITAUI_EXPORT SetSaturationCommand : public KUndo2Command {
diff --git a/plugins/flake/imageshape/ImageShape.cpp b/plugins/flake/imageshape/ImageShape.cpp
index c863a4c32f..4420fe1c3e 100644
--- a/plugins/flake/imageshape/ImageShape.cpp
+++ b/plugins/flake/imageshape/ImageShape.cpp
@@ -4,8 +4,6 @@
* SPDX-License-Identifier: GPL-2.0-or-later
*/
-#include <KoTosContainer_p.h>
-
#include "ImageShape.h"
#include "kis_debug.h"
@@ -45,7 +43,7 @@ ImageShape::ImageShape()
}
ImageShape::ImageShape(const ImageShape &rhs)
- : KoTosContainer(rhs),
+ : KoShape(rhs),
m_d(rhs.m_d)
{
}
@@ -73,7 +71,7 @@ void ImageShape::paint(QPainter &painter) const
void ImageShape::setSize(const QSizeF &size)
{
- KoTosContainer::setSize(size);
+ KoShape::setSize(size);
}
bool ImageShape::saveSvg(SvgSavingContext &context)
diff --git a/plugins/flake/imageshape/ImageShape.h b/plugins/flake/imageshape/ImageShape.h
index 5a0e1f32f1..3a030c85b6 100644
--- a/plugins/flake/imageshape/ImageShape.h
+++ b/plugins/flake/imageshape/ImageShape.h
@@ -9,13 +9,13 @@
#include <QSharedDataPointer>
-#include "KoTosContainer.h"
+#include "KoShape.h"
#include <SvgShape.h>
#define ImageShapeId "ImageShape"
-class ImageShape : public KoTosContainer, public SvgShape
+class ImageShape : public KoShape, public SvgShape
{
public:
ImageShape();
diff --git a/plugins/flake/pathshapes/enhancedpath/EnhancedPathShape.cpp b/plugins/flake/pathshapes/enhancedpath/EnhancedPathShape.cpp
index 5c0290fbde..7b720fbbaa 100644
--- a/plugins/flake/pathshapes/enhancedpath/EnhancedPathShape.cpp
+++ b/plugins/flake/pathshapes/enhancedpath/EnhancedPathShape.cpp
@@ -517,7 +517,6 @@ void EnhancedPathShape::updateTextArea()
r.setRight(evaluateConstantOrReference(m_textArea[2]));
r.setBottom(evaluateConstantOrReference(m_textArea[3]));
r = m_viewMatrix.mapRect(r).translated(m_viewBoxOffset);
- setPreferredTextRect(r);
}
}