author | sandman <sandman> | 2002-10-23 23:51:11 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-10-23 23:51:11 (UTC) |
commit | 36e13db0a1d44abd5a160a34e4679b90d62826c7 (patch) (side-by-side diff) | |
tree | 6996137d6ffd992e7eef8be1802d667b3184f62a | |
parent | 8d8ebc66cefd889c0cbc13d7d3d4158bdcb55962 (diff) | |
download | opie-36e13db0a1d44abd5a160a34e4679b90d62826c7.zip opie-36e13db0a1d44abd5a160a34e4679b90d62826c7.tar.gz opie-36e13db0a1d44abd5a160a34e4679b90d62826c7.tar.bz2 |
- fix for the busy indicator timer, in case someone switches to non-blink
style, while the indicator is blinking
- the launcher QIconView is now drawn flickerfree into a background QPixmap
-rw-r--r-- | core/launcher/launcherview.cpp | 57 |
1 files changed, 50 insertions, 7 deletions
diff --git a/core/launcher/launcherview.cpp b/core/launcher/launcherview.cpp index 6e63fca..9fc4565 100644 --- a/core/launcher/launcherview.cpp +++ b/core/launcher/launcherview.cpp @@ -51,172 +51,173 @@ public: QPixmap pm; int ref; }; enum BusyIndicatorType { BIT_Normal = 0, BIT_Blinking }; 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 } void setBusyIndicatorType ( BusyIndicatorType t ) { busyType = t; } 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 ) { QIconViewItem *oldbsy = bsy; bsy = c; if ( oldbsy ) oldbsy-> repaint ( ); + if ( busytimer ) { + killTimer ( busytimer ); + busytimer = 0; + } + if ( bsy ) { QPixmap *src = bsy-> QIconViewItem::pixmap(); for ( int i = 0; i <= 5; i++ ) { 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 ( i * 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 ); } bpm [i].convertFromImage( img ); } + if ( busyType == BIT_Blinking ) { busystate = 0; - if ( busytimer ) - killTimer ( busytimer ); busytimer = startTimer ( 200 ); } - else + else { busystate = 3; + } timerEvent ( 0 ); } - else { - killTimer ( busytimer ); - busytimer = 0; - } } } virtual void timerEvent ( QTimerEvent *te ) { if ( !te || ( te-> timerId ( ) == busytimer )) { if ( bsy ) { busystate++; if ( busystate > 5 ) busystate = -4; QScrollView::updateContents ( bsy-> pixmapRect ( false )); } } } 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 ) { if ( pm. isNull ( )) { bgPixmap = pm; } else { // This is need for bg images with alpha channel QPixmap tmp ( pm. size ( ), pm. depth ( )); @@ -271,128 +272,169 @@ public: hideOrShowItems(resort); } enum SortMethod { Name, Date, Type }; void setSortMethod( SortMethod m ) { if ( sortmeth != m ) { sortmeth = m; sort(); } } int compare(const AppLnk* a, const AppLnk* b) { switch (sortmeth) { case Name: return a->name().compare(b->name()); case Date: { QFileInfo fa(a->linkFileKnown() ? a->linkFile() : a->file()); QFileInfo fb(b->linkFileKnown() ? b->linkFile() : b->file()); return fa.lastModified().secsTo(fb.lastModified()); } case Type: return a->type().compare(b->type()); } return 0; } 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 ); } } + + // flicker free redrawing of busy indicator + // code was taken from QScrollView::viewportPaintEvent + void viewportPaintEvent( QPaintEvent* pe ) + { + static QPixmap *pix = new QPixmap ( ); + + QWidget* vp = viewport(); + + if ( vp-> size ( ) != pix-> size ( )) + pix-> resize ( vp-> size ( )); + + QPainter p(pix, vp); + QRect r = pe->rect(); + if ( clipper ( ) != vp ) { + QRect rr( + -vp->x(), -vp->y(), + clipper()->width(), clipper()->height() + ); + r &= rr; + if ( r.isValid() ) { + int ex = r.x() + vp->x() + contentsX(); + int ey = r.y() + vp->y() + contentsY(); + int ew = r.width(); + int eh = r.height(); + drawContentsOffset(&p, + contentsX()+vp->x(), + contentsY()+vp->y(), + ex, ey, ew, eh); + } + } else { + r &= clipper()->rect(); + int ex = r.x() + contentsX(); + int ey = r.y() + contentsY(); + int ew = r.width(); + int eh = r.height(); + drawContentsOffset(&p, contentsX(), contentsY(), ex, ey, ew, eh); + } + bitBlt ( vp, r.topLeft(), pix, r ); + } + 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 [6]; QColor bgColor; int busytimer; int busystate; BusyIndicatorType busyType; }; 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 ) return liv->busyPixmap(); return QIconViewItem::pixmap(); } @@ -870,64 +912,65 @@ void LauncherView::itemPressed( int btn, QIconViewItem *item ) */ item->setSelected(FALSE); } } void LauncherView::internalPopulate( AppLnkSet *folder, const QString& typefilter ) { QListIterator<AppLnk> it( folder->children() ); icons->setTypeFilter(typefilter,FALSE); while ( it.current() ) { // show only the icons for existing files if (QFile(it.current()->file()).exists() || ( it.current()->file().left(4) == "http" )) { icons->addItem(*it,FALSE); } else { //maybe insert some .desktop file deletion code later //maybe dir specific } ++it; } icons->sort(); } bool LauncherView::removeLink(const QString& linkfile) { return icons->removeLink(linkfile); } void LauncherView::sort() { icons->sort(); } void LauncherView::addItem(AppLnk* app, bool resort) { icons->addItem(app,resort); } void LauncherView::setFileSystems(const QList<FileSystem> &) { // ### does nothing now... } void LauncherView::paletteChange( const QPalette &p ) { icons->unsetPalette(); QVBox::paletteChange( p ); if ( bgType == Ruled ) setBackgroundType( Ruled, QString::null ); QColorGroup cg = icons->colorGroup(); cg.setColor( QColorGroup::Text, textCol ); icons->setPalette( QPalette(cg,cg,cg) ); } void LauncherView::setBusyIndicatorType ( const QString &type ) { if ( type. lower ( ) == "blink" ) icons-> setBusyIndicatorType ( BIT_Blinking ); else icons-> setBusyIndicatorType ( BIT_Normal ); } + |