File indexing completed on 2024-12-22 04:10:02
0001 /* 0002 * SPDX-FileCopyrightText: 2018 Dmitry Kazakov <dimula73@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "KisDeselectActiveSelectionCommand.h" 0008 #include "kis_image.h" 0009 #include "kis_selection.h" 0010 #include "kis_selection_mask.h" 0011 0012 KisDeselectActiveSelectionCommand::KisDeselectActiveSelectionCommand(KisSelectionSP activeSelection, KisImageWSP image, KUndo2Command *parent) 0013 : KisDeselectGlobalSelectionCommand(image, parent), 0014 m_activeSelection(activeSelection) 0015 { 0016 } 0017 0018 KisDeselectActiveSelectionCommand::~KisDeselectActiveSelectionCommand() 0019 { 0020 } 0021 0022 void KisDeselectActiveSelectionCommand::redo() 0023 { 0024 KisImageSP image = m_image.toStrongRef(); 0025 KIS_SAFE_ASSERT_RECOVER_RETURN(image); 0026 0027 if (m_activeSelection && m_activeSelection == image->globalSelection()) { 0028 KisDeselectGlobalSelectionCommand::redo(); 0029 } else if (m_activeSelection) { 0030 KisNodeSP parentNode = m_activeSelection->parentNode(); 0031 if (!parentNode) return; 0032 0033 m_deselectedMask = dynamic_cast<KisSelectionMask*>(parentNode.data()); 0034 if (m_deselectedMask) { 0035 KIS_SAFE_ASSERT_RECOVER(m_deselectedMask->active()) { 0036 m_deselectedMask.clear(); 0037 return; 0038 } 0039 0040 m_deselectedMask->setActive(false); 0041 } 0042 } 0043 } 0044 0045 void KisDeselectActiveSelectionCommand::undo() 0046 { 0047 if (m_deselectedMask) { 0048 m_deselectedMask->setActive(true); 0049 m_deselectedMask.clear(); 0050 } else { 0051 KisDeselectGlobalSelectionCommand::undo(); 0052 } 0053 }