-rw-r--r-- | core/launcher/launcherview.cpp | 98 | ||||
-rw-r--r-- | core/launcher/launcherview.h | 36 |
2 files changed, 131 insertions, 3 deletions
diff --git a/core/launcher/launcherview.cpp b/core/launcher/launcherview.cpp index cd9c14b..1317bda 100644 --- a/core/launcher/launcherview.cpp +++ b/core/launcher/launcherview.cpp @@ -8,48 +8,50 @@ ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #include "launcherview.h" /* OPIE */ #include <opie2/odebug.h> #include <qtopia/qpeapplication.h> #include <qtopia/private/categories.h> #include <qtopia/categoryselect.h> #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; @@ -58,60 +60,67 @@ 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(); + 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); protected: bool isBigIcon; int iteration; AppLnk* app; + private: void paintAnimatedIcon( QPainter *p ); BusyIndicatorType busyType; + int psize; + QPixmap m_iPixmap; + bool m_EyeImage; + LauncherThumbReceiver*m_EyeCallback; }; class LauncherIconView : public QIconView { public: LauncherIconView( QWidget* parent, const char* name=0 ) : QIconView(parent,name), tf(""), cf(0), bsy(0), busyTimer(0), bigIcns(TRUE), bgColor(white) { sortmeth = Name; hidden.setAutoDelete(TRUE); ike = FALSE; calculateGrid( Bottom ); } ~LauncherIconView() { #if 0 // debuggery QListIterator<AppLnk> it(hidden); @@ -356,58 +365,68 @@ private: #endif BusyIndicatorType busyType; }; 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 + app(applnk), // Takes ownership + psize( (bigIcon ? applnk->bigPixmap().width() :applnk->pixmap().width() ) ), + m_iPixmap(), + m_EyeImage(false) { + m_EyeCallback = new LauncherThumbReceiver(this); + if (applnk->type().lower().startsWith("image/") && applnk->exec().contains("opie-eye",false)) { + m_EyeImage = true; + m_iPixmap = (bigIcon ? applnk->bigPixmap():applnk->pixmap()); + m_EyeCallback->requestThumb(applnk->file(),m_iPixmap.width(),m_iPixmap.height()); + } } LauncherItem::~LauncherItem() { LauncherIconView* liv = (LauncherIconView*)iconView(); if ( liv->busyItem() == this ) liv->setBusy(FALSE); delete app; + if (m_EyeCallback) delete m_EyeCallback; } 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 ) ); } QIconViewItem::paintItem(p,mycg); // Paint animation overlay if ( liv->busyItem() == this ) paintAnimatedIcon(p); @@ -439,85 +458,92 @@ void LauncherItem::paintAnimatedIcon( QPainter *p ) #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 = isBigIcon ? app->bigPixmap() : app->pixmap(); + 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( isBigIcon ? app->bigPixmap() : app->pixmap() ); + setPixmap((isEyeImage()?m_iPixmap:(isBigIcon ? app->bigPixmap() : app->pixmap()))); +} + +void LauncherItem::setEyePixmap(const QPixmap&aIcon) +{ + if (!isEyeImage()) return; + m_iPixmap = aIcon; + setPixmap(aIcon); } //=========================================================================== QStringList LauncherIconView::mimeTypes() const { QStringList r; QDictIterator<void> it(mimes); while (it.current()) { r.append(it.currentKey()); ++it; } r.sort(); return r; } 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 ) ) (void) new LauncherItem( this, app, bigIcns ); @@ -1038,24 +1064,90 @@ void LauncherView::fontChanged(const QFont&) 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 ); } } } +/* 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(LauncherItem*parent) + :QObject() +{ + m_parent = parent; + 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()" ); + } + m_waiting = false; +} + +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 ); + if (!m_parent || !m_waiting) return; + /* we are just interested in thumbmails */ + if ( str == "pixmapsHandled(PixmapList)" ) + stream >> pixinfos; + + for ( PixmapInfos::Iterator it = pixinfos.begin(); it != pixinfos.end(); ++it ) { + if ((*it).file==m_reqFile) { + m_parent->setEyePixmap((*it).pixmap); + m_waiting = false; + break; + } + } +} + +void LauncherThumbReceiver::requestThumb(const QString&file,int width,int height) +{ + m_reqFile = file; + rItem.file = file; + rItem.width = width; + rItem.height = height; + QTimer::singleShot(1, this, SLOT(sendRequest())); +} + +void LauncherThumbReceiver::sendRequest() +{ + PixmapInfos m_inThumbNail; + m_inThumbNail.append(rItem); + QCopEnvelope env("QPE/opie-eye_slave", "pixmapInfos(PixmapInfos)" ); + env << m_inThumbNail; + m_waiting = true; +} diff --git a/core/launcher/launcherview.h b/core/launcher/launcherview.h index e40a006..a9ff9eb 100644 --- a/core/launcher/launcherview.h +++ b/core/launcher/launcherview.h @@ -6,48 +6,49 @@ ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #ifndef LAUNCHERVIEW_H #define LAUNCHERVIEW_H #include <qtopia/storage.h> #include <qtopia/applnk.h> #include <qvbox.h> class CategorySelect; class LauncherIconView; +class LauncherItem; class QIconView; class QIconViewItem; class QLabel; class QWidgetStack; class MenuButton; class QComboBox; enum BusyIndicatorType { BIT_Normal = 0, BIT_Animated }; class LauncherView : public QVBox { Q_OBJECT public: LauncherView( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); ~LauncherView(); void hideIcons(); @@ -95,25 +96,60 @@ protected slots: void resizeEvent(QResizeEvent *); void flushBgCache(); protected: void paletteChange( const QPalette & ); 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); }; +/* taken 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(LauncherItem*parent); + ~LauncherThumbReceiver(); + void requestThumb(const QString&file,int width,int height); + +public slots: + void recieve( const QCString&, const QByteArray& ); +protected slots: + virtual void sendRequest(); +protected: + LauncherItem*m_parent; + QString m_reqFile; + PixmapInfo rItem; + bool m_waiting:1; +}; + #endif // LAUNCHERVIEW_H |