summaryrefslogtreecommitdiff
authorsandman <sandman>2002-09-30 10:12:36 (UTC)
committer sandman <sandman>2002-09-30 10:12:36 (UTC)
commitece83520d6bf5c481275a3d4a8e792749119fa08 (patch) (side-by-side diff)
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 @@
#include <qfileinfo.h>
#include <qhbox.h>
#include <qiconview.h>
#include <qpainter.h>
#include <qregexp.h>
#include <qtoolbutton.h>
#include <qimage.h>
class BgPixmap
{
public:
BgPixmap( const QPixmap &p ) : pm(p), ref(1) {}
QPixmap pm;
int ref;
};
static QMap<QString,BgPixmap*> *bgCache = 0;
class LauncherIconView : public QIconView {
public:
LauncherIconView( QWidget* parent, const char* name=0 ) :
QIconView(parent,name),
tf(""),
cf(0),
bsy(0),
bigIcns(TRUE),
bgColor(white)
{
sortmeth = Name;
hidden.setAutoDelete(TRUE);
ike = FALSE;
busytimer = 0;
calculateGrid( Bottom );
}
~LauncherIconView()
{
#if 0 // debuggery
QListIterator<AppLnk> it(hidden);
AppLnk* l;
while ((l=it.current())) {
++it;
//qDebug("%p: hidden (should remove)",l);
}
#endif
}
- QPixmap* busyPixmap() const { return (QPixmap*)&bpm; }
+ QPixmap* busyPixmap() const { return (QPixmap*)&bpm[::abs(busystate)]; }
QIconViewItem* busyItem() const { return bsy; }
void setBigIcons( bool bi ) { bigIcns = bi; }
void updateCategoriesAndMimeTypes();
void doAutoScroll()
{
// We don't want rubberbanding (yet)
}
void setBusy(bool on)
{
QIconViewItem *c = on ? currentItem() : 0;
if ( bsy != c ) {
if ( bsy )
bsy-> repaint ( );
bsy = c;
if ( bsy ) {
+ busystate = 5;
+ for ( int i = 0; i <= 5; i++ )
+ bpm [i] = QPixmap ( );
+ timerEvent ( 0 );
busytimer = startTimer ( 150 );
- busystate = 50;
- // not sure what this startTimer is for, maybe i am just to tired. But
- // currently that causes 100% cpuload on app launch
- //startTimer ( 0 );
}
else
killTimer ( busytimer );
}
}
virtual void timerEvent ( QTimerEvent *te )
{
if ( !te || ( te-> timerId ( ) == busytimer )) {
if ( bsy ) {
- QPixmap *src = bsy-> QIconViewItem::pixmap();
- QImage img = src->convertToImage();
- QRgb* rgb;
- int count;
- if ( img.depth() == 32 ) {
- rgb = (QRgb*)img.bits();
- count = img.bytesPerLine()/sizeof(QRgb)*img.height();
- } else {
- rgb = img.colorTable();
- count = img.numColors();
- }
- int rc, gc, bc;
- int bs = ::abs ( busystate ) + 25;
- colorGroup().highlight().rgb( &rc, &gc, &bc );
- rc = rc * bs / 100;
- gc = gc * bs / 100;
- bc = bc * bs / 100;
+ if ( bpm [::abs(busystate)]. isNull ( )) {
+ QPixmap *src = bsy-> QIconViewItem::pixmap();
+ QImage img = src->convertToImage();
+ QRgb* rgb;
+ int count;
+ if ( img.depth() == 32 ) {
+ rgb = (QRgb*)img.bits();
+ count = img.bytesPerLine()/sizeof(QRgb)*img.height();
+ } else {
+ rgb = img.colorTable();
+ count = img.numColors();
+ }
+ int rc, gc, bc;
+ int bs = ::abs ( busystate * 10 ) + 25;
+ colorGroup().highlight().rgb( &rc, &gc, &bc );
+ rc = rc * bs / 100;
+ gc = gc * bs / 100;
+ bc = bc * bs / 100;
- for ( int r = 0; r < count; r++, rgb++ ) {
- int ri = rc + qRed ( *rgb ) * ( 100 - bs ) / 100;
- int gi = gc + qGreen ( *rgb ) * ( 100 - bs ) / 100;
- int bi = bc + qBlue ( *rgb ) * ( 100 - bs ) / 100;
- int ai = qAlpha ( *rgb );
- *rgb = qRgba ( ri, gi, bi, ai );
+ for ( int r = 0; r < count; r++, rgb++ ) {
+ int ri = rc + qRed ( *rgb ) * ( 100 - bs ) / 100;
+ int gi = gc + qGreen ( *rgb ) * ( 100 - bs ) / 100;
+ int bi = bc + qBlue ( *rgb ) * ( 100 - bs ) / 100;
+ int ai = qAlpha ( *rgb );
+ *rgb = qRgba ( ri, gi, bi, ai );
+ }
+
+ bpm [::abs(busystate)].convertFromImage( img );
}
-
- bpm.convertFromImage( img );
-
bsy-> repaint ( );
- busystate += 10;
- if ( busystate > 50 )
- busystate = -40;
+ busystate++;
+ if ( busystate > 5 )
+ busystate = -4;
}
}
}
bool inKeyEvent() const { return ike; }
void keyPressEvent(QKeyEvent* e)
{
ike = TRUE;
if ( e->key() == Key_F33 /* OK button */ || e->key() == Key_Space )
returnPressed(currentItem());
QIconView::keyPressEvent(e);
ike = FALSE;
}
void addItem(AppLnk* app, bool resort=TRUE);
bool removeLink(const QString& linkfile);
QStringList mimeTypes() const;
QStringList categories() const;
void clear()
{
mimes.clear();
cats.clear();
QIconView::clear();
hidden.clear();
}
void addCatsAndMimes(AppLnk* app)
{
// QStringList c = app->categories();
// for (QStringList::ConstIterator cit=c.begin(); cit!=c.end(); ++cit) {
// cats.replace(*cit,(void*)1);
// }
QString maj=app->type();
int sl=maj.find('/');
if (sl>=0) {
QString k;
k = maj.left(12) == "application/" ? maj : maj.left(sl);
mimes.replace(k,(void*)1);
}
}
void setBackgroundPixmap( const QPixmap &pm ) {
bgPixmap = pm;
}
void setBackgroundColor( const QColor &c ) {
@@ -266,97 +267,97 @@ public:
}
QString getAllDocLinkInfo() const;
protected:
void styleChange( QStyle &old )
{
QIconView::styleChange( old );
calculateGrid( itemTextPos() );
}
void calculateGrid( ItemTextPos pos )
{
int dw = QApplication::desktop()->width();
int viewerWidth = dw-style().scrollBarExtent().width();
if ( pos == Bottom ) {
int cols = 3;
if ( viewerWidth <= 200 )
cols = 2;
else if ( viewerWidth >= 400 )
cols = viewerWidth/96;
setSpacing( 4 );
setGridX( (viewerWidth-(cols+1)*spacing())/cols );
setGridY( fontMetrics().height()*2+24 );
} else {
int cols = 2;
if ( viewerWidth < 150 )
cols = 1;
else if ( viewerWidth >= 400 )
cols = viewerWidth/150;
setSpacing( 2 );
setGridX( (viewerWidth-(cols+1)*spacing())/cols );
setGridY( fontMetrics().height()+2 );
}
}
private:
QList<AppLnk> hidden;
QDict<void> mimes;
QDict<void> cats;
SortMethod sortmeth;
QRegExp tf;
int cf;
QIconViewItem* bsy;
bool ike;
bool bigIcns;
QPixmap bgPixmap;
- QPixmap bpm;
+ QPixmap bpm [6];
QColor bgColor;
int busytimer;
int busystate;
};
bool LauncherView::bsy=FALSE;
void LauncherView::setBusy(bool on)
{
icons->setBusy(on);
}
class LauncherItem : public QIconViewItem
{
public:
LauncherItem( QIconView *parent, AppLnk* applnk, bool bigIcon=TRUE );
~LauncherItem()
{
LauncherIconView* liv = (LauncherIconView*)iconView();
if ( liv->busyItem() == this )
liv->setBusy(FALSE);
delete app;
}
AppLnk* appLnk() const { return app; }
AppLnk* takeAppLnk() { AppLnk* r=app; app=0; return r; }
virtual int compare ( QIconViewItem * i ) const;
void paintItem( QPainter *p, const QColorGroup &cg )
{
LauncherIconView* liv = (LauncherIconView*)iconView();
QBrush oldBrush( liv->itemTextBackground() );
QColorGroup mycg( cg );
if ( liv->currentItem() == this ) {
liv->setItemTextBackground( cg.brush( QColorGroup::Highlight ) );
mycg.setColor( QColorGroup::Text, cg.color( QColorGroup::HighlightedText ) );
}
QIconViewItem::paintItem(p,mycg);
if ( liv->currentItem() == this )
liv->setItemTextBackground( oldBrush );
}
virtual QPixmap* pixmap () const
{
const LauncherIconView* liv = (LauncherIconView*)iconView();
if ( (const LauncherItem *)liv->busyItem() == this )