00001
00002
00003
00004
00005
00006 #include "iconview.h"
00007 #include "messagebox.h"
00008
00009 #include <lib/imagecache.h>
00010 #include <gui/imageinfoui.h>
00011
00012 #include <iface/dirview.h>
00013 #include <iface/dirlister.h>
00014
00015 #include <opie2/oconfig.h>
00016 #include <opie2/okeyconfigwidget.h>
00017 #include <opie2/odebug.h>
00018 #include <opie2/oimagescrollview.h>
00019 #include <opie2/oresource.h>
00020
00021 #include <qpe/qpemessagebox.h>
00022 #include <qpe/ir.h>
00023 #include <qpe/qcopenvelope_qws.h>
00024 #include <qpe/qpeapplication.h>
00025
00026 #include <qiconview.h>
00027 #include <qlabel.h>
00028 #include <qhbox.h>
00029 #include <qcombobox.h>
00030 #include <qdir.h>
00031 #include <qapplication.h>
00032 #include <qmainwindow.h>
00033 #include <qtimer.h>
00034 #include <qstyle.h>
00035
00036
00037 using Opie::Core::OKeyConfigItem;
00038
00039 const int PIconView::sMAX_ICON_SIZE = 128;
00040 const int PIconView::sMIN_ICON_SIZE = 12;
00041 const int PIconView::sDEF_ICON_SIZE = 64;
00042
00043
00044
00045
00046 namespace {
00047 static QPixmap* _dirPix = 0;
00048 static QPixmap* _unkPix = 0;
00049 static QPixmap* _cpyPix = 0;
00050 static QPixmap* _emptyPix = 0;
00051 class IconViewItem : public QIconViewItem {
00052 public:
00053 IconViewItem( QIconView*, const QString& path, const QString& name,int a_iconsize, bool isDir = false);
00054 QPixmap* pixmap()const;
00055 QString path()const { return m_path; }
00056 bool isDir()const { return m_isDir; }
00057 void setText( const QString& );
00058 bool textOnly()const{return m_textOnly;}
00059 void setTextOnly(bool how){m_textOnly=how;}
00060
00061 virtual void setPixmap( const QPixmap & icon, bool recalc, bool redraw = TRUE );
00062
00063 virtual void setPixmap( const QPixmap & icon);
00064
00065 protected:
00066 mutable QPixmap* m_pix;
00067 int m_iconsize;
00068 void check_pix()const;
00069
00070 private:
00071 QString m_path;
00072 bool m_isDir : 1;
00073 bool m_noInfo :1;
00074 bool m_textOnly:1;
00075 bool m_NameOnly:1;
00076 bool m_Pixset:1;
00077 };
00078 class TextViewItem : public IconViewItem {
00079 TextViewItem( QIconView*, const QString& path, const QString& name, int a_iconsize , bool isDir = false);
00080 QPixmap *pixmap()const;
00081 void setText( const QString& );
00082 };
00083 class ThumbViewItem : public IconViewItem {
00084 ThumbViewItem( QIconView*, const QString& path, const QString& name, int a_iconsize, bool isDir = false );
00085 QPixmap *pixmap()const;
00086 void setText( const QString& );
00087 };
00088
00089
00090
00091
00092
00093
00094 static QMap<QString, IconViewItem*> g_stringInf;
00095 static QMap<QString, IconViewItem*> g_stringPix;
00096
00097 IconViewItem::IconViewItem( QIconView* view,const QString& path,
00098 const QString& name, int a_iconsize, bool isDir)
00099 : QIconViewItem( view, name ), m_path( path ), m_isDir( isDir ),
00100 m_noInfo( false ),m_textOnly(false),m_Pixset(false)
00101 {
00102 m_iconsize = a_iconsize;
00103 if ( isDir ) {
00104 if (!_dirPix ) {
00105 _dirPix = new QPixmap( Opie::Core::OResource::loadPixmap("advancedfm/FileBrowser", Opie::Core::OResource::SmallIcon));
00106 }
00107 } else {
00108 if (!_unkPix ) {
00109 _unkPix = new QPixmap( Opie::Core::OResource::loadPixmap( "UnknownDocument", Opie::Core::OResource::SmallIcon ) );
00110 }
00111 }
00112 check_pix();
00113 }
00114
00115 inline void IconViewItem::check_pix()const
00116 {
00117 if (_dirPix && _dirPix->width()>m_iconsize) {
00118 QImage Pix = _dirPix->convertToImage();
00119 *_dirPix = Pix.smoothScale(m_iconsize,m_iconsize);
00120 }
00121 if (!_cpyPix && _unkPix) {
00122 if (_unkPix->width()>=m_iconsize) {
00123 QImage Pix = _unkPix->convertToImage();
00124 _cpyPix = new QPixmap();
00125 if (_unkPix->width()>m_iconsize) {
00126 *_cpyPix = Pix.smoothScale(m_iconsize,m_iconsize);
00127 } else {
00128 _cpyPix->convertFromImage(Pix);
00129 }
00130
00131 } else {
00132 _cpyPix = new QPixmap(m_iconsize,m_iconsize);
00133 _cpyPix->fill();
00134 QPainter pa(_cpyPix);
00135 int offset = (m_iconsize-_unkPix->width())/2;
00136 int offy = (m_iconsize-_unkPix->height())/2;
00137 if (offy<0) offy=0;
00138 pa.drawPixmap(offset,offy,*_unkPix);
00139 pa.end();
00140 }
00141 }
00142 }
00143
00144 inline void IconViewItem::setPixmap( const QPixmap & , bool, bool )
00145 {
00146 m_Pixset = true;
00147 calcRect(text());
00148 }
00149 inline void IconViewItem::setPixmap( const QPixmap & )
00150 {
00151 m_Pixset = true;
00152 calcRect(text());
00153 }
00154
00155 inline QPixmap* IconViewItem::pixmap()const {
00156
00157
00158
00159
00160 if (textOnly()&&!m_isDir) {
00161 if (!_emptyPix) _emptyPix = new QPixmap(0,0,1);
00162 return _emptyPix;
00163 }
00164 if ( m_isDir )
00165 return _dirPix;
00166 else{
00167 if (!m_noInfo && !g_stringInf.contains( m_path ) ) {
00168 g_stringInf.insert( m_path, const_cast<IconViewItem*>(this));
00169 currentView()->dirLister()->imageInfo( m_path );
00170 }
00171
00172 m_pix = PPixmapCache::self()->cachedImage( m_path, m_iconsize, m_iconsize );
00173 if (!m_pix && !g_stringPix.contains( m_path )) {
00174 check_pix();
00175 g_stringPix.insert( m_path, const_cast<IconViewItem*>(this));
00176 currentView()->dirLister()->thumbNail( m_path, m_iconsize, m_iconsize);
00177 }
00178 return m_pix ? m_pix : _cpyPix;
00179 }
00180 }
00181 inline void IconViewItem::setText( const QString& str ) {
00182 QString text = QIconViewItem::text()+"\n"+str;
00183 m_noInfo = true;
00184 QIconViewItem::setText( text );
00185 }
00186 }
00187
00188
00189
00190
00191
00192
00193 PIconView::PIconView( QWidget* wid, Opie::Core::OConfig* cfg )
00194 : QVBox( wid ), m_cfg( cfg ), m_updatet( false )
00195 {
00196 {
00197 QCopEnvelope( "QPE/Application/opie-eye_slave", "refUp()" );
00198 }
00199 m_path = QDir::homeDirPath();
00200 m_mode = 0;
00201 m_iconsize = 32;
00202 m_internalReset = false;
00203 m_customWidget = 0;
00204 m_setDocCalled = false;
00205
00206 m_hbox = new QHBox( this );
00207 QLabel* lbl = new QLabel( m_hbox );
00208 lbl->setText( tr("View as" ) );
00209
00210 m_views = new QComboBox( m_hbox, "View As" );
00211
00212 m_view= new QIconView( this );
00213 connect(m_view, SIGNAL(clicked(QIconViewItem*) ),
00214 this, SLOT(slotClicked(QIconViewItem*)) );
00215 connect(m_view, SIGNAL(returnPressed(QIconViewItem*)),
00216 this, SLOT(slotClicked(QIconViewItem*)) );
00217
00218 m_view->setArrangement( QIconView::LeftToRight );
00219
00220 m_mode = m_cfg->readNumEntry("ListViewMode", 1);
00221 if (m_mode < 1 || m_mode>3) m_mode = 1;
00222 m_view->setItemTextPos( QIconView::Right );
00223 if (m_mode >1) {
00224 m_view->setResizeMode(QIconView::Adjust);
00225 } else {
00226 m_view->setResizeMode(QIconView::Fixed);
00227 }
00228 m_iconsize = m_cfg->readNumEntry("iconsize", 32);
00229 if (m_iconsize<sMIN_ICON_SIZE)m_iconsize = sMIN_ICON_SIZE;
00230 if (m_iconsize>sMAX_ICON_SIZE)m_iconsize = sMAX_ICON_SIZE;
00231
00232 calculateGrid();
00233 initKeys();
00234 loadViews();
00235 }
00236
00237 void PIconView::setDoccalled(bool how)
00238 {
00239 m_setDocCalled = how;
00240 }
00241
00242
00243
00244
00245 PIconView::~PIconView() {
00246 {
00247 QCopEnvelope( "QPE/Application/opie-eye_slave", "refDown()" );
00248 }
00249 m_viewManager->save();
00250 delete m_viewManager;
00251 }
00252
00253 Opie::Core::OKeyConfigManager* PIconView::manager() {
00254 return m_viewManager;
00255 }
00256
00257
00258
00259
00260
00261
00262 void PIconView::initKeys() {
00263 Opie::Core::OKeyPair::List lst;
00264
00265 m_viewManager = new Opie::Core::OKeyConfigManager(m_cfg, "View-KeyBoard-Config",
00266 lst, false,this, "keyconfig name" );
00267 m_viewManager->addKeyConfig( OKeyConfigItem(tr("Beam Current Item") , "beam",
00268 Opie::Core::OResource::loadPixmap("beam", Opie::Core::OResource::SmallIcon),
00269 BeamItem, Opie::Core::OKeyPair(Qt::Key_B, Qt::ShiftButton),
00270 this, SLOT(slotBeam())) );
00271 m_viewManager->addKeyConfig( OKeyConfigItem(tr("Delete Current Item"), "delete",
00272 Opie::Core::OResource::loadPixmap("trash", Opie::Core::OResource::SmallIcon),
00273 DeleteItem, Opie::Core::OKeyPair(Qt::Key_D, Qt::ShiftButton),
00274 this, SLOT(slotTrash())) );
00275 m_viewManager->addKeyConfig( OKeyConfigItem(tr("View Current Item"), "view",
00276 Opie::Core::OResource::loadPixmap("1to1", Opie::Core::OResource::SmallIcon),
00277 ViewItem, Opie::Core::OKeyPair(Qt::Key_V, Qt::ShiftButton),
00278 this, SLOT(slotShowImage())));
00279 m_viewManager->addKeyConfig( OKeyConfigItem(tr("Show Image Info") , "info",
00280 Opie::Core::OResource::loadPixmap("DocumentTypeWord", Opie::Core::OResource::SmallIcon),
00281 InfoItem, Opie::Core::OKeyPair(Qt::Key_I, Qt::ShiftButton ),
00282 this, SLOT(slotImageInfo()) ) );
00283 m_viewManager->addKeyConfig( OKeyConfigItem(tr("Start slideshow"), "slideshow",
00284 Opie::Core::OResource::loadPixmap("1to1", Opie::Core::OResource::SmallIcon),
00285 SlideItem, Opie::Core::OKeyPair(Qt::Key_S, Qt::ShiftButton),
00286 this, SLOT(slotStartSlide())));
00287 m_viewManager->load();
00288 m_viewManager->handleWidget( m_view );
00289 }
00290
00291
00292
00293
00294
00295 void PIconView::slotDirUp()
00296 {
00297 slotChangeDir( currentView()->dirLister()->dirUp( m_path ) );
00298 }
00299
00300
00301
00302
00303 void PIconView::slotChangeDir(const QString& path) {
00304 if ( !currentView() )
00305 return;
00306
00307 PDirLister *lister = currentView()->dirLister();
00308 if (!lister )
00309 return;
00310
00311
00312
00313
00314 lister->setStartPath( path );
00315 m_path = lister->currentPath();
00316
00317 m_view->viewport()->setUpdatesEnabled( false );
00318 m_view->clear();
00319
00320
00321 g_stringPix.clear();
00322 g_stringInf.clear();
00323
00324
00325
00326
00327 addFolders( lister->folders() );
00328 addFiles( lister->files() );
00329 m_view->viewport()->setUpdatesEnabled( true );
00330
00331
00332 static_cast<QMainWindow*>(parent())->setCaption( QObject::tr("%1 - O View", "Name of the dir").arg( m_path ) );
00333 }
00334
00339 QString PIconView::currentFileName(bool &isDir)const {
00340 isDir = false;
00341 QIconViewItem* _it = m_view->currentItem();
00342 if ( !_it )
00343 return QString::null;
00344
00345 IconViewItem* it = static_cast<IconViewItem*>( _it );
00346 isDir = it->isDir();
00347 return it->path();
00348 }
00349
00350 QString PIconView::nextFileName(bool &isDir)const
00351 {
00352 isDir = false;
00353 QIconViewItem* _it1 = m_view->currentItem();
00354 if ( !_it1 )
00355 return QString::null;
00356 QIconViewItem* _it = _it1->nextItem();
00357 if ( !_it )
00358 return QString::null;
00359 IconViewItem* it = static_cast<IconViewItem*>( _it );
00360 isDir = it->isDir();
00361 return it->path();
00362 }
00363
00364 QString PIconView::prevFileName(bool &isDir)const{
00365 isDir = false;
00366 QIconViewItem* _it = m_view->currentItem();
00367 if ( !_it )
00368 return QString::null;
00369 _it = _it->prevItem();
00370 if ( !_it )
00371 return QString::null;
00372 IconViewItem* it = static_cast<IconViewItem*>( _it );
00373 isDir = it->isDir();
00374 return it->path();
00375 }
00376
00377 void PIconView::slotTrash() {
00378 bool isDir;
00379 QString pa = currentFileName( isDir );
00380 if ( isDir || pa.isEmpty() )
00381 return;
00382
00383 if (!OMessageBox::confirmDelete( this, tr("the Image"),
00384 pa, tr("Delete Image" )))
00385 return;
00386
00387
00388 currentView()->dirLister()->deleteImage( pa );
00389 delete m_view->currentItem();
00390 }
00391
00392
00393
00394
00395 void PIconView::loadViews() {
00396 ViewMap::Iterator it;
00397 ViewMap* map = viewMap();
00398 for ( it = map->begin(); it != map->end(); ++it )
00399 m_views->insertItem( it.key() );
00400 }
00401
00402 void PIconView::resetView() {
00403 m_internalReset = true;
00404
00405 g_stringPix.clear();
00406 g_stringInf.clear();
00407 if (m_mode>1) {
00408 int osize = m_iconsize;
00409 m_iconsize = m_cfg->readNumEntry("iconsize", 32);
00410 if (m_iconsize<sMIN_ICON_SIZE)m_iconsize = sMIN_ICON_SIZE;
00411 if (m_iconsize>sMAX_ICON_SIZE)m_iconsize = sMAX_ICON_SIZE;
00412 if (osize != m_iconsize) {
00413 if (_dirPix){
00414 delete _dirPix;
00415 _dirPix = 0;
00416 }
00417 if (_cpyPix){
00418 delete _cpyPix;
00419 _cpyPix = 0;
00420 }
00421 calculateGrid();
00422 }
00423 } else {
00424 m_iconsize = sDEF_ICON_SIZE;
00425 }
00426 slotViewChanged(m_views->currentItem());
00427 m_internalReset = false;
00428 }
00429
00430 void PIconView::polish()
00431 {
00432 QVBox::polish();
00433
00434 QString lastView = m_cfg->readEntry("LastView","");
00435 int cc=0;
00436 for (; cc<m_views->count();++cc) {
00437 if (m_views->text(cc)==lastView) {
00438 break;
00439 }
00440 }
00441 if (cc<m_views->count()) {
00442 m_views->setCurrentItem(cc);
00443 slotViewChanged(cc);
00444 } else {
00445 slotViewChanged(m_views->currentItem());
00446 }
00447 connect( m_views, SIGNAL(activated(int)),
00448 this, SLOT(slotViewChanged(int)) );
00449 }
00450
00451
00452
00453
00454 void PIconView::slotViewChanged( int i) {
00455 if (!m_views->count() ) {
00456 setCurrentView( 0l);
00457 return;
00458 }
00459
00460 if (m_customWidget) {
00461 delete m_customWidget;
00462 m_customWidget = 0;
00463 }
00464 PDirView* cur = currentView();
00465 if (cur) {
00466 delete cur;
00467 }
00468 QString str = m_views->text(i);
00469 ViewMap* map = viewMap();
00470 if (!map) {
00471 setCurrentView(0l);
00472 return;
00473 }
00474
00475 if (map->find(str) == map->end()) {
00476 owarn << "Key not found" << oendl;
00477 setCurrentView(0l);
00478 return;
00479 }
00480
00481 m_cfg->writeEntry("LastView",str);
00482 m_cfg->write();
00483 cur = (*(*map)[str])(*m_cfg);
00484 setCurrentView( cur );
00485 m_customWidget = cur->widget(m_hbox);
00486 if (m_customWidget) {
00487 odebug << "Got a widget" << oendl;
00488 m_customWidget->show();
00489 }
00490
00491
00492 PDirLister* lis = cur->dirLister();
00493 connect(lis, SIGNAL(sig_thumbInfo(const QString&, const QString& )),
00494 this, SLOT( slotThumbInfo(const QString&, const QString&)));
00495 connect(lis, SIGNAL( sig_thumbNail(const QString&, const QPixmap&)),
00496 this, SLOT(slotThumbNail(const QString&, const QPixmap&)));
00497 connect(lis, SIGNAL(sig_start()),
00498 this, SLOT(slotStart()));
00499 connect(lis, SIGNAL(sig_end()) ,
00500 this, SLOT(slotEnd()) );
00501 connect(lis,SIGNAL(sig_reloadDir()),this,SLOT(slotReloadDir()));
00502
00503
00504
00505
00506 if (!m_internalReset) {
00507 m_path = lis->defaultPath();
00508 }
00509 QTimer::singleShot( 0, this, SLOT(slotReloadDir()));
00510 }
00511
00512
00513 void PIconView::slotReloadDir() {
00514 slotChangeDir( m_path );
00515 }
00516
00517
00518
00519
00520
00521 void PIconView::addFolders( const QStringList& lst) {
00522 QStringList::ConstIterator it;
00523 IconViewItem * _iv;
00524
00525 for(it=lst.begin(); it != lst.end(); ++it ) {
00526 _iv = new IconViewItem( m_view, m_path+"/"+(*it), (*it),m_iconsize, true );
00527 if (m_mode==3) _iv->setTextOnly(true);
00528 }
00529 }
00530
00531 void PIconView::addFiles( const QStringList& lst) {
00532 QStringList::ConstIterator it;
00533 IconViewItem * _iv;
00534 QPixmap*m_pix = 0;
00535 QString pre = "";
00536 if (!m_path.isEmpty()) {
00537 pre = m_path+"/";
00538 }
00539 QString s = "";
00540 int pos;
00541 for (it=lst.begin(); it!= lst.end(); ++it ) {
00542 s = (*it);
00543 pos = s.find(char(0));
00544 m_pix = PPixmapCache::self()->cachedImage( pre+(*it), m_iconsize, m_iconsize );
00545 if (pos>-1) {
00546 _iv = new IconViewItem( m_view, s.mid(pos+1), s.left(pos),m_iconsize );
00547 } else {
00548 _iv = new IconViewItem( m_view, pre+(*it), (*it),m_iconsize );
00549 }
00550 if (m_mode==3) {
00551 _iv->setTextOnly(true);
00552 _iv->setPixmap(QPixmap());
00553 } else {
00554 if (m_pix) _iv->setPixmap(*m_pix);
00555 }
00556 }
00557
00558 }
00559
00560
00561
00562
00563 void PIconView::slotClicked(QIconViewItem* _it) {
00564 if(!_it )
00565 return;
00566
00567 IconViewItem* it = static_cast<IconViewItem*>(_it);
00568 if( it->isDir() )
00569 slotChangeDir( it->path() );
00570 else
00571 slotShowImage();
00572 }
00573
00574
00575
00576
00577
00578
00579 void PIconView::slotRetrun( QIconViewItem *_it ) {
00580 if(!_it )
00581 return;
00582
00583 IconViewItem* it = static_cast<IconViewItem*>(_it);
00584 if( it->isDir() )
00585 slotChangeDir( it->path() );
00586 else
00587 QTimer::singleShot(0, this, SLOT(slotShowImage()) );
00588 }
00589
00590
00591
00592
00593
00594 void PIconView::slotThumbInfo( const QString& _path, const QString& str ) {
00595 IconViewItem* item = g_stringInf[_path];
00596 if (!item )
00597 return;
00598
00599 if (m_mode == 2) {
00600 return;
00601 }
00602 if ( item->intersects(QRect( m_view->contentsX(),m_view->contentsY(),
00603 m_view->contentsWidth(), m_view->contentsHeight() ) ) )
00604 m_updatet = true;
00605
00606 item->setText( str );
00607 g_stringInf.remove( _path );
00608 }
00609
00610
00611
00612
00613 void PIconView::slotThumbNail(const QString& _path, const QPixmap &pix) {
00614 IconViewItem* item = g_stringPix[_path];
00615 if (!item )
00616 return;
00617
00618 if ( item->intersects(QRect( m_view->contentsX(),m_view->contentsY(),
00619 m_view->contentsWidth(), m_view->contentsHeight() ) ) )
00620 m_updatet = true;
00621
00622 if (pix.width()>0) {
00623 if (pix.width()<m_iconsize) {
00624 QPixmap p(m_iconsize,m_iconsize);
00625 p.fill();
00626 QPainter pa(&p);
00627 int offset = (m_iconsize-pix.width())/2;
00628 int offy = (m_iconsize-pix.height())/2;
00629 if (offy<0) offy=0;
00630 pa.drawPixmap(offset,offy,pix);
00631 pa.end();
00632 PPixmapCache::self()->insertImage( _path, p, m_iconsize, m_iconsize );
00633 item->setPixmap(p,true);
00634 } else {
00635 PPixmapCache::self()->insertImage( _path, pix, m_iconsize, m_iconsize );
00636 item->setPixmap(pix,true);
00637 }
00638
00639 } else {
00640 PPixmapCache::self()->insertImage( _path, Opie::Core::OResource::loadPixmap( "UnknownDocument",
00641 Opie::Core::OResource::SmallIcon ), m_iconsize, m_iconsize );
00642 }
00643 g_stringPix.remove( _path );
00644 m_view->arrangeItemsInGrid(true);
00645 }
00646
00647
00648
00649
00650
00651 void PIconView::slotRename() {
00652
00653 }
00654
00655
00656
00657
00658
00659 void PIconView::slotBeam() {
00660 bool isDir;
00661 QString pa = currentFileName( isDir );
00662 if ( isDir && pa.isEmpty() )
00663 return;
00664
00665 Ir* ir = new Ir( this );
00666 connect( ir, SIGNAL(done(Ir*)),
00667 this, SLOT(slotBeamDone(Ir*)));
00668 ir->send(pa, tr( "Image" ) );
00669 }
00670
00671
00672
00673
00674 void PIconView::slotBeamDone( Ir* ir) {
00675 delete ir;
00676 }
00677
00678 void PIconView::slotStart() {
00679 m_view->viewport()->setUpdatesEnabled( false );
00680 }
00681
00682 void PIconView::slotEnd() {
00683 if ( m_updatet )
00684 m_view->arrangeItemsInGrid( );
00685 m_view->viewport()->setUpdatesEnabled( true );
00686 m_updatet = false;
00687 }
00688
00689 void PIconView::slotShowLast()
00690 {
00691 QIconViewItem* last_it = m_view->lastItem();
00692 if (!last_it) return;
00693 m_view->setCurrentItem(last_it);
00694 IconViewItem* it = static_cast<IconViewItem*>( last_it );
00695 bool isDir = it->isDir();
00696 QString name = it->path();
00697 if (!isDir && !name.isEmpty()) {
00698 slotShowImage(name);
00699 return;
00700 }
00701 bool first_loop = true;
00702 while(isDir==true) {
00703 if (!first_loop) {
00704 m_view->setCurrentItem(m_view->currentItem()->prevItem());
00705 } else {
00706 first_loop = false;
00707 }
00708 name = prevFileName(isDir);
00709 }
00710
00711 if (name.isEmpty()) return;
00712
00713 m_view->setCurrentItem(m_view->currentItem()->prevItem());
00714 slotShowImage(name);
00715 }
00716
00717 bool PIconView::slotShowFirst()
00718 {
00719
00720 QIconViewItem* first_it = m_view->firstItem();
00721 if (!first_it) return false;
00722 m_view->setCurrentItem(first_it);
00723 IconViewItem* it = static_cast<IconViewItem*>( first_it );
00724 bool isDir = it->isDir();
00725 QString name = it->path();
00726 if (!isDir && !name.isEmpty()) {
00727 slotShowImage(name);
00728 return false;
00729 }
00730 bool first_loop = true;
00731 while(isDir==true) {
00732
00733 if (!first_loop) {
00734 m_view->setCurrentItem(m_view->currentItem()->nextItem());
00735 } else {
00736 first_loop = false;
00737 }
00738 name = nextFileName(isDir);
00739 }
00740 if (name.isEmpty()) return false;
00741
00742 m_view->setCurrentItem(m_view->currentItem()->nextItem());
00743 slotShowImage(name);
00744 return true;
00745 }
00746
00747 void PIconView::slotShowNext()
00748 {
00749 bool isDir = false;
00750 QString name = nextFileName(isDir);
00751 while (isDir==true) {
00752 m_view->setCurrentItem(m_view->currentItem()->nextItem());
00753 name = nextFileName(isDir);
00754 }
00755 if (name.isEmpty()) {
00756 slotShowFirst();
00757 return;
00758 }
00759 if (isDir) return;
00760
00761 m_view->setCurrentItem(m_view->currentItem()->nextItem());
00762 slotShowImage(name);
00763 }
00764
00765 void PIconView::slotShowPrev()
00766 {
00767 bool isDir = false;
00768 QString name = prevFileName(isDir);
00769 while (isDir==true) {
00770
00771 m_view->setCurrentItem(m_view->currentItem()->prevItem());
00772 name = prevFileName(isDir);
00773 }
00774 if (name.isEmpty()) {
00775 slotShowLast();
00776 return;
00777 }
00778 if (isDir) return;
00779
00780 m_view->setCurrentItem(m_view->currentItem()->prevItem());
00781 slotShowImage(name);
00782 }
00783
00784 void PIconView::slotShowImage()
00785 {
00786 bool isDir = false;
00787 QString name = currentFileName(isDir);
00788 if (isDir) return;
00789 slotShowImage( name );
00790 }
00791 void PIconView::slotShowImage( const QString& name) {
00792 PDirLister *lister = currentView()->dirLister();
00793 QString r_name = lister->nameToFname(name);
00794 emit sig_display(r_name);
00795 }
00796
00797 void PIconView::slotStartSlide() {
00798 bool isDir = false;
00799 QString name = currentFileName(isDir);
00800 if (isDir) {
00801 if (!slotShowFirst())
00802 return;
00803 } else {
00804 slotShowImage( name );
00805 }
00806 int t = m_cfg->readNumEntry("slideshowtimeout", 2);
00807 emit sig_startslide(t);
00808 }
00809
00810 void PIconView::slotImageInfo() {
00811 bool isDir = false;
00812 QString name = currentFileName(isDir);
00813 if (isDir) return;
00814 slotImageInfo( name );
00815 }
00816
00817 void PIconView::slotImageInfo( const QString& name) {
00818 PDirLister *lister = currentView()->dirLister();
00819 QString r_name = lister->nameToFname(name);
00820 emit sig_showInfo(r_name );
00821 }
00822
00823
00824 void PIconView::slotChangeMode( int mode ) {
00825 if ( mode >= 1 && mode <= 3 ) {
00826 m_mode = mode;
00827 m_cfg->writeEntry("ListViewMode", m_mode);
00828
00829 m_view->clear();
00830 if (m_mode >1) {
00831 m_view->setResizeMode(QIconView::Adjust);
00832 } else {
00833 m_view->setResizeMode(QIconView::Fixed);
00834 }
00835 if (m_mode==1) {
00836 m_iconsize = sDEF_ICON_SIZE;
00837 } else {
00838 m_iconsize = m_cfg->readNumEntry("iconsize", 32);
00839 if (m_iconsize<sMIN_ICON_SIZE)m_iconsize = sMIN_ICON_SIZE;
00840 if (m_iconsize>sMAX_ICON_SIZE)m_iconsize = sMAX_ICON_SIZE;
00841 }
00842 if (_dirPix){
00843 delete _dirPix;
00844 _dirPix = 0;
00845 }
00846 if (_cpyPix){
00847 delete _cpyPix;
00848 _cpyPix = 0;
00849 }
00850 calculateGrid();
00851 slotReloadDir();
00852 }
00853 }
00854
00855
00856 void PIconView::resizeEvent( QResizeEvent* re ) {
00857 calculateGrid(re);
00858 QVBox::resizeEvent( re );
00859
00860 }
00861
00862
00863 void PIconView::calculateGrid(QResizeEvent* re)
00864 {
00865 int viewerWidth;
00866 if (re) {
00867 viewerWidth=re->size().width();
00868 } else {
00869 int dw = QApplication::desktop()->width();
00870 viewerWidth = dw-style().scrollBarExtent().width();
00871 }
00872
00873 QIconView::ItemTextPos pos;
00874 switch( m_mode ) {
00875 case 2:
00876 pos = QIconView::Bottom;
00877 break;
00878 case 3:
00879 case 1:
00880 default:
00881 pos = QIconView::Right;
00882 break;
00883 }
00884 int cache = 0;
00885 m_view->setItemTextPos( pos );
00886 switch (m_mode) {
00887 case 2:
00888 m_view->setSpacing(2);
00889 m_view->setGridX(m_iconsize);
00890 m_view->setGridY(-1);
00891 cache = (int)((double)sDEF_ICON_SIZE/(double)m_iconsize*80.0);
00892 odebug << "cache size: " << cache << oendl;
00893 PPixmapCache::self()->setMaxImages(cache);
00894 break;
00895 case 3:
00896 m_view->setSpacing(10);
00897 m_view->setGridX( fontMetrics().width("testimage.jpg")+20);
00898 m_view->setGridY(8);
00899 PPixmapCache::self()->setMaxImages(2);
00900 break;
00901 case 1:
00902 default:
00903 m_view->setSpacing(10);
00904 m_view->setGridX( viewerWidth-3*m_view->spacing());
00905 m_view->setGridY( fontMetrics().height()*2+40 );
00906 PPixmapCache::self()->setMaxImages(20);
00907 break;
00908 }
00909 }