47 #include <qdeclarativepixmapcache_p.h> |
47 #include <qdeclarativepixmapcache_p.h> |
48 |
48 |
49 #include <QFile> |
49 #include <QFile> |
50 |
50 |
51 QT_BEGIN_NAMESPACE |
51 QT_BEGIN_NAMESPACE |
52 |
|
53 |
|
54 /*! |
|
55 \class QDeclarativeImageBase |
|
56 \internal |
|
57 \brief The base class for declarative images. |
|
58 */ |
|
59 |
52 |
60 QDeclarativeImageBase::QDeclarativeImageBase(QDeclarativeImageBasePrivate &dd, QDeclarativeItem *parent) |
53 QDeclarativeImageBase::QDeclarativeImageBase(QDeclarativeImageBasePrivate &dd, QDeclarativeItem *parent) |
61 : QDeclarativeItem(dd, parent) |
54 : QDeclarativeItem(dd, parent) |
62 { |
55 { |
63 } |
56 } |
148 setImplicitHeight(0); |
141 setImplicitHeight(0); |
149 emit statusChanged(d->status); |
142 emit statusChanged(d->status); |
150 pixmapChange(); |
143 pixmapChange(); |
151 update(); |
144 update(); |
152 } else { |
145 } else { |
|
146 |
153 d->status = Loading; |
147 d->status = Loading; |
|
148 emit statusChanged(d->status); |
154 |
149 |
155 d->pix.load(qmlEngine(this), d->url, d->sourcesize, d->async); |
150 d->pix.load(qmlEngine(this), d->url, d->sourcesize, d->async); |
156 |
151 |
157 if (d->pix.isLoading()) { |
152 if (d->pix.isLoading()) { |
158 |
153 |
167 |
162 |
168 d->pix.connectFinished(this, thisRequestFinished); |
163 d->pix.connectFinished(this, thisRequestFinished); |
169 d->pix.connectDownloadProgress(this, thisRequestProgress); |
164 d->pix.connectDownloadProgress(this, thisRequestProgress); |
170 |
165 |
171 } else { |
166 } else { |
172 QSize impsize = d->pix.implicitSize(); |
167 requestFinished(); |
173 setImplicitWidth(impsize.width()); |
|
174 setImplicitHeight(impsize.height()); |
|
175 |
|
176 if (d->pix.isReady()) { |
|
177 d->status = Ready; |
|
178 |
|
179 if (!d->sourcesize.isValid()) |
|
180 emit sourceSizeChanged(); |
|
181 |
|
182 } else { |
|
183 d->status = Error; |
|
184 qmlInfo(this) << d->pix.error(); |
|
185 } |
|
186 d->progress = 1.0; |
|
187 emit statusChanged(d->status); |
|
188 emit progressChanged(d->progress); |
|
189 pixmapChange(); |
|
190 update(); |
|
191 } |
168 } |
192 |
169 } |
193 } |
|
194 |
|
195 emit statusChanged(d->status); |
|
196 } |
170 } |
197 |
171 |
198 void QDeclarativeImageBase::requestFinished() |
172 void QDeclarativeImageBase::requestFinished() |
199 { |
173 { |
200 Q_D(QDeclarativeImageBase); |
174 Q_D(QDeclarativeImageBase); |
201 |
|
202 QSize impsize = d->pix.implicitSize(); |
|
203 |
175 |
204 if (d->pix.isError()) { |
176 if (d->pix.isError()) { |
205 d->status = Error; |
177 d->status = Error; |
206 qmlInfo(this) << d->pix.error(); |
178 qmlInfo(this) << d->pix.error(); |
207 } |
179 } else { |
208 |
|
209 setImplicitWidth(impsize.width()); |
|
210 setImplicitHeight(impsize.height()); |
|
211 |
|
212 if (d->status == Loading) |
|
213 d->status = Ready; |
180 d->status = Ready; |
|
181 } |
|
182 |
214 d->progress = 1.0; |
183 d->progress = 1.0; |
|
184 |
|
185 setImplicitWidth(d->pix.width()); |
|
186 setImplicitHeight(d->pix.height()); |
|
187 |
|
188 if (d->sourcesize.width() != d->pix.width() || d->sourcesize.height() != d->pix.height()) { |
|
189 d->sourcesize.setWidth(d->pix.width()); |
|
190 d->sourcesize.setHeight(d->pix.height()); |
|
191 emit sourceSizeChanged(); |
|
192 } |
|
193 |
215 emit statusChanged(d->status); |
194 emit statusChanged(d->status); |
216 emit progressChanged(1.0); |
195 emit progressChanged(d->progress); |
217 if (!d->sourcesize.isValid()) |
|
218 emit sourceSizeChanged(); |
|
219 pixmapChange(); |
196 pixmapChange(); |
220 update(); |
197 update(); |
221 } |
198 } |
222 |
199 |
223 void QDeclarativeImageBase::requestProgress(qint64 received, qint64 total) |
200 void QDeclarativeImageBase::requestProgress(qint64 received, qint64 total) |