chalk

kis_change_profile_visitor.h
1/*
2 * Copyright (c) 2006 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_CHANGE_PROFILE_VISITOR_H_
19#define KIS_CHANGE_PROFILE_VISITOR_H_
20
21#include "kis_global.h"
22#include "kis_types.h"
23#include "kis_layer_visitor.h"
24#include "kis_paint_layer.h"
25#include "kis_paint_device.h"
26#include "kis_adjustment_layer.h"
27#include "kis_group_layer.h"
28
36class KisChangeProfileVisitor :public KisLayerVisitor {
37public:
38 KisChangeProfileVisitor(KisColorSpace *oldColorSpace, KisColorSpace *dstColorSpace);
39 virtual ~KisChangeProfileVisitor();
40
41public:
42 virtual bool visit(KisPaintLayer *layer);
43 virtual bool visit(KisGroupLayer *layer);
44 virtual bool visit(KisPartLayer *layer);
45 virtual bool visit(KisAdjustmentLayer* layer);
46
47private:
48 KisColorSpace *m_oldColorSpace;
49 KisColorSpace *m_dstColorSpace;
50};
51
52KisChangeProfileVisitor::KisChangeProfileVisitor(KisColorSpace * oldColorSpace,
53 KisColorSpace *dstColorSpace) :
54 KisLayerVisitor(),
55 m_oldColorSpace(oldColorSpace),
56 m_dstColorSpace(dstColorSpace)
57{
58}
59
60KisChangeProfileVisitor::~KisChangeProfileVisitor()
61{
62}
63
64bool KisChangeProfileVisitor::visit(KisGroupLayer * layer)
65{
66 // Clear the projection, we will have to re-render everything.
67 layer->resetProjection();
68
69 KisLayerSP child = layer->firstChild();
70 while (child) {
71 child->accept(*this);
72 child = child->nextSibling();
73 }
74 layer->setDirty();
75 return true;
76}
77
78bool KisChangeProfileVisitor::visit(KisPaintLayer *layer)
79{
80 if (!layer) return false;
81 if (!layer->paintDevice()) return false;
82 if (!layer->paintDevice()->colorSpace()) return false;
83
84 KisColorSpace * cs = layer->paintDevice()->colorSpace();
85
86 if (cs == m_oldColorSpace) {
87
88 layer->paintDevice()->setProfile(m_dstColorSpace->getProfile());
89
90 layer->setDirty();
91 }
92 return true;
93}
94
95bool KisChangeProfileVisitor::visit(KisPartLayer *)
96{
97 return true;
98}
99
100
101bool KisChangeProfileVisitor::visit(KisAdjustmentLayer * layer)
102{
103 layer->resetCache();
104 layer->setDirty();
105 return true;
106}
107
108#endif // KIS_CHANGE_PROFILE_VISITOR_H_
109
Class that contains a KisFilter and optionally a KisSelection.
A colorspace is the definition of a certain color model in Chalk.
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.
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/.