krita

kis_transform_visitor.h

00001 /*
00002  *  Copyright (c) 2006 Casper Boemann <cbr@boemann.dk>
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_TRANSFORM_VISITOR_H_
00019 #define KIS_TRANSFORM_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_transform_worker.h"
00033 #include <kis_selected_transaction.h>
00034 
00035 class KisProgressDisplayInterface;
00036 class KisFilterStrategy;
00037 
00038 class KisTransformVisitor : public KisLayerVisitor {
00039 
00040 public:
00041 
00042     KisTransformVisitor(KisImageSP img, double  xscale, double  yscale,
00043         double  /*xshear*/, double  /*yshear*/, double angle,
00044         Q_INT32  tx, Q_INT32  ty, KisProgressDisplayInterface *progress, KisFilterStrategy *filter) 
00045         : KisLayerVisitor()
00046         , m_sx(xscale)
00047         , m_sy(yscale)
00048         , m_tx(tx)
00049         , m_ty(ty)
00050         , m_filter(filter)
00051         , m_angle(angle)
00052         , m_progress(progress)
00053         , m_img(img)
00054     {
00055     }
00056 
00057     virtual ~KisTransformVisitor()
00058     {
00059     }
00060 
00065     bool visit(KisPaintLayer *layer) 
00066     {
00067         KisPaintDeviceSP dev = layer->paintDevice();
00068 
00069         KisTransaction * t = 0;
00070         if (m_img->undo()) {
00071             t = new KisTransaction(i18n("Rotate Layer"), dev);
00072             Q_CHECK_PTR(t);
00073     }
00074 
00075         KisTransformWorker tw(dev, m_sx, m_sy, 0.0, 0.0, m_angle, m_tx, m_ty, m_progress, m_filter);
00076         tw.run();
00077 
00078         if (m_img->undo()) {
00079             m_img->undoAdapter()->addCommand(t);
00080     }
00081         layer->setDirty();
00082         return true;
00083     };
00084 
00085     bool visit(KisGroupLayer *layer)
00086     {
00087     layer->resetProjection();
00088 
00089         KisLayerSP child = layer->firstChild();
00090         while (child) {
00091             child->accept(*this);
00092             child = child->nextSibling();
00093         }
00094         layer->setDirty();
00095         return true;
00096     };
00097 
00098     bool visit(KisPartLayer */*layer*/)
00099     {
00100         return true;
00101     };
00102 
00103     virtual bool visit(KisAdjustmentLayer* layer)
00104     {
00105         KisPaintDeviceSP dev = layer->selection().data();
00106         
00107         KisTransaction * t = 0;
00108 
00109         if (m_img->undo()) {
00110             t = new KisTransaction(i18n("Rotate Layer"), dev);
00111             Q_CHECK_PTR(t);
00112         }
00113 
00114         KisTransformWorker tw(dev, m_sx, m_sy, 0.0, 0.0, m_angle, m_tx, m_ty, m_progress, m_filter);
00115         tw.run();
00116 
00117         if (m_img->undo()) {
00118             m_img->undoAdapter()->addCommand(t);
00119         }
00120         layer->setDirty();
00121         
00122         layer->resetCache();
00123         return true;
00124     }
00125     
00126 
00127 private:
00128     double m_sx, m_sy;
00129     Q_INT32 m_tx, m_ty;
00130     KisFilterStrategy *m_filter;
00131     double m_angle;
00132     KisProgressDisplayInterface *m_progress;
00133     KisImageSP m_img;
00134 };
00135 
00136 
00137 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys