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 the text properties interface in the default tool also a shape change listener.
Wolthera van Hövell tot Westerflier8e9afb35d2c3
diff --git a/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp b/plugins/tools/defaulttool/defaulttool/DefaultTool.cppindex 47ca40841f..87e950bc23 100644--- a/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp+++ b/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp@@ -466,7 +466,7 @@ DefaultTool::DefaultTool(KoCanvasBase *canvas, bool connectToSelectedShapesProxyconnect(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(selectionChanged()), m_textPropertyInterface, SLOT(slotSelectionChanged()));connect(canvas->selectedShapesProxy(), SIGNAL(selectionContentChanged()), this, SLOT(repaintDecorations()));}}@@ -1929,9 +1929,22 @@ void DefaultTool::explicitUserStrokeEndRequest()});}+struct Q_DECL_HIDDEN DefaultToolTextPropertiesInterface::Private {++ Private(DefaultTool *parent): parent(parent) {}++ DefaultTool *parent;+ QList<KoShape*> shapes;+};+DefaultToolTextPropertiesInterface::DefaultToolTextPropertiesInterface(DefaultTool *parent): KoSvgTextPropertiesInterface(parent)- , m_parent(parent)+ , d(new Private(parent))+{++}++DefaultToolTextPropertiesInterface::~DefaultToolTextPropertiesInterface(){}@@ -1939,9 +1952,9 @@ DefaultToolTextPropertiesInterface::DefaultToolTextPropertiesInterface(DefaultToQList<KoSvgTextProperties> DefaultToolTextPropertiesInterface::getSelectedProperties(){QList<KoSvgTextProperties> props = QList<KoSvgTextProperties>();- if (!m_parent->selection()->hasSelection()) return props;+ if (!d->parent->selection()->hasSelection()) return props;- QList<KoShape*> shapes = m_parent->canvas()->selectedShapesProxy()->selection()->selectedShapes();+ QList<KoShape*> shapes = d->parent->canvas()->selectedShapesProxy()->selection()->selectedShapes();for (auto it = shapes.begin(); it != shapes.end(); it++) {KoSvgTextShape *textShape = dynamic_cast<KoSvgTextShape*>(*it);if (!textShape) continue;@@ -1959,10 +1972,44 @@ KoSvgTextProperties DefaultToolTextPropertiesInterface::getInheritedProperties()void DefaultToolTextPropertiesInterface::setPropertiesOnSelected(KoSvgTextProperties properties, QSet<KoSvgTextProperties::PropertyId> removeProperties){- QList<KoShape*> shapes = m_parent->canvas()->selectedShapesProxy()->selection()->selectedShapes();+ QList<KoShape*> shapes = d->parent->canvas()->selectedShapesProxy()->selection()->selectedShapes();if (shapes.isEmpty()) return;KUndo2Command *cmd = new KoShapeMergeTextPropertiesCommand(shapes, properties, removeProperties);if (cmd) {- m_parent->canvas()->addCommand(cmd);+ d->parent->canvas()->addCommand(cmd);+ }+}++void DefaultToolTextPropertiesInterface::notifyCursorPosChanged(int pos, int anchor)+{+ emit textSelectionChanged();+}++void DefaultToolTextPropertiesInterface::notifyMarkupChanged()+{+ emit textSelectionChanged();+}++void DefaultToolTextPropertiesInterface::notifyShapeChanged(KoShape::ChangeType type, KoShape *shape)+{+ emit textSelectionChanged();+}++void DefaultToolTextPropertiesInterface::slotSelectionChanged()+{+ if (!d->shapes.isEmpty()) {+ for (int i = 0; i< d->shapes.size(); i++) {+ KoShape *shape = d->shapes.takeFirst();+ shape->removeShapeChangeListener(this);+ }+ }+ QList<KoShape*> shapes = d->parent->canvas()->selectedShapesProxy()->selection()->selectedShapes();+ if (!shapes.isEmpty()) {+ for (int i = 0; i< shapes.size(); i++) {+ KoShape *shape = shapes.takeFirst();+ shape->addShapeChangeListener(this);+ d->shapes.append(shape);+ }}+ emit textSelectionChanged();}diff --git a/plugins/tools/defaulttool/defaulttool/DefaultTool.h b/plugins/tools/defaulttool/defaulttool/DefaultTool.hindex 75ac6bec68..88e03fa78b 100644--- a/plugins/tools/defaulttool/defaulttool/DefaultTool.h+++ b/plugins/tools/defaulttool/defaulttool/DefaultTool.h@@ -204,15 +204,26 @@ private:DefaultToolTextPropertiesInterface *m_textPropertyInterface{0};};-class DefaultToolTextPropertiesInterface: public KoSvgTextPropertiesInterface+#include <KoSvgTextShape.h>++class DefaultToolTextPropertiesInterface: public KoSvgTextPropertiesInterface, public KoSvgTextShape::TextCursorChangeListener{+ Q_OBJECTpublic:DefaultToolTextPropertiesInterface(DefaultTool *parent);+ ~DefaultToolTextPropertiesInterface();virtual QList<KoSvgTextProperties> getSelectedProperties() override;virtual KoSvgTextProperties getInheritedProperties() override;virtual void setPropertiesOnSelected(KoSvgTextProperties properties, QSet<KoSvgTextProperties::PropertyId> removeProperties = QSet<KoSvgTextProperties::PropertyId>()) override;++ virtual void notifyCursorPosChanged(int pos, int anchor) override;+ virtual void notifyMarkupChanged() override;+ virtual void notifyShapeChanged(KoShape::ChangeType type, KoShape *shape) override;+public Q_SLOTS:+ void slotSelectionChanged();private:- DefaultTool *m_parent{nullptr};+ struct Private;+ const QScopedPointer<Private> d;};