libs/flake

KoShapeSavingContext.h

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2004-2006 David Faure <faure@kde.org>
00003    Copyright (C) 2007-2008 Thorsten Zachmann <zachmann@kde.org>
00004    Copyright (C) 2007 Jan Hambrecht <jaham@gmx.net>
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License as published by the Free Software Foundation; either
00009    version 2 of the License, or (at your option) any later version.
00010 
00011    This library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public License
00017    along with this library; see the file COPYING.LIB.  If not, write to
00018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #ifndef KOSHAPESAVINGCONTEXT_H
00023 #define KOSHAPESAVINGCONTEXT_H
00024 
00025 #include "flake_export.h"
00026 
00027 #include <QFlags>
00028 #include <QMap>
00029 #include <QSet>
00030 #include <QString>
00031 #include <QPixmap>
00032 
00033 class KoShape;
00034 class KoXmlWriter;
00035 class KoGenStyles;
00036 class KoDataCenter;
00037 class KoEmbeddedDocumentSaver;
00038 class KoImageData;
00039 class KoShapeLayer;
00040 class KoStore;
00041 class KoSharedSavingData;
00042 
00046 class FLAKE_EXPORT KoShapeSavingContext
00047 {
00048 public:
00049     enum SavingMode { Store, Flat };
00050 
00052     enum ShapeSavingOption {
00058         PresentationShape = 1,
00063         DrawId = 2,
00067         AutoStyleInStyleXml = 4,
00071         UniqueMasterPages = 8
00072     };
00073     Q_DECLARE_FLAGS(KoShapeSavingOptions, ShapeSavingOption)
00074 
00075     
00082     KoShapeSavingContext(KoXmlWriter &xmlWriter, KoGenStyles& mainStyles,
00083                          KoEmbeddedDocumentSaver& embeddedSaver, SavingMode savingMode = Store);
00084     virtual ~KoShapeSavingContext();
00085 
00091     KoXmlWriter & xmlWriter();
00092 
00101     void setXmlWriter(KoXmlWriter & xmlWriter);
00102 
00108     KoGenStyles & mainStyles();
00109 
00115     KoEmbeddedDocumentSaver & embeddedSaver();
00116 
00122     bool isSet(ShapeSavingOption option) const;
00123 
00129     void setOptions(KoShapeSavingOptions options);
00130 
00132     void addOption(ShapeSavingOption option);
00133 
00135     void removeOption(ShapeSavingOption option);
00136 
00142     KoShapeSavingOptions options() const;
00143 
00154     const QString drawId(const KoShape * shape, bool insert = true);
00155 
00164     void clearDrawIds();
00165 
00170     void addLayerForSaving(const KoShapeLayer * layer);
00171 
00175     void saveLayerSet(KoXmlWriter & xmlWriter) const;
00176 
00182     void clearLayers();
00183 
00187     QString imageHref(KoImageData * image);
00188 
00195     QString imageHref(QImage & image);
00196 
00200     QMap<qint64, QString> imagesToSave();
00201 
00205     void addDataCenter(KoDataCenter * dataCenter);
00206 
00213     bool saveDataCenter(KoStore *store, KoXmlWriter* manifestWriter);
00214 
00232     void addSharedData(const QString & id, KoSharedSavingData * data);
00233 
00242     KoSharedSavingData * sharedData(const QString & id) const;
00243 
00253     void addShapeOffset(const KoShape * shape, const QMatrix & m);
00254 
00260     void removeShapeOffset(const KoShape * shape);
00261 
00268     QMatrix shapeOffset(const KoShape * shape) const;
00269 
00270 private:
00271     KoXmlWriter *m_xmlWriter;
00272     KoShapeSavingOptions m_savingOptions;
00273     QMap<const KoShape *, QString> m_drawIds;
00274     QList<const KoShapeLayer*> m_layers;
00275     QSet<KoDataCenter *> m_dataCenter;
00276     int m_drawId;
00277     QMap<QString, KoSharedSavingData*> m_sharedData;
00278     QMap<qint64, QString> m_imageNames;
00279     int m_imageId;
00280     QMap<QString, QImage> m_images;
00281     QHash<const KoShape *, QMatrix> m_shapeOffsets;
00282 
00283     KoGenStyles& m_mainStyles;
00284     KoEmbeddedDocumentSaver& m_embeddedSaver;
00285     SavingMode m_savingMode;
00286 };
00287 
00288 Q_DECLARE_OPERATORS_FOR_FLAGS(KoShapeSavingContext::KoShapeSavingOptions)
00289 
00290 #endif // KOSHAPESAVINGCONTEXT_H