File indexing completed on 2024-12-22 04:10:02

0001 /*
0002  *  SPDX-FileCopyrightText: 2015 Dmitry Kazakov <dimula73@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #include "kis_activate_selection_mask_command.h"
0008 
0009 #include "kis_layer.h"
0010 #include "kis_selection_mask.h"
0011 
0012 
0013 KisActivateSelectionMaskCommand::KisActivateSelectionMaskCommand(KisSelectionMaskSP selectionMask, bool value)
0014     : m_selectionMask(selectionMask),
0015       m_value(value)
0016 {
0017     if (m_previousActiveMask != m_selectionMask) {
0018         KisLayerSP parent(qobject_cast<KisLayer*>(selectionMask->parent().data()));
0019         if (parent) {
0020             m_previousActiveMask = parent->selectionMask();
0021         }
0022     }
0023 
0024     m_previousValue = selectionMask->active();
0025 }
0026 
0027 void KisActivateSelectionMaskCommand::redo()
0028 {
0029     m_selectionMask->setActive(m_value);
0030 }
0031 
0032 void KisActivateSelectionMaskCommand::undo()
0033 {
0034     m_selectionMask->setActive(m_previousValue);
0035 
0036     if (m_value && m_previousActiveMask) {
0037         m_previousActiveMask->setActive(true);
0038     }
0039 }
0040 
0041