krita

kis_crop_visitor.h

00001 /*
00002  *  Copyright (c) 2005 Boudewijn Rempt <boud@valdyas.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 #ifndef KIS_CROP_VISITOR_H_
00019 #define KIS_CROP_VISITOR_H_
00020 
00021 #include "qrect.h"
00022 
00023 #include "klocale.h"
00024 
00025 #include "kis_layer_visitor.h"
00026 #include "kis_types.h"
00027 #include "kis_layer.h"
00028 #include "kis_group_layer.h"
00029 #include "kis_paint_layer.h"
00030 #include "kis_adjustment_layer.h"
00031 #include "kis_transaction.h"
00032 #include <kis_selected_transaction.h>
00033 
00034 class KisProgressDisplayInterface;
00035 class KisFilterStrategy;
00036 
00037 class KisCropVisitor : public KisLayerVisitor {
00038 
00039 public:
00040 
00041     KisCropVisitor( const QRect & rc, bool movelayers = true) 
00042         : KisLayerVisitor()
00043         , m_rect(rc), m_movelayers(movelayers)
00044     {
00045     }
00046 
00047     virtual ~KisCropVisitor()
00048     {
00049     }
00050 
00055     bool visit(KisPaintLayer *layer) 
00056     {
00057         KisPaintDeviceSP dev = layer->paintDevice();
00058         KisSelectedTransaction * t = 0;
00059         if (layer->undoAdapter() && layer->undoAdapter()->undo())
00060             t = new KisSelectedTransaction(i18n("Crop"), dev.data());
00061 
00062         dev->crop(m_rect);
00063 
00064         if (layer->undoAdapter() && layer->undoAdapter()->undo()) {
00065             layer->undoAdapter()->addCommand(t);
00066         }
00067         
00068         if(m_movelayers) {
00069             if(layer->undoAdapter() && layer->undoAdapter()->undo()) {
00070                 KNamedCommand * cmd = dev->moveCommand(layer->x() - m_rect.x(), layer->y() - m_rect.y());
00071                 layer->undoAdapter()->addCommand(cmd);
00072             }
00073         }
00074         layer->setDirty(dev->image()->bounds());
00075         return true;
00076     };
00077 
00078     bool visit(KisGroupLayer *layer)
00079     {
00080     layer->resetProjection();
00081 
00082         KisLayerSP child = layer->firstChild();
00083         while (child) {
00084             child->accept(*this);
00085             child = child->nextSibling();
00086         }
00087         layer->setDirty();
00088         return true;
00089     };
00090 
00091     bool visit(KisPartLayer */*layer*/)
00092     {
00093         return true;
00094     };
00095 
00096     virtual bool visit(KisAdjustmentLayer* layer)
00097     {
00098         layer->resetCache();
00099         return true;
00100     }
00101     
00102 
00103 private:
00104     QRect m_rect;
00105     bool m_movelayers;
00106 };
00107 
00108 
00109 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys