chalk

kis_transform_visitor.h
1/*
2 * Copyright (c) 2006 Casper Boemann <cbr@boemann.dk>
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#ifndef KIS_TRANSFORM_VISITOR_H_
19#define KIS_TRANSFORM_VISITOR_H_
20
21#include "tqrect.h"
22
23#include "tdelocale.h"
24
25#include "kis_layer_visitor.h"
26#include "kis_types.h"
27#include "kis_layer.h"
28#include "kis_group_layer.h"
29#include "kis_paint_layer.h"
30#include "kis_adjustment_layer.h"
31#include "kis_transaction.h"
32#include "kis_transform_worker.h"
33#include <kis_selected_transaction.h>
34
35class KisProgressDisplayInterface;
36class KisFilterStrategy;
37
38class KisTransformVisitor : public KisLayerVisitor {
39
40public:
41
42 KisTransformVisitor(KisImageSP img, double xscale, double yscale,
43 double /*xshear*/, double /*yshear*/, double angle,
44 TQ_INT32 tx, TQ_INT32 ty, KisProgressDisplayInterface *progress, KisFilterStrategy *filter)
45 : KisLayerVisitor()
46 , m_sx(xscale)
47 , m_sy(yscale)
48 , m_tx(tx)
49 , m_ty(ty)
50 , m_filter(filter)
51 , m_angle(angle)
52 , m_progress(progress)
53 , m_img(img)
54 {
55 }
56
57 virtual ~KisTransformVisitor()
58 {
59 }
60
65 bool visit(KisPaintLayer *layer)
66 {
67 KisPaintDeviceSP dev = layer->paintDevice();
68
69 KisTransaction * t = 0;
70 if (m_img->undo()) {
71 t = new KisTransaction(i18n("Rotate Layer"), dev);
72 TQ_CHECK_PTR(t);
73 }
74
75 KisTransformWorker tw(dev, m_sx, m_sy, 0.0, 0.0, m_angle, m_tx, m_ty, m_progress, m_filter, true);
76 tw.run();
77
78 if (m_img->undo()) {
79 m_img->undoAdapter()->addCommand(t);
80 }
81 layer->setDirty();
82 return true;
83 };
84
85 bool visit(KisGroupLayer *layer)
86 {
87 layer->resetProjection();
88
89 KisLayerSP child = layer->firstChild();
90 while (child) {
91 child->accept(*this);
92 child = child->nextSibling();
93 }
94 layer->setDirty();
95 return true;
96 };
97
98 bool visit(KisPartLayer */*layer*/)
99 {
100 return true;
101 };
102
103 virtual bool visit(KisAdjustmentLayer* layer)
104 {
105 KisPaintDeviceSP dev = layer->selection().data();
106
107 KisTransaction * t = 0;
108
109 if (m_img->undo()) {
110 t = new KisTransaction(i18n("Rotate Layer"), dev);
111 TQ_CHECK_PTR(t);
112 }
113
114 KisTransformWorker tw(dev, m_sx, m_sy, 0.0, 0.0, m_angle, m_tx, m_ty, m_progress, m_filter, true);
115 tw.run();
116
117 if (m_img->undo()) {
118 m_img->undoAdapter()->addCommand(t);
119 }
120 layer->setDirty();
121
122 layer->resetCache();
123 return true;
124 }
125
126
127private:
128 double m_sx, m_sy;
129 TQ_INT32 m_tx, m_ty;
130 KisFilterStrategy *m_filter;
131 double m_angle;
132 KisProgressDisplayInterface *m_progress;
133 KisImageSP m_img;
134};
135
136
137#endif
virtual KisLayerSP firstChild() const
Returns the first child layer of this layer (if it supports that).
virtual void resetProjection(KisPaintDevice *to=0)
virtual void setDirty(bool propagate=true)
Set the entire layer extent dirty; this percolates up to parent layers all the way to the root layer.
virtual void setDirty(bool propagate=true)
Set the entire layer extent dirty; this percolates up to parent layers all the way to the root layer.
virtual void setDirty(bool propagate=true)
Overridden to call the private convertMaskToSelection.