Diffstat (limited to 'noncore/graphics/opie-eye/slave/thumbnailtool.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/graphics/opie-eye/slave/thumbnailtool.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/noncore/graphics/opie-eye/slave/thumbnailtool.cpp b/noncore/graphics/opie-eye/slave/thumbnailtool.cpp new file mode 100644 index 0000000..a202457 --- a/dev/null +++ b/noncore/graphics/opie-eye/slave/thumbnailtool.cpp | |||
@@ -0,0 +1,61 @@ | |||
1 | #include "thumbnailtool.h" | ||
2 | |||
3 | #include <qfileinfo.h> | ||
4 | #include <qdir.h> | ||
5 | #include <qimage.h> | ||
6 | #include <qpixmap.h> | ||
7 | #include <qstring.h> | ||
8 | |||
9 | static bool makeThumbDir( const QFileInfo& inf, bool make = false) { | ||
10 | QDir dir( inf.dirPath()+ "/.opie-eye" ); | ||
11 | if ( !dir.exists() ) | ||
12 | if ( make ) | ||
13 | return dir.mkdir(QString::null); | ||
14 | else | ||
15 | return false; | ||
16 | return true; | ||
17 | } | ||
18 | |||
19 | |||
20 | /* | ||
21 | * check if the Opie opie-eye dir exists | ||
22 | * check if a thumbnail exists | ||
23 | * load the thumbnail | ||
24 | * /foo/bar/imagefoo.gif | ||
25 | * check for a png in /foo/bar/.opie-eye/%dx%d-imagefoo.gif | ||
26 | */ | ||
27 | QPixmap ThumbNailTool::getThumb( const QString& path, int width, int height ) { | ||
28 | QFileInfo inf( path ); | ||
29 | qWarning( "Get Thumb" ); | ||
30 | if ( !makeThumbDir( inf ) ) { | ||
31 | QPixmap pix; | ||
32 | return pix; | ||
33 | } | ||
34 | QString str = QString( "/.opie-eye/%1x%2-%3" ).arg( width ).arg( height ).arg( inf.fileName() ); | ||
35 | qWarning( inf.dirPath()+str ); | ||
36 | return QPixmap( inf.dirPath()+str,"PNG" ); | ||
37 | |||
38 | } | ||
39 | |||
40 | void ThumbNailTool::putThumb( const QString& path, const QPixmap& pix, int width, int height ) { | ||
41 | QFileInfo inf( path ); | ||
42 | makeThumbDir( inf, true ); | ||
43 | QString str = QString( "/.opie-eye/%1x%2-%3" ).arg( width ).arg( height ).arg( inf.fileName() ); | ||
44 | qWarning( inf.dirPath()+str ); | ||
45 | pix.save( inf.dirPath()+str, "PNG" ); | ||
46 | } | ||
47 | |||
48 | |||
49 | QPixmap ThumbNailTool::scaleImage( QImage& img, int w, int h ) { | ||
50 | double hs = (double)h / (double)img.height() ; | ||
51 | double ws = (double)w / (double)img.width() ; | ||
52 | double scaleFactor = (hs > ws) ? ws : hs; | ||
53 | int smoothW = (int)(scaleFactor * img.width()); | ||
54 | int smoothH = (int)(scaleFactor * img.height()); | ||
55 | QPixmap pixmap; | ||
56 | if ( img.width() <= w && img.height() <= h ) | ||
57 | pixmap.convertFromImage( img ); | ||
58 | else | ||
59 | pixmap.convertFromImage( img.smoothScale( smoothW, smoothH) ); | ||
60 | return pixmap; | ||
61 | } | ||