File indexing completed on 2024-05-05 16:39:02
0001 /**************************************************************************** 0002 ** $Id$ 0003 ** 0004 ** ImlibWidget: maps an Xlib window with Imlib's contents on a QWidget 0005 ** 0006 ** Created : 98 0007 ** 0008 ** Copyright (C) 1998-2001 by Carsten Pfeiffer. All rights reserved. 0009 ** 0010 ****************************************************************************/ 0011 0012 #ifndef IMLIBWIDGET_H 0013 #define IMLIBWIDGET_H 0014 0015 #include <QCursor> 0016 #include <QObject> 0017 #include <QWidget> 0018 #include <QX11Info> 0019 0020 #include "imlib-wrapper.h" 0021 0022 #include "imdata.h" 0023 #include "kuickdata.h" 0024 0025 class QCloseEvent; 0026 class QColor; 0027 class QUrl; 0028 class KuickFile; 0029 class KuickImage; 0030 0031 0032 class ImageCache : public QObject 0033 { 0034 Q_OBJECT 0035 0036 public: 0037 ImageCache( ImlibData *id, int maxImages=1 ); 0038 ~ImageCache(); 0039 0040 void setMaxImages( int maxImages ); 0041 int maxImages() const { return myMaxImages; } 0042 0043 KuickImage * getKuimage( KuickFile * file ); 0044 KuickImage * loadImage( KuickFile *file, ImlibColorModifier ); 0045 // KuickImage * find( const QString& filename ); 0046 0047 private: 0048 ImlibImage * loadImageWithQt( const QString& filename ) const; 0049 0050 int myMaxImages; 0051 QList<KuickFile*> fileList; 0052 QList<KuickImage*> kuickList; 0053 // QPtrList<ImlibImage> imList; 0054 ImlibData * myId; 0055 int idleCount; 0056 0057 private slots: 0058 void slotBusy(); 0059 void slotIdle(); 0060 0061 signals: 0062 void sigBusy(); 0063 void sigIdle(); 0064 0065 }; 0066 0067 0068 // ------------------------------------------ 0069 0070 0071 class ImlibWidget : public QWidget 0072 { 0073 Q_OBJECT 0074 0075 public: 0076 0077 ImlibWidget( ImData *_idata=0, QWidget *parent=0 ); 0078 ImlibWidget( ImData *_idata, ImlibData *id, QWidget *parent=0 ); 0079 virtual ~ImlibWidget(); 0080 0081 QUrl url() const; 0082 KuickFile * currentFile() const; 0083 bool loadImage( KuickFile * file); 0084 bool loadImage( const QUrl& url ); 0085 bool cacheImage( const QUrl& url ); 0086 void zoomImage( float ); 0087 void setBrightness( int ); 0088 void setContrast( int ); 0089 void setGamma( int ); 0090 void setRotation( Rotation ); 0091 void setFlipMode( int mode ); 0092 0093 int brightness() const; 0094 int contrast() const; 0095 int gamma() const; 0096 Rotation rotation() const; 0097 FlipMode flipMode() const; 0098 0099 int imageWidth() const; 0100 int imageHeight() const; 0101 0102 void setAutoRender( bool enable ) { isAutoRendering = enable;} 0103 bool isAutoRenderEnabled() const { return isAutoRendering; } 0104 void setMaxImageCache( int ); 0105 int maxImageCache() const { return myMaxImageCache; } 0106 const QColor& backgroundColor() const; 0107 void setBackgroundColor( const QColor& ); 0108 0109 /** 0110 * @return true if auto-rotation is not possible, e.g. because no metadata 0111 * about orientation is available 0112 */ 0113 virtual bool autoRotate( KuickImage *kuim ); 0114 0115 ImlibData* getImlibData() const { return id; } 0116 0117 // virtual void reparent( QWidget* parent, Qt::WFlags f, const QPoint& p, bool showIt = false ); 0118 0119 public slots: 0120 void rotate90(); 0121 void rotate270(); 0122 void rotate180(); 0123 void flipHoriz(); 0124 void flipVert(); 0125 void showImageOriginalSize(); 0126 inline void updateImage() { updateWidget( true ); } 0127 0128 0129 protected: 0130 Display * getX11Display() const { return QX11Info::display(); } 0131 int getX11Screen() const; 0132 KuickImage * loadImageInternal( KuickFile * file ); 0133 void showImage(); 0134 void setImageModifier(); 0135 void rotate( int ); 0136 void updateWidget( bool geometryUpdate=true ); 0137 virtual void updateGeometry( int width, int height ); 0138 virtual void loaded( KuickImage *, bool wasCached ); 0139 virtual bool canZoomTo( int newWidth, int newHeight ); 0140 virtual void rotated( KuickImage *kuim, int rotation ); 0141 0142 void closeEvent(QCloseEvent *) override; 0143 0144 inline void autoUpdate( bool geometryUpdate=false ) { 0145 if ( isAutoRendering ) 0146 updateWidget( geometryUpdate ); 0147 } 0148 0149 bool stillResizing, deleteImData, deleteImlibData; 0150 bool imlibModifierChanged; 0151 0152 KuickImage *m_kuim; 0153 ImageCache *imageCache; 0154 ImlibData *id; 0155 ImData *idata; 0156 Window win; 0157 ImlibColorModifier mod; 0158 0159 KuickFile *m_kuickFile; 0160 QCursor m_oldCursor; 0161 0162 static const int ImlibOffset; 0163 0164 0165 private: 0166 void init(); 0167 bool isAutoRendering; 0168 int myMaxImageCache; 0169 QColor myBackgroundColor; 0170 0171 0172 protected slots: 0173 bool cacheImage( KuickFile *file ); 0174 void setBusyCursor(); 0175 void restoreCursor(); 0176 0177 0178 signals: 0179 void sigImageError( const KuickFile * file, const QString& ); 0180 0181 }; 0182 0183 0184 #endif