Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

imagecache.cpp

Go to the documentation of this file.
00001 /*
00002  * GPLv2 zecke@handhelds.org
00003  * No WArranty...
00004  */
00005 
00006 #include <iface/dirview.h>
00007 #include <iface/dirlister.h>
00008 
00009 #include "imagecache.h"
00010 
00011 namespace {
00012     PImageCache * _imgCache = 0;
00013     PPixmapCache* _pxmCache = 0;
00014 }
00015 
00016 
00017 PImageCache::PImageCache()
00018     : QCache<QImage>()
00019 {
00020     /* just to set an initial value.. 4 big images */
00021     setMaxCost( (1024*1024*16)/8*4 );
00022 }
00023 
00024 PImageCache::~PImageCache() {
00025 }
00026 
00027 PImageCache* PImageCache::self() {
00028     if ( !_imgCache )
00029         _imgCache = new PImageCache;
00030     return _imgCache;
00031 }
00032 
00033 QImage* PImageCache::cachedImage( const QString& _path, int ori, int max ) {
00034     QString path = QString( "%1_%2:" ).arg( ori ).arg( max );
00035     path += _path;
00036 
00037     QImage* img = find( path );
00038     if ( !img ) {
00039 //        img = currentView()->dirLister()->image( _path, PDirLister::Factor(ori),  max);
00040 //        insertImage(  _path, img, ori, max );
00041         currentView()->dirLister()->image( _path, PDirLister::Factor( ori ), max );
00042     }
00043 
00044 
00045     return  img;
00046 }
00047 
00048 void PImageCache::insertImage(  const QString& _path,  const QImage* img, int ori, int max ) {
00049     QString path = QString("%1_%2:" ).arg( ori ).arg( max );
00050     path += _path;
00051     insert( path, img, (img->height()*img->width()*img->depth())/8 );
00052 }
00053 
00054 
00055 PPixmapCache::PPixmapCache() {
00056   /*
00057    * 20 64x64 16 bit images
00058    */
00059     setMaxCost( 64*64*QPixmap::defaultDepth()/8*20 );
00060 }
00061 
00062 PPixmapCache::~PPixmapCache() {
00063 }
00064 
00065 void PPixmapCache::setMaxImages(unsigned int aMax)
00066 {
00067     m_MaxImages = aMax;
00068     setMaxCost( 64*64*QPixmap::defaultDepth()/8*m_MaxImages);
00069 }
00070 
00071 PPixmapCache* PPixmapCache::self() {
00072     if ( !_pxmCache )
00073         _pxmCache = new PPixmapCache;
00074 
00075     return _pxmCache;
00076 }
00077 
00078 QPixmap* PPixmapCache::cachedImage( const QString& _path, int width, int height ) {
00079     QString path = QString( "%1_%2:" ).arg( width ).arg( height );
00080     path += _path;
00081 
00082     QPixmap* pxm = find( path );
00083 
00084 
00085 
00086     return  pxm;
00087 }
00088 
00089 void PPixmapCache::insertImage( const QString& _path, const QPixmap* pix, int width, int height ) {
00090     QString path = QString("%1_%2:" ).arg( width ).arg( height );
00091     path += _path;
00092     insert( path, pix, (pix->height()*pix->width()*pix->depth())/8 );
00093 }

Generated on Sat Nov 5 16:17:30 2005 for OPIE by  doxygen 1.4.2