krita

kis_shear_visitor.h

00001 /*
00002  *  Copyright (c) 2006 Bart Coppens <kde@bartcoppens.be>
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 
00019 #ifndef KIS_SHEAR_VISITOR_H_
00020 #define KIS_SHEAR_VISITOR_H_
00021 
00022 #include "kis_types.h"
00023 #include "kis_progress_subject.h"
00024 #include "kis_layer_visitor.h"
00025 #include "kis_transform_worker.h"
00026 #include "kis_filter_strategy.h"
00027 #include "kis_undo_adapter.h"
00028 #include "kis_transaction.h"
00029 #include "kis_rotate_visitor.h"
00030 
00031 class KisShearVisitor : public KisLayerVisitor {
00032 public:
00033     KisShearVisitor(double xshear, double yshear, KisProgressDisplayInterface *progress)
00034         : m_xshear(xshear), m_yshear(yshear), m_progress(progress), m_strategy(0), m_undo(0) {};
00035 
00036     void setStrategy(KisFilterStrategy* strategy) { m_strategy = strategy; }
00037     void setUndoAdapter(KisUndoAdapter* undo) { m_undo = undo; }
00038 public:
00039     virtual bool visit(KisPaintLayer* layer) {
00040         KisPaintDeviceSP dev = layer->paintDevice();
00041         if(!dev)
00042             return true;
00043 
00044         KisFilterStrategy* strategy = 0;
00045         if (m_strategy)
00046             strategy = m_strategy;
00047         else
00048             strategy = new KisMitchellFilterStrategy;
00049 
00050         KisTransaction* t = 0;
00051 
00052         if (m_undo && m_undo->undo())
00053             t = new KisTransaction("", dev.data());
00054 
00055         //Doesn't do anything, internally transforms x and y shear to 0 each :-///
00056         //KisTransformWorker w(dev, 1.0, 1.0, m_xshear, m_yshear, 0, 0, 0, m_progress, strategy);
00057         //w.run();
00058 
00059         KisRotateVisitor v;
00060         v.visitKisPaintDevice(dev);
00061         v.shear(m_xshear, m_yshear, m_progress);
00062 
00063         if (m_undo && m_undo->undo())
00064             m_undo->addCommand(t);
00065 
00066         if (!m_strategy)
00067             delete strategy;
00068 
00069         layer->setDirty();
00070 
00071         return true;
00072     }
00073 
00074     virtual bool visit(KisGroupLayer* layer) {
00075         KisLayerSP child = layer->firstChild();
00076 
00077         while(child)
00078         {
00079             child->accept(*this);
00080             child = child->nextSibling();
00081         }
00082         return true;
00083     }
00084 
00085     virtual bool visit(KisPartLayer*) { return true; }
00086     virtual bool visit(KisAdjustmentLayer *) { return true; }
00087 private:
00088     double m_xshear;
00089     double m_yshear;
00090     KisProgressDisplayInterface* m_progress;
00091     KisFilterStrategy* m_strategy;
00092     KisUndoAdapter* m_undo;
00093 };
00094 
00095 #endif // KIS_SHEAR_VISITOR_H_
KDE Home | KDE Accessibility Home | Description of Access Keys