Commit cfe16890 authored by Dmitry Kazakov's avatar Dmitry Kazakov

[FEATURE] Added ability to merge down Selection Masks

You can now merge them using usual Ctrl+E on one layer, or just
select multiple selection masks and press Ctrl+E again.

CC:kimageshop@kde.org
parent a4f550b6
......@@ -1066,8 +1066,54 @@ void reparentSelectionMasks(KisLayerSP newLayer, const QVector<KisSelectionMaskS
}
}
KisNodeSP tryMergeSelectionMasks(KisImageSP image, QList<KisNodeSP> mergedNodes)
{
if (mergedNodes.isEmpty()) return 0;
QList<KisSelectionMaskSP> selectionMasks;
foreach (KisNodeSP node, mergedNodes) {
KisSelectionMaskSP mask = dynamic_cast<KisSelectionMask*>(node.data());
if (!mask) return 0;
selectionMasks.append(mask);
}
KisLayerSP parentLayer = dynamic_cast<KisLayer*>(selectionMasks.first()->parent().data());
KIS_ASSERT_RECOVER(parentLayer) { return 0; }
KisSelectionSP selection = new KisSelection();
foreach (KisMaskSP mask, selectionMasks) {
selection->pixelSelection()->applySelection(
mask->selection()->pixelSelection(), SELECTION_ADD);
}
image->undoAdapter()->beginMacro(kundo2_i18n("Merge Selection Masks"));
KisSelectionMaskSP mergedMask = new KisSelectionMask(image);
mergedMask->initSelection(parentLayer);
image->undoAdapter()->addCommand(new KisImageLayerAddCommand(image, mergedMask, parentLayer, parentLayer->lastChild()));
mergedMask->setSelection(selection);
image->undoAdapter()->addCommand(new KisActivateSelectionMaskCommand(mergedMask, true));
image->safeRemoveMultipleNodes(mergedNodes);
image->undoAdapter()->endMacro();
return mergedMask;
}
KisNodeSP KisImage::mergeMultipleLayers(QList<KisNodeSP> mergedNodes, KisNodeSP putAfter)
{
{
KisNodeSP mask;
if ((mask = tryMergeSelectionMasks(this, mergedNodes))) {
return mask;
}
}
filterMergableNodes(mergedNodes);
{
......
......@@ -102,7 +102,7 @@
#include "kis_abstract_projection_plane.h"
#include "commands_new/kis_set_layer_style_command.h"
#include "kis_post_execution_undo_adapter.h"
#include "kis_selection_mask.h"
class KisSaveGroupVisitor : public KisNodeVisitor
......@@ -775,6 +775,30 @@ void KisLayerManager::flattenImage()
}
}
inline bool isSelectionMask(KisNodeSP node) {
return dynamic_cast<KisSelectionMask*>(node.data());
}
bool tryMergeSelectionMasks(KisNodeSP currentNode, KisImageSP image)
{
bool result = false;
KisNodeSP prevNode = currentNode->prevSibling();
if (isSelectionMask(currentNode) &&
prevNode && isSelectionMask(prevNode)) {
QList<KisNodeSP> mergedNodes;
mergedNodes.append(currentNode);
mergedNodes.append(prevNode);
image->mergeMultipleLayers(mergedNodes, currentNode);
result = true;
}
return result;
}
void KisLayerManager::mergeLayer()
{
KisImageWSP image = m_view->image();
......@@ -786,7 +810,9 @@ void KisLayerManager::mergeLayer()
QList<KisNodeSP> selectedNodes = m_view->nodeManager()->selectedNodes();
if (selectedNodes.size() > 1) {
image->mergeMultipleLayers(selectedNodes, layer);
} else {
} else if (!tryMergeSelectionMasks(m_view->activeNode(), image)) {
if (!layer->prevSibling()) return;
KisLayer *prevLayer = dynamic_cast<KisLayer*>(layer->prevSibling().data());
if (!prevLayer) return;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment