summaryrefslogtreecommitdiff
authorsandman <sandman>2002-10-01 16:20:28 (UTC)
committer sandman <sandman>2002-10-01 16:20:28 (UTC)
commit3352558f31f2f3f5f32730a28f07161fe71787a9 (patch) (unidiff)
tree613a75fb333cfd28f54e29cd2b420889ea4467f0
parent70d2cbd97a6b39b1738e3e6580f916dcf0fbc787 (diff)
downloadopie-3352558f31f2f3f5f32730a28f07161fe71787a9.zip
opie-3352558f31f2f3f5f32730a28f07161fe71787a9.tar.gz
opie-3352558f31f2f3f5f32730a28f07161fe71787a9.tar.bz2
Another performance tweak for busyindicator and alpha-blended bg pixmaps
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/launcherview.cpp22
1 files changed, 18 insertions, 4 deletions
diff --git a/core/launcher/launcherview.cpp b/core/launcher/launcherview.cpp
index 33717bc..e15b150 100644
--- a/core/launcher/launcherview.cpp
+++ b/core/launcher/launcherview.cpp
@@ -79,201 +79,215 @@ public:
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[::abs(busystate)]; } 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 qDebug ( "set busy %d -> %s", on, c ? c-> text ().latin1() : "(null)" ); 100 qDebug ( "set busy %d -> %s", on, c ? c-> text ().latin1() : "(null)" );
101 101
102 if ( bsy != c ) { 102 if ( bsy != c ) {
103 QIconViewItem *oldbsy = bsy; 103 QIconViewItem *oldbsy = bsy;
104 bsy = c; 104 bsy = c;
105 105
106 if ( oldbsy ) 106 if ( oldbsy )
107 oldbsy-> repaint ( ); 107 oldbsy-> repaint ( );
108 108
109 if ( bsy ) { 109 if ( bsy ) {
110 QPixmap *src = bsy-> QIconViewItem::pixmap(); 110 QPixmap *src = bsy-> QIconViewItem::pixmap();
111 for ( int i = 0; i <= 5; i++ ) { 111 for ( int i = 0; i <= 5; i++ ) {
112 QImage img = src->convertToImage(); 112 QImage img = src->convertToImage();
113 QRgb* rgb; 113 QRgb* rgb;
114 int count; 114 int count;
115 if ( img.depth() == 32 ) { 115 if ( img.depth() == 32 ) {
116 rgb = (QRgb*)img.bits(); 116 rgb = (QRgb*)img.bits();
117 count = img.bytesPerLine()/sizeof(QRgb)*img.height(); 117 count = img.bytesPerLine()/sizeof(QRgb)*img.height();
118 } else { 118 } else {
119 rgb = img.colorTable(); 119 rgb = img.colorTable();
120 count = img.numColors(); 120 count = img.numColors();
121 } 121 }
122 int rc, gc, bc; 122 int rc, gc, bc;
123 int bs = ::abs ( i * 10 ) + 25; 123 int bs = ::abs ( i * 10 ) + 25;
124 colorGroup().highlight().rgb( &rc, &gc, &bc ); 124 colorGroup().highlight().rgb( &rc, &gc, &bc );
125 rc = rc * bs / 100; 125 rc = rc * bs / 100;
126 gc = gc * bs / 100; 126 gc = gc * bs / 100;
127 bc = bc * bs / 100; 127 bc = bc * bs / 100;
128 128
129 for ( int r = 0; r < count; r++, rgb++ ) { 129 for ( int r = 0; r < count; r++, rgb++ ) {
130 int ri = rc + qRed ( *rgb ) * ( 100 - bs ) / 100; 130 int ri = rc + qRed ( *rgb ) * ( 100 - bs ) / 100;
131 int gi = gc + qGreen ( *rgb ) * ( 100 - bs ) / 100; 131 int gi = gc + qGreen ( *rgb ) * ( 100 - bs ) / 100;
132 int bi = bc + qBlue ( *rgb ) * ( 100 - bs ) / 100; 132 int bi = bc + qBlue ( *rgb ) * ( 100 - bs ) / 100;
133 int ai = qAlpha ( *rgb ); 133 int ai = qAlpha ( *rgb );
134 *rgb = qRgba ( ri, gi, bi, ai ); 134 *rgb = qRgba ( ri, gi, bi, ai );
135 } 135 }
136 136
137 bpm [i].convertFromImage( img ); 137 bpm [i].convertFromImage( img );
138 } 138 }
139 busystate = 0; 139 busystate = 0;
140 if ( busytimer ) 140 if ( busytimer )
141 killTimer ( busytimer ); 141 killTimer ( busytimer );
142 timerEvent ( 0 ); 142 timerEvent ( 0 );
143 busytimer = startTimer ( 180 ); 143 busytimer = startTimer ( 200 );
144 } 144 }
145 else { 145 else {
146 killTimer ( busytimer ); 146 killTimer ( busytimer );
147 busytimer = 0; 147 busytimer = 0;
148 } 148 }
149 } 149 }
150 } 150 }
151 151
152 virtual void timerEvent ( QTimerEvent *te ) 152 virtual void timerEvent ( QTimerEvent *te )
153 { 153 {
154 if ( !te || ( te-> timerId ( ) == busytimer )) { 154 if ( !te || ( te-> timerId ( ) == busytimer )) {
155 if ( bsy ) { 155 if ( bsy ) {
156 busystate++; 156 busystate++;
157 if ( busystate > 5 ) 157 if ( busystate > 5 )
158 busystate = -4; 158 busystate = -4;
159 159
160 bsy-> repaint ( ); 160 QScrollView::updateContents ( bsy-> pixmapRect ( false ));
161 } 161 }
162 } 162 }
163 } 163 }
164 164
165 bool inKeyEvent() const { return ike; } 165 bool inKeyEvent() const { return ike; }
166 void keyPressEvent(QKeyEvent* e) 166 void keyPressEvent(QKeyEvent* e)
167 { 167 {
168 ike = TRUE; 168 ike = TRUE;
169 if ( e->key() == Key_F33 /* OK button */ || e->key() == Key_Space ) 169 if ( e->key() == Key_F33 /* OK button */ || e->key() == Key_Space )
170 returnPressed(currentItem()); 170 returnPressed(currentItem());
171 QIconView::keyPressEvent(e); 171 QIconView::keyPressEvent(e);
172 ike = FALSE; 172 ike = FALSE;
173 } 173 }
174 174
175 void addItem(AppLnk* app, bool resort=TRUE); 175 void addItem(AppLnk* app, bool resort=TRUE);
176 bool removeLink(const QString& linkfile); 176 bool removeLink(const QString& linkfile);
177 177
178 QStringList mimeTypes() const; 178 QStringList mimeTypes() const;
179 QStringList categories() const; 179 QStringList categories() const;
180 180
181 void clear() 181 void clear()
182 { 182 {
183 mimes.clear(); 183 mimes.clear();
184 cats.clear(); 184 cats.clear();
185 QIconView::clear(); 185 QIconView::clear();
186 hidden.clear(); 186 hidden.clear();
187 } 187 }
188 188
189 void addCatsAndMimes(AppLnk* app) 189 void addCatsAndMimes(AppLnk* app)
190 { 190 {
191 // QStringList c = app->categories(); 191 // QStringList c = app->categories();
192 // for (QStringList::ConstIterator cit=c.begin(); cit!=c.end(); ++cit) { 192 // for (QStringList::ConstIterator cit=c.begin(); cit!=c.end(); ++cit) {
193 // cats.replace(*cit,(void*)1); 193 // cats.replace(*cit,(void*)1);
194 // } 194 // }
195 QString maj=app->type(); 195 QString maj=app->type();
196 int sl=maj.find('/'); 196 int sl=maj.find('/');
197 if (sl>=0) { 197 if (sl>=0) {
198 QString k; 198 QString k;
199 k = maj.left(12) == "application/" ? maj : maj.left(sl); 199 k = maj.left(12) == "application/" ? maj : maj.left(sl);
200 mimes.replace(k,(void*)1); 200 mimes.replace(k,(void*)1);
201 } 201 }
202 } 202 }
203 203
204 void setBackgroundPixmap( const QPixmap &pm ) { 204 void setBackgroundPixmap( const QPixmap &pm ) {
205 bgPixmap = pm; 205 if ( pm. isNull ( )) {
206 bgPixmap = pm;
207 }
208 else {
209 // This is need for bg images with alpha channel
210
211 QPixmap tmp ( pm. size ( ), pm. depth ( ));
212
213 QPainter p ( &tmp );
214 p. fillRect ( 0, 0, pm. width ( ), pm. height ( ), bgColor. isValid ( ) ? bgColor : white );
215 p. drawPixmap ( 0, 0, pm );
216 p. end ( );
217
218 bgPixmap = tmp;
219 }
206 } 220 }
207 221
208 void setBackgroundColor( const QColor &c ) { 222 void setBackgroundColor( const QColor &c ) {
209 bgColor = c; 223 bgColor = c;
210 } 224 }
211 225
212 void drawBackground( QPainter *p, const QRect &r ) 226 void drawBackground( QPainter *p, const QRect &r )
213 { 227 {
214 if ( !bgPixmap.isNull() ) { 228 if ( !bgPixmap.isNull() ) {
215 p-> fillRect ( r, bgColor ); 229 //p-> fillRect ( r, bgColor );
216 p->drawTiledPixmap( r, bgPixmap, 230 p->drawTiledPixmap( r, bgPixmap,
217 QPoint( (r.x() + contentsX()) % bgPixmap.width(), 231 QPoint( (r.x() + contentsX()) % bgPixmap.width(),
218 (r.y() + contentsY()) % bgPixmap.height() ) ); 232 (r.y() + contentsY()) % bgPixmap.height() ) );
219 } else { 233 } else {
220 p->fillRect( r, bgColor ); 234 p->fillRect( r, bgColor );
221 } 235 }
222 } 236 }
223 237
224 void setItemTextPos( ItemTextPos pos ) 238 void setItemTextPos( ItemTextPos pos )
225 { 239 {
226 calculateGrid( pos ); 240 calculateGrid( pos );
227 QIconView::setItemTextPos( pos ); 241 QIconView::setItemTextPos( pos );
228 } 242 }
229 243
230 void hideOrShowItems(bool resort); 244 void hideOrShowItems(bool resort);
231 245
232 void setTypeFilter(const QString& typefilter, bool resort) 246 void setTypeFilter(const QString& typefilter, bool resort)
233 { 247 {
234 tf = QRegExp(typefilter,FALSE,TRUE); 248 tf = QRegExp(typefilter,FALSE,TRUE);
235 hideOrShowItems(resort); 249 hideOrShowItems(resort);
236 } 250 }
237 251
238 void setCategoryFilter( int catfilter, bool resort ) 252 void setCategoryFilter( int catfilter, bool resort )
239 { 253 {
240 Categories cat; 254 Categories cat;
241 cat.load( categoryFileName() ); 255 cat.load( categoryFileName() );
242 QString str; 256 QString str;
243 if ( catfilter == -2 ) 257 if ( catfilter == -2 )
244 cf = 0; 258 cf = 0;
245 else 259 else
246 cf = catfilter; 260 cf = catfilter;
247 hideOrShowItems(resort); 261 hideOrShowItems(resort);
248 } 262 }
249 263
250 enum SortMethod { Name, Date, Type }; 264 enum SortMethod { Name, Date, Type };
251 265
252 void setSortMethod( SortMethod m ) 266 void setSortMethod( SortMethod m )
253 { 267 {
254 if ( sortmeth != m ) { 268 if ( sortmeth != m ) {
255 sortmeth = m; 269 sortmeth = m;
256 sort(); 270 sort();
257 } 271 }
258 } 272 }
259 273
260 int compare(const AppLnk* a, const AppLnk* b) 274 int compare(const AppLnk* a, const AppLnk* b)
261 { 275 {
262 switch (sortmeth) { 276 switch (sortmeth) {
263 case Name: 277 case Name:
264 return a->name().compare(b->name()); 278 return a->name().compare(b->name());
265 case Date: { 279 case Date: {
266 QFileInfo fa(a->linkFileKnown() ? a->linkFile() : a->file()); 280 QFileInfo fa(a->linkFileKnown() ? a->linkFile() : a->file());
267 QFileInfo fb(b->linkFileKnown() ? b->linkFile() : b->file()); 281 QFileInfo fb(b->linkFileKnown() ? b->linkFile() : b->file());
268 return fa.lastModified().secsTo(fb.lastModified()); 282 return fa.lastModified().secsTo(fb.lastModified());
269 } 283 }
270 case Type: 284 case Type:
271 return a->type().compare(b->type()); 285 return a->type().compare(b->type());
272 } 286 }
273 return 0; 287 return 0;
274 } 288 }
275 289
276 QString getAllDocLinkInfo() const; 290 QString getAllDocLinkInfo() const;
277 291
278protected: 292protected:
279 293