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

Implement a textPropertiesInterface in the Default/Shape Selection Tool.

Wolthera van Hövell tot Westerflier387cad0043c5
diff --git a/libs/command/kis_command_ids.h b/libs/command/kis_command_ids.h
index aea8f6c435..61d74d5105 100644
--- a/libs/command/kis_command_ids.h
+++ b/libs/command/kis_command_ids.h
@@ -39,7 +39,8 @@ enum CommandId {
SvgInsertTextCommand,
SvgRemoveTextCommand,
ChangePaintOrderCommand,
- SvgTextMergePropertiesRangeCommand
+ SvgTextMergePropertiesRangeCommand,
+ KoShapeMergeTextPropertiesCommandId
};
}
diff --git a/libs/flake/CMakeLists.txt b/libs/flake/CMakeLists.txt
index a41900be7c..d89c52db91 100644
--- a/libs/flake/CMakeLists.txt
+++ b/libs/flake/CMakeLists.txt
@@ -167,6 +167,7 @@ set(kritaflake_SRCS
commands/KoPathMergeUtils.cpp
commands/KoAddRemoveShapeCommands.cpp
commands/KoShapePaintOrderCommand.cpp
+ commands/KoShapeMergeTextPropertiesCommand.cpp
html/HtmlSavingContext.cpp
html/HtmlWriter.cpp
diff --git a/libs/flake/commands/KoShapeMergeTextPropertiesCommand.cpp b/libs/flake/commands/KoShapeMergeTextPropertiesCommand.cpp
new file mode 100644
index 0000000000..0c24101484
--- /dev/null
+++ b/libs/flake/commands/KoShapeMergeTextPropertiesCommand.cpp
@@ -0,0 +1,69 @@
+/*
+ * SPDX-FileCopyrightText: 2024 Wolthera van Hövell tot Westerflier <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#include "KoShapeMergeTextPropertiesCommand.h"
+
+#include <KoSvgTextShape.h>
+#include <KoSvgTextProperties.h>
+#include <kis_command_ids.h>
+
+struct KoShapeMergeTextPropertiesCommand::Private {
+ Private(const QList<KoShape*> &list) : shapes(list) { }
+ QList<KoShape *> shapes;
+ QMap<KoShape*, KoSvgTextShapeMementoSP> mementos;
+ KoSvgTextProperties newProperties;
+};
+
+KoShapeMergeTextPropertiesCommand::KoShapeMergeTextPropertiesCommand(const QList<KoShape *> &shapes, const KoSvgTextProperties &props, KUndo2Command *parent)
+ : KUndo2Command(parent),
+ d(new Private(shapes))
+{
+ d->newProperties = props;
+}
+
+void KoShapeMergeTextPropertiesCommand::redo()
+{
+ for(auto it = d->shapes.begin(); it!= d->shapes.end(); it++) {
+ KoSvgTextShape *shape = dynamic_cast<KoSvgTextShape*>(*it);
+ if (shape) {
+ d->mementos.insert(*it, shape->getMemento());
+ const QRectF oldDirtyRect = shape->boundingRect();
+ shape->mergePropertiesIntoRange(-1, -1, d->newProperties);
+ shape->updateAbsolute(oldDirtyRect | shape->boundingRect());
+ }
+ }
+}
+
+void KoShapeMergeTextPropertiesCommand::undo()
+{
+ for(auto it = d->shapes.begin(); it!= d->shapes.end(); it++) {
+ KoSvgTextShape *shape = dynamic_cast<KoSvgTextShape*>(*it);
+ if (shape && d->mementos.contains(*it)) {
+ const QRectF oldDirtyRect = shape->boundingRect();
+ shape->setMemento(d->mementos.value(*it));
+ shape->updateAbsolute(oldDirtyRect | shape->boundingRect());
+ }
+ }
+}
+
+int KoShapeMergeTextPropertiesCommand::id() const
+{
+ return KisCommandUtils::KoShapeMergeTextPropertiesCommandId;
+}
+
+bool KoShapeMergeTextPropertiesCommand::mergeWith(const KUndo2Command *other)
+{
+ const KoShapeMergeTextPropertiesCommand *command = dynamic_cast<const KoShapeMergeTextPropertiesCommand*>(other);
+
+ if (!command || command->d->shapes != d->shapes) {
+ return false;
+ }
+
+ Q_FOREACH(KoSvgTextProperties::PropertyId p, command->d->newProperties.properties()) {
+ d->newProperties.setProperty(p, command->d->newProperties.property(p));
+ }
+
+ return true;
+}
diff --git a/libs/flake/commands/KoShapeMergeTextPropertiesCommand.h b/libs/flake/commands/KoShapeMergeTextPropertiesCommand.h
new file mode 100644
index 0000000000..824333a1c7
--- /dev/null
+++ b/libs/flake/commands/KoShapeMergeTextPropertiesCommand.h
@@ -0,0 +1,31 @@
+/*
+ * SPDX-FileCopyrightText: 2024 Wolthera van Hövell tot Westerflier <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#ifndef KOMERGETEXTPROPERTIESINTOSHAPESCOMMAND_H
+#define KOMERGETEXTPROPERTIESINTOSHAPESCOMMAND_H
+
+#include "kritaflake_export.h"
+#include <kundo2command.h>
+
+class KoShape;
+class KoSvgTextProperties;
+
+class KRITAFLAKE_EXPORT KoShapeMergeTextPropertiesCommand : public KUndo2Command
+{
+public:
+ KoShapeMergeTextPropertiesCommand(const QList<KoShape*> &shapes, const KoSvgTextProperties &props, KUndo2Command *parent = nullptr);
+ ~KoShapeMergeTextPropertiesCommand() = default;
+
+ void redo() override;
+ void undo() override;
+
+ int id() const override;
+ bool mergeWith(const KUndo2Command *command) override;
+private:
+ class Private;
+ QScopedPointer<Private> d;
+};
+
+#endif // KOMERGETEXTPROPERTIESINTOSHAPESCOMMAND_H
diff --git a/libs/flake/text/KoSvgTextPropertyData.h b/libs/flake/text/KoSvgTextPropertyData.h
index 6949eacc20..1b20954b3a 100644
--- a/libs/flake/text/KoSvgTextPropertyData.h
+++ b/libs/flake/text/KoSvgTextPropertyData.h
@@ -34,7 +34,7 @@ struct KRITAFLAKE_EXPORT KoSvgTextPropertyData : public boost::equality_comparab
QSet<KoSvgTextProperties::PropertyId> tristate;
bool operator==(const KoSvgTextPropertyData &rhs) const {
- return commonProperties == rhs.commonProperties && tristate == rhs.tristate;
+ return commonProperties == rhs.commonProperties && inheritedProperties == rhs.inheritedProperties && tristate == rhs.tristate;
}
};
diff --git a/libs/flake/text/KoSvgTextShape.cpp b/libs/flake/text/KoSvgTextShape.cpp
index 009a33a015..f508bef04e 100644
--- a/libs/flake/text/KoSvgTextShape.cpp
+++ b/libs/flake/text/KoSvgTextShape.cpp
@@ -913,7 +913,9 @@ void KoSvgTextShape::mergePropertiesIntoRange(const int startPos, const int endP
{
if ((startPos < 0 && startPos == endPos) || d->cursorPos.isEmpty()) {
if (KisForestDetail::size(d->textData)) {
- d->textData.childBegin()->properties = properties;
+ Q_FOREACH(KoSvgTextProperties::PropertyId p, properties.properties()) {
+ d->textData.childBegin()->properties.setProperty(p, properties.property(p));
+ }
}
notifyChanged();
shapeChangedPriv(ContentChanged);
diff --git a/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp b/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp
index 41f81dcab1..5d7345ba66 100644
--- a/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp
+++ b/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp
@@ -31,6 +31,7 @@
#include <KoCanvasBase.h>
#include <KoCanvasResourceProvider.h>
#include <KoShapeRubberSelectStrategy.h>
+#include <KoSvgTextShape.h>
#include <commands/KoShapeMoveCommand.h>
#include <commands/KoShapeTransformCommand.h>
#include <commands/KoShapeDeleteCommand.h>
@@ -39,6 +40,7 @@
#include <commands/KoShapeUngroupCommand.h>
#include <commands/KoShapeDistributeCommand.h>
#include <commands/KoKeepShapesSelectedCommand.h>
+#include <commands/KoShapeMergeTextPropertiesCommand.h>
#include <KoSnapGuide.h>
#include <KoStrokeConfigWidget.h>
#include "kis_action_registry.h"
@@ -47,6 +49,7 @@
#include "KisViewManager.h"
#include "kis_canvas2.h"
#include "kis_canvas_resource_provider.h"
+#include "KisTextPropertiesManager.h"
#include <KoInteractionStrategyFactory.h>
#include "kis_document_aware_spin_box_unit_manager.h"
@@ -414,6 +417,7 @@ DefaultTool::DefaultTool(KoCanvasBase *canvas, bool connectToSelectedShapesProxy
, m_mouseWasInsideHandles(false)
, m_selectionHandler(new SelectionHandler(this))
, m_tabbedOptionWidget(0)
+ , m_textPropertyInterface(new DefaultToolTextPropertiesInterface(this))
{
setupActions();
@@ -462,6 +466,7 @@ DefaultTool::DefaultTool(KoCanvasBase *canvas, bool connectToSelectedShapesProxy
connect(canvas->selectedShapesProxy(), SIGNAL(selectionChanged()), this, SLOT(updateActions()));
connect(canvas->selectedShapesProxy(), SIGNAL(selectionChanged()), this, SLOT(repaintDecorations()));
+ connect(canvas->selectedShapesProxy(), SIGNAL(selectionChanged()), m_textPropertyInterface, SIGNAL(textSelectionChanged()));
connect(canvas->selectedShapesProxy(), SIGNAL(selectionContentChanged()), this, SLOT(repaintDecorations()));
}
}
@@ -1195,6 +1200,11 @@ void DefaultTool::activate(const QSet<KoShape *> &shapes)
repaintDecorations();
updateActions();
+ const KisCanvas2 *canvas2 = qobject_cast<const KisCanvas2 *>(this->canvas());
+ if (canvas2) {
+ canvas2->viewManager()->textPropertyManager()->setTextPropertiesInterface(m_textPropertyInterface);
+ }
+
if (m_tabbedOptionWidget) {
m_tabbedOptionWidget->activate();
}
@@ -1230,6 +1240,10 @@ void DefaultTool::deactivate()
disconnect(m_transformSignalsMapper, 0, this, 0);
disconnect(m_booleanSignalsMapper, 0, this, 0);
+ const KisCanvas2 *canvas2 = qobject_cast<const KisCanvas2 *>(this->canvas());
+ if (canvas2) {
+ canvas2->viewManager()->textPropertyManager()->setTextPropertiesInterface(nullptr);
+ }
if (m_tabbedOptionWidget) {
m_tabbedOptionWidget->deactivate();
@@ -1914,3 +1928,41 @@ void DefaultTool::explicitUserStrokeEndRequest()
KoToolManager::instance()->switchToolRequested(tool);
});
}
+
+DefaultToolTextPropertiesInterface::DefaultToolTextPropertiesInterface(DefaultTool *parent)
+ : KoSvgTextPropertiesInterface(parent)
+ , m_parent(parent)
+{
+
+}
+
+QList<KoSvgTextProperties> DefaultToolTextPropertiesInterface::getSelectedProperties()
+{
+ QList<KoSvgTextProperties> props = QList<KoSvgTextProperties>();
+ if (!m_parent->selection()->hasSelection()) return props;
+
+ QList<KoShape*> shapes = m_parent->canvas()->selectedShapesProxy()->selection()->selectedShapes();
+ 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);
+ }
+
+ return props;
+}
+
+KoSvgTextProperties DefaultToolTextPropertiesInterface::getInheritedProperties()
+{
+ return KoSvgTextProperties::defaultProperties();
+}
+
+void DefaultToolTextPropertiesInterface::setPropertiesOnSelected(KoSvgTextProperties properties)
+{
+ QList<KoShape*> shapes = m_parent->canvas()->selectedShapesProxy()->selection()->selectedShapes();
+ if (shapes.isEmpty()) return;
+ KUndo2Command *cmd = new KoShapeMergeTextPropertiesCommand(shapes, properties);
+ if (cmd) {
+ m_parent->canvas()->addCommand(cmd);
+ }
+}
diff --git a/plugins/tools/defaulttool/defaulttool/DefaultTool.h b/plugins/tools/defaulttool/defaulttool/DefaultTool.h
index 795f12fdbc..9b36f67969 100644
--- a/plugins/tools/defaulttool/defaulttool/DefaultTool.h
+++ b/plugins/tools/defaulttool/defaulttool/DefaultTool.h
@@ -15,6 +15,7 @@
#include <commands/KoShapeReorderCommand.h>
#include "SelectionDecorator.h"
#include "KoShapeMeshGradientHandles.h"
+#include <KoSvgTextPropertiesInterface.h>
#include <QPolygonF>
#include <QTime>
@@ -25,6 +26,7 @@ class KoShapeMoveCommand;
class KoSelection;
class DefaultToolTabbedWidget;
class KisViewManager;
+class DefaultToolTextPropertiesInterface;
/**
* The default tool (associated with the arrow icon) implements the default
@@ -198,6 +200,19 @@ private:
KisSignalMapper *m_distributeSignalsMapper {0};
KisSignalMapper *m_transformSignalsMapper {0};
KisSignalMapper *m_booleanSignalsMapper {0};
+
+ DefaultToolTextPropertiesInterface *m_textPropertyInterface{0};
+};
+
+class DefaultToolTextPropertiesInterface: public KoSvgTextPropertiesInterface
+{
+public:
+ DefaultToolTextPropertiesInterface(DefaultTool *parent);
+ virtual QList<KoSvgTextProperties> getSelectedProperties() override;
+ virtual KoSvgTextProperties getInheritedProperties() override;
+ virtual void setPropertiesOnSelected(KoSvgTextProperties properties) override;
+private:
+ DefaultTool *m_parent{nullptr};
};