-rw-r--r-- | library/resource.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/library/resource.cpp b/library/resource.cpp index cfa0d26..b31876f 100644 --- a/library/resource.cpp +++ b/library/resource.cpp | |||
@@ -46,39 +46,45 @@ static bool g_notUseSet = ::getenv("OVERWRITE_ICON_SET"); | |||
46 | 46 | ||
47 | Images can be loaded with loadImage(), loadPixmap(), loadBitmap() | 47 | Images can be loaded with loadImage(), loadPixmap(), loadBitmap() |
48 | and loadIconSet(). | 48 | and loadIconSet(). |
49 | 49 | ||
50 | \ingroup qtopiaemb | 50 | \ingroup qtopiaemb |
51 | */ | 51 | */ |
52 | 52 | ||
53 | /*! | 53 | /*! |
54 | \fn Resource::Resource() | 54 | \fn Resource::Resource() |
55 | \internal | 55 | \internal |
56 | */ | 56 | */ |
57 | 57 | ||
58 | /*! | 58 | /*! |
59 | Returns the QPixmap called \a pix. You should avoid including | 59 | Returns the QPixmap called \a pix. You should avoid including |
60 | any filename type extension (e.g. .png, .xpm). | 60 | any filename type extension (e.g. .png, .xpm). |
61 | */ | 61 | */ |
62 | #include <stdio.h> | ||
62 | QPixmap Resource::loadPixmap( const QString &pix ) | 63 | QPixmap Resource::loadPixmap( const QString &pix ) |
63 | { | 64 | { |
64 | QPixmap pm; | 65 | QPixmap pm; // null pixmap |
65 | QString key="QPE_"+pix; | 66 | QString key="QPE_"+pix; |
66 | if ( !QPixmapCache::find(key,pm) ) { | 67 | if ( !QPixmapCache::find(key,pm) ) { |
67 | pm.convertFromImage(loadImage(pix)); | 68 | QImage I = loadImage(pix); |
68 | QPixmapCache::insert(key,pm); | 69 | if( I.isNull() ) { |
70 | qWarning( "Could not load %s", pix.latin1() ); | ||
71 | } else { | ||
72 | pm.convertFromImage(I); | ||
73 | QPixmapCache::insert(key,pm); | ||
74 | } | ||
69 | } | 75 | } |
70 | return pm; | 76 | return pm; |
71 | } | 77 | } |
72 | 78 | ||
73 | /*! | 79 | /*! |
74 | Returns the QBitmap called \a pix. You should avoid including | 80 | Returns the QBitmap called \a pix. You should avoid including |
75 | any filename type extension (e.g. .png, .xpm). | 81 | any filename type extension (e.g. .png, .xpm). |
76 | */ | 82 | */ |
77 | QBitmap Resource::loadBitmap( const QString &pix ) | 83 | QBitmap Resource::loadBitmap( const QString &pix ) |
78 | { | 84 | { |
79 | QBitmap bm; | 85 | QBitmap bm; |
80 | bm = loadPixmap(pix); | 86 | bm = loadPixmap(pix); |
81 | return bm; | 87 | return bm; |
82 | } | 88 | } |
83 | 89 | ||
84 | /*! | 90 | /*! |
@@ -88,33 +94,32 @@ QBitmap Resource::loadBitmap( const QString &pix ) | |||
88 | Normally you will use loadPixmap() rather than this function. | 94 | Normally you will use loadPixmap() rather than this function. |
89 | */ | 95 | */ |
90 | QString Resource::findPixmap( const QString &pix ) | 96 | QString Resource::findPixmap( const QString &pix ) |
91 | { | 97 | { |
92 | QString picsPath = QPEApplication::qpeDir() + "pics/"; | 98 | QString picsPath = QPEApplication::qpeDir() + "pics/"; |
93 | 99 | ||
94 | QString f; | 100 | QString f; |
95 | 101 | ||
96 | // Common case optimizations... | 102 | // Common case optimizations... |
97 | f = picsPath + pix + ".png"; | 103 | f = picsPath + pix + ".png"; |
98 | if ( QFile( f ).exists() ) | 104 | if ( QFile( f ).exists() ) |
99 | return f; | 105 | return f; |
100 | f = picsPath + pix + ".xpm"; | 106 | f = picsPath + pix + ".xpm"; |
101 | if ( QFile( f ).exists() ) | 107 | if ( QFile( f ).exists() ) |
102 | return f; | 108 | return f; |
103 | 109 | ||
104 | |||
105 | // All formats... | 110 | // All formats... |
106 | QStrList fileFormats = QImageIO::inputFormats(); | 111 | QStrList fileFormats = QImageIO::inputFormats(); |
107 | QString ff = fileFormats.first(); | 112 | QString ff = fileFormats.first(); |
108 | while ( fileFormats.current() ) { | 113 | while ( fileFormats.current() ) { |
109 | QStringList exts = MimeType("image/"+ff.lower()).extensions(); | 114 | QStringList exts = MimeType("image/"+ff.lower()).extensions(); |
110 | for ( QStringList::ConstIterator it = exts.begin(); it!=exts.end(); ++it ) { | 115 | for ( QStringList::ConstIterator it = exts.begin(); it!=exts.end(); ++it ) { |
111 | QString f = picsPath + pix + "." + *it; | 116 | QString f = picsPath + pix + "." + *it; |
112 | if ( QFile(f).exists() ) | 117 | if ( QFile(f).exists() ) |
113 | return f; | 118 | return f; |
114 | } | 119 | } |
115 | ff = fileFormats.next(); | 120 | ff = fileFormats.next(); |
116 | } | 121 | } |
117 | 122 | ||
118 | // Finally, no (or existing) extension... | 123 | // Finally, no (or existing) extension... |
119 | if ( QFile( picsPath + pix ).exists() ) | 124 | if ( QFile( picsPath + pix ).exists() ) |
120 | return picsPath + pix; | 125 | return picsPath + pix; |