summaryrefslogtreecommitdiff
authoralwin <alwin>2004-04-19 09:16:15 (UTC)
committer alwin <alwin>2004-04-19 09:16:15 (UTC)
commite3ca538f7ce2e7b7df2f29f263778acc342d51db (patch) (unidiff)
treecb3e3c769ae12542d24eff7d17168635ddef65af
parent0b59a16b5a5a179c46ddb3f8c585dbca59b2826e (diff)
downloadopie-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?
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/graphics/opie-eye/gui/iconview.cpp26
-rw-r--r--noncore/graphics/opie-eye/lib/imagecache.cpp6
-rw-r--r--noncore/graphics/opie-eye/lib/imagecache.h5
3 files changed, 27 insertions, 10 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
@@ -43,25 +43,27 @@ namespace {
43 static QPixmap* _unkPix = 0; 43 static QPixmap* _unkPix = 0;
44 static QPixmap* _picPix = 0; 44 static QPixmap* _picPix = 0;
45 static QPixmap* _emptyPix = 0; 45 static QPixmap* _emptyPix = 0;
46 class IconViewItem : public QIconViewItem { 46 class IconViewItem : public QIconViewItem {
47 public: 47 public:
48 IconViewItem( QIconView*, const QString& path, const QString& name, bool isDir = false); 48 IconViewItem( QIconView*, const QString& path, const QString& name, bool isDir = false);
49 QPixmap* pixmap()const; 49 QPixmap* pixmap()const;
50 QString path()const { return m_path; } 50 QString path()const { return m_path; }
51 bool isDir()const { return m_isDir; } 51 bool isDir()const { return m_isDir; }
52 void setText( const QString& ); 52 void setText( const QString& );
53 bool textOnly()const{return m_textOnly;} 53 bool textOnly()const{return m_textOnly;}
54 void setTextOnly(bool how){m_textOnly=how;} 54 void setTextOnly(bool how){m_textOnly=how;}
55 /* just for starting recalc of item rect! */
55 virtual void setPixmap( const QPixmap & icon, bool recalc, bool redraw = TRUE ); 56 virtual void setPixmap( const QPixmap & icon, bool recalc, bool redraw = TRUE );
57 /* just for starting recalc of item rect! */
56 virtual void setPixmap( const QPixmap & icon); 58 virtual void setPixmap( const QPixmap & icon);
57 59
58 protected: 60 protected:
59 mutable QPixmap* m_pix; 61 mutable QPixmap* m_pix;
60 62
61 private: 63 private:
62 QString m_path; 64 QString m_path;
63 bool m_isDir : 1; 65 bool m_isDir : 1;
64 bool m_noInfo :1; 66 bool m_noInfo :1;
65 bool m_textOnly:1; 67 bool m_textOnly:1;
66 bool m_NameOnly:1; 68 bool m_NameOnly:1;
67 bool m_Pixset:1; 69 bool m_Pixset:1;
@@ -90,57 +92,54 @@ namespace {
90 : QIconViewItem( view, name ), m_path( path ), m_isDir( isDir ), 92 : QIconViewItem( view, name ), m_path( path ), m_isDir( isDir ),
91 m_noInfo( false ),m_textOnly(false),m_Pixset(false) 93 m_noInfo( false ),m_textOnly(false),m_Pixset(false)
92 { 94 {
93 if ( isDir && !_dirPix ) 95 if ( isDir && !_dirPix )
94 _dirPix = new QPixmap( Resource::loadPixmap("advancedfm/FileBrowser")); 96 _dirPix = new QPixmap( Resource::loadPixmap("advancedfm/FileBrowser"));
95 else if ( !isDir && !_unkPix ) 97 else if ( !isDir && !_unkPix )
96 _unkPix = new QPixmap( Resource::loadPixmap( "UnknownDocument" ) ); 98 _unkPix = new QPixmap( Resource::loadPixmap( "UnknownDocument" ) );
97 } 99 }
98 100
99 inline void IconViewItem::setPixmap( const QPixmap & icon, bool recalc, bool redraw) 101 inline void IconViewItem::setPixmap( const QPixmap & icon, bool recalc, bool redraw)
100 { 102 {
101 m_Pixset = true; 103 m_Pixset = true;
102 QIconViewItem::setPixmap(icon,recalc,redraw); 104 calcRect(text());
103 } 105 }
104 inline void IconViewItem::setPixmap( const QPixmap & icon) 106 inline void IconViewItem::setPixmap( const QPixmap & icon)
105 { 107 {
106 m_Pixset = true; 108 m_Pixset = true;
107 QIconViewItem::setPixmap(icon); 109 calcRect(text());
108 } 110 }
109 111
110 inline QPixmap* IconViewItem::pixmap()const { 112 inline QPixmap* IconViewItem::pixmap()const {
111// qWarning( "Name is " + m_path.right( 15 ) + " rect is %d %d %d %d | %d %d", 113// qWarning( "Name is " + m_path.right( 15 ) + " rect is %d %d %d %d | %d %d",
112// rect().x(),rect().y(),rect().width(),rect().height(), 114// rect().x(),rect().y(),rect().width(),rect().height(),
113// iconView()->contentsX(), iconView()->contentsY()); 115// iconView()->contentsX(), iconView()->contentsY());
114 116
115 if (textOnly()&&!m_isDir) { 117 if (textOnly()&&!m_isDir) {
116 if (!_emptyPix) _emptyPix = new QPixmap(0,0,1); 118 if (!_emptyPix) _emptyPix = new QPixmap(0,0,1);
117 return _emptyPix; 119 return _emptyPix;
118 } 120 }
119 if ( m_isDir ) 121 if ( m_isDir )
120 return _dirPix; 122 return _dirPix;
121 else{ 123 else{
122 if (!m_noInfo && !g_stringInf.contains( m_path ) ) { 124 if (!m_noInfo && !g_stringInf.contains( m_path ) ) {
123 currentView()->dirLister()->imageInfo( m_path ); 125 currentView()->dirLister()->imageInfo( m_path );
124 g_stringInf.insert( m_path, const_cast<IconViewItem*>(this)); 126 g_stringInf.insert( m_path, const_cast<IconViewItem*>(this));
125 } 127 }
126 128
127 m_pix = PPixmapCache::self()->cachedImage( m_path, 64, 64 ); 129 m_pix = PPixmapCache::self()->cachedImage( m_path, 64, 64 );
128 if (!m_pix && !g_stringPix.contains( m_path )&&!m_Pixset) { 130 if (!m_pix && !g_stringPix.contains( m_path )) {
129 currentView()->dirLister()->thumbNail( m_path, 64, 64 ); 131 currentView()->dirLister()->thumbNail( m_path, 64, 64 );
130 g_stringPix.insert( m_path, const_cast<IconViewItem*>(this)); 132 g_stringPix.insert( m_path, const_cast<IconViewItem*>(this));
131 } 133 }
132 if (m_Pixset) {
133 return QIconViewItem::pixmap();
134 }
135 return m_pix ? m_pix : _unkPix; 134 return m_pix ? m_pix : _unkPix;
136 } 135 }
137 } 136 }
138 inline void IconViewItem::setText( const QString& str ) { 137 inline void IconViewItem::setText( const QString& str ) {
139 QString text = QIconViewItem::text()+"\n"+str; 138 QString text = QIconViewItem::text()+"\n"+str;
140 m_noInfo = true; 139 m_noInfo = true;
141 QIconViewItem::setText( text ); 140 QIconViewItem::setText( text );
142 } 141 }
143} 142}
144 143
145 144
146/* 145/*
@@ -400,26 +399,30 @@ void PIconView::addFolders( const QStringList& lst) {
400 _iv = new IconViewItem( m_view, m_path+"/"+(*it), (*it), true ); 399 _iv = new IconViewItem( m_view, m_path+"/"+(*it), (*it), true );
401 if (m_mode==3) _iv->setTextOnly(true); 400 if (m_mode==3) _iv->setTextOnly(true);
402 } 401 }
403} 402}
404 403
405void PIconView::addFiles( const QStringList& lst) { 404void PIconView::addFiles( const QStringList& lst) {
406 QStringList::ConstIterator it; 405 QStringList::ConstIterator it;
407 IconViewItem * _iv; 406 IconViewItem * _iv;
408 QPixmap*m_pix = 0; 407 QPixmap*m_pix = 0;
409 for (it=lst.begin(); it!= lst.end(); ++it ) { 408 for (it=lst.begin(); it!= lst.end(); ++it ) {
410 m_pix = PPixmapCache::self()->cachedImage( m_path+"/"+(*it), 64, 64 ); 409 m_pix = PPixmapCache::self()->cachedImage( m_path+"/"+(*it), 64, 64 );
411 _iv = new IconViewItem( m_view, m_path+"/"+(*it), (*it) ); 410 _iv = new IconViewItem( m_view, m_path+"/"+(*it), (*it) );
412 if (m_mode==3) _iv->setTextOnly(true); 411 if (m_mode==3) {
413 if (m_pix) _iv->setPixmap(*m_pix); 412 _iv->setTextOnly(true);
413 _iv->setPixmap(QPixmap());
414 } else {
415 if (m_pix) _iv->setPixmap(*m_pix);
416 }
414 } 417 }
415 418
416} 419}
417 420
418/* 421/*
419 * user clicked on the item. Change dir or view 422 * user clicked on the item. Change dir or view
420 */ 423 */
421void PIconView::slotClicked(QIconViewItem* _it) { 424void PIconView::slotClicked(QIconViewItem* _it) {
422 if(!_it ) 425 if(!_it )
423 return; 426 return;
424 427
425 IconViewItem* it = static_cast<IconViewItem*>(_it); 428 IconViewItem* it = static_cast<IconViewItem*>(_it);
@@ -583,26 +586,29 @@ void PIconView::slotChangeMode( int mode ) {
583void PIconView::resizeEvent( QResizeEvent* re ) { 586void PIconView::resizeEvent( QResizeEvent* re ) {
584 QVBox::resizeEvent( re ); 587 QVBox::resizeEvent( re );
585 calculateGrid(); 588 calculateGrid();
586} 589}
587 590
588 591
589void PIconView::calculateGrid() { 592void PIconView::calculateGrid() {
590 odebug << "Calc grid: x=" << m_view->gridX() << " y=" << m_view->gridY() << oendl; 593 odebug << "Calc grid: x=" << m_view->gridX() << " y=" << m_view->gridY() << oendl;
591 odebug << "Size of view: " << m_view->size() << oendl; 594 odebug << "Size of view: " << m_view->size() << oendl;
592 595
593 switch (m_mode) { 596 switch (m_mode) {
594 case 2: 597 case 2:
595 m_view->setGridX(80); 598 m_view->setGridX(50);
596 m_view->setGridY(80); 599 m_view->setGridY(20);
600 PPixmapCache::self()->setMaxImages(40);
597 break; 601 break;
598 case 3: 602 case 3:
599 m_view->setGridX(m_view->width()); 603 m_view->setGridX(m_view->width());
600 m_view->setGridY(8); 604 m_view->setGridY(8);
605 PPixmapCache::self()->setMaxImages(2);
601 break; 606 break;
602 case 1: 607 case 1:
603 default: 608 default:
604 m_view->setGridX(m_view->width()); 609 m_view->setGridX(m_view->width());
605 m_view->setGridY(80); 610 m_view->setGridY(80);
611 PPixmapCache::self()->setMaxImages(20);
606 break; 612 break;
607 } 613 }
608} 614}
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
@@ -53,24 +53,30 @@ void PImageCache::insertImage( const QString& _path, const QImage* img, int or
53 53
54 54
55PPixmapCache::PPixmapCache() { 55PPixmapCache::PPixmapCache() {
56 /* 56 /*
57 * 20 64x64 16 bit images 57 * 20 64x64 16 bit images
58 */ 58 */
59 setMaxCost( 64*64*QPixmap::defaultDepth()/8*20 ); 59 setMaxCost( 64*64*QPixmap::defaultDepth()/8*20 );
60} 60}
61 61
62PPixmapCache::~PPixmapCache() { 62PPixmapCache::~PPixmapCache() {
63} 63}
64 64
65void PPixmapCache::setMaxImages(unsigned int aMax)
66{
67 m_MaxImages = aMax;
68 setMaxCost( 64*64*QPixmap::defaultDepth()/8*m_MaxImages);
69}
70
65PPixmapCache* PPixmapCache::self() { 71PPixmapCache* PPixmapCache::self() {
66 if ( !_pxmCache ) 72 if ( !_pxmCache )
67 _pxmCache = new PPixmapCache; 73 _pxmCache = new PPixmapCache;
68 74
69 return _pxmCache; 75 return _pxmCache;
70} 76}
71 77
72QPixmap* PPixmapCache::cachedImage( const QString& _path, int width, int height ) { 78QPixmap* PPixmapCache::cachedImage( const QString& _path, int width, int height ) {
73 QString path = QString( "%1_%2:" ).arg( width ).arg( height ); 79 QString path = QString( "%1_%2:" ).arg( width ).arg( height );
74 path += _path; 80 path += _path;
75 81
76 QPixmap* pxm = find( path ); 82 QPixmap* pxm = find( path );
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
@@ -19,28 +19,33 @@ private:
19public: 19public:
20 static PImageCache *self(); 20 static PImageCache *self();
21 QImage* cachedImage( const QString& path, int orientation = 3, int max = 0); //const; 21 QImage* cachedImage( const QString& path, int orientation = 3, int max = 0); //const;
22 void insertImage( const QString& path, const QImage &, int orien = 3, int max = 0); 22 void insertImage( const QString& path, const QImage &, int orien = 3, int max = 0);
23 void insertImage( const QString& path, const QImage *, int orien=3, int max = 0 ); 23 void insertImage( const QString& path, const QImage *, int orien=3, int max = 0 );
24}; 24};
25 25
26 26
27class PPixmapCache : public QCache<QPixmap> { 27class PPixmapCache : public QCache<QPixmap> {
28private: 28private:
29 PPixmapCache(); 29 PPixmapCache();
30 ~PPixmapCache(); 30 ~PPixmapCache();
31
32 unsigned int m_MaxImages;
33
31public: 34public:
32 static PPixmapCache *self(); 35 static PPixmapCache *self();
33 QPixmap* cachedImage( const QString& path, int width, int height ); 36 QPixmap* cachedImage( const QString& path, int width, int height );
34 void insertImage( const QString& path, const QPixmap &, int width, int height ); 37 void insertImage( const QString& path, const QPixmap &, int width, int height );
35 void insertImage( const QString& path, const QPixmap *, int width, int height ); 38 void insertImage( const QString& path, const QPixmap *, int width, int height );
39 void setMaxImages(unsigned int aMax);
40 unsigned int maxImages()const{return m_MaxImages;}
36}; 41};
37 42
38inline void PPixmapCache::insertImage( const QString& path, const QPixmap& p, int width, int height ) { 43inline void PPixmapCache::insertImage( const QString& path, const QPixmap& p, int width, int height ) {
39 insertImage( path, new QPixmap( p ), width, height ); 44 insertImage( path, new QPixmap( p ), width, height );
40} 45}
41 46
42inline void PImageCache::insertImage( const QString& path, const QImage& p, int width, int height ) { 47inline void PImageCache::insertImage( const QString& path, const QImage& p, int width, int height ) {
43 insertImage( path, new QImage( p ), width, height ); 48 insertImage( path, new QImage( p ), width, height );
44} 49}
45 50
46#endif 51#endif