chalk

kis_save_visitor.h
1/*
2 * Copyright (c) 2002 Patrick Julien <freak@codepimps.org>
3 * Copyright (c) 2005 Casper Boemann <cbr@boemann.dk>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19#ifndef KIS_SAVE_VISITOR_H_
20#define KIS_SAVE_VISITOR_H_
21
22#include <tqrect.h>
23#include "kis_types.h"
24#include "kis_layer_visitor.h"
25#include "kis_image.h"
26#include "kis_layer.h"
27#include "kis_paint_layer.h"
28#include "kis_group_layer.h"
29
30class KisSaveVisitor : public KisLayerVisitor {
31public:
32 KisSaveVisitor(KisImageSP img, KoStore *store, TQ_UINT32 &count) :
33 KisLayerVisitor(),
34 m_count(count)
35 {
36 m_external = false;
37 m_img = img;
38 m_store = store;
39 }
40
41public:
42 void setExternalUri(TQString &uri)
43 {
44 m_external = true;
45 m_uri = uri;
46 }
47
48 virtual bool visit(KisPaintLayer *layer)
49 {
50 //connect(*layer->paintDevice(), TQ_SIGNAL(ioProgress(TQ_INT8)), m_img, TQ_SLOT(slotIOProgress(TQ_INT8)));
51
52 TQString location = m_external ? TQString() : m_uri;
53 location += m_img->name() + TQString("/layers/layer%1").arg(m_count);
54
55 // Layer data
56 if (m_store->open(location)) {
57 if (!layer->paintDevice()->write(m_store)) {
58 layer->paintDevice()->disconnect();
59 m_store->close();
60 //IODone();
61 return false;
62 }
63
64 m_store->close();
65 }
66
67 if (layer->paintDevice()->colorSpace()->getProfile()) {
68 KisAnnotationSP annotation = layer->paintDevice()->colorSpace()->getProfile()->annotation();
69
70 if (annotation) {
71 // save layer profile
72 location = m_external ? TQString() : m_uri;
73 location += m_img->name() + TQString("/layers/layer%1").arg(m_count) + ".icc";
74
75 if (m_store->open(location)) {
76 m_store->write(annotation->annotation());
77 m_store->close();
78 }
79 }
80 }
81
82 if (layer->hasMask()) {
83 KisPaintDeviceSP mask = layer->getMask();
84
85 if (mask) {
86 // save layer profile
87 location = m_external ? TQString() : m_uri;
88 location += m_img->name() + TQString("/layers/layer%1").arg(m_count) + ".mask";
89
90 if (m_store->open(location)) {
91 if (!mask->write(m_store)) {
92 mask->disconnect();
93 m_store->close();
94 return false;
95 }
96
97 m_store->close();
98 }
99 }
100 }
101
102 m_count++;
103 return true;
104 }
105
106 virtual bool visit(KisGroupLayer *layer)
107 {
108 KisSaveVisitor visitor(m_img, m_store, m_count);
109
110 if(m_external)
111 visitor.setExternalUri(m_uri);
112
113 KisLayerSP child = layer->firstChild();
114
115 while(child)
116 {
117 child->accept(visitor);
118 child = child->nextSibling();
119 }
120 return true;
121 }
122
123 virtual bool visit(KisPartLayer *)
124 {
125 return true;
126 }
127
128 virtual bool visit(KisAdjustmentLayer* layer)
129 {
130
131 if (layer->selection()) {
132 TQString location = m_external ? TQString() : m_uri;
133 location += m_img->name() + TQString("/layers/layer%1").arg(m_count) + ".selection";
134
135 // Layer data
136 if (m_store->open(location)) {
137 if (!layer->selection()->write(m_store)) {
138 layer->selection()->disconnect();
139 m_store->close();
140 //IODone();
141 return false;
142 }
143 m_store->close();
144 }
145 }
146
147 if (layer->filter()) {
148 TQString location = m_external ? TQString() : m_uri;
149 location = m_external ? TQString() : m_uri;
150 location += m_img->name() + TQString("/layers/layer%1").arg(m_count) + ".filterconfig";
151
152 if (m_store->open(location)) {
153 TQString s = layer->filter()->toString();
154 m_store->write(s.utf8(), tqstrlen(s.utf8()));
155 m_store->close();
156 }
157 }
158 m_count++;
159 return true;
160 }
161
162private:
163 KisImageSP m_img;
164 KoStore *m_store;
165 bool m_external;
166 TQString m_uri;
167 TQ_UINT32 &m_count;
168};
169
170#endif // KIS_SAVE_VISITOR_H_
171
Class that contains a KisFilter and optionally a KisSelection.
virtual TQString toString()
Create a serialized version of this filter config.
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.
KisPaintDeviceSP getMask()
Returns the layer mask's device. Creates one if there is currently none.
bool hasMask() const
Does this layer have a layer mask?
An interface for the Part Layer so that we can use it in core/, but can implement it in ui/.