chalk

kis_crop_visitor.h
1/*
2 * Copyright (c) 2005 Boudewijn Rempt <boud@valdyas.org>
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_CROP_VISITOR_H_
19#define KIS_CROP_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_selected_transaction.h>
33
34class KisProgressDisplayInterface;
35class KisFilterStrategy;
36
37class KisCropVisitor : public KisLayerVisitor {
38
39public:
40
41 KisCropVisitor( const TQRect & rc, bool movelayers = true)
42 : KisLayerVisitor()
43 , m_rect(rc), m_movelayers(movelayers)
44 {
45 }
46
47 virtual ~KisCropVisitor()
48 {
49 }
50
55 bool visit(KisPaintLayer *layer)
56 {
57 KisPaintDeviceSP dev = layer->paintDevice();
58 KisSelectedTransaction * t = 0;
59 if (layer->undoAdapter() && layer->undoAdapter()->undo())
60 t = new KisSelectedTransaction(i18n("Crop"), dev.data());
61
62 dev->crop(m_rect);
63
64 if (layer->undoAdapter() && layer->undoAdapter()->undo()) {
65 layer->undoAdapter()->addCommand(t);
66 }
67
68 if(m_movelayers) {
69 if(layer->undoAdapter() && layer->undoAdapter()->undo()) {
70 KNamedCommand * cmd = dev->moveCommand(layer->x() - m_rect.x(), layer->y() - m_rect.y());
71 layer->undoAdapter()->addCommand(cmd);
72 }
73 }
74 layer->setDirty(dev->image()->bounds());
75 return true;
76 };
77
78 bool visit(KisGroupLayer *layer)
79 {
80 layer->resetProjection();
81
82 KisLayerSP child = layer->firstChild();
83 while (child) {
84 child->accept(*this);
85 child = child->nextSibling();
86 }
87 layer->setDirty();
88 return true;
89 };
90
91 bool visit(KisPartLayer */*layer*/)
92 {
93 return true;
94 };
95
96 virtual bool visit(KisAdjustmentLayer* layer)
97 {
98 layer->resetCache();
99 return true;
100 }
101
102
103private:
104 TQRect m_rect;
105 bool m_movelayers;
106};
107
108
109#endif
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).
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.
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/.