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 "Include Current Layer" option when referencing color labels on "fill" tool and "enclose and fill" tool
runch r.61b18f034482
diff --git a/libs/image/commands_new/KisMergeLabeledLayersCommand.cpp b/libs/image/commands_new/KisMergeLabeledLayersCommand.cppindex c16a34f3ab..68b6683864 100644--- a/libs/image/commands_new/KisMergeLabeledLayersCommand.cpp+++ b/libs/image/commands_new/KisMergeLabeledLayersCommand.cpp@@ -34,6 +34,7 @@ KisMergeLabeledLayersCommand::KisMergeLabeledLayersCommand(KisImageSP image,, m_selectedLabels(selectedLabels), m_groupSelectionPolicy(groupSelectionPolicy), m_forceRegeneration(true)+ , m_activeNode(nullptr){KIS_ASSERT(newRefPaintDevice);if (image->animationInterface()->hasAnimation()) {@@ -49,7 +50,8 @@ KisMergeLabeledLayersCommand::KisMergeLabeledLayersCommand(KisImageSP image,KisPaintDeviceSP newRefPaintDevice,QList<int> selectedLabels,GroupSelectionPolicy groupSelectionPolicy,- bool forceRegeneration)+ bool forceRegeneration,+ KisNodeSP activeNode): KUndo2Command(kundo2_noi18n("MERGE_LABELED_LAYERS")), m_refImage(new KisImage(new KisSurrogateUndoStore(), image->width(), image->height(), image->colorSpace(), "Merge Labeled Layers Reference Image")), m_prevRefNodeInfoList(prevRefNodeInfoList)@@ -60,6 +62,7 @@ KisMergeLabeledLayersCommand::KisMergeLabeledLayersCommand(KisImageSP image,, m_selectedLabels(selectedLabels), m_groupSelectionPolicy(groupSelectionPolicy), m_forceRegeneration(forceRegeneration)+ , m_activeNode(activeNode){KIS_SAFE_ASSERT_RECOVER_NOOP(prevRefNodeInfoList);KIS_SAFE_ASSERT_RECOVER_NOOP(newRefNodeInfoList);@@ -116,7 +119,11 @@ QPair<KisNodeSP, QPair<bool, bool>> KisMergeLabeledLayersCommand::collectNode(Ki// Do not use this node if it is not labeled appropriately. The children// should still be visited if it is a group. The next sibling should// also be visited- return {nullptr, {true, node->inherits("KisGroupLayer")}};+ if (!(m_activeNode != nullptr && node->uuid() == m_activeNode->uuid())) {+ // If the active node has been passed and it is being considered,+ // it should be treated as if it is labeled to match.+ return {nullptr, {true, node->inherits("KisGroupLayer")}};+ }}if (node->inherits("KisCloneLayer")) {@@ -164,7 +171,7 @@ QPair<KisNodeSP, QPair<bool, bool>> KisMergeLabeledLayersCommand::collectNode(Kireturn {node, {true, false}};}}-+// By default, visit the next sibling, but not the childrenreturn {node, {true, false}};}@@ -199,7 +206,7 @@ bool KisMergeLabeledLayersCommand::collectNodes(KisNodeSP node, QList<KisNodeSP>node = node->prevSibling();}}-+return visitNextSibling;}diff --git a/libs/image/commands_new/KisMergeLabeledLayersCommand.h b/libs/image/commands_new/KisMergeLabeledLayersCommand.hindex e1ff2b20f1..e959eaedee 100644--- a/libs/image/commands_new/KisMergeLabeledLayersCommand.h+++ b/libs/image/commands_new/KisMergeLabeledLayersCommand.h@@ -94,6 +94,7 @@ public:* @param groupSelectionPolicy How to treat groups* @param forceRegeneration If true, the cache is ignored and the merged* result is regenerated+ * @param activeNode The current node that is being edited.*/KisMergeLabeledLayersCommand(KisImageSP image,ReferenceNodeInfoListSP prevRefNodeInfoList,@@ -102,7 +103,8 @@ public:KisPaintDeviceSP newRefPaintDevice,QList<int> selectedLabels,GroupSelectionPolicy groupSelectionPolicy = GroupSelectionPolicy_SelectAlways,- bool forceRegeneration = false);+ bool forceRegeneration = false,+ KisNodeSP activeNode = nullptr);~KisMergeLabeledLayersCommand() override;@@ -127,6 +129,7 @@ private:QList<int> m_selectedLabels;GroupSelectionPolicy m_groupSelectionPolicy;bool m_forceRegeneration;+ KisNodeSP m_activeNode;};#endif /* __KIS_MERGE_LABELED_LAYERS_H */diff --git a/plugins/tools/basictools/kis_tool_fill.cc b/plugins/tools/basictools/kis_tool_fill.ccindex 6503311fff..466144b6d7 100644--- a/plugins/tools/basictools/kis_tool_fill.cc+++ b/plugins/tools/basictools/kis_tool_fill.cc@@ -283,7 +283,8 @@ void KisToolFill::beginFilling(const QPoint &seedPoint)newReferencePaintDevice,m_selectedColorLabels,KisMergeLabeledLayersCommand::GroupSelectionPolicy_SelectIfColorLabeled,- m_previousTime != currentTime+ m_previousTime != currentTime,+ m_useActiveLayer ? currentNode() : nullptr)),false,KisStrokeJobData::SEQUENTIAL,@@ -621,6 +622,7 @@ QWidget* KisToolFill::createOptionWidget()m_widgetLabels->setButtonSize(20);m_widgetLabels->setButtonWrapEnabled(true);m_widgetLabels->setMouseDragEnabled(true);+ m_checkBoxUseActiveLayer = new QCheckBox(i18n("Use active layer"));KisOptionButtonStrip *optionButtonStripDragFill =new KisOptionButtonStrip;@@ -664,6 +666,7 @@ QWidget* KisToolFill::createOptionWidget()m_buttonReferenceCurrent->setToolTip(i18n("Fill regions found from the active layer"));m_buttonReferenceAll->setToolTip(i18n("Fill regions found from the merging of all layers"));m_buttonReferenceLabeled->setToolTip(i18n("Fill regions found from the merging of layers with specific color labels"));+ m_checkBoxUseActiveLayer->setToolTip(i18n("Includes the active layer in regions found from merging of layers with specific color labels"));m_buttonDragFillDoNotUse->setToolTip(i18n("Dragging will not fill different regions"));m_buttonDragFillAny->setToolTip(i18n("Dragging will fill regions of any color"));@@ -697,12 +700,17 @@ QWidget* KisToolFill::createOptionWidget()sectionFillWith->setWidgetVisible("angleSelectorPatternRotation", false);m_optionWidget->appendWidget("sectionFillWith", sectionFillWith);+ KisOptionCollectionWidget *widgetLabelsGroup = new KisOptionCollectionWidget;+ widgetLabelsGroup->appendWidget("labelWidget", m_widgetLabels);+ widgetLabelsGroup->appendWidget("checkBoxUseActiveLayer", m_checkBoxUseActiveLayer);+ widgetLabelsGroup->setWidgetsMargin(0);+KisOptionCollectionWidgetWithHeader *sectionReference =new KisOptionCollectionWidgetWithHeader(i18nc("The 'reference' section label in fill tool options", "Reference"));sectionReference->setPrimaryWidget(optionButtonStripReference);- sectionReference->appendWidget("widgetLabels", m_widgetLabels);+ sectionReference->appendWidget("widgetLabels", widgetLabelsGroup);sectionReference->setWidgetVisible("widgetLabels", false);m_optionWidget->appendWidget("sectionReference", sectionReference);@@ -796,6 +804,7 @@ QWidget* KisToolFill::createOptionWidget()m_buttonDragFillSimilar->setChecked(true);}m_widgetLabels->setSelection(m_selectedColorLabels);+ m_checkBoxUseActiveLayer->setChecked(m_useActiveLayer);// Make connectionsconnect(optionButtonStripWhatToFill,@@ -841,6 +850,7 @@ QWidget* KisToolFill::createOptionWidget()SIGNAL(buttonToggled(KoGroupButton *, bool)),SLOT(slot_optionButtonStripReference_buttonToggled(KoGroupButton *, bool)));connect(m_widgetLabels, SIGNAL(selectionChanged()), SLOT(slot_widgetLabels_selectionChanged()));+ connect(m_checkBoxUseActiveLayer, SIGNAL(toggled(bool)), SLOT(slot_checkBoxUseActiveLayer_toggled(bool)));connect(optionButtonStripDragFill,SIGNAL(buttonToggled(KoGroupButton *, bool)),@@ -933,6 +943,7 @@ void KisToolFill::loadConfiguration()m_selectedColorLabels << colorLabel;}}+ m_useActiveLayer = m_configGroup.readEntry<bool>("useActiveLayer", false);}{const QString continuousFillModeStr = m_configGroup.readEntry<QString>("continuousFillMode", "fillAnyRegion");@@ -1308,3 +1319,12 @@ void KisToolFill::slot_colorSpaceChanged(const KoColorSpace *colorSpace)}m_comboBoxCustomCompositeOp->validate(compositionSpace);}++void KisToolFill::slot_checkBoxUseActiveLayer_toggled(bool checked)+{+ if (checked == m_useActiveLayer) {+ return;+ }+ m_useActiveLayer = checked;+ m_configGroup.writeEntry("useActiveLayer", checked);+}diff --git a/plugins/tools/basictools/kis_tool_fill.h b/plugins/tools/basictools/kis_tool_fill.hindex a07ef0ccfd..abd919e2bc 100644--- a/plugins/tools/basictools/kis_tool_fill.h+++ b/plugins/tools/basictools/kis_tool_fill.h@@ -126,6 +126,7 @@ private:Reference m_reference {Reference_CurrentLayer};QList<int> m_selectedColorLabels;+ bool m_useActiveLayer {false};ContinuousFillMode m_continuousFillMode {ContinuousFillMode_FillAnyRegion};@@ -181,6 +182,7 @@ private:KoGroupButton *m_buttonReferenceAll {nullptr};KoGroupButton *m_buttonReferenceLabeled {nullptr};KisColorLabelSelectorWidget *m_widgetLabels {nullptr};+ QCheckBox *m_checkBoxUseActiveLayer {nullptr};KoGroupButton *m_buttonDragFillDoNotUse {nullptr};KoGroupButton *m_buttonDragFillAny {nullptr};@@ -219,6 +221,7 @@ private Q_SLOTS:void slot_optionButtonStripReference_buttonToggled(KoGroupButton *button,bool checked);void slot_widgetLabels_selectionChanged();+ void slot_checkBoxUseActiveLayer_toggled(bool checked);void slot_optionButtonStripDragFill_buttonToggled(KoGroupButton *button,bool checked);void slot_buttonReset_clicked();diff --git a/plugins/tools/tool_enclose_and_fill/KisToolEncloseAndFill.cpp b/plugins/tools/tool_enclose_and_fill/KisToolEncloseAndFill.cppindex 5af01b07f1..cc5078361b 100644--- a/plugins/tools/tool_enclose_and_fill/KisToolEncloseAndFill.cpp+++ b/plugins/tools/tool_enclose_and_fill/KisToolEncloseAndFill.cpp@@ -297,7 +297,8 @@ void KisToolEncloseAndFill::slot_delegateTool_enclosingMaskProduced(KisPixelSelenewReferencePaintDevice,m_selectedColorLabels,KisMergeLabeledLayersCommand::GroupSelectionPolicy_SelectIfColorLabeled,- m_previousTime != currentTime+ m_previousTime != currentTime,+ m_useActiveLayer ? currentNode() : nullptr)),false,KisStrokeJobData::SEQUENTIAL,@@ -539,6 +540,7 @@ QWidget* KisToolEncloseAndFill::createOptionWidget()m_widgetLabels->setButtonSize(20);m_widgetLabels->setButtonWrapEnabled(true);m_widgetLabels->setMouseDragEnabled(true);+ m_checkBoxUseActiveLayer = new QCheckBox(i18n("Use active layer"));QPushButton *buttonReset = new QPushButton(i18nc("The 'reset' button in enclose and fill tool options", "Reset"));@@ -573,6 +575,7 @@ QWidget* KisToolEncloseAndFill::createOptionWidget()m_buttonReferenceCurrent->setToolTip(i18n("Fill regions found from the active layer"));m_buttonReferenceAll->setToolTip(i18n("Fill regions found from the merging of all layers"));m_buttonReferenceLabeled->setToolTip(i18n("Fill regions found from the merging of layers with specific color labels"));+ m_checkBoxUseActiveLayer->setToolTip(i18n("Includes the active layer in regions found from merging of layers with specific color labels"));buttonReset->setToolTip(i18n("Reset the options to their default values"));@@ -588,12 +591,17 @@ QWidget* KisToolEncloseAndFill::createOptionWidget()sectionEnclosingMethod->setPrimaryWidget(optionButtonStripEnclosingMethod);m_optionWidget->appendWidget("sectionEnclosingMethod", sectionEnclosingMethod);+ KisOptionCollectionWidget *widgetLabelsGroup = new KisOptionCollectionWidget;+ widgetLabelsGroup->appendWidget("labelWidget", m_widgetLabels);+ widgetLabelsGroup->appendWidget("checkBoxUseActiveLayer", m_checkBoxUseActiveLayer);+ widgetLabelsGroup->setWidgetsMargin(0);+KisOptionCollectionWidgetWithHeader *sectionReference =new KisOptionCollectionWidgetWithHeader(i18nc("The 'reference' section label in enclose and fill tool options", "Reference"));sectionReference->setPrimaryWidget(optionButtonStripReference);- sectionReference->appendWidget("widgetLabels", m_widgetLabels);+ sectionReference->appendWidget("widgetLabels", widgetLabelsGroup);sectionReference->setWidgetVisible("widgetLabels", false);m_optionWidget->appendWidget("sectionReference", sectionReference);@@ -712,6 +720,7 @@ QWidget* KisToolEncloseAndFill::createOptionWidget()sectionReference->setWidgetVisible("widgetLabels", true);}m_widgetLabels->setSelection(m_selectedColorLabels);+ m_checkBoxUseActiveLayer->setChecked(m_useActiveLayer);// Make connectionsconnect(optionButtonStripEnclosingMethod,@@ -779,6 +788,9 @@ QWidget* KisToolEncloseAndFill::createOptionWidget()connect(m_widgetLabels,SIGNAL(selectionChanged()),SLOT(slot_widgetLabels_selectionChanged()));+ connect(m_checkBoxUseActiveLayer,+ SIGNAL(toggled(bool)),+ SLOT(slot_checkBoxUseActiveLayer_toggled(bool)));connect(buttonReset,SIGNAL(clicked()),SLOT(slot_buttonReset_clicked()));@@ -847,6 +859,7 @@ void KisToolEncloseAndFill::loadConfiguration()}}}+ m_useActiveLayer = m_configGroup.readEntry<bool>("useActiveLayer", false);setupEnclosingSubtool();}@@ -1354,3 +1367,12 @@ void KisToolEncloseAndFill::slot_colorSpaceChanged(const KoColorSpace *colorSpac}m_comboBoxCustomCompositeOp->validate(compositionSpace);}++void KisToolEncloseAndFill::slot_checkBoxUseActiveLayer_toggled(bool checked)+{+ if (checked == m_useActiveLayer) {+ return;+ }+ m_useActiveLayer = checked;+ m_configGroup.writeEntry("useActiveLayer", checked);+}diff --git a/plugins/tools/tool_enclose_and_fill/KisToolEncloseAndFill.h b/plugins/tools/tool_enclose_and_fill/KisToolEncloseAndFill.hindex b1a5730c22..1a719344ea 100644--- a/plugins/tools/tool_enclose_and_fill/KisToolEncloseAndFill.h+++ b/plugins/tools/tool_enclose_and_fill/KisToolEncloseAndFill.h@@ -109,6 +109,7 @@ private:int m_expand {0};int m_stopGrowingAtDarkestPixel {false};int m_feather {0};+ bool m_useActiveLayer {false};Reference m_reference {CurrentLayer};QList<int> m_selectedColorLabels;@@ -156,6 +157,7 @@ private:KoGroupButton *m_buttonReferenceAll{nullptr};KoGroupButton *m_buttonReferenceLabeled{nullptr};KisColorLabelSelectorWidget *m_widgetLabels {nullptr};+ QCheckBox *m_checkBoxUseActiveLayer {nullptr};KConfigGroup m_configGroup;@@ -222,6 +224,7 @@ private Q_SLOTS:void slot_colorSpaceChanged(const KoColorSpace *colorSpace);void slot_delegateTool_enclosingMaskProduced(KisPixelSelectionSP enclosingMask);+ void slot_checkBoxUseActiveLayer_toggled(bool checked);void resetCursorStyle() override;};