File indexing completed on 2024-05-05 16:39:03
0001 /* This file is part of the KDE project 0002 Copyright (C) 2003,2009 Carsten Pfeiffer <pfeiffer@kde.org> 0003 0004 This program is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU General Public 0006 License as published by the Free Software Foundation, version 2. 0007 0008 This program is distributed in the hope that it will be useful, 0009 but WITHOUT ANY WARRANTY; without even the implied warranty of 0010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0011 General Public License for more details. 0012 0013 You should have received a copy of the GNU General Public License 0014 along with this program; see the file COPYING. If not, write to 0015 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0016 Boston, MA 02110-1301, USA. 0017 */ 0018 0019 #ifndef KUICKIMAGE_H 0020 #define KUICKIMAGE_H 0021 0022 #include <QObject> 0023 0024 #include "imlib-wrapper.h" 0025 0026 #include "kuickdata.h" 0027 #include "kuickfile.h" 0028 0029 class QImage; 0030 class QUrl; 0031 0032 0033 class KuickImage : public QObject 0034 { 0035 Q_OBJECT 0036 0037 public: 0038 enum ResizeMode { FAST, SMOOTH }; 0039 0040 KuickImage( const KuickFile * file, ImlibImage *im, ImlibData *id ); 0041 ~KuickImage(); 0042 0043 int width() const { return myWidth; } 0044 int height() const { return myHeight; } 0045 int originalWidth() const { return myOrigWidth; } 0046 int originalHeight() const { return myOrigHeight; } 0047 0048 /** 0049 * Returns true if this image is modified against the original loaded 0050 * version from disk. I.e. resized, rotated, flipped. 0051 */ 0052 bool isModified() const; 0053 void resize( int width, int height, KuickImage::ResizeMode mode ); 0054 void restoreOriginalSize(); 0055 void rotate( Rotation rot ); 0056 bool rotateAbs( Rotation rot ); 0057 void flip( FlipMode flipMode ); 0058 bool flipAbs( int mode ); 0059 ImlibImage * imlibImage() const { return myIm; } 0060 Pixmap& pixmap(); 0061 void renderPixmap(); 0062 // const QString& filename() const { return myFilename;} 0063 const KuickFile& file() const { return *myFile; } 0064 QUrl url() const { return myFile->url(); } 0065 0066 void setDirty( bool d ) { myIsDirty = d; } 0067 /** 0068 * Returns true if this image is "dirty", i.e some operation was done, 0069 * and it needs re-rendering. 0070 */ 0071 bool isDirty() const { return myIsDirty; } 0072 Rotation absRotation() const { return myRotation; } 0073 FlipMode flipMode() const { return myFlipMode; } 0074 0075 static ImlibImage * toImage( ImlibData *id, QImage& image ); 0076 0077 private: 0078 void fastResize( int newWidth, int newHeight ); 0079 bool smoothResize( int width, int height ); 0080 /** 0081 * Note: caller must delete it! 0082 */ 0083 QImage * newQImage() const; 0084 0085 const KuickFile * myFile; 0086 0087 int myWidth; 0088 int myHeight; 0089 ImlibImage * myOrigIm; 0090 ImlibImage * myIm; 0091 ImlibData * myId; 0092 Pixmap myPixmap; 0093 bool myIsDirty; 0094 0095 int myOrigWidth; 0096 int myOrigHeight; 0097 Rotation myRotation; 0098 FlipMode myFlipMode; 0099 0100 signals: 0101 void startRendering(); 0102 void stoppedRendering(); 0103 }; 0104 0105 0106 #endif // KUICKIMAGE_H