-rw-r--r-- | noncore/graphics/opie-eye/gui/iconview.cpp | 38 |
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 { bool isDir()const { return m_isDir; } void setText( const QString& ); bool textOnly()const{return m_textOnly;} void setTextOnly(bool how){m_textOnly=how;} /* just for starting recalc of item rect! */ virtual void setPixmap( const QPixmap & icon, bool recalc, bool redraw = TRUE ); /* just for starting recalc of item rect! */ virtual void setPixmap( const QPixmap & icon); protected: mutable QPixmap* m_pix; int m_iconsize; void check_pix()const; private: QString m_path; bool m_isDir : 1; bool m_noInfo :1; bool m_textOnly:1; bool m_NameOnly:1; bool m_Pixset:1; }; class TextViewItem : public IconViewItem { TextViewItem( QIconView*, const QString& path, const QString& name, int a_iconsize , bool isDir = false); QPixmap *pixmap()const; void setText( const QString& ); }; class ThumbViewItem : public IconViewItem { ThumbViewItem( QIconView*, const QString& path, const QString& name, int a_iconsize, bool isDir = false ); QPixmap *pixmap()const; void setText( const QString& ); }; /* * If we request an Image or String * we add it to the map */ static QMap<QString, IconViewItem*> g_stringInf; static QMap<QString, IconViewItem*> g_stringPix; IconViewItem::IconViewItem( QIconView* view,const QString& path, const QString& name, int a_iconsize, bool isDir) : QIconViewItem( view, name ), m_path( path ), m_isDir( isDir ), m_noInfo( false ),m_textOnly(false),m_Pixset(false) { m_iconsize = a_iconsize; if ( isDir ) { - if (_dirPix && _dirPix->width()!=m_iconsize) { - delete _dirPix; - _dirPix = 0; - } if (!_dirPix ) { _dirPix = new QPixmap( Resource::loadPixmap("advancedfm/FileBrowser")); } } else { if (!_unkPix ) { _unkPix = new QPixmap( Resource::loadPixmap( "UnknownDocument" ) ); } } check_pix(); } inline void IconViewItem::check_pix()const { - if (_cpyPix && _cpyPix->width()!=m_iconsize) { - delete _cpyPix; - _cpyPix = 0; - } if (_dirPix && _dirPix->width()>m_iconsize) { QPixmap*Pix = new QPixmap(*_dirPix); Pix->resize(m_iconsize,m_iconsize); delete _dirPix; _dirPix = Pix; } if (!_cpyPix && _unkPix) { if (_unkPix->width()>=m_iconsize) { _cpyPix = new QPixmap(*_unkPix); if (_unkPix->width()>m_iconsize) _cpyPix->resize(m_iconsize,m_iconsize); } else { _cpyPix = new QPixmap(m_iconsize,m_iconsize); _cpyPix->fill(); QPainter pa(_cpyPix); int offset = (m_iconsize-_unkPix->width())/2; int offy = (m_iconsize-_unkPix->height())/2; if (offy<0) offy=0; pa.drawPixmap(offset,offy,*_unkPix); pa.end(); } } } inline void IconViewItem::setPixmap( const QPixmap & , bool, bool ) { m_Pixset = true; calcRect(text()); } inline void IconViewItem::setPixmap( const QPixmap & ) { m_Pixset = true; calcRect(text()); } inline QPixmap* IconViewItem::pixmap()const { // owarn << "Name is " << m_path.right( 15 ) << " rect is " << rect().x() << " " << rect().y() // << " " << rect().width() << " " << rect().height() << " | " << iconView()->contentsX() // << " " << iconView()->contentsY() << oendl; if (textOnly()&&!m_isDir) { if (!_emptyPix) _emptyPix = new QPixmap(0,0,1); return _emptyPix; } if ( m_isDir ) return _dirPix; else{ if (!m_noInfo && !g_stringInf.contains( m_path ) ) { @@ -378,99 +370,111 @@ QString PIconView::nextFileName(bool &isDir)const return it->path(); } QString PIconView::prevFileName(bool &isDir)const{ isDir = false; QIconViewItem* _it = m_view->currentItem(); if ( !_it ) return QString::null; _it = _it->prevItem(); if ( !_it ) return QString::null; IconViewItem* it = static_cast<IconViewItem*>( _it ); isDir = it->isDir(); return it->path(); } void PIconView::slotTrash() { bool isDir; QString pa = currentFileName( isDir ); if ( isDir && pa.isEmpty() ) return; if (!QPEMessageBox::confirmDelete( this, tr("Delete Image" ), tr("the Image %1" ).arg(pa))) return currentView()->dirLister()->deleteImage( pa ); delete m_view->currentItem(); } /* * see what views are available */ void PIconView::loadViews() { ViewMap::Iterator it; ViewMap* map = viewMap(); for ( it = map->begin(); it != map->end(); ++it ) m_views->insertItem( it.key() ); } void PIconView::resetView() { m_internalReset = true; // Also invalidate the cache. We can't cancel the operations anyway g_stringPix.clear(); g_stringInf.clear(); if (m_mode>1) { + int osize = m_iconsize; m_iconsize = m_cfg->readNumEntry("iconsize", 32); if (m_iconsize<12)m_iconsize = 12; if (m_iconsize>64)m_iconsize = 64; + if (osize != m_iconsize) { + if (_dirPix){ + delete _dirPix; + _dirPix = 0; + } + if (_cpyPix){ + delete _cpyPix; + _cpyPix = 0; + } + calculateGrid(); + } } else { m_iconsize = 64; } slotViewChanged(m_views->currentItem()); m_internalReset = false; } /* *swicth view reloadDir and connect signals */ void PIconView::slotViewChanged( int i) { if (!m_views->count() ) { setCurrentView( 0l); return; } PDirView* cur = currentView(); if (cur) delete cur; QString str = m_views->text(i); ViewMap* map = viewMap(); if (!map) { setCurrentView(0l); return; } if (map->find(str) == map->end()) { owarn << "Key not found" << oendl; setCurrentView(0l); return; } m_cfg->writeEntry("LastView",str); m_cfg->write(); cur = (*(*map)[str])(*m_cfg); setCurrentView( cur ); /* connect to the signals of the lister */ PDirLister* lis = cur->dirLister(); connect(lis, SIGNAL(sig_thumbInfo(const QString&, const QString& )), this, SLOT( slotThumbInfo(const QString&, const QString&))); connect(lis, SIGNAL( sig_thumbNail(const QString&, const QPixmap&)), this, SLOT(slotThumbNail(const QString&, const QPixmap&))); connect(lis, SIGNAL(sig_start()), this, SLOT(slotStart())); connect(lis, SIGNAL(sig_end()) , this, SLOT(slotEnd()) ); @@ -762,104 +766,116 @@ void PIconView::slotShowImage( const QString& name) { emit sig_display(r_name); } void PIconView::slotStartSlide() { bool isDir = false; QString name = currentFileName(isDir); if (isDir) { if (!slotShowFirst()) return; } else { slotShowImage( name ); } int t = m_cfg->readNumEntry("slideshowtimeout", 2); emit sig_startslide(t); } void PIconView::slotImageInfo() { bool isDir = false; QString name = currentFileName(isDir); if (isDir) return; slotImageInfo( name ); } void PIconView::slotImageInfo( const QString& name) { PDirLister *lister = currentView()->dirLister(); QString r_name = lister->nameToFname(name); emit sig_showInfo(r_name ); } void PIconView::slotChangeMode( int mode ) { if ( mode >= 1 && mode <= 3 ) { m_mode = mode; m_cfg->writeEntry("ListViewMode", m_mode); /* performance! */ m_view->clear(); if (m_mode >1) { m_view->setResizeMode(QIconView::Adjust); } else { m_view->setResizeMode(QIconView::Fixed); } if (m_mode==1) { m_iconsize = 64; } else { m_iconsize = m_cfg->readNumEntry("iconsize", 32); if (m_iconsize<12)m_iconsize = 12; if (m_iconsize>64)m_iconsize = 64; } - + if (_dirPix){ + delete _dirPix; + _dirPix = 0; + } + if (_cpyPix){ + delete _cpyPix; + _cpyPix = 0; + } calculateGrid(); slotReloadDir(); } } void PIconView::resizeEvent( QResizeEvent* re ) { calculateGrid(re); QVBox::resizeEvent( re ); //calculateGrid(); } void PIconView::calculateGrid(QResizeEvent* re) { int viewerWidth; if (re) { viewerWidth=re->size().width(); } else { int dw = QApplication::desktop()->width(); viewerWidth = dw-style().scrollBarExtent().width(); } QIconView::ItemTextPos pos; switch( m_mode ) { case 2: pos = QIconView::Bottom; break; case 3: case 1: default: pos = QIconView::Right; break; } + int cache = 0; m_view->setItemTextPos( pos ); switch (m_mode) { case 2: + m_view->setSpacing(2); m_view->setGridX(m_iconsize); m_view->setGridY(-1); - PPixmapCache::self()->setMaxImages(40); + cache = (int)((double)64/(double)m_iconsize*40.0); + odebug << "cache size: " << cache << oendl; + PPixmapCache::self()->setMaxImages(cache); break; case 3: + m_view->setSpacing(10); m_view->setGridX( fontMetrics().width("testimage.jpg")+20); m_view->setGridY(8); PPixmapCache::self()->setMaxImages(2); break; case 1: default: + m_view->setSpacing(10); m_view->setGridX( viewerWidth-3*m_view->spacing()); m_view->setGridY( fontMetrics().height()*2+40 ); PPixmapCache::self()->setMaxImages(20); break; } - m_view->setSpacing(10); } |