chalk

kis_shear_visitor.h
1/*
2 * Copyright (c) 2006 Bart Coppens <kde@bartcoppens.be>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19#ifndef KIS_SHEAR_VISITOR_H_
20#define KIS_SHEAR_VISITOR_H_
21
22#include "kis_types.h"
23#include "kis_progress_subject.h"
24#include "kis_layer_visitor.h"
25#include "kis_transform_worker.h"
26#include "kis_filter_strategy.h"
27#include "kis_undo_adapter.h"
28#include "kis_transaction.h"
29#include "kis_rotate_visitor.h"
30
31class KisShearVisitor : public KisLayerVisitor {
32public:
33 KisShearVisitor(double xshear, double yshear, KisProgressDisplayInterface *progress)
34 : m_xshear(xshear), m_yshear(yshear), m_progress(progress), m_strategy(0), m_undo(0) {};
35
36 void setStrategy(KisFilterStrategy* strategy) { m_strategy = strategy; }
37 void setUndoAdapter(KisUndoAdapter* undo) { m_undo = undo; }
38public:
39 virtual bool visit(KisPaintLayer* layer) {
40 KisPaintDeviceSP dev = layer->paintDevice();
41 if(!dev)
42 return true;
43
44 KisFilterStrategy* strategy = 0;
45 if (m_strategy)
46 strategy = m_strategy;
47 else
48 strategy = new KisMitchellFilterStrategy;
49
50 KisTransaction* t = 0;
51
52 if (m_undo && m_undo->undo())
53 t = new KisTransaction("", dev.data());
54
55 //Doesn't do anything, internally transforms x and y shear to 0 each :-///
56 //KisTransformWorker w(dev, 1.0, 1.0, m_xshear, m_yshear, 0, 0, 0, m_progress, strategy);
57 //w.run();
58
59 KisRotateVisitor v;
60 v.visitKisPaintDevice(dev);
61 v.shear(m_xshear, m_yshear, m_progress);
62
63 if (m_undo && m_undo->undo())
64 m_undo->addCommand(t);
65
66 if (!m_strategy)
67 delete strategy;
68
69 layer->setDirty();
70
71 return true;
72 }
73
74 virtual bool visit(KisGroupLayer* layer) {
75 KisLayerSP child = layer->firstChild();
76
77 while(child)
78 {
79 child->accept(*this);
80 child = child->nextSibling();
81 }
82 return true;
83 }
84
85 virtual bool visit(KisPartLayer*) { return true; }
86 virtual bool visit(KisAdjustmentLayer *) { return true; }
87private:
88 double m_xshear;
89 double m_yshear;
90 KisProgressDisplayInterface* m_progress;
91 KisFilterStrategy* m_strategy;
92 KisUndoAdapter* m_undo;
93};
94
95#endif // KIS_SHEAR_VISITOR_H_
Class that contains a KisFilter and optionally a KisSelection.
A KisLayer that bundles child layers into a single layer.
virtual KisLayerSP firstChild() const
Returns the first child layer of this layer (if it supports that).
This layer is of a type that can be painted on.
virtual void setDirty(bool propagate=true)
Overridden to call the private convertMaskToSelection.
An interface for the Part Layer so that we can use it in core/, but can implement it in ui/.