author | alwin <alwin> | 2004-11-08 15:22:07 (UTC) |
---|---|---|
committer | alwin <alwin> | 2004-11-08 15:22:07 (UTC) |
commit | cce0a7a0d315993645870e88591b4afd647480a7 (patch) (side-by-side diff) | |
tree | beb8886020fe12a0f77bbb22bf0da76d4a73a3d5 | |
parent | 40bbaace5492ce6420a2d4a353b24df64c142287 (diff) | |
download | opie-cce0a7a0d315993645870e88591b4afd647480a7.zip opie-cce0a7a0d315993645870e88591b4afd647480a7.tar.gz opie-cce0a7a0d315993645870e88591b4afd647480a7.tar.bz2 |
image preview for documenttab again, I think, for first shot it is
working fine now.
-rw-r--r-- | core/launcher/launcherview.cpp | 91 | ||||
-rw-r--r-- | core/launcher/launcherview.h | 5 |
2 files changed, 64 insertions, 32 deletions
diff --git a/core/launcher/launcherview.cpp b/core/launcher/launcherview.cpp index 673e53c..506c11e 100644 --- a/core/launcher/launcherview.cpp +++ b/core/launcher/launcherview.cpp @@ -28,278 +28,281 @@ #include <qtopia/mimetype.h> #include <qtopia/resource.h> using namespace Opie::Core; #include <qpe/qcopenvelope_qws.h> /* QT */ #include <qtimer.h> #include <qfileinfo.h> #include <qiconview.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 class BgPixmap { public: BgPixmap( const QPixmap &p ) : pm(p), ref(1) {} QPixmap pm; int ref; }; 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: + enum iconstate_t { + BASE_ICON, + WAITING_ICON, + EYE_ICON + }; + 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(); bool isEyeImage()const{return m_EyeImage;} virtual int compare ( QIconViewItem * i ) const; void paintItem( QPainter *p, const QColorGroup &cg ); void setBusyIndicatorType ( BusyIndicatorType t ) { busyType = t; } void setEyePixmap(const QPixmap&aIcon); + virtual QPixmap*pixmap()const; + protected: bool isBigIcon; int iteration; AppLnk* app; private: void paintAnimatedIcon( QPainter *p ); BusyIndicatorType busyType; int psize; QPixmap m_iPixmap; bool m_EyeImage; + iconstate_t m_EyeImageSet; }; - -bool LauncherView::bsy=FALSE; - -void LauncherView::setBusy(bool on) -{ - icons->setBusy(on); -} - -void LauncherView::setBusyIndicatorType( const QString& type ) { - if ( type. lower ( ) == "animated" ) - icons->setBusyIndicatorType( BIT_Animated ) ; - else - icons->setBusyIndicatorType( BIT_Normal ) ; -} - 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 psize( (bigIcon ? applnk->bigPixmap().width() :applnk->pixmap().width() ) ), m_iPixmap(), - m_EyeImage(false) + m_EyeImage(false), + m_EyeImageSet(BASE_ICON) { if (applnk->type().lower().startsWith("image/") && applnk->exec().contains("opie-eye",false)) { m_EyeImage = true; m_iPixmap = (bigIcon ? applnk->bigPixmap():applnk->pixmap()); } } LauncherItem::~LauncherItem() { LauncherIconView* liv = (LauncherIconView*)iconView(); if ( liv->busyItem() == this ) liv->setBusy(FALSE); delete app; } +QPixmap*LauncherItem::pixmap()const +{ + if (m_EyeImage && m_EyeImageSet == BASE_ICON) { + LauncherIconView* liv = (LauncherIconView*)iconView(); + liv->requestEyePix(this); + } + return QIconViewItem::pixmap(); +} + int LauncherItem::compare ( QIconViewItem * i ) const { LauncherIconView* view = (LauncherIconView*)iconView(); return view->compare(app,((LauncherItem *)i)->appLnk()); } 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 ) ); + liv->setItemTextBackground( cg.brush( QColorGroup::Highlight ) ); + mycg.setColor( QColorGroup::Text, cg.color( QColorGroup::HighlightedText ) ); } QIconViewItem::paintItem(p,mycg); // Paint animation overlay if ( liv->busyItem() == this ) - paintAnimatedIcon(p); + paintAnimatedIcon(p); if ( liv->currentItem() == this ) - liv->setItemTextBackground( oldBrush ); + liv->setItemTextBackground( oldBrush ); } - - 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 if ( busyType == BIT_Animated ) { 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 ); #else Q_UNUSED( pic ) #endif p->drawPixmap( x1, y1, dblBuf ); } void LauncherItem::animateIcon() { LauncherIconView* liv = (LauncherIconView*)iconView(); if ( liv->busyItem() != this || !app ) return; // Highlight the icon if ( iteration == 0 ) { QPixmap src = (isEyeImage()?m_iPixmap:(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((isEyeImage()?m_iPixmap:(isBigIcon ? app->bigPixmap() : app->pixmap()))); } void LauncherItem::setEyePixmap(const QPixmap&aIcon) { if (!isEyeImage()) return; m_iPixmap = aIcon; setPixmap(aIcon); + m_EyeImageSet = EYE_ICON; } //=========================================================================== // Implemantation of LauncherIconview start //=========================================================================== LauncherIconView::LauncherIconView( QWidget* parent, const char* name ) : QIconView(parent,name),tf(""),cf(0),bsy(0),busyTimer(0),bigIcns(TRUE),bgColor(white) { m_EyeCallBack = 0; sortmeth = Name; hidden.setAutoDelete(TRUE); ike = FALSE; calculateGrid( Bottom ); } LauncherIconView::~LauncherIconView() { #if 0 // debuggery QListIterator<AppLnk> it(hidden); AppLnk* l; while ((l=it.current())) { ++it; //odebug << "" << l << ": hidden (should remove)" << oendl; } #endif } int LauncherIconView::compare(const AppLnk* a, const AppLnk* b) { switch (sortmeth) { case Name: return a->name().lower().compare(b->name().lower()); 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; } void LauncherIconView::setSortMethod( SortMethod m ) { if ( sortmeth != m ) { sortmeth = m; sort(); @@ -376,121 +379,130 @@ void LauncherIconView::setBusy(bool on) LauncherItem *c = on ? (LauncherItem*)currentItem() : 0; if ( bsy != c ) { LauncherItem *oldBusy = bsy; bsy = c; if ( oldBusy ) { oldBusy->resetIcon(); } if ( bsy ) { bsy->setBusyIndicatorType( busyType ) ; bsy->animateIcon(); } } } void LauncherIconView::clear() { mimes.clear(); cats.clear(); QIconView::clear(); hidden.clear(); } QStringList LauncherIconView::mimeTypes() const { QStringList r; QDictIterator<void> it(mimes); while (it.current()) { r.append(it.currentKey()); ++it; } r.sort(); return r; } LauncherItem*LauncherIconView::findDocItem(const QString&fname) { LauncherItem* item = (LauncherItem*)firstItem(); while (item) { if (item->appLnk()->file()==fname) { break; } item = (LauncherItem*)item->nextItem(); } return item; } -void LauncherIconView::setEyePixmap(const QPixmap&aPixmap,const QString&aFile) +void LauncherIconView::setEyePixmap(const QPixmap&aPixmap,const QString&aFile,int width) { + int s = ( bigIcns ) ? AppLnk::bigIconSize() : AppLnk::smallIconSize(); + if (s!=width) return; LauncherItem*item = findDocItem(aFile); if (!item||!item->isEyeImage()) return; - item->setEyePixmap(aPixmap); } void LauncherIconView::checkCallback() { if (m_EyeCallBack) { return; } m_EyeCallBack = new LauncherThumbReceiver(); - connect(m_EyeCallBack,SIGNAL(sig_Thumbnail(const QPixmap&,const QString&)), - this,SLOT(setEyePixmap(const QPixmap&,const QString&))); + connect(m_EyeCallBack,SIGNAL(sig_Thumbnail(const QPixmap&,const QString&,int)), + this,SLOT(setEyePixmap(const QPixmap&,const QString&,int))); } void LauncherIconView::addCheckItem(AppLnk* app) { LauncherItem*item = new LauncherItem( this, app, bigIcns ); if (item->isEyeImage()) { checkCallback(); + } +} + +void LauncherIconView::requestEyePix(const LauncherItem*item) +{ + if (!item) return; + if (item->isEyeImage()) { + checkCallback(); int s = ( bigIcns ) ? AppLnk::bigIconSize() : AppLnk::smallIconSize(); - m_EyeCallBack->requestThumb(app->file(),s,s); + m_EyeCallBack->requestThumb(item->appLnk()->file(),s,s); } } void LauncherIconView::addItem(AppLnk* app, bool resort) { addCatsAndMimes(app); if ( (tf.isEmpty() || tf.match(app->type()) >= 0) && (cf == 0 || app->categories().contains(cf) || cf == -1 && app->categories().count() == 0 ) ) { addCheckItem(app); } else { hidden.append(app); } if ( resort ){ sort(); } } void LauncherIconView::updateCategoriesAndMimeTypes() { mimes.clear(); cats.clear(); LauncherItem* item = (LauncherItem*)firstItem(); while (item) { addCatsAndMimes(item->appLnk()); item = (LauncherItem*)item->nextItem(); } QListIterator<AppLnk> it(hidden); AppLnk* l; while ((l=it.current())) { addCatsAndMimes(l); ++it; } } void LauncherIconView::hideOrShowItems(bool resort) { viewport()->setUpdatesEnabled( FALSE ); hidden.setAutoDelete(FALSE); QList<AppLnk> links=hidden; hidden.clear(); hidden.setAutoDelete(TRUE); LauncherItem* item = (LauncherItem*)firstItem(); while (item) { links.append(item->takeAppLnk()); item = (LauncherItem*)item->nextItem(); } clear(); @@ -588,96 +600,111 @@ void LauncherIconView::styleChange( QStyle &old ) { QIconView::styleChange( old ); calculateGrid( itemTextPos() ); } //=========================================================================== // Implemantation of LauncherIconview end //=========================================================================== //=========================================================================== LauncherView::LauncherView( QWidget* parent, const char* name, WFlags fl ) : QVBox( parent, name, fl ) { catmb = 0; icons = new LauncherIconView( this ); setFocusProxy(icons); QPEApplication::setStylusOperation( icons->viewport(), QPEApplication::RightOnHold ); icons->setItemsMovable( FALSE ); icons->setAutoArrange( TRUE ); icons->setSorting( TRUE ); icons->setFrameStyle( QFrame::NoFrame ); icons->setMargin( 0 ); icons->setSelectionMode( QIconView::NoSelection ); icons->setBackgroundMode( PaletteBase ); icons->setResizeMode( QIconView::Fixed ); vmode = (ViewMode)-1; setViewMode( Icon ); connect( icons, SIGNAL(mouseButtonClicked(int,QIconViewItem*,const QPoint&)), SLOT(itemClicked(int,QIconViewItem*)) ); connect( icons, SIGNAL(selectionChanged()), SLOT(selectionChanged()) ); connect( icons, SIGNAL(returnPressed(QIconViewItem*)), SLOT(returnPressed(QIconViewItem*)) ); connect( icons, SIGNAL(mouseButtonPressed(int,QIconViewItem*,const QPoint&)), SLOT(itemPressed(int,QIconViewItem*)) ); tools = 0; setBackgroundType( Ruled, QString::null ); } LauncherView::~LauncherView() { if ( bgCache && bgCache->contains( bgName ) ) (*bgCache)[bgName]->ref--; } + +bool LauncherView::bsy=FALSE; + +void LauncherView::setBusy(bool on) +{ + icons->setBusy(on); +} + +void LauncherView::setBusyIndicatorType( const QString& type ) { + if ( type. lower ( ) == "animated" ) + icons->setBusyIndicatorType( BIT_Animated ) ; + else + icons->setBusyIndicatorType( BIT_Normal ) ; +} + void LauncherView::hideIcons() { icons->hide(); } void LauncherView::setToolsEnabled(bool y) { if ( !y != !tools ) { if ( y ) { tools = new QHBox(this); // Type filter typemb = new QComboBox(tools); QSizePolicy p = typemb->sizePolicy(); p.setHorData(QSizePolicy::Expanding); typemb->setSizePolicy(p); // Category filter updateTools(); tools->show(); } else { delete tools; tools = 0; } } } void LauncherView::updateTools() { disconnect( typemb, SIGNAL(activated(int)), this, SLOT(showType(int)) ); if ( catmb ) disconnect( catmb, SIGNAL(signalSelected(int)), this, SLOT(showCategory(int)) ); // ### I want to remove this icons->updateCategoriesAndMimeTypes(); QString prev; // Type filter QStringList types; typelist = icons->mimeTypes(); for (QStringList::ConstIterator it = typelist.begin(); it!=typelist.end(); ++it) { QString t = *it; if ( t.left(12) == "application/" ) { MimeType mt(t); const AppLnk* app = mt.application(); @@ -1008,110 +1035,114 @@ void LauncherView::setUpdatesEnabled( bool u ) void LauncherView::sort() { icons->sort(); } void LauncherView::addItem(AppLnk* app, bool resort) { icons->addItem(app,resort); } 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::fontChanged(const QFont&) { odebug << "LauncherView::fontChanged()" << oendl; icons->hideOrShowItems( FALSE ); } void LauncherView::relayout(void) { 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 ); } } } +/* + * Launcherthumbnail handling for image files + */ + /* special image handling - based on opie eye */ QDataStream &operator>>( QDataStream& s, PixmapInfo& inf ) { s >> inf.file >> inf.pixmap >> inf.width >> inf.height; return s; } QDataStream &operator<<( QDataStream& s, const PixmapInfo& inf) { return s << inf.file << inf.width << inf.height; } LauncherThumbReceiver::LauncherThumbReceiver() :QObject() { QCopChannel * chan = new QCopChannel( "QPE/opie-eye",this ); connect(chan, SIGNAL(received(const QCString&,const QByteArray&)), this, SLOT(recieve(const QCString&,const QByteArray&)) ); { QCopEnvelope( "QPE/Application/opie-eye_slave", "refUp()" ); } } LauncherThumbReceiver::~LauncherThumbReceiver() { { QCopEnvelope( "QPE/Application/opie-eye_slave", "refDown()" ); } } void LauncherThumbReceiver::recieve( const QCString&str, const QByteArray&at ) { PixmapInfos pixinfos; QDataStream stream( at, IO_ReadOnly ); /* we are just interested in thumbmails */ if ( str == "pixmapsHandled(PixmapList)" ) stream >> pixinfos; for ( PixmapInfos::Iterator it = pixinfos.begin(); it != pixinfos.end(); ++it ) { odebug << "Pixinfos: " << (*it).file << " - " << (*it).width << oendl; - emit sig_Thumbnail((*it).pixmap,(*it).file); + emit sig_Thumbnail((*it).pixmap,(*it).file,(*it).width); } } void LauncherThumbReceiver::requestThumb(const QString&file,int width,int height) { PixmapInfo rItem; rItem.file = file; rItem.width = width; rItem.height = height; m_inThumbNail.append(rItem); - QTimer::singleShot(2, this, SLOT(sendRequest())); + QTimer::singleShot(0, this, SLOT(sendRequest())); } void LauncherThumbReceiver::sendRequest() { if (m_inThumbNail.count()>0) { QCopEnvelope env("QPE/opie-eye_slave", "pixmapInfos(PixmapInfos)" ); env << m_inThumbNail; + m_inThumbNail.clear(); } - m_inThumbNail.clear(); } diff --git a/core/launcher/launcherview.h b/core/launcher/launcherview.h index 3cca7f7..0be9a1f 100644 --- a/core/launcher/launcherview.h +++ b/core/launcher/launcherview.h @@ -101,153 +101,154 @@ protected: void fontChanged(const QFont &); private: static bool bsy; QWidget* tools; LauncherIconView* icons; QComboBox *typemb; QStringList typelist; CategorySelect *catmb; ViewMode vmode; BackgroundType bgType; QString bgName; QColor textCol; QImage loadBackgroundImage(QString &fname); }; /* from opie-eye */ struct PixmapInfo { PixmapInfo() : width( -1 ), height( -1 ) {} bool operator==( const PixmapInfo& r ) { if ( width != r.width ) return false; if ( height != r.height ) return false; if ( file != r.file ) return false; return true; } int width, height; QString file; QPixmap pixmap; }; class LauncherThumbReceiver:public QObject { Q_OBJECT typedef QValueList<PixmapInfo> PixmapInfos; public: LauncherThumbReceiver(); ~LauncherThumbReceiver(); void requestThumb(const QString&file,int width,int height); public slots: void recieve( const QCString&, const QByteArray& ); protected slots: virtual void sendRequest(); signals: - void sig_Thumbnail(const QPixmap&,const QString&); + void sig_Thumbnail(const QPixmap&,const QString&,int); protected: PixmapInfos m_inThumbNail; }; class LauncherIconView : public QIconView { Q_OBJECT public: LauncherIconView( QWidget* parent, const char* name=0 ); ~LauncherIconView(); QIconViewItem* busyItem() const; #ifdef USE_ANIMATED_BUSY_ICON_OVERLAY QPixmap busyPixmap() const { return busyPix; } #endif void setBigIcons( bool bi ); void updateCategoriesAndMimeTypes(); void setBusyIndicatorType ( BusyIndicatorType t ); void doAutoScroll() { // We don't want rubberbanding (yet) } void setBusy(bool on); bool inKeyEvent() const { return ike; } void keyPressEvent(QKeyEvent* e) { ike = TRUE; 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; } void addItem(AppLnk* app, bool resort=TRUE); bool removeLink(const QString& linkfile); QStringList mimeTypes() const; QStringList categories() const; void clear(); void addCatsAndMimes(AppLnk* app); void setBackgroundOrigin( QWidget::BackgroundOrigin ) {} void setBackgroundPixmap( const QPixmap &pm ) { bgPixmap = pm; } void setBackgroundColor( const QColor &c ) { bgColor = c; } void drawBackground( QPainter *p, const QRect &r ); void setItemTextPos( ItemTextPos pos ); void hideOrShowItems(bool resort); void setTypeFilter(const QString& typefilter, bool resort); void setCategoryFilter( int catfilter, bool resort ); enum SortMethod { Name, Date, Type }; void setSortMethod( SortMethod m ); int compare(const AppLnk* a, const AppLnk* b); + void requestEyePix(const LauncherItem*which); protected: void timerEvent( QTimerEvent *te ); void styleChange( QStyle &old ); void calculateGrid( ItemTextPos pos ); void focusInEvent( QFocusEvent * ) {} void focusOutEvent( QFocusEvent * ) {} LauncherItem*findDocItem(const QString&); void addCheckItem(AppLnk* app); void checkCallback(); protected slots: - void setEyePixmap(const QPixmap&,const QString&); + void setEyePixmap(const QPixmap&,const QString&,int width); private: QList<AppLnk> hidden; QDict<void> mimes; QDict<void> cats; SortMethod sortmeth; QRegExp tf; int cf; LauncherItem* bsy; int busyTimer; bool ike; bool bigIcns; QPixmap bgPixmap; QColor bgColor; LauncherThumbReceiver*m_EyeCallBack; #ifdef USE_ANIMATED_BUSY_ICON_OVERLAY QPixmap busyPix; #endif BusyIndicatorType busyType; }; #endif // LAUNCHERVIEW_H |