author | alwin <alwin> | 2004-04-19 09:16:15 (UTC) |
---|---|---|
committer | alwin <alwin> | 2004-04-19 09:16:15 (UTC) |
commit | e3ca538f7ce2e7b7df2f29f263778acc342d51db (patch) (side-by-side diff) | |
tree | cb3e3c769ae12542d24eff7d17168635ddef65af | |
parent | 0b59a16b5a5a179c46ddb3f8c585dbca59b2826e (diff) | |
download | opie-e3ca538f7ce2e7b7df2f29f263778acc342d51db.zip opie-e3ca538f7ce2e7b7df2f29f263778acc342d51db.tar.gz opie-e3ca538f7ce2e7b7df2f29f263778acc342d51db.tar.bz2 |
re-enabled the cache as designed.
for that, pixcache has now a method setting the size of cache (parameter count
of pix) and it will switched between the different views.
setPixmap is overloaded that way, that we don't store the pix inside the
item but calling calcRect which is accessing the cached pixmap. voila.
Zecke: Should we make a configure item where users can setup how much
pix-previews should cache? Should we setup a thumbnail cache like .xvpics?
-rw-r--r-- | noncore/graphics/opie-eye/gui/iconview.cpp | 24 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/lib/imagecache.cpp | 6 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/lib/imagecache.h | 5 |
3 files changed, 26 insertions, 9 deletions
diff --git a/noncore/graphics/opie-eye/gui/iconview.cpp b/noncore/graphics/opie-eye/gui/iconview.cpp index 039f53f..d546b64 100644 --- a/noncore/graphics/opie-eye/gui/iconview.cpp +++ b/noncore/graphics/opie-eye/gui/iconview.cpp @@ -23,144 +23,143 @@ #include <qpe/qpeapplication.h> #include <qiconview.h> #include <qlabel.h> #include <qhbox.h> #include <qcombobox.h> #include <qdir.h> #include <qapplication.h> #include <qmainwindow.h> #include <qtimer.h> #include <qstyle.h> using Opie::Core::OKeyConfigItem; /* * The Icons, Request Cache and IconViewItem for the IconView */ namespace { static QPixmap* _dirPix = 0; static QPixmap* _unkPix = 0; static QPixmap* _picPix = 0; static QPixmap* _emptyPix = 0; class IconViewItem : public QIconViewItem { public: IconViewItem( QIconView*, const QString& path, const QString& name, bool isDir = false); QPixmap* pixmap()const; QString path()const { return m_path; } bool isDir()const { return m_isDir; } void setText( const QString& ); bool textOnly()const{return m_textOnly;} void setTextOnly(bool how){m_textOnly=how;} + /* just for starting recalc of item rect! */ virtual void setPixmap( const QPixmap & icon, bool recalc, bool redraw = TRUE ); + /* just for starting recalc of item rect! */ virtual void setPixmap( const QPixmap & icon); protected: mutable QPixmap* m_pix; private: QString m_path; bool m_isDir : 1; bool m_noInfo :1; bool m_textOnly:1; bool m_NameOnly:1; bool m_Pixset:1; }; class TextViewItem : public IconViewItem { TextViewItem( QIconView*, const QString& path, const QString& name, bool isDir = false ); QPixmap *pixmap()const; void setText( const QString& ); }; class ThumbViewItem : public IconViewItem { ThumbViewItem( QIconView*, const QString& path, const QString& name, bool isDir = false ); QPixmap *pixmap()const; void setText( const QString& ); }; /* * If we request an Image or String * we add it to the map */ static QMap<QString, IconViewItem*> g_stringInf; static QMap<QString, IconViewItem*> g_stringPix; IconViewItem::IconViewItem( QIconView* view,const QString& path, const QString& name, bool isDir ) : QIconViewItem( view, name ), m_path( path ), m_isDir( isDir ), m_noInfo( false ),m_textOnly(false),m_Pixset(false) { if ( isDir && !_dirPix ) _dirPix = new QPixmap( Resource::loadPixmap("advancedfm/FileBrowser")); else if ( !isDir && !_unkPix ) _unkPix = new QPixmap( Resource::loadPixmap( "UnknownDocument" ) ); } inline void IconViewItem::setPixmap( const QPixmap & icon, bool recalc, bool redraw) { m_Pixset = true; - QIconViewItem::setPixmap(icon,recalc,redraw); + calcRect(text()); } inline void IconViewItem::setPixmap( const QPixmap & icon) { m_Pixset = true; - QIconViewItem::setPixmap(icon); + calcRect(text()); } inline QPixmap* IconViewItem::pixmap()const { // qWarning( "Name is " + m_path.right( 15 ) + " rect is %d %d %d %d | %d %d", // rect().x(),rect().y(),rect().width(),rect().height(), // iconView()->contentsX(), iconView()->contentsY()); if (textOnly()&&!m_isDir) { if (!_emptyPix) _emptyPix = new QPixmap(0,0,1); return _emptyPix; } if ( m_isDir ) return _dirPix; else{ if (!m_noInfo && !g_stringInf.contains( m_path ) ) { currentView()->dirLister()->imageInfo( m_path ); g_stringInf.insert( m_path, const_cast<IconViewItem*>(this)); } m_pix = PPixmapCache::self()->cachedImage( m_path, 64, 64 ); - if (!m_pix && !g_stringPix.contains( m_path )&&!m_Pixset) { + if (!m_pix && !g_stringPix.contains( m_path )) { currentView()->dirLister()->thumbNail( m_path, 64, 64 ); g_stringPix.insert( m_path, const_cast<IconViewItem*>(this)); } - if (m_Pixset) { - return QIconViewItem::pixmap(); - } return m_pix ? m_pix : _unkPix; } } inline void IconViewItem::setText( const QString& str ) { QString text = QIconViewItem::text()+"\n"+str; m_noInfo = true; QIconViewItem::setText( text ); } } /* * Set up the GUI.. initialize the slave set up gui * and also load a dir */ PIconView::PIconView( QWidget* wid, Opie::Core::OConfig* cfg ) : QVBox( wid ), m_cfg( cfg ), m_updatet( false ) { { QCopEnvelope( "QPE/Application/opie-eye_slave", "refUp()" ); } m_path = QDir::homeDirPath(); m_mode = 0; QHBox *hbox = new QHBox( this ); QLabel* lbl = new QLabel( hbox ); lbl->setText( tr("View as" ) ); m_views = new QComboBox( hbox, "View As" ); connect( m_views, SIGNAL(activated(int)), this, SLOT(slotViewChanged(int)) ); @@ -380,67 +379,71 @@ void PIconView::slotViewChanged( int i) { /* reload now */ QTimer::singleShot( 0, this, SLOT(slotReloadDir())); } void PIconView::slotReloadDir() { slotChangeDir( m_path ); } /* * add files and folders */ void PIconView::addFolders( const QStringList& lst) { QStringList::ConstIterator it; IconViewItem * _iv; for(it=lst.begin(); it != lst.end(); ++it ) { _iv = new IconViewItem( m_view, m_path+"/"+(*it), (*it), true ); if (m_mode==3) _iv->setTextOnly(true); } } void PIconView::addFiles( const QStringList& lst) { QStringList::ConstIterator it; IconViewItem * _iv; QPixmap*m_pix = 0; for (it=lst.begin(); it!= lst.end(); ++it ) { m_pix = PPixmapCache::self()->cachedImage( m_path+"/"+(*it), 64, 64 ); _iv = new IconViewItem( m_view, m_path+"/"+(*it), (*it) ); - if (m_mode==3) _iv->setTextOnly(true); + if (m_mode==3) { + _iv->setTextOnly(true); + _iv->setPixmap(QPixmap()); + } else { if (m_pix) _iv->setPixmap(*m_pix); } + } } /* * user clicked on the item. Change dir or view */ void PIconView::slotClicked(QIconViewItem* _it) { if(!_it ) return; IconViewItem* it = static_cast<IconViewItem*>(_it); if( it->isDir() ) slotChangeDir( it->path() ); else // view image slotShowImage(); } /* * got thumb info add to the cache if items is visible * we later need update after processing of slave is done */ void PIconView::slotThumbInfo( const QString& _path, const QString& str ) { IconViewItem* item = g_stringInf[_path]; if (!item ) return; if (m_mode == 2) { return; } if ( item->intersects(QRect( m_view->contentsX(),m_view->contentsY(), m_view->contentsWidth(), m_view->contentsHeight() ) ) ) m_updatet = true; @@ -563,46 +566,49 @@ void PIconView::slotChangeMode( int mode ) { m_mode = mode; QIconView::ItemTextPos pos; switch( m_mode ) { case 2: pos = QIconView::Bottom; break; case 3: case 1: default: pos = QIconView::Right; break; } m_view->setItemTextPos( pos ); calculateGrid(); slotReloadDir(); } void PIconView::resizeEvent( QResizeEvent* re ) { QVBox::resizeEvent( re ); calculateGrid(); } void PIconView::calculateGrid() { odebug << "Calc grid: x=" << m_view->gridX() << " y=" << m_view->gridY() << oendl; odebug << "Size of view: " << m_view->size() << oendl; switch (m_mode) { case 2: - m_view->setGridX(80); - m_view->setGridY(80); + m_view->setGridX(50); + m_view->setGridY(20); + PPixmapCache::self()->setMaxImages(40); break; case 3: m_view->setGridX(m_view->width()); m_view->setGridY(8); + PPixmapCache::self()->setMaxImages(2); break; case 1: default: m_view->setGridX(m_view->width()); m_view->setGridY(80); + PPixmapCache::self()->setMaxImages(20); break; } } diff --git a/noncore/graphics/opie-eye/lib/imagecache.cpp b/noncore/graphics/opie-eye/lib/imagecache.cpp index 3b74a83..f1042a4 100644 --- a/noncore/graphics/opie-eye/lib/imagecache.cpp +++ b/noncore/graphics/opie-eye/lib/imagecache.cpp @@ -33,55 +33,61 @@ PImageCache* PImageCache::self() { QImage* PImageCache::cachedImage( const QString& _path, int ori, int max ) { QString path = QString( "%1_%2:" ).arg( ori ).arg( max ); path += _path; QImage* img = find( path ); if ( !img ) { // img = currentView()->dirLister()->image( _path, PDirLister::Factor(ori), max); // insertImage( _path, img, ori, max ); currentView()->dirLister()->image( _path, PDirLister::Factor( ori ), max ); } return img; } void PImageCache::insertImage( const QString& _path, const QImage* img, int ori, int max ) { QString path = QString("%1_%2:" ).arg( ori ).arg( max ); path += _path; insert( path, img, (img->height()*img->width()*img->depth())/8 ); } PPixmapCache::PPixmapCache() { /* * 20 64x64 16 bit images */ setMaxCost( 64*64*QPixmap::defaultDepth()/8*20 ); } PPixmapCache::~PPixmapCache() { } +void PPixmapCache::setMaxImages(unsigned int aMax) +{ + m_MaxImages = aMax; + setMaxCost( 64*64*QPixmap::defaultDepth()/8*m_MaxImages); +} + PPixmapCache* PPixmapCache::self() { if ( !_pxmCache ) _pxmCache = new PPixmapCache; return _pxmCache; } QPixmap* PPixmapCache::cachedImage( const QString& _path, int width, int height ) { QString path = QString( "%1_%2:" ).arg( width ).arg( height ); path += _path; QPixmap* pxm = find( path ); return pxm; } void PPixmapCache::insertImage( const QString& _path, const QPixmap* pix, int width, int height ) { QString path = QString("%1_%2:" ).arg( width ).arg( height ); path += _path; insert( path, pix, (pix->height()*pix->width()*pix->depth())/8 ); } diff --git a/noncore/graphics/opie-eye/lib/imagecache.h b/noncore/graphics/opie-eye/lib/imagecache.h index 076ecd3..939247a 100644 --- a/noncore/graphics/opie-eye/lib/imagecache.h +++ b/noncore/graphics/opie-eye/lib/imagecache.h @@ -1,46 +1,51 @@ /* * GPLv2 zecke@handhelds.org * No WArranty... */ #ifndef PHUNK_IMAGE_CACHE_H #define PHUNK_IMAGE_CACHE_H #include <qimage.h> #include <qpixmap.h> #include <qcache.h> class PImageCache : public QCache<QImage> { private: PImageCache(); ~PImageCache(); public: static PImageCache *self(); QImage* cachedImage( const QString& path, int orientation = 3, int max = 0); //const; void insertImage( const QString& path, const QImage &, int orien = 3, int max = 0); void insertImage( const QString& path, const QImage *, int orien=3, int max = 0 ); }; class PPixmapCache : public QCache<QPixmap> { private: PPixmapCache(); ~PPixmapCache(); + + unsigned int m_MaxImages; + public: static PPixmapCache *self(); QPixmap* cachedImage( const QString& path, int width, int height ); void insertImage( const QString& path, const QPixmap &, int width, int height ); void insertImage( const QString& path, const QPixmap *, int width, int height ); + void setMaxImages(unsigned int aMax); + unsigned int maxImages()const{return m_MaxImages;} }; inline void PPixmapCache::insertImage( const QString& path, const QPixmap& p, int width, int height ) { insertImage( path, new QPixmap( p ), width, height ); } inline void PImageCache::insertImage( const QString& path, const QImage& p, int width, int height ) { insertImage( path, new QImage( p ), width, height ); } #endif |