-rw-r--r-- | noncore/graphics/opie-eye/gui/iconview.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/graphics/opie-eye/gui/iconview.cpp b/noncore/graphics/opie-eye/gui/iconview.cpp index e61f9d9..5633312 100644 --- a/noncore/graphics/opie-eye/gui/iconview.cpp +++ b/noncore/graphics/opie-eye/gui/iconview.cpp | |||
@@ -1,273 +1,273 @@ | |||
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 | #include <gui/imageinfoui.h> | 9 | #include <gui/imageinfoui.h> |
10 | #include <gui/imagescrollview.h> | ||
11 | 10 | ||
12 | #include <iface/dirview.h> | 11 | #include <iface/dirview.h> |
13 | #include <iface/dirlister.h> | 12 | #include <iface/dirlister.h> |
14 | 13 | ||
15 | #include <opie2/oconfig.h> | 14 | #include <opie2/oconfig.h> |
16 | #include <opie2/okeyconfigwidget.h> | 15 | #include <opie2/okeyconfigwidget.h> |
17 | #include <opie2/odebug.h> | 16 | #include <opie2/odebug.h> |
17 | #include <opie2/oimagescrollview.h> | ||
18 | 18 | ||
19 | #include <qpe/resource.h> | 19 | #include <qpe/resource.h> |
20 | #include <qpe/qpemessagebox.h> | 20 | #include <qpe/qpemessagebox.h> |
21 | #include <qpe/ir.h> | 21 | #include <qpe/ir.h> |
22 | #include <qpe/qcopenvelope_qws.h> | 22 | #include <qpe/qcopenvelope_qws.h> |
23 | #include <qpe/qpeapplication.h> | 23 | #include <qpe/qpeapplication.h> |
24 | 24 | ||
25 | #include <qiconview.h> | 25 | #include <qiconview.h> |
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 | ||
36 | using Opie::Core::OKeyConfigItem; | 36 | using Opie::Core::OKeyConfigItem; |
37 | 37 | ||
38 | /* | 38 | /* |
39 | * The Icons, Request Cache and IconViewItem for the IconView | 39 | * The Icons, Request Cache and IconViewItem for the IconView |
40 | */ | 40 | */ |
41 | namespace { | 41 | namespace { |
42 | static QPixmap* _dirPix = 0; | 42 | static QPixmap* _dirPix = 0; |
43 | static QPixmap* _unkPix = 0; | 43 | static QPixmap* _unkPix = 0; |
44 | static QPixmap* _picPix = 0; | 44 | static QPixmap* _picPix = 0; |
45 | class IconViewItem : public QIconViewItem { | 45 | class IconViewItem : public QIconViewItem { |
46 | public: | 46 | public: |
47 | IconViewItem( QIconView*, const QString& path, const QString& name, bool isDir = false); | 47 | IconViewItem( QIconView*, const QString& path, const QString& name, bool isDir = false); |
48 | QPixmap* pixmap()const; | 48 | QPixmap* pixmap()const; |
49 | QString path()const { return m_path; } | 49 | QString path()const { return m_path; } |
50 | bool isDir()const { return m_isDir; } | 50 | bool isDir()const { return m_isDir; } |
51 | void setText( const QString& ); | 51 | void setText( const QString& ); |
52 | 52 | ||
53 | protected: | 53 | protected: |
54 | mutable QPixmap* m_pix; | 54 | mutable QPixmap* m_pix; |
55 | 55 | ||
56 | private: | 56 | private: |
57 | QString m_path; | 57 | QString m_path; |
58 | bool m_isDir : 1; | 58 | bool m_isDir : 1; |
59 | bool m_noInfo :1; | 59 | bool m_noInfo :1; |
60 | }; | 60 | }; |
61 | class TextViewItem : public IconViewItem { | 61 | class TextViewItem : public IconViewItem { |
62 | TextViewItem( QIconView*, const QString& path, const QString& name, bool isDir = false ); | 62 | TextViewItem( QIconView*, const QString& path, const QString& name, bool isDir = false ); |
63 | QPixmap *pixmap()const; | 63 | QPixmap *pixmap()const; |
64 | void setText( const QString& ); | 64 | void setText( const QString& ); |
65 | }; | 65 | }; |
66 | class ThumbViewItem : public IconViewItem { | 66 | class ThumbViewItem : public IconViewItem { |
67 | ThumbViewItem( QIconView*, const QString& path, const QString& name, bool isDir = false ); | 67 | ThumbViewItem( QIconView*, const QString& path, const QString& name, bool isDir = false ); |
68 | QPixmap *pixmap()const; | 68 | QPixmap *pixmap()const; |
69 | void setText( const QString& ); | 69 | void setText( const QString& ); |
70 | }; | 70 | }; |
71 | 71 | ||
72 | 72 | ||
73 | /* | 73 | /* |
74 | * If we request an Image or String | 74 | * If we request an Image or String |
75 | * we add it to the map | 75 | * we add it to the map |
76 | */ | 76 | */ |
77 | static QMap<QString, IconViewItem*> g_stringInf; | 77 | static QMap<QString, IconViewItem*> g_stringInf; |
78 | static QMap<QString, IconViewItem*> g_stringPix; | 78 | static QMap<QString, IconViewItem*> g_stringPix; |
79 | 79 | ||
80 | IconViewItem::IconViewItem( QIconView* view,const QString& path, | 80 | IconViewItem::IconViewItem( QIconView* view,const QString& path, |
81 | const QString& name, bool isDir ) | 81 | const QString& name, bool isDir ) |
82 | : QIconViewItem( view, name ), m_path( path ), m_isDir( isDir ), | 82 | : QIconViewItem( view, name ), m_path( path ), m_isDir( isDir ), |
83 | m_noInfo( false ) | 83 | m_noInfo( false ) |
84 | { | 84 | { |
85 | if ( isDir && !_dirPix ) | 85 | if ( isDir && !_dirPix ) |
86 | _dirPix = new QPixmap( Resource::loadPixmap("advancedfm/FileBrowser")); | 86 | _dirPix = new QPixmap( Resource::loadPixmap("advancedfm/FileBrowser")); |
87 | else if ( !isDir && !_unkPix ) | 87 | else if ( !isDir && !_unkPix ) |
88 | _unkPix = new QPixmap( Resource::loadPixmap( "UnknownDocument" ) ); | 88 | _unkPix = new QPixmap( Resource::loadPixmap( "UnknownDocument" ) ); |
89 | } | 89 | } |
90 | inline QPixmap* IconViewItem::pixmap()const { | 90 | inline QPixmap* IconViewItem::pixmap()const { |
91 | // qWarning( "Name is " + m_path.right( 15 ) + " rect is %d %d %d %d | %d %d", | 91 | // qWarning( "Name is " + m_path.right( 15 ) + " rect is %d %d %d %d | %d %d", |
92 | // rect().x(),rect().y(),rect().width(),rect().height(), | 92 | // rect().x(),rect().y(),rect().width(),rect().height(), |
93 | // iconView()->contentsX(), iconView()->contentsY()); | 93 | // iconView()->contentsX(), iconView()->contentsY()); |
94 | 94 | ||
95 | if ( m_isDir ) | 95 | if ( m_isDir ) |
96 | return _dirPix; | 96 | return _dirPix; |
97 | else{ | 97 | else{ |
98 | if (!m_noInfo && !g_stringInf.contains( m_path ) ) { | 98 | if (!m_noInfo && !g_stringInf.contains( m_path ) ) { |
99 | currentView()->dirLister()->imageInfo( m_path ); | 99 | currentView()->dirLister()->imageInfo( m_path ); |
100 | g_stringInf.insert( m_path, const_cast<IconViewItem*>(this)); | 100 | g_stringInf.insert( m_path, const_cast<IconViewItem*>(this)); |
101 | } | 101 | } |
102 | 102 | ||
103 | m_pix = PPixmapCache::self()->cachedImage( m_path, 64, 64 ); | 103 | m_pix = PPixmapCache::self()->cachedImage( m_path, 64, 64 ); |
104 | if ( !m_pix && !g_stringPix.contains( m_path )) { | 104 | if ( !m_pix && !g_stringPix.contains( m_path )) { |
105 | currentView()->dirLister()->thumbNail( m_path, 64, 64 ); | 105 | currentView()->dirLister()->thumbNail( m_path, 64, 64 ); |
106 | g_stringPix.insert( m_path, const_cast<IconViewItem*>(this)); | 106 | g_stringPix.insert( m_path, const_cast<IconViewItem*>(this)); |
107 | } | 107 | } |
108 | return m_pix ? m_pix : _unkPix; | 108 | return m_pix ? m_pix : _unkPix; |
109 | } | 109 | } |
110 | } | 110 | } |
111 | inline void IconViewItem::setText( const QString& str ) { | 111 | inline void IconViewItem::setText( const QString& str ) { |
112 | QString text = QIconViewItem::text()+"\n"+str; | 112 | QString text = QIconViewItem::text()+"\n"+str; |
113 | m_noInfo = true; | 113 | m_noInfo = true; |
114 | QIconViewItem::setText( text ); | 114 | QIconViewItem::setText( text ); |
115 | } | 115 | } |
116 | } | 116 | } |
117 | 117 | ||
118 | 118 | ||
119 | /* | 119 | /* |
120 | * Set up the GUI.. initialize the slave set up gui | 120 | * Set up the GUI.. initialize the slave set up gui |
121 | * and also load a dir | 121 | * and also load a dir |
122 | */ | 122 | */ |
123 | PIconView::PIconView( QWidget* wid, Opie::Core::OConfig* cfg ) | 123 | PIconView::PIconView( QWidget* wid, Opie::Core::OConfig* cfg ) |
124 | : QVBox( wid ), m_cfg( cfg ), m_updatet( false ) | 124 | : QVBox( wid ), m_cfg( cfg ), m_updatet( false ) |
125 | { | 125 | { |
126 | { | 126 | { |
127 | QCopEnvelope( "QPE/Application/opie-eye_slave", "refUp()" ); | 127 | QCopEnvelope( "QPE/Application/opie-eye_slave", "refUp()" ); |
128 | } | 128 | } |
129 | m_path = QDir::homeDirPath(); | 129 | m_path = QDir::homeDirPath(); |
130 | m_mode = 0; | 130 | m_mode = 0; |
131 | 131 | ||
132 | QHBox *hbox = new QHBox( this ); | 132 | QHBox *hbox = new QHBox( this ); |
133 | QLabel* lbl = new QLabel( hbox ); | 133 | QLabel* lbl = new QLabel( hbox ); |
134 | lbl->setText( tr("View as" ) ); | 134 | lbl->setText( tr("View as" ) ); |
135 | 135 | ||
136 | m_views = new QComboBox( hbox, "View As" ); | 136 | m_views = new QComboBox( hbox, "View As" ); |
137 | connect( m_views, SIGNAL(activated(int)), | 137 | connect( m_views, SIGNAL(activated(int)), |
138 | this, SLOT(slotViewChanged(int)) ); | 138 | this, SLOT(slotViewChanged(int)) ); |
139 | 139 | ||
140 | m_view= new QIconView( this ); | 140 | m_view= new QIconView( this ); |
141 | connect(m_view, SIGNAL(clicked(QIconViewItem*) ), | 141 | connect(m_view, SIGNAL(clicked(QIconViewItem*) ), |
142 | this, SLOT(slotClicked(QIconViewItem*)) ); | 142 | this, SLOT(slotClicked(QIconViewItem*)) ); |
143 | connect(m_view, SIGNAL(returnPressed(QIconViewItem*)), | 143 | connect(m_view, SIGNAL(returnPressed(QIconViewItem*)), |
144 | this, SLOT(slotClicked(QIconViewItem*)) ); | 144 | this, SLOT(slotClicked(QIconViewItem*)) ); |
145 | 145 | ||
146 | m_view->setArrangement( QIconView::LeftToRight ); | 146 | m_view->setArrangement( QIconView::LeftToRight ); |
147 | m_view->setItemTextPos( QIconView::Right ); | 147 | m_view->setItemTextPos( QIconView::Right ); |
148 | 148 | ||
149 | int dw = QApplication::desktop()->width(); | 149 | int dw = QApplication::desktop()->width(); |
150 | int viewerWidth = dw-style().scrollBarExtent().width(); | 150 | int viewerWidth = dw-style().scrollBarExtent().width(); |
151 | m_view->setGridX( viewerWidth-3*m_view->spacing()); | 151 | m_view->setGridX( viewerWidth-3*m_view->spacing()); |
152 | m_view->setGridY( fontMetrics().height()*2+40 ); | 152 | m_view->setGridY( fontMetrics().height()*2+40 ); |
153 | 153 | ||
154 | 154 | ||
155 | initKeys(); | 155 | initKeys(); |
156 | 156 | ||
157 | loadViews(); | 157 | loadViews(); |
158 | slotViewChanged( m_views->currentItem() ); | 158 | slotViewChanged( m_views->currentItem() ); |
159 | } | 159 | } |
160 | 160 | ||
161 | /* | 161 | /* |
162 | * Unref the slave and save the keyboard manager | 162 | * Unref the slave and save the keyboard manager |
163 | */ | 163 | */ |
164 | PIconView::~PIconView() { | 164 | PIconView::~PIconView() { |
165 | { | 165 | { |
166 | QCopEnvelope( "QPE/Application/opie-eye_slave", "refDown()" ); | 166 | QCopEnvelope( "QPE/Application/opie-eye_slave", "refDown()" ); |
167 | } | 167 | } |
168 | m_viewManager->save(); | 168 | m_viewManager->save(); |
169 | delete m_viewManager; | 169 | delete m_viewManager; |
170 | } | 170 | } |
171 | 171 | ||
172 | Opie::Core::OKeyConfigManager* PIconView::manager() { | 172 | Opie::Core::OKeyConfigManager* PIconView::manager() { |
173 | return m_viewManager; | 173 | return m_viewManager; |
174 | } | 174 | } |
175 | 175 | ||
176 | 176 | ||
177 | /* | 177 | /* |
178 | * init the KeyBoard Shortcuts | 178 | * init the KeyBoard Shortcuts |
179 | * called from the c'tor | 179 | * called from the c'tor |
180 | */ | 180 | */ |
181 | void PIconView::initKeys() { | 181 | void PIconView::initKeys() { |
182 | Opie::Core::OKeyPair::List lst; | 182 | Opie::Core::OKeyPair::List lst; |
183 | lst.append( Opie::Core::OKeyPair::upArrowKey() ); | 183 | lst.append( Opie::Core::OKeyPair::upArrowKey() ); |
184 | lst.append( Opie::Core::OKeyPair::downArrowKey() ); | 184 | lst.append( Opie::Core::OKeyPair::downArrowKey() ); |
185 | lst.append( Opie::Core::OKeyPair::leftArrowKey() ); | 185 | lst.append( Opie::Core::OKeyPair::leftArrowKey() ); |
186 | lst.append( Opie::Core::OKeyPair::rightArrowKey() ); | 186 | lst.append( Opie::Core::OKeyPair::rightArrowKey() ); |
187 | lst.append( Opie::Core::OKeyPair::returnKey() ); | 187 | lst.append( Opie::Core::OKeyPair::returnKey() ); |
188 | 188 | ||
189 | m_viewManager = new Opie::Core::OKeyConfigManager(m_cfg, "View-KeyBoard-Config", | 189 | m_viewManager = new Opie::Core::OKeyConfigManager(m_cfg, "View-KeyBoard-Config", |
190 | lst, false,this, "keyconfig name" ); | 190 | lst, false,this, "keyconfig name" ); |
191 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("Beam Current Item") , "beam", | 191 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("Beam Current Item") , "beam", |
192 | Resource::loadPixmap("beam"), BeamItem, | 192 | Resource::loadPixmap("beam"), BeamItem, |
193 | Opie::Core::OKeyPair(Qt::Key_B, Qt::ShiftButton), | 193 | Opie::Core::OKeyPair(Qt::Key_B, Qt::ShiftButton), |
194 | this, SLOT(slotBeam())) ); | 194 | this, SLOT(slotBeam())) ); |
195 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("Delete Current Item"), "delete", | 195 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("Delete Current Item"), "delete", |
196 | Resource::loadPixmap("trash"), DeleteItem, | 196 | Resource::loadPixmap("trash"), DeleteItem, |
197 | Opie::Core::OKeyPair(Qt::Key_D, Qt::ShiftButton), | 197 | Opie::Core::OKeyPair(Qt::Key_D, Qt::ShiftButton), |
198 | this, SLOT(slotTrash())) ); | 198 | this, SLOT(slotTrash())) ); |
199 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("View Current Item"), "view", | 199 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("View Current Item"), "view", |
200 | Resource::loadPixmap("1to1"), ViewItem, | 200 | Resource::loadPixmap("1to1"), ViewItem, |
201 | Opie::Core::OKeyPair(Qt::Key_V, Qt::ShiftButton), | 201 | Opie::Core::OKeyPair(Qt::Key_V, Qt::ShiftButton), |
202 | this, SLOT(slotShowImage()))); | 202 | this, SLOT(slotShowImage()))); |
203 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("Show Image Info") , "info", | 203 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("Show Image Info") , "info", |
204 | Resource::loadPixmap("DocumentTypeWord"), InfoItem, | 204 | Resource::loadPixmap("DocumentTypeWord"), InfoItem, |
205 | Opie::Core::OKeyPair(Qt::Key_I, Qt::ShiftButton ), | 205 | Opie::Core::OKeyPair(Qt::Key_I, Qt::ShiftButton ), |
206 | this, SLOT(slotImageInfo()) ) ); | 206 | this, SLOT(slotImageInfo()) ) ); |
207 | m_viewManager->load(); | 207 | m_viewManager->load(); |
208 | m_viewManager->handleWidget( m_view ); | 208 | m_viewManager->handleWidget( m_view ); |
209 | } | 209 | } |
210 | 210 | ||
211 | 211 | ||
212 | /* | 212 | /* |
213 | * change one dir up | 213 | * change one dir up |
214 | */ | 214 | */ |
215 | void PIconView::slotDirUp() { | 215 | void PIconView::slotDirUp() { |
216 | QDir dir( m_path ); | 216 | QDir dir( m_path ); |
217 | dir.cdUp(); | 217 | dir.cdUp(); |
218 | slotChangeDir( dir.absPath() ); | 218 | slotChangeDir( dir.absPath() ); |
219 | } | 219 | } |
220 | 220 | ||
221 | /* | 221 | /* |
222 | * change the dir | 222 | * change the dir |
223 | */ | 223 | */ |
224 | void PIconView::slotChangeDir(const QString& path) { | 224 | void PIconView::slotChangeDir(const QString& path) { |
225 | if ( !currentView() ) | 225 | if ( !currentView() ) |
226 | return; | 226 | return; |
227 | 227 | ||
228 | PDirLister *lister = currentView()->dirLister(); | 228 | PDirLister *lister = currentView()->dirLister(); |
229 | if (!lister ) | 229 | if (!lister ) |
230 | return; | 230 | return; |
231 | 231 | ||
232 | /* | 232 | /* |
233 | * Say what we want and take what we get | 233 | * Say what we want and take what we get |
234 | */ | 234 | */ |
235 | lister->setStartPath( path ); | 235 | lister->setStartPath( path ); |
236 | m_path = lister->currentPath(); | 236 | m_path = lister->currentPath(); |
237 | 237 | ||
238 | m_view->viewport()->setUpdatesEnabled( false ); | 238 | m_view->viewport()->setUpdatesEnabled( false ); |
239 | m_view->clear(); | 239 | m_view->clear(); |
240 | 240 | ||
241 | /* | 241 | /* |
242 | * add files and folders | 242 | * add files and folders |
243 | */ | 243 | */ |
244 | addFolders( lister->folders() ); | 244 | addFolders( lister->folders() ); |
245 | addFiles( lister->files() ); | 245 | addFiles( lister->files() ); |
246 | m_view->viewport()->setUpdatesEnabled( true ); | 246 | m_view->viewport()->setUpdatesEnabled( true ); |
247 | 247 | ||
248 | // Also invalidate the cache. We can't cancel the operations anyway | 248 | // Also invalidate the cache. We can't cancel the operations anyway |
249 | g_stringPix.clear(); | 249 | g_stringPix.clear(); |
250 | g_stringInf.clear(); | 250 | g_stringInf.clear(); |
251 | 251 | ||
252 | // looks ugly | 252 | // looks ugly |
253 | static_cast<QMainWindow*>(parent())->setCaption( QObject::tr("%1 - O View", "Name of the dir").arg( m_path ) ); | 253 | static_cast<QMainWindow*>(parent())->setCaption( QObject::tr("%1 - O View", "Name of the dir").arg( m_path ) ); |
254 | } | 254 | } |
255 | 255 | ||
256 | /** | 256 | /** |
257 | * get the current file name | 257 | * get the current file name |
258 | * @param isDir see if this is a dir or real file | 258 | * @param isDir see if this is a dir or real file |
259 | */ | 259 | */ |
260 | QString PIconView::currentFileName(bool &isDir)const { | 260 | QString PIconView::currentFileName(bool &isDir)const { |
261 | isDir = false; | 261 | isDir = false; |
262 | QIconViewItem* _it = m_view->currentItem(); | 262 | QIconViewItem* _it = m_view->currentItem(); |
263 | if ( !_it ) | 263 | if ( !_it ) |
264 | return QString::null; | 264 | return QString::null; |
265 | 265 | ||
266 | IconViewItem* it = static_cast<IconViewItem*>( _it ); | 266 | IconViewItem* it = static_cast<IconViewItem*>( _it ); |
267 | isDir = it->isDir(); | 267 | isDir = it->isDir(); |
268 | return it->path(); | 268 | return it->path(); |
269 | } | 269 | } |
270 | 270 | ||
271 | void PIconView::slotTrash() { | 271 | void PIconView::slotTrash() { |
272 | bool isDir; | 272 | bool isDir; |
273 | QString pa = currentFileName( isDir ); | 273 | QString pa = currentFileName( isDir ); |