-rw-r--r-- | noncore/graphics/opie-eye/gui/iconview.cpp | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/noncore/graphics/opie-eye/gui/iconview.cpp b/noncore/graphics/opie-eye/gui/iconview.cpp index 729b64f..aeaa3c6 100644 --- a/noncore/graphics/opie-eye/gui/iconview.cpp +++ b/noncore/graphics/opie-eye/gui/iconview.cpp | |||
@@ -25,32 +25,33 @@ | |||
25 | #include <qmainwindow.h> | 25 | #include <qmainwindow.h> |
26 | #include <qtimer.h> | 26 | #include <qtimer.h> |
27 | #include <qstyle.h> | 27 | #include <qstyle.h> |
28 | 28 | ||
29 | 29 | ||
30 | 30 | ||
31 | namespace { | 31 | namespace { |
32 | QPixmap* _dirPix = 0; | 32 | QPixmap* _dirPix = 0; |
33 | QPixmap* _unkPix = 0; | 33 | QPixmap* _unkPix = 0; |
34 | class IconViewItem : public QIconViewItem { | 34 | class IconViewItem : public QIconViewItem { |
35 | public: | 35 | public: |
36 | IconViewItem( QIconView*, const QString& path, const QString& name, bool isDir = false); | 36 | IconViewItem( QIconView*, const QString& path, const QString& name, bool isDir = false); |
37 | QPixmap* pixmap()const; | 37 | QPixmap* pixmap()const; |
38 | QString path()const { return m_path; } | 38 | QString path()const { return m_path; } |
39 | bool isDir()const { return m_isDir; } | 39 | bool isDir()const { return m_isDir; } |
40 | void setText( const QString& ); | 40 | void setText( const QString& ); |
41 | void reCalc(); | ||
41 | private: | 42 | private: |
42 | mutable QPixmap* m_pix; | 43 | mutable QPixmap* m_pix; |
43 | QString m_path; | 44 | QString m_path; |
44 | bool m_isDir : 1; | 45 | bool m_isDir : 1; |
45 | bool m_noInfo :1; | 46 | bool m_noInfo :1; |
46 | }; | 47 | }; |
47 | 48 | ||
48 | 49 | ||
49 | /* | 50 | /* |
50 | * If we request an Image or String | 51 | * If we request an Image or String |
51 | * we add it to the map | 52 | * we add it to the map |
52 | */ | 53 | */ |
53 | QMap<QString, IconViewItem*> g_stringInf; | 54 | QMap<QString, IconViewItem*> g_stringInf; |
54 | QMap<QString, IconViewItem*> g_stringPix; | 55 | QMap<QString, IconViewItem*> g_stringPix; |
55 | 56 | ||
56 | IconViewItem::IconViewItem( QIconView* view,const QString& path, | 57 | IconViewItem::IconViewItem( QIconView* view,const QString& path, |
@@ -73,58 +74,63 @@ namespace { | |||
73 | g_stringInf.insert( m_path, const_cast<IconViewItem*>(this)); | 74 | g_stringInf.insert( m_path, const_cast<IconViewItem*>(this)); |
74 | } | 75 | } |
75 | 76 | ||
76 | m_pix = PPixmapCache::self()->cachedImage( m_path, 64, 64 ); | 77 | m_pix = PPixmapCache::self()->cachedImage( m_path, 64, 64 ); |
77 | if ( !m_pix && !g_stringPix.contains( m_path )) { | 78 | if ( !m_pix && !g_stringPix.contains( m_path )) { |
78 | currentView()->dirLister()->thumbNail( m_path, 64, 64 ); | 79 | currentView()->dirLister()->thumbNail( m_path, 64, 64 ); |
79 | g_stringPix.insert( m_path, const_cast<IconViewItem*>(this)); | 80 | g_stringPix.insert( m_path, const_cast<IconViewItem*>(this)); |
80 | } | 81 | } |
81 | return m_pix ? m_pix : _unkPix; | 82 | return m_pix ? m_pix : _unkPix; |
82 | } | 83 | } |
83 | } | 84 | } |
84 | inline void IconViewItem::setText( const QString& str ) { | 85 | inline void IconViewItem::setText( const QString& str ) { |
85 | QString text = QIconViewItem::text()+"\n"+str; | 86 | QString text = QIconViewItem::text()+"\n"+str; |
86 | m_noInfo = true; | 87 | m_noInfo = true; |
87 | QIconViewItem::setText( text ); | 88 | QIconViewItem::setText( text ); |
88 | } | 89 | } |
90 | |||
91 | inline void IconViewItem::reCalc() | ||
92 | { | ||
93 | calcRect(); | ||
94 | } | ||
89 | } | 95 | } |
90 | 96 | ||
91 | 97 | ||
92 | PIconView::PIconView( QWidget* wid, Config* cfg ) | 98 | PIconView::PIconView( QWidget* wid, Config* cfg ) |
93 | : QVBox( wid ), m_cfg( cfg ) | 99 | : QVBox( wid ), m_cfg( cfg ) |
94 | { | 100 | { |
95 | { | 101 | { |
96 | QCopEnvelope( "QPE/Application/opie-eye_slave", "refUp()" ); | 102 | QCopEnvelope( "QPE/Application/opie-eye_slave", "refUp()" ); |
97 | } | 103 | } |
98 | m_path = QDir::homeDirPath(); | 104 | m_path = QDir::homeDirPath(); |
99 | 105 | ||
100 | QHBox *hbox = new QHBox( this ); | 106 | QHBox *hbox = new QHBox( this ); |
101 | QLabel* lbl = new QLabel( hbox ); | 107 | QLabel* lbl = new QLabel( hbox ); |
102 | lbl->setText( tr("View as" ) ); | 108 | lbl->setText( tr("View as" ) ); |
103 | 109 | ||
104 | m_views = new QComboBox( hbox, "View As" ); | 110 | m_views = new QComboBox( hbox, "View As" ); |
105 | connect( m_views, SIGNAL(activated(int)), | 111 | connect( m_views, SIGNAL(activated(int)), |
106 | this, SLOT(slotViewChanged(int)) ); | 112 | this, SLOT(slotViewChanged(int)) ); |
107 | 113 | ||
108 | m_view= new QIconView( this ); | 114 | m_view= new QIconView( this ); |
109 | connect(m_view, SIGNAL(clicked(QIconViewItem*) ), | 115 | connect(m_view, SIGNAL(clicked(QIconViewItem*) ), |
110 | this, SLOT(slotClicked(QIconViewItem*)) ); | 116 | this, SLOT(slotClicked(QIconViewItem*)) ); |
111 | 117 | ||
112 | m_view->setArrangement( QIconView::LeftToRight ); | 118 | m_view->setArrangement( QIconView::LeftToRight ); |
113 | m_view->setItemTextPos( QIconView::Right ); | 119 | m_view->setItemTextPos( QIconView::Right ); |
114 | 120 | m_view->setResizeMode(QIconView::Adjust); | |
115 | 121 | ||
116 | int dw = QApplication::desktop()->width(); | 122 | int dw = QApplication::desktop()->width(); |
117 | int viewerWidth = dw-style().scrollBarExtent().width(); | 123 | int viewerWidth = dw-style().scrollBarExtent().width(); |
118 | m_view->setGridX( viewerWidth-2*m_view->spacing() ); | 124 | m_view->setGridX( viewerWidth-2*m_view->spacing() ); |
119 | m_view->setGridY( fontMetrics().height()*2+40 ); | 125 | m_view->setGridY( fontMetrics().height()*2+40 ); |
120 | loadViews(); | 126 | loadViews(); |
121 | slotViewChanged( m_views->currentItem() ); | 127 | slotViewChanged( m_views->currentItem() ); |
122 | } | 128 | } |
123 | 129 | ||
124 | PIconView::~PIconView() { | 130 | PIconView::~PIconView() { |
125 | { | 131 | { |
126 | QCopEnvelope( "QPE/Application/opie-eye_slave", "refDown()" ); | 132 | QCopEnvelope( "QPE/Application/opie-eye_slave", "refDown()" ); |
127 | } | 133 | } |
128 | } | 134 | } |
129 | 135 | ||
130 | void PIconView::slotDirUp() { | 136 | void PIconView::slotDirUp() { |
@@ -245,41 +251,50 @@ void PIconView::addFiles( const QStringList& lst) { | |||
245 | } | 251 | } |
246 | 252 | ||
247 | void PIconView::slotClicked(QIconViewItem* _it) { | 253 | void PIconView::slotClicked(QIconViewItem* _it) { |
248 | if(!_it ) | 254 | if(!_it ) |
249 | return; | 255 | return; |
250 | 256 | ||
251 | IconViewItem* it = static_cast<IconViewItem*>(_it); | 257 | IconViewItem* it = static_cast<IconViewItem*>(_it); |
252 | if( it->isDir() ) | 258 | if( it->isDir() ) |
253 | slotChangeDir( it->path() ); | 259 | slotChangeDir( it->path() ); |
254 | else // view image | 260 | else // view image |
255 | ; | 261 | ; |
256 | } | 262 | } |
257 | 263 | ||
258 | void PIconView::slotThumbInfo( const QString& _path, const QString& str ) { | 264 | void PIconView::slotThumbInfo( const QString& _path, const QString& str ) { |
259 | if ( g_stringInf.contains( _path ) ) { | 265 | if ( g_stringInf.contains( _path ) ) { |
260 | IconViewItem* item = g_stringInf[_path]; | 266 | IconViewItem* item = g_stringInf[_path]; |
261 | item->setText( str ); | 267 | /* if set the view shows nonsens! |
268 | I dont know how to fix the format of displayed text :(*/ | ||
269 | //item->setText( str ); | ||
262 | item->repaint(); | 270 | item->repaint(); |
263 | g_stringInf.remove( _path ); | 271 | g_stringInf.remove( _path ); |
264 | } | 272 | } |
265 | } | 273 | } |
266 | void PIconView::slotThumbNail(const QString& _path, const QPixmap &pix) { | 274 | void PIconView::slotThumbNail(const QString& _path, const QPixmap &pix) { |
267 | if ( g_stringPix.contains( _path ) ) { | 275 | if ( g_stringPix.contains( _path ) ) { |
268 | IconViewItem* item = g_stringPix[_path]; | 276 | IconViewItem* item = g_stringPix[_path]; |
269 | PPixmapCache::self()->insertImage( _path, pix, 64, 64 ); | 277 | |
278 | if (pix.width()>0) { | ||
279 | PPixmapCache::self()->insertImage( _path, pix, 64, 64 ); | ||
280 | /* required for a recalculated rectangle. otherwise the view show nonsense! */ | ||
281 | item->reCalc(); | ||
282 | } else { | ||
283 | PPixmapCache::self()->insertImage(_path,Resource::loadPixmap( "UnknownDocument" ),64,64 ); | ||
284 | } | ||
270 | item->repaint(); | 285 | item->repaint(); |
271 | g_stringPix.remove( _path ); | 286 | g_stringPix.remove( _path ); |
272 | } | 287 | } |
273 | } | 288 | } |
274 | 289 | ||
275 | 290 | ||
276 | void PIconView::slotRename() { | 291 | void PIconView::slotRename() { |
277 | 292 | ||
278 | } | 293 | } |
279 | 294 | ||
280 | void PIconView::slotBeam() { | 295 | void PIconView::slotBeam() { |
281 | bool isDir; | 296 | bool isDir; |
282 | QString pa = currentFileName( isDir ); | 297 | QString pa = currentFileName( isDir ); |
283 | if ( isDir && pa.isEmpty() ) | 298 | if ( isDir && pa.isEmpty() ) |
284 | return; | 299 | return; |
285 | 300 | ||