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
@@ -3,213 +3,205 @@
3 * No WArranty... 3 * No WArranty...
4 */ 4 */
5 5
6#include "iconview.h" 6#include "iconview.h"
7 7
8#include <lib/imagecache.h> 8#include <lib/imagecache.h>
9#include <gui/imageinfoui.h> 9#include <gui/imageinfoui.h>
10 10
11#include <iface/dirview.h> 11#include <iface/dirview.h>
12#include <iface/dirlister.h> 12#include <iface/dirlister.h>
13 13
14#include <opie2/oconfig.h> 14#include <opie2/oconfig.h>
15#include <opie2/okeyconfigwidget.h> 15#include <opie2/okeyconfigwidget.h>
16#include <opie2/odebug.h> 16#include <opie2/odebug.h>
17#include <opie2/oimagescrollview.h> 17#include <opie2/oimagescrollview.h>
18 18
19#include <qpe/resource.h> 19#include <qpe/resource.h>
20#include <qpe/qpemessagebox.h> 20#include <qpe/qpemessagebox.h>
21#include <qpe/ir.h> 21#include <qpe/ir.h>
22#include <qpe/qcopenvelope_qws.h> 22#include <qpe/qcopenvelope_qws.h>
23#include <qpe/qpeapplication.h> 23#include <qpe/qpeapplication.h>
24 24
25#include <qiconview.h> 25#include <qiconview.h>
26#include <qlabel.h> 26#include <qlabel.h>
27#include <qhbox.h> 27#include <qhbox.h>
28#include <qcombobox.h> 28#include <qcombobox.h>
29#include <qdir.h> 29#include <qdir.h>
30#include <qapplication.h> 30#include <qapplication.h>
31#include <qmainwindow.h> 31#include <qmainwindow.h>
32#include <qtimer.h> 32#include <qtimer.h>
33#include <qstyle.h> 33#include <qstyle.h>
34 34
35 35
36using Opie::Core::OKeyConfigItem; 36using Opie::Core::OKeyConfigItem;
37 37
38/* 38/*
39 * The Icons, Request Cache and IconViewItem for the IconView 39 * The Icons, Request Cache and IconViewItem for the IconView
40 */ 40 */
41namespace { 41namespace {
42 static QPixmap* _dirPix = 0; 42 static QPixmap* _dirPix = 0;
43 static QPixmap* _unkPix = 0; 43 static QPixmap* _unkPix = 0;
44 static QPixmap* _cpyPix = 0; 44 static QPixmap* _cpyPix = 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,int a_iconsize, bool isDir = false); 48 IconViewItem( QIconView*, const QString& path, const QString& name,int a_iconsize, 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 /* 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 ) ) {
168 g_stringInf.insert( m_path, const_cast<IconViewItem*>(this)); 160 g_stringInf.insert( m_path, const_cast<IconViewItem*>(this));
169 currentView()->dirLister()->imageInfo( m_path ); 161 currentView()->dirLister()->imageInfo( m_path );
170 } 162 }
171 163
172 m_pix = PPixmapCache::self()->cachedImage( m_path, m_iconsize, m_iconsize ); 164 m_pix = PPixmapCache::self()->cachedImage( m_path, m_iconsize, m_iconsize );
173 if (!m_pix && !g_stringPix.contains( m_path )) { 165 if (!m_pix && !g_stringPix.contains( m_path )) {
174 check_pix(); 166 check_pix();
175 g_stringPix.insert( m_path, const_cast<IconViewItem*>(this)); 167 g_stringPix.insert( m_path, const_cast<IconViewItem*>(this));
176 currentView()->dirLister()->thumbNail( m_path, m_iconsize, m_iconsize); 168 currentView()->dirLister()->thumbNail( m_path, m_iconsize, m_iconsize);
177 } 169 }
178 return m_pix ? m_pix : _cpyPix; 170 return m_pix ? m_pix : _cpyPix;
179 } 171 }
180 } 172 }
181 inline void IconViewItem::setText( const QString& str ) { 173 inline void IconViewItem::setText( const QString& str ) {
182 QString text = QIconViewItem::text()+"\n"+str; 174 QString text = QIconViewItem::text()+"\n"+str;
183 m_noInfo = true; 175 m_noInfo = true;
184 QIconViewItem::setText( text ); 176 QIconViewItem::setText( text );
185 } 177 }
186} 178}
187 179
188 180
189/* 181/*
190 * Set up the GUI.. initialize the slave set up gui 182 * Set up the GUI.. initialize the slave set up gui
191 * and also load a dir 183 * and also load a dir
192 */ 184 */
193PIconView::PIconView( QWidget* wid, Opie::Core::OConfig* cfg ) 185PIconView::PIconView( QWidget* wid, Opie::Core::OConfig* cfg )
194 : QVBox( wid ), m_cfg( cfg ), m_updatet( false ) 186 : QVBox( wid ), m_cfg( cfg ), m_updatet( false )
195{ 187{
196 { 188 {
197 QCopEnvelope( "QPE/Application/opie-eye_slave", "refUp()" ); 189 QCopEnvelope( "QPE/Application/opie-eye_slave", "refUp()" );
198 } 190 }
199 m_path = QDir::homeDirPath(); 191 m_path = QDir::homeDirPath();
200 m_mode = 0; 192 m_mode = 0;
201 m_iconsize = 32; 193 m_iconsize = 32;
202 m_internalReset = false; 194 m_internalReset = false;
203 195
204 QHBox *hbox = new QHBox( this ); 196 QHBox *hbox = new QHBox( this );
205 QLabel* lbl = new QLabel( hbox ); 197 QLabel* lbl = new QLabel( hbox );
206 lbl->setText( tr("View as" ) ); 198 lbl->setText( tr("View as" ) );
207 199
208 m_views = new QComboBox( hbox, "View As" ); 200 m_views = new QComboBox( hbox, "View As" );
209 201
210 m_view= new QIconView( this ); 202 m_view= new QIconView( this );
211 connect(m_view, SIGNAL(clicked(QIconViewItem*) ), 203 connect(m_view, SIGNAL(clicked(QIconViewItem*) ),
212 this, SLOT(slotClicked(QIconViewItem*)) ); 204 this, SLOT(slotClicked(QIconViewItem*)) );
213 connect(m_view, SIGNAL(returnPressed(QIconViewItem*)), 205 connect(m_view, SIGNAL(returnPressed(QIconViewItem*)),
214 this, SLOT(slotClicked(QIconViewItem*)) ); 206 this, SLOT(slotClicked(QIconViewItem*)) );
215 207
@@ -330,195 +322,207 @@ void PIconView::slotChangeDir(const QString& path) {
330 */ 322 */
331 lister->setStartPath( path ); 323 lister->setStartPath( path );
332 m_path = lister->currentPath(); 324 m_path = lister->currentPath();
333 325
334 m_view->viewport()->setUpdatesEnabled( false ); 326 m_view->viewport()->setUpdatesEnabled( false );
335 m_view->clear(); 327 m_view->clear();
336 328
337 // Also invalidate the cache. We can't cancel the operations anyway 329 // Also invalidate the cache. We can't cancel the operations anyway
338 g_stringPix.clear(); 330 g_stringPix.clear();
339 g_stringInf.clear(); 331 g_stringInf.clear();
340 332
341 /* 333 /*
342 * add files and folders 334 * add files and folders
343 */ 335 */
344 addFolders( lister->folders() ); 336 addFolders( lister->folders() );
345 addFiles( lister->files() ); 337 addFiles( lister->files() );
346 m_view->viewport()->setUpdatesEnabled( true ); 338 m_view->viewport()->setUpdatesEnabled( true );
347 339
348 // looks ugly 340 // looks ugly
349 static_cast<QMainWindow*>(parent())->setCaption( QObject::tr("%1 - O View", "Name of the dir").arg( m_path ) ); 341 static_cast<QMainWindow*>(parent())->setCaption( QObject::tr("%1 - O View", "Name of the dir").arg( m_path ) );
350} 342}
351 343
352/** 344/**
353 * get the current file name 345 * get the current file name
354 * @param isDir see if this is a dir or real file 346 * @param isDir see if this is a dir or real file
355 */ 347 */
356QString PIconView::currentFileName(bool &isDir)const { 348QString PIconView::currentFileName(bool &isDir)const {
357 isDir = false; 349 isDir = false;
358 QIconViewItem* _it = m_view->currentItem(); 350 QIconViewItem* _it = m_view->currentItem();
359 if ( !_it ) 351 if ( !_it )
360 return QString::null; 352 return QString::null;
361 353
362 IconViewItem* it = static_cast<IconViewItem*>( _it ); 354 IconViewItem* it = static_cast<IconViewItem*>( _it );
363 isDir = it->isDir(); 355 isDir = it->isDir();
364 return it->path(); 356 return it->path();
365} 357}
366 358
367QString PIconView::nextFileName(bool &isDir)const 359QString PIconView::nextFileName(bool &isDir)const
368{ 360{
369 isDir = false; 361 isDir = false;
370 QIconViewItem* _it1 = m_view->currentItem(); 362 QIconViewItem* _it1 = m_view->currentItem();
371 if ( !_it1 ) 363 if ( !_it1 )
372 return QString::null; 364 return QString::null;
373 QIconViewItem* _it = _it1->nextItem(); 365 QIconViewItem* _it = _it1->nextItem();
374 if ( !_it ) 366 if ( !_it )
375 return QString::null; 367 return QString::null;
376 IconViewItem* it = static_cast<IconViewItem*>( _it ); 368 IconViewItem* it = static_cast<IconViewItem*>( _it );
377 isDir = it->isDir(); 369 isDir = it->isDir();
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
477 /* reload now with default Path 481 /* reload now with default Path
478 * but only if it isn't a reset like from setupdlg 482 * but only if it isn't a reset like from setupdlg
479 */ 483 */
480 if (!m_internalReset) { 484 if (!m_internalReset) {
481 m_path = lis->defaultPath(); 485 m_path = lis->defaultPath();
482 } 486 }
483 QTimer::singleShot( 0, this, SLOT(slotReloadDir())); 487 QTimer::singleShot( 0, this, SLOT(slotReloadDir()));
484} 488}
485 489
486 490
487void PIconView::slotReloadDir() { 491void PIconView::slotReloadDir() {
488 slotChangeDir( m_path ); 492 slotChangeDir( m_path );
489} 493}
490 494
491 495
492/* 496/*
493 * add files and folders 497 * add files and folders
494 */ 498 */
495void PIconView::addFolders( const QStringList& lst) { 499void PIconView::addFolders( const QStringList& lst) {
496 QStringList::ConstIterator it; 500 QStringList::ConstIterator it;
497 IconViewItem * _iv; 501 IconViewItem * _iv;
498 502
499 for(it=lst.begin(); it != lst.end(); ++it ) { 503 for(it=lst.begin(); it != lst.end(); ++it ) {
500 _iv = new IconViewItem( m_view, m_path+"/"+(*it), (*it),m_iconsize, true ); 504 _iv = new IconViewItem( m_view, m_path+"/"+(*it), (*it),m_iconsize, true );
501 if (m_mode==3) _iv->setTextOnly(true); 505 if (m_mode==3) _iv->setTextOnly(true);
502 } 506 }
503} 507}
504 508
505void PIconView::addFiles( const QStringList& lst) { 509void PIconView::addFiles( const QStringList& lst) {
506 QStringList::ConstIterator it; 510 QStringList::ConstIterator it;
507 IconViewItem * _iv; 511 IconViewItem * _iv;
508 QPixmap*m_pix = 0; 512 QPixmap*m_pix = 0;
509 QString pre = ""; 513 QString pre = "";
510 if (!m_path.isEmpty()) { 514 if (!m_path.isEmpty()) {
511 pre = m_path+"/"; 515 pre = m_path+"/";
512 } 516 }
513 for (it=lst.begin(); it!= lst.end(); ++it ) { 517 for (it=lst.begin(); it!= lst.end(); ++it ) {
514 m_pix = PPixmapCache::self()->cachedImage( pre+(*it), m_iconsize, m_iconsize ); 518 m_pix = PPixmapCache::self()->cachedImage( pre+(*it), m_iconsize, m_iconsize );
515 _iv = new IconViewItem( m_view, pre+(*it), (*it),m_iconsize ); 519 _iv = new IconViewItem( m_view, pre+(*it), (*it),m_iconsize );
516 if (m_mode==3) { 520 if (m_mode==3) {
517 _iv->setTextOnly(true); 521 _iv->setTextOnly(true);
518 _iv->setPixmap(QPixmap()); 522 _iv->setPixmap(QPixmap());
519 523
520 524
521 525
522 } else { 526 } else {
523 if (m_pix) _iv->setPixmap(*m_pix); 527 if (m_pix) _iv->setPixmap(*m_pix);
524 } 528 }
@@ -714,152 +718,164 @@ bool PIconView::slotShowFirst()
714 718
715void PIconView::slotShowNext() 719void PIconView::slotShowNext()
716{ 720{
717 bool isDir = false; 721 bool isDir = false;
718 QString name = nextFileName(isDir); 722 QString name = nextFileName(isDir);
719 while (isDir==true) { 723 while (isDir==true) {
720 m_view->setCurrentItem(m_view->currentItem()->nextItem()); 724 m_view->setCurrentItem(m_view->currentItem()->nextItem());
721 name = nextFileName(isDir); 725 name = nextFileName(isDir);
722 } 726 }
723 if (name.isEmpty()) { 727 if (name.isEmpty()) {
724 slotShowFirst(); 728 slotShowFirst();
725 return; 729 return;
726 } 730 }
727 if (isDir) return; 731 if (isDir) return;
728 /* if we got a name we have a next item */ 732 /* if we got a name we have a next item */
729 m_view->setCurrentItem(m_view->currentItem()->nextItem()); 733 m_view->setCurrentItem(m_view->currentItem()->nextItem());
730 slotShowImage(name); 734 slotShowImage(name);
731} 735}
732 736
733void PIconView::slotShowPrev() 737void PIconView::slotShowPrev()
734{ 738{
735 bool isDir = false; 739 bool isDir = false;
736 QString name = prevFileName(isDir); 740 QString name = prevFileName(isDir);
737 while (isDir==true) { 741 while (isDir==true) {
738 /* if name is empty isDir is false, too. */ 742 /* if name is empty isDir is false, too. */
739 m_view->setCurrentItem(m_view->currentItem()->prevItem()); 743 m_view->setCurrentItem(m_view->currentItem()->prevItem());
740 name = prevFileName(isDir); 744 name = prevFileName(isDir);
741 } 745 }
742 if (name.isEmpty()) { 746 if (name.isEmpty()) {
743 slotShowLast(); 747 slotShowLast();
744 return; 748 return;
745 } 749 }
746 if (isDir) return; 750 if (isDir) return;
747 /* if we got a name we have a prev item */ 751 /* if we got a name we have a prev item */
748 m_view->setCurrentItem(m_view->currentItem()->prevItem()); 752 m_view->setCurrentItem(m_view->currentItem()->prevItem());
749 slotShowImage(name); 753 slotShowImage(name);
750} 754}
751 755
752void PIconView::slotShowImage() 756void PIconView::slotShowImage()
753{ 757{
754 bool isDir = false; 758 bool isDir = false;
755 QString name = currentFileName(isDir); 759 QString name = currentFileName(isDir);
756 if (isDir) return; 760 if (isDir) return;
757 slotShowImage( name ); 761 slotShowImage( name );
758} 762}
759void PIconView::slotShowImage( const QString& name) { 763void PIconView::slotShowImage( const QString& name) {
760 PDirLister *lister = currentView()->dirLister(); 764 PDirLister *lister = currentView()->dirLister();
761 QString r_name = lister->nameToFname(name); 765 QString r_name = lister->nameToFname(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}