Warning, file /office/calligra/libs/flake/KoImageData.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* This file is part of the KDE project 0002 * Copyright (C) 2007, 2009 Thomas Zander <zander@kde.org> 0003 * Copyright (C) 2007 Jan Hambrecht <jaham@gmx.net> 0004 * Copyright (C) 2008 Thorsten Zachmann <zachmann@kde.org> 0005 * 0006 * This library is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU Library General Public 0008 * License as published by the Free Software Foundation; either 0009 * version 2 of the License, or (at your option) any later version. 0010 * 0011 * This library is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0014 * Library General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU Library General Public License 0017 * along with this library; see the file COPYING.LIB. If not, write to 0018 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0019 * Boston, MA 02110-1301, USA. 0020 */ 0021 #ifndef KOIMAGEDATA_H 0022 #define KOIMAGEDATA_H 0023 0024 #include "flake_export.h" 0025 0026 #include <QSize> 0027 #include <QMetaType> 0028 0029 #include <KoShapeUserData.h> 0030 0031 class QIODevice; 0032 class QPixmap; 0033 class QImage; 0034 class QSizeF; 0035 class QUrl; 0036 class KoImageCollection; 0037 class KoImageDataPrivate; 0038 class KoStore; 0039 0040 /** 0041 * This class is meant to represent the image data so it can be shared between image shapes. 0042 * 0043 * This class inherits from KoShapeUserData which means you can set it on any KoShape using 0044 * KoShape::setUserData() and get it using KoShape::userData(). The pictureshape plugin 0045 * uses this class to show its image data. 0046 * 0047 * Plugins should not make a copy of the pixmap data, but use the pixmap() method, which 0048 * handles caching. 0049 */ 0050 class FLAKE_EXPORT KoImageData : public KoShapeUserData 0051 { 0052 Q_OBJECT 0053 public: 0054 /// Various error codes representing what has gone wrong 0055 enum ErrorCode { 0056 Success, 0057 OpenFailed, 0058 StorageFailed, ///< This is set if the image data has to be stored on disk in a temporary file, but we failed to do so 0059 LoadFailed 0060 }; 0061 0062 /// default constructor, creates an invalid imageData object 0063 KoImageData(); 0064 0065 ~KoImageData() override; 0066 KoImageData(const KoImageData &imageData); 0067 KoImageData &operator=(const KoImageData &other); 0068 inline bool operator!=(const KoImageData &other) const { return !operator==(other); } 0069 bool operator==(const KoImageData &other) const; 0070 0071 void setImage(const QString &location, KoStore *store, KoImageCollection *collection = 0); 0072 0073 /** 0074 * Renders a pixmap the first time you request it is called and returns it. 0075 * @returns the cached pixmap 0076 * @see isValid(), hasCachedPixmap() 0077 */ 0078 QPixmap pixmap(const QSize &targetSize = QSize()); 0079 0080 /** 0081 * Return the internal store of the image. 0082 * @see isValid(), hasCachedImage() 0083 */ 0084 QImage image() const; 0085 0086 /** 0087 * The size of the image in points 0088 */ 0089 QSizeF imageSize(); 0090 0091 /** 0092 * Save the image data to the param device. 0093 * The full file is saved. 0094 * @param device the device that is used to get the data from. 0095 * @return returns true if load was successful. 0096 */ 0097 bool saveData(QIODevice &device); 0098 0099 /** 0100 * Get a unique key of the image data 0101 */ 0102 qint64 key() const; 0103 0104 /// @return the original image file's extension, e.g. "png" or "gif" 0105 QString suffix() const; 0106 0107 ErrorCode errorCode() const; 0108 0109 /// returns if this is a valid imageData with actual image data present on it. 0110 bool isValid() const; 0111 0112 /// \internal 0113 KoImageDataPrivate *priv() { return d; } 0114 0115 private: 0116 friend class KoImageCollection; 0117 friend class TestImageCollection; 0118 0119 0120 explicit KoImageData(KoImageDataPrivate *priv); 0121 0122 /// returns true only if pixmap() would return immediately with a cached pixmap 0123 bool hasCachedPixmap() const; 0124 0125 /// returns true only if image() would return immediately with a cached image 0126 bool hasCachedImage() const; 0127 0128 void setImage(const QImage &image, KoImageCollection *collection = 0); 0129 void setImage(const QByteArray &imageData, KoImageCollection *collection = 0); 0130 0131 0132 private: 0133 KoImageDataPrivate *d; 0134 Q_PRIVATE_SLOT(d, void cleanupImageCache()) 0135 }; 0136 0137 Q_DECLARE_METATYPE(KoImageData*) 0138 0139 #endif