summaryrefslogtreecommitdiff
path: root/noncore/graphics/opie-eye/gui/iconview.cpp
Unidiff
Diffstat (limited to 'noncore/graphics/opie-eye/gui/iconview.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/graphics/opie-eye/gui/iconview.cpp61
1 files changed, 41 insertions, 20 deletions
diff --git a/noncore/graphics/opie-eye/gui/iconview.cpp b/noncore/graphics/opie-eye/gui/iconview.cpp
index de2cdf0..4ced52d 100644
--- a/noncore/graphics/opie-eye/gui/iconview.cpp
+++ b/noncore/graphics/opie-eye/gui/iconview.cpp
@@ -26,50 +26,53 @@
26#include <qlabel.h> 26#include <qlabel.h>
27#include <qhbox.h> 27#include <qhbox.h>
28#include <qcombobox.h> 28#include <qcombobox.h>
29#include <qdir.h> 29#include <qdir.h>
30#include <qapplication.h> 30#include <qapplication.h>
31#include <qmainwindow.h> 31#include <qmainwindow.h>
32#include <qtimer.h> 32#include <qtimer.h>
33#include <qstyle.h> 33#include <qstyle.h>
34 34
35 35
36using Opie::Ui::OKeyConfigItem; 36using Opie::Ui::OKeyConfigItem;
37 37
38/*
39 * The Icons, Request Cache and IconViewItem for the IconView
40 */
38namespace { 41namespace {
39 QPixmap* _dirPix = 0; 42 static QPixmap* _dirPix = 0;
40 QPixmap* _unkPix = 0; 43 static QPixmap* _unkPix = 0;
41 class IconViewItem : public QIconViewItem { 44 class IconViewItem : public QIconViewItem {
42 public: 45 public:
43 IconViewItem( QIconView*, const QString& path, const QString& name, bool isDir = false); 46 IconViewItem( QIconView*, const QString& path, const QString& name, bool isDir = false);
44 QPixmap* pixmap()const; 47 QPixmap* pixmap()const;
45 QString path()const { return m_path; } 48 QString path()const { return m_path; }
46 bool isDir()const { return m_isDir; } 49 bool isDir()const { return m_isDir; }
47 void setText( const QString& ); 50 void setText( const QString& );
48 51
49 52
50 private: 53 private:
51 mutable QPixmap* m_pix; 54 mutable QPixmap* m_pix;
52 QString m_path; 55 QString m_path;
53 bool m_isDir : 1; 56 bool m_isDir : 1;
54 bool m_noInfo :1; 57 bool m_noInfo :1;
55 }; 58 };
56 59
57 60
58/* 61/*
59 * If we request an Image or String 62 * If we request an Image or String
60 * we add it to the map 63 * we add it to the map
61 */ 64 */
62 QMap<QString, IconViewItem*> g_stringInf; 65 static QMap<QString, IconViewItem*> g_stringInf;
63 QMap<QString, IconViewItem*> g_stringPix; 66 static QMap<QString, IconViewItem*> g_stringPix;
64 67
65 IconViewItem::IconViewItem( QIconView* view,const QString& path, 68 IconViewItem::IconViewItem( QIconView* view,const QString& path,
66 const QString& name, bool isDir ) 69 const QString& name, bool isDir )
67 : QIconViewItem( view, name ), m_path( path ), m_isDir( isDir ), 70 : QIconViewItem( view, name ), m_path( path ), m_isDir( isDir ),
68 m_noInfo( false ) 71 m_noInfo( false )
69 { 72 {
70 if ( isDir && !_dirPix ) 73 if ( isDir && !_dirPix )
71 _dirPix = new QPixmap( Resource::loadPixmap("advancedfm/FileBrowser")); 74 _dirPix = new QPixmap( Resource::loadPixmap("advancedfm/FileBrowser"));
72 else if ( !isDir && !_unkPix ) 75 else if ( !isDir && !_unkPix )
73 _unkPix = new QPixmap( Resource::loadPixmap( "UnknownDocument" ) ); 76 _unkPix = new QPixmap( Resource::loadPixmap( "UnknownDocument" ) );
74 } 77 }
75 inline QPixmap* IconViewItem::pixmap()const { 78 inline QPixmap* IconViewItem::pixmap()const {
@@ -92,24 +95,28 @@ namespace {
92 } 95 }
93 return m_pix ? m_pix : _unkPix; 96 return m_pix ? m_pix : _unkPix;
94 } 97 }
95 } 98 }
96 inline void IconViewItem::setText( const QString& str ) { 99 inline void IconViewItem::setText( const QString& str ) {
97 QString text = QIconViewItem::text()+"\n"+str; 100 QString text = QIconViewItem::text()+"\n"+str;
98 m_noInfo = true; 101 m_noInfo = true;
99 QIconViewItem::setText( text ); 102 QIconViewItem::setText( text );
100 } 103 }
101} 104}
102 105
103 106
107/*
108 * Set up the GUI.. initialize the slave set up gui
109 * and also load a dir
110 */
104PIconView::PIconView( QWidget* wid, Opie::Core::OConfig* cfg ) 111PIconView::PIconView( QWidget* wid, Opie::Core::OConfig* cfg )
105 : QVBox( wid ), m_cfg( cfg ), m_updatet( false ) 112 : QVBox( wid ), m_cfg( cfg ), m_updatet( false )
106{ 113{
107 { 114 {
108 QCopEnvelope( "QPE/Application/opie-eye_slave", "refUp()" ); 115 QCopEnvelope( "QPE/Application/opie-eye_slave", "refUp()" );
109 } 116 }
110 m_path = QDir::homeDirPath(); 117 m_path = QDir::homeDirPath();
111 118
112 QHBox *hbox = new QHBox( this ); 119 QHBox *hbox = new QHBox( this );
113 QLabel* lbl = new QLabel( hbox ); 120 QLabel* lbl = new QLabel( hbox );
114 lbl->setText( tr("View as" ) ); 121 lbl->setText( tr("View as" ) );
115 122
@@ -127,36 +134,44 @@ PIconView::PIconView( QWidget* wid, Opie::Core::OConfig* cfg )
127 int dw = QApplication::desktop()->width(); 134 int dw = QApplication::desktop()->width();
128 int viewerWidth = dw-style().scrollBarExtent().width(); 135 int viewerWidth = dw-style().scrollBarExtent().width();
129 m_view->setGridX( viewerWidth-3*m_view->spacing()); 136 m_view->setGridX( viewerWidth-3*m_view->spacing());
130 m_view->setGridY( fontMetrics().height()*2+40 ); 137 m_view->setGridY( fontMetrics().height()*2+40 );
131 138
132 139
133 initKeys(); 140 initKeys();
134 141
135 loadViews(); 142 loadViews();
136 slotViewChanged( m_views->currentItem() ); 143 slotViewChanged( m_views->currentItem() );
137} 144}
138 145
146/*
147 * Unref the slave and save the keyboard manager
148 */
139PIconView::~PIconView() { 149PIconView::~PIconView() {
140 { 150 {
141 QCopEnvelope( "QPE/Application/opie-eye_slave", "refDown()" ); 151 QCopEnvelope( "QPE/Application/opie-eye_slave", "refDown()" );
142 } 152 }
143 m_viewManager->save(); 153 m_viewManager->save();
144 delete m_viewManager; 154 delete m_viewManager;
145} 155}
146 156
147Opie::Ui::OKeyConfigManager* PIconView::manager() { 157Opie::Ui::OKeyConfigManager* PIconView::manager() {
148 return m_viewManager; 158 return m_viewManager;
149} 159}
150 160
161
162/*
163 * init the KeyBoard Shortcuts
164 * called from the c'tor
165 */
151void PIconView::initKeys() { 166void PIconView::initKeys() {
152 Opie::Ui::OKeyPair::List lst; 167 Opie::Ui::OKeyPair::List lst;
153 lst.append( Opie::Ui::OKeyPair::upArrowKey() ); 168 lst.append( Opie::Ui::OKeyPair::upArrowKey() );
154 lst.append( Opie::Ui::OKeyPair::downArrowKey() ); 169 lst.append( Opie::Ui::OKeyPair::downArrowKey() );
155 lst.append( Opie::Ui::OKeyPair::leftArrowKey() ); 170 lst.append( Opie::Ui::OKeyPair::leftArrowKey() );
156 lst.append( Opie::Ui::OKeyPair::rightArrowKey() ); 171 lst.append( Opie::Ui::OKeyPair::rightArrowKey() );
157 lst.append( Opie::Ui::OKeyPair::returnKey() ); 172 lst.append( Opie::Ui::OKeyPair::returnKey() );
158 173
159 m_viewManager = new Opie::Ui::OKeyConfigManager(m_cfg, "View-KeyBoard-Config", 174 m_viewManager = new Opie::Ui::OKeyConfigManager(m_cfg, "View-KeyBoard-Config",
160 lst, false,this, "keyconfig name" ); 175 lst, false,this, "keyconfig name" );
161 m_viewManager->addKeyConfig( OKeyConfigItem(tr("Beam Current Item") , "beam", 176 m_viewManager->addKeyConfig( OKeyConfigItem(tr("Beam Current Item") , "beam",
162 Resource::loadPixmap("beam"), BeamItem, 177 Resource::loadPixmap("beam"), BeamItem,
@@ -169,31 +184,38 @@ void PIconView::initKeys() {
169 m_viewManager->addKeyConfig( OKeyConfigItem(tr("View Current Item"), "view", 184 m_viewManager->addKeyConfig( OKeyConfigItem(tr("View Current Item"), "view",
170 Resource::loadPixmap("1to1"), ViewItem, 185 Resource::loadPixmap("1to1"), ViewItem,
171 Opie::Ui::OKeyPair(Qt::Key_V, Qt::ShiftButton), 186 Opie::Ui::OKeyPair(Qt::Key_V, Qt::ShiftButton),
172 this, SLOT(slotShowImage()))); 187 this, SLOT(slotShowImage())));
173 m_viewManager->addKeyConfig( OKeyConfigItem(tr("Show Image Info") , "info", 188 m_viewManager->addKeyConfig( OKeyConfigItem(tr("Show Image Info") , "info",
174 Resource::loadPixmap("DocumentTypeWord"), InfoItem, 189 Resource::loadPixmap("DocumentTypeWord"), InfoItem,
175 Opie::Ui::OKeyPair(Qt::Key_I, Qt::ShiftButton ), 190 Opie::Ui::OKeyPair(Qt::Key_I, Qt::ShiftButton ),
176 this, SLOT(slotImageInfo()) ) ); 191 this, SLOT(slotImageInfo()) ) );
177 m_viewManager->load(); 192 m_viewManager->load();
178 m_viewManager->handleWidget( m_view ); 193 m_viewManager->handleWidget( m_view );
179} 194}
180 195
196
197/*
198 * change one dir up
199 */
181void PIconView::slotDirUp() { 200void PIconView::slotDirUp() {
182 QDir dir( m_path ); 201 QDir dir( m_path );
183 dir.cdUp(); 202 dir.cdUp();
184 slotChangeDir( dir.absPath() ); 203 slotChangeDir( dir.absPath() );
185 204
186} 205}
187 206
207/*
208 * change the dir
209 */
188void PIconView::slotChangeDir(const QString& path) { 210void PIconView::slotChangeDir(const QString& path) {
189 if ( !currentView() ) 211 if ( !currentView() )
190 return; 212 return;
191 213
192 PDirLister *lister = currentView()->dirLister(); 214 PDirLister *lister = currentView()->dirLister();
193 if (!lister ) 215 if (!lister )
194 return; 216 return;
195 217
196 lister->setStartPath( path ); 218 lister->setStartPath( path );
197 m_path = lister->currentPath(); 219 m_path = lister->currentPath();
198 220
199 m_view->viewport()->setUpdatesEnabled( false ); 221 m_view->viewport()->setUpdatesEnabled( false );
@@ -275,46 +297,46 @@ void PIconView::slotViewChanged( int i) {
275 QTimer::singleShot( 0, this, SLOT(slotReloadDir())); 297 QTimer::singleShot( 0, this, SLOT(slotReloadDir()));
276} 298}
277 299
278 300
279void PIconView::slotReloadDir() { 301void PIconView::slotReloadDir() {
280 slotChangeDir( m_path ); 302 slotChangeDir( m_path );
281} 303}
282 304
283 305
284void PIconView::addFolders( const QStringList& lst) { 306void PIconView::addFolders( const QStringList& lst) {
285 QStringList::ConstIterator it; 307 QStringList::ConstIterator it;
286 308
287 for(it=lst.begin(); it != lst.end(); ++it ) { 309 for(it=lst.begin(); it != lst.end(); ++it )
288 (void)new IconViewItem( m_view, m_path+"/"+(*it), (*it), true ); 310 (void)new IconViewItem( m_view, m_path+"/"+(*it), (*it), true );
289 } 311
290 312
291} 313}
292 314
293void PIconView::addFiles( const QStringList& lst) { 315void PIconView::addFiles( const QStringList& lst) {
294 QStringList::ConstIterator it; 316 QStringList::ConstIterator it;
295 for (it=lst.begin(); it!= lst.end(); ++it ) 317 for (it=lst.begin(); it!= lst.end(); ++it )
296 (void)new IconViewItem( m_view, m_path+"/"+(*it), (*it) ); 318 (void)new IconViewItem( m_view, m_path+"/"+(*it), (*it) );
297 319
298} 320}
299 321
300void PIconView::slotClicked(QIconViewItem* _it) { 322void PIconView::slotClicked(QIconViewItem* _it) {
301 if(!_it ) 323 if(!_it )
302 return; 324 return;
303 325
304 IconViewItem* it = static_cast<IconViewItem*>(_it); 326 IconViewItem* it = static_cast<IconViewItem*>(_it);
305 if( it->isDir() ) 327 if( it->isDir() )
306 slotChangeDir( it->path() ); 328 slotChangeDir( it->path() );
307 else // view image 329 else // view image
308 ; 330 slotShowImage();
309} 331}
310 332
311void PIconView::slotThumbInfo( const QString& _path, const QString& str ) { 333void PIconView::slotThumbInfo( const QString& _path, const QString& str ) {
312 IconViewItem* item = g_stringInf[_path]; 334 IconViewItem* item = g_stringInf[_path];
313 if (!item ) 335 if (!item )
314 return; 336 return;
315 337
316 if ( item->intersects(QRect( m_view->contentsX(),m_view->contentsY(), 338 if ( item->intersects(QRect( m_view->contentsX(),m_view->contentsY(),
317 m_view->contentsWidth(), m_view->contentsHeight() ) ) ) 339 m_view->contentsWidth(), m_view->contentsHeight() ) ) )
318 m_updatet = true; 340 m_updatet = true;
319 341
320 item->setText( str ); 342 item->setText( str );
@@ -351,46 +373,45 @@ void PIconView::slotBeam() {
351 connect( ir, SIGNAL(done(Ir*)), 373 connect( ir, SIGNAL(done(Ir*)),
352 this, SLOT(slotBeamDone(Ir*))); 374 this, SLOT(slotBeamDone(Ir*)));
353 ir->send(pa, tr( "Image" ) ); 375 ir->send(pa, tr( "Image" ) );
354 376
355} 377}
356 378
357void PIconView::slotBeamDone( Ir* ir) { 379void PIconView::slotBeamDone( Ir* ir) {
358 delete ir; 380 delete ir;
359} 381}
360 382
361void PIconView::slotStart() { 383void PIconView::slotStart() {
362 m_view->viewport()->setUpdatesEnabled( false ); 384 m_view->viewport()->setUpdatesEnabled( false );
363 qWarning( "Sig Start" );
364} 385}
365 386
366void PIconView::slotEnd() { 387void PIconView::slotEnd() {
367 qWarning( "SLot End" );
368 if ( m_updatet ) 388 if ( m_updatet )
369 m_view->arrangeItemsInGrid( ); 389 m_view->arrangeItemsInGrid( );
370 m_view->viewport()->setUpdatesEnabled( true ); 390 m_view->viewport()->setUpdatesEnabled( true );
371 m_updatet = false; 391 m_updatet = false;
372} 392}
373 393
374void PIconView::slotShowImage() { 394void PIconView::slotShowImage()
375 qDebug("image show"); 395{
396 qWarning( "SLotShowImage" );
376 bool isDir = false; 397 bool isDir = false;
377 QString name = currentFileName(isDir); 398 QString name = currentFileName(isDir);
378 if (isDir) return; 399 if (isDir) return;
379 ImageDlg dlg(name);
380 QPEApplication::execDialog(&dlg);
381}
382void PIconView::slotShowImage( const QString& ) {
383 400
401 slotShowImage( name );
402}
403void PIconView::slotShowImage( const QString& name) {
404 emit sig_display( name );
384} 405}
385void PIconView::slotImageInfo() { 406void PIconView::slotImageInfo() {
386 qDebug("image info"); 407 qWarning( "SlotImageInfo" );
387 bool isDir = false; 408 bool isDir = false;
388 QString name = currentFileName(isDir); 409 QString name = currentFileName(isDir);
389 if (isDir) return; 410 if (isDir) return;
390 infoDlg dlg(name);
391 QPEApplication::execDialog(&dlg);
392}
393 411
394void PIconView::slotImageInfo( const QString& ) { 412 slotImageInfo( name );
413}
395 414
415void PIconView::slotImageInfo( const QString& name) {
416 emit sig_showInfo( name );
396} 417}