krita

kis_transaction.cc

00001 /*
00002  *  Copyright (c) 2002 Patrick Julien <freak@codepimps.org>
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  */
00018 #include "kis_types.h"
00019 #include "kis_global.h"
00020 #include "kis_tile.h"
00021 #include "kis_tileddatamanager.h"
00022 #include "kis_image.h"
00023 #include "kis_transaction.h"
00024 #include "kis_memento.h"
00025 #include "kis_paint_device.h"
00026 #include "kis_layer.h"
00027 
00028 class KisTransactionPrivate {
00029 public:
00030     QString m_name;
00031     KisPaintDeviceSP m_device;
00032     KisMementoSP m_memento;
00033 
00034 };
00035 
00036 KisTransaction::KisTransaction(const QString& name, KisPaintDeviceSP device)
00037 {
00038     m_private = new KisTransactionPrivate;
00039 
00040     m_private->m_name = name;
00041     m_private->m_device = device;
00042     m_private->m_memento = device->getMemento();
00043 }
00044 
00045 KisTransaction::~KisTransaction()
00046 {
00047     if (m_private->m_memento) {
00048         // For debugging purposes
00049         m_private->m_memento->setInvalid();
00050     }
00051     delete m_private;
00052 }
00053 
00054 void KisTransaction::execute()
00055 {
00056     Q_ASSERT(m_private->m_memento != 0);
00057 
00058     m_private->m_device->rollforward(m_private->m_memento);
00059 
00060     QRect rc;
00061     Q_INT32 x, y, width, height;
00062     m_private->m_memento->extent(x,y,width,height);
00063     rc.setRect(x + m_private->m_device->getX(), y + m_private->m_device->getY(), width, height);
00064 
00065     KisLayerSP l = m_private->m_device->parentLayer();
00066     if (l) l->setDirty(rc);
00067 }
00068 
00069 void KisTransaction::unexecute()
00070 {
00071     Q_ASSERT(m_private->m_memento != 0);
00072     m_private->m_device->rollback(m_private->m_memento);
00073 
00074     QRect rc;
00075     Q_INT32 x, y, width, height;
00076     m_private->m_memento->extent(x,y,width,height);
00077     rc.setRect(x + m_private->m_device->getX(), y + m_private->m_device->getY(), width, height);
00078 
00079     KisLayerSP l = m_private->m_device->parentLayer();
00080     if (l) l->setDirty(rc);
00081 
00082 }
00083 
00084 void KisTransaction::unexecuteNoUpdate()
00085 {
00086     Q_ASSERT(m_private->m_memento != 0);
00087 
00088     m_private->m_device->rollback(m_private->m_memento);
00089 }
00090 
00091 QString KisTransaction::name() const
00092 {
00093     return m_private->m_name;
00094 }
KDE Home | KDE Accessibility Home | Description of Access Keys