author | alwin <alwin> | 2004-11-07 19:37:17 (UTC) |
---|---|---|
committer | alwin <alwin> | 2004-11-07 19:37:17 (UTC) |
commit | 9218d2bf841e1f999475c86ba602dc1cd7e338f6 (patch) (side-by-side diff) | |
tree | eb02e9dc2d1d4e8188f2c7cf8260d81298352117 | |
parent | c7eb493b3c2efa871104b27b6abf487da94f33f6 (diff) | |
download | opie-9218d2bf841e1f999475c86ba602dc1cd7e338f6.zip opie-9218d2bf841e1f999475c86ba602dc1cd7e338f6.tar.gz opie-9218d2bf841e1f999475c86ba602dc1cd7e338f6.tar.bz2 |
try to improve the icon scaling
-rw-r--r-- | noncore/graphics/opie-eye/gui/iconview.cpp | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/noncore/graphics/opie-eye/gui/iconview.cpp b/noncore/graphics/opie-eye/gui/iconview.cpp index f173ecc..5472ead 100644 --- a/noncore/graphics/opie-eye/gui/iconview.cpp +++ b/noncore/graphics/opie-eye/gui/iconview.cpp @@ -1,314 +1,317 @@ /* * GPLv2 zecke@handhelds.org * No WArranty... */ #include "iconview.h" #include <lib/imagecache.h> #include <gui/imageinfoui.h> #include <iface/dirview.h> #include <iface/dirlister.h> #include <opie2/oconfig.h> #include <opie2/okeyconfigwidget.h> #include <opie2/odebug.h> #include <opie2/oimagescrollview.h> #include <qpe/resource.h> #include <qpe/qpemessagebox.h> #include <qpe/ir.h> #include <qpe/qcopenvelope_qws.h> #include <qpe/qpeapplication.h> #include <qiconview.h> #include <qlabel.h> #include <qhbox.h> #include <qcombobox.h> #include <qdir.h> #include <qapplication.h> #include <qmainwindow.h> #include <qtimer.h> #include <qstyle.h> using Opie::Core::OKeyConfigItem; /* * The Icons, Request Cache and IconViewItem for the IconView */ namespace { static QPixmap* _dirPix = 0; static QPixmap* _unkPix = 0; static QPixmap* _cpyPix = 0; static QPixmap* _emptyPix = 0; class IconViewItem : public QIconViewItem { public: IconViewItem( QIconView*, const QString& path, const QString& name,int a_iconsize, bool isDir = false); QPixmap* pixmap()const; QString path()const { return m_path; } 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 = new QPixmap( Resource::loadPixmap("advancedfm/FileBrowser")); } } else { if (!_unkPix ) { _unkPix = new QPixmap( Resource::loadPixmap( "UnknownDocument" ) ); } } check_pix(); } inline void IconViewItem::check_pix()const { if (_dirPix && _dirPix->width()>m_iconsize) { - QPixmap*Pix = new QPixmap(*_dirPix); - Pix->resize(m_iconsize,m_iconsize); - delete _dirPix; - _dirPix = Pix; + QImage Pix = _dirPix->convertToImage(); + *_dirPix = Pix.smoothScale(m_iconsize,m_iconsize); } if (!_cpyPix && _unkPix) { if (_unkPix->width()>=m_iconsize) { - _cpyPix = new QPixmap(*_unkPix); - if (_unkPix->width()>m_iconsize) - _cpyPix->resize(m_iconsize,m_iconsize); + QImage Pix = _unkPix->convertToImage(); + _cpyPix = new QPixmap(); + if (_unkPix->width()>m_iconsize) { + *_cpyPix = Pix.smoothScale(m_iconsize,m_iconsize); + } else { + _cpyPix->convertFromImage(Pix); + } + } 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 ) ) { g_stringInf.insert( m_path, const_cast<IconViewItem*>(this)); currentView()->dirLister()->imageInfo( m_path ); } m_pix = PPixmapCache::self()->cachedImage( m_path, m_iconsize, m_iconsize ); if (!m_pix && !g_stringPix.contains( m_path )) { check_pix(); g_stringPix.insert( m_path, const_cast<IconViewItem*>(this)); currentView()->dirLister()->thumbNail( m_path, m_iconsize, m_iconsize); } return m_pix ? m_pix : _cpyPix; } } inline void IconViewItem::setText( const QString& str ) { QString text = QIconViewItem::text()+"\n"+str; m_noInfo = true; QIconViewItem::setText( text ); } } /* * Set up the GUI.. initialize the slave set up gui * and also load a dir */ PIconView::PIconView( QWidget* wid, Opie::Core::OConfig* cfg ) : QVBox( wid ), m_cfg( cfg ), m_updatet( false ) { { QCopEnvelope( "QPE/Application/opie-eye_slave", "refUp()" ); } m_path = QDir::homeDirPath(); m_mode = 0; m_iconsize = 32; m_internalReset = false; QHBox *hbox = new QHBox( this ); QLabel* lbl = new QLabel( hbox ); lbl->setText( tr("View as" ) ); m_views = new QComboBox( hbox, "View As" ); m_view= new QIconView( this ); connect(m_view, SIGNAL(clicked(QIconViewItem*) ), this, SLOT(slotClicked(QIconViewItem*)) ); connect(m_view, SIGNAL(returnPressed(QIconViewItem*)), this, SLOT(slotClicked(QIconViewItem*)) ); m_view->setArrangement( QIconView::LeftToRight ); m_mode = m_cfg->readNumEntry("ListViewMode", 1); QString lastView = m_cfg->readEntry("LastView",""); if (m_mode < 1 || m_mode>3) m_mode = 1; m_view->setItemTextPos( QIconView::Right ); if (m_mode >1) { m_view->setResizeMode(QIconView::Adjust); } else { m_view->setResizeMode(QIconView::Fixed); } m_iconsize = m_cfg->readNumEntry("iconsize", 32); if (m_iconsize<12)m_iconsize = 12; if (m_iconsize>64)m_iconsize = 64; calculateGrid(); initKeys(); loadViews(); int cc=0; for (; cc<m_views->count();++cc) { if (m_views->text(cc)==lastView) { break; } } if (cc<m_views->count()) { m_views->setCurrentItem(cc); slotViewChanged(cc); } else { slotViewChanged(m_views->currentItem()); } connect( m_views, SIGNAL(activated(int)), this, SLOT(slotViewChanged(int)) ); } /* * Unref the slave and save the keyboard manager */ PIconView::~PIconView() { { QCopEnvelope( "QPE/Application/opie-eye_slave", "refDown()" ); } m_viewManager->save(); delete m_viewManager; } Opie::Core::OKeyConfigManager* PIconView::manager() { return m_viewManager; } /* * init the KeyBoard Shortcuts * called from the c'tor */ void PIconView::initKeys() { Opie::Core::OKeyPair::List lst; lst.append( Opie::Core::OKeyPair::upArrowKey() ); lst.append( Opie::Core::OKeyPair::downArrowKey() ); lst.append( Opie::Core::OKeyPair::leftArrowKey() ); lst.append( Opie::Core::OKeyPair::rightArrowKey() ); lst.append( Opie::Core::OKeyPair::returnKey() ); m_viewManager = new Opie::Core::OKeyConfigManager(m_cfg, "View-KeyBoard-Config", lst, false,this, "keyconfig name" ); m_viewManager->addKeyConfig( OKeyConfigItem(tr("Beam Current Item") , "beam", Resource::loadPixmap("beam"), BeamItem, Opie::Core::OKeyPair(Qt::Key_B, Qt::ShiftButton), this, SLOT(slotBeam())) ); m_viewManager->addKeyConfig( OKeyConfigItem(tr("Delete Current Item"), "delete", Resource::loadPixmap("trash"), DeleteItem, Opie::Core::OKeyPair(Qt::Key_D, Qt::ShiftButton), this, SLOT(slotTrash())) ); m_viewManager->addKeyConfig( OKeyConfigItem(tr("View Current Item"), "view", Resource::loadPixmap("1to1"), ViewItem, Opie::Core::OKeyPair(Qt::Key_V, Qt::ShiftButton), this, SLOT(slotShowImage()))); m_viewManager->addKeyConfig( OKeyConfigItem(tr("Show Image Info") , "info", Resource::loadPixmap("DocumentTypeWord"), InfoItem, Opie::Core::OKeyPair(Qt::Key_I, Qt::ShiftButton ), this, SLOT(slotImageInfo()) ) ); m_viewManager->addKeyConfig( OKeyConfigItem(tr("Start slideshow"), "slideshow", Resource::loadPixmap("1to1"), SlideItem, Opie::Core::OKeyPair(Qt::Key_S, Qt::ShiftButton), this, SLOT(slotStartSlide()))); m_viewManager->load(); m_viewManager->handleWidget( m_view ); } /* * change one dir up */ void PIconView::slotDirUp() { slotChangeDir( currentView()->dirLister()->dirUp( m_path ) ); } /* * change the dir */ void PIconView::slotChangeDir(const QString& path) { if ( !currentView() ) return; |