-rw-r--r-- | noncore/graphics/opie-eye/gui/iconview.cpp | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/noncore/graphics/opie-eye/gui/iconview.cpp b/noncore/graphics/opie-eye/gui/iconview.cpp index c037d0d..f173ecc 100644 --- a/noncore/graphics/opie-eye/gui/iconview.cpp +++ b/noncore/graphics/opie-eye/gui/iconview.cpp | |||
@@ -1,865 +1,881 @@ | |||
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* _cpyPix = 0; | 44 | static QPixmap* _cpyPix = 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,int a_iconsize, bool isDir = false); | 48 | IconViewItem( QIconView*, const QString& path, const QString& name,int a_iconsize, 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 | /* just for starting recalc of item rect! */ |
56 | 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! */ | 57 | /* just for starting recalc of item rect! */ |
58 | virtual void setPixmap( const QPixmap & icon); | 58 | virtual void setPixmap( const QPixmap & icon); |
59 | 59 | ||
60 | protected: | 60 | protected: |
61 | mutable QPixmap* m_pix; | 61 | mutable QPixmap* m_pix; |
62 | int m_iconsize; | 62 | int m_iconsize; |
63 | void check_pix()const; | 63 | void check_pix()const; |
64 | 64 | ||
65 | private: | 65 | private: |
66 | QString m_path; | 66 | QString m_path; |
67 | bool m_isDir : 1; | 67 | bool m_isDir : 1; |
68 | bool m_noInfo :1; | 68 | bool m_noInfo :1; |
69 | bool m_textOnly:1; | 69 | bool m_textOnly:1; |
70 | bool m_NameOnly:1; | 70 | bool m_NameOnly:1; |
71 | bool m_Pixset:1; | 71 | bool m_Pixset:1; |
72 | }; | 72 | }; |
73 | class TextViewItem : public IconViewItem { | 73 | class TextViewItem : public IconViewItem { |
74 | TextViewItem( QIconView*, const QString& path, const QString& name, int a_iconsize , bool isDir = false); | 74 | TextViewItem( QIconView*, const QString& path, const QString& name, int a_iconsize , bool isDir = false); |
75 | QPixmap *pixmap()const; | 75 | QPixmap *pixmap()const; |
76 | void setText( const QString& ); | 76 | void setText( const QString& ); |
77 | }; | 77 | }; |
78 | class ThumbViewItem : public IconViewItem { | 78 | class ThumbViewItem : public IconViewItem { |
79 | ThumbViewItem( QIconView*, const QString& path, const QString& name, int a_iconsize, bool isDir = false ); | 79 | ThumbViewItem( QIconView*, const QString& path, const QString& name, int a_iconsize, bool isDir = false ); |
80 | QPixmap *pixmap()const; | 80 | QPixmap *pixmap()const; |
81 | void setText( const QString& ); | 81 | void setText( const QString& ); |
82 | }; | 82 | }; |
83 | 83 | ||
84 | 84 | ||
85 | /* | 85 | /* |
86 | * If we request an Image or String | 86 | * If we request an Image or String |
87 | * we add it to the map | 87 | * we add it to the map |
88 | */ | 88 | */ |
89 | static QMap<QString, IconViewItem*> g_stringInf; | 89 | static QMap<QString, IconViewItem*> g_stringInf; |
90 | static QMap<QString, IconViewItem*> g_stringPix; | 90 | static QMap<QString, IconViewItem*> g_stringPix; |
91 | 91 | ||
92 | IconViewItem::IconViewItem( QIconView* view,const QString& path, | 92 | IconViewItem::IconViewItem( QIconView* view,const QString& path, |
93 | const QString& name, int a_iconsize, bool isDir) | 93 | const QString& name, int a_iconsize, bool isDir) |
94 | : QIconViewItem( view, name ), m_path( path ), m_isDir( isDir ), | 94 | : QIconViewItem( view, name ), m_path( path ), m_isDir( isDir ), |
95 | m_noInfo( false ),m_textOnly(false),m_Pixset(false) | 95 | m_noInfo( false ),m_textOnly(false),m_Pixset(false) |
96 | { | 96 | { |
97 | m_iconsize = a_iconsize; | 97 | m_iconsize = a_iconsize; |
98 | if ( isDir ) { | 98 | if ( isDir ) { |
99 | if (_dirPix && _dirPix->width()!=m_iconsize) { | ||
100 | delete _dirPix; | ||
101 | _dirPix = 0; | ||
102 | } | ||
103 | if (!_dirPix ) { | 99 | if (!_dirPix ) { |
104 | _dirPix = new QPixmap( Resource::loadPixmap("advancedfm/FileBrowser")); | 100 | _dirPix = new QPixmap( Resource::loadPixmap("advancedfm/FileBrowser")); |
105 | } | 101 | } |
106 | } else { | 102 | } else { |
107 | if (!_unkPix ) { | 103 | if (!_unkPix ) { |
108 | _unkPix = new QPixmap( Resource::loadPixmap( "UnknownDocument" ) ); | 104 | _unkPix = new QPixmap( Resource::loadPixmap( "UnknownDocument" ) ); |
109 | } | 105 | } |
110 | } | 106 | } |
111 | check_pix(); | 107 | check_pix(); |
112 | } | 108 | } |
113 | 109 | ||
114 | inline void IconViewItem::check_pix()const | 110 | inline void IconViewItem::check_pix()const |
115 | { | 111 | { |
116 | if (_cpyPix && _cpyPix->width()!=m_iconsize) { | ||
117 | delete _cpyPix; | ||
118 | _cpyPix = 0; | ||
119 | } | ||
120 | if (_dirPix && _dirPix->width()>m_iconsize) { | 112 | if (_dirPix && _dirPix->width()>m_iconsize) { |
121 | QPixmap*Pix = new QPixmap(*_dirPix); | 113 | QPixmap*Pix = new QPixmap(*_dirPix); |
122 | Pix->resize(m_iconsize,m_iconsize); | 114 | Pix->resize(m_iconsize,m_iconsize); |
123 | delete _dirPix; | 115 | delete _dirPix; |
124 | _dirPix = Pix; | 116 | _dirPix = Pix; |
125 | } | 117 | } |
126 | if (!_cpyPix && _unkPix) { | 118 | if (!_cpyPix && _unkPix) { |
127 | if (_unkPix->width()>=m_iconsize) { | 119 | if (_unkPix->width()>=m_iconsize) { |
128 | _cpyPix = new QPixmap(*_unkPix); | 120 | _cpyPix = new QPixmap(*_unkPix); |
129 | if (_unkPix->width()>m_iconsize) | 121 | if (_unkPix->width()>m_iconsize) |
130 | _cpyPix->resize(m_iconsize,m_iconsize); | 122 | _cpyPix->resize(m_iconsize,m_iconsize); |
131 | } else { | 123 | } else { |
132 | _cpyPix = new QPixmap(m_iconsize,m_iconsize); | 124 | _cpyPix = new QPixmap(m_iconsize,m_iconsize); |
133 | _cpyPix->fill(); | 125 | _cpyPix->fill(); |
134 | QPainter pa(_cpyPix); | 126 | QPainter pa(_cpyPix); |
135 | int offset = (m_iconsize-_unkPix->width())/2; | 127 | int offset = (m_iconsize-_unkPix->width())/2; |
136 | int offy = (m_iconsize-_unkPix->height())/2; | 128 | int offy = (m_iconsize-_unkPix->height())/2; |
137 | if (offy<0) offy=0; | 129 | if (offy<0) offy=0; |
138 | pa.drawPixmap(offset,offy,*_unkPix); | 130 | pa.drawPixmap(offset,offy,*_unkPix); |
139 | pa.end(); | 131 | pa.end(); |
140 | } | 132 | } |
141 | } | 133 | } |
142 | } | 134 | } |
143 | 135 | ||
144 | inline void IconViewItem::setPixmap( const QPixmap & , bool, bool ) | 136 | inline void IconViewItem::setPixmap( const QPixmap & , bool, bool ) |
145 | { | 137 | { |
146 | m_Pixset = true; | 138 | m_Pixset = true; |
147 | calcRect(text()); | 139 | calcRect(text()); |
148 | } | 140 | } |
149 | inline void IconViewItem::setPixmap( const QPixmap & ) | 141 | inline void IconViewItem::setPixmap( const QPixmap & ) |
150 | { | 142 | { |
151 | m_Pixset = true; | 143 | m_Pixset = true; |
152 | calcRect(text()); | 144 | calcRect(text()); |
153 | } | 145 | } |
154 | 146 | ||
155 | inline QPixmap* IconViewItem::pixmap()const { | 147 | inline QPixmap* IconViewItem::pixmap()const { |
156 | // owarn << "Name is " << m_path.right( 15 ) << " rect is " << rect().x() << " " << rect().y() | 148 | // owarn << "Name is " << m_path.right( 15 ) << " rect is " << rect().x() << " " << rect().y() |
157 | // << " " << rect().width() << " " << rect().height() << " | " << iconView()->contentsX() | 149 | // << " " << rect().width() << " " << rect().height() << " | " << iconView()->contentsX() |
158 | // << " " << iconView()->contentsY() << oendl; | 150 | // << " " << iconView()->contentsY() << oendl; |
159 | 151 | ||
160 | if (textOnly()&&!m_isDir) { | 152 | if (textOnly()&&!m_isDir) { |
161 | if (!_emptyPix) _emptyPix = new QPixmap(0,0,1); | 153 | if (!_emptyPix) _emptyPix = new QPixmap(0,0,1); |
162 | return _emptyPix; | 154 | return _emptyPix; |
163 | } | 155 | } |
164 | if ( m_isDir ) | 156 | if ( m_isDir ) |
165 | return _dirPix; | 157 | return _dirPix; |
166 | else{ | 158 | else{ |
167 | if (!m_noInfo && !g_stringInf.contains( m_path ) ) { | 159 | if (!m_noInfo && !g_stringInf.contains( m_path ) ) { |
168 | g_stringInf.insert( m_path, const_cast<IconViewItem*>(this)); | 160 | g_stringInf.insert( m_path, const_cast<IconViewItem*>(this)); |
169 | currentView()->dirLister()->imageInfo( m_path ); | 161 | currentView()->dirLister()->imageInfo( m_path ); |
170 | } | 162 | } |
171 | 163 | ||
172 | m_pix = PPixmapCache::self()->cachedImage( m_path, m_iconsize, m_iconsize ); | 164 | m_pix = PPixmapCache::self()->cachedImage( m_path, m_iconsize, m_iconsize ); |
173 | if (!m_pix && !g_stringPix.contains( m_path )) { | 165 | if (!m_pix && !g_stringPix.contains( m_path )) { |
174 | check_pix(); | 166 | check_pix(); |
175 | g_stringPix.insert( m_path, const_cast<IconViewItem*>(this)); | 167 | g_stringPix.insert( m_path, const_cast<IconViewItem*>(this)); |
176 | currentView()->dirLister()->thumbNail( m_path, m_iconsize, m_iconsize); | 168 | currentView()->dirLister()->thumbNail( m_path, m_iconsize, m_iconsize); |
177 | } | 169 | } |
178 | return m_pix ? m_pix : _cpyPix; | 170 | return m_pix ? m_pix : _cpyPix; |
179 | } | 171 | } |
180 | } | 172 | } |
181 | inline void IconViewItem::setText( const QString& str ) { | 173 | inline void IconViewItem::setText( const QString& str ) { |
182 | QString text = QIconViewItem::text()+"\n"+str; | 174 | QString text = QIconViewItem::text()+"\n"+str; |
183 | m_noInfo = true; | 175 | m_noInfo = true; |
184 | QIconViewItem::setText( text ); | 176 | QIconViewItem::setText( text ); |
185 | } | 177 | } |
186 | } | 178 | } |
187 | 179 | ||
188 | 180 | ||
189 | /* | 181 | /* |
190 | * Set up the GUI.. initialize the slave set up gui | 182 | * Set up the GUI.. initialize the slave set up gui |
191 | * and also load a dir | 183 | * and also load a dir |
192 | */ | 184 | */ |
193 | PIconView::PIconView( QWidget* wid, Opie::Core::OConfig* cfg ) | 185 | PIconView::PIconView( QWidget* wid, Opie::Core::OConfig* cfg ) |
194 | : QVBox( wid ), m_cfg( cfg ), m_updatet( false ) | 186 | : QVBox( wid ), m_cfg( cfg ), m_updatet( false ) |
195 | { | 187 | { |
196 | { | 188 | { |
197 | QCopEnvelope( "QPE/Application/opie-eye_slave", "refUp()" ); | 189 | QCopEnvelope( "QPE/Application/opie-eye_slave", "refUp()" ); |
198 | } | 190 | } |
199 | m_path = QDir::homeDirPath(); | 191 | m_path = QDir::homeDirPath(); |
200 | m_mode = 0; | 192 | m_mode = 0; |
201 | m_iconsize = 32; | 193 | m_iconsize = 32; |
202 | m_internalReset = false; | 194 | m_internalReset = false; |
203 | 195 | ||
204 | QHBox *hbox = new QHBox( this ); | 196 | QHBox *hbox = new QHBox( this ); |
205 | QLabel* lbl = new QLabel( hbox ); | 197 | QLabel* lbl = new QLabel( hbox ); |
206 | lbl->setText( tr("View as" ) ); | 198 | lbl->setText( tr("View as" ) ); |
207 | 199 | ||
208 | m_views = new QComboBox( hbox, "View As" ); | 200 | m_views = new QComboBox( hbox, "View As" ); |
209 | 201 | ||
210 | m_view= new QIconView( this ); | 202 | m_view= new QIconView( this ); |
211 | connect(m_view, SIGNAL(clicked(QIconViewItem*) ), | 203 | connect(m_view, SIGNAL(clicked(QIconViewItem*) ), |
212 | this, SLOT(slotClicked(QIconViewItem*)) ); | 204 | this, SLOT(slotClicked(QIconViewItem*)) ); |
213 | connect(m_view, SIGNAL(returnPressed(QIconViewItem*)), | 205 | connect(m_view, SIGNAL(returnPressed(QIconViewItem*)), |
214 | this, SLOT(slotClicked(QIconViewItem*)) ); | 206 | this, SLOT(slotClicked(QIconViewItem*)) ); |
215 | 207 | ||
216 | m_view->setArrangement( QIconView::LeftToRight ); | 208 | m_view->setArrangement( QIconView::LeftToRight ); |
217 | 209 | ||
218 | m_mode = m_cfg->readNumEntry("ListViewMode", 1); | 210 | m_mode = m_cfg->readNumEntry("ListViewMode", 1); |
219 | QString lastView = m_cfg->readEntry("LastView",""); | 211 | QString lastView = m_cfg->readEntry("LastView",""); |
220 | 212 | ||
221 | if (m_mode < 1 || m_mode>3) m_mode = 1; | 213 | if (m_mode < 1 || m_mode>3) m_mode = 1; |
222 | 214 | ||
223 | m_view->setItemTextPos( QIconView::Right ); | 215 | m_view->setItemTextPos( QIconView::Right ); |
224 | if (m_mode >1) { | 216 | if (m_mode >1) { |
225 | m_view->setResizeMode(QIconView::Adjust); | 217 | m_view->setResizeMode(QIconView::Adjust); |
226 | } else { | 218 | } else { |
227 | m_view->setResizeMode(QIconView::Fixed); | 219 | m_view->setResizeMode(QIconView::Fixed); |
228 | } | 220 | } |
229 | m_iconsize = m_cfg->readNumEntry("iconsize", 32); | 221 | m_iconsize = m_cfg->readNumEntry("iconsize", 32); |
230 | if (m_iconsize<12)m_iconsize = 12; | 222 | if (m_iconsize<12)m_iconsize = 12; |
231 | if (m_iconsize>64)m_iconsize = 64; | 223 | if (m_iconsize>64)m_iconsize = 64; |
232 | 224 | ||
233 | calculateGrid(); | 225 | calculateGrid(); |
234 | 226 | ||
235 | initKeys(); | 227 | initKeys(); |
236 | 228 | ||
237 | loadViews(); | 229 | loadViews(); |
238 | int cc=0; | 230 | int cc=0; |
239 | for (; cc<m_views->count();++cc) { | 231 | for (; cc<m_views->count();++cc) { |
240 | if (m_views->text(cc)==lastView) { | 232 | if (m_views->text(cc)==lastView) { |
241 | break; | 233 | break; |
242 | } | 234 | } |
243 | } | 235 | } |
244 | if (cc<m_views->count()) { | 236 | if (cc<m_views->count()) { |
245 | m_views->setCurrentItem(cc); | 237 | m_views->setCurrentItem(cc); |
246 | slotViewChanged(cc); | 238 | slotViewChanged(cc); |
247 | } else { | 239 | } else { |
248 | slotViewChanged(m_views->currentItem()); | 240 | slotViewChanged(m_views->currentItem()); |
249 | } | 241 | } |
250 | connect( m_views, SIGNAL(activated(int)), | 242 | connect( m_views, SIGNAL(activated(int)), |
251 | this, SLOT(slotViewChanged(int)) ); | 243 | this, SLOT(slotViewChanged(int)) ); |
252 | } | 244 | } |
253 | 245 | ||
254 | /* | 246 | /* |
255 | * Unref the slave and save the keyboard manager | 247 | * Unref the slave and save the keyboard manager |
256 | */ | 248 | */ |
257 | PIconView::~PIconView() { | 249 | PIconView::~PIconView() { |
258 | { | 250 | { |
259 | QCopEnvelope( "QPE/Application/opie-eye_slave", "refDown()" ); | 251 | QCopEnvelope( "QPE/Application/opie-eye_slave", "refDown()" ); |
260 | } | 252 | } |
261 | m_viewManager->save(); | 253 | m_viewManager->save(); |
262 | delete m_viewManager; | 254 | delete m_viewManager; |
263 | } | 255 | } |
264 | 256 | ||
265 | Opie::Core::OKeyConfigManager* PIconView::manager() { | 257 | Opie::Core::OKeyConfigManager* PIconView::manager() { |
266 | return m_viewManager; | 258 | return m_viewManager; |
267 | } | 259 | } |
268 | 260 | ||
269 | 261 | ||
270 | /* | 262 | /* |
271 | * init the KeyBoard Shortcuts | 263 | * init the KeyBoard Shortcuts |
272 | * called from the c'tor | 264 | * called from the c'tor |
273 | */ | 265 | */ |
274 | void PIconView::initKeys() { | 266 | void PIconView::initKeys() { |
275 | Opie::Core::OKeyPair::List lst; | 267 | Opie::Core::OKeyPair::List lst; |
276 | lst.append( Opie::Core::OKeyPair::upArrowKey() ); | 268 | lst.append( Opie::Core::OKeyPair::upArrowKey() ); |
277 | lst.append( Opie::Core::OKeyPair::downArrowKey() ); | 269 | lst.append( Opie::Core::OKeyPair::downArrowKey() ); |
278 | lst.append( Opie::Core::OKeyPair::leftArrowKey() ); | 270 | lst.append( Opie::Core::OKeyPair::leftArrowKey() ); |
279 | lst.append( Opie::Core::OKeyPair::rightArrowKey() ); | 271 | lst.append( Opie::Core::OKeyPair::rightArrowKey() ); |
280 | lst.append( Opie::Core::OKeyPair::returnKey() ); | 272 | lst.append( Opie::Core::OKeyPair::returnKey() ); |
281 | 273 | ||
282 | m_viewManager = new Opie::Core::OKeyConfigManager(m_cfg, "View-KeyBoard-Config", | 274 | m_viewManager = new Opie::Core::OKeyConfigManager(m_cfg, "View-KeyBoard-Config", |
283 | lst, false,this, "keyconfig name" ); | 275 | lst, false,this, "keyconfig name" ); |
284 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("Beam Current Item") , "beam", | 276 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("Beam Current Item") , "beam", |
285 | Resource::loadPixmap("beam"), BeamItem, | 277 | Resource::loadPixmap("beam"), BeamItem, |
286 | Opie::Core::OKeyPair(Qt::Key_B, Qt::ShiftButton), | 278 | Opie::Core::OKeyPair(Qt::Key_B, Qt::ShiftButton), |
287 | this, SLOT(slotBeam())) ); | 279 | this, SLOT(slotBeam())) ); |
288 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("Delete Current Item"), "delete", | 280 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("Delete Current Item"), "delete", |
289 | Resource::loadPixmap("trash"), DeleteItem, | 281 | Resource::loadPixmap("trash"), DeleteItem, |
290 | Opie::Core::OKeyPair(Qt::Key_D, Qt::ShiftButton), | 282 | Opie::Core::OKeyPair(Qt::Key_D, Qt::ShiftButton), |
291 | this, SLOT(slotTrash())) ); | 283 | this, SLOT(slotTrash())) ); |
292 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("View Current Item"), "view", | 284 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("View Current Item"), "view", |
293 | Resource::loadPixmap("1to1"), ViewItem, | 285 | Resource::loadPixmap("1to1"), ViewItem, |
294 | Opie::Core::OKeyPair(Qt::Key_V, Qt::ShiftButton), | 286 | Opie::Core::OKeyPair(Qt::Key_V, Qt::ShiftButton), |
295 | this, SLOT(slotShowImage()))); | 287 | this, SLOT(slotShowImage()))); |
296 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("Show Image Info") , "info", | 288 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("Show Image Info") , "info", |
297 | Resource::loadPixmap("DocumentTypeWord"), InfoItem, | 289 | Resource::loadPixmap("DocumentTypeWord"), InfoItem, |
298 | Opie::Core::OKeyPair(Qt::Key_I, Qt::ShiftButton ), | 290 | Opie::Core::OKeyPair(Qt::Key_I, Qt::ShiftButton ), |
299 | this, SLOT(slotImageInfo()) ) ); | 291 | this, SLOT(slotImageInfo()) ) ); |
300 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("Start slideshow"), "slideshow", | 292 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("Start slideshow"), "slideshow", |
301 | Resource::loadPixmap("1to1"), SlideItem, | 293 | Resource::loadPixmap("1to1"), SlideItem, |
302 | Opie::Core::OKeyPair(Qt::Key_S, Qt::ShiftButton), | 294 | Opie::Core::OKeyPair(Qt::Key_S, Qt::ShiftButton), |
303 | this, SLOT(slotStartSlide()))); | 295 | this, SLOT(slotStartSlide()))); |
304 | m_viewManager->load(); | 296 | m_viewManager->load(); |
305 | m_viewManager->handleWidget( m_view ); | 297 | m_viewManager->handleWidget( m_view ); |
306 | } | 298 | } |
307 | 299 | ||
308 | 300 | ||
309 | /* | 301 | /* |
310 | * change one dir up | 302 | * change one dir up |
311 | */ | 303 | */ |
312 | void PIconView::slotDirUp() | 304 | void PIconView::slotDirUp() |
313 | { | 305 | { |
314 | slotChangeDir( currentView()->dirLister()->dirUp( m_path ) ); | 306 | slotChangeDir( currentView()->dirLister()->dirUp( m_path ) ); |
315 | } | 307 | } |
316 | 308 | ||
317 | /* | 309 | /* |
318 | * change the dir | 310 | * change the dir |
319 | */ | 311 | */ |
320 | void PIconView::slotChangeDir(const QString& path) { | 312 | void PIconView::slotChangeDir(const QString& path) { |
321 | if ( !currentView() ) | 313 | if ( !currentView() ) |
322 | return; | 314 | return; |
323 | 315 | ||
324 | PDirLister *lister = currentView()->dirLister(); | 316 | PDirLister *lister = currentView()->dirLister(); |
325 | if (!lister ) | 317 | if (!lister ) |
326 | return; | 318 | return; |
327 | 319 | ||
328 | /* | 320 | /* |
329 | * Say what we want and take what we get | 321 | * Say what we want and take what we get |
330 | */ | 322 | */ |
331 | lister->setStartPath( path ); | 323 | lister->setStartPath( path ); |
332 | m_path = lister->currentPath(); | 324 | m_path = lister->currentPath(); |
333 | 325 | ||
334 | m_view->viewport()->setUpdatesEnabled( false ); | 326 | m_view->viewport()->setUpdatesEnabled( false ); |
335 | m_view->clear(); | 327 | m_view->clear(); |
336 | 328 | ||
337 | // Also invalidate the cache. We can't cancel the operations anyway | 329 | // Also invalidate the cache. We can't cancel the operations anyway |
338 | g_stringPix.clear(); | 330 | g_stringPix.clear(); |
339 | g_stringInf.clear(); | 331 | g_stringInf.clear(); |
340 | 332 | ||
341 | /* | 333 | /* |
342 | * add files and folders | 334 | * add files and folders |
343 | */ | 335 | */ |
344 | addFolders( lister->folders() ); | 336 | addFolders( lister->folders() ); |
345 | addFiles( lister->files() ); | 337 | addFiles( lister->files() ); |
346 | m_view->viewport()->setUpdatesEnabled( true ); | 338 | m_view->viewport()->setUpdatesEnabled( true ); |
347 | 339 | ||
348 | // looks ugly | 340 | // looks ugly |
349 | static_cast<QMainWindow*>(parent())->setCaption( QObject::tr("%1 - O View", "Name of the dir").arg( m_path ) ); | 341 | static_cast<QMainWindow*>(parent())->setCaption( QObject::tr("%1 - O View", "Name of the dir").arg( m_path ) ); |
350 | } | 342 | } |
351 | 343 | ||
352 | /** | 344 | /** |
353 | * get the current file name | 345 | * get the current file name |
354 | * @param isDir see if this is a dir or real file | 346 | * @param isDir see if this is a dir or real file |
355 | */ | 347 | */ |
356 | QString PIconView::currentFileName(bool &isDir)const { | 348 | QString PIconView::currentFileName(bool &isDir)const { |
357 | isDir = false; | 349 | isDir = false; |
358 | QIconViewItem* _it = m_view->currentItem(); | 350 | QIconViewItem* _it = m_view->currentItem(); |
359 | if ( !_it ) | 351 | if ( !_it ) |
360 | return QString::null; | 352 | return QString::null; |
361 | 353 | ||
362 | IconViewItem* it = static_cast<IconViewItem*>( _it ); | 354 | IconViewItem* it = static_cast<IconViewItem*>( _it ); |
363 | isDir = it->isDir(); | 355 | isDir = it->isDir(); |
364 | return it->path(); | 356 | return it->path(); |
365 | } | 357 | } |
366 | 358 | ||
367 | QString PIconView::nextFileName(bool &isDir)const | 359 | QString PIconView::nextFileName(bool &isDir)const |
368 | { | 360 | { |
369 | isDir = false; | 361 | isDir = false; |
370 | QIconViewItem* _it1 = m_view->currentItem(); | 362 | QIconViewItem* _it1 = m_view->currentItem(); |
371 | if ( !_it1 ) | 363 | if ( !_it1 ) |
372 | return QString::null; | 364 | return QString::null; |
373 | QIconViewItem* _it = _it1->nextItem(); | 365 | QIconViewItem* _it = _it1->nextItem(); |
374 | if ( !_it ) | 366 | if ( !_it ) |
375 | return QString::null; | 367 | return QString::null; |
376 | IconViewItem* it = static_cast<IconViewItem*>( _it ); | 368 | IconViewItem* it = static_cast<IconViewItem*>( _it ); |
377 | isDir = it->isDir(); | 369 | isDir = it->isDir(); |
378 | return it->path(); | 370 | return it->path(); |
379 | } | 371 | } |
380 | 372 | ||
381 | QString PIconView::prevFileName(bool &isDir)const{ | 373 | QString PIconView::prevFileName(bool &isDir)const{ |
382 | isDir = false; | 374 | isDir = false; |
383 | QIconViewItem* _it = m_view->currentItem(); | 375 | QIconViewItem* _it = m_view->currentItem(); |
384 | if ( !_it ) | 376 | if ( !_it ) |
385 | return QString::null; | 377 | return QString::null; |
386 | _it = _it->prevItem(); | 378 | _it = _it->prevItem(); |
387 | if ( !_it ) | 379 | if ( !_it ) |
388 | return QString::null; | 380 | return QString::null; |
389 | IconViewItem* it = static_cast<IconViewItem*>( _it ); | 381 | IconViewItem* it = static_cast<IconViewItem*>( _it ); |
390 | isDir = it->isDir(); | 382 | isDir = it->isDir(); |
391 | return it->path(); | 383 | return it->path(); |
392 | } | 384 | } |
393 | 385 | ||
394 | void PIconView::slotTrash() { | 386 | void PIconView::slotTrash() { |
395 | bool isDir; | 387 | bool isDir; |
396 | QString pa = currentFileName( isDir ); | 388 | QString pa = currentFileName( isDir ); |
397 | if ( isDir && pa.isEmpty() ) | 389 | if ( isDir && pa.isEmpty() ) |
398 | return; | 390 | return; |
399 | 391 | ||
400 | if (!QPEMessageBox::confirmDelete( this, | 392 | if (!QPEMessageBox::confirmDelete( this, |
401 | tr("Delete Image" ), | 393 | tr("Delete Image" ), |
402 | tr("the Image %1" ).arg(pa))) | 394 | tr("the Image %1" ).arg(pa))) |
403 | return | 395 | return |
404 | 396 | ||
405 | 397 | ||
406 | currentView()->dirLister()->deleteImage( pa ); | 398 | currentView()->dirLister()->deleteImage( pa ); |
407 | delete m_view->currentItem(); | 399 | delete m_view->currentItem(); |
408 | } | 400 | } |
409 | 401 | ||
410 | /* | 402 | /* |
411 | * see what views are available | 403 | * see what views are available |
412 | */ | 404 | */ |
413 | void PIconView::loadViews() { | 405 | void PIconView::loadViews() { |
414 | ViewMap::Iterator it; | 406 | ViewMap::Iterator it; |
415 | ViewMap* map = viewMap(); | 407 | ViewMap* map = viewMap(); |
416 | for ( it = map->begin(); it != map->end(); ++it ) | 408 | for ( it = map->begin(); it != map->end(); ++it ) |
417 | m_views->insertItem( it.key() ); | 409 | m_views->insertItem( it.key() ); |
418 | } | 410 | } |
419 | 411 | ||
420 | void PIconView::resetView() { | 412 | void PIconView::resetView() { |
421 | m_internalReset = true; | 413 | m_internalReset = true; |
422 | // Also invalidate the cache. We can't cancel the operations anyway | 414 | // Also invalidate the cache. We can't cancel the operations anyway |
423 | g_stringPix.clear(); | 415 | g_stringPix.clear(); |
424 | g_stringInf.clear(); | 416 | g_stringInf.clear(); |
425 | if (m_mode>1) { | 417 | if (m_mode>1) { |
418 | int osize = m_iconsize; | ||
426 | m_iconsize = m_cfg->readNumEntry("iconsize", 32); | 419 | m_iconsize = m_cfg->readNumEntry("iconsize", 32); |
427 | if (m_iconsize<12)m_iconsize = 12; | 420 | if (m_iconsize<12)m_iconsize = 12; |
428 | if (m_iconsize>64)m_iconsize = 64; | 421 | if (m_iconsize>64)m_iconsize = 64; |
422 | if (osize != m_iconsize) { | ||
423 | if (_dirPix){ | ||
424 | delete _dirPix; | ||
425 | _dirPix = 0; | ||
426 | } | ||
427 | if (_cpyPix){ | ||
428 | delete _cpyPix; | ||
429 | _cpyPix = 0; | ||
430 | } | ||
431 | calculateGrid(); | ||
432 | } | ||
429 | } else { | 433 | } else { |
430 | m_iconsize = 64; | 434 | m_iconsize = 64; |
431 | } | 435 | } |
432 | slotViewChanged(m_views->currentItem()); | 436 | slotViewChanged(m_views->currentItem()); |
433 | m_internalReset = false; | 437 | m_internalReset = false; |
434 | } | 438 | } |
435 | 439 | ||
436 | /* | 440 | /* |
437 | *swicth view reloadDir and connect signals | 441 | *swicth view reloadDir and connect signals |
438 | */ | 442 | */ |
439 | void PIconView::slotViewChanged( int i) { | 443 | void PIconView::slotViewChanged( int i) { |
440 | if (!m_views->count() ) { | 444 | if (!m_views->count() ) { |
441 | setCurrentView( 0l); | 445 | setCurrentView( 0l); |
442 | return; | 446 | return; |
443 | } | 447 | } |
444 | 448 | ||
445 | PDirView* cur = currentView(); | 449 | PDirView* cur = currentView(); |
446 | if (cur) delete cur; | 450 | if (cur) delete cur; |
447 | QString str = m_views->text(i); | 451 | QString str = m_views->text(i); |
448 | ViewMap* map = viewMap(); | 452 | ViewMap* map = viewMap(); |
449 | if (!map) { | 453 | if (!map) { |
450 | setCurrentView(0l); | 454 | setCurrentView(0l); |
451 | return; | 455 | return; |
452 | } | 456 | } |
453 | 457 | ||
454 | if (map->find(str) == map->end()) { | 458 | if (map->find(str) == map->end()) { |
455 | owarn << "Key not found" << oendl; | 459 | owarn << "Key not found" << oendl; |
456 | setCurrentView(0l); | 460 | setCurrentView(0l); |
457 | return; | 461 | return; |
458 | } | 462 | } |
459 | 463 | ||
460 | m_cfg->writeEntry("LastView",str); | 464 | m_cfg->writeEntry("LastView",str); |
461 | m_cfg->write(); | 465 | m_cfg->write(); |
462 | cur = (*(*map)[str])(*m_cfg); | 466 | cur = (*(*map)[str])(*m_cfg); |
463 | setCurrentView( cur ); | 467 | setCurrentView( cur ); |
464 | 468 | ||
465 | /* connect to the signals of the lister */ | 469 | /* connect to the signals of the lister */ |
466 | PDirLister* lis = cur->dirLister(); | 470 | PDirLister* lis = cur->dirLister(); |
467 | connect(lis, SIGNAL(sig_thumbInfo(const QString&, const QString& )), | 471 | connect(lis, SIGNAL(sig_thumbInfo(const QString&, const QString& )), |
468 | this, SLOT( slotThumbInfo(const QString&, const QString&))); | 472 | this, SLOT( slotThumbInfo(const QString&, const QString&))); |
469 | connect(lis, SIGNAL( sig_thumbNail(const QString&, const QPixmap&)), | 473 | connect(lis, SIGNAL( sig_thumbNail(const QString&, const QPixmap&)), |
470 | this, SLOT(slotThumbNail(const QString&, const QPixmap&))); | 474 | this, SLOT(slotThumbNail(const QString&, const QPixmap&))); |
471 | connect(lis, SIGNAL(sig_start()), | 475 | connect(lis, SIGNAL(sig_start()), |
472 | this, SLOT(slotStart())); | 476 | this, SLOT(slotStart())); |
473 | connect(lis, SIGNAL(sig_end()) , | 477 | connect(lis, SIGNAL(sig_end()) , |
474 | this, SLOT(slotEnd()) ); | 478 | this, SLOT(slotEnd()) ); |
475 | 479 | ||
476 | 480 | ||
477 | /* reload now with default Path | 481 | /* reload now with default Path |
478 | * but only if it isn't a reset like from setupdlg | 482 | * but only if it isn't a reset like from setupdlg |
479 | */ | 483 | */ |
480 | if (!m_internalReset) { | 484 | if (!m_internalReset) { |
481 | m_path = lis->defaultPath(); | 485 | m_path = lis->defaultPath(); |
482 | } | 486 | } |
483 | QTimer::singleShot( 0, this, SLOT(slotReloadDir())); | 487 | QTimer::singleShot( 0, this, SLOT(slotReloadDir())); |
484 | } | 488 | } |
485 | 489 | ||
486 | 490 | ||
487 | void PIconView::slotReloadDir() { | 491 | void PIconView::slotReloadDir() { |
488 | slotChangeDir( m_path ); | 492 | slotChangeDir( m_path ); |
489 | } | 493 | } |
490 | 494 | ||
491 | 495 | ||
492 | /* | 496 | /* |
493 | * add files and folders | 497 | * add files and folders |
494 | */ | 498 | */ |
495 | void PIconView::addFolders( const QStringList& lst) { | 499 | void PIconView::addFolders( const QStringList& lst) { |
496 | QStringList::ConstIterator it; | 500 | QStringList::ConstIterator it; |
497 | IconViewItem * _iv; | 501 | IconViewItem * _iv; |
498 | 502 | ||
499 | for(it=lst.begin(); it != lst.end(); ++it ) { | 503 | for(it=lst.begin(); it != lst.end(); ++it ) { |
500 | _iv = new IconViewItem( m_view, m_path+"/"+(*it), (*it),m_iconsize, true ); | 504 | _iv = new IconViewItem( m_view, m_path+"/"+(*it), (*it),m_iconsize, true ); |
501 | if (m_mode==3) _iv->setTextOnly(true); | 505 | if (m_mode==3) _iv->setTextOnly(true); |
502 | } | 506 | } |
503 | } | 507 | } |
504 | 508 | ||
505 | void PIconView::addFiles( const QStringList& lst) { | 509 | void PIconView::addFiles( const QStringList& lst) { |
506 | QStringList::ConstIterator it; | 510 | QStringList::ConstIterator it; |
507 | IconViewItem * _iv; | 511 | IconViewItem * _iv; |
508 | QPixmap*m_pix = 0; | 512 | QPixmap*m_pix = 0; |
509 | QString pre = ""; | 513 | QString pre = ""; |
510 | if (!m_path.isEmpty()) { | 514 | if (!m_path.isEmpty()) { |
511 | pre = m_path+"/"; | 515 | pre = m_path+"/"; |
512 | } | 516 | } |
513 | for (it=lst.begin(); it!= lst.end(); ++it ) { | 517 | for (it=lst.begin(); it!= lst.end(); ++it ) { |
514 | m_pix = PPixmapCache::self()->cachedImage( pre+(*it), m_iconsize, m_iconsize ); | 518 | m_pix = PPixmapCache::self()->cachedImage( pre+(*it), m_iconsize, m_iconsize ); |
515 | _iv = new IconViewItem( m_view, pre+(*it), (*it),m_iconsize ); | 519 | _iv = new IconViewItem( m_view, pre+(*it), (*it),m_iconsize ); |
516 | if (m_mode==3) { | 520 | if (m_mode==3) { |
517 | _iv->setTextOnly(true); | 521 | _iv->setTextOnly(true); |
518 | _iv->setPixmap(QPixmap()); | 522 | _iv->setPixmap(QPixmap()); |
519 | 523 | ||
520 | 524 | ||
521 | 525 | ||
522 | } else { | 526 | } else { |
523 | if (m_pix) _iv->setPixmap(*m_pix); | 527 | if (m_pix) _iv->setPixmap(*m_pix); |
524 | } | 528 | } |
525 | } | 529 | } |
526 | 530 | ||
527 | } | 531 | } |
528 | 532 | ||
529 | /* | 533 | /* |
530 | * user clicked on the item. Change dir or view | 534 | * user clicked on the item. Change dir or view |
531 | */ | 535 | */ |
532 | void PIconView::slotClicked(QIconViewItem* _it) { | 536 | void PIconView::slotClicked(QIconViewItem* _it) { |
533 | if(!_it ) | 537 | if(!_it ) |
534 | return; | 538 | return; |
535 | 539 | ||
536 | IconViewItem* it = static_cast<IconViewItem*>(_it); | 540 | IconViewItem* it = static_cast<IconViewItem*>(_it); |
537 | if( it->isDir() ) | 541 | if( it->isDir() ) |
538 | slotChangeDir( it->path() ); | 542 | slotChangeDir( it->path() ); |
539 | else // view image | 543 | else // view image |
540 | slotShowImage(); | 544 | slotShowImage(); |
541 | } | 545 | } |
542 | 546 | ||
543 | /* | 547 | /* |
544 | * Return was pressed. which is triggered by the keydown | 548 | * Return was pressed. which is triggered by the keydown |
545 | * handler. The problem is that the key up will be handled | 549 | * handler. The problem is that the key up will be handled |
546 | * by the ImageDisplayer and goes to the next image | 550 | * by the ImageDisplayer and goes to the next image |
547 | */ | 551 | */ |
548 | void PIconView::slotRetrun( QIconViewItem *_it ) { | 552 | void PIconView::slotRetrun( QIconViewItem *_it ) { |
549 | if(!_it ) | 553 | if(!_it ) |
550 | return; | 554 | return; |
551 | 555 | ||
552 | IconViewItem* it = static_cast<IconViewItem*>(_it); | 556 | IconViewItem* it = static_cast<IconViewItem*>(_it); |
553 | if( it->isDir() ) | 557 | if( it->isDir() ) |
554 | slotChangeDir( it->path() ); | 558 | slotChangeDir( it->path() ); |
555 | else | 559 | else |
556 | QTimer::singleShot(0, this, SLOT(slotShowImage()) ); | 560 | QTimer::singleShot(0, this, SLOT(slotShowImage()) ); |
557 | } | 561 | } |
558 | 562 | ||
559 | /* | 563 | /* |
560 | * got thumb info add to the cache if items is visible | 564 | * got thumb info add to the cache if items is visible |
561 | * we later need update after processing of slave is done | 565 | * we later need update after processing of slave is done |
562 | */ | 566 | */ |
563 | void PIconView::slotThumbInfo( const QString& _path, const QString& str ) { | 567 | void PIconView::slotThumbInfo( const QString& _path, const QString& str ) { |
564 | IconViewItem* item = g_stringInf[_path]; | 568 | IconViewItem* item = g_stringInf[_path]; |
565 | if (!item ) | 569 | if (!item ) |
566 | return; | 570 | return; |
567 | 571 | ||
568 | if (m_mode == 2) { | 572 | if (m_mode == 2) { |
569 | return; | 573 | return; |
570 | } | 574 | } |
571 | if ( item->intersects(QRect( m_view->contentsX(),m_view->contentsY(), | 575 | if ( item->intersects(QRect( m_view->contentsX(),m_view->contentsY(), |
572 | m_view->contentsWidth(), m_view->contentsHeight() ) ) ) | 576 | m_view->contentsWidth(), m_view->contentsHeight() ) ) ) |
573 | m_updatet = true; | 577 | m_updatet = true; |
574 | 578 | ||
575 | item->setText( str ); | 579 | item->setText( str ); |
576 | g_stringInf.remove( _path ); | 580 | g_stringInf.remove( _path ); |
577 | } | 581 | } |
578 | 582 | ||
579 | /* | 583 | /* |
580 | * got thumbnail and see if it is visible so we need to update later | 584 | * got thumbnail and see if it is visible so we need to update later |
581 | */ | 585 | */ |
582 | void PIconView::slotThumbNail(const QString& _path, const QPixmap &pix) { | 586 | void PIconView::slotThumbNail(const QString& _path, const QPixmap &pix) { |
583 | IconViewItem* item = g_stringPix[_path]; | 587 | IconViewItem* item = g_stringPix[_path]; |
584 | if (!item ) | 588 | if (!item ) |
585 | return; | 589 | return; |
586 | 590 | ||
587 | if ( item->intersects(QRect( m_view->contentsX(),m_view->contentsY(), | 591 | if ( item->intersects(QRect( m_view->contentsX(),m_view->contentsY(), |
588 | m_view->contentsWidth(), m_view->contentsHeight() ) ) ) | 592 | m_view->contentsWidth(), m_view->contentsHeight() ) ) ) |
589 | m_updatet = true; | 593 | m_updatet = true; |
590 | 594 | ||
591 | if (pix.width()>0) { | 595 | if (pix.width()>0) { |
592 | if (pix.width()<m_iconsize) { | 596 | if (pix.width()<m_iconsize) { |
593 | QPixmap p(m_iconsize,m_iconsize); | 597 | QPixmap p(m_iconsize,m_iconsize); |
594 | p.fill(); | 598 | p.fill(); |
595 | QPainter pa(&p); | 599 | QPainter pa(&p); |
596 | int offset = (m_iconsize-pix.width())/2; | 600 | int offset = (m_iconsize-pix.width())/2; |
597 | int offy = (m_iconsize-pix.height())/2; | 601 | int offy = (m_iconsize-pix.height())/2; |
598 | if (offy<0) offy=0; | 602 | if (offy<0) offy=0; |
599 | pa.drawPixmap(offset,offy,pix); | 603 | pa.drawPixmap(offset,offy,pix); |
600 | pa.end(); | 604 | pa.end(); |
601 | PPixmapCache::self()->insertImage( _path, p, m_iconsize, m_iconsize ); | 605 | PPixmapCache::self()->insertImage( _path, p, m_iconsize, m_iconsize ); |
602 | item->setPixmap(p,true); | 606 | item->setPixmap(p,true); |
603 | } else { | 607 | } else { |
604 | PPixmapCache::self()->insertImage( _path, pix, m_iconsize, m_iconsize ); | 608 | PPixmapCache::self()->insertImage( _path, pix, m_iconsize, m_iconsize ); |
605 | item->setPixmap(pix,true); | 609 | item->setPixmap(pix,true); |
606 | } | 610 | } |
607 | 611 | ||
608 | } else { | 612 | } else { |
609 | PPixmapCache::self()->insertImage( _path, Resource::loadPixmap( "UnknownDocument" ), m_iconsize, m_iconsize ); | 613 | PPixmapCache::self()->insertImage( _path, Resource::loadPixmap( "UnknownDocument" ), m_iconsize, m_iconsize ); |
610 | } | 614 | } |
611 | g_stringPix.remove( _path ); | 615 | g_stringPix.remove( _path ); |
612 | m_view->arrangeItemsInGrid(true); | 616 | m_view->arrangeItemsInGrid(true); |
613 | } | 617 | } |
614 | 618 | ||
615 | 619 | ||
616 | /* | 620 | /* |
617 | * FIXME rename | 621 | * FIXME rename |
618 | */ | 622 | */ |
619 | void PIconView::slotRename() { | 623 | void PIconView::slotRename() { |
620 | 624 | ||
621 | } | 625 | } |
622 | 626 | ||
623 | 627 | ||
624 | /* | 628 | /* |
625 | * BEAM the current file | 629 | * BEAM the current file |
626 | */ | 630 | */ |
627 | void PIconView::slotBeam() { | 631 | void PIconView::slotBeam() { |
628 | bool isDir; | 632 | bool isDir; |
629 | QString pa = currentFileName( isDir ); | 633 | QString pa = currentFileName( isDir ); |
630 | if ( isDir && pa.isEmpty() ) | 634 | if ( isDir && pa.isEmpty() ) |
631 | return; | 635 | return; |
632 | 636 | ||
633 | Ir* ir = new Ir( this ); | 637 | Ir* ir = new Ir( this ); |
634 | connect( ir, SIGNAL(done(Ir*)), | 638 | connect( ir, SIGNAL(done(Ir*)), |
635 | this, SLOT(slotBeamDone(Ir*))); | 639 | this, SLOT(slotBeamDone(Ir*))); |
636 | ir->send(pa, tr( "Image" ) ); | 640 | ir->send(pa, tr( "Image" ) ); |
637 | } | 641 | } |
638 | 642 | ||
639 | /* | 643 | /* |
640 | * BEAM done clean up | 644 | * BEAM done clean up |
641 | */ | 645 | */ |
642 | void PIconView::slotBeamDone( Ir* ir) { | 646 | void PIconView::slotBeamDone( Ir* ir) { |
643 | delete ir; | 647 | delete ir; |
644 | } | 648 | } |
645 | 649 | ||
646 | void PIconView::slotStart() { | 650 | void PIconView::slotStart() { |
647 | m_view->viewport()->setUpdatesEnabled( false ); | 651 | m_view->viewport()->setUpdatesEnabled( false ); |
648 | } | 652 | } |
649 | 653 | ||
650 | void PIconView::slotEnd() { | 654 | void PIconView::slotEnd() { |
651 | if ( m_updatet ) | 655 | if ( m_updatet ) |
652 | m_view->arrangeItemsInGrid( ); | 656 | m_view->arrangeItemsInGrid( ); |
653 | m_view->viewport()->setUpdatesEnabled( true ); | 657 | m_view->viewport()->setUpdatesEnabled( true ); |
654 | m_updatet = false; | 658 | m_updatet = false; |
655 | } | 659 | } |
656 | 660 | ||
657 | void PIconView::slotShowLast() | 661 | void PIconView::slotShowLast() |
658 | { | 662 | { |
659 | QIconViewItem* last_it = m_view->lastItem(); | 663 | QIconViewItem* last_it = m_view->lastItem(); |
660 | if (!last_it) return; | 664 | if (!last_it) return; |
661 | m_view->setCurrentItem(last_it); | 665 | m_view->setCurrentItem(last_it); |
662 | IconViewItem* it = static_cast<IconViewItem*>( last_it ); | 666 | IconViewItem* it = static_cast<IconViewItem*>( last_it ); |
663 | bool isDir = it->isDir(); | 667 | bool isDir = it->isDir(); |
664 | QString name = it->path(); | 668 | QString name = it->path(); |
665 | if (!isDir && !name.isEmpty()) { | 669 | if (!isDir && !name.isEmpty()) { |
666 | slotShowImage(name); | 670 | slotShowImage(name); |
667 | return; | 671 | return; |
668 | } | 672 | } |
669 | bool first_loop = true; | 673 | bool first_loop = true; |
670 | while(isDir==true) { | 674 | while(isDir==true) { |
671 | if (!first_loop) { | 675 | if (!first_loop) { |
672 | m_view->setCurrentItem(m_view->currentItem()->prevItem()); | 676 | m_view->setCurrentItem(m_view->currentItem()->prevItem()); |
673 | } else { | 677 | } else { |
674 | first_loop = false; | 678 | first_loop = false; |
675 | } | 679 | } |
676 | name = prevFileName(isDir); | 680 | name = prevFileName(isDir); |
677 | } | 681 | } |
678 | 682 | ||
679 | if (name.isEmpty()) return; | 683 | if (name.isEmpty()) return; |
680 | /* if we got a name we have a prev item */ | 684 | /* if we got a name we have a prev item */ |
681 | m_view->setCurrentItem(m_view->currentItem()->prevItem()); | 685 | m_view->setCurrentItem(m_view->currentItem()->prevItem()); |
682 | slotShowImage(name); | 686 | slotShowImage(name); |
683 | } | 687 | } |
684 | 688 | ||
685 | bool PIconView::slotShowFirst() | 689 | bool PIconView::slotShowFirst() |
686 | { | 690 | { |
687 | /* stop when reached - otherwise we may get an endless loop */ | 691 | /* stop when reached - otherwise we may get an endless loop */ |
688 | QIconViewItem* first_it = m_view->firstItem(); | 692 | QIconViewItem* first_it = m_view->firstItem(); |
689 | if (!first_it) return false; | 693 | if (!first_it) return false; |
690 | m_view->setCurrentItem(first_it); | 694 | m_view->setCurrentItem(first_it); |
691 | IconViewItem* it = static_cast<IconViewItem*>( first_it ); | 695 | IconViewItem* it = static_cast<IconViewItem*>( first_it ); |
692 | bool isDir = it->isDir(); | 696 | bool isDir = it->isDir(); |
693 | QString name = it->path(); | 697 | QString name = it->path(); |
694 | if (!isDir && !name.isEmpty()) { | 698 | if (!isDir && !name.isEmpty()) { |
695 | slotShowImage(name); | 699 | slotShowImage(name); |
696 | return false; | 700 | return false; |
697 | } | 701 | } |
698 | bool first_loop = true; | 702 | bool first_loop = true; |
699 | while(isDir==true) { | 703 | while(isDir==true) { |
700 | /* if name is empty isDir is false, too. */ | 704 | /* if name is empty isDir is false, too. */ |
701 | if (!first_loop) { | 705 | if (!first_loop) { |
702 | m_view->setCurrentItem(m_view->currentItem()->nextItem()); | 706 | m_view->setCurrentItem(m_view->currentItem()->nextItem()); |
703 | } else { | 707 | } else { |
704 | first_loop = false; | 708 | first_loop = false; |
705 | } | 709 | } |
706 | name = nextFileName(isDir); | 710 | name = nextFileName(isDir); |
707 | } | 711 | } |
708 | if (name.isEmpty()) return false; | 712 | if (name.isEmpty()) return false; |
709 | /* if we got a name we have a next item */ | 713 | /* if we got a name we have a next item */ |
710 | m_view->setCurrentItem(m_view->currentItem()->nextItem()); | 714 | m_view->setCurrentItem(m_view->currentItem()->nextItem()); |
711 | slotShowImage(name); | 715 | slotShowImage(name); |
712 | return true; | 716 | return true; |
713 | } | 717 | } |
714 | 718 | ||
715 | void PIconView::slotShowNext() | 719 | void PIconView::slotShowNext() |
716 | { | 720 | { |
717 | bool isDir = false; | 721 | bool isDir = false; |
718 | QString name = nextFileName(isDir); | 722 | QString name = nextFileName(isDir); |
719 | while (isDir==true) { | 723 | while (isDir==true) { |
720 | m_view->setCurrentItem(m_view->currentItem()->nextItem()); | 724 | m_view->setCurrentItem(m_view->currentItem()->nextItem()); |
721 | name = nextFileName(isDir); | 725 | name = nextFileName(isDir); |
722 | } | 726 | } |
723 | if (name.isEmpty()) { | 727 | if (name.isEmpty()) { |
724 | slotShowFirst(); | 728 | slotShowFirst(); |
725 | return; | 729 | return; |
726 | } | 730 | } |
727 | if (isDir) return; | 731 | if (isDir) return; |
728 | /* if we got a name we have a next item */ | 732 | /* if we got a name we have a next item */ |
729 | m_view->setCurrentItem(m_view->currentItem()->nextItem()); | 733 | m_view->setCurrentItem(m_view->currentItem()->nextItem()); |
730 | slotShowImage(name); | 734 | slotShowImage(name); |
731 | } | 735 | } |
732 | 736 | ||
733 | void PIconView::slotShowPrev() | 737 | void PIconView::slotShowPrev() |
734 | { | 738 | { |
735 | bool isDir = false; | 739 | bool isDir = false; |
736 | QString name = prevFileName(isDir); | 740 | QString name = prevFileName(isDir); |
737 | while (isDir==true) { | 741 | while (isDir==true) { |
738 | /* if name is empty isDir is false, too. */ | 742 | /* if name is empty isDir is false, too. */ |
739 | m_view->setCurrentItem(m_view->currentItem()->prevItem()); | 743 | m_view->setCurrentItem(m_view->currentItem()->prevItem()); |
740 | name = prevFileName(isDir); | 744 | name = prevFileName(isDir); |
741 | } | 745 | } |
742 | if (name.isEmpty()) { | 746 | if (name.isEmpty()) { |
743 | slotShowLast(); | 747 | slotShowLast(); |
744 | return; | 748 | return; |
745 | } | 749 | } |
746 | if (isDir) return; | 750 | if (isDir) return; |
747 | /* if we got a name we have a prev item */ | 751 | /* if we got a name we have a prev item */ |
748 | m_view->setCurrentItem(m_view->currentItem()->prevItem()); | 752 | m_view->setCurrentItem(m_view->currentItem()->prevItem()); |
749 | slotShowImage(name); | 753 | slotShowImage(name); |
750 | } | 754 | } |
751 | 755 | ||
752 | void PIconView::slotShowImage() | 756 | void PIconView::slotShowImage() |
753 | { | 757 | { |
754 | bool isDir = false; | 758 | bool isDir = false; |
755 | QString name = currentFileName(isDir); | 759 | QString name = currentFileName(isDir); |
756 | if (isDir) return; | 760 | if (isDir) return; |
757 | slotShowImage( name ); | 761 | slotShowImage( name ); |
758 | } | 762 | } |
759 | void PIconView::slotShowImage( const QString& name) { | 763 | void PIconView::slotShowImage( const QString& name) { |
760 | PDirLister *lister = currentView()->dirLister(); | 764 | PDirLister *lister = currentView()->dirLister(); |
761 | QString r_name = lister->nameToFname(name); | 765 | QString r_name = lister->nameToFname(name); |
762 | emit sig_display(r_name); | 766 | emit sig_display(r_name); |
763 | } | 767 | } |
764 | 768 | ||
765 | void PIconView::slotStartSlide() { | 769 | void PIconView::slotStartSlide() { |
766 | bool isDir = false; | 770 | bool isDir = false; |
767 | QString name = currentFileName(isDir); | 771 | QString name = currentFileName(isDir); |
768 | if (isDir) { | 772 | if (isDir) { |
769 | if (!slotShowFirst()) | 773 | if (!slotShowFirst()) |
770 | return; | 774 | return; |
771 | } else { | 775 | } else { |
772 | slotShowImage( name ); | 776 | slotShowImage( name ); |
773 | } | 777 | } |
774 | int t = m_cfg->readNumEntry("slideshowtimeout", 2); | 778 | int t = m_cfg->readNumEntry("slideshowtimeout", 2); |
775 | emit sig_startslide(t); | 779 | emit sig_startslide(t); |
776 | } | 780 | } |
777 | 781 | ||
778 | void PIconView::slotImageInfo() { | 782 | void PIconView::slotImageInfo() { |
779 | bool isDir = false; | 783 | bool isDir = false; |
780 | QString name = currentFileName(isDir); | 784 | QString name = currentFileName(isDir); |
781 | if (isDir) return; | 785 | if (isDir) return; |
782 | slotImageInfo( name ); | 786 | slotImageInfo( name ); |
783 | } | 787 | } |
784 | 788 | ||
785 | void PIconView::slotImageInfo( const QString& name) { | 789 | void PIconView::slotImageInfo( const QString& name) { |
786 | PDirLister *lister = currentView()->dirLister(); | 790 | PDirLister *lister = currentView()->dirLister(); |
787 | QString r_name = lister->nameToFname(name); | 791 | QString r_name = lister->nameToFname(name); |
788 | emit sig_showInfo(r_name ); | 792 | emit sig_showInfo(r_name ); |
789 | } | 793 | } |
790 | 794 | ||
791 | 795 | ||
792 | void PIconView::slotChangeMode( int mode ) { | 796 | void PIconView::slotChangeMode( int mode ) { |
793 | if ( mode >= 1 && mode <= 3 ) { | 797 | if ( mode >= 1 && mode <= 3 ) { |
794 | m_mode = mode; | 798 | m_mode = mode; |
795 | m_cfg->writeEntry("ListViewMode", m_mode); | 799 | m_cfg->writeEntry("ListViewMode", m_mode); |
796 | /* performance! */ | 800 | /* performance! */ |
797 | m_view->clear(); | 801 | m_view->clear(); |
798 | if (m_mode >1) { | 802 | if (m_mode >1) { |
799 | m_view->setResizeMode(QIconView::Adjust); | 803 | m_view->setResizeMode(QIconView::Adjust); |
800 | } else { | 804 | } else { |
801 | m_view->setResizeMode(QIconView::Fixed); | 805 | m_view->setResizeMode(QIconView::Fixed); |
802 | } | 806 | } |
803 | if (m_mode==1) { | 807 | if (m_mode==1) { |
804 | m_iconsize = 64; | 808 | m_iconsize = 64; |
805 | } else { | 809 | } else { |
806 | m_iconsize = m_cfg->readNumEntry("iconsize", 32); | 810 | m_iconsize = m_cfg->readNumEntry("iconsize", 32); |
807 | if (m_iconsize<12)m_iconsize = 12; | 811 | if (m_iconsize<12)m_iconsize = 12; |
808 | if (m_iconsize>64)m_iconsize = 64; | 812 | if (m_iconsize>64)m_iconsize = 64; |
809 | } | 813 | } |
810 | 814 | if (_dirPix){ | |
815 | delete _dirPix; | ||
816 | _dirPix = 0; | ||
817 | } | ||
818 | if (_cpyPix){ | ||
819 | delete _cpyPix; | ||
820 | _cpyPix = 0; | ||
821 | } | ||
811 | calculateGrid(); | 822 | calculateGrid(); |
812 | slotReloadDir(); | 823 | slotReloadDir(); |
813 | } | 824 | } |
814 | } | 825 | } |
815 | 826 | ||
816 | 827 | ||
817 | void PIconView::resizeEvent( QResizeEvent* re ) { | 828 | void PIconView::resizeEvent( QResizeEvent* re ) { |
818 | calculateGrid(re); | 829 | calculateGrid(re); |
819 | QVBox::resizeEvent( re ); | 830 | QVBox::resizeEvent( re ); |
820 | //calculateGrid(); | 831 | //calculateGrid(); |
821 | } | 832 | } |
822 | 833 | ||
823 | 834 | ||
824 | void PIconView::calculateGrid(QResizeEvent* re) | 835 | void PIconView::calculateGrid(QResizeEvent* re) |
825 | { | 836 | { |
826 | int viewerWidth; | 837 | int viewerWidth; |
827 | if (re) { | 838 | if (re) { |
828 | viewerWidth=re->size().width(); | 839 | viewerWidth=re->size().width(); |
829 | } else { | 840 | } else { |
830 | int dw = QApplication::desktop()->width(); | 841 | int dw = QApplication::desktop()->width(); |
831 | viewerWidth = dw-style().scrollBarExtent().width(); | 842 | viewerWidth = dw-style().scrollBarExtent().width(); |
832 | } | 843 | } |
833 | 844 | ||
834 | QIconView::ItemTextPos pos; | 845 | QIconView::ItemTextPos pos; |
835 | switch( m_mode ) { | 846 | switch( m_mode ) { |
836 | case 2: | 847 | case 2: |
837 | pos = QIconView::Bottom; | 848 | pos = QIconView::Bottom; |
838 | break; | 849 | break; |
839 | case 3: | 850 | case 3: |
840 | case 1: | 851 | case 1: |
841 | default: | 852 | default: |
842 | pos = QIconView::Right; | 853 | pos = QIconView::Right; |
843 | break; | 854 | break; |
844 | } | 855 | } |
856 | int cache = 0; | ||
845 | m_view->setItemTextPos( pos ); | 857 | m_view->setItemTextPos( pos ); |
846 | switch (m_mode) { | 858 | switch (m_mode) { |
847 | case 2: | 859 | case 2: |
860 | m_view->setSpacing(2); | ||
848 | m_view->setGridX(m_iconsize); | 861 | m_view->setGridX(m_iconsize); |
849 | m_view->setGridY(-1); | 862 | m_view->setGridY(-1); |
850 | PPixmapCache::self()->setMaxImages(40); | 863 | cache = (int)((double)64/(double)m_iconsize*40.0); |
864 | odebug << "cache size: " << cache << oendl; | ||
865 | PPixmapCache::self()->setMaxImages(cache); | ||
851 | break; | 866 | break; |
852 | case 3: | 867 | case 3: |
868 | m_view->setSpacing(10); | ||
853 | m_view->setGridX( fontMetrics().width("testimage.jpg")+20); | 869 | m_view->setGridX( fontMetrics().width("testimage.jpg")+20); |
854 | m_view->setGridY(8); | 870 | m_view->setGridY(8); |
855 | PPixmapCache::self()->setMaxImages(2); | 871 | PPixmapCache::self()->setMaxImages(2); |
856 | break; | 872 | break; |
857 | case 1: | 873 | case 1: |
858 | default: | 874 | default: |
875 | m_view->setSpacing(10); | ||
859 | m_view->setGridX( viewerWidth-3*m_view->spacing()); | 876 | m_view->setGridX( viewerWidth-3*m_view->spacing()); |
860 | m_view->setGridY( fontMetrics().height()*2+40 ); | 877 | m_view->setGridY( fontMetrics().height()*2+40 ); |
861 | PPixmapCache::self()->setMaxImages(20); | 878 | PPixmapCache::self()->setMaxImages(20); |
862 | break; | 879 | break; |
863 | } | 880 | } |
864 | m_view->setSpacing(10); | ||
865 | } | 881 | } |