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

Fix copy-pasting of shapes between vector layers and selections

Dmitry Kazakov5d08fd57d0f8
diff --git a/libs/ui/flake/kis_shape_controller.cpp b/libs/ui/flake/kis_shape_controller.cpp
index d5b61597a1..df5a5a52e1 100644
--- a/libs/ui/flake/kis_shape_controller.cpp
+++ b/libs/ui/flake/kis_shape_controller.cpp
@@ -38,6 +38,8 @@
#include "kis_shape_layer.h"
#include "KisViewManager.h"
#include "kis_node.h"
+#include <kis_selection_mask.h>
+#include <KoShapeStroke.h>
#include <KoDocumentResourceManager.h>
#include <commands/kis_image_layer_add_command.h>
@@ -173,20 +175,57 @@ KoShapeContainer *KisShapeController::createParentForShapes(const QList<KoShape
KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(!baseBelongsToSelection || allSameBelongsToShapeSelection, resultParent);
+ KisSelectionSP parentSelection;
+
if (baseBelongsToSelection && allSameBelongsToShapeSelection) {
- KisSelectionSP selection = canvas->viewManager()->selection();
- if (selection) {
- KisSelectionComponent* shapeSelectionComponent = selection->shapeSelection();
+ parentSelection = canvas->viewManager()->selection(); // TODO: fix logic
+ }
- if (!shapeSelectionComponent) {
- shapeSelectionComponent = new KisShapeSelection(this, selection);
- resultCommand->addCommand(selection->convertToVectorSelection(shapeSelectionComponent));
+ if (KisNodeSP activeNode = canvas->viewManager()->activeNode()) {
+ if (KisSelectionMask *selectionMask = qobject_cast<KisSelectionMask *>(activeNode.data())) {
+ if (KisSelectionSP selection = selectionMask->selection()) {
+ parentSelection = selection;
}
+ }
+ }
+
+ if (parentSelection) {
+ KisSelectionComponent *shapeSelectionComponent = parentSelection->shapeSelection();
- KisShapeSelection * shapeSelection = static_cast<KisShapeSelection*>(shapeSelectionComponent);
- resultParent = shapeSelection;
+ Q_FOREACH (KoShape *shape, shapes) {
+ if (!belongsToShapeSelection(shape)) {
+ shape->setUserData(new KisShapeSelectionMarker);
+ }
+ }
+
+ if (!shapeSelectionComponent) {
+ shapeSelectionComponent = new KisShapeSelection(this, parentSelection);
+ resultCommand->addCommand(parentSelection->convertToVectorSelection(shapeSelectionComponent));
}
- } else {
+
+ KisShapeSelection *shapeSelection = static_cast<KisShapeSelection *>(shapeSelectionComponent);
+ resultParent = shapeSelection;
+ }
+
+ if (!resultParent) {
+ Q_FOREACH (KoShape *shape, shapes) {
+ if (belongsToShapeSelection(shape)) {
+ shape->setUserData(nullptr);
+ }
+
+ /**
+ * We should try to avoid pasting fully invisible shapes, add some
+ * default stroke to them.
+ *
+ * Such shapes may be appear when pasting a shape from a vector selection
+ * to a normal layer
+ */
+ if ((!shape->stroke() || !shape->stroke()->isVisible()) && !shape->background()) {
+ shape->setStroke(toQShared(new KoShapeStroke(1, Qt::black)));
+ }
+ }
+
+
KisShapeLayer *shapeLayer =
dynamic_cast<KisShapeLayer*>(
canvas->selectedShapesProxy()->selection()->activeLayer());
diff --git a/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp b/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp
index ec4c9156f9..a52938be38 100644
--- a/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp
+++ b/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp
@@ -406,20 +406,20 @@ class SelectionHandler : public KoToolSelection
public:
SelectionHandler(DefaultTool *parent)
: KoToolSelection(parent)
- , m_selection(parent->koSelection())
+ , m_parent(parent)
{
}
- bool hasSelection() override
- {
- if (m_selection) {
- return m_selection->count();
+ bool hasSelection() override {
+ KoSelection *selection = m_parent->koSelection();
+ if (selection) {
+ return selection->count() > 0;
}
return false;
}
private:
- QPointer<KoSelection> m_selection;
+ DefaultTool *m_parent;
};
DefaultTool::DefaultTool(KoCanvasBase *canvas, bool connectToSelectedShapesProxy)