File indexing completed on 2024-12-22 04:10:02
0001 /* 0002 * SPDX-FileCopyrightText: 2007 Sven Langkamp <sven.langkamp@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "kis_reselect_global_selection_command.h" 0008 #include <klocalizedstring.h> 0009 0010 #include "kis_image.h" 0011 #include "kis_group_layer.h" 0012 #include "kis_selection_mask.h" 0013 #include "KisImageGlobalSelectionManagementInterface.h" 0014 #include "KisChangeDeselectedMaskCommand.h" 0015 #include "kis_image_layer_remove_command.h" 0016 #include "kis_image_layer_add_command.h" 0017 #include "KisNotifySelectionChangedCommand.h" 0018 0019 0020 KisReselectGlobalSelectionCommand::KisReselectGlobalSelectionCommand(KisImageWSP image, KUndo2Command * parent) 0021 : KisCommandUtils::AggregateCommand(kundo2_i18n("Reselect"), parent) 0022 , m_image(image) 0023 { 0024 } 0025 0026 KisReselectGlobalSelectionCommand::~KisReselectGlobalSelectionCommand() 0027 { 0028 } 0029 0030 void KisReselectGlobalSelectionCommand::populateChildCommands() 0031 { 0032 KisImageSP image = m_image.toStrongRef(); 0033 KIS_SAFE_ASSERT_RECOVER_RETURN(image); 0034 0035 addCommand(new KisNotifySelectionChangedCommand(image, KisNotifySelectionChangedCommand::INITIALIZING)); 0036 0037 KisSelectionMaskSP selectionMask = image->globalSelectionManagementInterface()->deselectedGlobalSelection(); 0038 if (selectionMask) { 0039 KisSelectionMaskSP activeSelectionMask = image->rootLayer()->selectionMask(); 0040 if (activeSelectionMask) { 0041 addCommand(new KisImageLayerRemoveCommand(image, activeSelectionMask, false, false)); 0042 } 0043 0044 addCommand(new KisChangeDeselectedMaskCommand(image, nullptr)); 0045 addCommand(new KisImageLayerAddCommand(image, selectionMask, image->root(), image->root()->lastChild(), false, false)); 0046 } 0047 0048 addCommand(new KisNotifySelectionChangedCommand(image, KisNotifySelectionChangedCommand::FINALIZING)); 0049 } 0050