summaryrefslogtreecommitdiff
authorsandman <sandman>2002-09-30 10:12:36 (UTC)
committer sandman <sandman>2002-09-30 10:12:36 (UTC)
commitece83520d6bf5c481275a3d4a8e792749119fa08 (patch) (unidiff)
treeeb1c8bfdc013a3aca46c4feaa2ff50e38e5d632b
parenta999acbcd1b8bc1715f2ad2dda6acedf423b89ea (diff)
downloadopie-ece83520d6bf5c481275a3d4a8e792749119fa08.zip
opie-ece83520d6bf5c481275a3d4a8e792749119fa08.tar.gz
opie-ece83520d6bf5c481275a3d4a8e792749119fa08.tar.bz2
Optimizations for the new busy indicator:
- QPixmaps are buffered now - real fix for the startTimer 100% cpu-load bug (was a typo)
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/launcherview.cpp71
1 files changed, 36 insertions, 35 deletions
diff --git a/core/launcher/launcherview.cpp b/core/launcher/launcherview.cpp
index dbcb0d7..5daaeff 100644
--- a/core/launcher/launcherview.cpp
+++ b/core/launcher/launcherview.cpp
@@ -38,164 +38,165 @@
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 <qpainter.h> 41#include <qpainter.h>
42#include <qregexp.h> 42#include <qregexp.h>
43#include <qtoolbutton.h> 43#include <qtoolbutton.h>
44#include <qimage.h> 44#include <qimage.h>
45 45
46 46
47class BgPixmap 47class BgPixmap
48{ 48{
49public: 49public:
50 BgPixmap( const QPixmap &p ) : pm(p), ref(1) {} 50 BgPixmap( const QPixmap &p ) : pm(p), ref(1) {}
51 QPixmap pm; 51 QPixmap pm;
52 int ref; 52 int ref;
53}; 53};
54 54
55static QMap<QString,BgPixmap*> *bgCache = 0; 55static QMap<QString,BgPixmap*> *bgCache = 0;
56 56
57class LauncherIconView : public QIconView { 57class LauncherIconView : public QIconView {
58public: 58public:
59 LauncherIconView( QWidget* parent, const char* name=0 ) : 59 LauncherIconView( QWidget* parent, const char* name=0 ) :
60 QIconView(parent,name), 60 QIconView(parent,name),
61 tf(""), 61 tf(""),
62 cf(0), 62 cf(0),
63 bsy(0), 63 bsy(0),
64 bigIcns(TRUE), 64 bigIcns(TRUE),
65 bgColor(white) 65 bgColor(white)
66 { 66 {
67 sortmeth = Name; 67 sortmeth = Name;
68 hidden.setAutoDelete(TRUE); 68 hidden.setAutoDelete(TRUE);
69 ike = FALSE; 69 ike = FALSE;
70 busytimer = 0; 70 busytimer = 0;
71 calculateGrid( Bottom ); 71 calculateGrid( Bottom );
72 } 72 }
73 73
74 ~LauncherIconView() 74 ~LauncherIconView()
75 { 75 {
76#if 0 // debuggery 76#if 0 // debuggery
77 QListIterator<AppLnk> it(hidden); 77 QListIterator<AppLnk> it(hidden);
78 AppLnk* l; 78 AppLnk* l;
79 while ((l=it.current())) { 79 while ((l=it.current())) {
80 ++it; 80 ++it;
81 //qDebug("%p: hidden (should remove)",l); 81 //qDebug("%p: hidden (should remove)",l);
82 } 82 }
83#endif 83#endif
84 } 84 }
85 85
86 QPixmap* busyPixmap() const { return (QPixmap*)&bpm; } 86 QPixmap* busyPixmap() const { return (QPixmap*)&bpm[::abs(busystate)]; }
87 QIconViewItem* busyItem() const { return bsy; } 87 QIconViewItem* busyItem() const { return bsy; }
88 void setBigIcons( bool bi ) { bigIcns = bi; } 88 void setBigIcons( bool bi ) { bigIcns = bi; }
89 89
90 void updateCategoriesAndMimeTypes(); 90 void updateCategoriesAndMimeTypes();
91 91
92 void doAutoScroll() 92 void doAutoScroll()
93 { 93 {
94 // We don't want rubberbanding (yet) 94 // We don't want rubberbanding (yet)
95 } 95 }
96 96
97 void setBusy(bool on) 97 void setBusy(bool on)
98 { 98 {
99 QIconViewItem *c = on ? currentItem() : 0; 99 QIconViewItem *c = on ? currentItem() : 0;
100 if ( bsy != c ) { 100 if ( bsy != c ) {
101 if ( bsy ) 101 if ( bsy )
102 bsy-> repaint ( ); 102 bsy-> repaint ( );
103 bsy = c; 103 bsy = c;
104 104
105 if ( bsy ) { 105 if ( bsy ) {
106 busystate = 5;
107 for ( int i = 0; i <= 5; i++ )
108 bpm [i] = QPixmap ( );
109 timerEvent ( 0 );
106 busytimer = startTimer ( 150 ); 110 busytimer = startTimer ( 150 );
107 busystate = 50;
108 // not sure what this startTimer is for, maybe i am just to tired. But
109 // currently that causes 100% cpuload on app launch
110 //startTimer ( 0 );
111 } 111 }
112 else 112 else
113 killTimer ( busytimer ); 113 killTimer ( busytimer );
114 } 114 }
115 } 115 }
116 116
117 virtual void timerEvent ( QTimerEvent *te ) 117 virtual void timerEvent ( QTimerEvent *te )
118 { 118 {
119 if ( !te || ( te-> timerId ( ) == busytimer )) { 119 if ( !te || ( te-> timerId ( ) == busytimer )) {
120 if ( bsy ) { 120 if ( bsy ) {
121 QPixmap *src = bsy-> QIconViewItem::pixmap(); 121 if ( bpm [::abs(busystate)]. isNull ( )) {
122 QImage img = src->convertToImage(); 122 QPixmap *src = bsy-> QIconViewItem::pixmap();
123 QRgb* rgb; 123 QImage img = src->convertToImage();
124 int count; 124 QRgb* rgb;
125 if ( img.depth() == 32 ) { 125 int count;
126 rgb = (QRgb*)img.bits(); 126 if ( img.depth() == 32 ) {
127 count = img.bytesPerLine()/sizeof(QRgb)*img.height(); 127 rgb = (QRgb*)img.bits();
128 } else { 128 count = img.bytesPerLine()/sizeof(QRgb)*img.height();
129 rgb = img.colorTable(); 129 } else {
130 count = img.numColors(); 130 rgb = img.colorTable();
131 } 131 count = img.numColors();
132 int rc, gc, bc; 132 }
133 int bs = ::abs ( busystate ) + 25; 133 int rc, gc, bc;
134 colorGroup().highlight().rgb( &rc, &gc, &bc ); 134 int bs = ::abs ( busystate * 10 ) + 25;
135 rc = rc * bs / 100; 135 colorGroup().highlight().rgb( &rc, &gc, &bc );
136 gc = gc * bs / 100; 136 rc = rc * bs / 100;
137 bc = bc * bs / 100; 137 gc = gc * bs / 100;
138 bc = bc * bs / 100;
138 139
139 for ( int r = 0; r < count; r++, rgb++ ) { 140 for ( int r = 0; r < count; r++, rgb++ ) {
140 int ri = rc + qRed ( *rgb ) * ( 100 - bs ) / 100; 141 int ri = rc + qRed ( *rgb ) * ( 100 - bs ) / 100;
141 int gi = gc + qGreen ( *rgb ) * ( 100 - bs ) / 100; 142 int gi = gc + qGreen ( *rgb ) * ( 100 - bs ) / 100;
142 int bi = bc + qBlue ( *rgb ) * ( 100 - bs ) / 100; 143 int bi = bc + qBlue ( *rgb ) * ( 100 - bs ) / 100;
143 int ai = qAlpha ( *rgb ); 144 int ai = qAlpha ( *rgb );
144 *rgb = qRgba ( ri, gi, bi, ai ); 145 *rgb = qRgba ( ri, gi, bi, ai );
146 }
147
148 bpm [::abs(busystate)].convertFromImage( img );
145 } 149 }
146
147 bpm.convertFromImage( img );
148
149 bsy-> repaint ( ); 150 bsy-> repaint ( );
150 151
151 busystate += 10; 152 busystate++;
152 if ( busystate > 50 ) 153 if ( busystate > 5 )
153 busystate = -40; 154 busystate = -4;
154 } 155 }
155 } 156 }
156 } 157 }
157 158
158 bool inKeyEvent() const { return ike; } 159 bool inKeyEvent() const { return ike; }
159 void keyPressEvent(QKeyEvent* e) 160 void keyPressEvent(QKeyEvent* e)
160 { 161 {
161 ike = TRUE; 162 ike = TRUE;
162 if ( e->key() == Key_F33 /* OK button */ || e->key() == Key_Space ) 163 if ( e->key() == Key_F33 /* OK button */ || e->key() == Key_Space )
163 returnPressed(currentItem()); 164 returnPressed(currentItem());
164 QIconView::keyPressEvent(e); 165 QIconView::keyPressEvent(e);
165 ike = FALSE; 166 ike = FALSE;
166 } 167 }
167 168
168 void addItem(AppLnk* app, bool resort=TRUE); 169 void addItem(AppLnk* app, bool resort=TRUE);
169 bool removeLink(const QString& linkfile); 170 bool removeLink(const QString& linkfile);
170 171
171 QStringList mimeTypes() const; 172 QStringList mimeTypes() const;
172 QStringList categories() const; 173 QStringList categories() const;
173 174
174 void clear() 175 void clear()
175 { 176 {
176 mimes.clear(); 177 mimes.clear();
177 cats.clear(); 178 cats.clear();
178 QIconView::clear(); 179 QIconView::clear();
179 hidden.clear(); 180 hidden.clear();
180 } 181 }
181 182
182 void addCatsAndMimes(AppLnk* app) 183 void addCatsAndMimes(AppLnk* app)
183 { 184 {
184 // QStringList c = app->categories(); 185 // QStringList c = app->categories();
185 // for (QStringList::ConstIterator cit=c.begin(); cit!=c.end(); ++cit) { 186 // for (QStringList::ConstIterator cit=c.begin(); cit!=c.end(); ++cit) {
186 // cats.replace(*cit,(void*)1); 187 // cats.replace(*cit,(void*)1);
187 // } 188 // }
188 QString maj=app->type(); 189 QString maj=app->type();
189 int sl=maj.find('/'); 190 int sl=maj.find('/');
190 if (sl>=0) { 191 if (sl>=0) {
191 QString k; 192 QString k;
192 k = maj.left(12) == "application/" ? maj : maj.left(sl); 193 k = maj.left(12) == "application/" ? maj : maj.left(sl);
193 mimes.replace(k,(void*)1); 194 mimes.replace(k,(void*)1);
194 } 195 }
195 } 196 }
196 197
197 void setBackgroundPixmap( const QPixmap &pm ) { 198 void setBackgroundPixmap( const QPixmap &pm ) {
198 bgPixmap = pm; 199 bgPixmap = pm;
199 } 200 }
200 201
201 void setBackgroundColor( const QColor &c ) { 202 void setBackgroundColor( const QColor &c ) {
@@ -266,97 +267,97 @@ public:
266 } 267 }
267 268
268 QString getAllDocLinkInfo() const; 269 QString getAllDocLinkInfo() const;
269 270
270protected: 271protected:
271 272
272 void styleChange( QStyle &old ) 273 void styleChange( QStyle &old )
273 { 274 {
274 QIconView::styleChange( old ); 275 QIconView::styleChange( old );
275 calculateGrid( itemTextPos() ); 276 calculateGrid( itemTextPos() );
276 } 277 }
277 278
278 void calculateGrid( ItemTextPos pos ) 279 void calculateGrid( ItemTextPos pos )
279 { 280 {
280 int dw = QApplication::desktop()->width(); 281 int dw = QApplication::desktop()->width();
281 int viewerWidth = dw-style().scrollBarExtent().width(); 282 int viewerWidth = dw-style().scrollBarExtent().width();
282 if ( pos == Bottom ) { 283 if ( pos == Bottom ) {
283 int cols = 3; 284 int cols = 3;
284 if ( viewerWidth <= 200 ) 285 if ( viewerWidth <= 200 )
285 cols = 2; 286 cols = 2;
286 else if ( viewerWidth >= 400 ) 287 else if ( viewerWidth >= 400 )
287 cols = viewerWidth/96; 288 cols = viewerWidth/96;
288 setSpacing( 4 ); 289 setSpacing( 4 );
289 setGridX( (viewerWidth-(cols+1)*spacing())/cols ); 290 setGridX( (viewerWidth-(cols+1)*spacing())/cols );
290 setGridY( fontMetrics().height()*2+24 ); 291 setGridY( fontMetrics().height()*2+24 );
291 } else { 292 } else {
292 int cols = 2; 293 int cols = 2;
293 if ( viewerWidth < 150 ) 294 if ( viewerWidth < 150 )
294 cols = 1; 295 cols = 1;
295 else if ( viewerWidth >= 400 ) 296 else if ( viewerWidth >= 400 )
296 cols = viewerWidth/150; 297 cols = viewerWidth/150;
297 setSpacing( 2 ); 298 setSpacing( 2 );
298 setGridX( (viewerWidth-(cols+1)*spacing())/cols ); 299 setGridX( (viewerWidth-(cols+1)*spacing())/cols );
299 setGridY( fontMetrics().height()+2 ); 300 setGridY( fontMetrics().height()+2 );
300 } 301 }
301 } 302 }
302 303
303private: 304private:
304 QList<AppLnk> hidden; 305 QList<AppLnk> hidden;
305 QDict<void> mimes; 306 QDict<void> mimes;
306 QDict<void> cats; 307 QDict<void> cats;
307 SortMethod sortmeth; 308 SortMethod sortmeth;
308 QRegExp tf; 309 QRegExp tf;
309 int cf; 310 int cf;
310 QIconViewItem* bsy; 311 QIconViewItem* bsy;
311 bool ike; 312 bool ike;
312 bool bigIcns; 313 bool bigIcns;
313 QPixmap bgPixmap; 314 QPixmap bgPixmap;
314 QPixmap bpm; 315 QPixmap bpm [6];
315 QColor bgColor; 316 QColor bgColor;
316 int busytimer; 317 int busytimer;
317 int busystate; 318 int busystate;
318}; 319};
319 320
320 321
321bool LauncherView::bsy=FALSE; 322bool LauncherView::bsy=FALSE;
322 323
323void LauncherView::setBusy(bool on) 324void LauncherView::setBusy(bool on)
324{ 325{
325 icons->setBusy(on); 326 icons->setBusy(on);
326} 327}
327 328
328class LauncherItem : public QIconViewItem 329class LauncherItem : public QIconViewItem
329{ 330{
330public: 331public:
331 LauncherItem( QIconView *parent, AppLnk* applnk, bool bigIcon=TRUE ); 332 LauncherItem( QIconView *parent, AppLnk* applnk, bool bigIcon=TRUE );
332 ~LauncherItem() 333 ~LauncherItem()
333 { 334 {
334 LauncherIconView* liv = (LauncherIconView*)iconView(); 335 LauncherIconView* liv = (LauncherIconView*)iconView();
335 if ( liv->busyItem() == this ) 336 if ( liv->busyItem() == this )
336 liv->setBusy(FALSE); 337 liv->setBusy(FALSE);
337 delete app; 338 delete app;
338 } 339 }
339 340
340 AppLnk* appLnk() const { return app; } 341 AppLnk* appLnk() const { return app; }
341 AppLnk* takeAppLnk() { AppLnk* r=app; app=0; return r; } 342 AppLnk* takeAppLnk() { AppLnk* r=app; app=0; return r; }
342 343
343 virtual int compare ( QIconViewItem * i ) const; 344 virtual int compare ( QIconViewItem * i ) const;
344 345
345 void paintItem( QPainter *p, const QColorGroup &cg ) 346 void paintItem( QPainter *p, const QColorGroup &cg )
346 { 347 {
347 LauncherIconView* liv = (LauncherIconView*)iconView(); 348 LauncherIconView* liv = (LauncherIconView*)iconView();
348 QBrush oldBrush( liv->itemTextBackground() ); 349 QBrush oldBrush( liv->itemTextBackground() );
349 QColorGroup mycg( cg ); 350 QColorGroup mycg( cg );
350 if ( liv->currentItem() == this ) { 351 if ( liv->currentItem() == this ) {
351 liv->setItemTextBackground( cg.brush( QColorGroup::Highlight ) ); 352 liv->setItemTextBackground( cg.brush( QColorGroup::Highlight ) );
352 mycg.setColor( QColorGroup::Text, cg.color( QColorGroup::HighlightedText ) ); 353 mycg.setColor( QColorGroup::Text, cg.color( QColorGroup::HighlightedText ) );
353 } 354 }
354 QIconViewItem::paintItem(p,mycg); 355 QIconViewItem::paintItem(p,mycg);
355 if ( liv->currentItem() == this ) 356 if ( liv->currentItem() == this )
356 liv->setItemTextBackground( oldBrush ); 357 liv->setItemTextBackground( oldBrush );
357 } 358 }
358 359
359 virtual QPixmap* pixmap () const 360 virtual QPixmap* pixmap () const
360 { 361 {
361 const LauncherIconView* liv = (LauncherIconView*)iconView(); 362 const LauncherIconView* liv = (LauncherIconView*)iconView();
362 if ( (const LauncherItem *)liv->busyItem() == this ) 363 if ( (const LauncherItem *)liv->busyItem() == this )