[krita] /: Make ShowGlobalSelectionMask option auto-create the mask
Dmitry Kazakov
dimula73 at gmail.com
Fri Aug 17 17:16:57 BST 2018
Here is a short demo video of this new feature:
http://nonaynever.ru/pub/krita-quick-mask-feature-2018-08-17_19.13.19.mkv
On 17.08.2018 19:11, Dmitry Kazakov wrote:
> Git commit 23be34a6bd97a01cc6615e06209018e3868ea3b6 by Dmitry Kazakov.
> Committed on 17/08/2018 at 16:10.
> Pushed by dkazakov into branch 'master'.
>
> Make ShowGlobalSelectionMask option auto-create the mask
>
> 1) When the option is activated and there is no global mask yet,
> a new mask is created.
>
> 2) When the option is deactivated and the global selection mask
> is empty (nothing selected!), then the mask is automatically
> deleted
>
> TODO: perhaps we don't want to save this option into KisConfig
> anymore, but somehow activate that depending on the presence
> on a global selection in the image?
>
> BUG:343218
> CC:kimageshop at kde.org
>
> M +13 -0 libs/image/kis_layer_utils.cpp
> M +8 -0 libs/image/kis_layer_utils.h
> M +45 -10 plugins/dockers/defaultdockers/kis_layer_box.cpp
>
> https://commits.kde.org/krita/23be34a6bd97a01cc6615e06209018e3868ea3b6
>
> diff --git a/libs/image/kis_layer_utils.cpp b/libs/image/kis_layer_utils.cpp
> index cbc9867d35c..2a2f0e24981 100644
> --- a/libs/image/kis_layer_utils.cpp
> +++ b/libs/image/kis_layer_utils.cpp
> @@ -574,6 +574,19 @@ namespace KisLayerUtils {
> m_image->signalRouter()->emitNotification(type);
> }
>
> + SelectGlobalSelectionMask::SelectGlobalSelectionMask(KisImageSP image)
> + : m_image(image)
> + {
> + }
> +
> + void SelectGlobalSelectionMask::redo() {
> +
> + KisImageSignalType type =
> + ComplexNodeReselectionSignal(m_image->rootLayer()->selectionMask(), KisNodeList());
> + m_image->signalRouter()->emitNotification(type);
> +
> + }
> +
> KisLayerSP constructDefaultLayer(KisImageSP image) {
> return new KisPaintLayer(image.data(), image->nextLayerName(), OPACITY_OPAQUE_U8, image->colorSpace());
> }
> diff --git a/libs/image/kis_layer_utils.h b/libs/image/kis_layer_utils.h
> index 87962f4e8fe..1ce9ede5064 100644
> --- a/libs/image/kis_layer_utils.h
> +++ b/libs/image/kis_layer_utils.h
> @@ -125,6 +125,14 @@ namespace KisLayerUtils
> KisImageWSP m_image;
> };
>
> + struct KRITAIMAGE_EXPORT SelectGlobalSelectionMask : public KUndo2Command
> + {
> + SelectGlobalSelectionMask(KisImageSP image);
> + void redo() override;
> +
> + KisImageSP m_image;
> + };
> +
> KRITAIMAGE_EXPORT KisLayerSP constructDefaultLayer(KisImageSP image);
>
> class KRITAIMAGE_EXPORT RemoveNodeHelper {
> diff --git a/plugins/dockers/defaultdockers/kis_layer_box.cpp b/plugins/dockers/defaultdockers/kis_layer_box.cpp
> index d60f469e323..562ceb9ff59 100644
> --- a/plugins/dockers/defaultdockers/kis_layer_box.cpp
> +++ b/plugins/dockers/defaultdockers/kis_layer_box.cpp
> @@ -86,6 +86,10 @@
> #include "kis_color_filter_combo.h"
> #include "kis_node_filter_proxy_model.h"
>
> +#include "kis_selection.h"
> +#include "kis_processing_applicator.h"
> +#include "commands/kis_set_global_selection_command.h"
> +
> #include "kis_layer_utils.h"
>
> #include "ui_wdglayerbox.h"
> @@ -778,6 +782,7 @@ void KisLayerBox::slotEditGlobalSelection(bool showSelections)
> {
> KisNodeSP lastActiveNode = m_nodeManager->activeNode();
> KisNodeSP activateNode = lastActiveNode;
> + KisSelectionMaskSP globalSelectionMask;
>
> if (!showSelections) {
> activateNode = findNonHidableNode(activateNode);
> @@ -785,20 +790,50 @@ void KisLayerBox::slotEditGlobalSelection(bool showSelections)
>
> m_nodeModel->setShowGlobalSelection(showSelections);
>
> - if (showSelections) {
> - KisNodeSP newMask = m_image->rootLayer()->selectionMask();
> - if (newMask) {
> - activateNode = newMask;
> + globalSelectionMask = m_image->rootLayer()->selectionMask();
> + if (globalSelectionMask) {
> + if (showSelections) {
> + activateNode = globalSelectionMask;
> }
> }
>
> - if (activateNode) {
> - if (lastActiveNode != activateNode) {
> - m_nodeManager->slotNonUiActivatedNode(activateNode);
> - } else {
> - setCurrentNode(lastActiveNode);
> - }
> + if (activateNode != lastActiveNode) {
> + m_nodeManager->slotNonUiActivatedNode(activateNode);
> + } else if (lastActiveNode) {
> + setCurrentNode(lastActiveNode);
> }
> +
> + if (showSelections && !globalSelectionMask) {
> + KisProcessingApplicator applicator(m_image, 0,
> + KisProcessingApplicator::NONE,
> + KisImageSignalVector() << ModifiedSignal,
> + kundo2_i18n("Quick Selection Mask"));
> +
> + applicator.applyCommand(
> + new KisLayerUtils::KeepNodesSelectedCommand(
> + m_nodeManager->selectedNodes(), KisNodeList(),
> + lastActiveNode, 0, m_image, false),
> + KisStrokeJobData::SEQUENTIAL, KisStrokeJobData::EXCLUSIVE);
> + applicator.applyCommand(new KisSetEmptyGlobalSelectionCommand(m_image),
> + KisStrokeJobData::SEQUENTIAL,
> + KisStrokeJobData::EXCLUSIVE);
> + applicator.applyCommand(new KisLayerUtils::SelectGlobalSelectionMask(m_image),
> + KisStrokeJobData::SEQUENTIAL,
> + KisStrokeJobData::EXCLUSIVE);
> +
> + applicator.end();
> + } else if (!showSelections &&
> + globalSelectionMask &&
> + globalSelectionMask->selection()->selectedRect().isEmpty()) {
> +
> + KisProcessingApplicator applicator(m_image, 0,
> + KisProcessingApplicator::NONE,
> + KisImageSignalVector() << ModifiedSignal,
> + kundo2_i18n("Cancel Quick Selection Mask"));
> + applicator.applyCommand(new KisSetGlobalSelectionCommand(m_image, 0), KisStrokeJobData::SEQUENTIAL, KisStrokeJobData::EXCLUSIVE);
> + applicator.end();
> + }
> +
> }
>
> void KisLayerBox::selectionChanged(const QModelIndexList selection)
--
Dmitry Kazakov
More information about the kimageshop
mailing list