Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

thumbnailtool.cpp

Go to the documentation of this file.
00001 #include "thumbnailtool.h"
00002 
00003 /* OPIE */
00004 #include <opie2/odebug.h>
00005 using namespace Opie::Core;
00006 
00007 /* QT */
00008 #include <qfileinfo.h>
00009 #include <qdir.h>
00010 #include <qimage.h>
00011 #include <qpixmap.h>
00012 #include <qstring.h>
00013 
00014 static bool makeThumbDir( const QFileInfo& inf,  bool make = false) {
00015     QDir dir( inf.dirPath()+ "/.opie-eye" );
00016     if ( !dir.exists() )
00017         if ( make )
00018             return dir.mkdir(QString::null);
00019         else
00020             return false;
00021     return true;
00022 }
00023 
00024 
00025 /*
00026  * check if the Opie opie-eye dir exists
00027  * check if a thumbnail exists
00028  * load the thumbnail
00029  * /foo/bar/imagefoo.gif
00030  * check for a png in /foo/bar/.opie-eye/%dx%d-imagefoo.gif
00031  */
00032 QPixmap ThumbNailTool::getThumb( const QString& path, int width, int height ) {
00033     QFileInfo inf( path );
00034     if ( !makeThumbDir( inf ) ) {
00035         QPixmap pix;
00036         return pix;
00037     }
00038     QString str = QString( "/.opie-eye/%1x%2-%3" ).arg( width ).arg( height ).arg( inf.fileName() );
00039     return QPixmap( inf.dirPath()+str,"PNG" );
00040 
00041 }
00042 
00043 void ThumbNailTool::putThumb( const QString& path, const QPixmap& pix, int width, int height ) {
00044     QFileInfo inf( path );
00045     makeThumbDir( inf, true );
00046     QString str = QString( "/.opie-eye/%1x%2-%3" ).arg( width ).arg( height ).arg( inf.fileName() );
00047     pix.save( inf.dirPath()+str, "PNG" );
00048 }
00049 
00050 
00051 QPixmap ThumbNailTool::scaleImage( QImage& img, int w, int h ) {
00052     double hs = (double)h / (double)img.height() ;
00053     double ws = (double)w / (double)img.width() ;
00054     double scaleFactor = (hs > ws) ? ws : hs;
00055     int smoothW = (int)(scaleFactor * img.width());
00056     int smoothH = (int)(scaleFactor * img.height());
00057     QPixmap pixmap;
00058     if ( img.width() <= w && img.height() <= h )
00059         pixmap.convertFromImage( img );
00060     else
00061         pixmap.convertFromImage( img.smoothScale( smoothW, smoothH) );
00062     return pixmap;
00063 }

Generated on Sat Nov 5 16:17:31 2005 for OPIE by  doxygen 1.4.2