summaryrefslogtreecommitdiff
authoralwin <alwin>2004-11-07 15:08:59 (UTC)
committer alwin <alwin>2004-11-07 15:08:59 (UTC)
commitcf8bdb2fe272ca0ecf96aae479df9e1d357ae8a4 (patch) (unidiff)
tree6c55d20ded81c17b5ed772776f333cc7c3ac36bc
parente11d189bfd48ab072da4753240a4ab0bbf81296f (diff)
downloadopie-cf8bdb2fe272ca0ecf96aae479df9e1d357ae8a4.zip
opie-cf8bdb2fe272ca0ecf96aae479df9e1d357ae8a4.tar.gz
opie-cf8bdb2fe272ca0ecf96aae479df9e1d357ae8a4.tar.bz2
fixed up the icon display, imagecache size depends on size of icons
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/graphics/opie-eye/gui/iconview.cpp38
1 files changed, 27 insertions, 11 deletions
diff --git a/noncore/graphics/opie-eye/gui/iconview.cpp b/noncore/graphics/opie-eye/gui/iconview.cpp
index c037d0d..f173ecc 100644
--- a/noncore/graphics/opie-eye/gui/iconview.cpp
+++ b/noncore/graphics/opie-eye/gui/iconview.cpp
@@ -51,117 +51,109 @@ namespace {
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 /* just for starting recalc of item rect! */
56 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! */ 57 /* just for starting recalc of item rect! */
58 virtual void setPixmap( const QPixmap & icon); 58 virtual void setPixmap( const QPixmap & icon);
59 59
60 protected: 60 protected:
61 mutable QPixmap* m_pix; 61 mutable QPixmap* m_pix;
62 int m_iconsize; 62 int m_iconsize;
63 void check_pix()const; 63 void check_pix()const;
64 64
65 private: 65 private:
66 QString m_path; 66 QString m_path;
67 bool m_isDir : 1; 67 bool m_isDir : 1;
68 bool m_noInfo :1; 68 bool m_noInfo :1;
69 bool m_textOnly:1; 69 bool m_textOnly:1;
70 bool m_NameOnly:1; 70 bool m_NameOnly:1;
71 bool m_Pixset:1; 71 bool m_Pixset:1;
72 }; 72 };
73 class TextViewItem : public IconViewItem { 73 class TextViewItem : public IconViewItem {
74 TextViewItem( QIconView*, const QString& path, const QString& name, int a_iconsize , bool isDir = false); 74 TextViewItem( QIconView*, const QString& path, const QString& name, int a_iconsize , bool isDir = false);
75 QPixmap *pixmap()const; 75 QPixmap *pixmap()const;
76 void setText( const QString& ); 76 void setText( const QString& );
77 }; 77 };
78 class ThumbViewItem : public IconViewItem { 78 class ThumbViewItem : public IconViewItem {
79 ThumbViewItem( QIconView*, const QString& path, const QString& name, int a_iconsize, bool isDir = false ); 79 ThumbViewItem( QIconView*, const QString& path, const QString& name, int a_iconsize, bool isDir = false );
80 QPixmap *pixmap()const; 80 QPixmap *pixmap()const;
81 void setText( const QString& ); 81 void setText( const QString& );
82 }; 82 };
83 83
84 84
85/* 85/*
86 * If we request an Image or String 86 * If we request an Image or String
87 * we add it to the map 87 * we add it to the map
88 */ 88 */
89 static QMap<QString, IconViewItem*> g_stringInf; 89 static QMap<QString, IconViewItem*> g_stringInf;
90 static QMap<QString, IconViewItem*> g_stringPix; 90 static QMap<QString, IconViewItem*> g_stringPix;
91 91
92 IconViewItem::IconViewItem( QIconView* view,const QString& path, 92 IconViewItem::IconViewItem( QIconView* view,const QString& path,
93 const QString& name, int a_iconsize, bool isDir) 93 const QString& name, int a_iconsize, bool isDir)
94 : QIconViewItem( view, name ), m_path( path ), m_isDir( isDir ), 94 : QIconViewItem( view, name ), m_path( path ), m_isDir( isDir ),
95 m_noInfo( false ),m_textOnly(false),m_Pixset(false) 95 m_noInfo( false ),m_textOnly(false),m_Pixset(false)
96 { 96 {
97 m_iconsize = a_iconsize; 97 m_iconsize = a_iconsize;
98 if ( isDir ) { 98 if ( isDir ) {
99 if (_dirPix && _dirPix->width()!=m_iconsize) {
100 delete _dirPix;
101 _dirPix = 0;
102 }
103 if (!_dirPix ) { 99 if (!_dirPix ) {
104 _dirPix = new QPixmap( Resource::loadPixmap("advancedfm/FileBrowser")); 100 _dirPix = new QPixmap( Resource::loadPixmap("advancedfm/FileBrowser"));
105 } 101 }
106 } else { 102 } else {
107 if (!_unkPix ) { 103 if (!_unkPix ) {
108 _unkPix = new QPixmap( Resource::loadPixmap( "UnknownDocument" ) ); 104 _unkPix = new QPixmap( Resource::loadPixmap( "UnknownDocument" ) );
109 } 105 }
110 } 106 }
111 check_pix(); 107 check_pix();
112 } 108 }
113 109
114 inline void IconViewItem::check_pix()const 110 inline void IconViewItem::check_pix()const
115 { 111 {
116 if (_cpyPix && _cpyPix->width()!=m_iconsize) {
117 delete _cpyPix;
118 _cpyPix = 0;
119 }
120 if (_dirPix && _dirPix->width()>m_iconsize) { 112 if (_dirPix && _dirPix->width()>m_iconsize) {
121 QPixmap*Pix = new QPixmap(*_dirPix); 113 QPixmap*Pix = new QPixmap(*_dirPix);
122 Pix->resize(m_iconsize,m_iconsize); 114 Pix->resize(m_iconsize,m_iconsize);
123 delete _dirPix; 115 delete _dirPix;
124 _dirPix = Pix; 116 _dirPix = Pix;
125 } 117 }
126 if (!_cpyPix && _unkPix) { 118 if (!_cpyPix && _unkPix) {
127 if (_unkPix->width()>=m_iconsize) { 119 if (_unkPix->width()>=m_iconsize) {
128 _cpyPix = new QPixmap(*_unkPix); 120 _cpyPix = new QPixmap(*_unkPix);
129 if (_unkPix->width()>m_iconsize) 121 if (_unkPix->width()>m_iconsize)
130 _cpyPix->resize(m_iconsize,m_iconsize); 122 _cpyPix->resize(m_iconsize,m_iconsize);
131 } else { 123 } else {
132 _cpyPix = new QPixmap(m_iconsize,m_iconsize); 124 _cpyPix = new QPixmap(m_iconsize,m_iconsize);
133 _cpyPix->fill(); 125 _cpyPix->fill();
134 QPainter pa(_cpyPix); 126 QPainter pa(_cpyPix);
135 int offset = (m_iconsize-_unkPix->width())/2; 127 int offset = (m_iconsize-_unkPix->width())/2;
136 int offy = (m_iconsize-_unkPix->height())/2; 128 int offy = (m_iconsize-_unkPix->height())/2;
137 if (offy<0) offy=0; 129 if (offy<0) offy=0;
138 pa.drawPixmap(offset,offy,*_unkPix); 130 pa.drawPixmap(offset,offy,*_unkPix);
139 pa.end(); 131 pa.end();
140 } 132 }
141 } 133 }
142 } 134 }
143 135
144 inline void IconViewItem::setPixmap( const QPixmap & , bool, bool ) 136 inline void IconViewItem::setPixmap( const QPixmap & , bool, bool )
145 { 137 {
146 m_Pixset = true; 138 m_Pixset = true;
147 calcRect(text()); 139 calcRect(text());
148 } 140 }
149 inline void IconViewItem::setPixmap( const QPixmap & ) 141 inline void IconViewItem::setPixmap( const QPixmap & )
150 { 142 {
151 m_Pixset = true; 143 m_Pixset = true;
152 calcRect(text()); 144 calcRect(text());
153 } 145 }
154 146
155 inline QPixmap* IconViewItem::pixmap()const { 147 inline QPixmap* IconViewItem::pixmap()const {
156// owarn << "Name is " << m_path.right( 15 ) << " rect is " << rect().x() << " " << rect().y() 148// owarn << "Name is " << m_path.right( 15 ) << " rect is " << rect().x() << " " << rect().y()
157// << " " << rect().width() << " " << rect().height() << " | " << iconView()->contentsX() 149// << " " << rect().width() << " " << rect().height() << " | " << iconView()->contentsX()
158// << " " << iconView()->contentsY() << oendl; 150// << " " << iconView()->contentsY() << oendl;
159 151
160 if (textOnly()&&!m_isDir) { 152 if (textOnly()&&!m_isDir) {
161 if (!_emptyPix) _emptyPix = new QPixmap(0,0,1); 153 if (!_emptyPix) _emptyPix = new QPixmap(0,0,1);
162 return _emptyPix; 154 return _emptyPix;
163 } 155 }
164 if ( m_isDir ) 156 if ( m_isDir )
165 return _dirPix; 157 return _dirPix;
166 else{ 158 else{
167 if (!m_noInfo && !g_stringInf.contains( m_path ) ) { 159 if (!m_noInfo && !g_stringInf.contains( m_path ) ) {
@@ -378,99 +370,111 @@ QString PIconView::nextFileName(bool &isDir)const
378 return it->path(); 370 return it->path();
379} 371}
380 372
381QString PIconView::prevFileName(bool &isDir)const{ 373QString PIconView::prevFileName(bool &isDir)const{
382 isDir = false; 374 isDir = false;
383 QIconViewItem* _it = m_view->currentItem(); 375 QIconViewItem* _it = m_view->currentItem();
384 if ( !_it ) 376 if ( !_it )
385 return QString::null; 377 return QString::null;
386 _it = _it->prevItem(); 378 _it = _it->prevItem();
387 if ( !_it ) 379 if ( !_it )
388 return QString::null; 380 return QString::null;
389 IconViewItem* it = static_cast<IconViewItem*>( _it ); 381 IconViewItem* it = static_cast<IconViewItem*>( _it );
390 isDir = it->isDir(); 382 isDir = it->isDir();
391 return it->path(); 383 return it->path();
392} 384}
393 385
394void PIconView::slotTrash() { 386void PIconView::slotTrash() {
395 bool isDir; 387 bool isDir;
396 QString pa = currentFileName( isDir ); 388 QString pa = currentFileName( isDir );
397 if ( isDir && pa.isEmpty() ) 389 if ( isDir && pa.isEmpty() )
398 return; 390 return;
399 391
400 if (!QPEMessageBox::confirmDelete( this, 392 if (!QPEMessageBox::confirmDelete( this,
401 tr("Delete Image" ), 393 tr("Delete Image" ),
402 tr("the Image %1" ).arg(pa))) 394 tr("the Image %1" ).arg(pa)))
403 return 395 return
404 396
405 397
406 currentView()->dirLister()->deleteImage( pa ); 398 currentView()->dirLister()->deleteImage( pa );
407 delete m_view->currentItem(); 399 delete m_view->currentItem();
408} 400}
409 401
410/* 402/*
411 * see what views are available 403 * see what views are available
412 */ 404 */
413void PIconView::loadViews() { 405void PIconView::loadViews() {
414 ViewMap::Iterator it; 406 ViewMap::Iterator it;
415 ViewMap* map = viewMap(); 407 ViewMap* map = viewMap();
416 for ( it = map->begin(); it != map->end(); ++it ) 408 for ( it = map->begin(); it != map->end(); ++it )
417 m_views->insertItem( it.key() ); 409 m_views->insertItem( it.key() );
418} 410}
419 411
420void PIconView::resetView() { 412void PIconView::resetView() {
421 m_internalReset = true; 413 m_internalReset = true;
422 // Also invalidate the cache. We can't cancel the operations anyway 414 // Also invalidate the cache. We can't cancel the operations anyway
423 g_stringPix.clear(); 415 g_stringPix.clear();
424 g_stringInf.clear(); 416 g_stringInf.clear();
425 if (m_mode>1) { 417 if (m_mode>1) {
418 int osize = m_iconsize;
426 m_iconsize = m_cfg->readNumEntry("iconsize", 32); 419 m_iconsize = m_cfg->readNumEntry("iconsize", 32);
427 if (m_iconsize<12)m_iconsize = 12; 420 if (m_iconsize<12)m_iconsize = 12;
428 if (m_iconsize>64)m_iconsize = 64; 421 if (m_iconsize>64)m_iconsize = 64;
422 if (osize != m_iconsize) {
423 if (_dirPix){
424 delete _dirPix;
425 _dirPix = 0;
426 }
427 if (_cpyPix){
428 delete _cpyPix;
429 _cpyPix = 0;
430 }
431 calculateGrid();
432 }
429 } else { 433 } else {
430 m_iconsize = 64; 434 m_iconsize = 64;
431 } 435 }
432 slotViewChanged(m_views->currentItem()); 436 slotViewChanged(m_views->currentItem());
433 m_internalReset = false; 437 m_internalReset = false;
434} 438}
435 439
436/* 440/*
437 *swicth view reloadDir and connect signals 441 *swicth view reloadDir and connect signals
438 */ 442 */
439void PIconView::slotViewChanged( int i) { 443void PIconView::slotViewChanged( int i) {
440 if (!m_views->count() ) { 444 if (!m_views->count() ) {
441 setCurrentView( 0l); 445 setCurrentView( 0l);
442 return; 446 return;
443 } 447 }
444 448
445 PDirView* cur = currentView(); 449 PDirView* cur = currentView();
446 if (cur) delete cur; 450 if (cur) delete cur;
447 QString str = m_views->text(i); 451 QString str = m_views->text(i);
448 ViewMap* map = viewMap(); 452 ViewMap* map = viewMap();
449 if (!map) { 453 if (!map) {
450 setCurrentView(0l); 454 setCurrentView(0l);
451 return; 455 return;
452 } 456 }
453 457
454 if (map->find(str) == map->end()) { 458 if (map->find(str) == map->end()) {
455 owarn << "Key not found" << oendl; 459 owarn << "Key not found" << oendl;
456 setCurrentView(0l); 460 setCurrentView(0l);
457 return; 461 return;
458 } 462 }
459 463
460 m_cfg->writeEntry("LastView",str); 464 m_cfg->writeEntry("LastView",str);
461 m_cfg->write(); 465 m_cfg->write();
462 cur = (*(*map)[str])(*m_cfg); 466 cur = (*(*map)[str])(*m_cfg);
463 setCurrentView( cur ); 467 setCurrentView( cur );
464 468
465 /* connect to the signals of the lister */ 469 /* connect to the signals of the lister */
466 PDirLister* lis = cur->dirLister(); 470 PDirLister* lis = cur->dirLister();
467 connect(lis, SIGNAL(sig_thumbInfo(const QString&, const QString& )), 471 connect(lis, SIGNAL(sig_thumbInfo(const QString&, const QString& )),
468 this, SLOT( slotThumbInfo(const QString&, const QString&))); 472 this, SLOT( slotThumbInfo(const QString&, const QString&)));
469 connect(lis, SIGNAL( sig_thumbNail(const QString&, const QPixmap&)), 473 connect(lis, SIGNAL( sig_thumbNail(const QString&, const QPixmap&)),
470 this, SLOT(slotThumbNail(const QString&, const QPixmap&))); 474 this, SLOT(slotThumbNail(const QString&, const QPixmap&)));
471 connect(lis, SIGNAL(sig_start()), 475 connect(lis, SIGNAL(sig_start()),
472 this, SLOT(slotStart())); 476 this, SLOT(slotStart()));
473 connect(lis, SIGNAL(sig_end()) , 477 connect(lis, SIGNAL(sig_end()) ,
474 this, SLOT(slotEnd()) ); 478 this, SLOT(slotEnd()) );
475 479
476 480
@@ -762,104 +766,116 @@ void PIconView::slotShowImage( const QString& name) {
762 emit sig_display(r_name); 766 emit sig_display(r_name);
763} 767}
764 768
765void PIconView::slotStartSlide() { 769void PIconView::slotStartSlide() {
766 bool isDir = false; 770 bool isDir = false;
767 QString name = currentFileName(isDir); 771 QString name = currentFileName(isDir);
768 if (isDir) { 772 if (isDir) {
769 if (!slotShowFirst()) 773 if (!slotShowFirst())
770 return; 774 return;
771 } else { 775 } else {
772 slotShowImage( name ); 776 slotShowImage( name );
773 } 777 }
774 int t = m_cfg->readNumEntry("slideshowtimeout", 2); 778 int t = m_cfg->readNumEntry("slideshowtimeout", 2);
775 emit sig_startslide(t); 779 emit sig_startslide(t);
776} 780}
777 781
778void PIconView::slotImageInfo() { 782void PIconView::slotImageInfo() {
779 bool isDir = false; 783 bool isDir = false;
780 QString name = currentFileName(isDir); 784 QString name = currentFileName(isDir);
781 if (isDir) return; 785 if (isDir) return;
782 slotImageInfo( name ); 786 slotImageInfo( name );
783} 787}
784 788
785void PIconView::slotImageInfo( const QString& name) { 789void PIconView::slotImageInfo( const QString& name) {
786 PDirLister *lister = currentView()->dirLister(); 790 PDirLister *lister = currentView()->dirLister();
787 QString r_name = lister->nameToFname(name); 791 QString r_name = lister->nameToFname(name);
788 emit sig_showInfo(r_name ); 792 emit sig_showInfo(r_name );
789} 793}
790 794
791 795
792void PIconView::slotChangeMode( int mode ) { 796void PIconView::slotChangeMode( int mode ) {
793 if ( mode >= 1 && mode <= 3 ) { 797 if ( mode >= 1 && mode <= 3 ) {
794 m_mode = mode; 798 m_mode = mode;
795 m_cfg->writeEntry("ListViewMode", m_mode); 799 m_cfg->writeEntry("ListViewMode", m_mode);
796 /* performance! */ 800 /* performance! */
797 m_view->clear(); 801 m_view->clear();
798 if (m_mode >1) { 802 if (m_mode >1) {
799 m_view->setResizeMode(QIconView::Adjust); 803 m_view->setResizeMode(QIconView::Adjust);
800 } else { 804 } else {
801 m_view->setResizeMode(QIconView::Fixed); 805 m_view->setResizeMode(QIconView::Fixed);
802 } 806 }
803 if (m_mode==1) { 807 if (m_mode==1) {
804 m_iconsize = 64; 808 m_iconsize = 64;
805 } else { 809 } else {
806 m_iconsize = m_cfg->readNumEntry("iconsize", 32); 810 m_iconsize = m_cfg->readNumEntry("iconsize", 32);
807 if (m_iconsize<12)m_iconsize = 12; 811 if (m_iconsize<12)m_iconsize = 12;
808 if (m_iconsize>64)m_iconsize = 64; 812 if (m_iconsize>64)m_iconsize = 64;
809 } 813 }
810 814 if (_dirPix){
815 delete _dirPix;
816 _dirPix = 0;
817 }
818 if (_cpyPix){
819 delete _cpyPix;
820 _cpyPix = 0;
821 }
811 calculateGrid(); 822 calculateGrid();
812 slotReloadDir(); 823 slotReloadDir();
813 } 824 }
814} 825}
815 826
816 827
817void PIconView::resizeEvent( QResizeEvent* re ) { 828void PIconView::resizeEvent( QResizeEvent* re ) {
818 calculateGrid(re); 829 calculateGrid(re);
819 QVBox::resizeEvent( re ); 830 QVBox::resizeEvent( re );
820 //calculateGrid(); 831 //calculateGrid();
821} 832}
822 833
823 834
824void PIconView::calculateGrid(QResizeEvent* re) 835void PIconView::calculateGrid(QResizeEvent* re)
825{ 836{
826 int viewerWidth; 837 int viewerWidth;
827 if (re) { 838 if (re) {
828 viewerWidth=re->size().width(); 839 viewerWidth=re->size().width();
829 } else { 840 } else {
830 int dw = QApplication::desktop()->width(); 841 int dw = QApplication::desktop()->width();
831 viewerWidth = dw-style().scrollBarExtent().width(); 842 viewerWidth = dw-style().scrollBarExtent().width();
832 } 843 }
833 844
834 QIconView::ItemTextPos pos; 845 QIconView::ItemTextPos pos;
835 switch( m_mode ) { 846 switch( m_mode ) {
836 case 2: 847 case 2:
837 pos = QIconView::Bottom; 848 pos = QIconView::Bottom;
838 break; 849 break;
839 case 3: 850 case 3:
840 case 1: 851 case 1:
841 default: 852 default:
842 pos = QIconView::Right; 853 pos = QIconView::Right;
843 break; 854 break;
844 } 855 }
856 int cache = 0;
845 m_view->setItemTextPos( pos ); 857 m_view->setItemTextPos( pos );
846 switch (m_mode) { 858 switch (m_mode) {
847 case 2: 859 case 2:
860 m_view->setSpacing(2);
848 m_view->setGridX(m_iconsize); 861 m_view->setGridX(m_iconsize);
849 m_view->setGridY(-1); 862 m_view->setGridY(-1);
850 PPixmapCache::self()->setMaxImages(40); 863 cache = (int)((double)64/(double)m_iconsize*40.0);
864 odebug << "cache size: " << cache << oendl;
865 PPixmapCache::self()->setMaxImages(cache);
851 break; 866 break;
852 case 3: 867 case 3:
868 m_view->setSpacing(10);
853 m_view->setGridX( fontMetrics().width("testimage.jpg")+20); 869 m_view->setGridX( fontMetrics().width("testimage.jpg")+20);
854 m_view->setGridY(8); 870 m_view->setGridY(8);
855 PPixmapCache::self()->setMaxImages(2); 871 PPixmapCache::self()->setMaxImages(2);
856 break; 872 break;
857 case 1: 873 case 1:
858 default: 874 default:
875 m_view->setSpacing(10);
859 m_view->setGridX( viewerWidth-3*m_view->spacing()); 876 m_view->setGridX( viewerWidth-3*m_view->spacing());
860 m_view->setGridY( fontMetrics().height()*2+40 ); 877 m_view->setGridY( fontMetrics().height()*2+40 );
861 PPixmapCache::self()->setMaxImages(20); 878 PPixmapCache::self()->setMaxImages(20);
862 break; 879 break;
863 } 880 }
864 m_view->setSpacing(10);
865} 881}