summaryrefslogtreecommitdiff
authoralwin <alwin>2004-03-25 17:13:47 (UTC)
committer alwin <alwin>2004-03-25 17:13:47 (UTC)
commit97016caf3a660676a8a1ce300b7e4c7588262209 (patch) (unidiff)
treed59a6a50d71378516e4a457f2a0d7a839519c74f
parent2487430405f4faa9671a81a1db4be825c06bb601 (diff)
downloadopie-97016caf3a660676a8a1ce300b7e4c7588262209.zip
opie-97016caf3a660676a8a1ce300b7e4c7588262209.tar.gz
opie-97016caf3a660676a8a1ce300b7e4c7588262209.tar.bz2
some workarounds so the dirview displays the icons a little bit better
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/graphics/opie-eye/gui/iconview.cpp21
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
@@ -1,303 +1,318 @@
1/* 1/*
2 * GPLv2 zecke@handhelds.org 2 * GPLv2 zecke@handhelds.org
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 9
10#include <iface/dirview.h> 10#include <iface/dirview.h>
11#include <iface/dirlister.h> 11#include <iface/dirlister.h>
12 12
13#include <qpe/config.h> 13#include <qpe/config.h>
14#include <qpe/resource.h> 14#include <qpe/resource.h>
15#include <qpe/qpemessagebox.h> 15#include <qpe/qpemessagebox.h>
16#include <qpe/ir.h> 16#include <qpe/ir.h>
17#include <qpe/qcopenvelope_qws.h> 17#include <qpe/qcopenvelope_qws.h>
18 18
19#include <qiconview.h> 19#include <qiconview.h>
20#include <qlabel.h> 20#include <qlabel.h>
21#include <qhbox.h> 21#include <qhbox.h>
22#include <qcombobox.h> 22#include <qcombobox.h>
23#include <qdir.h> 23#include <qdir.h>
24#include <qapplication.h> 24#include <qapplication.h>
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
31namespace { 31namespace {
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,
57 const QString& name, bool isDir ) 58 const QString& name, bool isDir )
58 : QIconViewItem( view ), m_path( path ), m_isDir( isDir ), 59 : QIconViewItem( view ), m_path( path ), m_isDir( isDir ),
59 m_noInfo( false ) 60 m_noInfo( false )
60 { 61 {
61 QIconViewItem::setText( name ); 62 QIconViewItem::setText( name );
62 if ( isDir && !_dirPix ) 63 if ( isDir && !_dirPix )
63 _dirPix = new QPixmap( Resource::loadPixmap("advancedfm/FileBrowser")); 64 _dirPix = new QPixmap( Resource::loadPixmap("advancedfm/FileBrowser"));
64 else if ( !isDir && !_unkPix ) 65 else if ( !isDir && !_unkPix )
65 _unkPix = new QPixmap( Resource::loadPixmap( "UnknownDocument" ) ); 66 _unkPix = new QPixmap( Resource::loadPixmap( "UnknownDocument" ) );
66 } 67 }
67 inline QPixmap* IconViewItem::pixmap()const { 68 inline QPixmap* IconViewItem::pixmap()const {
68 if ( m_isDir ) 69 if ( m_isDir )
69 return _dirPix; 70 return _dirPix;
70 else{ 71 else{
71 if (!m_noInfo && !g_stringInf.contains( m_path ) ) { 72 if (!m_noInfo && !g_stringInf.contains( m_path ) ) {
72 currentView()->dirLister()->imageInfo( m_path ); 73 currentView()->dirLister()->imageInfo( m_path );
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
92PIconView::PIconView( QWidget* wid, Config* cfg ) 98PIconView::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
124PIconView::~PIconView() { 130PIconView::~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
130void PIconView::slotDirUp() { 136void PIconView::slotDirUp() {
131 QDir dir( m_path ); 137 QDir dir( m_path );
132 dir.cdUp(); 138 dir.cdUp();
133 slotChangeDir( dir.absPath() ); 139 slotChangeDir( dir.absPath() );
134 140
135} 141}
136 142
137void PIconView::slotChangeDir(const QString& path) { 143void PIconView::slotChangeDir(const QString& path) {
138 if ( !currentView() ) 144 if ( !currentView() )
139 return; 145 return;
140 146
141 PDirLister *lister = currentView()->dirLister(); 147 PDirLister *lister = currentView()->dirLister();
142 if (!lister ) 148 if (!lister )
143 return; 149 return;
144 150
145 lister->setStartPath( path ); 151 lister->setStartPath( path );
146 m_path = lister->currentPath(); 152 m_path = lister->currentPath();
147 153
148 m_view->clear(); 154 m_view->clear();
149 addFolders( lister->folders() ); 155 addFolders( lister->folders() );
150 addFiles( lister->files() ); 156 addFiles( lister->files() );
151 157
152 // Also invalidate the cache. We can't cancel the operations anyway 158 // Also invalidate the cache. We can't cancel the operations anyway
153 g_stringPix.clear(); 159 g_stringPix.clear();
154 g_stringInf.clear(); 160 g_stringInf.clear();
155 161
156 // looks ugly 162 // looks ugly
157 static_cast<QMainWindow*>(parent())->setCaption( QObject::tr("%1 - O View", "Name of the dir").arg( m_path ) ); 163 static_cast<QMainWindow*>(parent())->setCaption( QObject::tr("%1 - O View", "Name of the dir").arg( m_path ) );
158} 164}
159 165
160QString PIconView::currentFileName(bool &isDir)const { 166QString PIconView::currentFileName(bool &isDir)const {
161 isDir = false; 167 isDir = false;
162 QIconViewItem* _it = m_view->currentItem(); 168 QIconViewItem* _it = m_view->currentItem();
163 if ( !_it ) 169 if ( !_it )
164 return QString::null; 170 return QString::null;
165 171
166 IconViewItem* it = static_cast<IconViewItem*>( _it ); 172 IconViewItem* it = static_cast<IconViewItem*>( _it );
167 isDir = it->isDir(); 173 isDir = it->isDir();
168 return it->path(); 174 return it->path();
169} 175}
170 176
171void PIconView::slotTrash() { 177void PIconView::slotTrash() {
172 bool isDir; 178 bool isDir;
173 QString pa = currentFileName( isDir ); 179 QString pa = currentFileName( isDir );
174 if ( isDir && pa.isEmpty() ) 180 if ( isDir && pa.isEmpty() )
175 return; 181 return;
176 182
177 if (!QPEMessageBox::confirmDelete( this, 183 if (!QPEMessageBox::confirmDelete( this,
178 tr("Delete Image" ), 184 tr("Delete Image" ),
179 tr("the Image %1" ).arg(pa))) 185 tr("the Image %1" ).arg(pa)))
180 return 186 return
181 187
182 188
183 currentView()->dirLister()->deleteImage( pa ); 189 currentView()->dirLister()->deleteImage( pa );
184 delete m_view->currentItem(); 190 delete m_view->currentItem();
185} 191}
186void PIconView::loadViews() { 192void PIconView::loadViews() {
187 ViewMap::Iterator it; 193 ViewMap::Iterator it;
188 ViewMap* map = viewMap(); 194 ViewMap* map = viewMap();
189 for ( it = map->begin(); it != map->end(); ++it ) 195 for ( it = map->begin(); it != map->end(); ++it )
190 m_views->insertItem( QObject::tr(it.key() ) ); 196 m_views->insertItem( QObject::tr(it.key() ) );
191} 197}
192 198
193void PIconView::resetView() { 199void PIconView::resetView() {
194 slotViewChanged(m_views->currentItem()); 200 slotViewChanged(m_views->currentItem());
195} 201}
196 202
197void PIconView::slotViewChanged( int i) { 203void PIconView::slotViewChanged( int i) {
198 if (!m_views->count() ) { 204 if (!m_views->count() ) {
199 setCurrentView( 0l); 205 setCurrentView( 0l);
200 return; 206 return;
201 } 207 }
202 208
203 PDirView* cur = currentView(); 209 PDirView* cur = currentView();
204 delete cur; 210 delete cur;
205 QString str = m_views->text(i); 211 QString str = m_views->text(i);
206 cur = (*(*viewMap())[str])(*m_cfg); 212 cur = (*(*viewMap())[str])(*m_cfg);
207 setCurrentView( cur ); 213 setCurrentView( cur );
208 214
209 /* connect to the signals of the lister */ 215 /* connect to the signals of the lister */
210 PDirLister* lis = cur->dirLister(); 216 PDirLister* lis = cur->dirLister();
211 connect(lis, SIGNAL(sig_thumbInfo(const QString&, const QString& )), 217 connect(lis, SIGNAL(sig_thumbInfo(const QString&, const QString& )),
212 this, SLOT( slotThumbInfo(const QString&, const QString&))); 218 this, SLOT( slotThumbInfo(const QString&, const QString&)));
213 connect(lis, SIGNAL( sig_thumbNail(const QString&, const QPixmap&)), 219 connect(lis, SIGNAL( sig_thumbNail(const QString&, const QPixmap&)),
214 this, SLOT(slotThumbNail(const QString&, const QPixmap&))); 220 this, SLOT(slotThumbNail(const QString&, const QPixmap&)));
215 connect(lis, SIGNAL(sig_start()), 221 connect(lis, SIGNAL(sig_start()),
216 this, SLOT(slotStart())); 222 this, SLOT(slotStart()));
217 connect(lis, SIGNAL(sig_end()) , 223 connect(lis, SIGNAL(sig_end()) ,
218 this, SLOT(slotEnd()) ); 224 this, SLOT(slotEnd()) );
219 225
220 226
221 /* reload now */ 227 /* reload now */
222 QTimer::singleShot( 0, this, SLOT(slotReloadDir())); 228 QTimer::singleShot( 0, this, SLOT(slotReloadDir()));
223} 229}
224 230
225 231
226void PIconView::slotReloadDir() { 232void PIconView::slotReloadDir() {
227 slotChangeDir( m_path ); 233 slotChangeDir( m_path );
228} 234}
229 235
230 236
231void PIconView::addFolders( const QStringList& lst) { 237void PIconView::addFolders( const QStringList& lst) {
232 QStringList::ConstIterator it; 238 QStringList::ConstIterator it;
233 239
234 for(it=lst.begin(); it != lst.end(); ++it ) { 240 for(it=lst.begin(); it != lst.end(); ++it ) {
235 (void)new IconViewItem( m_view, m_path+"/"+(*it), (*it), true ); 241 (void)new IconViewItem( m_view, m_path+"/"+(*it), (*it), true );
236 } 242 }
237 243
238} 244}
239 245
240void PIconView::addFiles( const QStringList& lst) { 246void PIconView::addFiles( const QStringList& lst) {
241 QStringList::ConstIterator it; 247 QStringList::ConstIterator it;
242 for (it=lst.begin(); it!= lst.end(); ++it ) 248 for (it=lst.begin(); it!= lst.end(); ++it )
243 (void)new IconViewItem( m_view, m_path+"/"+(*it), (*it) ); 249 (void)new IconViewItem( m_view, m_path+"/"+(*it), (*it) );
244 250
245} 251}
246 252
247void PIconView::slotClicked(QIconViewItem* _it) { 253void 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
258void PIconView::slotThumbInfo( const QString& _path, const QString& str ) { 264void 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}
266void PIconView::slotThumbNail(const QString& _path, const QPixmap &pix) { 274void 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
276void PIconView::slotRename() { 291void PIconView::slotRename() {
277 292
278} 293}
279 294
280void PIconView::slotBeam() { 295void 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
286 Ir* ir = new Ir( this ); 301 Ir* ir = new Ir( this );
287 connect( ir, SIGNAL(done(Ir*)), 302 connect( ir, SIGNAL(done(Ir*)),
288 this, SLOT(slotBeamDone(Ir*))); 303 this, SLOT(slotBeamDone(Ir*)));
289 ir->send(pa, tr( "Image" ) ); 304 ir->send(pa, tr( "Image" ) );
290 305
291} 306}
292 307
293void PIconView::slotBeamDone( Ir* ir) { 308void PIconView::slotBeamDone( Ir* ir) {
294 delete ir; 309 delete ir;
295} 310}
296 311
297void PIconView::slotStart() { 312void PIconView::slotStart() {
298 m_view->setUpdatesEnabled( false ); 313 m_view->setUpdatesEnabled( false );
299} 314}
300 315
301void PIconView::slotEnd() { 316void PIconView::slotEnd() {
302 m_view->setUpdatesEnabled( true ); 317 m_view->setUpdatesEnabled( true );
303} 318}