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

Create text properties manager that uploads text property data to the canvas resources.

Wolthera van Hövell tot Westerflier35e9cde55f7f
diff --git a/libs/flake/CMakeLists.txt b/libs/flake/CMakeLists.txt
index f4beaa7d00..15c2a9be8a 100644
--- a/libs/flake/CMakeLists.txt
+++ b/libs/flake/CMakeLists.txt
@@ -224,6 +224,7 @@ set(kritaflake_SRCS
text/KoFontRegistry.cpp
text/KoCssTextUtils.cpp
text/KoPolygonUtils.cpp
+ text/KoSvgTextPropertyData.cpp
resources/KoSvgSymbolCollectionResource.cpp
resources/KoGamutMask.cpp
diff --git a/libs/flake/text/KoSvgTextProperties.cpp b/libs/flake/text/KoSvgTextProperties.cpp
index 079fa1213f..eb65843717 100644
--- a/libs/flake/text/KoSvgTextProperties.cpp
+++ b/libs/flake/text/KoSvgTextProperties.cpp
@@ -49,7 +49,7 @@ KoSvgTextProperties &KoSvgTextProperties::operator=(const KoSvgTextProperties &r
return *this;
}
-bool KoSvgTextProperties::operator==(const KoSvgTextProperties &rhs) {
+bool KoSvgTextProperties::operator==(const KoSvgTextProperties &rhs) const {
return m_d->properties == rhs.m_d->properties;
}
diff --git a/libs/flake/text/KoSvgTextProperties.h b/libs/flake/text/KoSvgTextProperties.h
index 58c258530a..875cde6f64 100644
--- a/libs/flake/text/KoSvgTextProperties.h
+++ b/libs/flake/text/KoSvgTextProperties.h
@@ -126,7 +126,7 @@ public:
KoSvgTextProperties(const KoSvgTextProperties &rhs);
KoSvgTextProperties& operator=(const KoSvgTextProperties &rhs);
- bool operator==(const KoSvgTextProperties &rhs);
+ bool operator==(const KoSvgTextProperties &rhs) const;
/**
* Set the property \p id to \p value
diff --git a/libs/flake/text/KoSvgTextPropertyData.cpp b/libs/flake/text/KoSvgTextPropertyData.cpp
new file mode 100644
index 0000000000..83cb2dfc04
--- /dev/null
+++ b/libs/flake/text/KoSvgTextPropertyData.cpp
@@ -0,0 +1,24 @@
+/*
+ * SPDX-FileCopyrightText: 2024 Wolthera van Hövell tot Westerflier <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#include "KoSvgTextPropertyData.h"
+#include <QDebug>
+
+#include <KisStaticInitializer.h>
+
+KIS_DECLARE_STATIC_INITIALIZER {
+ qRegisterMetaType<KoSvgTextPropertyData>("KoSvgTextPropertyData");
+ QMetaType::registerEqualsComparator<KoSvgTextPropertyData>();
+ QMetaType::registerDebugStreamOperator<KoSvgTextPropertyData>();
+}
+
+QDebug operator<<(QDebug dbg, const KoSvgTextPropertyData &prop)
+{
+ dbg.nospace() << "TextPropertyData(";
+ dbg.nospace() << " Common properties:" << prop.commonProperties.convertToSvgTextAttributes();
+ dbg.nospace() << " Tristate:" << prop.tristate;
+ dbg.nospace() << " )";
+ return dbg.space();
+}
diff --git a/libs/flake/text/KoSvgTextPropertyData.h b/libs/flake/text/KoSvgTextPropertyData.h
new file mode 100644
index 0000000000..c58b46ed30
--- /dev/null
+++ b/libs/flake/text/KoSvgTextPropertyData.h
@@ -0,0 +1,41 @@
+/*
+ * SPDX-FileCopyrightText: 2024 Wolthera van Hövell tot Westerflier <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#ifndef KOSVGTEXTPROPERTYDATA_H
+#define KOSVGTEXTPROPERTYDATA_H
+
+#include "KoSvgTextProperties.h"
+#include "kritaflake_export.h"
+
+#include <boost/operators.hpp>
+
+/**
+ * @brief The KoSvgTextPropertyData struct
+ *
+ * This struct contains the style data of a given set of text objects.
+ * Within text editing it is very common to select ranges of multiple
+ * styled spans, each with their own properties.
+ *
+ * This struct encapsulates the data to represent it inside a text property
+ * widget, and is the source data for the lager model.
+ */
+struct KRITAFLAKE_EXPORT KoSvgTextPropertyData : public boost::equality_comparable<KoSvgTextPropertyData>
+{
+ /// The properties common between all the selected text.
+ KoSvgTextProperties commonProperties;
+
+ /// The properties that are not common (tri-state) between the selected text.
+ QSet<KoSvgTextProperties::PropertyId> tristate;
+
+ bool operator==(const KoSvgTextPropertyData &rhs) const {
+ return commonProperties == rhs.commonProperties && tristate == rhs.tristate;
+ }
+};
+
+QDebug KRITAFLAKE_EXPORT operator<<(QDebug dbg, const KoSvgTextPropertyData &prop);
+
+Q_DECLARE_METATYPE(KoSvgTextPropertyData)
+
+#endif // KOSVGTEXTPROPERTYDATA_H
diff --git a/libs/resources/KoCanvasResourcesIds.h b/libs/resources/KoCanvasResourcesIds.h
index fd5edb5107..93b7bba1d0 100644
--- a/libs/resources/KoCanvasResourcesIds.h
+++ b/libs/resources/KoCanvasResourcesIds.h
@@ -63,7 +63,8 @@ enum CanvasResourceId {
HandleRadius, ///< The handle radius used for drawing handles of any kind
DecorationThickness, ///< Integer, the thickness of single px decorations, will be adjusted by HiDPI settings. Because most of our decorations are drawn without anti-aliasing, this is an integer, so that line thickness won't vary as the painter tries round the floating point.
UsingOtherColor, ///<- a boolean that is controlled by the tool invocation action
- ColorHistory // Color history if not per document
+ ColorHistory, ///< Color history if not per document
+ SvgTextPropertyData, ///< KoSvgTextPropertyDataStruct
};
}
diff --git a/libs/ui/CMakeLists.txt b/libs/ui/CMakeLists.txt
index 71c537d90d..37529fd4d7 100644
--- a/libs/ui/CMakeLists.txt
+++ b/libs/ui/CMakeLists.txt
@@ -164,6 +164,7 @@ set(kritaui_LIB_SRCS
KisIdleTasksManager.cpp
KisIdleTaskStrokeStrategy.cpp
KisImageThumbnailStrokeStrategy.cpp
+ KisTextPropertiesManager.cpp
opengl/kis_opengl.cpp
opengl/kis_opengl_canvas2.cpp
diff --git a/libs/ui/KisTextPropertiesManager.cpp b/libs/ui/KisTextPropertiesManager.cpp
new file mode 100644
index 0000000000..b0510261ff
--- /dev/null
+++ b/libs/ui/KisTextPropertiesManager.cpp
@@ -0,0 +1,97 @@
+/*
+ * SPDX-FileCopyrightText: 2024 Wolthera van Hövell tot Westerflier <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#include "KisTextPropertiesManager.h"
+#include <KoSelectedShapesProxy.h>
+#include <kis_canvas_resource_provider.h>
+#include <KoSvgTextPropertyData.h>
+#include <KoSelection.h>
+#include <KoSvgTextShape.h>
+
+#include <KisView.h>
+#include <kis_canvas2.h>
+
+#include <QPointer>
+
+struct KisTextPropertiesManager::Private {
+ KisCanvasResourceProvider *provider;
+ QPointer<KisView> view {0};
+};
+
+KisTextPropertiesManager::KisTextPropertiesManager(QObject *parent)
+ : QObject(parent)
+ , d(new Private)
+{
+}
+
+KisTextPropertiesManager::~KisTextPropertiesManager()
+{
+}
+
+void KisTextPropertiesManager::setView(QPointer<KisView> imageView)
+{
+ if (d->view) {
+ disconnect(d->view->canvasBase()->selectedShapesProxy(), SIGNAL(selectionChanged()), this, SLOT(slotShapeSelectionChanged()));
+ }
+
+ d->view = imageView;
+ connect(d->view->canvasBase()->selectedShapesProxy(), SIGNAL(selectionChanged()), this, SLOT(slotShapeSelectionChanged()));
+}
+
+void KisTextPropertiesManager::setCanvasResourceProvider(KisCanvasResourceProvider *provider)
+{
+ d->provider = provider;
+}
+
+void KisTextPropertiesManager::slotShapeSelectionChanged()
+{
+ if (!d->view
+ || !d->view->canvasBase()
+ || !d->view->canvasBase()->selectedShapesProxy()
+ || !d->view->canvasBase()->selectedShapesProxy()->selection()
+ || !d->provider) return;
+
+ KoSvgTextPropertyData textData;
+
+ const QList<KoShape*> shapes = d->view->canvasBase()->selectedShapesProxy()->selection()->selectedEditableShapes();
+ QList<KoSvgTextProperties> props;
+ QSet<KoSvgTextProperties::PropertyId> propIds;
+
+ for (auto it = shapes.begin(); it != shapes.end(); it++) {
+ KoSvgTextShape *textShape = dynamic_cast<KoSvgTextShape*>(*it);
+ if (!textShape) continue;
+ KoSvgTextProperties p = textShape->textProperties();
+ props.append(p);
+ for (int i = 0; i < p.properties().size(); i++) {
+ propIds.insert(p.properties().at(i));
+ }
+ }
+
+ if (props.isEmpty()) return;
+
+ // Find common properties, and mark all non-common properties as tristate.
+
+ textData.commonProperties = props.first();
+
+ for (auto it = props.begin(); it != props.end(); it++) {
+ for (int i = 0; i < propIds.size(); i++) {
+ KoSvgTextProperties::PropertyId p = propIds.values().at(i);
+ if (it->hasProperty(p)) {
+ if (textData.commonProperties.property(p) != it->property(p)) {
+ textData.commonProperties.removeProperty(p);
+ textData.tristate.insert(p);
+ }
+ } else {
+ textData.commonProperties.removeProperty(p);
+ textData.tristate.insert(p);
+ }
+ }
+ }
+
+ qDebug() << "Setting text data on canvas resources";
+ qDebug() << textData;
+
+ d->provider->setTextPropertyData(textData);
+}
diff --git a/libs/ui/KisTextPropertiesManager.h b/libs/ui/KisTextPropertiesManager.h
new file mode 100644
index 0000000000..3b645737e2
--- /dev/null
+++ b/libs/ui/KisTextPropertiesManager.h
@@ -0,0 +1,39 @@
+/*
+ * SPDX-FileCopyrightText: 2024 Wolthera van Hövell tot Westerflier <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#ifndef KISTEXTPROPERTYMANAGER_H
+#define KISTEXTPROPERTYMANAGER_H
+
+#include <QObject>
+
+class KisView;
+class KisCanvasResourceProvider;
+
+/**
+ * @brief The KisTextPropertyManager class
+ *
+ * This class handles taking text property data from the currently selected
+ * text objects and then setting it on the resource provider.
+ */
+class KisTextPropertiesManager : public QObject
+{
+ Q_OBJECT
+public:
+ KisTextPropertiesManager(QObject *parent = nullptr);
+ ~KisTextPropertiesManager();
+
+ void setView(QPointer<KisView> imageView);
+ void setCanvasResourceProvider(KisCanvasResourceProvider *provider);
+
+private Q_SLOTS:
+ void slotShapeSelectionChanged();
+private:
+
+ struct Private;
+ QScopedPointer<Private> d;
+
+};
+
+#endif // KISTEXTPROPERTYMANAGER_H
diff --git a/libs/ui/KisViewManager.cpp b/libs/ui/KisViewManager.cpp
index 2a88e2c09a..509f978902 100644
--- a/libs/ui/KisViewManager.cpp
+++ b/libs/ui/KisViewManager.cpp
@@ -124,6 +124,7 @@
#include <KoToolDocker.h>
#include <KisIdleTasksManager.h>
#include <KisImageBarrierLock.h>
+#include <KisTextPropertiesManager.h>
#include "kis_filter_configuration.h"
@@ -233,6 +234,7 @@ public:
KisMirrorManager mirrorManager;
KisInputManager inputManager;
KisIdleTasksManager idleTasksManager;
+ KisTextPropertiesManager textPropertyManager;
KisSignalAutoConnectionsStore viewConnections;
KSelectAction *actionAuthor {nullptr}; // Select action for author profile.
@@ -343,6 +345,7 @@ KisViewManager::KisViewManager(QWidget *parent, KisKActionCollection *_actionCol
KoColor background(Qt::white, cs);
d->canvasResourceProvider.setBGColor(cfg.readKoColor("LastBackGroundColor",background));
d->canvasResourceProvider.setColorHistory(cfg.readKoColors("LastColorHistory"));
+ d->textPropertyManager.setCanvasResourceProvider(&d->canvasResourceProvider);
// Initialize the old imagesize plugin
new ImageSize(this);
@@ -532,6 +535,7 @@ void KisViewManager::setCurrentView(KisView *view)
d->statusBar.setView(imageView);
d->paintingAssistantsManager.setView(imageView);
d->mirrorManager.setView(imageView);
+ d->textPropertyManager.setView(imageView);
if (d->currentImageView) {
d->currentImageView->notifyCurrentStateChanged(true);
diff --git a/libs/ui/KisViewManager.h b/libs/ui/KisViewManager.h
index 40feb9d5a8..dbac2cfea6 100644
--- a/libs/ui/KisViewManager.h
+++ b/libs/ui/KisViewManager.h
@@ -44,6 +44,7 @@ class KisMainWindow;
class KoZoomController;
class KoCanvasResourceProvider;
class KisIdleTasksManager;
+class KisTextPropertiesManager;
/**
* KisViewManager manages the collection of views shown in a single mainwindow.
@@ -128,6 +129,8 @@ public: // Krita specific interfaces
KisIdleTasksManager *idleTasksManager();
+ KisTextPropertiesManager *textPropertyManager() const;
+
/// Convenience method to get at the active selection (the
/// selection of the current layer, or, if that does not exist,
/// the global selection.
diff --git a/libs/ui/kis_canvas_resource_provider.cpp b/libs/ui/kis_canvas_resource_provider.cpp
index 3472b80364..18d5cdefb6 100644
--- a/libs/ui/kis_canvas_resource_provider.cpp
+++ b/libs/ui/kis_canvas_resource_provider.cpp
@@ -18,6 +18,7 @@
#include <resources/KoStopGradient.h>
#include <KoColorSpaceRegistry.h>
#include <KoResource.h>
+#include <KoSvgTextPropertyData.h>
#include <resources/KoPattern.h>
#include <kis_paint_device.h>
@@ -545,6 +546,16 @@ bool KisCanvasResourceProvider::disablePressure() const
return m_resourceManager->resource(KoCanvasResource::DisablePressure).toBool();
}
+void KisCanvasResourceProvider::setTextPropertyData(KoSvgTextPropertyData data)
+{
+ m_resourceManager->setResource(KoCanvasResource::SvgTextPropertyData, QVariant::fromValue(data));
+}
+
+KoSvgTextPropertyData KisCanvasResourceProvider::textPropertyData() const
+{
+ return m_resourceManager->resource(KoCanvasResource::SvgTextPropertyData).value<KoSvgTextPropertyData>();
+}
+
void KisCanvasResourceProvider::notifyLoadingWorkspace(KisWorkspaceResourceSP workspace)
{
emit sigLoadingWorkspace(workspace);
diff --git a/libs/ui/kis_canvas_resource_provider.h b/libs/ui/kis_canvas_resource_provider.h
index d1d10a962b..d311810072 100644
--- a/libs/ui/kis_canvas_resource_provider.h
+++ b/libs/ui/kis_canvas_resource_provider.h
@@ -25,6 +25,7 @@
class KoColorProfile;
class KoAbstractGradient;
+struct KoSvgTextPropertyData;
class KoCanvasBase;
class KisViewManager;
@@ -130,6 +131,9 @@ public:
void setDisablePressure(bool value);
bool disablePressure() const;
+ void setTextPropertyData(KoSvgTextPropertyData data);
+ KoSvgTextPropertyData textPropertyData() const;
+
///Notify that the workspace is saved and settings should be saved to it
void notifySavingWorkspace(KisWorkspaceResourceSP workspace);