krita
kis_save_visitor.h00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef KIS_SAVE_VISITOR_H_
00020 #define KIS_SAVE_VISITOR_H_
00021
00022 #include <qrect.h>
00023 #include "kis_types.h"
00024 #include "kis_layer_visitor.h"
00025 #include "kis_image.h"
00026 #include "kis_layer.h"
00027 #include "kis_paint_layer.h"
00028 #include "kis_group_layer.h"
00029
00030 class KisSaveVisitor : public KisLayerVisitor {
00031 public:
00032 KisSaveVisitor(KisImageSP img, KoStore *store, Q_UINT32 &count) :
00033 KisLayerVisitor(),
00034 m_count(count)
00035 {
00036 m_external = false;
00037 m_img = img;
00038 m_store = store;
00039 }
00040
00041 public:
00042 void setExternalUri(QString &uri)
00043 {
00044 m_external = true;
00045 m_uri = uri;
00046 }
00047
00048 virtual bool visit(KisPaintLayer *layer)
00049 {
00050
00051
00052 QString location = m_external ? QString::null : m_uri;
00053 location += m_img->name() + QString("/layers/layer%1").arg(m_count);
00054
00055
00056 if (m_store->open(location)) {
00057 if (!layer->paintDevice()->write(m_store)) {
00058 layer->paintDevice()->disconnect();
00059 m_store->close();
00060
00061 return false;
00062 }
00063
00064 m_store->close();
00065 }
00066
00067 if (layer->paintDevice()->colorSpace()->getProfile()) {
00068 KisAnnotationSP annotation = layer->paintDevice()->colorSpace()->getProfile()->annotation();
00069
00070 if (annotation) {
00071
00072 location = m_external ? QString::null : m_uri;
00073 location += m_img->name() + QString("/layers/layer%1").arg(m_count) + ".icc";
00074
00075 if (m_store->open(location)) {
00076 m_store->write(annotation->annotation());
00077 m_store->close();
00078 }
00079 }
00080 }
00081
00082 if (layer->hasMask()) {
00083 KisPaintDeviceSP mask = layer->getMask();
00084
00085 if (mask) {
00086
00087 location = m_external ? QString::null : m_uri;
00088 location += m_img->name() + QString("/layers/layer%1").arg(m_count) + ".mask";
00089
00090 if (m_store->open(location)) {
00091 if (!mask->write(m_store)) {
00092 mask->disconnect();
00093 m_store->close();
00094 return false;
00095 }
00096
00097 m_store->close();
00098 }
00099 }
00100 }
00101
00102 m_count++;
00103 return true;
00104 }
00105
00106 virtual bool visit(KisGroupLayer *layer)
00107 {
00108 KisSaveVisitor visitor(m_img, m_store, m_count);
00109
00110 if(m_external)
00111 visitor.setExternalUri(m_uri);
00112
00113 KisLayerSP child = layer->firstChild();
00114
00115 while(child)
00116 {
00117 child->accept(visitor);
00118 child = child->nextSibling();
00119 }
00120 return true;
00121 }
00122
00123 virtual bool visit(KisPartLayer *)
00124 {
00125 return true;
00126 }
00127
00128 virtual bool visit(KisAdjustmentLayer* layer)
00129 {
00130
00131 if (layer->selection()) {
00132 QString location = m_external ? QString::null : m_uri;
00133 location += m_img->name() + QString("/layers/layer%1").arg(m_count) + ".selection";
00134
00135
00136 if (m_store->open(location)) {
00137 if (!layer->selection()->write(m_store)) {
00138 layer->selection()->disconnect();
00139 m_store->close();
00140
00141 return false;
00142 }
00143 m_store->close();
00144 }
00145 }
00146
00147 if (layer->filter()) {
00148 QString location = m_external ? QString::null : m_uri;
00149 location = m_external ? QString::null : m_uri;
00150 location += m_img->name() + QString("/layers/layer%1").arg(m_count) + ".filterconfig";
00151
00152 if (m_store->open(location)) {
00153 QString s = layer->filter()->toString();
00154 m_store->write(s.utf8(), qstrlen(s.utf8()));
00155 m_store->close();
00156 }
00157 }
00158 m_count++;
00159 return true;
00160 }
00161
00162 private:
00163 KisImageSP m_img;
00164 KoStore *m_store;
00165 bool m_external;
00166 QString m_uri;
00167 Q_UINT32 &m_count;
00168 };
00169
00170 #endif // KIS_SAVE_VISITOR_H_
00171
|