File indexing completed on 2024-12-22 04:10:01
0001 /* 0002 * SPDX-FileCopyrightText: 2002 Patrick Julien <freak@codepimps.org> 0003 * SPDX-FileCopyrightText: 2007 Sven Langkamp <sven.langkamp@gmail.com> 0004 * 0005 * SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #include "kis_image_commands.h" 0009 #include <QString> 0010 #include <QBitArray> 0011 0012 #include <klocalizedstring.h> 0013 0014 #include "KoColor.h" 0015 #include "KoColorProfile.h" 0016 0017 0018 #include "kis_image.h" 0019 #include "kis_layer.h" 0020 #include "kis_group_layer.h" 0021 #include "kis_undo_adapter.h" 0022 0023 0024 KisImageLayerMoveCommand::KisImageLayerMoveCommand(KisImageWSP image, KisNodeSP layer, KisNodeSP newParent, KisNodeSP newAbove, bool doUpdates) 0025 : KisImageCommand(kundo2_i18n("Move Layer"), image) 0026 { 0027 m_layer = layer; 0028 m_newParent = newParent; 0029 m_newAbove = newAbove; 0030 m_prevParent = layer->parent(); 0031 m_prevAbove = layer->prevSibling(); 0032 m_index = -1; 0033 m_useIndex = false; 0034 m_doUpdates = doUpdates; 0035 } 0036 0037 KisImageLayerMoveCommand::KisImageLayerMoveCommand(KisImageWSP image, KisNodeSP node, KisNodeSP newParent, quint32 index) 0038 : KisImageCommand(kundo2_i18n("Move Layer"), image) 0039 { 0040 m_layer = node; 0041 m_newParent = newParent; 0042 m_newAbove = 0; 0043 m_prevParent = node->parent(); 0044 m_prevAbove = node->prevSibling(); 0045 m_index = index; 0046 m_useIndex = true; 0047 m_doUpdates = true; 0048 } 0049 0050 void KisImageLayerMoveCommand::redo() 0051 { 0052 KisImageSP image = m_image.toStrongRef(); 0053 if (!image) { 0054 return; 0055 } 0056 if (m_useIndex) { 0057 image->moveNode(m_layer, m_newParent, m_index); 0058 } else { 0059 image->moveNode(m_layer, m_newParent, m_newAbove); 0060 } 0061 0062 if (m_doUpdates) { 0063 image->refreshGraphAsync(m_prevParent, KisImage::NoFilthyUpdate); 0064 if (m_newParent != m_prevParent) { 0065 m_layer->setDirty(image->bounds()); 0066 } 0067 } 0068 } 0069 0070 void KisImageLayerMoveCommand::undo() 0071 { 0072 KisImageSP image = m_image.toStrongRef(); 0073 if (!image) { 0074 return; 0075 } 0076 image->moveNode(m_layer, m_prevParent, m_prevAbove); 0077 0078 if (m_doUpdates) { 0079 image->refreshGraphAsync(m_newParent, KisImage::NoFilthyUpdate); 0080 if (m_newParent != m_prevParent) { 0081 m_layer->setDirty(image->bounds()); 0082 } 0083 } 0084 }