Diffstat (limited to 'core/launcher/launcherview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/launcher/launcherview.cpp | 745 |
1 files changed, 412 insertions, 333 deletions
diff --git a/core/launcher/launcherview.cpp b/core/launcher/launcherview.cpp index 7117e0b..85163b6 100644 --- a/core/launcher/launcherview.cpp +++ b/core/launcher/launcherview.cpp | |||
@@ -11,184 +11,198 @@ | |||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "launcherview.h" | 21 | #include "launcherview.h" |
22 | 22 | ||
23 | #include <qpe/qpeapplication.h> | 23 | #include <qtopia/qpeapplication.h> |
24 | #include <qpe/applnk.h> | 24 | #include <qtopia/applnk.h> |
25 | #include <qpe/qpedebug.h> | 25 | #include <qtopia/qpedebug.h> |
26 | #include <qpe/categories.h> | 26 | #include <qtopia/private/categories.h> |
27 | #include <qpe/categoryselect.h> | 27 | #include <qtopia/categoryselect.h> |
28 | #include <qpe/menubutton.h> | 28 | #include <qtopia/menubutton.h> |
29 | #include <qpe/mimetype.h> | 29 | #include <qtopia/mimetype.h> |
30 | #include <qpe/resource.h> | 30 | #include <qtopia/resource.h> |
31 | #include <qpe/qpetoolbar.h> | 31 | #include <qtopia/qpetoolbar.h> |
32 | //#include <qtopia/private/palmtoprecord.h> | 32 | //#include <qtopia/private/palmtoprecord.h> |
33 | 33 | ||
34 | #include <qtimer.h> | 34 | #include <qtimer.h> |
35 | #include <qtextstream.h> | 35 | #include <qtextstream.h> |
36 | #include <qdict.h> | 36 | #include <qdict.h> |
37 | #include <qfile.h> | 37 | #include <qfile.h> |
38 | #include <qfileinfo.h> | 38 | #include <qfileinfo.h> |
39 | #include <qhbox.h> | 39 | #include <qhbox.h> |
40 | #include <qiconview.h> | 40 | #include <qiconview.h> |
41 | #include <qwidgetstack.h> | ||
41 | #include <qpainter.h> | 42 | #include <qpainter.h> |
42 | #include <qregexp.h> | 43 | #include <qregexp.h> |
43 | #include <qtoolbutton.h> | 44 | #include <qtoolbutton.h> |
44 | #include <qimage.h> | 45 | #include <qimage.h> |
46 | #include <qlabel.h> | ||
47 | #include <qobjectlist.h> | ||
48 | |||
49 | |||
50 | // These define how the busy icon is animated and highlighted | ||
51 | #define BRIGHTEN_BUSY_ICON | ||
52 | //#define ALPHA_FADE_BUSY_ICON | ||
53 | //#define USE_ANIMATED_BUSY_ICON_OVERLAY | ||
54 | #define BOUNCE_BUSY_ICON | ||
45 | 55 | ||
46 | #include <cstdlib> | ||
47 | 56 | ||
48 | class BgPixmap | 57 | class BgPixmap |
49 | { | 58 | { |
50 | public: | 59 | public: |
51 | BgPixmap( const QPixmap &p ) : pm(p), ref(1) {} | 60 | BgPixmap( const QPixmap &p ) : pm(p), ref(1) {} |
52 | QPixmap pm; | 61 | QPixmap pm; |
53 | int ref; | 62 | int ref; |
54 | }; | 63 | }; |
55 | 64 | ||
56 | enum BusyIndicatorType { | 65 | enum BusyIndicatorType { |
57 | BIT_Normal = 0, | 66 | BIT_Normal = 0, |
58 | BIT_Blinking | 67 | BIT_Blinking |
59 | }; | 68 | }; |
60 | 69 | ||
61 | static QMap<QString,BgPixmap*> *bgCache = 0; | 70 | static QMap<QString,BgPixmap*> *bgCache = 0; |
62 | 71 | ||
72 | static void cleanup_cache() | ||
73 | { | ||
74 | QMap<QString,BgPixmap*>::Iterator it = bgCache->begin(); | ||
75 | while ( it != bgCache->end() ) { | ||
76 | QMap<QString,BgPixmap*>::Iterator curr = it; | ||
77 | ++it; | ||
78 | delete (*curr); | ||
79 | bgCache->remove( curr ); | ||
80 | } | ||
81 | delete bgCache; | ||
82 | bgCache = 0; | ||
83 | } | ||
84 | |||
85 | |||
86 | class LauncherItem : public QIconViewItem | ||
87 | { | ||
88 | public: | ||
89 | LauncherItem( QIconView *parent, AppLnk* applnk, bool bigIcon=TRUE ); | ||
90 | ~LauncherItem(); | ||
91 | |||
92 | AppLnk *appLnk() const { return app; } | ||
93 | AppLnk *takeAppLnk() { AppLnk* r=app; app=0; return r; } | ||
94 | |||
95 | void animateIcon(); | ||
96 | void resetIcon(); | ||
97 | |||
98 | virtual int compare ( QIconViewItem * i ) const; | ||
99 | void paintItem( QPainter *p, const QColorGroup &cg ); | ||
100 | protected: | ||
101 | bool isBigIcon; | ||
102 | int iteration; | ||
103 | AppLnk* app; | ||
104 | private: | ||
105 | void paintAnimatedIcon( QPainter *p ); | ||
106 | }; | ||
107 | |||
108 | |||
63 | class LauncherIconView : public QIconView { | 109 | class LauncherIconView : public QIconView { |
64 | public: | 110 | public: |
65 | LauncherIconView( QWidget* parent, const char* name=0 ) : | 111 | LauncherIconView( QWidget* parent, const char* name=0 ) : |
66 | QIconView(parent,name), | 112 | QIconView(parent,name), |
67 | tf(""), | 113 | tf(""), |
68 | cf(0), | 114 | cf(0), |
69 | bsy(0), | 115 | bsy(0), |
116 | busyTimer(0), | ||
70 | bigIcns(TRUE), | 117 | bigIcns(TRUE), |
71 | bgColor(white) | 118 | bgColor(white) |
72 | { | 119 | { |
73 | sortmeth = Name; | 120 | sortmeth = Name; |
74 | hidden.setAutoDelete(TRUE); | 121 | hidden.setAutoDelete(TRUE); |
75 | ike = FALSE; | 122 | ike = FALSE; |
76 | busytimer = 0; | ||
77 | calculateGrid( Bottom ); | 123 | calculateGrid( Bottom ); |
78 | } | 124 | } |
79 | 125 | ||
80 | ~LauncherIconView() | 126 | ~LauncherIconView() |
81 | { | 127 | { |
82 | #if 0 // debuggery | 128 | #if 0 // debuggery |
83 | QListIterator<AppLnk> it(hidden); | 129 | QListIterator<AppLnk> it(hidden); |
84 | AppLnk* l; | 130 | AppLnk* l; |
85 | while ((l=it.current())) { | 131 | while ((l=it.current())) { |
86 | ++it; | 132 | ++it; |
87 | //qDebug("%p: hidden (should remove)",l); | 133 | //qDebug("%p: hidden (should remove)",l); |
88 | } | 134 | } |
89 | #endif | 135 | #endif |
90 | } | 136 | } |
91 | |||
92 | void setBusyIndicatorType ( BusyIndicatorType t ) { busyType = t; } | ||
93 | 137 | ||
94 | QPixmap* busyPixmap() const { return (QPixmap*)&bpm[abs(busystate)]; } | ||
95 | QIconViewItem* busyItem() const { return bsy; } | 138 | QIconViewItem* busyItem() const { return bsy; } |
96 | void setBigIcons( bool bi ) { bigIcns = bi; } | 139 | #ifdef USE_ANIMATED_BUSY_ICON_OVERLAY |
140 | QPixmap busyPixmap() const { return busyPix; } | ||
141 | #endif | ||
142 | void setBigIcons( bool bi ) { | ||
143 | bigIcns = bi; | ||
144 | #ifdef USE_ANIMATED_BUSY_ICON_OVERLAY | ||
145 | busyPix.resize(0,0); | ||
146 | #endif | ||
147 | } | ||
97 | 148 | ||
98 | void updateCategoriesAndMimeTypes(); | 149 | void updateCategoriesAndMimeTypes(); |
99 | 150 | ||
100 | void doAutoScroll() | 151 | void doAutoScroll() |
101 | { | 152 | { |
102 | // We don't want rubberbanding (yet) | 153 | // We don't want rubberbanding (yet) |
103 | } | 154 | } |
104 | 155 | ||
105 | void setBusy(bool on) | 156 | void setBusy(bool on) |
106 | { | 157 | { |
107 | QIconViewItem *c = on ? currentItem() : 0; | 158 | #ifdef USE_ANIMATED_BUSY_ICON_OVERLAY |
108 | 159 | if ( busyPix.isNull() ) { | |
109 | if ( bsy != c ) { | 160 | int size = ( bigIcns ) ? AppLnk::bigIconSize() : AppLnk::smallIconSize(); |
110 | QIconViewItem *oldbsy = bsy; | 161 | busyPix.convertFromImage( Resource::loadImage( "busy" ).smoothScale( size * 16, size ) ); |
111 | bsy = c; | 162 | } |
112 | 163 | #endif | |
113 | if ( oldbsy ) | ||
114 | oldbsy-> repaint ( ); | ||
115 | |||
116 | if ( busytimer ) { | ||
117 | killTimer ( busytimer ); | ||
118 | busytimer = 0; | ||
119 | } | ||
120 | |||
121 | if ( bsy ) { | ||
122 | QPixmap *src = bsy-> QIconViewItem::pixmap(); | ||
123 | for ( int i = 0; i <= 5; i++ ) { | ||
124 | QImage img = src->convertToImage(); | ||
125 | QRgb* rgb; | ||
126 | int count; | ||
127 | if ( img.depth() == 32 ) { | ||
128 | rgb = (QRgb*)img.bits(); | ||
129 | count = img.bytesPerLine()/sizeof(QRgb)*img.height(); | ||
130 | } else { | ||
131 | rgb = img.colorTable(); | ||
132 | count = img.numColors(); | ||
133 | } | ||
134 | int rc, gc, bc; | ||
135 | int bs = abs ( i * 10 ) + 25; | ||
136 | colorGroup().highlight().rgb( &rc, &gc, &bc ); | ||
137 | rc = rc * bs / 100; | ||
138 | gc = gc * bs / 100; | ||
139 | bc = bc * bs / 100; | ||
140 | |||
141 | for ( int r = 0; r < count; r++, rgb++ ) { | ||
142 | int ri = rc + qRed ( *rgb ) * ( 100 - bs ) / 100; | ||
143 | int gi = gc + qGreen ( *rgb ) * ( 100 - bs ) / 100; | ||
144 | int bi = bc + qBlue ( *rgb ) * ( 100 - bs ) / 100; | ||
145 | int ai = qAlpha ( *rgb ); | ||
146 | *rgb = qRgba ( ri, gi, bi, ai ); | ||
147 | } | ||
148 | 164 | ||
149 | bpm [i].convertFromImage( img ); | 165 | if ( on ) { |
150 | } | 166 | busyTimer = startTimer( 100 ); |
151 | 167 | } else { | |
152 | if ( busyType == BIT_Blinking ) { | 168 | if ( busyTimer ) { |
153 | busystate = 0; | 169 | killTimer( busyTimer ); |
154 | busytimer = startTimer ( 200 ); | 170 | busyTimer = 0; |
155 | } | ||
156 | else { | ||
157 | busystate = 3; | ||
158 | } | ||
159 | timerEvent ( 0 ); | ||
160 | } | 171 | } |
161 | } | 172 | } |
162 | } | ||
163 | 173 | ||
164 | virtual void timerEvent ( QTimerEvent *te ) | 174 | LauncherItem *c = on ? (LauncherItem*)currentItem() : 0; |
165 | { | 175 | |
166 | if ( !te || ( te-> timerId ( ) == busytimer )) { | 176 | if ( bsy != c ) { |
167 | if ( bsy ) { | 177 | LauncherItem *oldBusy = bsy; |
168 | busystate++; | 178 | bsy = c; |
169 | if ( busystate > 5 ) | 179 | if ( oldBusy ) |
170 | busystate = -4; | 180 | oldBusy->resetIcon(); |
171 | 181 | if ( bsy ) | |
172 | QScrollView::updateContents ( bsy-> pixmapRect ( false )); | 182 | bsy->animateIcon(); |
173 | } | ||
174 | } | 183 | } |
175 | } | 184 | } |
176 | 185 | ||
177 | bool inKeyEvent() const { return ike; } | 186 | bool inKeyEvent() const { return ike; } |
178 | void keyPressEvent(QKeyEvent* e) | 187 | void keyPressEvent(QKeyEvent* e) |
179 | { | 188 | { |
180 | ike = TRUE; | 189 | ike = TRUE; |
181 | if ( e->key() == Key_F33 /* OK button */ || e->key() == Key_Space ) | 190 | if ( e->key() == Key_F33 /* OK button */ || e->key() == Key_Space ) { |
182 | returnPressed(currentItem()); | 191 | if ( (e->state() & ShiftButton) ) |
192 | emit mouseButtonPressed(ShiftButton, currentItem(), QPoint() ); | ||
193 | else | ||
194 | returnPressed(currentItem()); | ||
195 | } | ||
196 | |||
183 | QIconView::keyPressEvent(e); | 197 | QIconView::keyPressEvent(e); |
184 | ike = FALSE; | 198 | ike = FALSE; |
185 | } | 199 | } |
186 | 200 | ||
187 | void addItem(AppLnk* app, bool resort=TRUE); | 201 | void addItem(AppLnk* app, bool resort=TRUE); |
188 | bool removeLink(const QString& linkfile); | 202 | bool removeLink(const QString& linkfile); |
189 | 203 | ||
190 | QStringList mimeTypes() const; | 204 | QStringList mimeTypes() const; |
191 | QStringList categories() const; | 205 | QStringList categories() const; |
192 | 206 | ||
193 | void clear() | 207 | void clear() |
194 | { | 208 | { |
@@ -204,51 +218,39 @@ public: | |||
204 | // for (QStringList::ConstIterator cit=c.begin(); cit!=c.end(); ++cit) { | 218 | // for (QStringList::ConstIterator cit=c.begin(); cit!=c.end(); ++cit) { |
205 | // cats.replace(*cit,(void*)1); | 219 | // cats.replace(*cit,(void*)1); |
206 | // } | 220 | // } |
207 | QString maj=app->type(); | 221 | QString maj=app->type(); |
208 | int sl=maj.find('/'); | 222 | int sl=maj.find('/'); |
209 | if (sl>=0) { | 223 | if (sl>=0) { |
210 | QString k; | 224 | QString k; |
211 | k = maj.left(12) == "application/" ? maj : maj.left(sl); | 225 | k = maj.left(12) == "application/" ? maj : maj.left(sl); |
212 | mimes.replace(k,(void*)1); | 226 | mimes.replace(k,(void*)1); |
213 | } | 227 | } |
214 | } | 228 | } |
215 | 229 | ||
230 | void setBackgroundOrigin( QWidget::BackgroundOrigin ) { | ||
231 | } | ||
232 | |||
216 | void setBackgroundPixmap( const QPixmap &pm ) { | 233 | void setBackgroundPixmap( const QPixmap &pm ) { |
217 | if ( pm. isNull ( )) { | 234 | bgPixmap = pm; |
218 | bgPixmap = pm; | ||
219 | } | ||
220 | else { | ||
221 | // This is need for bg images with alpha channel | ||
222 | |||
223 | QPixmap tmp ( pm. size ( ), pm. depth ( )); | ||
224 | |||
225 | QPainter p ( &tmp ); | ||
226 | p. fillRect ( 0, 0, pm. width ( ), pm. height ( ), bgColor. isValid ( ) ? bgColor : white ); | ||
227 | p. drawPixmap ( 0, 0, pm ); | ||
228 | p. end ( ); | ||
229 | |||
230 | bgPixmap = tmp; | ||
231 | } | ||
232 | } | 235 | } |
233 | 236 | ||
234 | void setBackgroundColor( const QColor &c ) { | 237 | void setBackgroundColor( const QColor &c ) { |
235 | bgColor = c; | 238 | bgColor = c; |
236 | } | 239 | } |
237 | 240 | ||
238 | void drawBackground( QPainter *p, const QRect &r ) | 241 | void drawBackground( QPainter *p, const QRect &r ) |
239 | { | 242 | { |
240 | if ( !bgPixmap.isNull() ) { | 243 | if ( !bgPixmap.isNull() ) { |
241 | //p-> fillRect ( r, bgColor ); | 244 | p->drawTiledPixmap( r, bgPixmap, |
242 | p->drawTiledPixmap( r, bgPixmap, | ||
243 | QPoint( (r.x() + contentsX()) % bgPixmap.width(), | 245 | QPoint( (r.x() + contentsX()) % bgPixmap.width(), |
244 | (r.y() + contentsY()) % bgPixmap.height() ) ); | 246 | (r.y() + contentsY()) % bgPixmap.height() ) ); |
245 | } else { | 247 | } else { |
246 | p->fillRect( r, bgColor ); | 248 | p->fillRect( r, bgColor ); |
247 | } | 249 | } |
248 | } | 250 | } |
249 | 251 | ||
250 | void setItemTextPos( ItemTextPos pos ) | 252 | void setItemTextPos( ItemTextPos pos ) |
251 | { | 253 | { |
252 | calculateGrid( pos ); | 254 | calculateGrid( pos ); |
253 | QIconView::setItemTextPos( pos ); | 255 | QIconView::setItemTextPos( pos ); |
254 | } | 256 | } |
@@ -278,40 +280,48 @@ public: | |||
278 | void setSortMethod( SortMethod m ) | 280 | void setSortMethod( SortMethod m ) |
279 | { | 281 | { |
280 | if ( sortmeth != m ) { | 282 | if ( sortmeth != m ) { |
281 | sortmeth = m; | 283 | sortmeth = m; |
282 | sort(); | 284 | sort(); |
283 | } | 285 | } |
284 | } | 286 | } |
285 | 287 | ||
286 | int compare(const AppLnk* a, const AppLnk* b) | 288 | int compare(const AppLnk* a, const AppLnk* b) |
287 | { | 289 | { |
288 | switch (sortmeth) { | 290 | switch (sortmeth) { |
289 | case Name: | 291 | case Name: |
290 | return a->name().compare(b->name()); | 292 | return a->name().lower().compare(b->name().lower()); |
291 | case Date: { | 293 | case Date: { |
292 | QFileInfo fa(a->linkFileKnown() ? a->linkFile() : a->file()); | 294 | QFileInfo fa(a->linkFileKnown() ? a->linkFile() : a->file()); |
293 | QFileInfo fb(b->linkFileKnown() ? b->linkFile() : b->file()); | 295 | QFileInfo fb(b->linkFileKnown() ? b->linkFile() : b->file()); |
294 | return fa.lastModified().secsTo(fb.lastModified()); | 296 | return fa.lastModified().secsTo(fb.lastModified()); |
295 | } | 297 | } |
296 | case Type: | 298 | case Type: |
297 | return a->type().compare(b->type()); | 299 | return a->type().compare(b->type()); |
298 | } | 300 | } |
299 | return 0; | 301 | return 0; |
300 | } | 302 | } |
301 | 303 | ||
302 | QString getAllDocLinkInfo() const; | ||
303 | |||
304 | protected: | 304 | protected: |
305 | 305 | ||
306 | void timerEvent( QTimerEvent *te ) | ||
307 | { | ||
308 | if ( te->timerId() == busyTimer ) { | ||
309 | if ( bsy ) | ||
310 | bsy->animateIcon(); | ||
311 | } else { | ||
312 | QIconView::timerEvent( te ); | ||
313 | } | ||
314 | } | ||
315 | |||
306 | void styleChange( QStyle &old ) | 316 | void styleChange( QStyle &old ) |
307 | { | 317 | { |
308 | QIconView::styleChange( old ); | 318 | QIconView::styleChange( old ); |
309 | calculateGrid( itemTextPos() ); | 319 | calculateGrid( itemTextPos() ); |
310 | } | 320 | } |
311 | 321 | ||
312 | void calculateGrid( ItemTextPos pos ) | 322 | void calculateGrid( ItemTextPos pos ) |
313 | { | 323 | { |
314 | int dw = QApplication::desktop()->width(); | 324 | int dw = QApplication::desktop()->width(); |
315 | int viewerWidth = dw-style().scrollBarExtent().width(); | 325 | int viewerWidth = dw-style().scrollBarExtent().width(); |
316 | if ( pos == Bottom ) { | 326 | if ( pos == Bottom ) { |
317 | int cols = 3; | 327 | int cols = 3; |
@@ -325,148 +335,180 @@ protected: | |||
325 | } else { | 335 | } else { |
326 | int cols = 2; | 336 | int cols = 2; |
327 | if ( viewerWidth < 150 ) | 337 | if ( viewerWidth < 150 ) |
328 | cols = 1; | 338 | cols = 1; |
329 | else if ( viewerWidth >= 400 ) | 339 | else if ( viewerWidth >= 400 ) |
330 | cols = viewerWidth/150; | 340 | cols = viewerWidth/150; |
331 | setSpacing( 2 ); | 341 | setSpacing( 2 ); |
332 | setGridX( (viewerWidth-(cols+1)*spacing())/cols ); | 342 | setGridX( (viewerWidth-(cols+1)*spacing())/cols ); |
333 | setGridY( fontMetrics().height()+2 ); | 343 | setGridY( fontMetrics().height()+2 ); |
334 | } | 344 | } |
335 | } | 345 | } |
336 | 346 | ||
347 | void focusInEvent( QFocusEvent * ) {} | ||
348 | void focusOutEvent( QFocusEvent * ) {} | ||
337 | 349 | ||
338 | // flicker free redrawing of busy indicator | ||
339 | // code was taken from QScrollView::viewportPaintEvent | ||
340 | void viewportPaintEvent( QPaintEvent* pe ) | ||
341 | { | ||
342 | static QPixmap *pix = new QPixmap ( ); | ||
343 | |||
344 | QWidget* vp = viewport(); | ||
345 | |||
346 | if ( vp-> size ( ) != pix-> size ( )) | ||
347 | pix-> resize ( vp-> size ( )); | ||
348 | |||
349 | QPainter p(pix, vp); | ||
350 | QRect r = pe->rect(); | ||
351 | if ( clipper ( ) != vp ) { | ||
352 | QRect rr( | ||
353 | -vp->x(), -vp->y(), | ||
354 | clipper()->width(), clipper()->height() | ||
355 | ); | ||
356 | r &= rr; | ||
357 | if ( r.isValid() ) { | ||
358 | int ex = r.x() + vp->x() + contentsX(); | ||
359 | int ey = r.y() + vp->y() + contentsY(); | ||
360 | int ew = r.width(); | ||
361 | int eh = r.height(); | ||
362 | drawContentsOffset(&p, | ||
363 | contentsX()+vp->x(), | ||
364 | contentsY()+vp->y(), | ||
365 | ex, ey, ew, eh); | ||
366 | } | ||
367 | } else { | ||
368 | r &= clipper()->rect(); | ||
369 | int ex = r.x() + contentsX(); | ||
370 | int ey = r.y() + contentsY(); | ||
371 | int ew = r.width(); | ||
372 | int eh = r.height(); | ||
373 | drawContentsOffset(&p, contentsX(), contentsY(), ex, ey, ew, eh); | ||
374 | } | ||
375 | bitBlt ( vp, r.topLeft(), pix, r ); | ||
376 | } | ||
377 | |||
378 | private: | 350 | private: |
379 | QList<AppLnk> hidden; | 351 | QList<AppLnk> hidden; |
380 | QDict<void> mimes; | 352 | QDict<void> mimes; |
381 | QDict<void> cats; | 353 | QDict<void> cats; |
382 | SortMethod sortmeth; | 354 | SortMethod sortmeth; |
383 | QRegExp tf; | 355 | QRegExp tf; |
384 | int cf; | 356 | int cf; |
385 | QIconViewItem* bsy; | 357 | LauncherItem* bsy; |
358 | int busyTimer; | ||
386 | bool ike; | 359 | bool ike; |
387 | bool bigIcns; | 360 | bool bigIcns; |
388 | QPixmap bgPixmap; | 361 | QPixmap bgPixmap; |
389 | QPixmap bpm [6]; | ||
390 | QColor bgColor; | 362 | QColor bgColor; |
391 | int busytimer; | 363 | #ifdef USE_ANIMATED_BUSY_ICON_OVERLAY |
392 | int busystate; | 364 | QPixmap busyPix; |
393 | BusyIndicatorType busyType; | 365 | #endif |
394 | }; | 366 | }; |
395 | 367 | ||
396 | 368 | ||
397 | bool LauncherView::bsy=FALSE; | 369 | bool LauncherView::bsy=FALSE; |
398 | 370 | ||
399 | void LauncherView::setBusy(bool on) | 371 | void LauncherView::setBusy(bool on) |
400 | { | 372 | { |
401 | icons->setBusy(on); | 373 | icons->setBusy(on); |
402 | } | 374 | } |
403 | 375 | ||
404 | class LauncherItem : public QIconViewItem | 376 | void LauncherView::setBusyIndicatorType( const QString& type ) { |
377 | /* ### FIXME */ | ||
378 | } | ||
379 | |||
380 | LauncherItem::LauncherItem( QIconView *parent, AppLnk *applnk, bool bigIcon ) | ||
381 | : QIconViewItem( parent, applnk->name(), | ||
382 | bigIcon ? applnk->bigPixmap() :applnk->pixmap() ), | ||
383 | isBigIcon( bigIcon ), | ||
384 | iteration(0), | ||
385 | app(applnk) // Takes ownership | ||
405 | { | 386 | { |
406 | public: | 387 | } |
407 | LauncherItem( QIconView *parent, AppLnk* applnk, bool bigIcon=TRUE ); | ||
408 | ~LauncherItem() | ||
409 | { | ||
410 | LauncherIconView* liv = (LauncherIconView*)iconView(); | ||
411 | if ( liv->busyItem() == this ) | ||
412 | liv->setBusy(FALSE); | ||
413 | delete app; | ||
414 | } | ||
415 | 388 | ||
416 | AppLnk* appLnk() const { return app; } | 389 | LauncherItem::~LauncherItem() |
417 | AppLnk* takeAppLnk() { AppLnk* r=app; app=0; return r; } | 390 | { |
391 | LauncherIconView* liv = (LauncherIconView*)iconView(); | ||
392 | if ( liv->busyItem() == this ) | ||
393 | liv->setBusy(FALSE); | ||
394 | delete app; | ||
395 | } | ||
418 | 396 | ||
419 | virtual int compare ( QIconViewItem * i ) const; | 397 | int LauncherItem::compare ( QIconViewItem * i ) const |
398 | { | ||
399 | LauncherIconView* view = (LauncherIconView*)iconView(); | ||
400 | return view->compare(app,((LauncherItem *)i)->appLnk()); | ||
401 | } | ||
420 | 402 | ||
421 | void paintItem( QPainter *p, const QColorGroup &cg ) | 403 | void LauncherItem::paintItem( QPainter *p, const QColorGroup &cg ) |
422 | { | 404 | { |
423 | LauncherIconView* liv = (LauncherIconView*)iconView(); | 405 | LauncherIconView* liv = (LauncherIconView*)iconView(); |
424 | QBrush oldBrush( liv->itemTextBackground() ); | 406 | QBrush oldBrush( liv->itemTextBackground() ); |
425 | QColorGroup mycg( cg ); | 407 | QColorGroup mycg( cg ); |
426 | if ( liv->currentItem() == this ) { | 408 | if ( liv->currentItem() == this ) { |
427 | liv->setItemTextBackground( cg.brush( QColorGroup::Highlight ) ); | 409 | liv->setItemTextBackground( cg.brush( QColorGroup::Highlight ) ); |
428 | mycg.setColor( QColorGroup::Text, cg.color( QColorGroup::HighlightedText ) ); | 410 | mycg.setColor( QColorGroup::Text, cg.color( QColorGroup::HighlightedText ) ); |
429 | } | ||
430 | QIconViewItem::paintItem(p,mycg); | ||
431 | if ( liv->currentItem() == this ) | ||
432 | liv->setItemTextBackground( oldBrush ); | ||
433 | } | 411 | } |
434 | 412 | ||
435 | virtual QPixmap* pixmap () const | 413 | QIconViewItem::paintItem(p,mycg); |
436 | { | ||
437 | const LauncherIconView* liv = (LauncherIconView*)iconView(); | ||
438 | if ( (const LauncherItem *)liv->busyItem() == this ) | ||
439 | return liv->busyPixmap(); | ||
440 | return QIconViewItem::pixmap(); | ||
441 | } | ||
442 | 414 | ||
443 | protected: | 415 | // Paint animation overlay |
444 | AppLnk* app; | 416 | if ( liv->busyItem() == this ) |
445 | }; | 417 | paintAnimatedIcon(p); |
446 | 418 | ||
419 | if ( liv->currentItem() == this ) | ||
420 | liv->setItemTextBackground( oldBrush ); | ||
421 | } | ||
447 | 422 | ||
448 | LauncherItem::LauncherItem( QIconView *parent, AppLnk *applnk, bool bigIcon ) | 423 | void LauncherItem::paintAnimatedIcon( QPainter *p ) |
449 | : QIconViewItem( parent, applnk->name(), | ||
450 | bigIcon ? applnk->bigPixmap() :applnk->pixmap() ), | ||
451 | app(applnk) // Takes ownership | ||
452 | { | 424 | { |
425 | LauncherIconView* liv = (LauncherIconView*)iconView(); | ||
426 | int pic = iteration % 16; | ||
427 | int w = pixmap()->width(), h = pixmap()->height(); | ||
428 | QPixmap dblBuf( w, h + 4 ); | ||
429 | QPainter p2( &dblBuf ); | ||
430 | int x1, y1; | ||
431 | if ( liv->itemTextPos() == QIconView::Bottom ) { | ||
432 | x1 = x() + (width() - w) / 2 - liv->contentsX(); | ||
433 | y1 = y() - liv->contentsY(); | ||
434 | } else { | ||
435 | x1 = x() - liv->contentsX(); | ||
436 | y1 = y() + (height() - h) / 2 - liv->contentsY(); | ||
437 | } | ||
438 | y1 -= 2; | ||
439 | p2.translate(-x1,-y1); | ||
440 | liv->drawBackground( &p2, QRect(x1,y1,w,h+4) ); | ||
441 | int bounceY = 2; | ||
442 | #ifdef BOUNCE_BUSY_ICON | ||
443 | bounceY = 4 - ((iteration+2)%8); | ||
444 | bounceY = bounceY < 0 ? -bounceY : bounceY; | ||
445 | #endif | ||
446 | p2.drawPixmap( x1, y1 + bounceY, *pixmap() ); | ||
447 | #ifdef USE_ANIMATED_BUSY_ICON_OVERLAY | ||
448 | p2.drawPixmap( x1, y1 + bounceY, liv->busyPixmap(), w * pic, 0, w, h ); | ||
449 | #endif | ||
450 | p->drawPixmap( x1, y1, dblBuf ); | ||
453 | } | 451 | } |
454 | 452 | ||
455 | int LauncherItem::compare ( QIconViewItem * i ) const | 453 | void LauncherItem::animateIcon() |
456 | { | 454 | { |
457 | LauncherIconView* view = (LauncherIconView*)iconView(); | 455 | LauncherIconView* liv = (LauncherIconView*)iconView(); |
458 | return view->compare(app,((LauncherItem *)i)->appLnk()); | 456 | |
457 | if ( liv->busyItem() != this || !app ) | ||
458 | return; | ||
459 | |||
460 | // Highlight the icon | ||
461 | if ( iteration == 0 ) { | ||
462 | QPixmap src = isBigIcon ? app->bigPixmap() : app->pixmap(); | ||
463 | QImage img = src.convertToImage(); | ||
464 | QRgb *rgb; | ||
465 | int count; | ||
466 | if ( img.depth() == 32 ) { | ||
467 | rgb = (QRgb*)img.bits(); | ||
468 | count = img.bytesPerLine()/sizeof(QRgb)*img.height(); | ||
469 | } else { | ||
470 | rgb = img.colorTable(); | ||
471 | count = img.numColors(); | ||
472 | } | ||
473 | for ( int r = 0; r < count; r++, rgb++ ) { | ||
474 | #if defined(BRIGHTEN_BUSY_ICON) | ||
475 | QColor c(*rgb); | ||
476 | int h, s, v; | ||
477 | c.hsv(&h,&s,&v); | ||
478 | c.setHsv(h,QMAX(s-24,0),QMIN(v+48,255)); | ||
479 | *rgb = qRgba(c.red(),c.green(),c.blue(),qAlpha(*rgb)); | ||
480 | #elif defined(ALPHA_FADE_BUSY_ICON) | ||
481 | *rgb = qRgba(qRed(*rgb),qGreen(*rgb),qBlue(*rgb),qAlpha(*rgb)/2); | ||
482 | #endif | ||
483 | } | ||
484 | src.convertFromImage( img ); | ||
485 | setPixmap( src ); | ||
486 | } | ||
487 | |||
488 | iteration++; | ||
489 | |||
490 | // Paint animation overlay | ||
491 | QPainter p( liv->viewport() ); | ||
492 | paintAnimatedIcon( &p ); | ||
493 | } | ||
494 | |||
495 | void LauncherItem::resetIcon() | ||
496 | { | ||
497 | iteration = 0; | ||
498 | setPixmap( isBigIcon ? app->bigPixmap() : app->pixmap() ); | ||
459 | } | 499 | } |
460 | 500 | ||
501 | //=========================================================================== | ||
502 | |||
461 | QStringList LauncherIconView::mimeTypes() const | 503 | QStringList LauncherIconView::mimeTypes() const |
462 | { | 504 | { |
463 | QStringList r; | 505 | QStringList r; |
464 | QDictIterator<void> it(mimes); | 506 | QDictIterator<void> it(mimes); |
465 | while (it.current()) { | 507 | while (it.current()) { |
466 | r.append(it.currentKey()); | 508 | r.append(it.currentKey()); |
467 | ++it; | 509 | ++it; |
468 | } | 510 | } |
469 | r.sort(); | 511 | r.sort(); |
470 | return r; | 512 | return r; |
471 | } | 513 | } |
472 | 514 | ||
@@ -494,131 +536,83 @@ void LauncherIconView::updateCategoriesAndMimeTypes() | |||
494 | item = (LauncherItem*)item->nextItem(); | 536 | item = (LauncherItem*)item->nextItem(); |
495 | } | 537 | } |
496 | QListIterator<AppLnk> it(hidden); | 538 | QListIterator<AppLnk> it(hidden); |
497 | AppLnk* l; | 539 | AppLnk* l; |
498 | while ((l=it.current())) { | 540 | while ((l=it.current())) { |
499 | addCatsAndMimes(l); | 541 | addCatsAndMimes(l); |
500 | ++it; | 542 | ++it; |
501 | } | 543 | } |
502 | } | 544 | } |
503 | 545 | ||
504 | void LauncherIconView::hideOrShowItems(bool resort) | 546 | void LauncherIconView::hideOrShowItems(bool resort) |
505 | { | 547 | { |
548 | viewport()->setUpdatesEnabled( FALSE ); | ||
506 | hidden.setAutoDelete(FALSE); | 549 | hidden.setAutoDelete(FALSE); |
507 | QList<AppLnk> links=hidden; | 550 | QList<AppLnk> links=hidden; |
508 | hidden.clear(); | 551 | hidden.clear(); |
509 | hidden.setAutoDelete(TRUE); | 552 | hidden.setAutoDelete(TRUE); |
510 | LauncherItem* item = (LauncherItem*)firstItem(); | 553 | LauncherItem* item = (LauncherItem*)firstItem(); |
511 | while (item) { | 554 | while (item) { |
512 | links.append(item->takeAppLnk()); | 555 | links.append(item->takeAppLnk()); |
513 | item = (LauncherItem*)item->nextItem(); | 556 | item = (LauncherItem*)item->nextItem(); |
514 | } | 557 | } |
515 | viewport()->setUpdatesEnabled( FALSE ); | ||
516 | clear(); | 558 | clear(); |
517 | QListIterator<AppLnk> it(links); | 559 | QListIterator<AppLnk> it(links); |
518 | AppLnk* l; | 560 | AppLnk* l; |
519 | while ((l=it.current())) { | 561 | while ((l=it.current())) { |
520 | addItem(l,FALSE); | 562 | addItem(l,FALSE); |
521 | ++it; | 563 | ++it; |
522 | } | 564 | } |
523 | viewport()->setUpdatesEnabled( TRUE ); | ||
524 | if ( resort && !autoArrange() ) | 565 | if ( resort && !autoArrange() ) |
525 | sort(); | 566 | sort(); |
567 | viewport()->setUpdatesEnabled( TRUE ); | ||
526 | } | 568 | } |
527 | 569 | ||
528 | bool LauncherIconView::removeLink(const QString& linkfile) | 570 | bool LauncherIconView::removeLink(const QString& linkfile) |
529 | { | 571 | { |
530 | LauncherItem* item = (LauncherItem*)firstItem(); | 572 | LauncherItem* item = (LauncherItem*)firstItem(); |
531 | AppLnk* l; | 573 | AppLnk* l; |
532 | bool did = FALSE; | 574 | bool did = FALSE; |
533 | DocLnk dl(linkfile); | 575 | DocLnk dl(linkfile); |
534 | while (item) { | 576 | while (item) { |
535 | l = item->appLnk(); | 577 | l = item->appLnk(); |
536 | if ( ( l->linkFileKnown() && ( l->linkFile() == linkfile )) | 578 | LauncherItem *nextItem = (LauncherItem *)item->nextItem(); |
537 | || ( l->fileKnown() && ( l->file() == linkfile )) | 579 | if ( l->linkFileKnown() && l->linkFile() == linkfile |
538 | || ( dl.fileKnown() && l->fileKnown() && ( dl.file() == l->file() )) ) { | 580 | || l->fileKnown() && ( |
581 | l->file() == linkfile | ||
582 | || dl.isValid() && dl.file() == l->file() ) ) { | ||
539 | delete item; | 583 | delete item; |
540 | did = TRUE; | 584 | did = TRUE; |
541 | } | 585 | } |
542 | item = (LauncherItem*)item->nextItem(); | 586 | item = nextItem; |
543 | } | 587 | } |
544 | QListIterator<AppLnk> it(hidden); | 588 | QListIterator<AppLnk> it(hidden); |
545 | while ((l=it.current())) { | 589 | while ((l=it.current())) { |
546 | ++it; | 590 | ++it; |
547 | if ( ( l->linkFileKnown() && ( l->linkFile() == linkfile )) | 591 | if ( l->linkFileKnown() && l->linkFile() == linkfile |
548 | || ( l->file() == linkfile ) | 592 | || l->file() == linkfile |
549 | || ( dl.fileKnown() && ( dl.file() == l->file() )) ) { | 593 | || dl.isValid() && dl.file() == l->file() ) { |
550 | hidden.removeRef(l); | 594 | hidden.removeRef(l); |
551 | did = TRUE; | 595 | did = TRUE; |
552 | } | 596 | } |
553 | } | 597 | } |
554 | return did; | 598 | return did; |
555 | } | 599 | } |
556 | 600 | ||
557 | static QString docLinkInfo(const Categories& cats, DocLnk* doc) | ||
558 | { | ||
559 | QString contents; | ||
560 | |||
561 | QFileInfo fi( doc->file() ); | ||
562 | if ( !fi.exists() ) | ||
563 | return contents; | ||
564 | |||
565 | if ( doc->linkFileKnown() ) { | ||
566 | QString lfn = doc->linkFile(); | ||
567 | QFile f( lfn ); | ||
568 | if ( f.open( IO_ReadOnly ) ) { | ||
569 | QTextStream ts( &f ); | ||
570 | ts.setEncoding( QTextStream::UnicodeUTF8 ); | ||
571 | contents += ts.read(); | ||
572 | f.close(); | ||
573 | goto calcsize; | ||
574 | } | ||
575 | } | ||
576 | |||
577 | contents += "[Desktop Entry]\n"; | ||
578 | contents += "Categories = " // No tr | ||
579 | + cats.labels("Document View", doc->categories()).join(";") + "\n"; // No tr | ||
580 | contents += "File = "+doc->file()+"\n"; // No tr | ||
581 | contents += "Name = "+doc->name()+"\n"; // No tr | ||
582 | contents += "Type = "+doc->type()+"\n"; // No tr | ||
583 | |||
584 | calcsize: | ||
585 | contents += QString("Size = %1\n").arg( fi.size() ); // No tr | ||
586 | return contents; | ||
587 | } | ||
588 | |||
589 | QString LauncherIconView::getAllDocLinkInfo() const | ||
590 | { | ||
591 | QString contents; | ||
592 | LauncherItem* item = (LauncherItem*)firstItem(); | ||
593 | Categories cats; | ||
594 | while (item) { | ||
595 | DocLnk* doc = (DocLnk*)item->appLnk(); | ||
596 | contents += docLinkInfo(cats,doc); | ||
597 | item = (LauncherItem*)item->nextItem(); | ||
598 | } | ||
599 | QListIterator<AppLnk> it(hidden); | ||
600 | DocLnk* doc; | ||
601 | while ((doc=(DocLnk*)it.current())) { | ||
602 | contents += docLinkInfo(cats,doc); | ||
603 | ++it; | ||
604 | } | ||
605 | return contents; | ||
606 | } | ||
607 | |||
608 | //=========================================================================== | 601 | //=========================================================================== |
609 | 602 | ||
610 | LauncherView::LauncherView( QWidget* parent, const char* name, WFlags fl ) | 603 | LauncherView::LauncherView( QWidget* parent, const char* name, WFlags fl ) |
611 | : QVBox( parent, name, fl ) | 604 | : QVBox( parent, name, fl ) |
612 | { | 605 | { |
606 | catmb = 0; | ||
613 | icons = new LauncherIconView( this ); | 607 | icons = new LauncherIconView( this ); |
614 | setFocusProxy(icons); | 608 | setFocusProxy(icons); |
615 | QPEApplication::setStylusOperation( icons->viewport(), QPEApplication::RightOnHold ); | 609 | QPEApplication::setStylusOperation( icons->viewport(), QPEApplication::RightOnHold ); |
616 | 610 | ||
617 | icons->setItemsMovable( FALSE ); | 611 | icons->setItemsMovable( FALSE ); |
618 | icons->setAutoArrange( TRUE ); | 612 | icons->setAutoArrange( TRUE ); |
619 | icons->setSorting( TRUE ); | 613 | icons->setSorting( TRUE ); |
620 | icons->setFrameStyle( QFrame::NoFrame ); | 614 | icons->setFrameStyle( QFrame::NoFrame ); |
621 | icons->setMargin( 0 ); | 615 | icons->setMargin( 0 ); |
622 | icons->setSelectionMode( QIconView::NoSelection ); | 616 | icons->setSelectionMode( QIconView::NoSelection ); |
623 | icons->setBackgroundMode( PaletteBase ); | 617 | icons->setBackgroundMode( PaletteBase ); |
624 | icons->setResizeMode( QIconView::Fixed ); | 618 | icons->setResizeMode( QIconView::Fixed ); |
@@ -631,95 +625,115 @@ LauncherView::LauncherView( QWidget* parent, const char* name, WFlags fl ) | |||
631 | SLOT(selectionChanged()) ); | 625 | SLOT(selectionChanged()) ); |
632 | connect( icons, SIGNAL(returnPressed(QIconViewItem *)), | 626 | connect( icons, SIGNAL(returnPressed(QIconViewItem *)), |
633 | SLOT(returnPressed(QIconViewItem *)) ); | 627 | SLOT(returnPressed(QIconViewItem *)) ); |
634 | connect( icons, SIGNAL(mouseButtonPressed(int, QIconViewItem *, const QPoint&)), | 628 | connect( icons, SIGNAL(mouseButtonPressed(int, QIconViewItem *, const QPoint&)), |
635 | SLOT(itemPressed(int, QIconViewItem *)) ); | 629 | SLOT(itemPressed(int, QIconViewItem *)) ); |
636 | 630 | ||
637 | tools = 0; | 631 | tools = 0; |
638 | setBackgroundType( Ruled, QString::null ); | 632 | setBackgroundType( Ruled, QString::null ); |
639 | } | 633 | } |
640 | 634 | ||
641 | LauncherView::~LauncherView() | 635 | LauncherView::~LauncherView() |
642 | { | 636 | { |
637 | if ( bgCache && bgCache->contains( bgName ) ) | ||
638 | (*bgCache)[bgName]->ref--; | ||
639 | } | ||
640 | |||
641 | void LauncherView::hideIcons() | ||
642 | { | ||
643 | icons->hide(); | ||
643 | } | 644 | } |
644 | 645 | ||
645 | void LauncherView::setToolsEnabled(bool y) | 646 | void LauncherView::setToolsEnabled(bool y) |
646 | { | 647 | { |
647 | if ( !y != !tools ) { | 648 | if ( !y != !tools ) { |
648 | if ( y ) { | 649 | if ( y ) { |
649 | tools = new QHBox(this); | 650 | tools = new QHBox(this); |
650 | 651 | ||
651 | // Type filter | 652 | // Type filter |
652 | typemb = new QComboBox(tools); | 653 | typemb = new QComboBox(tools); |
654 | QSizePolicy p = typemb->sizePolicy(); | ||
655 | p.setHorData(QSizePolicy::Expanding); | ||
656 | typemb->setSizePolicy(p); | ||
653 | 657 | ||
654 | // Category filter | 658 | // Category filter |
655 | catmb = new CategorySelect(tools); | ||
656 | |||
657 | updateTools(); | 659 | updateTools(); |
658 | tools->show(); | 660 | tools->show(); |
661 | |||
662 | // Always show vscrollbar | ||
663 | icons->setVScrollBarMode( QScrollView::AlwaysOn ); | ||
659 | } else { | 664 | } else { |
660 | delete tools; | 665 | delete tools; |
661 | tools = 0; | 666 | tools = 0; |
662 | } | 667 | } |
663 | } | 668 | } |
664 | } | 669 | } |
665 | 670 | ||
666 | void LauncherView::updateTools() | 671 | void LauncherView::updateTools() |
667 | { | 672 | { |
668 | disconnect( typemb, SIGNAL(activated(int)), | 673 | disconnect( typemb, SIGNAL(activated(int)), |
669 | this, SLOT(showType(int)) ); | 674 | this, SLOT(showType(int)) ); |
670 | disconnect( catmb, SIGNAL(signalSelected(int)), | 675 | if ( catmb ) disconnect( catmb, SIGNAL(signalSelected(int)), |
671 | this, SLOT(showCategory(int)) ); | 676 | this, SLOT(showCategory(int)) ); |
672 | 677 | ||
678 | // ### I want to remove this | ||
673 | icons->updateCategoriesAndMimeTypes(); | 679 | icons->updateCategoriesAndMimeTypes(); |
674 | 680 | ||
675 | QString prev; | 681 | QString prev; |
676 | 682 | ||
677 | // Type filter | 683 | // Type filter |
678 | QStringList types; | 684 | QStringList types; |
679 | typelist = icons->mimeTypes(); | 685 | typelist = icons->mimeTypes(); |
680 | for (QStringList::ConstIterator it = typelist.begin(); it!=typelist.end(); ++it) { | 686 | for (QStringList::ConstIterator it = typelist.begin(); it!=typelist.end(); ++it) { |
681 | QString t = *it; | 687 | QString t = *it; |
682 | if ( t.left(12) == "application/" ) { | 688 | if ( t.left(12) == "application/" ) { |
683 | MimeType mt(t); | 689 | MimeType mt(t); |
684 | const AppLnk* app = mt.application(); | 690 | const AppLnk* app = mt.application(); |
685 | if ( app ) | 691 | if ( app ) |
686 | t = app->name(); | 692 | t = app->name(); |
687 | else | 693 | else |
688 | t = t.mid(12); | 694 | t = t.mid(12); |
689 | } else { | 695 | } else { |
690 | t[0] = t[0].upper(); | 696 | t[0] = t[0].upper(); |
691 | } | 697 | } |
692 | types += tr("%1 files").arg(t); | 698 | types += t; |
693 | } | 699 | } |
694 | types << tr("All types of file"); | 700 | types << tr("All types"); |
695 | prev = typemb->currentText(); | 701 | prev = typemb->currentText(); |
696 | typemb->clear(); | 702 | typemb->clear(); |
697 | typemb->insertStringList(types); | 703 | typemb->insertStringList(types); |
698 | for (int i=0; i<typemb->count(); i++) { | 704 | for (int i=0; i<typemb->count(); i++) { |
699 | if ( typemb->text(i) == prev ) { | 705 | if ( typemb->text(i) == prev ) { |
700 | typemb->setCurrentItem(i); | 706 | typemb->setCurrentItem(i); |
701 | break; | 707 | break; |
702 | } | 708 | } |
703 | } | 709 | } |
704 | if ( prev.isNull() ) | 710 | if ( prev.isNull() ) |
705 | typemb->setCurrentItem(typemb->count()-1); | 711 | typemb->setCurrentItem(typemb->count()-1); |
706 | 712 | ||
713 | int pcat = catmb ? catmb->currentCategory() : -2; | ||
714 | if ( !catmb ) | ||
715 | catmb = new CategorySelect(tools); | ||
707 | Categories cats( 0 ); | 716 | Categories cats( 0 ); |
708 | cats.load( categoryFileName() ); | 717 | cats.load( categoryFileName() ); |
709 | QArray<int> vl( 0 ); | 718 | QArray<int> vl( 0 ); |
710 | catmb->setCategories( vl, "Document View", // No tr | 719 | catmb->setCategories( vl, "Document View", // No tr |
711 | tr("Document View") ); | 720 | tr("Document View") ); |
712 | catmb->setRemoveCategoryEdit( TRUE ); | 721 | catmb->setRemoveCategoryEdit( TRUE ); |
713 | catmb->setAllCategories( TRUE ); | 722 | catmb->setAllCategories( TRUE ); |
723 | catmb->setCurrentCategory(pcat); | ||
724 | |||
725 | // if type has changed we need to redisplay | ||
726 | if ( typemb->currentText() != prev ) | ||
727 | showType( typemb->currentItem() ); | ||
714 | 728 | ||
715 | connect(typemb, SIGNAL(activated(int)), this, SLOT(showType(int))); | 729 | connect(typemb, SIGNAL(activated(int)), this, SLOT(showType(int))); |
716 | connect(catmb, SIGNAL(signalSelected(int)), this, SLOT(showCategory(int))); | 730 | connect(catmb, SIGNAL(signalSelected(int)), this, SLOT(showCategory(int))); |
717 | } | 731 | } |
718 | 732 | ||
719 | void LauncherView::sortBy(int s) | 733 | void LauncherView::sortBy(int s) |
720 | { | 734 | { |
721 | icons->setSortMethod((LauncherIconView::SortMethod)s); | 735 | icons->setSortMethod((LauncherIconView::SortMethod)s); |
722 | } | 736 | } |
723 | 737 | ||
724 | void LauncherView::showType(int t) | 738 | void LauncherView::showType(int t) |
725 | { | 739 | { |
@@ -749,139 +763,196 @@ void LauncherView::setViewMode( ViewMode m ) | |||
749 | icons->setItemTextPos( QIconView::Right ); | 763 | icons->setItemTextPos( QIconView::Right ); |
750 | break; | 764 | break; |
751 | case Icon: | 765 | case Icon: |
752 | icons->setItemTextPos( QIconView::Bottom ); | 766 | icons->setItemTextPos( QIconView::Bottom ); |
753 | break; | 767 | break; |
754 | } | 768 | } |
755 | icons->hideOrShowItems( FALSE ); | 769 | icons->hideOrShowItems( FALSE ); |
756 | icons->viewport()->setUpdatesEnabled( TRUE ); | 770 | icons->viewport()->setUpdatesEnabled( TRUE ); |
757 | vmode = m; | 771 | vmode = m; |
758 | } | 772 | } |
759 | } | 773 | } |
760 | 774 | ||
775 | // | ||
776 | // User images may require scaling. | ||
777 | // | ||
778 | QImage LauncherView::loadBackgroundImage(QString &bgName) | ||
779 | { | ||
780 | QImageIO imgio; | ||
781 | QSize ds = qApp->desktop()->size(); // should be launcher, not desktop | ||
782 | bool further_scaling = TRUE; | ||
783 | |||
784 | imgio.setFileName( bgName ); | ||
785 | imgio.setParameters("GetHeaderInformation"); | ||
786 | |||
787 | if (imgio.read() == FALSE) { | ||
788 | return imgio.image(); | ||
789 | } | ||
790 | |||
791 | if (imgio.image().width() < ds.width() && | ||
792 | imgio.image().height() < ds.height()) { | ||
793 | further_scaling = FALSE; | ||
794 | } | ||
795 | |||
796 | if (!imgio.image().bits()) { | ||
797 | // | ||
798 | // Scale and load. Note we don't scale up. | ||
799 | // | ||
800 | QString param( "Scale( %1, %2, ScaleMin )" ); // No tr | ||
801 | imgio.setParameters(further_scaling ? | ||
802 | param.arg(ds.width()).arg(ds.height()).latin1() : | ||
803 | ""); | ||
804 | imgio.read(); | ||
805 | } else { | ||
806 | if (further_scaling) { | ||
807 | intt1 = imgio.image().width() * ds.height(); | ||
808 | int t2 = imgio.image().height() * ds.width(); | ||
809 | int dsth = ds.height(); | ||
810 | int dstw = ds.width(); | ||
811 | |||
812 | if (t1 > t2) { | ||
813 | dsth = t2 / imgio.image().width(); | ||
814 | } else { | ||
815 | dstw = t1 / imgio.image().height(); | ||
816 | } | ||
817 | |||
818 | // | ||
819 | // Loader didn't scale for us. Do it manually. | ||
820 | // | ||
821 | return imgio.image().smoothScale(dstw, dsth); | ||
822 | } | ||
823 | } | ||
824 | |||
825 | return imgio.image(); | ||
826 | } | ||
827 | |||
761 | void LauncherView::setBackgroundType( BackgroundType t, const QString &val ) | 828 | void LauncherView::setBackgroundType( BackgroundType t, const QString &val ) |
762 | { | 829 | { |
763 | if ( !bgCache ) | 830 | if ( !bgCache ) { |
764 | bgCache = new QMap<QString,BgPixmap*>; | 831 | bgCache = new QMap<QString,BgPixmap*>; |
832 | qAddPostRoutine( cleanup_cache ); | ||
833 | } | ||
834 | |||
765 | if ( bgCache->contains( bgName ) ) | 835 | if ( bgCache->contains( bgName ) ) |
766 | (*bgCache)[bgName]->ref--; | 836 | (*bgCache)[bgName]->ref--; |
837 | bgName = ""; | ||
838 | |||
839 | QPixmap bg; | ||
767 | 840 | ||
768 | switch ( t ) { | 841 | switch ( t ) { |
769 | case Ruled: { | 842 | case Ruled: { |
770 | bgName = QString("Ruled_%1").arg(colorGroup().background().name()); // No tr | 843 | bgName = QString("Ruled_%1").arg(colorGroup().background().name()); // No tr |
771 | QPixmap bg; | ||
772 | if ( bgCache->contains( bgName ) ) { | 844 | if ( bgCache->contains( bgName ) ) { |
773 | (*bgCache)[bgName]->ref++; | 845 | (*bgCache)[bgName]->ref++; |
774 | bg = (*bgCache)[bgName]->pm; | 846 | bg = (*bgCache)[bgName]->pm; |
775 | } else { | 847 | } else { |
776 | bg.resize( width(), 9 ); | 848 | bg.resize( width(), 9 ); |
777 | QPainter painter( &bg ); | 849 | QPainter painter( &bg ); |
778 | for ( int i = 0; i < 3; i++ ) { | 850 | for ( int i = 0; i < 3; i++ ) { |
779 | painter.setPen( white ); | 851 | painter.setPen( white ); |
780 | painter.drawLine( 0, i*3, width()-1, i*3 ); | 852 | painter.drawLine( 0, i*3, width()-1, i*3 ); |
781 | painter.drawLine( 0, i*3+1, width()-1, i*3+1 ); | 853 | painter.drawLine( 0, i*3+1, width()-1, i*3+1 ); |
782 | painter.setPen( colorGroup().background().light(105) ); | 854 | painter.setPen( colorGroup().background().light(105) ); |
783 | painter.drawLine( 0, i*3+2, width()-1, i*3+2 ); | 855 | painter.drawLine( 0, i*3+2, width()-1, i*3+2 ); |
784 | } | 856 | } |
785 | painter.end(); | 857 | painter.end(); |
786 | bgCache->insert( bgName, new BgPixmap(bg) ); | 858 | bgCache->insert( bgName, new BgPixmap(bg) ); |
787 | } | 859 | } |
788 | icons->setBackgroundPixmap( bg ); | ||
789 | break; | 860 | break; |
790 | } | 861 | } |
791 | 862 | ||
792 | case SolidColor: | ||
793 | icons->setBackgroundPixmap( QPixmap() ); | ||
794 | if ( val.isEmpty() ) { | ||
795 | icons->setBackgroundColor( colorGroup().base() ); | ||
796 | } else { | ||
797 | icons->setBackgroundColor( val ); | ||
798 | } | ||
799 | bgName = ""; | ||
800 | break; | ||
801 | |||
802 | case Image: | 863 | case Image: |
803 | bgName = val; | 864 | if (!val.isEmpty()) { |
804 | if ( bgCache->contains( bgName ) ) { | 865 | bgName = val; |
805 | (*bgCache)[bgName]->ref++; | 866 | if ( bgCache->contains( bgName ) ) { |
806 | icons->setBackgroundPixmap( (*bgCache)[bgName]->pm ); | 867 | (*bgCache)[bgName]->ref++; |
807 | } else { | 868 | bg = (*bgCache)[bgName]->pm; |
808 | QPixmap bg( Resource::loadPixmap( val ) ); | 869 | } else { |
809 | if ( bg.isNull() ) { | 870 | QString imgFile = bgName; |
810 | QImageIO imgio; | 871 | bool tile = FALSE; |
811 | imgio.setFileName( bgName ); | 872 | if ( imgFile[0]!='/' || !QFile::exists(imgFile) ) { |
812 | QSize ds = qApp->desktop()->size(); | 873 | imgFile = Resource::findPixmap( imgFile ); |
813 | QString param( "Scale( %1, %2, ScaleMin )" ); // No tr | 874 | tile = TRUE; |
814 | imgio.setParameters( param.arg(ds.width()).arg(ds.height()).latin1() ); | 875 | } |
815 | imgio.read(); | 876 | QImage img = loadBackgroundImage(imgFile); |
816 | bg = imgio.image(); | 877 | |
878 | |||
879 | if ( img.depth() == 1 ) | ||
880 | img = img.convertDepth(8); | ||
881 | img.setAlphaBuffer(FALSE); | ||
882 | bg.convertFromImage(img); | ||
883 | bgCache->insert( bgName, new BgPixmap(bg) ); | ||
817 | } | 884 | } |
818 | bgCache->insert( bgName, new BgPixmap(bg) ); | ||
819 | icons->setBackgroundPixmap( bg ); | ||
820 | } | 885 | } |
821 | break; | 886 | break; |
887 | |||
888 | case SolidColor: | ||
889 | default: | ||
890 | break; | ||
822 | } | 891 | } |
823 | 892 | ||
824 | // remove unreferenced backgrounds. | 893 | const QObjectList *list = queryList( "QWidget", 0, FALSE ); |
825 | QMap<QString,BgPixmap*>::Iterator it = bgCache->begin(); | 894 | QObject *obj; |
826 | while ( it != bgCache->end() ) { | 895 | for ( QObjectListIt it( *list ); (obj=it.current()); ++it ) { |
827 | QMap<QString,BgPixmap*>::Iterator curr = it; | 896 | if ( obj->isWidgetType() ) { |
828 | ++it; | 897 | QWidget *w = (QWidget*)obj; |
829 | if ( (*curr)->ref == 0 ) { | 898 | w->setBackgroundPixmap( bg ); |
830 | delete (*curr); | 899 | if ( bgName.isEmpty() ) { |
831 | bgCache->remove( curr ); | 900 | // Solid Color |
901 | if ( val.isEmpty() ) | ||
902 | w->setBackgroundColor( colorGroup().base() ); | ||
903 | else | ||
904 | w->setBackgroundColor( val ); | ||
905 | } else { | ||
906 | // Ruled or Image pixmap | ||
907 | w->setBackgroundOrigin( ParentOrigin ); | ||
908 | } | ||
832 | } | 909 | } |
833 | } | 910 | } |
911 | delete list; | ||
834 | 912 | ||
835 | bgType = t; | 913 | bgType = t; |
836 | icons->viewport()->update(); | 914 | icons->viewport()->update(); |
915 | |||
916 | QTimer::singleShot( 1000, this, SLOT(flushBgCache()) ); | ||
837 | } | 917 | } |
838 | 918 | ||
839 | void LauncherView::setTextColor( const QColor &tc ) | 919 | void LauncherView::setTextColor( const QColor &tc ) |
840 | { | 920 | { |
841 | textCol = tc; | 921 | textCol = tc; |
842 | QColorGroup cg = icons->colorGroup(); | 922 | QColorGroup cg = icons->colorGroup(); |
843 | cg.setColor( QColorGroup::Text, tc ); | 923 | cg.setColor( QColorGroup::Text, tc ); |
844 | icons->setPalette( QPalette(cg,cg,cg) ); | 924 | icons->setPalette( QPalette(cg,cg,cg) ); |
845 | icons->viewport()->update(); | 925 | icons->viewport()->update(); |
846 | } | 926 | } |
847 | 927 | ||
848 | void LauncherView::setViewFont( const QFont &f ) | 928 | void LauncherView::setViewFont( const QFont &f ) |
849 | { | 929 | { |
850 | icons->setFont( f ); | 930 | icons->setFont( f ); |
931 | icons->hideOrShowItems( FALSE ); | ||
851 | } | 932 | } |
852 | 933 | ||
853 | void LauncherView::unsetViewFont( ) | 934 | void LauncherView::clearViewFont() |
854 | { | 935 | { |
855 | icons->unsetFont( ); | 936 | icons->unsetFont(); |
937 | icons->hideOrShowItems( FALSE ); | ||
856 | } | 938 | } |
857 | 939 | ||
858 | void LauncherView::resizeEvent(QResizeEvent *e) | 940 | void LauncherView::resizeEvent(QResizeEvent *e) |
859 | { | 941 | { |
860 | QVBox::resizeEvent( e ); | 942 | QVBox::resizeEvent( e ); |
861 | if ( e->size().width() != e->oldSize().width() ) | 943 | if ( e->size().width() != e->oldSize().width() ) |
862 | sort(); | 944 | sort(); |
863 | } | 945 | } |
864 | 946 | ||
865 | void LauncherView::populate( AppLnkSet *folder, const QString& typefilter ) | ||
866 | { | ||
867 | icons->clear(); | ||
868 | internalPopulate( folder, typefilter ); | ||
869 | } | ||
870 | |||
871 | QString LauncherView::getAllDocLinkInfo() const | ||
872 | { | ||
873 | return icons->getAllDocLinkInfo(); | ||
874 | } | ||
875 | |||
876 | void LauncherView::selectionChanged() | 947 | void LauncherView::selectionChanged() |
877 | { | 948 | { |
878 | QIconViewItem* item = icons->currentItem(); | 949 | QIconViewItem* item = icons->currentItem(); |
879 | if ( item && item->isSelected() ) { | 950 | if ( item && item->isSelected() ) { |
880 | AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); | 951 | AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); |
881 | if ( icons->inKeyEvent() ) // not for mouse press | 952 | if ( icons->inKeyEvent() ) // not for mouse press |
882 | emit clicked( appLnk ); | 953 | emit clicked( appLnk ); |
883 | item->setSelected(FALSE); | 954 | item->setSelected(FALSE); |
884 | } | 955 | } |
885 | } | 956 | } |
886 | 957 | ||
887 | void LauncherView::returnPressed( QIconViewItem *item ) | 958 | void LauncherView::returnPressed( QIconViewItem *item ) |
@@ -902,80 +973,88 @@ void LauncherView::itemClicked( int btn, QIconViewItem *item ) | |||
902 | emit clicked( appLnk ); | 973 | emit clicked( appLnk ); |
903 | } | 974 | } |
904 | item->setSelected(FALSE); | 975 | item->setSelected(FALSE); |
905 | } | 976 | } |
906 | } | 977 | } |
907 | 978 | ||
908 | void LauncherView::itemPressed( int btn, QIconViewItem *item ) | 979 | void LauncherView::itemPressed( int btn, QIconViewItem *item ) |
909 | { | 980 | { |
910 | if ( item ) { | 981 | if ( item ) { |
911 | AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); | 982 | AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); |
912 | if ( btn == RightButton ) | 983 | if ( btn == RightButton ) |
913 | emit rightPressed( appLnk ); | 984 | emit rightPressed( appLnk ); |
914 | /* | 985 | else if ( btn == ShiftButton ) |
915 | else if ( btn == LeftButton ) | 986 | emit rightPressed( appLnk ); |
916 | emit clicked( appLnk ); | ||
917 | */ | ||
918 | item->setSelected(FALSE); | 987 | item->setSelected(FALSE); |
919 | } | 988 | } |
920 | } | 989 | } |
921 | 990 | ||
922 | void LauncherView::internalPopulate( AppLnkSet *folder, const QString& typefilter ) | 991 | void LauncherView::removeAllItems() |
923 | { | 992 | { |
924 | QListIterator<AppLnk> it( folder->children() ); | 993 | icons->clear(); |
925 | icons->setTypeFilter(typefilter,FALSE); | ||
926 | |||
927 | while ( it.current() ) { | ||
928 | // show only the icons for existing files | ||
929 | if (QFile(it.current()->file()).exists() || ( it.current()->file().left(4) == "http" )) { | ||
930 | icons->addItem(*it,FALSE); | ||
931 | } | ||
932 | else { | ||
933 | //maybe insert some .desktop file deletion code later | ||
934 | //maybe dir specific | ||
935 | } | ||
936 | ++it; | ||
937 | } | ||
938 | |||
939 | icons->sort(); | ||
940 | } | 994 | } |
941 | 995 | ||
942 | bool LauncherView::removeLink(const QString& linkfile) | 996 | bool LauncherView::removeLink(const QString& linkfile) |
943 | { | 997 | { |
944 | return icons->removeLink(linkfile); | 998 | return icons->removeLink(linkfile); |
945 | } | 999 | } |
946 | 1000 | ||
1001 | void LauncherView::setSortEnabled( bool v ) | ||
1002 | { | ||
1003 | icons->setSorting( v ); | ||
1004 | if ( v ) | ||
1005 | sort(); | ||
1006 | } | ||
1007 | |||
1008 | void LauncherView::setUpdatesEnabled( bool u ) | ||
1009 | { | ||
1010 | icons->setUpdatesEnabled( u ); | ||
1011 | } | ||
1012 | |||
947 | void LauncherView::sort() | 1013 | void LauncherView::sort() |
948 | { | 1014 | { |
949 | icons->sort(); | 1015 | icons->sort(); |
950 | } | 1016 | } |
951 | 1017 | ||
952 | void LauncherView::addItem(AppLnk* app, bool resort) | 1018 | void LauncherView::addItem(AppLnk* app, bool resort) |
953 | { | 1019 | { |
954 | icons->addItem(app,resort); | 1020 | icons->addItem(app,resort); |
955 | } | 1021 | } |
956 | 1022 | ||
957 | void LauncherView::setFileSystems(const QList<FileSystem> &) | ||
958 | { | ||
959 | // ### does nothing now... | ||
960 | } | ||
961 | |||
962 | void LauncherView::paletteChange( const QPalette &p ) | 1023 | void LauncherView::paletteChange( const QPalette &p ) |
963 | { | 1024 | { |
964 | icons->unsetPalette(); | 1025 | icons->unsetPalette(); |
965 | QVBox::paletteChange( p ); | 1026 | QVBox::paletteChange( p ); |
966 | if ( bgType == Ruled ) | 1027 | if ( bgType == Ruled ) |
967 | setBackgroundType( Ruled, QString::null ); | 1028 | setBackgroundType( Ruled, QString::null ); |
968 | QColorGroup cg = icons->colorGroup(); | 1029 | QColorGroup cg = icons->colorGroup(); |
969 | cg.setColor( QColorGroup::Text, textCol ); | 1030 | cg.setColor( QColorGroup::Text, textCol ); |
970 | icons->setPalette( QPalette(cg,cg,cg) ); | 1031 | icons->setPalette( QPalette(cg,cg,cg) ); |
971 | } | 1032 | } |
972 | 1033 | ||
1034 | void LauncherView::fontChanged(const QFont&) | ||
1035 | { | ||
1036 | qDebug("LauncherView::fontChanged()"); | ||
1037 | icons->hideOrShowItems( FALSE ); | ||
1038 | } | ||
973 | 1039 | ||
974 | void LauncherView::setBusyIndicatorType ( const QString &type ) | 1040 | void LauncherView::relayout(void) |
975 | { | 1041 | { |
976 | if ( type. lower ( ) == "blink" ) | 1042 | icons->hideOrShowItems(FALSE); |
977 | icons-> setBusyIndicatorType ( BIT_Blinking ); | 1043 | } |
978 | else | 1044 | |
979 | icons-> setBusyIndicatorType ( BIT_Normal ); | 1045 | void LauncherView::flushBgCache() |
1046 | { | ||
1047 | if ( !bgCache ) | ||
1048 | return; | ||
1049 | // remove unreferenced backgrounds. | ||
1050 | QMap<QString,BgPixmap*>::Iterator it = bgCache->begin(); | ||
1051 | while ( it != bgCache->end() ) { | ||
1052 | QMap<QString,BgPixmap*>::Iterator curr = it; | ||
1053 | ++it; | ||
1054 | if ( (*curr)->ref == 0 ) { | ||
1055 | delete (*curr); | ||
1056 | bgCache->remove( curr ); | ||
1057 | } | ||
1058 | } | ||
980 | } | 1059 | } |
981 | 1060 | ||