summaryrefslogtreecommitdiff
path: root/noncore/graphics/opie-eye/gui/iconview.cpp
Unidiff
Diffstat (limited to 'noncore/graphics/opie-eye/gui/iconview.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/graphics/opie-eye/gui/iconview.cpp157
1 files changed, 129 insertions, 28 deletions
diff --git a/noncore/graphics/opie-eye/gui/iconview.cpp b/noncore/graphics/opie-eye/gui/iconview.cpp
index eafff1d..c037d0d 100644
--- a/noncore/graphics/opie-eye/gui/iconview.cpp
+++ b/noncore/graphics/opie-eye/gui/iconview.cpp
@@ -43,2 +43,3 @@ namespace {
43 static QPixmap* _unkPix = 0; 43 static QPixmap* _unkPix = 0;
44 static QPixmap* _cpyPix = 0;
44 static QPixmap* _emptyPix = 0; 45 static QPixmap* _emptyPix = 0;
@@ -46,3 +47,3 @@ namespace {
46 public: 47 public:
47 IconViewItem( QIconView*, const QString& path, const QString& name, bool isDir = false); 48 IconViewItem( QIconView*, const QString& path, const QString& name,int a_iconsize, bool isDir = false);
48 QPixmap* pixmap()const; 49 QPixmap* pixmap()const;
@@ -60,2 +61,4 @@ namespace {
60 mutable QPixmap* m_pix; 61 mutable QPixmap* m_pix;
62 int m_iconsize;
63 void check_pix()const;
61 64
@@ -70,3 +73,3 @@ namespace {
70 class TextViewItem : public IconViewItem { 73 class TextViewItem : public IconViewItem {
71 TextViewItem( QIconView*, const QString& path, const QString& name, bool isDir = false ); 74 TextViewItem( QIconView*, const QString& path, const QString& name, int a_iconsize , bool isDir = false);
72 QPixmap *pixmap()const; 75 QPixmap *pixmap()const;
@@ -75,3 +78,3 @@ namespace {
75 class ThumbViewItem : public IconViewItem { 78 class ThumbViewItem : public IconViewItem {
76 ThumbViewItem( QIconView*, const QString& path, const QString& name, bool isDir = false ); 79 ThumbViewItem( QIconView*, const QString& path, const QString& name, int a_iconsize, bool isDir = false );
77 QPixmap *pixmap()const; 80 QPixmap *pixmap()const;
@@ -89,3 +92,3 @@ namespace {
89 IconViewItem::IconViewItem( QIconView* view,const QString& path, 92 IconViewItem::IconViewItem( QIconView* view,const QString& path,
90 const QString& name, bool isDir ) 93 const QString& name, int a_iconsize, bool isDir)
91 : QIconViewItem( view, name ), m_path( path ), m_isDir( isDir ), 94 : QIconViewItem( view, name ), m_path( path ), m_isDir( isDir ),
@@ -93,7 +96,48 @@ namespace {
93 { 96 {
94 if ( isDir && !_dirPix ) 97 m_iconsize = a_iconsize;
98 if ( isDir ) {
99 if (_dirPix && _dirPix->width()!=m_iconsize) {
100 delete _dirPix;
101 _dirPix = 0;
102 }
103 if (!_dirPix ) {
95 _dirPix = new QPixmap( Resource::loadPixmap("advancedfm/FileBrowser")); 104 _dirPix = new QPixmap( Resource::loadPixmap("advancedfm/FileBrowser"));
96 else if ( !isDir && !_unkPix ) 105 }
106 } else {
107 if (!_unkPix ) {
97 _unkPix = new QPixmap( Resource::loadPixmap( "UnknownDocument" ) ); 108 _unkPix = new QPixmap( Resource::loadPixmap( "UnknownDocument" ) );
98 } 109 }
110 }
111 check_pix();
112 }
113
114 inline void IconViewItem::check_pix()const
115 {
116 if (_cpyPix && _cpyPix->width()!=m_iconsize) {
117 delete _cpyPix;
118 _cpyPix = 0;
119 }
120 if (_dirPix && _dirPix->width()>m_iconsize) {
121 QPixmap*Pix = new QPixmap(*_dirPix);
122 Pix->resize(m_iconsize,m_iconsize);
123 delete _dirPix;
124 _dirPix = Pix;
125 }
126 if (!_cpyPix && _unkPix) {
127 if (_unkPix->width()>=m_iconsize) {
128 _cpyPix = new QPixmap(*_unkPix);
129 if (_unkPix->width()>m_iconsize)
130 _cpyPix->resize(m_iconsize,m_iconsize);
131 } else {
132 _cpyPix = new QPixmap(m_iconsize,m_iconsize);
133 _cpyPix->fill();
134 QPainter pa(_cpyPix);
135 int offset = (m_iconsize-_unkPix->width())/2;
136 int offy = (m_iconsize-_unkPix->height())/2;
137 if (offy<0) offy=0;
138 pa.drawPixmap(offset,offy,*_unkPix);
139 pa.end();
140 }
141 }
142 }
99 143
@@ -123,12 +167,13 @@ namespace {
123 if (!m_noInfo && !g_stringInf.contains( m_path ) ) { 167 if (!m_noInfo && !g_stringInf.contains( m_path ) ) {
124 currentView()->dirLister()->imageInfo( m_path );
125 g_stringInf.insert( m_path, const_cast<IconViewItem*>(this)); 168 g_stringInf.insert( m_path, const_cast<IconViewItem*>(this));
169 currentView()->dirLister()->imageInfo( m_path );
126 } 170 }
127 171
128 m_pix = PPixmapCache::self()->cachedImage( m_path, 64, 64 ); 172 m_pix = PPixmapCache::self()->cachedImage( m_path, m_iconsize, m_iconsize );
129 if (!m_pix && !g_stringPix.contains( m_path )) { 173 if (!m_pix && !g_stringPix.contains( m_path )) {
130 currentView()->dirLister()->thumbNail( m_path, 64, 64 ); 174 check_pix();
131 g_stringPix.insert( m_path, const_cast<IconViewItem*>(this)); 175 g_stringPix.insert( m_path, const_cast<IconViewItem*>(this));
176 currentView()->dirLister()->thumbNail( m_path, m_iconsize, m_iconsize);
132 } 177 }
133 return m_pix ? m_pix : _unkPix; 178 return m_pix ? m_pix : _cpyPix;
134 } 179 }
@@ -155,2 +200,3 @@ PIconView::PIconView( QWidget* wid, Opie::Core::OConfig* cfg )
155 m_mode = 0; 200 m_mode = 0;
201 m_iconsize = 32;
156 m_internalReset = false; 202 m_internalReset = false;
@@ -177,2 +223,10 @@ PIconView::PIconView( QWidget* wid, Opie::Core::OConfig* cfg )
177 m_view->setItemTextPos( QIconView::Right ); 223 m_view->setItemTextPos( QIconView::Right );
224 if (m_mode >1) {
225 m_view->setResizeMode(QIconView::Adjust);
226 } else {
227 m_view->setResizeMode(QIconView::Fixed);
228 }
229 m_iconsize = m_cfg->readNumEntry("iconsize", 32);
230 if (m_iconsize<12)m_iconsize = 12;
231 if (m_iconsize>64)m_iconsize = 64;
178 232
@@ -282,2 +336,6 @@ void PIconView::slotChangeDir(const QString& path) {
282 336
337 // Also invalidate the cache. We can't cancel the operations anyway
338 g_stringPix.clear();
339 g_stringInf.clear();
340
283 /* 341 /*
@@ -289,6 +347,2 @@ void PIconView::slotChangeDir(const QString& path) {
289 347
290 // Also invalidate the cache. We can't cancel the operations anyway
291 g_stringPix.clear();
292 g_stringInf.clear();
293
294 // looks ugly 348 // looks ugly
@@ -367,2 +421,12 @@ void PIconView::resetView() {
367 m_internalReset = true; 421 m_internalReset = true;
422 // Also invalidate the cache. We can't cancel the operations anyway
423 g_stringPix.clear();
424 g_stringInf.clear();
425 if (m_mode>1) {
426 m_iconsize = m_cfg->readNumEntry("iconsize", 32);
427 if (m_iconsize<12)m_iconsize = 12;
428 if (m_iconsize>64)m_iconsize = 64;
429 } else {
430 m_iconsize = 64;
431 }
368 slotViewChanged(m_views->currentItem()); 432 slotViewChanged(m_views->currentItem());
@@ -415,4 +479,5 @@ void PIconView::slotViewChanged( int i) {
415 */ 479 */
416 if (!m_internalReset) 480 if (!m_internalReset) {
417 m_path = lis->defaultPath(); 481 m_path = lis->defaultPath();
482 }
418 QTimer::singleShot( 0, this, SLOT(slotReloadDir())); 483 QTimer::singleShot( 0, this, SLOT(slotReloadDir()));
@@ -434,3 +499,3 @@ void PIconView::addFolders( const QStringList& lst) {
434 for(it=lst.begin(); it != lst.end(); ++it ) { 499 for(it=lst.begin(); it != lst.end(); ++it ) {
435 _iv = new IconViewItem( m_view, m_path+"/"+(*it), (*it), true ); 500 _iv = new IconViewItem( m_view, m_path+"/"+(*it), (*it),m_iconsize, true );
436 if (m_mode==3) _iv->setTextOnly(true); 501 if (m_mode==3) _iv->setTextOnly(true);
@@ -448,4 +513,4 @@ void PIconView::addFiles( const QStringList& lst) {
448 for (it=lst.begin(); it!= lst.end(); ++it ) { 513 for (it=lst.begin(); it!= lst.end(); ++it ) {
449 m_pix = PPixmapCache::self()->cachedImage( pre+(*it), 64, 64 ); 514 m_pix = PPixmapCache::self()->cachedImage( pre+(*it), m_iconsize, m_iconsize );
450 _iv = new IconViewItem( m_view, pre+(*it), (*it) ); 515 _iv = new IconViewItem( m_view, pre+(*it), (*it),m_iconsize );
451 if (m_mode==3) { 516 if (m_mode==3) {
@@ -526,8 +591,23 @@ void PIconView::slotThumbNail(const QString& _path, const QPixmap &pix) {
526 if (pix.width()>0) { 591 if (pix.width()>0) {
527 PPixmapCache::self()->insertImage( _path, pix, 64, 64 ); 592 if (pix.width()<m_iconsize) {
593 QPixmap p(m_iconsize,m_iconsize);
594 p.fill();
595 QPainter pa(&p);
596 int offset = (m_iconsize-pix.width())/2;
597 int offy = (m_iconsize-pix.height())/2;
598 if (offy<0) offy=0;
599 pa.drawPixmap(offset,offy,pix);
600 pa.end();
601 PPixmapCache::self()->insertImage( _path, p, m_iconsize, m_iconsize );
602 item->setPixmap(p,true);
603 } else {
604 PPixmapCache::self()->insertImage( _path, pix, m_iconsize, m_iconsize );
528 item->setPixmap(pix,true); 605 item->setPixmap(pix,true);
606 }
607
529 } else { 608 } else {
530 PPixmapCache::self()->insertImage( _path, Resource::loadPixmap( "UnknownDocument" ), 64, 64 ); 609 PPixmapCache::self()->insertImage( _path, Resource::loadPixmap( "UnknownDocument" ), m_iconsize, m_iconsize );
531 } 610 }
532 g_stringPix.remove( _path ); 611 g_stringPix.remove( _path );
612 m_view->arrangeItemsInGrid(true);
533} 613}
@@ -693,3 +773,3 @@ void PIconView::slotStartSlide() {
693 } 773 }
694 int t = m_cfg->readNumEntry("base_slideshowtimeout", 2); 774 int t = m_cfg->readNumEntry("slideshowtimeout", 2);
695 emit sig_startslide(t); 775 emit sig_startslide(t);
@@ -712,5 +792,4 @@ void PIconView::slotImageInfo( const QString& name) {
712void PIconView::slotChangeMode( int mode ) { 792void PIconView::slotChangeMode( int mode ) {
713 if ( mode >= 1 && mode <= 3 ) 793 if ( mode >= 1 && mode <= 3 ) {
714 m_mode = mode; 794 m_mode = mode;
715
716 m_cfg->writeEntry("ListViewMode", m_mode); 795 m_cfg->writeEntry("ListViewMode", m_mode);
@@ -718,2 +797,15 @@ void PIconView::slotChangeMode( int mode ) {
718 m_view->clear(); 797 m_view->clear();
798 if (m_mode >1) {
799 m_view->setResizeMode(QIconView::Adjust);
800 } else {
801 m_view->setResizeMode(QIconView::Fixed);
802 }
803 if (m_mode==1) {
804 m_iconsize = 64;
805 } else {
806 m_iconsize = m_cfg->readNumEntry("iconsize", 32);
807 if (m_iconsize<12)m_iconsize = 12;
808 if (m_iconsize>64)m_iconsize = 64;
809 }
810
719 calculateGrid(); 811 calculateGrid();
@@ -721,2 +813,3 @@ void PIconView::slotChangeMode( int mode ) {
721} 813}
814}
722 815
@@ -724,4 +817,5 @@ void PIconView::slotChangeMode( int mode ) {
724void PIconView::resizeEvent( QResizeEvent* re ) { 817void PIconView::resizeEvent( QResizeEvent* re ) {
818 calculateGrid(re);
725 QVBox::resizeEvent( re ); 819 QVBox::resizeEvent( re );
726 calculateGrid(); 820 //calculateGrid();
727} 821}
@@ -729,5 +823,11 @@ void PIconView::resizeEvent( QResizeEvent* re ) {
729 823
730void PIconView::calculateGrid() { 824void PIconView::calculateGrid(QResizeEvent* re)
825{
826 int viewerWidth;
827 if (re) {
828 viewerWidth=re->size().width();
829 } else {
731 int dw = QApplication::desktop()->width(); 830 int dw = QApplication::desktop()->width();
732 int viewerWidth = dw-style().scrollBarExtent().width(); 831 viewerWidth = dw-style().scrollBarExtent().width();
832 }
733 833
@@ -747,4 +847,4 @@ void PIconView::calculateGrid() {
747 case 2: 847 case 2:
748 m_view->setGridX(50); 848 m_view->setGridX(m_iconsize);
749 m_view->setGridY(20); 849 m_view->setGridY(-1);
750 PPixmapCache::self()->setMaxImages(40); 850 PPixmapCache::self()->setMaxImages(40);
@@ -763,2 +863,3 @@ void PIconView::calculateGrid() {
763 } 863 }
864 m_view->setSpacing(10);
764} 865}