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