-rw-r--r-- | noncore/graphics/opie-eye/gui/iconview.cpp | 26 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/lib/imagecache.cpp | 6 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/lib/imagecache.h | 5 |
3 files changed, 27 insertions, 10 deletions
diff --git a/noncore/graphics/opie-eye/gui/iconview.cpp b/noncore/graphics/opie-eye/gui/iconview.cpp index 039f53f..d546b64 100644 --- a/noncore/graphics/opie-eye/gui/iconview.cpp +++ b/noncore/graphics/opie-eye/gui/iconview.cpp | |||
@@ -1,608 +1,614 @@ | |||
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 | 10 | ||
11 | #include <iface/dirview.h> | 11 | #include <iface/dirview.h> |
12 | #include <iface/dirlister.h> | 12 | #include <iface/dirlister.h> |
13 | 13 | ||
14 | #include <opie2/oconfig.h> | 14 | #include <opie2/oconfig.h> |
15 | #include <opie2/okeyconfigwidget.h> | 15 | #include <opie2/okeyconfigwidget.h> |
16 | #include <opie2/odebug.h> | 16 | #include <opie2/odebug.h> |
17 | #include <opie2/oimagescrollview.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 | static QPixmap* _emptyPix = 0; | 45 | static QPixmap* _emptyPix = 0; |
46 | class IconViewItem : public QIconViewItem { | 46 | class IconViewItem : public QIconViewItem { |
47 | public: | 47 | public: |
48 | IconViewItem( QIconView*, const QString& path, const QString& name, bool isDir = false); | 48 | IconViewItem( QIconView*, const QString& path, const QString& name, bool isDir = false); |
49 | QPixmap* pixmap()const; | 49 | QPixmap* pixmap()const; |
50 | QString path()const { return m_path; } | 50 | QString path()const { return m_path; } |
51 | bool isDir()const { return m_isDir; } | 51 | bool isDir()const { return m_isDir; } |
52 | void setText( const QString& ); | 52 | void setText( const QString& ); |
53 | bool textOnly()const{return m_textOnly;} | 53 | bool textOnly()const{return m_textOnly;} |
54 | void setTextOnly(bool how){m_textOnly=how;} | 54 | void setTextOnly(bool how){m_textOnly=how;} |
55 | /* just for starting recalc of item rect! */ | ||
55 | virtual void setPixmap( const QPixmap & icon, bool recalc, bool redraw = TRUE ); | 56 | virtual void setPixmap( const QPixmap & icon, bool recalc, bool redraw = TRUE ); |
57 | /* just for starting recalc of item rect! */ | ||
56 | virtual void setPixmap( const QPixmap & icon); | 58 | virtual void setPixmap( const QPixmap & icon); |
57 | 59 | ||
58 | protected: | 60 | protected: |
59 | mutable QPixmap* m_pix; | 61 | mutable QPixmap* m_pix; |
60 | 62 | ||
61 | private: | 63 | private: |
62 | QString m_path; | 64 | QString m_path; |
63 | bool m_isDir : 1; | 65 | bool m_isDir : 1; |
64 | bool m_noInfo :1; | 66 | bool m_noInfo :1; |
65 | bool m_textOnly:1; | 67 | bool m_textOnly:1; |
66 | bool m_NameOnly:1; | 68 | bool m_NameOnly:1; |
67 | bool m_Pixset:1; | 69 | bool m_Pixset:1; |
68 | }; | 70 | }; |
69 | class TextViewItem : public IconViewItem { | 71 | class TextViewItem : public IconViewItem { |
70 | TextViewItem( QIconView*, const QString& path, const QString& name, bool isDir = false ); | 72 | TextViewItem( QIconView*, const QString& path, const QString& name, bool isDir = false ); |
71 | QPixmap *pixmap()const; | 73 | QPixmap *pixmap()const; |
72 | void setText( const QString& ); | 74 | void setText( const QString& ); |
73 | }; | 75 | }; |
74 | class ThumbViewItem : public IconViewItem { | 76 | class ThumbViewItem : public IconViewItem { |
75 | ThumbViewItem( QIconView*, const QString& path, const QString& name, bool isDir = false ); | 77 | ThumbViewItem( QIconView*, const QString& path, const QString& name, bool isDir = false ); |
76 | QPixmap *pixmap()const; | 78 | QPixmap *pixmap()const; |
77 | void setText( const QString& ); | 79 | void setText( const QString& ); |
78 | }; | 80 | }; |
79 | 81 | ||
80 | 82 | ||
81 | /* | 83 | /* |
82 | * If we request an Image or String | 84 | * If we request an Image or String |
83 | * we add it to the map | 85 | * we add it to the map |
84 | */ | 86 | */ |
85 | static QMap<QString, IconViewItem*> g_stringInf; | 87 | static QMap<QString, IconViewItem*> g_stringInf; |
86 | static QMap<QString, IconViewItem*> g_stringPix; | 88 | static QMap<QString, IconViewItem*> g_stringPix; |
87 | 89 | ||
88 | IconViewItem::IconViewItem( QIconView* view,const QString& path, | 90 | IconViewItem::IconViewItem( QIconView* view,const QString& path, |
89 | const QString& name, bool isDir ) | 91 | const QString& name, bool isDir ) |
90 | : QIconViewItem( view, name ), m_path( path ), m_isDir( isDir ), | 92 | : QIconViewItem( view, name ), m_path( path ), m_isDir( isDir ), |
91 | m_noInfo( false ),m_textOnly(false),m_Pixset(false) | 93 | m_noInfo( false ),m_textOnly(false),m_Pixset(false) |
92 | { | 94 | { |
93 | if ( isDir && !_dirPix ) | 95 | if ( isDir && !_dirPix ) |
94 | _dirPix = new QPixmap( Resource::loadPixmap("advancedfm/FileBrowser")); | 96 | _dirPix = new QPixmap( Resource::loadPixmap("advancedfm/FileBrowser")); |
95 | else if ( !isDir && !_unkPix ) | 97 | else if ( !isDir && !_unkPix ) |
96 | _unkPix = new QPixmap( Resource::loadPixmap( "UnknownDocument" ) ); | 98 | _unkPix = new QPixmap( Resource::loadPixmap( "UnknownDocument" ) ); |
97 | } | 99 | } |
98 | 100 | ||
99 | inline void IconViewItem::setPixmap( const QPixmap & icon, bool recalc, bool redraw) | 101 | inline void IconViewItem::setPixmap( const QPixmap & icon, bool recalc, bool redraw) |
100 | { | 102 | { |
101 | m_Pixset = true; | 103 | m_Pixset = true; |
102 | QIconViewItem::setPixmap(icon,recalc,redraw); | 104 | calcRect(text()); |
103 | } | 105 | } |
104 | inline void IconViewItem::setPixmap( const QPixmap & icon) | 106 | inline void IconViewItem::setPixmap( const QPixmap & icon) |
105 | { | 107 | { |
106 | m_Pixset = true; | 108 | m_Pixset = true; |
107 | QIconViewItem::setPixmap(icon); | 109 | calcRect(text()); |
108 | } | 110 | } |
109 | 111 | ||
110 | inline QPixmap* IconViewItem::pixmap()const { | 112 | inline QPixmap* IconViewItem::pixmap()const { |
111 | // qWarning( "Name is " + m_path.right( 15 ) + " rect is %d %d %d %d | %d %d", | 113 | // qWarning( "Name is " + m_path.right( 15 ) + " rect is %d %d %d %d | %d %d", |
112 | // rect().x(),rect().y(),rect().width(),rect().height(), | 114 | // rect().x(),rect().y(),rect().width(),rect().height(), |
113 | // iconView()->contentsX(), iconView()->contentsY()); | 115 | // iconView()->contentsX(), iconView()->contentsY()); |
114 | 116 | ||
115 | if (textOnly()&&!m_isDir) { | 117 | if (textOnly()&&!m_isDir) { |
116 | if (!_emptyPix) _emptyPix = new QPixmap(0,0,1); | 118 | if (!_emptyPix) _emptyPix = new QPixmap(0,0,1); |
117 | return _emptyPix; | 119 | return _emptyPix; |
118 | } | 120 | } |
119 | if ( m_isDir ) | 121 | if ( m_isDir ) |
120 | return _dirPix; | 122 | return _dirPix; |
121 | else{ | 123 | else{ |
122 | if (!m_noInfo && !g_stringInf.contains( m_path ) ) { | 124 | if (!m_noInfo && !g_stringInf.contains( m_path ) ) { |
123 | currentView()->dirLister()->imageInfo( m_path ); | 125 | currentView()->dirLister()->imageInfo( m_path ); |
124 | g_stringInf.insert( m_path, const_cast<IconViewItem*>(this)); | 126 | g_stringInf.insert( m_path, const_cast<IconViewItem*>(this)); |
125 | } | 127 | } |
126 | 128 | ||
127 | m_pix = PPixmapCache::self()->cachedImage( m_path, 64, 64 ); | 129 | m_pix = PPixmapCache::self()->cachedImage( m_path, 64, 64 ); |
128 | if (!m_pix && !g_stringPix.contains( m_path )&&!m_Pixset) { | 130 | if (!m_pix && !g_stringPix.contains( m_path )) { |
129 | currentView()->dirLister()->thumbNail( m_path, 64, 64 ); | 131 | currentView()->dirLister()->thumbNail( m_path, 64, 64 ); |
130 | g_stringPix.insert( m_path, const_cast<IconViewItem*>(this)); | 132 | g_stringPix.insert( m_path, const_cast<IconViewItem*>(this)); |
131 | } | 133 | } |
132 | if (m_Pixset) { | ||
133 | return QIconViewItem::pixmap(); | ||
134 | } | ||
135 | return m_pix ? m_pix : _unkPix; | 134 | return m_pix ? m_pix : _unkPix; |
136 | } | 135 | } |
137 | } | 136 | } |
138 | inline void IconViewItem::setText( const QString& str ) { | 137 | inline void IconViewItem::setText( const QString& str ) { |
139 | QString text = QIconViewItem::text()+"\n"+str; | 138 | QString text = QIconViewItem::text()+"\n"+str; |
140 | m_noInfo = true; | 139 | m_noInfo = true; |
141 | QIconViewItem::setText( text ); | 140 | QIconViewItem::setText( text ); |
142 | } | 141 | } |
143 | } | 142 | } |
144 | 143 | ||
145 | 144 | ||
146 | /* | 145 | /* |
147 | * Set up the GUI.. initialize the slave set up gui | 146 | * Set up the GUI.. initialize the slave set up gui |
148 | * and also load a dir | 147 | * and also load a dir |
149 | */ | 148 | */ |
150 | PIconView::PIconView( QWidget* wid, Opie::Core::OConfig* cfg ) | 149 | PIconView::PIconView( QWidget* wid, Opie::Core::OConfig* cfg ) |
151 | : QVBox( wid ), m_cfg( cfg ), m_updatet( false ) | 150 | : QVBox( wid ), m_cfg( cfg ), m_updatet( false ) |
152 | { | 151 | { |
153 | { | 152 | { |
154 | QCopEnvelope( "QPE/Application/opie-eye_slave", "refUp()" ); | 153 | QCopEnvelope( "QPE/Application/opie-eye_slave", "refUp()" ); |
155 | } | 154 | } |
156 | m_path = QDir::homeDirPath(); | 155 | m_path = QDir::homeDirPath(); |
157 | m_mode = 0; | 156 | m_mode = 0; |
158 | 157 | ||
159 | QHBox *hbox = new QHBox( this ); | 158 | QHBox *hbox = new QHBox( this ); |
160 | QLabel* lbl = new QLabel( hbox ); | 159 | QLabel* lbl = new QLabel( hbox ); |
161 | lbl->setText( tr("View as" ) ); | 160 | lbl->setText( tr("View as" ) ); |
162 | 161 | ||
163 | m_views = new QComboBox( hbox, "View As" ); | 162 | m_views = new QComboBox( hbox, "View As" ); |
164 | connect( m_views, SIGNAL(activated(int)), | 163 | connect( m_views, SIGNAL(activated(int)), |
165 | this, SLOT(slotViewChanged(int)) ); | 164 | this, SLOT(slotViewChanged(int)) ); |
166 | 165 | ||
167 | m_view= new QIconView( this ); | 166 | m_view= new QIconView( this ); |
168 | connect(m_view, SIGNAL(clicked(QIconViewItem*) ), | 167 | connect(m_view, SIGNAL(clicked(QIconViewItem*) ), |
169 | this, SLOT(slotClicked(QIconViewItem*)) ); | 168 | this, SLOT(slotClicked(QIconViewItem*)) ); |
170 | connect(m_view, SIGNAL(returnPressed(QIconViewItem*)), | 169 | connect(m_view, SIGNAL(returnPressed(QIconViewItem*)), |
171 | this, SLOT(slotClicked(QIconViewItem*)) ); | 170 | this, SLOT(slotClicked(QIconViewItem*)) ); |
172 | 171 | ||
173 | m_view->setArrangement( QIconView::LeftToRight ); | 172 | m_view->setArrangement( QIconView::LeftToRight ); |
174 | m_view->setItemTextPos( QIconView::Right ); | 173 | m_view->setItemTextPos( QIconView::Right ); |
175 | 174 | ||
176 | int dw = QApplication::desktop()->width(); | 175 | int dw = QApplication::desktop()->width(); |
177 | int viewerWidth = dw-style().scrollBarExtent().width(); | 176 | int viewerWidth = dw-style().scrollBarExtent().width(); |
178 | m_view->setGridX( viewerWidth-3*m_view->spacing()); | 177 | m_view->setGridX( viewerWidth-3*m_view->spacing()); |
179 | m_view->setGridY( fontMetrics().height()*2+40 ); | 178 | m_view->setGridY( fontMetrics().height()*2+40 ); |
180 | 179 | ||
181 | 180 | ||
182 | initKeys(); | 181 | initKeys(); |
183 | 182 | ||
184 | loadViews(); | 183 | loadViews(); |
185 | slotViewChanged( m_views->currentItem() ); | 184 | slotViewChanged( m_views->currentItem() ); |
186 | } | 185 | } |
187 | 186 | ||
188 | /* | 187 | /* |
189 | * Unref the slave and save the keyboard manager | 188 | * Unref the slave and save the keyboard manager |
190 | */ | 189 | */ |
191 | PIconView::~PIconView() { | 190 | PIconView::~PIconView() { |
192 | { | 191 | { |
193 | QCopEnvelope( "QPE/Application/opie-eye_slave", "refDown()" ); | 192 | QCopEnvelope( "QPE/Application/opie-eye_slave", "refDown()" ); |
194 | } | 193 | } |
195 | m_viewManager->save(); | 194 | m_viewManager->save(); |
196 | delete m_viewManager; | 195 | delete m_viewManager; |
197 | } | 196 | } |
198 | 197 | ||
199 | Opie::Core::OKeyConfigManager* PIconView::manager() { | 198 | Opie::Core::OKeyConfigManager* PIconView::manager() { |
200 | return m_viewManager; | 199 | return m_viewManager; |
201 | } | 200 | } |
202 | 201 | ||
203 | 202 | ||
204 | /* | 203 | /* |
205 | * init the KeyBoard Shortcuts | 204 | * init the KeyBoard Shortcuts |
206 | * called from the c'tor | 205 | * called from the c'tor |
207 | */ | 206 | */ |
208 | void PIconView::initKeys() { | 207 | void PIconView::initKeys() { |
209 | Opie::Core::OKeyPair::List lst; | 208 | Opie::Core::OKeyPair::List lst; |
210 | lst.append( Opie::Core::OKeyPair::upArrowKey() ); | 209 | lst.append( Opie::Core::OKeyPair::upArrowKey() ); |
211 | lst.append( Opie::Core::OKeyPair::downArrowKey() ); | 210 | lst.append( Opie::Core::OKeyPair::downArrowKey() ); |
212 | lst.append( Opie::Core::OKeyPair::leftArrowKey() ); | 211 | lst.append( Opie::Core::OKeyPair::leftArrowKey() ); |
213 | lst.append( Opie::Core::OKeyPair::rightArrowKey() ); | 212 | lst.append( Opie::Core::OKeyPair::rightArrowKey() ); |
214 | lst.append( Opie::Core::OKeyPair::returnKey() ); | 213 | lst.append( Opie::Core::OKeyPair::returnKey() ); |
215 | 214 | ||
216 | m_viewManager = new Opie::Core::OKeyConfigManager(m_cfg, "View-KeyBoard-Config", | 215 | m_viewManager = new Opie::Core::OKeyConfigManager(m_cfg, "View-KeyBoard-Config", |
217 | lst, false,this, "keyconfig name" ); | 216 | lst, false,this, "keyconfig name" ); |
218 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("Beam Current Item") , "beam", | 217 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("Beam Current Item") , "beam", |
219 | Resource::loadPixmap("beam"), BeamItem, | 218 | Resource::loadPixmap("beam"), BeamItem, |
220 | Opie::Core::OKeyPair(Qt::Key_B, Qt::ShiftButton), | 219 | Opie::Core::OKeyPair(Qt::Key_B, Qt::ShiftButton), |
221 | this, SLOT(slotBeam())) ); | 220 | this, SLOT(slotBeam())) ); |
222 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("Delete Current Item"), "delete", | 221 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("Delete Current Item"), "delete", |
223 | Resource::loadPixmap("trash"), DeleteItem, | 222 | Resource::loadPixmap("trash"), DeleteItem, |
224 | Opie::Core::OKeyPair(Qt::Key_D, Qt::ShiftButton), | 223 | Opie::Core::OKeyPair(Qt::Key_D, Qt::ShiftButton), |
225 | this, SLOT(slotTrash())) ); | 224 | this, SLOT(slotTrash())) ); |
226 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("View Current Item"), "view", | 225 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("View Current Item"), "view", |
227 | Resource::loadPixmap("1to1"), ViewItem, | 226 | Resource::loadPixmap("1to1"), ViewItem, |
228 | Opie::Core::OKeyPair(Qt::Key_V, Qt::ShiftButton), | 227 | Opie::Core::OKeyPair(Qt::Key_V, Qt::ShiftButton), |
229 | this, SLOT(slotShowImage()))); | 228 | this, SLOT(slotShowImage()))); |
230 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("Show Image Info") , "info", | 229 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("Show Image Info") , "info", |
231 | Resource::loadPixmap("DocumentTypeWord"), InfoItem, | 230 | Resource::loadPixmap("DocumentTypeWord"), InfoItem, |
232 | Opie::Core::OKeyPair(Qt::Key_I, Qt::ShiftButton ), | 231 | Opie::Core::OKeyPair(Qt::Key_I, Qt::ShiftButton ), |
233 | this, SLOT(slotImageInfo()) ) ); | 232 | this, SLOT(slotImageInfo()) ) ); |
234 | m_viewManager->load(); | 233 | m_viewManager->load(); |
235 | m_viewManager->handleWidget( m_view ); | 234 | m_viewManager->handleWidget( m_view ); |
236 | } | 235 | } |
237 | 236 | ||
238 | 237 | ||
239 | /* | 238 | /* |
240 | * change one dir up | 239 | * change one dir up |
241 | */ | 240 | */ |
242 | void PIconView::slotDirUp() { | 241 | void PIconView::slotDirUp() { |
243 | QDir dir( m_path ); | 242 | QDir dir( m_path ); |
244 | dir.cdUp(); | 243 | dir.cdUp(); |
245 | slotChangeDir( dir.absPath() ); | 244 | slotChangeDir( dir.absPath() ); |
246 | } | 245 | } |
247 | 246 | ||
248 | /* | 247 | /* |
249 | * change the dir | 248 | * change the dir |
250 | */ | 249 | */ |
251 | void PIconView::slotChangeDir(const QString& path) { | 250 | void PIconView::slotChangeDir(const QString& path) { |
252 | if ( !currentView() ) | 251 | if ( !currentView() ) |
253 | return; | 252 | return; |
254 | 253 | ||
255 | PDirLister *lister = currentView()->dirLister(); | 254 | PDirLister *lister = currentView()->dirLister(); |
256 | if (!lister ) | 255 | if (!lister ) |
257 | return; | 256 | return; |
258 | 257 | ||
259 | /* | 258 | /* |
260 | * Say what we want and take what we get | 259 | * Say what we want and take what we get |
261 | */ | 260 | */ |
262 | lister->setStartPath( path ); | 261 | lister->setStartPath( path ); |
263 | m_path = lister->currentPath(); | 262 | m_path = lister->currentPath(); |
264 | 263 | ||
265 | m_view->viewport()->setUpdatesEnabled( false ); | 264 | m_view->viewport()->setUpdatesEnabled( false ); |
266 | m_view->clear(); | 265 | m_view->clear(); |
267 | 266 | ||
268 | /* | 267 | /* |
269 | * add files and folders | 268 | * add files and folders |
270 | */ | 269 | */ |
271 | addFolders( lister->folders() ); | 270 | addFolders( lister->folders() ); |
272 | addFiles( lister->files() ); | 271 | addFiles( lister->files() ); |
273 | m_view->viewport()->setUpdatesEnabled( true ); | 272 | m_view->viewport()->setUpdatesEnabled( true ); |
274 | 273 | ||
275 | // Also invalidate the cache. We can't cancel the operations anyway | 274 | // Also invalidate the cache. We can't cancel the operations anyway |
276 | g_stringPix.clear(); | 275 | g_stringPix.clear(); |
277 | g_stringInf.clear(); | 276 | g_stringInf.clear(); |
278 | 277 | ||
279 | // looks ugly | 278 | // looks ugly |
280 | static_cast<QMainWindow*>(parent())->setCaption( QObject::tr("%1 - O View", "Name of the dir").arg( m_path ) ); | 279 | static_cast<QMainWindow*>(parent())->setCaption( QObject::tr("%1 - O View", "Name of the dir").arg( m_path ) ); |
281 | } | 280 | } |
282 | 281 | ||
283 | /** | 282 | /** |
284 | * get the current file name | 283 | * get the current file name |
285 | * @param isDir see if this is a dir or real file | 284 | * @param isDir see if this is a dir or real file |
286 | */ | 285 | */ |
287 | QString PIconView::currentFileName(bool &isDir)const { | 286 | QString PIconView::currentFileName(bool &isDir)const { |
288 | isDir = false; | 287 | isDir = false; |
289 | QIconViewItem* _it = m_view->currentItem(); | 288 | QIconViewItem* _it = m_view->currentItem(); |
290 | if ( !_it ) | 289 | if ( !_it ) |
291 | return QString::null; | 290 | return QString::null; |
292 | 291 | ||
293 | IconViewItem* it = static_cast<IconViewItem*>( _it ); | 292 | IconViewItem* it = static_cast<IconViewItem*>( _it ); |
294 | isDir = it->isDir(); | 293 | isDir = it->isDir(); |
295 | return it->path(); | 294 | return it->path(); |
296 | } | 295 | } |
297 | 296 | ||
298 | QString PIconView::nextFileName(bool &isDir)const | 297 | QString PIconView::nextFileName(bool &isDir)const |
299 | { | 298 | { |
300 | isDir = false; | 299 | isDir = false; |
301 | QIconViewItem* _it1 = m_view->currentItem(); | 300 | QIconViewItem* _it1 = m_view->currentItem(); |
302 | if ( !_it1 ) | 301 | if ( !_it1 ) |
303 | return QString::null; | 302 | return QString::null; |
304 | QIconViewItem* _it = _it1->nextItem(); | 303 | QIconViewItem* _it = _it1->nextItem(); |
305 | if ( !_it ) | 304 | if ( !_it ) |
306 | return QString::null; | 305 | return QString::null; |
307 | IconViewItem* it = static_cast<IconViewItem*>( _it ); | 306 | IconViewItem* it = static_cast<IconViewItem*>( _it ); |
308 | isDir = it->isDir(); | 307 | isDir = it->isDir(); |
309 | return it->path(); | 308 | return it->path(); |
310 | } | 309 | } |
311 | 310 | ||
312 | QString PIconView::prevFileName(bool &isDir)const{ | 311 | QString PIconView::prevFileName(bool &isDir)const{ |
313 | isDir = false; | 312 | isDir = false; |
314 | QIconViewItem* _it = m_view->currentItem(); | 313 | QIconViewItem* _it = m_view->currentItem(); |
315 | if ( !_it ) | 314 | if ( !_it ) |
316 | return QString::null; | 315 | return QString::null; |
317 | _it = _it->prevItem(); | 316 | _it = _it->prevItem(); |
318 | if ( !_it ) | 317 | if ( !_it ) |
319 | return QString::null; | 318 | return QString::null; |
320 | IconViewItem* it = static_cast<IconViewItem*>( _it ); | 319 | IconViewItem* it = static_cast<IconViewItem*>( _it ); |
321 | isDir = it->isDir(); | 320 | isDir = it->isDir(); |
322 | return it->path(); | 321 | return it->path(); |
323 | } | 322 | } |
324 | 323 | ||
325 | void PIconView::slotTrash() { | 324 | void PIconView::slotTrash() { |
326 | bool isDir; | 325 | bool isDir; |
327 | QString pa = currentFileName( isDir ); | 326 | QString pa = currentFileName( isDir ); |
328 | if ( isDir && pa.isEmpty() ) | 327 | if ( isDir && pa.isEmpty() ) |
329 | return; | 328 | return; |
330 | 329 | ||
331 | if (!QPEMessageBox::confirmDelete( this, | 330 | if (!QPEMessageBox::confirmDelete( this, |
332 | tr("Delete Image" ), | 331 | tr("Delete Image" ), |
333 | tr("the Image %1" ).arg(pa))) | 332 | tr("the Image %1" ).arg(pa))) |
334 | return | 333 | return |
335 | 334 | ||
336 | 335 | ||
337 | currentView()->dirLister()->deleteImage( pa ); | 336 | currentView()->dirLister()->deleteImage( pa ); |
338 | delete m_view->currentItem(); | 337 | delete m_view->currentItem(); |
339 | } | 338 | } |
340 | 339 | ||
341 | /* | 340 | /* |
342 | * see what views are available | 341 | * see what views are available |
343 | */ | 342 | */ |
344 | void PIconView::loadViews() { | 343 | void PIconView::loadViews() { |
345 | ViewMap::Iterator it; | 344 | ViewMap::Iterator it; |
346 | ViewMap* map = viewMap(); | 345 | ViewMap* map = viewMap(); |
347 | for ( it = map->begin(); it != map->end(); ++it ) | 346 | for ( it = map->begin(); it != map->end(); ++it ) |
348 | m_views->insertItem( QObject::tr(it.key() ) ); | 347 | m_views->insertItem( QObject::tr(it.key() ) ); |
349 | } | 348 | } |
350 | 349 | ||
351 | void PIconView::resetView() { | 350 | void PIconView::resetView() { |
352 | slotViewChanged(m_views->currentItem()); | 351 | slotViewChanged(m_views->currentItem()); |
353 | } | 352 | } |
354 | 353 | ||
355 | /* | 354 | /* |
356 | *swicth view reloadDir and connect signals | 355 | *swicth view reloadDir and connect signals |
357 | */ | 356 | */ |
358 | void PIconView::slotViewChanged( int i) { | 357 | void PIconView::slotViewChanged( int i) { |
359 | if (!m_views->count() ) { | 358 | if (!m_views->count() ) { |
360 | setCurrentView( 0l); | 359 | setCurrentView( 0l); |
361 | return; | 360 | return; |
362 | } | 361 | } |
363 | 362 | ||
364 | PDirView* cur = currentView(); | 363 | PDirView* cur = currentView(); |
365 | delete cur; | 364 | delete cur; |
366 | QString str = m_views->text(i); | 365 | QString str = m_views->text(i); |
367 | cur = (*(*viewMap())[str])(*m_cfg); | 366 | cur = (*(*viewMap())[str])(*m_cfg); |
368 | setCurrentView( cur ); | 367 | setCurrentView( cur ); |
369 | 368 | ||
370 | /* connect to the signals of the lister */ | 369 | /* connect to the signals of the lister */ |
371 | PDirLister* lis = cur->dirLister(); | 370 | PDirLister* lis = cur->dirLister(); |
372 | connect(lis, SIGNAL(sig_thumbInfo(const QString&, const QString& )), | 371 | connect(lis, SIGNAL(sig_thumbInfo(const QString&, const QString& )), |
373 | this, SLOT( slotThumbInfo(const QString&, const QString&))); | 372 | this, SLOT( slotThumbInfo(const QString&, const QString&))); |
374 | connect(lis, SIGNAL( sig_thumbNail(const QString&, const QPixmap&)), | 373 | connect(lis, SIGNAL( sig_thumbNail(const QString&, const QPixmap&)), |
375 | this, SLOT(slotThumbNail(const QString&, const QPixmap&))); | 374 | this, SLOT(slotThumbNail(const QString&, const QPixmap&))); |
376 | connect(lis, SIGNAL(sig_start()), | 375 | connect(lis, SIGNAL(sig_start()), |
377 | this, SLOT(slotStart())); | 376 | this, SLOT(slotStart())); |
378 | connect(lis, SIGNAL(sig_end()) , | 377 | connect(lis, SIGNAL(sig_end()) , |
379 | this, SLOT(slotEnd()) ); | 378 | this, SLOT(slotEnd()) ); |
380 | 379 | ||
381 | 380 | ||
382 | /* reload now */ | 381 | /* reload now */ |
383 | QTimer::singleShot( 0, this, SLOT(slotReloadDir())); | 382 | QTimer::singleShot( 0, this, SLOT(slotReloadDir())); |
384 | } | 383 | } |
385 | 384 | ||
386 | 385 | ||
387 | void PIconView::slotReloadDir() { | 386 | void PIconView::slotReloadDir() { |
388 | slotChangeDir( m_path ); | 387 | slotChangeDir( m_path ); |
389 | } | 388 | } |
390 | 389 | ||
391 | 390 | ||
392 | /* | 391 | /* |
393 | * add files and folders | 392 | * add files and folders |
394 | */ | 393 | */ |
395 | void PIconView::addFolders( const QStringList& lst) { | 394 | void PIconView::addFolders( const QStringList& lst) { |
396 | QStringList::ConstIterator it; | 395 | QStringList::ConstIterator it; |
397 | IconViewItem * _iv; | 396 | IconViewItem * _iv; |
398 | 397 | ||
399 | for(it=lst.begin(); it != lst.end(); ++it ) { | 398 | for(it=lst.begin(); it != lst.end(); ++it ) { |
400 | _iv = new IconViewItem( m_view, m_path+"/"+(*it), (*it), true ); | 399 | _iv = new IconViewItem( m_view, m_path+"/"+(*it), (*it), true ); |
401 | if (m_mode==3) _iv->setTextOnly(true); | 400 | if (m_mode==3) _iv->setTextOnly(true); |
402 | } | 401 | } |
403 | } | 402 | } |
404 | 403 | ||
405 | void PIconView::addFiles( const QStringList& lst) { | 404 | void PIconView::addFiles( const QStringList& lst) { |
406 | QStringList::ConstIterator it; | 405 | QStringList::ConstIterator it; |
407 | IconViewItem * _iv; | 406 | IconViewItem * _iv; |
408 | QPixmap*m_pix = 0; | 407 | QPixmap*m_pix = 0; |
409 | for (it=lst.begin(); it!= lst.end(); ++it ) { | 408 | for (it=lst.begin(); it!= lst.end(); ++it ) { |
410 | m_pix = PPixmapCache::self()->cachedImage( m_path+"/"+(*it), 64, 64 ); | 409 | m_pix = PPixmapCache::self()->cachedImage( m_path+"/"+(*it), 64, 64 ); |
411 | _iv = new IconViewItem( m_view, m_path+"/"+(*it), (*it) ); | 410 | _iv = new IconViewItem( m_view, m_path+"/"+(*it), (*it) ); |
412 | if (m_mode==3) _iv->setTextOnly(true); | 411 | if (m_mode==3) { |
413 | if (m_pix) _iv->setPixmap(*m_pix); | 412 | _iv->setTextOnly(true); |
413 | _iv->setPixmap(QPixmap()); | ||
414 | } else { | ||
415 | if (m_pix) _iv->setPixmap(*m_pix); | ||
416 | } | ||
414 | } | 417 | } |
415 | 418 | ||
416 | } | 419 | } |
417 | 420 | ||
418 | /* | 421 | /* |
419 | * user clicked on the item. Change dir or view | 422 | * user clicked on the item. Change dir or view |
420 | */ | 423 | */ |
421 | void PIconView::slotClicked(QIconViewItem* _it) { | 424 | void PIconView::slotClicked(QIconViewItem* _it) { |
422 | if(!_it ) | 425 | if(!_it ) |
423 | return; | 426 | return; |
424 | 427 | ||
425 | IconViewItem* it = static_cast<IconViewItem*>(_it); | 428 | IconViewItem* it = static_cast<IconViewItem*>(_it); |
426 | if( it->isDir() ) | 429 | if( it->isDir() ) |
427 | slotChangeDir( it->path() ); | 430 | slotChangeDir( it->path() ); |
428 | else // view image | 431 | else // view image |
429 | slotShowImage(); | 432 | slotShowImage(); |
430 | } | 433 | } |
431 | 434 | ||
432 | /* | 435 | /* |
433 | * got thumb info add to the cache if items is visible | 436 | * got thumb info add to the cache if items is visible |
434 | * we later need update after processing of slave is done | 437 | * we later need update after processing of slave is done |
435 | */ | 438 | */ |
436 | void PIconView::slotThumbInfo( const QString& _path, const QString& str ) { | 439 | void PIconView::slotThumbInfo( const QString& _path, const QString& str ) { |
437 | IconViewItem* item = g_stringInf[_path]; | 440 | IconViewItem* item = g_stringInf[_path]; |
438 | if (!item ) | 441 | if (!item ) |
439 | return; | 442 | return; |
440 | 443 | ||
441 | if (m_mode == 2) { | 444 | if (m_mode == 2) { |
442 | return; | 445 | return; |
443 | } | 446 | } |
444 | if ( item->intersects(QRect( m_view->contentsX(),m_view->contentsY(), | 447 | if ( item->intersects(QRect( m_view->contentsX(),m_view->contentsY(), |
445 | m_view->contentsWidth(), m_view->contentsHeight() ) ) ) | 448 | m_view->contentsWidth(), m_view->contentsHeight() ) ) ) |
446 | m_updatet = true; | 449 | m_updatet = true; |
447 | 450 | ||
448 | item->setText( str ); | 451 | item->setText( str ); |
449 | g_stringInf.remove( _path ); | 452 | g_stringInf.remove( _path ); |
450 | } | 453 | } |
451 | 454 | ||
452 | /* | 455 | /* |
453 | * got thumbnail and see if it is visible so we need to update later | 456 | * got thumbnail and see if it is visible so we need to update later |
454 | */ | 457 | */ |
455 | void PIconView::slotThumbNail(const QString& _path, const QPixmap &pix) { | 458 | void PIconView::slotThumbNail(const QString& _path, const QPixmap &pix) { |
456 | IconViewItem* item = g_stringPix[_path]; | 459 | IconViewItem* item = g_stringPix[_path]; |
457 | if (!item ) | 460 | if (!item ) |
458 | return; | 461 | return; |
459 | 462 | ||
460 | if ( item->intersects(QRect( m_view->contentsX(),m_view->contentsY(), | 463 | if ( item->intersects(QRect( m_view->contentsX(),m_view->contentsY(), |
461 | m_view->contentsWidth(), m_view->contentsHeight() ) ) ) | 464 | m_view->contentsWidth(), m_view->contentsHeight() ) ) ) |
462 | m_updatet = true; | 465 | m_updatet = true; |
463 | 466 | ||
464 | if (pix.width()>0) { | 467 | if (pix.width()>0) { |
465 | PPixmapCache::self()->insertImage( _path, pix, 64, 64 ); | 468 | PPixmapCache::self()->insertImage( _path, pix, 64, 64 ); |
466 | item->setPixmap(pix,true); | 469 | item->setPixmap(pix,true); |
467 | } else { | 470 | } else { |
468 | PPixmapCache::self()->insertImage( _path, Resource::loadPixmap( "UnknownDocument" ), 64, 64 ); | 471 | PPixmapCache::self()->insertImage( _path, Resource::loadPixmap( "UnknownDocument" ), 64, 64 ); |
469 | } | 472 | } |
470 | g_stringPix.remove( _path ); | 473 | g_stringPix.remove( _path ); |
471 | } | 474 | } |
472 | 475 | ||
473 | 476 | ||
474 | /* | 477 | /* |
475 | * FIXME rename | 478 | * FIXME rename |
476 | */ | 479 | */ |
477 | void PIconView::slotRename() { | 480 | void PIconView::slotRename() { |
478 | 481 | ||
479 | } | 482 | } |
480 | 483 | ||
481 | 484 | ||
482 | /* | 485 | /* |
483 | * BEAM the current file | 486 | * BEAM the current file |
484 | */ | 487 | */ |
485 | void PIconView::slotBeam() { | 488 | void PIconView::slotBeam() { |
486 | bool isDir; | 489 | bool isDir; |
487 | QString pa = currentFileName( isDir ); | 490 | QString pa = currentFileName( isDir ); |
488 | if ( isDir && pa.isEmpty() ) | 491 | if ( isDir && pa.isEmpty() ) |
489 | return; | 492 | return; |
490 | 493 | ||
491 | Ir* ir = new Ir( this ); | 494 | Ir* ir = new Ir( this ); |
492 | connect( ir, SIGNAL(done(Ir*)), | 495 | connect( ir, SIGNAL(done(Ir*)), |
493 | this, SLOT(slotBeamDone(Ir*))); | 496 | this, SLOT(slotBeamDone(Ir*))); |
494 | ir->send(pa, tr( "Image" ) ); | 497 | ir->send(pa, tr( "Image" ) ); |
495 | } | 498 | } |
496 | 499 | ||
497 | /* | 500 | /* |
498 | * BEAM done clean up | 501 | * BEAM done clean up |
499 | */ | 502 | */ |
500 | void PIconView::slotBeamDone( Ir* ir) { | 503 | void PIconView::slotBeamDone( Ir* ir) { |
501 | delete ir; | 504 | delete ir; |
502 | } | 505 | } |
503 | 506 | ||
504 | void PIconView::slotStart() { | 507 | void PIconView::slotStart() { |
505 | m_view->viewport()->setUpdatesEnabled( false ); | 508 | m_view->viewport()->setUpdatesEnabled( false ); |
506 | } | 509 | } |
507 | 510 | ||
508 | void PIconView::slotEnd() { | 511 | void PIconView::slotEnd() { |
509 | if ( m_updatet ) | 512 | if ( m_updatet ) |
510 | m_view->arrangeItemsInGrid( ); | 513 | m_view->arrangeItemsInGrid( ); |
511 | m_view->viewport()->setUpdatesEnabled( true ); | 514 | m_view->viewport()->setUpdatesEnabled( true ); |
512 | m_updatet = false; | 515 | m_updatet = false; |
513 | } | 516 | } |
514 | 517 | ||
515 | void PIconView::slotShowNext() | 518 | void PIconView::slotShowNext() |
516 | { | 519 | { |
517 | bool isDir = false; | 520 | bool isDir = false; |
518 | QString name = nextFileName(isDir); | 521 | QString name = nextFileName(isDir); |
519 | if (name.isEmpty()) return; | 522 | if (name.isEmpty()) return; |
520 | if (isDir) return; | 523 | if (isDir) return; |
521 | /* if we got a name we have a next item */ | 524 | /* if we got a name we have a next item */ |
522 | m_view->setCurrentItem(m_view->currentItem()->nextItem()); | 525 | m_view->setCurrentItem(m_view->currentItem()->nextItem()); |
523 | slotShowImage(name); | 526 | slotShowImage(name); |
524 | } | 527 | } |
525 | 528 | ||
526 | void PIconView::slotShowPrev() | 529 | void PIconView::slotShowPrev() |
527 | { | 530 | { |
528 | bool isDir = false; | 531 | bool isDir = false; |
529 | QString name = prevFileName(isDir); | 532 | QString name = prevFileName(isDir); |
530 | if (name.isEmpty()) return; | 533 | if (name.isEmpty()) return; |
531 | if (isDir) return; | 534 | if (isDir) return; |
532 | /* if we got a name we have a prev item */ | 535 | /* if we got a name we have a prev item */ |
533 | m_view->setCurrentItem(m_view->currentItem()->prevItem()); | 536 | m_view->setCurrentItem(m_view->currentItem()->prevItem()); |
534 | slotShowImage(name); | 537 | slotShowImage(name); |
535 | } | 538 | } |
536 | 539 | ||
537 | void PIconView::slotShowImage() | 540 | void PIconView::slotShowImage() |
538 | { | 541 | { |
539 | bool isDir = false; | 542 | bool isDir = false; |
540 | QString name = currentFileName(isDir); | 543 | QString name = currentFileName(isDir); |
541 | if (isDir) return; | 544 | if (isDir) return; |
542 | 545 | ||
543 | slotShowImage( name ); | 546 | slotShowImage( name ); |
544 | } | 547 | } |
545 | void PIconView::slotShowImage( const QString& name) { | 548 | void PIconView::slotShowImage( const QString& name) { |
546 | emit sig_display( name ); | 549 | emit sig_display( name ); |
547 | } | 550 | } |
548 | void PIconView::slotImageInfo() { | 551 | void PIconView::slotImageInfo() { |
549 | bool isDir = false; | 552 | bool isDir = false; |
550 | QString name = currentFileName(isDir); | 553 | QString name = currentFileName(isDir); |
551 | if (isDir) return; | 554 | if (isDir) return; |
552 | 555 | ||
553 | slotImageInfo( name ); | 556 | slotImageInfo( name ); |
554 | } | 557 | } |
555 | 558 | ||
556 | void PIconView::slotImageInfo( const QString& name) { | 559 | void PIconView::slotImageInfo( const QString& name) { |
557 | emit sig_showInfo( name ); | 560 | emit sig_showInfo( name ); |
558 | } | 561 | } |
559 | 562 | ||
560 | 563 | ||
561 | void PIconView::slotChangeMode( int mode ) { | 564 | void PIconView::slotChangeMode( int mode ) { |
562 | if ( mode >= 1 && mode <= 3 ) | 565 | if ( mode >= 1 && mode <= 3 ) |
563 | m_mode = mode; | 566 | m_mode = mode; |
564 | 567 | ||
565 | QIconView::ItemTextPos pos; | 568 | QIconView::ItemTextPos pos; |
566 | switch( m_mode ) { | 569 | switch( m_mode ) { |
567 | case 2: | 570 | case 2: |
568 | pos = QIconView::Bottom; | 571 | pos = QIconView::Bottom; |
569 | break; | 572 | break; |
570 | case 3: | 573 | case 3: |
571 | case 1: | 574 | case 1: |
572 | default: | 575 | default: |
573 | pos = QIconView::Right; | 576 | pos = QIconView::Right; |
574 | break; | 577 | break; |
575 | } | 578 | } |
576 | m_view->setItemTextPos( pos ); | 579 | m_view->setItemTextPos( pos ); |
577 | 580 | ||
578 | calculateGrid(); | 581 | calculateGrid(); |
579 | slotReloadDir(); | 582 | slotReloadDir(); |
580 | } | 583 | } |
581 | 584 | ||
582 | 585 | ||
583 | void PIconView::resizeEvent( QResizeEvent* re ) { | 586 | void PIconView::resizeEvent( QResizeEvent* re ) { |
584 | QVBox::resizeEvent( re ); | 587 | QVBox::resizeEvent( re ); |
585 | calculateGrid(); | 588 | calculateGrid(); |
586 | } | 589 | } |
587 | 590 | ||
588 | 591 | ||
589 | void PIconView::calculateGrid() { | 592 | void PIconView::calculateGrid() { |
590 | odebug << "Calc grid: x=" << m_view->gridX() << " y=" << m_view->gridY() << oendl; | 593 | odebug << "Calc grid: x=" << m_view->gridX() << " y=" << m_view->gridY() << oendl; |
591 | odebug << "Size of view: " << m_view->size() << oendl; | 594 | odebug << "Size of view: " << m_view->size() << oendl; |
592 | 595 | ||
593 | switch (m_mode) { | 596 | switch (m_mode) { |
594 | case 2: | 597 | case 2: |
595 | m_view->setGridX(80); | 598 | m_view->setGridX(50); |
596 | m_view->setGridY(80); | 599 | m_view->setGridY(20); |
600 | PPixmapCache::self()->setMaxImages(40); | ||
597 | break; | 601 | break; |
598 | case 3: | 602 | case 3: |
599 | m_view->setGridX(m_view->width()); | 603 | m_view->setGridX(m_view->width()); |
600 | m_view->setGridY(8); | 604 | m_view->setGridY(8); |
605 | PPixmapCache::self()->setMaxImages(2); | ||
601 | break; | 606 | break; |
602 | case 1: | 607 | case 1: |
603 | default: | 608 | default: |
604 | m_view->setGridX(m_view->width()); | 609 | m_view->setGridX(m_view->width()); |
605 | m_view->setGridY(80); | 610 | m_view->setGridY(80); |
611 | PPixmapCache::self()->setMaxImages(20); | ||
606 | break; | 612 | break; |
607 | } | 613 | } |
608 | } | 614 | } |
diff --git a/noncore/graphics/opie-eye/lib/imagecache.cpp b/noncore/graphics/opie-eye/lib/imagecache.cpp index 3b74a83..f1042a4 100644 --- a/noncore/graphics/opie-eye/lib/imagecache.cpp +++ b/noncore/graphics/opie-eye/lib/imagecache.cpp | |||
@@ -1,87 +1,93 @@ | |||
1 | /* | 1 | /* |
2 | * GPLv2 zecke@handhelds.org | 2 | * GPLv2 zecke@handhelds.org |
3 | * No WArranty... | 3 | * No WArranty... |
4 | */ | 4 | */ |
5 | 5 | ||
6 | #include <iface/dirview.h> | 6 | #include <iface/dirview.h> |
7 | #include <iface/dirlister.h> | 7 | #include <iface/dirlister.h> |
8 | 8 | ||
9 | #include "imagecache.h" | 9 | #include "imagecache.h" |
10 | 10 | ||
11 | namespace { | 11 | namespace { |
12 | PImageCache * _imgCache = 0; | 12 | PImageCache * _imgCache = 0; |
13 | PPixmapCache* _pxmCache = 0; | 13 | PPixmapCache* _pxmCache = 0; |
14 | } | 14 | } |
15 | 15 | ||
16 | 16 | ||
17 | PImageCache::PImageCache() | 17 | PImageCache::PImageCache() |
18 | : QCache<QImage>() | 18 | : QCache<QImage>() |
19 | { | 19 | { |
20 | /* just to set an initial value.. 4 big images */ | 20 | /* just to set an initial value.. 4 big images */ |
21 | setMaxCost( (1024*1024*16)/8*4 ); | 21 | setMaxCost( (1024*1024*16)/8*4 ); |
22 | } | 22 | } |
23 | 23 | ||
24 | PImageCache::~PImageCache() { | 24 | PImageCache::~PImageCache() { |
25 | } | 25 | } |
26 | 26 | ||
27 | PImageCache* PImageCache::self() { | 27 | PImageCache* PImageCache::self() { |
28 | if ( !_imgCache ) | 28 | if ( !_imgCache ) |
29 | _imgCache = new PImageCache; | 29 | _imgCache = new PImageCache; |
30 | return _imgCache; | 30 | return _imgCache; |
31 | } | 31 | } |
32 | 32 | ||
33 | QImage* PImageCache::cachedImage( const QString& _path, int ori, int max ) { | 33 | QImage* PImageCache::cachedImage( const QString& _path, int ori, int max ) { |
34 | QString path = QString( "%1_%2:" ).arg( ori ).arg( max ); | 34 | QString path = QString( "%1_%2:" ).arg( ori ).arg( max ); |
35 | path += _path; | 35 | path += _path; |
36 | 36 | ||
37 | QImage* img = find( path ); | 37 | QImage* img = find( path ); |
38 | if ( !img ) { | 38 | if ( !img ) { |
39 | // img = currentView()->dirLister()->image( _path, PDirLister::Factor(ori), max); | 39 | // img = currentView()->dirLister()->image( _path, PDirLister::Factor(ori), max); |
40 | // insertImage( _path, img, ori, max ); | 40 | // insertImage( _path, img, ori, max ); |
41 | currentView()->dirLister()->image( _path, PDirLister::Factor( ori ), max ); | 41 | currentView()->dirLister()->image( _path, PDirLister::Factor( ori ), max ); |
42 | } | 42 | } |
43 | 43 | ||
44 | 44 | ||
45 | return img; | 45 | return img; |
46 | } | 46 | } |
47 | 47 | ||
48 | void PImageCache::insertImage( const QString& _path, const QImage* img, int ori, int max ) { | 48 | void PImageCache::insertImage( const QString& _path, const QImage* img, int ori, int max ) { |
49 | QString path = QString("%1_%2:" ).arg( ori ).arg( max ); | 49 | QString path = QString("%1_%2:" ).arg( ori ).arg( max ); |
50 | path += _path; | 50 | path += _path; |
51 | insert( path, img, (img->height()*img->width()*img->depth())/8 ); | 51 | insert( path, img, (img->height()*img->width()*img->depth())/8 ); |
52 | } | 52 | } |
53 | 53 | ||
54 | 54 | ||
55 | PPixmapCache::PPixmapCache() { | 55 | PPixmapCache::PPixmapCache() { |
56 | /* | 56 | /* |
57 | * 20 64x64 16 bit images | 57 | * 20 64x64 16 bit images |
58 | */ | 58 | */ |
59 | setMaxCost( 64*64*QPixmap::defaultDepth()/8*20 ); | 59 | setMaxCost( 64*64*QPixmap::defaultDepth()/8*20 ); |
60 | } | 60 | } |
61 | 61 | ||
62 | PPixmapCache::~PPixmapCache() { | 62 | PPixmapCache::~PPixmapCache() { |
63 | } | 63 | } |
64 | 64 | ||
65 | void PPixmapCache::setMaxImages(unsigned int aMax) | ||
66 | { | ||
67 | m_MaxImages = aMax; | ||
68 | setMaxCost( 64*64*QPixmap::defaultDepth()/8*m_MaxImages); | ||
69 | } | ||
70 | |||
65 | PPixmapCache* PPixmapCache::self() { | 71 | PPixmapCache* PPixmapCache::self() { |
66 | if ( !_pxmCache ) | 72 | if ( !_pxmCache ) |
67 | _pxmCache = new PPixmapCache; | 73 | _pxmCache = new PPixmapCache; |
68 | 74 | ||
69 | return _pxmCache; | 75 | return _pxmCache; |
70 | } | 76 | } |
71 | 77 | ||
72 | QPixmap* PPixmapCache::cachedImage( const QString& _path, int width, int height ) { | 78 | QPixmap* PPixmapCache::cachedImage( const QString& _path, int width, int height ) { |
73 | QString path = QString( "%1_%2:" ).arg( width ).arg( height ); | 79 | QString path = QString( "%1_%2:" ).arg( width ).arg( height ); |
74 | path += _path; | 80 | path += _path; |
75 | 81 | ||
76 | QPixmap* pxm = find( path ); | 82 | QPixmap* pxm = find( path ); |
77 | 83 | ||
78 | 84 | ||
79 | 85 | ||
80 | return pxm; | 86 | return pxm; |
81 | } | 87 | } |
82 | 88 | ||
83 | void PPixmapCache::insertImage( const QString& _path, const QPixmap* pix, int width, int height ) { | 89 | void PPixmapCache::insertImage( const QString& _path, const QPixmap* pix, int width, int height ) { |
84 | QString path = QString("%1_%2:" ).arg( width ).arg( height ); | 90 | QString path = QString("%1_%2:" ).arg( width ).arg( height ); |
85 | path += _path; | 91 | path += _path; |
86 | insert( path, pix, (pix->height()*pix->width()*pix->depth())/8 ); | 92 | insert( path, pix, (pix->height()*pix->width()*pix->depth())/8 ); |
87 | } | 93 | } |
diff --git a/noncore/graphics/opie-eye/lib/imagecache.h b/noncore/graphics/opie-eye/lib/imagecache.h index 076ecd3..939247a 100644 --- a/noncore/graphics/opie-eye/lib/imagecache.h +++ b/noncore/graphics/opie-eye/lib/imagecache.h | |||
@@ -1,46 +1,51 @@ | |||
1 | /* | 1 | /* |
2 | * GPLv2 zecke@handhelds.org | 2 | * GPLv2 zecke@handhelds.org |
3 | * No WArranty... | 3 | * No WArranty... |
4 | */ | 4 | */ |
5 | 5 | ||
6 | #ifndef PHUNK_IMAGE_CACHE_H | 6 | #ifndef PHUNK_IMAGE_CACHE_H |
7 | #define PHUNK_IMAGE_CACHE_H | 7 | #define PHUNK_IMAGE_CACHE_H |
8 | 8 | ||
9 | #include <qimage.h> | 9 | #include <qimage.h> |
10 | #include <qpixmap.h> | 10 | #include <qpixmap.h> |
11 | #include <qcache.h> | 11 | #include <qcache.h> |
12 | 12 | ||
13 | 13 | ||
14 | class PImageCache : public QCache<QImage> { | 14 | class PImageCache : public QCache<QImage> { |
15 | private: | 15 | private: |
16 | PImageCache(); | 16 | PImageCache(); |
17 | ~PImageCache(); | 17 | ~PImageCache(); |
18 | 18 | ||
19 | public: | 19 | public: |
20 | static PImageCache *self(); | 20 | static PImageCache *self(); |
21 | QImage* cachedImage( const QString& path, int orientation = 3, int max = 0); //const; | 21 | QImage* cachedImage( const QString& path, int orientation = 3, int max = 0); //const; |
22 | void insertImage( const QString& path, const QImage &, int orien = 3, int max = 0); | 22 | void insertImage( const QString& path, const QImage &, int orien = 3, int max = 0); |
23 | void insertImage( const QString& path, const QImage *, int orien=3, int max = 0 ); | 23 | void insertImage( const QString& path, const QImage *, int orien=3, int max = 0 ); |
24 | }; | 24 | }; |
25 | 25 | ||
26 | 26 | ||
27 | class PPixmapCache : public QCache<QPixmap> { | 27 | class PPixmapCache : public QCache<QPixmap> { |
28 | private: | 28 | private: |
29 | PPixmapCache(); | 29 | PPixmapCache(); |
30 | ~PPixmapCache(); | 30 | ~PPixmapCache(); |
31 | |||
32 | unsigned int m_MaxImages; | ||
33 | |||
31 | public: | 34 | public: |
32 | static PPixmapCache *self(); | 35 | static PPixmapCache *self(); |
33 | QPixmap* cachedImage( const QString& path, int width, int height ); | 36 | QPixmap* cachedImage( const QString& path, int width, int height ); |
34 | void insertImage( const QString& path, const QPixmap &, int width, int height ); | 37 | void insertImage( const QString& path, const QPixmap &, int width, int height ); |
35 | void insertImage( const QString& path, const QPixmap *, int width, int height ); | 38 | void insertImage( const QString& path, const QPixmap *, int width, int height ); |
39 | void setMaxImages(unsigned int aMax); | ||
40 | unsigned int maxImages()const{return m_MaxImages;} | ||
36 | }; | 41 | }; |
37 | 42 | ||
38 | inline void PPixmapCache::insertImage( const QString& path, const QPixmap& p, int width, int height ) { | 43 | inline void PPixmapCache::insertImage( const QString& path, const QPixmap& p, int width, int height ) { |
39 | insertImage( path, new QPixmap( p ), width, height ); | 44 | insertImage( path, new QPixmap( p ), width, height ); |
40 | } | 45 | } |
41 | 46 | ||
42 | inline void PImageCache::insertImage( const QString& path, const QImage& p, int width, int height ) { | 47 | inline void PImageCache::insertImage( const QString& path, const QImage& p, int width, int height ) { |
43 | insertImage( path, new QImage( p ), width, height ); | 48 | insertImage( path, new QImage( p ), width, height ); |
44 | } | 49 | } |
45 | 50 | ||
46 | #endif | 51 | #endif |