50 // to avoid IconLoader dependency in ThemeIndexer, which needs this source file. |
50 // to avoid IconLoader dependency in ThemeIndexer, which needs this source file. |
51 QString iconTypeFromFilename(const QString &iconPath) |
51 QString iconTypeFromFilename(const QString &iconPath) |
52 { |
52 { |
53 QString loweredIconPath = iconPath.toLower(); |
53 QString loweredIconPath = iconPath.toLower(); |
54 |
54 |
55 if (loweredIconPath.endsWith(".svgz") ) { |
55 if (loweredIconPath.endsWith(QLatin1String(".svgz"))) { |
56 return "SVG"; |
56 return QLatin1String("SVG"); |
57 } |
57 } |
58 if (loweredIconPath.endsWith(".qpic") ) { |
58 if (loweredIconPath.endsWith(QLatin1String(".qpic"))) { |
59 return "PIC"; |
59 return QLatin1String("PIC"); |
60 } |
60 } |
61 |
61 |
62 if (loweredIconPath.endsWith(".svg") |
62 if (loweredIconPath.endsWith(QLatin1String(".svg")) |
63 || loweredIconPath.endsWith(".png") |
63 || loweredIconPath.endsWith(QLatin1String(".png")) |
64 || loweredIconPath.endsWith(".mng") |
64 || loweredIconPath.endsWith(QLatin1String(".mng")) |
65 || loweredIconPath.endsWith(".gif") |
65 || loweredIconPath.endsWith(QLatin1String(".gif")) |
66 || loweredIconPath.endsWith(".xpm") |
66 || loweredIconPath.endsWith(QLatin1String(".xpm")) |
67 || loweredIconPath.endsWith(".jpg") |
67 || loweredIconPath.endsWith(QLatin1String(".jpg")) |
68 || loweredIconPath.endsWith(".nvg")) { |
68 || loweredIconPath.endsWith(QLatin1String(".nvg"))) { |
69 return iconPath.right(3).toUpper(); |
69 return iconPath.right(3).toUpper(); |
70 } |
70 } |
71 |
71 |
72 if (loweredIconPath.endsWith(".xml") |
72 if (loweredIconPath.endsWith(QLatin1String(".xml")) |
73 || loweredIconPath.endsWith(".axml") |
73 || loweredIconPath.endsWith(QLatin1String(".axml")) |
74 || loweredIconPath.endsWith(".fxml")) |
74 || loweredIconPath.endsWith(QLatin1String(".fxml"))) { |
75 { |
|
76 return "BLOB"; |
75 return "BLOB"; |
77 } |
76 } |
78 |
77 |
79 return iconPath.section('.', -1); |
78 return iconPath.section('.', -1); |
80 } |
79 } |
84 |
83 |
85 // Copied from HbNvgEnginePrivate::contentDimensions, |
84 // Copied from HbNvgEnginePrivate::contentDimensions, |
86 // to avoid NVG dependency in ThemeIndexer |
85 // to avoid NVG dependency in ThemeIndexer |
87 QSize nvgContentDimensions(const QByteArray &buffer) |
86 QSize nvgContentDimensions(const QByteArray &buffer) |
88 { |
87 { |
89 QSize ret(0,0); |
88 QSize ret(0, 0); |
90 if (buffer.length() < static_cast<qint32>(NVG_VIEWBOX_HEIGHT_OFS + sizeof (float))){ |
89 if (buffer.length() < static_cast<qint32>(NVG_VIEWBOX_HEIGHT_OFS + sizeof(float))) { |
91 ret = QSize(0, 0); |
90 ret = QSize(0, 0); |
92 } |
91 } |
93 |
92 |
94 const quint8* lBuf = (quint8*) buffer.data(); |
93 const quint8 *lBuf = (quint8 *) buffer.data(); |
95 if((buffer.length() > NVG_VIEWBOX_WIDTH_OFS) && (buffer.length() > NVG_VIEWBOX_HEIGHT_OFS)) { |
94 if ((buffer.length() > NVG_VIEWBOX_WIDTH_OFS) && (buffer.length() > NVG_VIEWBOX_HEIGHT_OFS)) { |
96 float lViewboxWidth = * (float*)(lBuf + NVG_VIEWBOX_WIDTH_OFS); |
95 // Do not change to qreal, no matter what krazy says. |
97 float lViewboxHeight = * (float*)(lBuf + NVG_VIEWBOX_HEIGHT_OFS); |
96 float lViewboxWidth = * (float *)(lBuf + NVG_VIEWBOX_WIDTH_OFS); |
98 |
97 float lViewboxHeight = * (float *)(lBuf + NVG_VIEWBOX_HEIGHT_OFS); |
99 if (lViewboxWidth > 0 && lViewboxHeight > 0) { |
98 |
100 ret = QSize((int)lViewboxWidth, (int)lViewboxHeight); |
99 if (lViewboxWidth > 0 && lViewboxHeight > 0) { |
101 } else { |
100 ret = QSize((int)lViewboxWidth, (int)lViewboxHeight); |
102 ret = QSize(0, 0); |
101 } else { |
103 } |
102 ret = QSize(0, 0); |
|
103 } |
104 } |
104 } |
105 return ret; |
105 return ret; |
106 } |
106 } |
107 |
107 |
108 |
108 |
109 #endif // HB_BOOTSTRAPPED |
109 #endif // HB_BOOTSTRAPPED |
110 |
110 |
111 /*! |
111 /*! |
112 \class HbIconSource |
112 \class HbIconSource |
113 |
113 |
114 \brief Encapsulates access (size and pixel data reading) to image files. |
114 \brief Encapsulates access (size and pixel data reading) to image files. |
115 |
115 |
116 \internal |
116 \internal |
117 */ |
117 */ |
118 |
118 |
171 if (!mDefaultSize.isValid()) { |
171 if (!mDefaultSize.isValid()) { |
172 type(); // make sure type is initialized |
172 type(); // make sure type is initialized |
173 if (mType == "NVG") { |
173 if (mType == "NVG") { |
174 #ifndef HB_BOOTSTRAPPED |
174 #ifndef HB_BOOTSTRAPPED |
175 #ifdef HB_NVG_CS_ICON |
175 #ifdef HB_NVG_CS_ICON |
176 if(!mByteArray){ |
176 if (!mByteArray) { |
177 QFile file(mFilename); |
177 QFile file(mFilename); |
178 if (!file.open(QIODevice::NotOpen | QIODevice::ReadOnly)) { |
178 if (!file.open(QIODevice::NotOpen | QIODevice::ReadOnly)) { |
179 return QSizeF(); |
179 return QSizeF(); |
180 } |
180 } |
181 mByteArray = new QByteArray(file.readAll()); |
181 mByteArray = new QByteArray(file.readAll()); |
182 } |
182 } |
183 HbNvgEngine nvgEngine; |
183 HbNvgEngine nvgEngine; |
184 mDefaultSize = nvgEngine.contentDimensions(*mByteArray); |
184 mDefaultSize = nvgEngine.contentDimensions(*mByteArray); |
185 #endif // HB_NVG_CS_ICON |
185 #endif // HB_NVG_CS_ICON |
186 #else // HB_BOOTSTRAPPED |
186 #else // HB_BOOTSTRAPPED |
187 |
187 |
188 if(!mByteArray){ |
188 if (!mByteArray) { |
189 QFile file(mFilename); |
189 QFile file(mFilename); |
190 if (!file.open(QIODevice::NotOpen | QIODevice::ReadOnly)) { |
190 if (!file.open(QIODevice::NotOpen | QIODevice::ReadOnly)) { |
191 return QSizeF(); |
191 return QSizeF(); |
192 } |
192 } |
193 mByteArray = new QByteArray (file.readAll()); |
193 mByteArray = new QByteArray(file.readAll()); |
194 } |
194 } |
195 |
195 |
196 mDefaultSize = nvgContentDimensions(*mByteArray); |
196 mDefaultSize = nvgContentDimensions(*mByteArray); |
197 #endif |
197 #endif |
198 } |
198 } else if (mType == "SVG") { |
199 else if (mType == "SVG") { |
|
200 QSvgRenderer *renderer = svgRenderer(); |
199 QSvgRenderer *renderer = svgRenderer(); |
201 if (renderer) { // isValid() is already checked in svgRenderer() |
200 if (renderer) { // isValid() is already checked in svgRenderer() |
202 mDefaultSize = renderer->defaultSize(); |
201 mDefaultSize = renderer->defaultSize(); |
203 } |
202 } |
204 releaseSvgRenderer(); |
203 releaseSvgRenderer(); |
205 } |
204 } else if (mType == "PIC") { |
206 else if (mType == "PIC") { |
|
207 if (!mPicture) { |
205 if (!mPicture) { |
208 mPicture = new QPicture; |
206 mPicture = new QPicture; |
209 mPicture->load(mFilename); |
207 mPicture->load(mFilename); |
210 } |
208 } |
211 mDefaultSize = mPicture->boundingRect().size(); |
209 mDefaultSize = mPicture->boundingRect().size(); |
227 QImage img = reader->read(); |
225 QImage img = reader->read(); |
228 mDefaultSize = img.size(); |
226 mDefaultSize = img.size(); |
229 } |
227 } |
230 } |
228 } |
231 releaseImageReader(); |
229 releaseImageReader(); |
232 } |
230 } else if (mType != "BLOB") { |
233 else if (mType != "BLOB") { |
|
234 if (!mPixmap) { |
231 if (!mPixmap) { |
235 mPixmap = new QPixmap(mFilename); |
232 mPixmap = new QPixmap(mFilename); |
236 } |
233 } |
237 mDefaultSize = mPixmap->size(); |
234 mDefaultSize = mPixmap->size(); |
238 } |
235 } |
268 */ |
265 */ |
269 void HbIconSource::takeSvgRenderer() |
266 void HbIconSource::takeSvgRenderer() |
270 { |
267 { |
271 mSvgRenderer = 0; |
268 mSvgRenderer = 0; |
272 } |
269 } |
273 |
270 |
274 QByteArray* HbIconSource::byteArray() |
271 QByteArray *HbIconSource::byteArray() |
275 { |
272 { |
276 if (!mByteArray) { |
273 if (!mByteArray) { |
277 #ifdef HB_NVG_CS_ICON |
274 #ifdef HB_NVG_CS_ICON |
278 QFile file(mFilename); |
275 QFile file(mFilename); |
279 if (!file.open(QIODevice::NotOpen | QIODevice::ReadOnly)) { |
276 if (!file.open(QIODevice::NotOpen | QIODevice::ReadOnly)) { |
280 return 0; |
277 return 0; |
281 } |
278 } |
282 mByteArray = new QByteArray (file.readAll()); |
279 mByteArray = new QByteArray(file.readAll()); |
283 #endif//nvg |
280 #endif |
284 } |
281 } |
285 |
282 |
286 if (!mByteArray->isEmpty()) { |
283 if (mByteArray && !mByteArray->isEmpty()) { |
287 return mByteArray; |
284 return mByteArray; |
288 } else { |
285 } else { |
289 return 0; |
286 return 0; |
290 } |
287 } |
291 } |
288 } |
304 caller. However make sure to call releaseImageReader() as soon as possible. |
301 caller. However make sure to call releaseImageReader() as soon as possible. |
305 */ |
302 */ |
306 QImageReader *HbIconSource::imageReader() |
303 QImageReader *HbIconSource::imageReader() |
307 { |
304 { |
308 if (!mImageReader) { |
305 if (!mImageReader) { |
|
306 type(); // make sure type is initialized |
309 mImageReader = new QImageReader(mFilename, mType.toLatin1()); |
307 mImageReader = new QImageReader(mFilename, mType.toLatin1()); |
310 } |
308 } |
311 return mImageReader && mImageReader->canRead() ? mImageReader : 0; |
309 return mImageReader && mImageReader->canRead() ? mImageReader : 0; |
312 } |
310 } |
313 |
311 |