author | zecke <zecke> | 2003-08-28 14:37:27 (UTC) |
---|---|---|
committer | zecke <zecke> | 2003-08-28 14:37:27 (UTC) |
commit | 245dcac2f79d7409f80da37f9c6c47fff70dc949 (patch) (side-by-side diff) | |
tree | aa5401e3cea0453da32f6062dba6ac454a3457ae /core/launcher/launcherview.cpp | |
parent | f837944e9a404c46efc00e4d5851ea13dbb88ef2 (diff) | |
download | opie-245dcac2f79d7409f80da37f9c6c47fff70dc949.zip opie-245dcac2f79d7409f80da37f9c6c47fff70dc949.tar.gz opie-245dcac2f79d7409f80da37f9c6c47fff70dc949.tar.bz2 |
-Make it compile
-apply Opie patches
-prepare BusyIndicator changes
-add QCOP method for showing the desktop and going to the next tab
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 @@ -21,13 +21,13 @@ #include "launcherview.h" -#include <qpe/qpeapplication.h> -#include <qpe/applnk.h> -#include <qpe/qpedebug.h> -#include <qpe/categories.h> -#include <qpe/categoryselect.h> -#include <qpe/menubutton.h> -#include <qpe/mimetype.h> -#include <qpe/resource.h> -#include <qpe/qpetoolbar.h> +#include <qtopia/qpeapplication.h> +#include <qtopia/applnk.h> +#include <qtopia/qpedebug.h> +#include <qtopia/private/categories.h> +#include <qtopia/categoryselect.h> +#include <qtopia/menubutton.h> +#include <qtopia/mimetype.h> +#include <qtopia/resource.h> +#include <qtopia/qpetoolbar.h> //#include <qtopia/private/palmtoprecord.h> @@ -39,10 +39,19 @@ #include <qhbox.h> #include <qiconview.h> +#include <qwidgetstack.h> #include <qpainter.h> #include <qregexp.h> #include <qtoolbutton.h> #include <qimage.h> +#include <qlabel.h> +#include <qobjectlist.h> + + +// These define how the busy icon is animated and highlighted +#define BRIGHTEN_BUSY_ICON +//#define ALPHA_FADE_BUSY_ICON +//#define USE_ANIMATED_BUSY_ICON_OVERLAY +#define BOUNCE_BUSY_ICON -#include <cstdlib> class BgPixmap @@ -61,4 +70,41 @@ enum BusyIndicatorType { static QMap<QString,BgPixmap*> *bgCache = 0; +static void cleanup_cache() +{ + QMap<QString,BgPixmap*>::Iterator it = bgCache->begin(); + while ( it != bgCache->end() ) { + QMap<QString,BgPixmap*>::Iterator curr = it; + ++it; + delete (*curr); + bgCache->remove( curr ); + } + delete bgCache; + bgCache = 0; +} + + +class LauncherItem : public QIconViewItem +{ +public: + LauncherItem( QIconView *parent, AppLnk* applnk, bool bigIcon=TRUE ); + ~LauncherItem(); + + AppLnk *appLnk() const { return app; } + AppLnk *takeAppLnk() { AppLnk* r=app; app=0; return r; } + + void animateIcon(); + void resetIcon(); + + virtual int compare ( QIconViewItem * i ) const; + void paintItem( QPainter *p, const QColorGroup &cg ); +protected: + bool isBigIcon; + int iteration; + AppLnk* app; +private: + void paintAnimatedIcon( QPainter *p ); +}; + + class LauncherIconView : public QIconView { public: @@ -68,4 +114,5 @@ public: cf(0), bsy(0), + busyTimer(0), bigIcns(TRUE), bgColor(white) @@ -74,5 +121,4 @@ public: hidden.setAutoDelete(TRUE); ike = FALSE; - busytimer = 0; calculateGrid( Bottom ); } @@ -89,10 +135,15 @@ public: #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; } +#ifdef USE_ANIMATED_BUSY_ICON_OVERLAY + QPixmap busyPixmap() const { return busyPix; } +#endif + void setBigIcons( bool bi ) { + bigIcns = bi; +#ifdef USE_ANIMATED_BUSY_ICON_OVERLAY + busyPix.resize(0,0); +#endif + } void updateCategoriesAndMimeTypes(); @@ -105,71 +156,29 @@ public: 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 ); - } +#ifdef USE_ANIMATED_BUSY_ICON_OVERLAY + if ( busyPix.isNull() ) { + int size = ( bigIcns ) ? AppLnk::bigIconSize() : AppLnk::smallIconSize(); + busyPix.convertFromImage( Resource::loadImage( "busy" ).smoothScale( size * 16, size ) ); + } +#endif - bpm [i].convertFromImage( img ); - } - - if ( busyType == BIT_Blinking ) { - busystate = 0; - busytimer = startTimer ( 200 ); - } - else { - busystate = 3; - } - timerEvent ( 0 ); + if ( on ) { + busyTimer = startTimer( 100 ); + } else { + if ( busyTimer ) { + 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 )); - } + LauncherItem *c = on ? (LauncherItem*)currentItem() : 0; + + if ( bsy != c ) { + LauncherItem *oldBusy = bsy; + bsy = c; + if ( oldBusy ) + oldBusy->resetIcon(); + if ( bsy ) + bsy->animateIcon(); } } @@ -179,6 +188,11 @@ public: { ike = TRUE; - if ( e->key() == Key_F33 /* OK button */ || e->key() == Key_Space ) - returnPressed(currentItem()); + if ( e->key() == Key_F33 /* OK button */ || e->key() == Key_Space ) { + if ( (e->state() & ShiftButton) ) + emit mouseButtonPressed(ShiftButton, currentItem(), QPoint() ); + else + returnPressed(currentItem()); + } + QIconView::keyPressEvent(e); ike = FALSE; @@ -214,20 +228,9 @@ public: } + void setBackgroundOrigin( QWidget::BackgroundOrigin ) { + } + 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 ( )); - - QPainter p ( &tmp ); - p. fillRect ( 0, 0, pm. width ( ), pm. height ( ), bgColor. isValid ( ) ? bgColor : white ); - p. drawPixmap ( 0, 0, pm ); - p. end ( ); - - bgPixmap = tmp; - } + bgPixmap = pm; } @@ -239,6 +242,5 @@ public: { if ( !bgPixmap.isNull() ) { - //p-> fillRect ( r, bgColor ); - p->drawTiledPixmap( r, bgPixmap, + p->drawTiledPixmap( r, bgPixmap, QPoint( (r.x() + contentsX()) % bgPixmap.width(), (r.y() + contentsY()) % bgPixmap.height() ) ); @@ -288,5 +290,5 @@ public: switch (sortmeth) { case Name: - return a->name().compare(b->name()); + return a->name().lower().compare(b->name().lower()); case Date: { QFileInfo fa(a->linkFileKnown() ? a->linkFile() : a->file()); @@ -300,8 +302,16 @@ public: } - QString getAllDocLinkInfo() const; - protected: + void timerEvent( QTimerEvent *te ) + { + if ( te->timerId() == busyTimer ) { + if ( bsy ) + bsy->animateIcon(); + } else { + QIconView::timerEvent( te ); + } + } + void styleChange( QStyle &old ) { @@ -335,45 +345,7 @@ protected: } + void focusInEvent( QFocusEvent * ) {} + void focusOutEvent( QFocusEvent * ) {} - // 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; @@ -383,13 +355,13 @@ private: QRegExp tf; int cf; - QIconViewItem* bsy; + LauncherItem* bsy; + int busyTimer; bool ike; bool bigIcns; QPixmap bgPixmap; - QPixmap bpm [6]; QColor bgColor; - int busytimer; - int busystate; - BusyIndicatorType busyType; +#ifdef USE_ANIMATED_BUSY_ICON_OVERLAY + QPixmap busyPix; +#endif }; @@ -402,61 +374,131 @@ void LauncherView::setBusy(bool on) } -class LauncherItem : public QIconViewItem +void LauncherView::setBusyIndicatorType( const QString& type ) { + /* ### FIXME */ +} + +LauncherItem::LauncherItem( QIconView *parent, AppLnk *applnk, bool bigIcon ) + : QIconViewItem( parent, applnk->name(), + bigIcon ? applnk->bigPixmap() :applnk->pixmap() ), + isBigIcon( bigIcon ), + iteration(0), + app(applnk) // Takes ownership { -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; } +LauncherItem::~LauncherItem() +{ + LauncherIconView* liv = (LauncherIconView*)iconView(); + if ( liv->busyItem() == this ) + liv->setBusy(FALSE); + delete app; +} - virtual int compare ( QIconViewItem * i ) const; +int LauncherItem::compare ( QIconViewItem * i ) const +{ + LauncherIconView* view = (LauncherIconView*)iconView(); + return view->compare(app,((LauncherItem *)i)->appLnk()); +} - 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 ); +void LauncherItem::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 ) ); } - virtual QPixmap* pixmap () const - { - const LauncherIconView* liv = (LauncherIconView*)iconView(); - if ( (const LauncherItem *)liv->busyItem() == this ) - return liv->busyPixmap(); - return QIconViewItem::pixmap(); - } + QIconViewItem::paintItem(p,mycg); -protected: - AppLnk* app; -}; + // Paint animation overlay + if ( liv->busyItem() == this ) + paintAnimatedIcon(p); + if ( liv->currentItem() == this ) + liv->setItemTextBackground( oldBrush ); +} -LauncherItem::LauncherItem( QIconView *parent, AppLnk *applnk, bool bigIcon ) - : QIconViewItem( parent, applnk->name(), - bigIcon ? applnk->bigPixmap() :applnk->pixmap() ), - app(applnk) // Takes ownership +void LauncherItem::paintAnimatedIcon( QPainter *p ) { + LauncherIconView* liv = (LauncherIconView*)iconView(); + int pic = iteration % 16; + int w = pixmap()->width(), h = pixmap()->height(); + QPixmap dblBuf( w, h + 4 ); + QPainter p2( &dblBuf ); + int x1, y1; + if ( liv->itemTextPos() == QIconView::Bottom ) { + x1 = x() + (width() - w) / 2 - liv->contentsX(); + y1 = y() - liv->contentsY(); + } else { + x1 = x() - liv->contentsX(); + y1 = y() + (height() - h) / 2 - liv->contentsY(); + } + y1 -= 2; + p2.translate(-x1,-y1); + liv->drawBackground( &p2, QRect(x1,y1,w,h+4) ); + int bounceY = 2; +#ifdef BOUNCE_BUSY_ICON + bounceY = 4 - ((iteration+2)%8); + bounceY = bounceY < 0 ? -bounceY : bounceY; +#endif + p2.drawPixmap( x1, y1 + bounceY, *pixmap() ); +#ifdef USE_ANIMATED_BUSY_ICON_OVERLAY + p2.drawPixmap( x1, y1 + bounceY, liv->busyPixmap(), w * pic, 0, w, h ); +#endif + p->drawPixmap( x1, y1, dblBuf ); } -int LauncherItem::compare ( QIconViewItem * i ) const +void LauncherItem::animateIcon() { - LauncherIconView* view = (LauncherIconView*)iconView(); - return view->compare(app,((LauncherItem *)i)->appLnk()); + LauncherIconView* liv = (LauncherIconView*)iconView(); + + if ( liv->busyItem() != this || !app ) + return; + + // Highlight the icon + if ( iteration == 0 ) { + QPixmap src = isBigIcon ? app->bigPixmap() : app->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(); + } + for ( int r = 0; r < count; r++, rgb++ ) { +#if defined(BRIGHTEN_BUSY_ICON) + QColor c(*rgb); + int h, s, v; + c.hsv(&h,&s,&v); + c.setHsv(h,QMAX(s-24,0),QMIN(v+48,255)); + *rgb = qRgba(c.red(),c.green(),c.blue(),qAlpha(*rgb)); +#elif defined(ALPHA_FADE_BUSY_ICON) + *rgb = qRgba(qRed(*rgb),qGreen(*rgb),qBlue(*rgb),qAlpha(*rgb)/2); +#endif + } + src.convertFromImage( img ); + setPixmap( src ); + } + + iteration++; + + // Paint animation overlay + QPainter p( liv->viewport() ); + paintAnimatedIcon( &p ); +} + +void LauncherItem::resetIcon() +{ + iteration = 0; + setPixmap( isBigIcon ? app->bigPixmap() : app->pixmap() ); } +//=========================================================================== + QStringList LauncherIconView::mimeTypes() const { @@ -504,4 +546,5 @@ void LauncherIconView::updateCategoriesAndMimeTypes() void LauncherIconView::hideOrShowItems(bool resort) { + viewport()->setUpdatesEnabled( FALSE ); hidden.setAutoDelete(FALSE); QList<AppLnk> links=hidden; @@ -513,5 +556,4 @@ void LauncherIconView::hideOrShowItems(bool resort) item = (LauncherItem*)item->nextItem(); } - viewport()->setUpdatesEnabled( FALSE ); clear(); QListIterator<AppLnk> it(links); @@ -521,7 +563,7 @@ void LauncherIconView::hideOrShowItems(bool resort) ++it; } - viewport()->setUpdatesEnabled( TRUE ); if ( resort && !autoArrange() ) sort(); + viewport()->setUpdatesEnabled( TRUE ); } @@ -534,18 +576,20 @@ bool LauncherIconView::removeLink(const QString& linkfile) while (item) { l = item->appLnk(); - if ( ( l->linkFileKnown() && ( l->linkFile() == linkfile )) - || ( l->fileKnown() && ( l->file() == linkfile )) - || ( dl.fileKnown() && l->fileKnown() && ( dl.file() == l->file() )) ) { + LauncherItem *nextItem = (LauncherItem *)item->nextItem(); + if ( l->linkFileKnown() && l->linkFile() == linkfile + || l->fileKnown() && ( + l->file() == linkfile + || dl.isValid() && dl.file() == l->file() ) ) { delete item; did = TRUE; } - item = (LauncherItem*)item->nextItem(); + item = nextItem; } QListIterator<AppLnk> it(hidden); while ((l=it.current())) { ++it; - if ( ( l->linkFileKnown() && ( l->linkFile() == linkfile )) - || ( l->file() == linkfile ) - || ( dl.fileKnown() && ( dl.file() == l->file() )) ) { + if ( l->linkFileKnown() && l->linkFile() == linkfile + || l->file() == linkfile + || dl.isValid() && dl.file() == l->file() ) { hidden.removeRef(l); did = TRUE; @@ -555,55 +599,4 @@ bool LauncherIconView::removeLink(const QString& linkfile) } -static QString docLinkInfo(const Categories& cats, DocLnk* doc) -{ - QString contents; - - QFileInfo fi( doc->file() ); - if ( !fi.exists() ) - return contents; - - if ( doc->linkFileKnown() ) { - QString lfn = doc->linkFile(); - QFile f( lfn ); - if ( f.open( IO_ReadOnly ) ) { - QTextStream ts( &f ); - ts.setEncoding( QTextStream::UnicodeUTF8 ); - contents += ts.read(); - f.close(); - goto calcsize; - } - } - - contents += "[Desktop Entry]\n"; - contents += "Categories = " // No tr - + cats.labels("Document View", doc->categories()).join(";") + "\n"; // No tr - contents += "File = "+doc->file()+"\n"; // No tr - contents += "Name = "+doc->name()+"\n"; // No tr - contents += "Type = "+doc->type()+"\n"; // No tr - -calcsize: - contents += QString("Size = %1\n").arg( fi.size() ); // No tr - return contents; -} - -QString LauncherIconView::getAllDocLinkInfo() const -{ - QString contents; - LauncherItem* item = (LauncherItem*)firstItem(); - Categories cats; - while (item) { - DocLnk* doc = (DocLnk*)item->appLnk(); - contents += docLinkInfo(cats,doc); - item = (LauncherItem*)item->nextItem(); - } - QListIterator<AppLnk> it(hidden); - DocLnk* doc; - while ((doc=(DocLnk*)it.current())) { - contents += docLinkInfo(cats,doc); - ++it; - } - return contents; -} - //=========================================================================== @@ -611,4 +604,5 @@ LauncherView::LauncherView( QWidget* parent, const char* name, WFlags fl ) : QVBox( parent, name, fl ) { + catmb = 0; icons = new LauncherIconView( this ); setFocusProxy(icons); @@ -641,4 +635,11 @@ LauncherView::LauncherView( QWidget* parent, const char* name, WFlags fl ) LauncherView::~LauncherView() { + if ( bgCache && bgCache->contains( bgName ) ) + (*bgCache)[bgName]->ref--; +} + +void LauncherView::hideIcons() +{ + icons->hide(); } @@ -651,10 +652,14 @@ void LauncherView::setToolsEnabled(bool y) // Type filter typemb = new QComboBox(tools); + QSizePolicy p = typemb->sizePolicy(); + p.setHorData(QSizePolicy::Expanding); + typemb->setSizePolicy(p); // Category filter - catmb = new CategorySelect(tools); - updateTools(); tools->show(); + + // Always show vscrollbar + icons->setVScrollBarMode( QScrollView::AlwaysOn ); } else { delete tools; @@ -668,7 +673,8 @@ void LauncherView::updateTools() disconnect( typemb, SIGNAL(activated(int)), this, SLOT(showType(int)) ); - disconnect( catmb, SIGNAL(signalSelected(int)), + if ( catmb ) disconnect( catmb, SIGNAL(signalSelected(int)), this, SLOT(showCategory(int)) ); + // ### I want to remove this icons->updateCategoriesAndMimeTypes(); @@ -690,7 +696,7 @@ void LauncherView::updateTools() t[0] = t[0].upper(); } - types += tr("%1 files").arg(t); + types += t; } - types << tr("All types of file"); + types << tr("All types"); prev = typemb->currentText(); typemb->clear(); @@ -705,4 +711,7 @@ void LauncherView::updateTools() typemb->setCurrentItem(typemb->count()-1); + int pcat = catmb ? catmb->currentCategory() : -2; + if ( !catmb ) + catmb = new CategorySelect(tools); Categories cats( 0 ); cats.load( categoryFileName() ); @@ -712,4 +721,9 @@ void LauncherView::updateTools() catmb->setRemoveCategoryEdit( TRUE ); catmb->setAllCategories( TRUE ); + catmb->setCurrentCategory(pcat); + + // if type has changed we need to redisplay + if ( typemb->currentText() != prev ) + showType( typemb->currentItem() ); connect(typemb, SIGNAL(activated(int)), this, SLOT(showType(int))); @@ -759,15 +773,73 @@ void LauncherView::setViewMode( ViewMode m ) } +// +// User images may require scaling. +// +QImage LauncherView::loadBackgroundImage(QString &bgName) +{ + QImageIO imgio; + QSize ds = qApp->desktop()->size(); // should be launcher, not desktop + bool further_scaling = TRUE; + + imgio.setFileName( bgName ); + imgio.setParameters("GetHeaderInformation"); + + if (imgio.read() == FALSE) { + return imgio.image(); + } + + if (imgio.image().width() < ds.width() && + imgio.image().height() < ds.height()) { + further_scaling = FALSE; + } + + if (!imgio.image().bits()) { + // + // Scale and load. Note we don't scale up. + // + QString param( "Scale( %1, %2, ScaleMin )" ); // No tr + imgio.setParameters(further_scaling ? + param.arg(ds.width()).arg(ds.height()).latin1() : + ""); + imgio.read(); + } else { + if (further_scaling) { + int t1 = imgio.image().width() * ds.height(); + int t2 = imgio.image().height() * ds.width(); + int dsth = ds.height(); + int dstw = ds.width(); + + if (t1 > t2) { + dsth = t2 / imgio.image().width(); + } else { + dstw = t1 / imgio.image().height(); + } + + // + // Loader didn't scale for us. Do it manually. + // + return imgio.image().smoothScale(dstw, dsth); + } + } + + return imgio.image(); +} + void LauncherView::setBackgroundType( BackgroundType t, const QString &val ) { - if ( !bgCache ) + if ( !bgCache ) { bgCache = new QMap<QString,BgPixmap*>; + qAddPostRoutine( cleanup_cache ); + } + if ( bgCache->contains( bgName ) ) (*bgCache)[bgName]->ref--; + bgName = ""; + + QPixmap bg; switch ( t ) { case Ruled: { bgName = QString("Ruled_%1").arg(colorGroup().background().name()); // No tr - QPixmap bg; if ( bgCache->contains( bgName ) ) { (*bgCache)[bgName]->ref++; @@ -786,53 +858,61 @@ void LauncherView::setBackgroundType( BackgroundType t, const QString &val ) bgCache->insert( bgName, new BgPixmap(bg) ); } - icons->setBackgroundPixmap( bg ); break; } - case SolidColor: - icons->setBackgroundPixmap( QPixmap() ); - if ( val.isEmpty() ) { - icons->setBackgroundColor( colorGroup().base() ); - } else { - icons->setBackgroundColor( val ); - } - bgName = ""; - break; - case Image: - bgName = val; - if ( bgCache->contains( bgName ) ) { - (*bgCache)[bgName]->ref++; - icons->setBackgroundPixmap( (*bgCache)[bgName]->pm ); - } else { - QPixmap bg( Resource::loadPixmap( val ) ); - if ( bg.isNull() ) { - QImageIO imgio; - imgio.setFileName( bgName ); - QSize ds = qApp->desktop()->size(); - QString param( "Scale( %1, %2, ScaleMin )" ); // No tr - imgio.setParameters( param.arg(ds.width()).arg(ds.height()).latin1() ); - imgio.read(); - bg = imgio.image(); + if (!val.isEmpty()) { + bgName = val; + if ( bgCache->contains( bgName ) ) { + (*bgCache)[bgName]->ref++; + bg = (*bgCache)[bgName]->pm; + } else { + QString imgFile = bgName; + bool tile = FALSE; + if ( imgFile[0]!='/' || !QFile::exists(imgFile) ) { + imgFile = Resource::findPixmap( imgFile ); + tile = TRUE; + } + QImage img = loadBackgroundImage(imgFile); + + + if ( img.depth() == 1 ) + img = img.convertDepth(8); + img.setAlphaBuffer(FALSE); + bg.convertFromImage(img); + bgCache->insert( bgName, new BgPixmap(bg) ); } - bgCache->insert( bgName, new BgPixmap(bg) ); - icons->setBackgroundPixmap( bg ); } break; + + case SolidColor: + default: + break; } - // remove unreferenced backgrounds. - QMap<QString,BgPixmap*>::Iterator it = bgCache->begin(); - while ( it != bgCache->end() ) { - QMap<QString,BgPixmap*>::Iterator curr = it; - ++it; - if ( (*curr)->ref == 0 ) { - delete (*curr); - bgCache->remove( curr ); + const QObjectList *list = queryList( "QWidget", 0, FALSE ); + QObject *obj; + for ( QObjectListIt it( *list ); (obj=it.current()); ++it ) { + if ( obj->isWidgetType() ) { + QWidget *w = (QWidget*)obj; + w->setBackgroundPixmap( bg ); + if ( bgName.isEmpty() ) { + // Solid Color + if ( val.isEmpty() ) + w->setBackgroundColor( colorGroup().base() ); + else + w->setBackgroundColor( val ); + } else { + // Ruled or Image pixmap + w->setBackgroundOrigin( ParentOrigin ); + } } } + delete list; bgType = t; icons->viewport()->update(); + + QTimer::singleShot( 1000, this, SLOT(flushBgCache()) ); } @@ -849,9 +929,11 @@ void LauncherView::setViewFont( const QFont &f ) { icons->setFont( f ); + icons->hideOrShowItems( FALSE ); } -void LauncherView::unsetViewFont( ) +void LauncherView::clearViewFont() { - icons->unsetFont( ); + icons->unsetFont(); + icons->hideOrShowItems( FALSE ); } @@ -863,15 +945,4 @@ void LauncherView::resizeEvent(QResizeEvent *e) } -void LauncherView::populate( AppLnkSet *folder, const QString& typefilter ) -{ - icons->clear(); - internalPopulate( folder, typefilter ); -} - -QString LauncherView::getAllDocLinkInfo() const -{ - return icons->getAllDocLinkInfo(); -} - void LauncherView::selectionChanged() { @@ -912,30 +983,13 @@ void LauncherView::itemPressed( int btn, QIconViewItem *item ) if ( btn == RightButton ) emit rightPressed( appLnk ); -/* - else if ( btn == LeftButton ) - emit clicked( appLnk ); -*/ + else if ( btn == ShiftButton ) + emit rightPressed( appLnk ); item->setSelected(FALSE); } } -void LauncherView::internalPopulate( AppLnkSet *folder, const QString& typefilter ) +void LauncherView::removeAllItems() { - 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(); + icons->clear(); } @@ -945,4 +999,16 @@ bool LauncherView::removeLink(const QString& linkfile) } +void LauncherView::setSortEnabled( bool v ) +{ + icons->setSorting( v ); + if ( v ) + sort(); +} + +void LauncherView::setUpdatesEnabled( bool u ) +{ + icons->setUpdatesEnabled( u ); +} + void LauncherView::sort() { @@ -955,9 +1021,4 @@ void LauncherView::addItem(AppLnk* app, bool resort) } -void LauncherView::setFileSystems(const QList<FileSystem> &) -{ - // ### does nothing now... -} - void LauncherView::paletteChange( const QPalette &p ) { @@ -971,11 +1032,29 @@ void LauncherView::paletteChange( const QPalette &p ) } +void LauncherView::fontChanged(const QFont&) +{ + qDebug("LauncherView::fontChanged()"); + icons->hideOrShowItems( FALSE ); +} -void LauncherView::setBusyIndicatorType ( const QString &type ) +void LauncherView::relayout(void) { - if ( type. lower ( ) == "blink" ) - icons-> setBusyIndicatorType ( BIT_Blinking ); - else - icons-> setBusyIndicatorType ( BIT_Normal ); + icons->hideOrShowItems(FALSE); +} + +void LauncherView::flushBgCache() +{ + if ( !bgCache ) + return; + // remove unreferenced backgrounds. + QMap<QString,BgPixmap*>::Iterator it = bgCache->begin(); + while ( it != bgCache->end() ) { + QMap<QString,BgPixmap*>::Iterator curr = it; + ++it; + if ( (*curr)->ref == 0 ) { + delete (*curr); + bgCache->remove( curr ); + } + } } |