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

Add the parent layer as the new source for the contiguous and similar selection tool

killy |0veufOreverf14b789ed804
diff --git a/krita/pics/svg/dark_parent-layer.svg b/krita/pics/svg/dark_parent-layer.svg
new file mode 100644
index 0000000000..2e947c612a
--- /dev/null
+++ b/krita/pics/svg/dark_parent-layer.svg
@@ -0,0 +1 @@
+<svg width="16" height="16" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><g fill="#373737" stroke-width=".82858px" color="#000"><path d="M8.04 10.471 2.938 7.953l2.085-1.03-.932-.46-3.017 1.49L8.04 11.39l6.965-3.437-3.017-1.49-.93.46 2.084 1.03z" fill-opacity=".4" style="-inkscape-stroke:none" transform="matrix(1.1485 0 0 1.2471 -1.233 -1.917)"/><path d="M8.04 13.448 2.938 10.93 5.023 9.9l-.932-.46-3.017 1.49 6.966 3.437 6.965-3.437-3.017-1.49-.93.46 2.084 1.03z" fill-opacity=".4" style="-inkscape-stroke:none" transform="matrix(1.1485 0 0 1.2471 -1.233 -1.917)"/><path d="M8.04 1.537 1.074 4.974 8.04 8.41l6.965-3.437zm0 .919 5.102 2.518L8.04 7.492 2.938 4.974z" style="-inkscape-stroke:none" transform="matrix(1.1485 0 0 1.2471 -1.233 -1.917)"/></g></svg>
\ No newline at end of file
diff --git a/krita/pics/svg/light_parent-layer.svg b/krita/pics/svg/light_parent-layer.svg
new file mode 100644
index 0000000000..d5d949c071
--- /dev/null
+++ b/krita/pics/svg/light_parent-layer.svg
@@ -0,0 +1 @@
+<svg width="16" height="16" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><g fill="#d2d2d2" stroke-width=".82858px" color="#000"><path d="M8.04 10.471 2.938 7.953l2.085-1.03-.932-.46-3.017 1.49L8.04 11.39l6.965-3.437-3.017-1.49-.93.46 2.084 1.03z" fill-opacity=".4" style="-inkscape-stroke:none" transform="matrix(1.1485 0 0 1.2471 -1.233 -1.917)"/><path d="M8.04 13.448 2.938 10.93 5.023 9.9l-.932-.46-3.017 1.49 6.966 3.437 6.965-3.437-3.017-1.49-.93.46 2.084 1.03z" fill-opacity=".4" style="-inkscape-stroke:none" transform="matrix(1.1485 0 0 1.2471 -1.233 -1.917)"/><path d="M8.04 1.537 1.074 4.974 8.04 8.41l6.965-3.437zm0 .919 5.102 2.518L8.04 7.492 2.938 4.974z" style="-inkscape-stroke:none" transform="matrix(1.1485 0 0 1.2471 -1.233 -1.917)"/></g></svg>
\ No newline at end of file
diff --git a/krita/pics/svg/svg-icons.qrc b/krita/pics/svg/svg-icons.qrc
index 0f0d1abd56..df151f2b3e 100644
--- a/krita/pics/svg/svg-icons.qrc
+++ b/krita/pics/svg/svg-icons.qrc
@@ -543,6 +543,8 @@
<file>light_histogram-show-best.svg</file>
<file>dark_current-layer.svg</file>
<file>light_current-layer.svg</file>
+ <file>dark_parent-layer.svg</file>
+ <file>light_parent-layer.svg</file>
<file>dark_all-layers.svg</file>
<file>light_all-layers.svg</file>
<file>dark_contiguous-selection.svg</file>
diff --git a/libs/ui/tool/kis_selection_tool_config_widget_helper.cpp b/libs/ui/tool/kis_selection_tool_config_widget_helper.cpp
index 9365bb9bde..f91d508c69 100644
--- a/libs/ui/tool/kis_selection_tool_config_widget_helper.cpp
+++ b/libs/ui/tool/kis_selection_tool_config_widget_helper.cpp
@@ -180,9 +180,11 @@ void KisSelectionToolConfigWidgetHelper::slotReferenceLayersChanged(
"sampleLayersMode",
referenceLayers == KisSelectionOptions::AllLayers
? "sampleAllLayers"
- : (referenceLayers == KisSelectionOptions::ColorLabeledLayers
- ? "sampleColorLabeledLayers"
- : "sampleCurrentLayer"));
+ : (referenceLayers == KisSelectionOptions::ParentLayer
+ ? "sampleParentLayer"
+ : (referenceLayers == KisSelectionOptions::CurrentLayer
+ ? "sampleCurrentLayer"
+ : "sampleColorLabeledLayers")));
}
void KisSelectionToolConfigWidgetHelper::slotSelectedColorLabelsChanged()
@@ -277,9 +279,12 @@ void KisSelectionToolConfigWidgetHelper::reloadExactToolConfig()
const KisSelectionOptions::ReferenceLayers referenceLayers =
referenceLayersStr == "sampleAllLayers"
? KisSelectionOptions::AllLayers
- : (referenceLayersStr == "sampleColorLabeledLayers"
- ? KisSelectionOptions::ColorLabeledLayers
- : KisSelectionOptions::CurrentLayer);
+ : (referenceLayersStr == "sampleParentLayer"
+ ? KisSelectionOptions::ParentLayer
+ : (referenceLayersStr == "sampleCurrentLayer"
+ ? KisSelectionOptions::CurrentLayer
+ : KisSelectionOptions::ColorLabeledLayers));
+
QList<int> colorLabels;
for (const QString &colorLabelStr : colorLabelsStr) {
bool ok;
diff --git a/libs/ui/tool/kis_tool_select_base.h b/libs/ui/tool/kis_tool_select_base.h
index b21733a124..3e5ca2b7e3 100644
--- a/libs/ui/tool/kis_tool_select_base.h
+++ b/libs/ui/tool/kis_tool_select_base.h
@@ -90,6 +90,7 @@ public:
enum SampleLayersMode
{
SampleAllLayers,
+ SampleParentLayer,
SampleCurrentLayer,
SampleColorLabeledLayers,
};
@@ -221,6 +222,8 @@ public:
m_widgetHelper.referenceLayers();
if (referenceLayers == KisSelectionOptions::AllLayers) {
return SampleAllLayers;
+ } else if (referenceLayers == KisSelectionOptions::ParentLayer) {
+ return SampleParentLayer;
} else if (referenceLayers == KisSelectionOptions::CurrentLayer) {
return SampleCurrentLayer;
} else if (referenceLayers == KisSelectionOptions::ColorLabeledLayers) {
diff --git a/libs/ui/widgets/kis_selection_options.cc b/libs/ui/widgets/kis_selection_options.cc
index 3eafa1a854..b8196ca8ea 100644
--- a/libs/ui/widgets/kis_selection_options.cc
+++ b/libs/ui/widgets/kis_selection_options.cc
@@ -87,10 +87,12 @@ public:
switch (action) {
case CurrentLayer:
return 0;
- case AllLayers:
+ case ParentLayer:
return 1;
- case ColorLabeledLayers:
+ case AllLayers:
return 2;
+ case ColorLabeledLayers:
+ return 3;
default:
return 0;
}
@@ -102,8 +104,10 @@ public:
case 0:
return CurrentLayer;
case 1:
- return AllLayers;
+ return ParentLayer;
case 2:
+ return AllLayers;
+ case 3:
return ColorLabeledLayers;
default:
return CurrentLayer;
@@ -213,6 +217,8 @@ KisSelectionOptions::KisSelectionOptions(QWidget *parent)
m_d->optionButtonStripReference = new KisOptionButtonStrip;
m_d->optionButtonStripReference->addButton(
KisIconUtils::loadIcon("current-layer"));
+ m_d->optionButtonStripReference->addButton(
+ KisIconUtils::loadIcon("parent-layer"));
m_d->optionButtonStripReference->addButton(
KisIconUtils::loadIcon("all-layers"));
m_d->optionButtonStripReference->addButton(KisIconUtils::loadIcon("tag"));
@@ -252,8 +258,10 @@ KisSelectionOptions::KisSelectionOptions(QWidget *parent)
m_d->optionButtonStripReference->button(0)->setToolTip(
i18n("Select regions found from the active layer"));
m_d->optionButtonStripReference->button(1)->setToolTip(
- i18n("Select regions found from the merging of all layers"));
+ i18n("Select regions found from the parent layer of the active layer"));
m_d->optionButtonStripReference->button(2)->setToolTip(
+ i18n("Select regions found from the merging of all layers"));
+ m_d->optionButtonStripReference->button(3)->setToolTip(
i18n("Select regions found from the merging of layers with specific color labels"));
// Construct the option widget
diff --git a/libs/ui/widgets/kis_selection_options.h b/libs/ui/widgets/kis_selection_options.h
index b98c7bfb79..523d3edd78 100644
--- a/libs/ui/widgets/kis_selection_options.h
+++ b/libs/ui/widgets/kis_selection_options.h
@@ -19,7 +19,7 @@ class KRITAUI_EXPORT KisSelectionOptions : public KisOptionCollectionWidget
Q_OBJECT
public:
- enum ReferenceLayers { CurrentLayer, AllLayers, ColorLabeledLayers };
+ enum ReferenceLayers { CurrentLayer, ParentLayer, AllLayers, ColorLabeledLayers };
KisSelectionOptions(QWidget *parent = nullptr);
~KisSelectionOptions() override;
diff --git a/plugins/tools/selectiontools/kis_tool_select_contiguous.cc b/plugins/tools/selectiontools/kis_tool_select_contiguous.cc
index b0c914185b..3dce58d52e 100644
--- a/plugins/tools/selectiontools/kis_tool_select_contiguous.cc
+++ b/plugins/tools/selectiontools/kis_tool_select_contiguous.cc
@@ -116,6 +116,8 @@ void KisToolSelectContiguous::beginPrimaryAction(KoPointerEvent *event)
if (sampleLayersMode() == SampleCurrentLayer) {
sourceDevice = m_referencePaintDevice = dev;
+ } else if (sampleLayersMode() == SampleParentLayer) {
+ sourceDevice = m_referencePaintDevice = currentNode()->parent()->projection();
} else if (sampleLayersMode() == SampleAllLayers) {
sourceDevice = m_referencePaintDevice = currentImage()->projection();
} else if (sampleLayersMode() == SampleColorLabeledLayers) {
diff --git a/plugins/tools/selectiontools/kis_tool_select_similar.cc b/plugins/tools/selectiontools/kis_tool_select_similar.cc
index 65c88220c3..d2bed48ce9 100644
--- a/plugins/tools/selectiontools/kis_tool_select_similar.cc
+++ b/plugins/tools/selectiontools/kis_tool_select_similar.cc
@@ -92,6 +92,8 @@ void KisToolSelectSimilar::beginPrimaryAction(KoPointerEvent *event)
// Construct the reference device
if (sampleLayersMode() == SampleCurrentLayer) {
m_referencePaintDevice = currentNode()->projection();
+ } else if (sampleLayersMode() == SampleParentLayer) {
+ m_referencePaintDevice = currentNode()->parent()->projection();
} else if (sampleLayersMode() == SampleAllLayers) {
m_referencePaintDevice = currentImage()->projection();
} else if (sampleLayersMode() == SampleColorLabeledLayers) {