141 d->progress = 0.0; |
140 d->progress = 0.0; |
142 emit progressChanged(d->progress); |
141 emit progressChanged(d->progress); |
143 } |
142 } |
144 |
143 |
145 if (d->url.isEmpty()) { |
144 if (d->url.isEmpty()) { |
146 d->pix = QPixmap(); |
145 d->pix.clear(); |
147 d->status = Null; |
146 d->status = Null; |
148 setImplicitWidth(0); |
147 setImplicitWidth(0); |
149 setImplicitHeight(0); |
148 setImplicitHeight(0); |
150 emit statusChanged(d->status); |
149 emit statusChanged(d->status); |
151 pixmapChange(); |
150 pixmapChange(); |
152 update(); |
151 update(); |
153 } else { |
152 } else { |
154 d->status = Loading; |
153 d->status = Loading; |
155 int reqwidth = d->sourcesize.width(); |
154 |
156 int reqheight = d->sourcesize.height(); |
155 d->pix.load(qmlEngine(this), d->url, d->sourcesize, d->async); |
157 QSize impsize; |
156 |
158 QString errorString; |
157 if (d->pix.isLoading()) { |
159 QDeclarativePixmapReply::Status status = QDeclarativePixmapCache::get(d->url, &d->pix, &errorString, &impsize, d->async, reqwidth, reqheight); |
158 |
160 if (status != QDeclarativePixmapReply::Ready && status != QDeclarativePixmapReply::Error) { |
|
161 QDeclarativePixmapReply *reply = QDeclarativePixmapCache::request(qmlEngine(this), d->url, reqwidth, reqheight); |
|
162 d->pendingPixmapCache = true; |
|
163 |
|
164 static int replyDownloadProgress = -1; |
|
165 static int replyFinished = -1; |
|
166 static int thisRequestProgress = -1; |
159 static int thisRequestProgress = -1; |
167 static int thisRequestFinished = -1; |
160 static int thisRequestFinished = -1; |
168 if (replyDownloadProgress == -1) { |
161 if (thisRequestProgress == -1) { |
169 replyDownloadProgress = |
|
170 QDeclarativePixmapReply::staticMetaObject.indexOfSignal("downloadProgress(qint64,qint64)"); |
|
171 replyFinished = |
|
172 QDeclarativePixmapReply::staticMetaObject.indexOfSignal("finished()"); |
|
173 thisRequestProgress = |
162 thisRequestProgress = |
174 QDeclarativeImageBase::staticMetaObject.indexOfSlot("requestProgress(qint64,qint64)"); |
163 QDeclarativeImageBase::staticMetaObject.indexOfSlot("requestProgress(qint64,qint64)"); |
175 thisRequestFinished = |
164 thisRequestFinished = |
176 QDeclarativeImageBase::staticMetaObject.indexOfSlot("requestFinished()"); |
165 QDeclarativeImageBase::staticMetaObject.indexOfSlot("requestFinished()"); |
177 } |
166 } |
178 |
167 |
179 QMetaObject::connect(reply, replyFinished, this, |
168 d->pix.connectFinished(this, thisRequestFinished); |
180 thisRequestFinished, Qt::DirectConnection); |
169 d->pix.connectDownloadProgress(this, thisRequestProgress); |
181 QMetaObject::connect(reply, replyDownloadProgress, this, |
170 |
182 thisRequestProgress, Qt::DirectConnection); |
|
183 } else { |
171 } else { |
184 //### should be unified with requestFinished |
172 QSize impsize = d->pix.implicitSize(); |
185 if (status == QDeclarativePixmapReply::Ready) { |
173 setImplicitWidth(impsize.width()); |
186 setImplicitWidth(impsize.width()); |
174 setImplicitHeight(impsize.height()); |
187 setImplicitHeight(impsize.height()); |
175 |
188 |
176 if (d->pix.isReady()) { |
189 if (d->status == Loading) |
177 d->status = Ready; |
190 d->status = Ready; |
|
191 |
178 |
192 if (!d->sourcesize.isValid()) |
179 if (!d->sourcesize.isValid()) |
193 emit sourceSizeChanged(); |
180 emit sourceSizeChanged(); |
|
181 |
194 } else { |
182 } else { |
195 d->status = Error; |
183 d->status = Error; |
196 qmlInfo(this) << errorString; |
184 qmlInfo(this) << d->pix.error(); |
197 } |
185 } |
198 d->progress = 1.0; |
186 d->progress = 1.0; |
199 emit statusChanged(d->status); |
187 emit statusChanged(d->status); |
200 emit progressChanged(d->progress); |
188 emit progressChanged(d->progress); |
201 pixmapChange(); |
189 pixmapChange(); |
202 update(); |
190 update(); |
203 } |
191 } |
|
192 |
204 } |
193 } |
205 |
194 |
206 emit statusChanged(d->status); |
195 emit statusChanged(d->status); |
207 } |
196 } |
208 |
197 |
209 void QDeclarativeImageBase::requestFinished() |
198 void QDeclarativeImageBase::requestFinished() |
210 { |
199 { |
211 Q_D(QDeclarativeImageBase); |
200 Q_D(QDeclarativeImageBase); |
212 |
201 |
213 d->pendingPixmapCache = false; |
202 QSize impsize = d->pix.implicitSize(); |
214 |
203 |
215 QSize impsize; |
204 if (d->pix.isError()) { |
216 QString errorString; |
|
217 if (QDeclarativePixmapCache::get(d->url, &d->pix, &errorString, &impsize, d->async, d->sourcesize.width(), d->sourcesize.height()) != QDeclarativePixmapReply::Ready) { |
|
218 d->status = Error; |
205 d->status = Error; |
219 qmlInfo(this) << errorString; |
206 qmlInfo(this) << d->pix.error(); |
220 } |
207 } |
|
208 |
221 setImplicitWidth(impsize.width()); |
209 setImplicitWidth(impsize.width()); |
222 setImplicitHeight(impsize.height()); |
210 setImplicitHeight(impsize.height()); |
223 |
211 |
224 if (d->status == Loading) |
212 if (d->status == Loading) |
225 d->status = Ready; |
213 d->status = Ready; |