author | zecke <zecke> | 2005-02-22 22:33:23 (UTC) |
---|---|---|
committer | zecke <zecke> | 2005-02-22 22:33:23 (UTC) |
commit | e33e10f5643a2fb5c640667939e4139bf7b580e2 (patch) (unidiff) | |
tree | 335b67bdf59a85235aeb3195062a894a9298913d | |
parent | 214b14b03ca3806142eacb2248af98a06f765e2a (diff) | |
download | opie-e33e10f5643a2fb5c640667939e4139bf7b580e2.zip opie-e33e10f5643a2fb5c640667939e4139bf7b580e2.tar.gz opie-e33e10f5643a2fb5c640667939e4139bf7b580e2.tar.bz2 |
No special (2nd) lookup for the inline pictures. This saves additional seeks.
people not having defined LIBQPE_... will not notice a different as we still
default to inline pictures
-rw-r--r-- | library/resource.cpp | 7 |
1 files changed, 0 insertions, 7 deletions
diff --git a/library/resource.cpp b/library/resource.cpp index f6b548d..a093e2f 100644 --- a/library/resource.cpp +++ b/library/resource.cpp | |||
@@ -105,129 +105,122 @@ QString Resource::findPixmap( const QString &pix ) | |||
105 | f = picsPath + pix + ".xpm"; | 105 | f = picsPath + pix + ".xpm"; |
106 | if ( QFile( f ).exists() ) | 106 | if ( QFile( f ).exists() ) |
107 | return f; | 107 | return f; |
108 | 108 | ||
109 | // All formats... | 109 | // All formats... |
110 | QStrList fileFormats = QImageIO::inputFormats(); | 110 | QStrList fileFormats = QImageIO::inputFormats(); |
111 | QString ff = fileFormats.first(); | 111 | QString ff = fileFormats.first(); |
112 | while ( fileFormats.current() ) { | 112 | while ( fileFormats.current() ) { |
113 | QStringList exts = MimeType("image/"+ff.lower()).extensions(); | 113 | QStringList exts = MimeType("image/"+ff.lower()).extensions(); |
114 | for ( QStringList::ConstIterator it = exts.begin(); it!=exts.end(); ++it ) { | 114 | for ( QStringList::ConstIterator it = exts.begin(); it!=exts.end(); ++it ) { |
115 | QString f = picsPath + pix + "." + *it; | 115 | QString f = picsPath + pix + "." + *it; |
116 | if ( QFile(f).exists() ) | 116 | if ( QFile(f).exists() ) |
117 | return f; | 117 | return f; |
118 | } | 118 | } |
119 | ff = fileFormats.next(); | 119 | ff = fileFormats.next(); |
120 | } | 120 | } |
121 | 121 | ||
122 | // Finally, no (or existing) extension... | 122 | // Finally, no (or existing) extension... |
123 | if ( QFile( picsPath + pix ).exists() ) | 123 | if ( QFile( picsPath + pix ).exists() ) |
124 | return picsPath + pix; | 124 | return picsPath + pix; |
125 | 125 | ||
126 | //qDebug("Cannot find pixmap: %s", pix.latin1()); | 126 | //qDebug("Cannot find pixmap: %s", pix.latin1()); |
127 | return QString(); | 127 | return QString(); |
128 | } | 128 | } |
129 | 129 | ||
130 | /*! | 130 | /*! |
131 | Returns a sound file for a sound called \a name. | 131 | Returns a sound file for a sound called \a name. |
132 | 132 | ||
133 | You should avoid including any filename type extension (e.g. .wav), | 133 | You should avoid including any filename type extension (e.g. .wav), |
134 | as the system will search for only those fileformats which are supported | 134 | as the system will search for only those fileformats which are supported |
135 | by the library. | 135 | by the library. |
136 | 136 | ||
137 | Currently, only WAV files are supported. | 137 | Currently, only WAV files are supported. |
138 | */ | 138 | */ |
139 | QString Resource::findSound( const QString &name ) | 139 | QString Resource::findSound( const QString &name ) |
140 | { | 140 | { |
141 | QString picsPath = QPEApplication::qpeDir() + "sounds/"; | 141 | QString picsPath = QPEApplication::qpeDir() + "sounds/"; |
142 | 142 | ||
143 | QString result; | 143 | QString result; |
144 | if ( QFile( (result = picsPath + name + ".wav") ).exists() ) | 144 | if ( QFile( (result = picsPath + name + ".wav") ).exists() ) |
145 | return result; | 145 | return result; |
146 | 146 | ||
147 | return QString(); | 147 | return QString(); |
148 | } | 148 | } |
149 | 149 | ||
150 | /*! | 150 | /*! |
151 | Returns a list of all sound names. | 151 | Returns a list of all sound names. |
152 | */ | 152 | */ |
153 | QStringList Resource::allSounds() | 153 | QStringList Resource::allSounds() |
154 | { | 154 | { |
155 | QDir resourcedir( QPEApplication::qpeDir() + "sounds/", "*.wav" ); | 155 | QDir resourcedir( QPEApplication::qpeDir() + "sounds/", "*.wav" ); |
156 | QStringList entries = resourcedir.entryList(); | 156 | QStringList entries = resourcedir.entryList(); |
157 | QStringList result; | 157 | QStringList result; |
158 | for (QStringList::Iterator i=entries.begin(); i != entries.end(); ++i) | 158 | for (QStringList::Iterator i=entries.begin(); i != entries.end(); ++i) |
159 | result.append((*i).replace(QRegExp("\\.wav"),"")); | 159 | result.append((*i).replace(QRegExp("\\.wav"),"")); |
160 | return result; | 160 | return result; |
161 | } | 161 | } |
162 | 162 | ||
163 | static QImage load_image(const QString &name) | 163 | static QImage load_image(const QString &name) |
164 | { | 164 | { |
165 | QImage img; | 165 | QImage img; |
166 | 166 | ||
167 | #ifndef LIBQPE_NO_INLINE_IMAGES | 167 | #ifndef LIBQPE_NO_INLINE_IMAGES |
168 | img = qembed_findImage(name.latin1()); | 168 | img = qembed_findImage(name.latin1()); |
169 | #else | ||
170 | QString f = Resource::findPixmap( "/inline/" + name ); | ||
171 | if ( !f.isEmpty() ) | ||
172 | { | ||
173 | img.load(f); | ||
174 | return img; | ||
175 | } | ||
176 | #endif | 169 | #endif |
177 | if ( img.isNull() ) | 170 | if ( img.isNull() ) |
178 | { | 171 | { |
179 | // No inlined image, try file | 172 | // No inlined image, try file |
180 | QString f = Resource::findPixmap(name); | 173 | QString f = Resource::findPixmap(name); |
181 | if ( !f.isEmpty() ) | 174 | if ( !f.isEmpty() ) |
182 | img.load(f); | 175 | img.load(f); |
183 | } | 176 | } |
184 | return img; | 177 | return img; |
185 | } | 178 | } |
186 | 179 | ||
187 | /*! | 180 | /*! |
188 | Returns the QImage called \a name. You should avoid including | 181 | Returns the QImage called \a name. You should avoid including |
189 | any filename type extension (e.g. .png, .xpm). | 182 | any filename type extension (e.g. .png, .xpm). |
190 | */ | 183 | */ |
191 | QImage Resource::loadImage( const QString &name) | 184 | QImage Resource::loadImage( const QString &name) |
192 | { | 185 | { |
193 | #ifndef QT_NO_DEPTH_32// have alpha-blended pixmaps | 186 | #ifndef QT_NO_DEPTH_32// have alpha-blended pixmaps |
194 | static QImage last_enabled; | 187 | static QImage last_enabled; |
195 | static QString last_enabled_name; | 188 | static QString last_enabled_name; |
196 | if ( name == last_enabled_name ) | 189 | if ( name == last_enabled_name ) |
197 | return last_enabled; | 190 | return last_enabled; |
198 | #endif | 191 | #endif |
199 | QImage img = load_image(name); | 192 | QImage img = load_image(name); |
200 | #ifndef QT_NO_DEPTH_32// have alpha-blended pixmaps | 193 | #ifndef QT_NO_DEPTH_32// have alpha-blended pixmaps |
201 | if ( img.isNull() ) { | 194 | if ( img.isNull() ) { |
202 | // No file, try generating | 195 | // No file, try generating |
203 | if ( name[name.length()-1]=='d' && name.right(9)=="_disabled" ) { | 196 | if ( name[name.length()-1]=='d' && name.right(9)=="_disabled" ) { |
204 | last_enabled_name = name.left(name.length()-9); | 197 | last_enabled_name = name.left(name.length()-9); |
205 | last_enabled = load_image(last_enabled_name); | 198 | last_enabled = load_image(last_enabled_name); |
206 | if ( last_enabled.isNull() ) { | 199 | if ( last_enabled.isNull() ) { |
207 | last_enabled_name = QString::null; | 200 | last_enabled_name = QString::null; |
208 | } else { | 201 | } else { |
209 | img.detach(); | 202 | img.detach(); |
210 | img.create( last_enabled.width(), last_enabled.height(), 32 ); | 203 | img.create( last_enabled.width(), last_enabled.height(), 32 ); |
211 | for ( int y = 0; y < img.height(); y++ ) { | 204 | for ( int y = 0; y < img.height(); y++ ) { |
212 | for ( int x = 0; x < img.width(); x++ ) { | 205 | for ( int x = 0; x < img.width(); x++ ) { |
213 | QRgb p = last_enabled.pixel( x, y ); | 206 | QRgb p = last_enabled.pixel( x, y ); |
214 | int a = qAlpha(p)/3; | 207 | int a = qAlpha(p)/3; |
215 | int g = qGray(qRed(p),qGreen(p),qBlue(p)); | 208 | int g = qGray(qRed(p),qGreen(p),qBlue(p)); |
216 | img.setPixel( x, y, qRgba(g,g,g,a) ); | 209 | img.setPixel( x, y, qRgba(g,g,g,a) ); |
217 | } | 210 | } |
218 | } | 211 | } |
219 | img.setAlphaBuffer( TRUE ); | 212 | img.setAlphaBuffer( TRUE ); |
220 | } | 213 | } |
221 | } | 214 | } |
222 | } | 215 | } |
223 | #endif | 216 | #endif |
224 | return img; | 217 | return img; |
225 | } | 218 | } |
226 | 219 | ||
227 | /*! | 220 | /*! |
228 | \fn QIconSet Resource::loadIconSet( const QString &name ) | 221 | \fn QIconSet Resource::loadIconSet( const QString &name ) |
229 | 222 | ||
230 | Returns a QIconSet for the pixmap named \a name. A disabled icon is | 223 | Returns a QIconSet for the pixmap named \a name. A disabled icon is |
231 | generated that conforms to the Qtopia look & feel. You should avoid | 224 | generated that conforms to the Qtopia look & feel. You should avoid |
232 | including any filename type extension (eg. .png, .xpm). | 225 | including any filename type extension (eg. .png, .xpm). |
233 | */ | 226 | */ |