File indexing completed on 2024-05-12 15:56:49
0001 /* This file is part of the KDE project 0002 SPDX-FileCopyrightText: 2004-2006 David Faure <faure@kde.org> 0003 SPDX-FileCopyrightText: 2007-2008 Thorsten Zachmann <zachmann@kde.org> 0004 SPDX-FileCopyrightText: 2007 Jan Hambrecht <jaham@gmx.net> 0005 SPDX-FileCopyrightText: 2010 Benjamin Port <port.benjamin@gmail.com> 0006 0007 SPDX-License-Identifier: LGPL-2.0-or-later 0008 */ 0009 0010 #ifndef KOSHAPESAVINGCONTEXT_H 0011 #define KOSHAPESAVINGCONTEXT_H 0012 0013 #include "kritaflake_export.h" 0014 0015 #include <QMap> 0016 0017 class KoShape; 0018 class KoXmlWriter; 0019 class KoMarker; 0020 class KoShapeLayer; 0021 class KoStore; 0022 class KoSharedSavingData; 0023 class KoShapeSavingContextPrivate; 0024 0025 class QImage; 0026 class QTransform; 0027 0028 /** 0029 * The set of data for the ODF file format used during saving of a shape. 0030 */ 0031 class KRITAFLAKE_EXPORT KoShapeSavingContext 0032 { 0033 public: 0034 /// The Style used for saving the shape 0035 enum ShapeSavingOption { 0036 /** 0037 * If set the style of family presentation is used, when not set the 0038 * family graphic is used. 0039 * See OpenDocument 9.2.15 Common Drawing Shape Attributes / Style 0040 */ 0041 PresentationShape = 1, 0042 /** 0043 * Save the draw:id used for referencing the shape. If draw:id is saved, xml:id is also 0044 * saved. 0045 * See OpenDocument 9.2.15 Common Drawing Shape Attributes / ID 0046 */ 0047 DrawId = 2, 0048 /** 0049 * If set the automatic style will be marked as being needed in styles.xml 0050 */ 0051 AutoStyleInStyleXml = 4, 0052 /** 0053 * If set duplicate master pages will be merged to one 0054 */ 0055 UniqueMasterPages = 8, 0056 /** 0057 * If set the z-index is saved in the shape 0058 */ 0059 ZIndex = 16 0060 }; 0061 Q_DECLARE_FLAGS(ShapeSavingOptions, ShapeSavingOption) 0062 0063 /** 0064 * @brief Constructor 0065 * @param xmlWriter used for writing the xml 0066 * @param mainStyles for saving the styles 0067 * @param embeddedSaver for saving embedded documents 0068 */ 0069 KoShapeSavingContext(KoXmlWriter &xmlWriter); 0070 virtual ~KoShapeSavingContext(); 0071 0072 /** 0073 * @brief Get the xml writer 0074 * 0075 * @return xmlWriter 0076 */ 0077 KoXmlWriter &xmlWriter(); 0078 0079 /** 0080 * @brief Set the xml writer 0081 * 0082 * Change the xmlWriter that is used in the Context e.g. for saving to styles.xml 0083 * instead of content.xml 0084 * 0085 * @param xmlWriter to use 0086 */ 0087 void setXmlWriter(KoXmlWriter &xmlWriter); 0088 0089 /** 0090 * @brief Check if an option is set 0091 * 0092 * @return ture if the option is set, false otherwise 0093 */ 0094 bool isSet(ShapeSavingOption option) const; 0095 0096 /** 0097 * @brief Set the options to use 0098 * 0099 * @param options to use 0100 */ 0101 void setOptions(ShapeSavingOptions options); 0102 0103 /// add an option to the set of options stored on this context, will leave the other options intact. 0104 void addOption(ShapeSavingOption option); 0105 0106 /// remove an option, will leave the other options intact. 0107 void removeOption(ShapeSavingOption option); 0108 0109 /** 0110 * @brief Get the options used 0111 * 0112 * @return options used 0113 */ 0114 ShapeSavingOptions options() const; 0115 0116 /** 0117 * Adds a layer to save into a layer-set in styles.xml according to 9.1.2/9.1.3 odf spec 0118 * @param layer the layer to save 0119 */ 0120 void addLayerForSaving(const KoShapeLayer *layer); 0121 0122 /** 0123 * Saves the layers added with addLayerForSaving to the xml writer 0124 */ 0125 void saveLayerSet(KoXmlWriter &xmlWriter) const; 0126 0127 /** 0128 * remove all layers 0129 * 0130 * This can be used for saving different layer sets per page. 0131 */ 0132 void clearLayers(); 0133 0134 /** 0135 * Get the images that needs to be saved to the store 0136 */ 0137 QMap<qint64, QString> imagesToSave(); 0138 0139 /** 0140 * Get the reference to use for the marker lookup 0141 */ 0142 QString markerRef(const KoMarker *marker); 0143 0144 /** 0145 * Add shared data 0146 * 0147 * This can be use to pass data between shapes on saving. E.g. The presentation page layout 0148 * styles. With that e.g. the styles only need to be saved once and can be used everywhere 0149 * without creating them again. 0150 * 0151 * The ownership of the added data is passed to the context. The KoShapeSavingContext will 0152 * delete the added data when it is destroyed. 0153 * 0154 * Data inserted for a specific id will not be overwritten by calling addSharedData with 0155 * the same id again. 0156 * 0157 * You get an assertion when the id is already existing. 0158 * 0159 * @see KoSharedSavingData 0160 */ 0161 void addSharedData(const QString &id, KoSharedSavingData *data); 0162 0163 /** 0164 * Get the shared data. 0165 * 0166 * @see KoSharedLoadingData 0167 * 0168 * @param id The id used to identify the shared data. 0169 * @return The shared data for the id or 0 if there is no shared data for the id. 0170 */ 0171 KoSharedSavingData *sharedData(const QString &id) const; 0172 0173 /** 0174 * Add an offset that will be applied to the shape position when saved 0175 * 0176 * This is needed e.g. for shapes anchored to a text shape as the position is 0177 * saved as offset to the anchor. 0178 * 0179 * @param shape The shape for which the offset should be added. 0180 * @param matrix The offset which should be applied on saving the position. 0181 */ 0182 void addShapeOffset(const KoShape *shape, const QTransform &matrix); 0183 0184 /** 0185 * Remove an offset from the saved offset list 0186 * 0187 * @param shape The shape for which the offset should be removed. 0188 */ 0189 void removeShapeOffset(const KoShape *shape); 0190 0191 /** 0192 * Get the offset that will be applied to the shape position when saved. 0193 * 0194 * @param shape The shape for which the offset should be get. 0195 * @return the saved offset or QTransform() when offset is not set. 0196 */ 0197 QTransform shapeOffset(const KoShape *shape) const; 0198 0199 private: 0200 KoShapeSavingContextPrivate * const d; 0201 }; 0202 0203 Q_DECLARE_OPERATORS_FOR_FLAGS(KoShapeSavingContext::ShapeSavingOptions) 0204 0205 #endif // KOSHAPESAVINGCONTEXT_H