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++
Fix some issues with selected shapes and the interfaces.
Wolthera van Hövell tot Westerflieref63b3d828f2
diff --git a/libs/flake/commands/KoShapeMergeTextPropertiesCommand.cpp b/libs/flake/commands/KoShapeMergeTextPropertiesCommand.cppindex b40ccc046a..a4190467c6 100644--- a/libs/flake/commands/KoShapeMergeTextPropertiesCommand.cpp+++ b/libs/flake/commands/KoShapeMergeTextPropertiesCommand.cpp@@ -22,6 +22,7 @@ KoShapeMergeTextPropertiesCommand::KoShapeMergeTextPropertiesCommand(const QList: KUndo2Command(parent),d(new Private(shapes)){+ setText(kundo2_i18n("Change Text Shape Properties"));d->newProperties = props;d->removeProperties = removeProperties;}diff --git a/libs/flake/commands/KoShapeMergeTextPropertiesCommand.h b/libs/flake/commands/KoShapeMergeTextPropertiesCommand.hindex a55d19b1fe..80e7cd979a 100644--- a/libs/flake/commands/KoShapeMergeTextPropertiesCommand.h+++ b/libs/flake/commands/KoShapeMergeTextPropertiesCommand.h@@ -13,6 +13,11 @@class KoShape;class KoSvgTextProperties;+/**+ * @brief The KoShapeMergeTextPropertiesCommand class+ * This sets text properties on given text shapes. For setting text+ * on range, see SvgTextMergePropertiesRangeCommand.+ */class KRITAFLAKE_EXPORT KoShapeMergeTextPropertiesCommand : public KUndo2Command{public:diff --git a/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp b/plugins/tools/defaulttool/defaulttool/DefaultTool.cppindex 7329bdae78..6937f111b7 100644--- a/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp+++ b/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp@@ -1203,6 +1203,7 @@ void DefaultTool::activate(const QSet<KoShape *> &shapes)const KisCanvas2 *canvas2 = qobject_cast<const KisCanvas2 *>(this->canvas());if (canvas2) {canvas2->viewManager()->textPropertyManager()->setTextPropertiesInterface(m_textPropertyInterface);+ m_textPropertyInterface->slotSelectionChanged();}if (m_tabbedOptionWidget) {@@ -1243,6 +1244,7 @@ void DefaultTool::deactivate()const KisCanvas2 *canvas2 = qobject_cast<const KisCanvas2 *>(this->canvas());if (canvas2) {canvas2->viewManager()->textPropertyManager()->setTextPropertiesInterface(nullptr);+ m_textPropertyInterface->clearSelection();}if (m_tabbedOptionWidget) {@@ -1946,7 +1948,7 @@ DefaultToolTextPropertiesInterface::DefaultToolTextPropertiesInterface(DefaultToDefaultToolTextPropertiesInterface::~DefaultToolTextPropertiesInterface(){-+ clearSelection();}QList<KoSvgTextProperties> DefaultToolTextPropertiesInterface::getSelectedProperties()@@ -1954,8 +1956,7 @@ QList<KoSvgTextProperties> DefaultToolTextPropertiesInterface::getSelectedProperQList<KoSvgTextProperties> props = QList<KoSvgTextProperties>();if (!d->parent->selection()->hasSelection()) return props;- QList<KoShape*> shapes = d->parent->canvas()->selectedShapesProxy()->selection()->selectedShapes();- for (auto it = shapes.begin(); it != shapes.end(); it++) {+ for (auto it = d->shapes.begin(); it != d->shapes.end(); it++) {KoSvgTextShape *textShape = dynamic_cast<KoSvgTextShape*>(*it);if (!textShape) continue;KoSvgTextProperties p = textShape->textProperties();@@ -1972,9 +1973,8 @@ KoSvgTextProperties DefaultToolTextPropertiesInterface::getInheritedProperties()void DefaultToolTextPropertiesInterface::setPropertiesOnSelected(KoSvgTextProperties properties, QSet<KoSvgTextProperties::PropertyId> removeProperties){- QList<KoShape*> shapes = d->parent->canvas()->selectedShapesProxy()->selection()->selectedShapes();- if (shapes.isEmpty()) return;- KUndo2Command *cmd = new KoShapeMergeTextPropertiesCommand(shapes, properties, removeProperties);+ if (d->shapes.isEmpty()) return;+ KUndo2Command *cmd = new KoShapeMergeTextPropertiesCommand(d->shapes, properties, removeProperties);if (cmd) {d->parent->canvas()->addCommand(cmd);}@@ -2004,13 +2004,20 @@ void DefaultToolTextPropertiesInterface::notifyShapeChanged(KoShape::ChangeTypeemit textSelectionChanged();}-void DefaultToolTextPropertiesInterface::slotSelectionChanged()+void DefaultToolTextPropertiesInterface::clearSelection(){- QList<KoShape*> shapes = d->parent->canvas()->selectedShapesProxy()->selection()->selectedShapes();Q_FOREACH(KoShape *shape, d->shapes) {shape->removeShapeChangeListener(this);}+ d->shapes.clear();+}+void DefaultToolTextPropertiesInterface::slotSelectionChanged()+{+ Q_FOREACH(KoShape *shape, d->shapes) {+ shape->removeShapeChangeListener(this);+ }+ QList<KoShape*> shapes = d->parent->canvas()->selectedShapesProxy()->selection()->selectedEditableShapes();d->shapes = shapes;Q_FOREACH(KoShape *shape, d->shapes) {diff --git a/plugins/tools/defaulttool/defaulttool/DefaultTool.h b/plugins/tools/defaulttool/defaulttool/DefaultTool.hindex a89c11b42a..1ec9fccb4a 100644--- a/plugins/tools/defaulttool/defaulttool/DefaultTool.h+++ b/plugins/tools/defaulttool/defaulttool/DefaultTool.h@@ -206,6 +206,7 @@ private:#include <KoSvgTextShape.h>+/// Interface to interact with the text property manager.class DefaultToolTextPropertiesInterface: public KoSvgTextPropertiesInterface, public KoSvgTextShape::TextCursorChangeListener{Q_OBJECT@@ -220,6 +221,8 @@ public:virtual void notifyCursorPosChanged(int pos, int anchor) override;virtual void notifyMarkupChanged() override;virtual void notifyShapeChanged(KoShape::ChangeType type, KoShape *shape) override;++ void clearSelection();public Q_SLOTS:void slotSelectionChanged();private:diff --git a/plugins/tools/svgtexttool/SvgTextCursor.cpp b/plugins/tools/svgtexttool/SvgTextCursor.cppindex c9bca772d9..1bc54a4462 100644--- a/plugins/tools/svgtexttool/SvgTextCursor.cpp+++ b/plugins/tools/svgtexttool/SvgTextCursor.cpp@@ -135,7 +135,7 @@ struct Q_DECL_HIDDEN SvgTextCursor::Private {QRectF oldIMEDecorationRect; ///< Update Rectangle of previous decoration.bool blockQueryUpdates = false; ///< Block qApp->inputMethod->update(), enabled during the inputmethod event flow.- SvgTextPropertyCursor *interface{nullptr};+ SvgTextCursorPropertyInterface *interface{nullptr};};SvgTextCursor::SvgTextCursor(KoCanvasBase *canvas) :@@ -148,7 +148,7 @@ SvgTextCursor::SvgTextCursor(KoCanvasBase *canvas) :connect(d->canvas->resourceManager(), SIGNAL(canvasResourceChanged(int,QVariant)),this, SLOT(canvasResourceChanged(int,QVariant)));}- d->interface = new SvgTextPropertyCursor(this);+ d->interface = new SvgTextCursorPropertyInterface(this);}SvgTextCursor::~SvgTextCursor()@@ -1432,44 +1432,44 @@ void SvgTextCursor::updateCanvasResources()}}-struct SvgTextPropertyCursor::Private {+struct SvgTextCursorPropertyInterface::Private {Private(SvgTextCursor *parent): parent(parent) {}SvgTextCursor *parent{nullptr};};-SvgTextPropertyCursor::SvgTextPropertyCursor(SvgTextCursor *parent)+SvgTextCursorPropertyInterface::SvgTextCursorPropertyInterface(SvgTextCursor *parent): KoSvgTextPropertiesInterface(parent), d(new Private(parent)){}-SvgTextPropertyCursor::~SvgTextPropertyCursor()+SvgTextCursorPropertyInterface::~SvgTextCursorPropertyInterface(){}-QList<KoSvgTextProperties> SvgTextPropertyCursor::getSelectedProperties()+QList<KoSvgTextProperties> SvgTextCursorPropertyInterface::getSelectedProperties(){return d->parent->propertiesForRange();}-KoSvgTextProperties SvgTextPropertyCursor::getInheritedProperties()+KoSvgTextProperties SvgTextCursorPropertyInterface::getInheritedProperties(){// 9 times out of 10 this is correct, though we could do better by actually// getting inherited properties for the range and not just defaulting to the paragraph.return (d->parent->shape() && spanSelection())? d->parent->shape()->textProperties(): KoSvgTextProperties();}-void SvgTextPropertyCursor::setPropertiesOnSelected(KoSvgTextProperties properties, QSet<KoSvgTextProperties::PropertyId> removeProperties)+void SvgTextCursorPropertyInterface::setPropertiesOnSelected(KoSvgTextProperties properties, QSet<KoSvgTextProperties::PropertyId> removeProperties){d->parent->mergePropertiesIntoSelection(properties, removeProperties);}-bool SvgTextPropertyCursor::spanSelection()+bool SvgTextCursorPropertyInterface::spanSelection(){return d->parent->hasSelection();}-void SvgTextPropertyCursor::emitSelectionChange()+void SvgTextCursorPropertyInterface::emitSelectionChange(){emit textSelectionChanged();}diff --git a/plugins/tools/svgtexttool/SvgTextCursor.h b/plugins/tools/svgtexttool/SvgTextCursor.hindex cfb0f4c85b..1f31ea9636 100644--- a/plugins/tools/svgtexttool/SvgTextCursor.h+++ b/plugins/tools/svgtexttool/SvgTextCursor.h@@ -227,11 +227,12 @@ private:const QScopedPointer<Private> d;};-class KRITATOOLSVGTEXT_EXPORT SvgTextPropertyCursor : public KoSvgTextPropertiesInterface+/// Interface to interact with the text property manager.+class KRITATOOLSVGTEXT_EXPORT SvgTextCursorPropertyInterface : public KoSvgTextPropertiesInterface{public:- SvgTextPropertyCursor(SvgTextCursor *parent);- ~SvgTextPropertyCursor();+ SvgTextCursorPropertyInterface(SvgTextCursor *parent);+ ~SvgTextCursorPropertyInterface();virtual QList<KoSvgTextProperties> getSelectedProperties() override;virtual KoSvgTextProperties getInheritedProperties() override;virtual void setPropertiesOnSelected(KoSvgTextProperties properties, QSet<KoSvgTextProperties::PropertyId> removeProperties = QSet<KoSvgTextProperties::PropertyId>()) override;diff --git a/plugins/tools/svgtexttool/SvgTextMergePropertiesRangeCommand.h b/plugins/tools/svgtexttool/SvgTextMergePropertiesRangeCommand.hindex 06339e3ef2..ea1a965545 100644--- a/plugins/tools/svgtexttool/SvgTextMergePropertiesRangeCommand.h+++ b/plugins/tools/svgtexttool/SvgTextMergePropertiesRangeCommand.h@@ -15,6 +15,12 @@class KoSvgTextShape;class KoSvgTextProperties;+/**+ * @brief The SvgTextMergePropertiesRangeCommand class+ * This sets properties on a specific range in a single text shape.+ *+ * For setting text on multiple shapes, see KoShapeMergeTextPropertiesCommand+ */class KRITATOOLSVGTEXT_EXPORT SvgTextMergePropertiesRangeCommand : public KUndo2Command{public:diff --git a/plugins/tools/svgtexttool/SvgTextTool.cpp b/plugins/tools/svgtexttool/SvgTextTool.cppindex 899f1f6764..a7ec9e7860 100644--- a/plugins/tools/svgtexttool/SvgTextTool.cpp+++ b/plugins/tools/svgtexttool/SvgTextTool.cpp@@ -132,6 +132,7 @@ void SvgTextTool::deactivate()if (canvas2) {canvas2->viewManager()->textPropertyManager()->setTextPropertiesInterface(nullptr);}+ m_textCursor.setShape(nullptr);m_hoveredShapeHighlightRect = QPainterPath();@@ -388,9 +389,9 @@ void SvgTextTool::storeDefaults()void SvgTextTool::slotShapeSelectionChanged(){- QList<KoShape *> shapes = koSelection()->selectedShapes();+ QList<KoShape *> shapes = koSelection()->selectedEditableShapes();if (shapes.size() == 1) {- KoSvgTextShape *textShape = dynamic_cast<KoSvgTextShape*>(*shapes.constBegin());+ KoSvgTextShape *textShape = selectedShape();if (!textShape) {koSelection()->deselectAll();return;