File indexing completed on 2024-05-12 05:09:49

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 class TellicoReadTest;
0034 namespace Tellico {
0035   class ImageFactory;
0036   class ImageDirectory;
0037   class ImageZipArchive;
0038   class FileHandler;
0039   class ImageJob;
0040 
0041   namespace Data {
0042 
0043 /**
0044  * @author Robby Stephenson
0045  */
0046 class Image : public QImage {
0047 
0048 friend class ::TellicoReadTest;
0049 friend class Tellico::ImageFactory;
0050 friend class Tellico::ImageDirectory;
0051 friend class Tellico::ImageZipArchive;
0052 friend class Tellico::FileHandler;
0053 friend class Tellico::ImageJob;
0054 
0055 public:
0056   ~Image();
0057 
0058   const QString& id() const { return m_id; };
0059   const QByteArray& format() const { return m_format; };
0060   QByteArray byteArray() const;
0061   bool isNull() const;
0062   bool linkOnly() const { return m_linkOnly; }
0063   void setLinkOnly(bool l) { m_linkOnly = l; }
0064 
0065   QPixmap convertToPixmap() const;
0066   QPixmap convertToPixmap(int width, int height) const;
0067 
0068   static QByteArray outputFormat(const QByteArray& inputFormat);
0069   static QByteArray byteArray(const QImage& img, const QByteArray& outputFormat);
0070   static QString idClean(const QString& id);
0071   static QString calculateID(const QByteArray& data, const QString& format);
0072 
0073   static const Image null;
0074 
0075 private:
0076   Image();
0077   Image(const Image& image);
0078   Image& operator=(const Image&);
0079   explicit Image(const QString& filename, const QString& id = QString());
0080   Image(const QImage& image, const QString& format);
0081   Image(const QByteArray& data, const QString& format, const QString& id);
0082 
0083   void setID(const QString& id);
0084   void setFormat(const QByteArray& format_) { m_format = format_; }
0085   void calculateID();
0086 
0087   QString m_id;
0088   QByteArray m_format;
0089   bool m_linkOnly : 1;
0090 
0091   static QList<QByteArray> s_outputFormats;
0092 };
0093 
0094   } // end namespace
0095 } // end namespace
0096 
0097 inline bool operator== (const Tellico::Data::Image& img1, const Tellico::Data::Image& img2) {
0098   return img1.id() == img2.id();
0099 }
0100 
0101 #endif