summaryrefslogtreecommitdiff
path: root/noncore/graphics/opie-eye/gui
authorzecke <zecke>2004-03-22 23:32:41 (UTC)
committer zecke <zecke>2004-03-22 23:32:41 (UTC)
commit428b687982966dc2efabaf6dbcc55ad0ea30aa10 (patch) (unidiff)
tree86da20abd2e4b97a59dc32e17996bde5ee74cc91 /noncore/graphics/opie-eye/gui
parent7ce623c6351646ce738a81e103632d73c5454ecc (diff)
downloadopie-428b687982966dc2efabaf6dbcc55ad0ea30aa10.zip
opie-428b687982966dc2efabaf6dbcc55ad0ea30aa10.tar.gz
opie-428b687982966dc2efabaf6dbcc55ad0ea30aa10.tar.bz2
Initial Check in of the Eye Of Zilla. This ImageViewer features
Image Infos, EXIF, Jpeg,Png,Gif support. It supports scaled loading of Jpegs. an smart image cache.... GUI needs some work and we need to find a bug in QCOP as well. TODO: Add Image Service for example Mailer Add ImageCanvas/Zoomer/Display
Diffstat (limited to 'noncore/graphics/opie-eye/gui') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/graphics/opie-eye/gui/filesystem.cpp52
-rw-r--r--noncore/graphics/opie-eye/gui/filesystem.h34
-rw-r--r--noncore/graphics/opie-eye/gui/iconview.cpp296
-rw-r--r--noncore/graphics/opie-eye/gui/iconview.h59
-rw-r--r--noncore/graphics/opie-eye/gui/mainwindow.cpp114
-rw-r--r--noncore/graphics/opie-eye/gui/mainwindow.h29
-rw-r--r--noncore/graphics/opie-eye/gui/viewmap.cpp9
7 files changed, 593 insertions, 0 deletions
diff --git a/noncore/graphics/opie-eye/gui/filesystem.cpp b/noncore/graphics/opie-eye/gui/filesystem.cpp
new file mode 100644
index 0000000..91bcf67
--- a/dev/null
+++ b/noncore/graphics/opie-eye/gui/filesystem.cpp
@@ -0,0 +1,52 @@
1/*
2 * GPLv2 zecke@handhelds.org
3 * No WArranty...
4 */
5
6#include <qpopupmenu.h>
7#include <qtoolbar.h>
8
9#include <qpe/resource.h>
10#include <qpe/storage.h>
11
12
13#include "filesystem.h"
14
15PFileSystem::PFileSystem( QToolBar* bar)
16 : QToolButton( bar )
17{
18 setIconSet( Resource::loadIconSet( "cardmon/pcmcia" ) );
19
20 m_pop = new QPopupMenu( this );
21 connect( m_pop, SIGNAL( activated( int ) ),
22 this, SLOT(slotSelectDir( int ) ) );
23
24 m_storage = new StorageInfo();
25 connect(m_storage, SIGNAL(disksChanged() ),
26 this, SLOT( changed() ) );
27 changed();
28
29 setPopup( m_pop );
30}
31
32PFileSystem::~PFileSystem() {
33 delete m_storage;
34}
35
36
37void PFileSystem::changed() {
38 m_pop->clear();
39 m_dev.clear();
40 const QList<FileSystem> &fs = m_storage->fileSystems();
41 QListIterator<FileSystem> it(fs );
42 for ( ; it.current(); ++it ) {
43 const QString disk = (*it)->name();
44 const QString path = (*it)->path();
45 m_dev.insert( disk, path );
46 m_pop->insertItem( disk );
47 }
48}
49
50void PFileSystem::slotSelectDir( int id ) {
51 emit changeDir( m_dev[m_pop->text(id )] );
52}
diff --git a/noncore/graphics/opie-eye/gui/filesystem.h b/noncore/graphics/opie-eye/gui/filesystem.h
new file mode 100644
index 0000000..a29ad87
--- a/dev/null
+++ b/noncore/graphics/opie-eye/gui/filesystem.h
@@ -0,0 +1,34 @@
1/*
2 * GPLv2 zecke@handhelds.org
3 * No WArranty...
4 */
5
6#ifndef PHUNK_FILE_SYSTEM_H
7#define PHUNK_FILE_SYSTEM_H
8
9#include <qtoolbutton.h>
10#include <qmap.h>
11
12class QPopupMenu;
13class StorageInfo;
14class PFileSystem : public QToolButton {
15 Q_OBJECT
16public:
17 PFileSystem( QToolBar* );
18 ~PFileSystem();
19
20signals:
21 void changeDir( const QString& );
22
23private slots:
24 void slotSelectDir( int );
25 void changed();
26
27private:
28 QPopupMenu* m_pop;
29 StorageInfo *m_storage;
30 QMap<QString, QString> m_dev;
31};
32
33
34#endif
diff --git a/noncore/graphics/opie-eye/gui/iconview.cpp b/noncore/graphics/opie-eye/gui/iconview.cpp
new file mode 100644
index 0000000..0b80012
--- a/dev/null
+++ b/noncore/graphics/opie-eye/gui/iconview.cpp
@@ -0,0 +1,296 @@
1/*
2 * GPLv2 zecke@handhelds.org
3 * No WArranty...
4 */
5
6#include "iconview.h"
7
8#include <lib/imagecache.h>
9
10#include <iface/dirview.h>
11#include <iface/dirlister.h>
12
13#include <qpe/config.h>
14#include <qpe/resource.h>
15#include <qpe/qpemessagebox.h>
16#include <qpe/ir.h>
17#include <qpe/qcopenvelope_qws.h>
18
19#include <qiconview.h>
20#include <qlabel.h>
21#include <qhbox.h>
22#include <qcombobox.h>
23#include <qdir.h>
24#include <qapplication.h>
25#include <qmainwindow.h>
26#include <qtimer.h>
27#include <qstyle.h>
28
29
30
31namespace {
32 QPixmap* _dirPix = 0;
33 QPixmap* _unkPix = 0;
34 class IconViewItem : public QIconViewItem {
35 public:
36 IconViewItem( QIconView*, const QString& path, const QString& name, bool isDir = false);
37 QPixmap* pixmap()const;
38 QString path()const { return m_path; }
39 bool isDir()const { return m_isDir; }
40 void setText( const QString& );
41 private:
42 mutable QPixmap* m_pix;
43 QString m_path;
44 bool m_isDir : 1;
45 bool m_noInfo :1;
46 };
47
48
49/*
50 * If we request an Image or String
51 * we add it to the map
52 */
53 QMap<QString, IconViewItem*> g_stringInf;
54 QMap<QString, IconViewItem*> g_stringPix;
55
56 IconViewItem::IconViewItem( QIconView* view,const QString& path,
57 const QString& name, bool isDir )
58 : QIconViewItem( view ), m_path( path ), m_isDir( isDir ),
59 m_noInfo( false )
60 {
61 QIconViewItem::setText( name );
62 if ( isDir && !_dirPix )
63 _dirPix = new QPixmap( Resource::loadPixmap("advancedfm/FileBrowser"));
64 else if ( !isDir && !_unkPix )
65 _unkPix = new QPixmap( Resource::loadPixmap( "UnknownDocument" ) );
66 }
67 inline QPixmap* IconViewItem::pixmap()const {
68 if ( m_isDir )
69 return _dirPix;
70 else{
71 if (!m_noInfo && !g_stringInf.contains( m_path ) ) {
72 currentView()->dirLister()->imageInfo( m_path );
73 g_stringInf.insert( m_path, const_cast<IconViewItem*>(this));
74 }
75
76 m_pix = PPixmapCache::self()->cachedImage( m_path, 64, 64 );
77 if ( !m_pix && !g_stringPix.contains( m_path )) {
78 currentView()->dirLister()->thumbNail( m_path, 64, 64 );
79 g_stringPix.insert( m_path, const_cast<IconViewItem*>(this));
80 }
81 return m_pix ? m_pix : _unkPix;
82 }
83 }
84 inline void IconViewItem::setText( const QString& str ) {
85 QString text = QIconViewItem::text()+"\n"+str;
86 m_noInfo = true;
87 QIconViewItem::setText( text );
88 }
89}
90
91
92PIconView::PIconView( QWidget* wid, Config* cfg )
93 : QVBox( wid ), m_cfg( cfg )
94{
95 {
96 QCopEnvelope( "QPE/Application/opie-eye_slave", "foo()" );
97 }
98 m_path = QDir::homeDirPath();
99
100 QHBox *hbox = new QHBox( this );
101 QLabel* lbl = new QLabel( hbox );
102 lbl->setText( tr("View as" ) );
103
104 m_views = new QComboBox( hbox, "View As" );
105 connect( m_views, SIGNAL(activated(int)),
106 this, SLOT(slotViewChanged(int)) );
107
108 m_view= new QIconView( this );
109 connect(m_view, SIGNAL(clicked(QIconViewItem*) ),
110 this, SLOT(slotClicked(QIconViewItem*)) );
111
112 m_view->setArrangement( QIconView::LeftToRight );
113 m_view->setItemTextPos( QIconView::Right );
114
115
116 int dw = QApplication::desktop()->width();
117 int viewerWidth = dw-style().scrollBarExtent().width();
118 m_view->setGridX( viewerWidth-2*m_view->spacing() );
119 m_view->setGridY( fontMetrics().height()*2+40 );
120 loadViews();
121 slotViewChanged( m_views->currentItem() );
122}
123
124PIconView::~PIconView() {
125}
126
127void PIconView::slotDirUp() {
128 QDir dir( m_path );
129 dir.cdUp();
130 slotChangeDir( dir.absPath() );
131
132}
133
134void PIconView::slotChangeDir(const QString& path) {
135 if ( !currentView() )
136 return;
137
138 PDirLister *lister = currentView()->dirLister();
139 if (!lister )
140 return;
141
142 lister->setStartPath( path );
143 m_path = lister->currentPath();
144
145 m_view->clear();
146 addFolders( lister->folders() );
147 addFiles( lister->files() );
148
149 // looks ugly
150 static_cast<QMainWindow*>(parent())->setCaption( QObject::tr("%1 - O View", "Name of the dir").arg( m_path ) );
151}
152
153QString PIconView::currentFileName(bool &isDir)const {
154 isDir = false;
155 QIconViewItem* _it = m_view->currentItem();
156 if ( !_it )
157 return QString::null;
158
159 IconViewItem* it = static_cast<IconViewItem*>( _it );
160 isDir = it->isDir();
161 return it->path();
162}
163
164void PIconView::slotTrash() {
165 bool isDir;
166 QString pa = currentFileName( isDir );
167 if ( isDir && pa.isEmpty() )
168 return;
169
170 if (!QPEMessageBox::confirmDelete( this,
171 tr("Delete Image" ),
172 tr("the Image %1" ).arg(pa)))
173 return
174
175
176 currentView()->dirLister()->deleteImage( pa );
177 delete m_view->currentItem();
178}
179void PIconView::loadViews() {
180 ViewMap::Iterator it;
181 ViewMap* map = viewMap();
182 for ( it = map->begin(); it != map->end(); ++it )
183 m_views->insertItem( QObject::tr(it.key() ) );
184}
185
186void PIconView::resetView() {
187 slotViewChanged(m_views->currentItem());
188}
189
190void PIconView::slotViewChanged( int i) {
191 if (!m_views->count() ) {
192 setCurrentView( 0l);
193 return;
194 }
195
196 PDirView* cur = currentView();
197 delete cur;
198 QString str = m_views->text(i);
199 cur = (*(*viewMap())[str])(*m_cfg);
200 setCurrentView( cur );
201
202 /* connect to the signals of the lister */
203 PDirLister* lis = cur->dirLister();
204 connect(lis, SIGNAL(sig_thumbInfo(const QString&, const QString& )),
205 this, SLOT( slotThumbInfo(const QString&, const QString&)));
206 connect(lis, SIGNAL( sig_thumbNail(const QString&, const QPixmap&)),
207 this, SLOT(slotThumbNail(const QString&, const QPixmap&)));
208 connect(lis, SIGNAL(sig_start()),
209 this, SLOT(slotStart()));
210 connect(lis, SIGNAL(sig_end()) ,
211 this, SLOT(slotEnd()) );
212
213
214 /* reload now */
215 QTimer::singleShot( 0, this, SLOT(slotReloadDir()));
216}
217
218
219void PIconView::slotReloadDir() {
220 slotChangeDir( m_path );
221}
222
223
224void PIconView::addFolders( const QStringList& lst) {
225 QStringList::ConstIterator it;
226
227 for(it=lst.begin(); it != lst.end(); ++it ) {
228 (void)new IconViewItem( m_view, m_path+"/"+(*it), (*it), true );
229 }
230
231}
232
233void PIconView::addFiles( const QStringList& lst) {
234 QStringList::ConstIterator it;
235 for (it=lst.begin(); it!= lst.end(); ++it )
236 (void)new IconViewItem( m_view, m_path+"/"+(*it), (*it) );
237
238}
239
240void PIconView::slotClicked(QIconViewItem* _it) {
241 if(!_it )
242 return;
243
244 IconViewItem* it = static_cast<IconViewItem*>(_it);
245 if( it->isDir() )
246 slotChangeDir( it->path() );
247 else // view image
248 ;
249}
250
251void PIconView::slotThumbInfo( const QString& _path, const QString& str ) {
252 if ( g_stringInf.contains( _path ) ) {
253 IconViewItem* item = g_stringInf[_path];
254 item->setText( str );
255 item->repaint();
256 g_stringInf.remove( _path );
257 }
258}
259void PIconView::slotThumbNail(const QString& _path, const QPixmap &pix) {
260 if ( g_stringPix.contains( _path ) ) {
261 IconViewItem* item = g_stringPix[_path];
262 PPixmapCache::self()->insertImage( _path, pix, 64, 64 );
263 item->repaint();
264 g_stringPix.remove( _path );
265 }
266}
267
268
269void PIconView::slotRename() {
270
271}
272
273void PIconView::slotBeam() {
274 bool isDir;
275 QString pa = currentFileName( isDir );
276 if ( isDir && pa.isEmpty() )
277 return;
278
279 Ir* ir = new Ir( this );
280 connect( ir, SIGNAL(done(Ir*)),
281 this, SLOT(slotBeamDone(Ir*)));
282 ir->send(pa, tr( "Image" ) );
283
284}
285
286void PIconView::slotBeamDone( Ir* ir) {
287 delete ir;
288}
289
290void PIconView::slotStart() {
291 m_view->setUpdatesEnabled( false );
292}
293
294void PIconView::slotEnd() {
295 m_view->setUpdatesEnabled( true );
296}
diff --git a/noncore/graphics/opie-eye/gui/iconview.h b/noncore/graphics/opie-eye/gui/iconview.h
new file mode 100644
index 0000000..439833a
--- a/dev/null
+++ b/noncore/graphics/opie-eye/gui/iconview.h
@@ -0,0 +1,59 @@
1/*
2 * GPLv2 zecke@handhelds.org
3 * No WArranty...
4 */
5
6#ifndef PHUNK_ICON_VIEW_H
7#define PHUNK_ICON_VIEW_H
8
9#include <qvbox.h>
10
11#include <qpe/config.h>
12
13class QIconView;
14class QIconViewItem;
15class QComboBox;
16class PIconViewItem;
17class PDirLister;
18class Ir;
19class PIconView : public QVBox {
20 Q_OBJECT
21 friend class PIconViewItem;
22public:
23 PIconView( QWidget* wid, Config *cfg );
24 ~PIconView();
25 void resetView();
26
27private:
28 QString currentFileName(bool &isDir)const;
29 void loadViews();
30
31private slots:
32 void slotDirUp();
33 void slotChangeDir(const QString&);
34 void slotTrash();
35 void slotViewChanged( int );
36 void slotReloadDir();
37 void slotRename();
38 void slotBeam();
39 void slotBeamDone( Ir* );
40
41 void slotStart();
42 void slotEnd();
43
44/* for performance reasons make it inline in the future */
45 void addFolders( const QStringList& );
46 void addFiles( const QStringList& );
47 void slotClicked(QIconViewItem* );
48
49/**/
50 void slotThumbInfo(const QString&, const QString&);
51 void slotThumbNail(const QString&, const QPixmap&);
52private:
53 Config *m_cfg;
54 QComboBox* m_views;
55 QIconView* m_view;
56 QString m_path;
57};
58
59#endif
diff --git a/noncore/graphics/opie-eye/gui/mainwindow.cpp b/noncore/graphics/opie-eye/gui/mainwindow.cpp
new file mode 100644
index 0000000..0a2fcab
--- a/dev/null
+++ b/noncore/graphics/opie-eye/gui/mainwindow.cpp
@@ -0,0 +1,114 @@
1/*
2 * GPLv2 zecke@handhelds.org
3 * No WArranty...
4 */
5
6#include <qtoolbar.h>
7#include <qtoolbutton.h>
8#include <qlayout.h>
9#include <qdialog.h>
10#include <qmap.h>
11
12#include <qpe/resource.h>
13#include <qpe/config.h>
14#include <qpe/ir.h>
15
16#include <opie/oapplicationfactory.h>
17#include <opie/otabwidget.h>
18
19#include <iface/ifaceinfo.h>
20#include <iface/dirview.h>
21
22#include "iconview.h"
23#include "filesystem.h"
24
25#include "mainwindow.h"
26
27OPIE_EXPORT_APP( OApplicationFactory<PMainWindow> )
28
29PMainWindow::PMainWindow(QWidget* wid, const char* name, WFlags style)
30 : QMainWindow( wid, name, style ), m_cfg("phunkview")
31{
32 setCaption( QObject::tr("Opie Eye Caramba" ) );
33 m_cfg.setGroup("Zecke_view" );
34 /*
35 * Initialize ToolBar and IconView
36 * And Connect Them
37 */
38 QToolBar *bar = new QToolBar( this );
39 bar->setHorizontalStretchable( true );
40 setToolBarsMovable( false );
41
42 m_view = new PIconView( this, &m_cfg );
43 setCentralWidget( m_view );
44
45 QToolButton *btn = new QToolButton( bar );
46 btn->setIconSet( Resource::loadIconSet( "up" ) );
47 connect( btn, SIGNAL(clicked()),
48 m_view, SLOT(slotDirUp()) );
49
50 btn = new PFileSystem( bar );
51 connect( btn, SIGNAL( changeDir( const QString& ) ),
52 m_view, SLOT(slotChangeDir( const QString& ) ) );
53
54 btn = new QToolButton( bar );
55 btn->setIconSet( Resource::loadIconSet( "edit" ) );
56 connect( btn, SIGNAL(clicked()),
57 m_view, SLOT(slotRename()) );
58
59 if ( Ir::supported() ) {
60 btn = new QToolButton( bar );
61 btn->setIconSet( Resource::loadIconSet( "beam" ) );
62 connect( btn, SIGNAL(clicked()),
63 m_view, SLOT(slotBeam()) );
64 }
65
66 btn = new QToolButton( bar );
67 btn->setIconSet( Resource::loadIconSet( "trash" ) );
68 connect( btn, SIGNAL(clicked() ),
69 m_view, SLOT(slotTrash() ) );
70
71 btn = new QToolButton( bar );
72 btn->setIconSet( Resource::loadIconSet( "SettingsIcon" ) );
73 connect( btn, SIGNAL(clicked() ),
74 this, SLOT(slotConfig() ) );
75
76}
77
78PMainWindow::~PMainWindow() {
79}
80
81
82void PMainWindow::slotConfig() {
83 QDialog dlg(this, 0, true);
84 dlg.setCaption( tr("Phunk View - Config" ) );
85
86 QHBoxLayout *lay = new QHBoxLayout(&dlg);
87 OTabWidget *wid = new OTabWidget(&dlg );
88 lay->addWidget( wid );
89 ViewMap *vM = viewMap();
90 ViewMap::Iterator _it = vM->begin();
91 QMap<PDirView*, QWidget*> lst;
92
93 for( ; _it != vM->end(); ++_it ) {
94 PDirView *view = (_it.data())(m_cfg);
95 PInterfaceInfo *inf = view->interfaceInfo();
96 QWidget *_wid = inf->configWidget( m_cfg );
97 _wid->reparent(wid, QPoint() );
98 lst.insert( view, _wid );
99 wid->addTab( _wid, QString::null, inf->name() );
100 }
101
102 dlg.showMaximized();
103 bool act = ( dlg.exec() == QDialog::Accepted );
104
105 QMap<PDirView*, QWidget*>::Iterator it;
106 for ( it = lst.begin(); it != lst.end(); ++it ) {
107 if ( act )
108 it.key()->interfaceInfo()->writeConfig(it.data(), m_cfg);
109 delete it.key();
110 }
111
112 if ( act )
113 m_view->resetView();
114}
diff --git a/noncore/graphics/opie-eye/gui/mainwindow.h b/noncore/graphics/opie-eye/gui/mainwindow.h
new file mode 100644
index 0000000..408fe32
--- a/dev/null
+++ b/noncore/graphics/opie-eye/gui/mainwindow.h
@@ -0,0 +1,29 @@
1/*
2 * GPLv2 zecke@handhelds.org
3 * No WArranty...
4 */
5
6#ifndef PHUNK_MAIN_WINDOW_H
7#define PHUNK_MAIN_WINDOW_H
8
9#include <qmainwindow.h>
10
11#include <qpe/config.h>
12
13class PIconView;
14class PMainWindow : public QMainWindow {
15 Q_OBJECT
16public:
17 static QString appName() { return QString::fromLatin1("opie-eye" ); }
18 PMainWindow(QWidget*, const char*, WFlags );
19 ~PMainWindow();
20
21private:
22 Config m_cfg;
23 PIconView* m_view;
24
25private slots:
26 void slotConfig();
27};
28
29#endif
diff --git a/noncore/graphics/opie-eye/gui/viewmap.cpp b/noncore/graphics/opie-eye/gui/viewmap.cpp
new file mode 100644
index 0000000..2dffb38
--- a/dev/null
+++ b/noncore/graphics/opie-eye/gui/viewmap.cpp
@@ -0,0 +1,9 @@
1#include <iface/dirview.h>
2
3namespace {
4 ViewMap m_view;
5}
6
7ViewMap* viewMap() {
8 return m_view;
9}