diff options
Diffstat (limited to 'src/quick')
-rw-r--r-- | src/quick/items/qquickanimatedimage.cpp | 169 | ||||
-rw-r--r-- | src/quick/items/qquickanimatedimage_p.h | 3 | ||||
-rw-r--r-- | src/quick/items/qquickborderimage.cpp | 82 | ||||
-rw-r--r-- | src/quick/items/qquickimagebase.cpp | 57 | ||||
-rw-r--r-- | src/quick/items/qquickimagebase_p_p.h | 1 |
5 files changed, 168 insertions, 144 deletions
diff --git a/src/quick/items/qquickanimatedimage.cpp b/src/quick/items/qquickanimatedimage.cpp index b4c1bd435a..72b24a7fac 100644 --- a/src/quick/items/qquickanimatedimage.cpp +++ b/src/quick/items/qquickanimatedimage.cpp @@ -131,6 +131,8 @@ QQuickAnimatedImage::QQuickAnimatedImage(QQuickItem *parent) QQuickAnimatedImage::~QQuickAnimatedImage() { Q_D(QQuickAnimatedImage); + if (d->reply) + d->reply->deleteLater(); delete d->_movie; } @@ -233,14 +235,16 @@ void QQuickAnimatedImage::setSource(const QUrl &url) if (url == d->url) return; - delete d->_movie; - d->_movie = 0; - if (d->reply) { d->reply->deleteLater(); d->reply = 0; } + if (d->_movie) { + delete d->_movie; + d->_movie = 0; + } + d->url = url; emit sourceChanged(d->url); @@ -252,64 +256,43 @@ void QQuickAnimatedImage::load() { Q_D(QQuickAnimatedImage); - QQuickImageBase::Status oldStatus = d->status; - qreal oldProgress = d->progress; - if (d->url.isEmpty()) { - delete d->_movie; + if (d->progress != 0) { + d->progress = 0; + emit progressChanged(d->progress); + } + d->setImage(QImage()); - d->progress = 0; d->status = Null; - if (d->status != oldStatus) - emit statusChanged(d->status); - if (d->progress != oldProgress) - emit progressChanged(d->progress); + emit statusChanged(d->status); + + if (sourceSize() != d->oldSourceSize) { + d->oldSourceSize = sourceSize(); + emit sourceSizeChanged(); + } } else { QString lf = QQmlFile::urlToLocalFileOrQrc(d->url); if (!lf.isEmpty()) { - //### should be unified with movieRequestFinished d->_movie = new QMovie(lf); - if (!d->_movie->isValid()){ - qmlInfo(this) << "Error Reading Animated Image File " << d->url.toString(); - delete d->_movie; - d->_movie = 0; - d->status = Error; - if (d->status != oldStatus) - emit statusChanged(d->status); - return; - } - connect(d->_movie, SIGNAL(stateChanged(QMovie::MovieState)), - this, SLOT(playingStatusChanged())); - connect(d->_movie, SIGNAL(frameChanged(int)), - this, SLOT(movieUpdate())); - d->_movie->setCacheMode(QMovie::CacheAll); - if (d->playing) - d->_movie->start(); - else - d->_movie->jumpToFrame(0); - if (d->paused) - d->_movie->setPaused(true); - d->setImage(d->_movie->currentPixmap().toImage()); - d->status = Ready; - d->progress = 1.0; - if (d->status != oldStatus) + movieRequestFinished(); + } else { + if (d->status != Loading) { + d->status = Loading; emit statusChanged(d->status); - if (d->progress != oldProgress) + } + if (d->progress != 0) { + d->progress = 0; emit progressChanged(d->progress); - return; + } + QNetworkRequest req(d->url); + req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true); + + d->reply = qmlEngine(this)->networkAccessManager()->get(req); + QObject::connect(d->reply, SIGNAL(finished()), + this, SLOT(movieRequestFinished())); + QObject::connect(d->reply, SIGNAL(downloadProgress(qint64,qint64)), + this, SLOT(requestProgress(qint64,qint64))); } - - d->status = Loading; - d->progress = 0; - emit statusChanged(d->status); - emit progressChanged(d->progress); - QNetworkRequest req(d->url); - req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true); - d->reply = qmlEngine(this)->networkAccessManager()->get(req); - QObject::connect(d->reply, SIGNAL(finished()), - this, SLOT(movieRequestFinished())); - QObject::connect(d->reply, SIGNAL(downloadProgress(qint64,qint64)), - this, SLOT(requestProgress(qint64,qint64))); } } @@ -319,58 +302,85 @@ void QQuickAnimatedImage::movieRequestFinished() { Q_D(QQuickAnimatedImage); - d->redirectCount++; - if (d->redirectCount < ANIMATEDIMAGE_MAXIMUM_REDIRECT_RECURSION) { - QVariant redirect = d->reply->attribute(QNetworkRequest::RedirectionTargetAttribute); - if (redirect.isValid()) { - QUrl url = d->reply->url().resolved(redirect.toUrl()); - d->reply->deleteLater(); - d->reply = 0; - setSource(url); - return; + if (d->reply) { + d->redirectCount++; + if (d->redirectCount < ANIMATEDIMAGE_MAXIMUM_REDIRECT_RECURSION) { + QVariant redirect = d->reply->attribute(QNetworkRequest::RedirectionTargetAttribute); + if (redirect.isValid()) { + QUrl url = d->reply->url().resolved(redirect.toUrl()); + d->reply->deleteLater(); + setSource(url); + return; + } } + + d->redirectCount=0; + d->_movie = new QMovie(d->reply); } - d->redirectCount=0; - d->_movie = new QMovie(d->reply); - if (!d->_movie->isValid()){ -#ifndef QT_NO_DEBUG_STREAM - qmlInfo(this) << "Error Reading Animated Image File " << d->url; -#endif + if (!d->_movie->isValid()) { + qmlInfo(this) << "Error Reading Animated Image File " << d->url.toString(); delete d->_movie; d->_movie = 0; + d->setImage(QImage()); + if (d->progress != 0) { + d->progress = 0; + emit progressChanged(d->progress); + } d->status = Error; emit statusChanged(d->status); + + if (sourceSize() != d->oldSourceSize) { + d->oldSourceSize = sourceSize(); + emit sourceSizeChanged(); + } return; } + connect(d->_movie, SIGNAL(stateChanged(QMovie::MovieState)), this, SLOT(playingStatusChanged())); connect(d->_movie, SIGNAL(frameChanged(int)), this, SLOT(movieUpdate())); d->_movie->setCacheMode(QMovie::CacheAll); + + d->status = Ready; + emit statusChanged(d->status); + + if (d->progress != 1.0) { + d->progress = 1.0; + emit progressChanged(d->progress); + } if (d->playing) d->_movie->start(); + + if (d->paused) + d->_movie->setPaused(true); if (d->paused || !d->playing) { d->_movie->jumpToFrame(d->preset_currentframe); d->preset_currentframe = 0; } - if (d->paused) - d->_movie->setPaused(true); d->setImage(d->_movie->currentPixmap().toImage()); - d->status = Ready; - emit statusChanged(d->status); + + if (sourceSize() != d->oldSourceSize) { + d->oldSourceSize = sourceSize(); + emit sourceSizeChanged(); + } } void QQuickAnimatedImage::movieUpdate() { Q_D(QQuickAnimatedImage); - d->setImage(d->_movie->currentPixmap().toImage()); - emit frameChanged(); + + if (d->_movie) { + d->setImage(d->_movie->currentPixmap().toImage()); + emit frameChanged(); + } } void QQuickAnimatedImage::playingStatusChanged() { Q_D(QQuickAnimatedImage); + if ((d->_movie->state() != QMovie::NotRunning) != d->playing) { d->playing = (d->_movie->state() != QMovie::NotRunning); emit playingChanged(); @@ -381,16 +391,19 @@ void QQuickAnimatedImage::playingStatusChanged() } } +QSize QQuickAnimatedImage::sourceSize() +{ + Q_D(QQuickAnimatedImage); + if (!d->_movie) + return QSize(0, 0); + return QSize(d->_movie->currentPixmap().size()); +} + void QQuickAnimatedImage::componentComplete() { Q_D(QQuickAnimatedImage); QQuickItem::componentComplete(); // NOT QQuickImage - if (d->url.isValid()) - load(); - if (!d->reply) { - setCurrentFrame(d->preset_currentframe); - d->preset_currentframe = 0; - } + load(); } QT_END_NAMESPACE diff --git a/src/quick/items/qquickanimatedimage_p.h b/src/quick/items/qquickanimatedimage_p.h index 86910199ac..0841683f38 100644 --- a/src/quick/items/qquickanimatedimage_p.h +++ b/src/quick/items/qquickanimatedimage_p.h @@ -80,8 +80,9 @@ public: int frameCount() const; - // Extends QQuickImage's src property*/ + // Extends QQuickImage's src property virtual void setSource(const QUrl&); + virtual QSize sourceSize(); Q_SIGNALS: void playingChanged(); diff --git a/src/quick/items/qquickborderimage.cpp b/src/quick/items/qquickborderimage.cpp index 889877aea1..6c0387f859 100644 --- a/src/quick/items/qquickborderimage.cpp +++ b/src/quick/items/qquickborderimage.cpp @@ -293,34 +293,42 @@ void QQuickBorderImage::setSource(const QUrl &url) void QQuickBorderImage::load() { Q_D(QQuickBorderImage); - if (d->progress != 0.0) { - d->progress = 0.0; - emit progressChanged(d->progress); - } if (d->url.isEmpty()) { d->pix.clear(this); d->status = Null; setImplicitSize(0, 0); emit statusChanged(d->status); + if (d->progress != 0.0) { + d->progress = 0.0; + emit progressChanged(d->progress); + } + if (sourceSize() != d->oldSourceSize) { + d->oldSourceSize = sourceSize(); + emit sourceSizeChanged(); + } update(); return; } else { - d->status = Loading; if (d->url.path().endsWith(QLatin1String("sci"))) { QString lf = QQmlFile::urlToLocalFileOrQrc(d->url); if (!lf.isEmpty()) { QFile file(lf); file.open(QIODevice::ReadOnly); setGridScaledImage(QQuickGridScaledImage(&file)); + return; } else { + if (d->progress != 0.0) { + d->progress = 0.0; + emit progressChanged(d->progress); + } + d->status = Loading; QNetworkRequest req(d->url); d->sciReply = qmlEngine(this)->networkAccessManager()->get(req); qmlobject_connect(d->sciReply, QNetworkReply, SIGNAL(finished()), this, QQuickBorderImage, SLOT(sciRequestFinished())) } } else { - QQuickPixmap::Options options; if (d->async) options |= QQuickPixmap::Asynchronous; @@ -330,23 +338,15 @@ void QQuickBorderImage::load() d->pix.load(qmlEngine(this), d->url, options); if (d->pix.isLoading()) { + if (d->progress != 0.0) { + d->progress = 0.0; + emit progressChanged(d->progress); + } + d->status = Loading; d->pix.connectFinished(this, SLOT(requestFinished())); d->pix.connectDownloadProgress(this, SLOT(requestProgress(qint64,qint64))); } else { - QSize impsize = d->pix.implicitSize(); - setImplicitSize(impsize.width(), impsize.height()); - - if (d->pix.isReady()) { - d->status = Ready; - } else { - d->status = Error; - qmlInfo(this) << d->pix.error(); - } - - d->progress = 1.0; - emit statusChanged(d->status); - emit progressChanged(d->progress); - update(); + requestFinished(); return; } } @@ -462,6 +462,14 @@ void QQuickBorderImage::setGridScaledImage(const QQuickGridScaledImage& sci) d->pix.load(qmlEngine(this), d->sciurl, options); if (d->pix.isLoading()) { + if (d->progress != 0.0) { + d->progress = 0.0; + emit progressChanged(d->progress); + } + if (d->status != Loading) { + d->status = Loading; + emit statusChanged(d->status); + } static int thisRequestProgress = -1; static int thisRequestFinished = -1; if (thisRequestProgress == -1) { @@ -475,22 +483,7 @@ void QQuickBorderImage::setGridScaledImage(const QQuickGridScaledImage& sci) d->pix.connectDownloadProgress(this, thisRequestProgress); } else { - - QSize impsize = d->pix.implicitSize(); - setImplicitSize(impsize.width(), impsize.height()); - - if (d->pix.isReady()) { - d->status = Ready; - } else { - d->status = Error; - qmlInfo(this) << d->pix.error(); - } - - d->progress = 1.0; - emit statusChanged(d->status); - emit progressChanged(1.0); - update(); - + requestFinished(); } } } @@ -503,18 +496,25 @@ void QQuickBorderImage::requestFinished() if (d->pix.isError()) { d->status = Error; qmlInfo(this) << d->pix.error(); + if (d->progress != 0) { + d->progress = 0; + emit progressChanged(d->progress); + } } else { d->status = Ready; + if (d->progress != 1.0) { + d->progress = 1.0; + emit progressChanged(d->progress); + } } setImplicitSize(impsize.width(), impsize.height()); - - if (d->sourcesize.width() != d->pix.width() || d->sourcesize.height() != d->pix.height()) + emit statusChanged(d->status); + if (sourceSize() != d->oldSourceSize) { + d->oldSourceSize = sourceSize(); emit sourceSizeChanged(); + } - d->progress = 1.0; - emit statusChanged(d->status); - emit progressChanged(1.0); update(); } diff --git a/src/quick/items/qquickimagebase.cpp b/src/quick/items/qquickimagebase.cpp index 798050d776..e42b0ee2e2 100644 --- a/src/quick/items/qquickimagebase.cpp +++ b/src/quick/items/qquickimagebase.cpp @@ -187,27 +187,37 @@ void QQuickImageBase::load() if (d->url.isEmpty()) { d->pix.clear(this); - d->status = Null; - d->progress = 0.0; + if (d->progress != 0.0) { + d->progress = 0.0; + emit progressChanged(d->progress); + } pixmapChange(); - emit progressChanged(d->progress); + d->status = Null; emit statusChanged(d->status); + + if (sourceSize() != d->oldSourceSize) { + d->oldSourceSize = sourceSize(); + emit sourceSizeChanged(); + } update(); + } else { QQuickPixmap::Options options; if (d->async) options |= QQuickPixmap::Asynchronous; if (d->cache) options |= QQuickPixmap::Cache; - d->pix.clear(this); - pixmapChange(); d->pix.load(qmlEngine(this), d->url, d->sourcesize, options); if (d->pix.isLoading()) { - d->progress = 0.0; - d->status = Loading; - emit progressChanged(d->progress); - emit statusChanged(d->status); + if (d->progress != 0.0) { + d->progress = 0.0; + emit progressChanged(d->progress); + } + if (d->status != Loading) { + d->status = Loading; + emit statusChanged(d->status); + } static int thisRequestProgress = -1; static int thisRequestFinished = -1; @@ -231,28 +241,27 @@ void QQuickImageBase::requestFinished() { Q_D(QQuickImageBase); - QQuickImageBase::Status oldStatus = d->status; - qreal oldProgress = d->progress; - if (d->pix.isError()) { - d->status = Error; qmlInfo(this) << d->pix.error(); + d->pix.clear(this); + d->status = Error; + if (d->progress != 0.0) { + d->progress = 0.0; + emit progressChanged(d->progress); + } } else { d->status = Ready; + if (d->progress != 1.0) { + d->progress = 1.0; + emit progressChanged(d->progress); + } } - - d->progress = 1.0; - pixmapChange(); - - if (d->sourcesize.width() != d->pix.width() || d->sourcesize.height() != d->pix.height()) + emit statusChanged(d->status); + if (sourceSize() != d->oldSourceSize) { + d->oldSourceSize = sourceSize(); emit sourceSizeChanged(); - - if (d->status != oldStatus) - emit statusChanged(d->status); - if (d->progress != oldProgress) - emit progressChanged(d->progress); - + } update(); } diff --git a/src/quick/items/qquickimagebase_p_p.h b/src/quick/items/qquickimagebase_p_p.h index 6e452387ae..5708e6d177 100644 --- a/src/quick/items/qquickimagebase_p_p.h +++ b/src/quick/items/qquickimagebase_p_p.h @@ -80,6 +80,7 @@ public: QUrl url; qreal progress; QSize sourcesize; + QSize oldSourceSize; bool async : 1; bool cache : 1; bool mirror: 1; |