00001
00002
00003
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
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
00040
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
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 }