[krita] /: Implement boolean modes for **vector** selection tools
Dmitry Kazakov
null at kde.org
Sun Sep 2 22:07:35 BST 2018
Git commit fc5a91d946c738f7d6fc4011aafcc73a9f91b3b1 by Dmitry Kazakov.
Committed on 02/09/2018 at 21:07.
Pushed by dkazakov into branch 'master'.
Implement boolean modes for **vector** selection tools
Now one can choose Replace/Add/Subtract/Intersect modes when
creating vector selections with standard tools. Previously, only
pixel selection tools supported that
Ref T9486
CC:kimageshop at kde.org
M +73 -13 libs/ui/tool/kis_selection_tool_helper.cpp
M +2 -2 libs/ui/tool/kis_selection_tool_helper.h
M +1 -6 libs/ui/widgets/kis_selection_options.cc
M +1 -1 plugins/tools/selectiontools/kis_tool_select_elliptical.cc
M +1 -1 plugins/tools/selectiontools/kis_tool_select_outline.cc
M +1 -1 plugins/tools/selectiontools/kis_tool_select_path.cc
M +1 -1 plugins/tools/selectiontools/kis_tool_select_polygonal.cc
M +2 -1 plugins/tools/selectiontools/kis_tool_select_rectangular.cc
https://commits.kde.org/krita/fc5a91d946c738f7d6fc4011aafcc73a9f91b3b1
diff --git a/libs/ui/tool/kis_selection_tool_helper.cpp b/libs/ui/tool/kis_selection_tool_helper.cpp
index 696ae1d8dbd..dab79c1e49c 100644
--- a/libs/ui/tool/kis_selection_tool_helper.cpp
+++ b/libs/ui/tool/kis_selection_tool_helper.cpp
@@ -135,14 +135,14 @@ void KisSelectionToolHelper::selectPixelSelection(KisPixelSelectionSP selection,
applicator.end();
}
-void KisSelectionToolHelper::addSelectionShape(KoShape* shape)
+void KisSelectionToolHelper::addSelectionShape(KoShape* shape, SelectionAction action)
{
QList<KoShape*> shapes;
shapes.append(shape);
- addSelectionShapes(shapes);
+ addSelectionShapes(shapes, action);
}
-void KisSelectionToolHelper::addSelectionShapes(QList< KoShape* > shapes)
+void KisSelectionToolHelper::addSelectionShapes(QList< KoShape* > shapes, SelectionAction action)
{
KisViewManager* view = m_canvas->viewManager();
@@ -177,29 +177,89 @@ void KisSelectionToolHelper::addSelectionShapes(QList< KoShape* > shapes)
}
};
- applicator.applyCommand(new ClearPixelSelection(view));
+ if (action == SELECTION_REPLACE || action == SELECTION_DEFAULT) {
+ applicator.applyCommand(new ClearPixelSelection(view));
+ }
struct AddSelectionShape : public KisTransactionBasedCommand {
- AddSelectionShape(KisViewManager *view, KoShape* shape) : m_view(view),
- m_shape(shape) {}
+ AddSelectionShape(KisViewManager *view, KoShape* shape, SelectionAction action)
+ : m_view(view),
+ m_shape(shape),
+ m_action(action) {}
+
KisViewManager *m_view;
KoShape* m_shape;
+ SelectionAction m_action;
KUndo2Command* paint() override {
- /**
- * Mark a shape that it belongs to a shape selection
- */
- if(!m_shape->userData()) {
- m_shape->setUserData(new KisShapeSelectionMarker);
+ KUndo2Command *resultCommand = 0;
+
+
+ KisSelectionSP selection = m_view->selection();
+ if (selection) {
+ KisShapeSelection * shapeSelection = static_cast<KisShapeSelection*>(selection->shapeSelection());
+
+ if (shapeSelection) {
+ QList<KoShape*> existingShapes = shapeSelection->shapes();
+
+ if (existingShapes.size() == 1) {
+ KoShape *currentShape = existingShapes.first();
+ QPainterPath path1 = currentShape->absoluteTransformation(0).map(currentShape->outline());
+ QPainterPath path2 = m_shape->absoluteTransformation(0).map(m_shape->outline());
+
+ QPainterPath path = path2;
+
+ switch (m_action) {
+ case SELECTION_DEFAULT:
+ case SELECTION_REPLACE:
+ path = path2;
+ break;
+
+ case SELECTION_INTERSECT:
+ path = path1 & path2;
+ break;
+
+ case SELECTION_ADD:
+ path = path1 | path2;
+ break;
+
+ case SELECTION_SUBTRACT:
+ path = path1 - path2;
+ break;
+ }
+
+ KoShape *newShape = KoPathShape::createShapeFromPainterPath(path);
+ newShape->setUserData(new KisShapeSelectionMarker);
+
+ KUndo2Command *parentCommand = new KUndo2Command();
+
+ m_view->canvasBase()->shapeController()->removeShape(currentShape, parentCommand);
+ m_view->canvasBase()->shapeController()->addShape(newShape, 0, parentCommand);
+
+ resultCommand = parentCommand;
+ }
+ }
+ }
+
+
+ if (!resultCommand) {
+ /**
+ * Mark a shape that it belongs to a shape selection
+ */
+ if(!m_shape->userData()) {
+ m_shape->setUserData(new KisShapeSelectionMarker);
+ }
+
+ resultCommand = m_view->canvasBase()->shapeController()->addShape(m_shape, 0);
}
- return m_view->canvasBase()->shapeController()->addShape(m_shape, 0);
+ return resultCommand;
}
};
Q_FOREACH (KoShape* shape, shapes) {
applicator.applyCommand(
- new KisGuiContextCommand(new AddSelectionShape(view, shape), view));
+ new KisGuiContextCommand(new AddSelectionShape(view, shape, action), view));
}
applicator.end();
}
diff --git a/libs/ui/tool/kis_selection_tool_helper.h b/libs/ui/tool/kis_selection_tool_helper.h
index 92500f70e02..280775549df 100644
--- a/libs/ui/tool/kis_selection_tool_helper.h
+++ b/libs/ui/tool/kis_selection_tool_helper.h
@@ -40,8 +40,8 @@ public:
virtual ~KisSelectionToolHelper();
void selectPixelSelection(KisPixelSelectionSP selection, SelectionAction action);
- void addSelectionShape(KoShape* shape);
- void addSelectionShapes(QList<KoShape*> shapes);
+ void addSelectionShape(KoShape* shape, SelectionAction action = SELECTION_DEFAULT);
+ void addSelectionShapes(QList<KoShape*> shapes, SelectionAction action = SELECTION_DEFAULT);
bool canShortcutToDeselect(const QRect &rect, SelectionAction action);
bool canShortcutToNoop(const QRect &rect, SelectionAction action);
diff --git a/libs/ui/widgets/kis_selection_options.cc b/libs/ui/widgets/kis_selection_options.cc
index 0bedb0b242e..995c15ef568 100644
--- a/libs/ui/widgets/kis_selection_options.cc
+++ b/libs/ui/widgets/kis_selection_options.cc
@@ -98,13 +98,8 @@ void KisSelectionOptions::setMode(int mode) {
//hide action buttons and antialiasing, if shape selection is active (actions currently don't work on shape selection)
void KisSelectionOptions::hideActionsForSelectionMode(int mode) {
- bool isPixelSelection = (mode == (int)PIXEL_SELECTION);
+ const bool isPixelSelection = (mode == (int)PIXEL_SELECTION);
- m_page->lblAction->setVisible(isPixelSelection);
- m_page->add->setVisible(isPixelSelection);
- m_page->subtract->setVisible(isPixelSelection);
- m_page->replace->setVisible(isPixelSelection);
- m_page->intersect->setVisible(isPixelSelection);
m_page->chkAntiAliasing->setVisible(isPixelSelection);
}
diff --git a/plugins/tools/selectiontools/kis_tool_select_elliptical.cc b/plugins/tools/selectiontools/kis_tool_select_elliptical.cc
index d925bfe624f..251a039c3a4 100644
--- a/plugins/tools/selectiontools/kis_tool_select_elliptical.cc
+++ b/plugins/tools/selectiontools/kis_tool_select_elliptical.cc
@@ -75,7 +75,7 @@ void __KisToolSelectEllipticalLocal::finishRect(const QRectF &rect, qreal roundC
QRectF ptRect = convertToPt(rect);
KoShape* shape = KisShapeToolHelper::createEllipseShape(ptRect);
- helper.addSelectionShape(shape);
+ helper.addSelectionShape(shape, selectionAction());
}
}
diff --git a/plugins/tools/selectiontools/kis_tool_select_outline.cc b/plugins/tools/selectiontools/kis_tool_select_outline.cc
index 9bd049a44e8..03f863e41ea 100644
--- a/plugins/tools/selectiontools/kis_tool_select_outline.cc
+++ b/plugins/tools/selectiontools/kis_tool_select_outline.cc
@@ -196,7 +196,7 @@ void KisToolSelectOutline::finishSelectionAction()
path->close();
path->normalize();
- helper.addSelectionShape(path);
+ helper.addSelectionShape(path, selectionAction());
}
QApplication::restoreOverrideCursor();
}
diff --git a/plugins/tools/selectiontools/kis_tool_select_path.cc b/plugins/tools/selectiontools/kis_tool_select_path.cc
index bdb93facd9a..d969ef29826 100644
--- a/plugins/tools/selectiontools/kis_tool_select_path.cc
+++ b/plugins/tools/selectiontools/kis_tool_select_path.cc
@@ -157,7 +157,7 @@ void __KisToolSelectPathLocalTool::addPathShape(KoPathShape* pathShape)
delete pathShape;
} else {
- helper.addSelectionShape(pathShape);
+ helper.addSelectionShape(pathShape, m_selectionTool->selectionAction());
}
}
diff --git a/plugins/tools/selectiontools/kis_tool_select_polygonal.cc b/plugins/tools/selectiontools/kis_tool_select_polygonal.cc
index 5ceb25760cf..ea79b6e03eb 100644
--- a/plugins/tools/selectiontools/kis_tool_select_polygonal.cc
+++ b/plugins/tools/selectiontools/kis_tool_select_polygonal.cc
@@ -83,7 +83,7 @@ void __KisToolSelectPolygonalLocal::finishPolyline(const QVector<QPointF> &point
path->close();
path->normalize();
- helper.addSelectionShape(path);
+ helper.addSelectionShape(path, selectionAction());
}
}
diff --git a/plugins/tools/selectiontools/kis_tool_select_rectangular.cc b/plugins/tools/selectiontools/kis_tool_select_rectangular.cc
index 9e52a4a1267..1882f7fbce8 100644
--- a/plugins/tools/selectiontools/kis_tool_select_rectangular.cc
+++ b/plugins/tools/selectiontools/kis_tool_select_rectangular.cc
@@ -92,7 +92,8 @@ void __KisToolSelectRectangularLocal::finishRect(const QRectF& rect, qreal round
const qreal docRoundCornersX = convertToPt(roundCornersX);
const qreal docRoundCornersY = convertToPt(roundCornersY);
- helper.addSelectionShape(KisShapeToolHelper::createRectangleShape(documentRect, docRoundCornersX, docRoundCornersY));
+ helper.addSelectionShape(KisShapeToolHelper::createRectangleShape(documentRect, docRoundCornersX, docRoundCornersY),
+ selectionAction());
}
}
More information about the kimageshop
mailing list