File indexing completed on 2024-05-12 16:46:08
0001 /*************************************************************************** 0002 Copyright (C) 2003-2009 Robby Stephenson <robby@periapsis.org> 0003 ***************************************************************************/ 0004 0005 /*************************************************************************** 0006 * * 0007 * This program is free software; you can redistribute it and/or * 0008 * modify it under the terms of the GNU General Public License as * 0009 * published by the Free Software Foundation; either version 2 of * 0010 * the License or (at your option) version 3 or any later version * 0011 * accepted by the membership of KDE e.V. (or its successor approved * 0012 * by the membership of KDE e.V.), which shall act as a proxy * 0013 * defined in Section 14 of version 3 of the license. * 0014 * * 0015 * This program is distributed in the hope that it will be useful, * 0016 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0018 * GNU General Public License for more details. * 0019 * * 0020 * You should have received a copy of the GNU General Public License * 0021 * along with this program. If not, see <http://www.gnu.org/licenses/>. * 0022 * * 0023 ***************************************************************************/ 0024 0025 #ifndef TELLICO_IMAGE_H 0026 #define TELLICO_IMAGE_H 0027 0028 #include <QImage> 0029 #include <QString> 0030 #include <QByteArray> 0031 #include <QPixmap> 0032 0033 #if (QT_VERSION < QT_VERSION_CHECK(5, 10, 0)) 0034 using qsizetype = QIntegerForSizeof<std::size_t>::Signed; 0035 #endif 0036 0037 namespace Tellico { 0038 class ImageFactory; 0039 class ImageDirectory; 0040 class ImageZipArchive; 0041 class FileHandler; 0042 class ImageJob; 0043 0044 namespace Data { 0045 0046 /** 0047 * @author Robby Stephenson 0048 */ 0049 class Image : public QImage { 0050 0051 friend class Tellico::ImageFactory; 0052 friend class Tellico::ImageDirectory; 0053 friend class Tellico::ImageZipArchive; 0054 friend class Tellico::FileHandler; 0055 friend class Tellico::ImageJob; 0056 0057 public: 0058 ~Image(); 0059 0060 const QString& id() const { return m_id; }; 0061 const QByteArray& format() const { return m_format; }; 0062 QByteArray byteArray() const; 0063 bool isNull() const; 0064 bool linkOnly() const { return m_linkOnly; } 0065 void setLinkOnly(bool l) { m_linkOnly = l; } 0066 qsizetype byteSize() const; 0067 0068 QPixmap convertToPixmap() const; 0069 QPixmap convertToPixmap(int width, int height) const; 0070 0071 static QByteArray outputFormat(const QByteArray& inputFormat); 0072 static QByteArray byteArray(const QImage& img, const QByteArray& outputFormat); 0073 static QString idClean(const QString& id); 0074 static QString calculateID(const QByteArray& data, const QString& format); 0075 0076 static const Image null; 0077 0078 private: 0079 Image(); 0080 Image(const Image& image); 0081 Image& operator=(const Image&); 0082 explicit Image(const QString& filename, const QString& id = QString()); 0083 Image(const QImage& image, const QString& format); 0084 Image(const QByteArray& data, const QString& format, const QString& id); 0085 0086 void setID(const QString& id); 0087 void setFormat(const QByteArray& format_) { m_format = format_; } 0088 void calculateID(); 0089 0090 QString m_id; 0091 QByteArray m_format; 0092 bool m_linkOnly : 1; 0093 0094 static QList<QByteArray> s_outputFormats; 0095 }; 0096 0097 } // end namespace 0098 } // end namespace 0099 0100 inline bool operator== (const Tellico::Data::Image& img1, const Tellico::Data::Image& img2) { 0101 return img1.id() == img2.id(); 0102 } 0103 0104 #endif