From 56693f7d247ee8da6b730b157d1871a1dceab5a8 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Fri, 14 Aug 2009 13:56:05 +1000 Subject: QFxPixmap -> QFxPixmapCache --- src/declarative/extra/qfxparticles.cpp | 10 +- src/declarative/fx/fx.pri | 4 +- src/declarative/fx/qfxborderimage.cpp | 14 +- src/declarative/fx/qfximagebase.cpp | 10 +- src/declarative/fx/qfxpixmap.cpp | 233 --------------------------------- src/declarative/fx/qfxpixmap.h | 70 ---------- src/declarative/fx/qfxpixmapcache.cpp | 231 ++++++++++++++++++++++++++++++++ src/declarative/fx/qfxpixmapcache.h | 70 ++++++++++ src/declarative/fx/qfxscalegrid_p.h | 2 +- 9 files changed, 321 insertions(+), 323 deletions(-) delete mode 100644 src/declarative/fx/qfxpixmap.cpp delete mode 100644 src/declarative/fx/qfxpixmap.h create mode 100644 src/declarative/fx/qfxpixmapcache.cpp create mode 100644 src/declarative/fx/qfxpixmapcache.h diff --git a/src/declarative/extra/qfxparticles.cpp b/src/declarative/extra/qfxparticles.cpp index f05f233..0e94ea6 100644 --- a/src/declarative/extra/qfxparticles.cpp +++ b/src/declarative/extra/qfxparticles.cpp @@ -50,7 +50,7 @@ #ifndef INT_MAX #define INT_MAX 2147483647 #endif -#include +#include #include #include #include @@ -617,7 +617,7 @@ QFxParticles::~QFxParticles() { Q_D(QFxParticles); if (!d->url.isEmpty()) - QFxPixmap::cancelGet(d->url, this); + QFxPixmapCache::cancelGet(d->url, this); } /*! @@ -638,7 +638,7 @@ QUrl QFxParticles::source() const void QFxParticles::imageLoaded() { Q_D(QFxParticles); - QFxPixmap::find(d->url, &d->image); + QFxPixmapCache::find(d->url, &d->image); d->paintItem->updateSize(); d->paintItem->update(); } @@ -651,7 +651,7 @@ void QFxParticles::setSource(const QUrl &name) return; if (!d->url.isEmpty()) - QFxPixmap::cancelGet(d->url, this); + QFxPixmapCache::cancelGet(d->url, this); if (name.isEmpty()) { d->url = name; d->image = QPixmap(); @@ -660,7 +660,7 @@ void QFxParticles::setSource(const QUrl &name) } else { d->url = name; Q_ASSERT(!name.isRelative()); - d->reply = QFxPixmap::get(qmlEngine(this), d->url, &d->image); + d->reply = QFxPixmapCache::get(qmlEngine(this), d->url, &d->image); if (d->reply) connect(d->reply, SIGNAL(finished()), this, SLOT(imageLoaded())); else { diff --git a/src/declarative/fx/fx.pri b/src/declarative/fx/fx.pri index 5f574cd..48af58e 100644 --- a/src/declarative/fx/fx.pri +++ b/src/declarative/fx/fx.pri @@ -41,7 +41,7 @@ HEADERS += \ fx/qfxtextedit_p.h \ fx/qfxtext.h \ fx/qfxtext_p.h \ - fx/qfxpixmap.cpp \ + fx/qfxpixmapcache.h \ fx/qfxvisualitemmodel.h \ fx/qfxlistview.h \ fx/qfxgraphicsobjectcontainer.h \ @@ -72,7 +72,7 @@ SOURCES += \ fx/qfxlineedit.cpp \ fx/qfxtext.cpp \ fx/qfxtextedit.cpp \ - fx/qfxpixmap.cpp \ + fx/qfxpixmapcache.cpp \ fx/qfxvisualitemmodel.cpp \ fx/qfxlistview.cpp \ fx/qfxgraphicsobjectcontainer.cpp \ diff --git a/src/declarative/fx/qfxborderimage.cpp b/src/declarative/fx/qfxborderimage.cpp index adb70a3..4920bf6 100644 --- a/src/declarative/fx/qfxborderimage.cpp +++ b/src/declarative/fx/qfxborderimage.cpp @@ -92,7 +92,7 @@ QFxBorderImage::~QFxBorderImage() if (d->sciReply) d->sciReply->deleteLater(); if (!d->sciurl.isEmpty()) - QFxPixmap::cancelGet(d->sciurl, this); + QFxPixmapCache::cancelGet(d->sciurl, this); } /*! \qmlproperty enum BorderImage::status @@ -166,9 +166,9 @@ void QFxBorderImage::setSource(const QUrl &url) } if (!d->url.isEmpty()) - QFxPixmap::cancelGet(d->url, this); + QFxPixmapCache::cancelGet(d->url, this); if (!d->sciurl.isEmpty()) - QFxPixmap::cancelGet(d->sciurl, this); + QFxPixmapCache::cancelGet(d->sciurl, this); d->url = url; d->sciurl = QUrl(); @@ -205,7 +205,7 @@ void QFxBorderImage::setSource(const QUrl &url) this, SLOT(sciRequestFinished())); } } else { - d->reply = QFxPixmap::get(qmlEngine(this), d->url, &d->pix); + d->reply = QFxPixmapCache::get(qmlEngine(this), d->url, &d->pix); if (d->reply) { connect(d->reply, SIGNAL(finished()), this, SLOT(requestFinished())); connect(d->reply, SIGNAL(downloadProgress(qint64,qint64)), @@ -315,7 +315,7 @@ void QFxBorderImage::setGridScaledImage(const QFxGridScaledImage& sci) d->verticalTileMode = sci.verticalTileRule(); d->sciurl = d->url.resolved(QUrl(sci.pixmapUrl())); - d->reply = QFxPixmap::get(qmlEngine(this), d->sciurl, &d->pix); + d->reply = QFxPixmapCache::get(qmlEngine(this), d->sciurl, &d->pix); if (d->reply) { connect(d->reply, SIGNAL(finished()), this, SLOT(requestFinished())); connect(d->reply, SIGNAL(downloadProgress(qint64,qint64)), @@ -340,7 +340,7 @@ void QFxBorderImage::requestFinished() { Q_D(QFxBorderImage); if (d->url.path().endsWith(QLatin1String(".sci"))) { - QFxPixmap::find(d->sciurl, &d->pix); + QFxPixmapCache::find(d->sciurl, &d->pix); } else { if (d->reply) { //###disconnect really needed? @@ -349,7 +349,7 @@ void QFxBorderImage::requestFinished() if (d->reply->error() != QNetworkReply::NoError) d->status = Error; } - QFxPixmap::find(d->url, &d->pix); + QFxPixmapCache::find(d->url, &d->pix); } setImplicitWidth(d->pix.width()); setImplicitHeight(d->pix.height()); diff --git a/src/declarative/fx/qfximagebase.cpp b/src/declarative/fx/qfximagebase.cpp index f96ff6f..66685c2 100644 --- a/src/declarative/fx/qfximagebase.cpp +++ b/src/declarative/fx/qfximagebase.cpp @@ -45,7 +45,7 @@ #include #include #include -#include +#include QT_BEGIN_NAMESPACE @@ -65,7 +65,7 @@ QFxImageBase::~QFxImageBase() { Q_D(QFxImageBase); if (!d->url.isEmpty()) - QFxPixmap::cancelGet(d->url, this); + QFxPixmapCache::cancelGet(d->url, this); } QFxImageBase::Status QFxImageBase::status() const @@ -103,7 +103,7 @@ void QFxImageBase::setSource(const QUrl &url) return; if (!d->url.isEmpty()) - QFxPixmap::cancelGet(d->url, this); + QFxPixmapCache::cancelGet(d->url, this); d->url = url; if (d->progress != 0.0) { @@ -123,7 +123,7 @@ void QFxImageBase::setSource(const QUrl &url) update(); } else { d->status = Loading; - d->reply = QFxPixmap::get(qmlEngine(this), d->url, &d->pix); + d->reply = QFxPixmapCache::get(qmlEngine(this), d->url, &d->pix); if (d->reply) { connect(d->reply, SIGNAL(finished()), this, SLOT(requestFinished())); connect(d->reply, SIGNAL(downloadProgress(qint64,qint64)), @@ -156,7 +156,7 @@ void QFxImageBase::requestFinished() if (d->reply->error() != QNetworkReply::NoError) d->status = Error; } - QFxPixmap::find(d->url, &d->pix); + QFxPixmapCache::find(d->url, &d->pix); setImplicitWidth(d->pix.width()); setImplicitHeight(d->pix.height()); diff --git a/src/declarative/fx/qfxpixmap.cpp b/src/declarative/fx/qfxpixmap.cpp deleted file mode 100644 index 43e94e5..0000000 --- a/src/declarative/fx/qfxpixmap.cpp +++ /dev/null @@ -1,233 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qfxpixmap.h" -#include -#include -#include -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE -class QSharedNetworkReply; -typedef QHash QFxSharedNetworkReplyHash; -static QFxSharedNetworkReplyHash qfxActiveNetworkReplies; - -class QSharedNetworkReply -{ -public: - QSharedNetworkReply(QNetworkReply *r) : reply(r), refCount(1) {} - ~QSharedNetworkReply() - { - reply->deleteLater(); - } - QNetworkReply *reply; - - int refCount; - void addRef() - { - ++refCount; - } - void release() - { - Q_ASSERT(refCount > 0); - --refCount; - if (refCount == 0) { - QString key = reply->url().toString(); - qfxActiveNetworkReplies.remove(key); - delete this; - } - } -}; - -static bool readImage(QIODevice *dev, QPixmap *pixmap) - { - QImageReader imgio(dev); - -//#define QT_TEST_SCALED_SIZE -#ifdef QT_TEST_SCALED_SIZE - /* - Some mechanism is needed for loading images at a limited size, especially - for remote images. Loading only thumbnails of remote progressive JPEG - images can be efficient. (Qt jpeg handler does not do so currently) - */ - - QSize limit(60,60); - QSize sz = imgio.size(); - if (sz.width() > limit.width() || sz.height() > limit.height()) { - sz.scale(limit,Qt::KeepAspectRatio); - imgio.setScaledSize(sz); - } -#endif - - QImage img; - if (imgio.read(&img)) { -#ifdef QT_TEST_SCALED_SIZE - if (!sz.isValid()) - img = img.scaled(limit,Qt::KeepAspectRatio); -#endif - *pixmap = QPixmap::fromImage(img); - return true; - } else { - return false; - } - } - -/*! - \internal - \class QFxPixmap - \ingroup group_utility - \brief Enacapsultes a pixmap for QFx items. - - This class is NOT reentrant. - The pixmap cache will grow indefinately. - */ - - -bool QFxPixmap::find(const QUrl& url, QPixmap *pixmap) -{ -#ifdef Q_ENABLE_PERFORMANCE_LOG - QFxPerfTimer perf; -#endif - - QString key = url.toString(); - if (!QPixmapCache::find(key,pixmap)) { -#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML - if (url.scheme()==QLatin1String("file")) { - QFile f(url.toLocalFile()); - if (f.open(QIODevice::ReadOnly)) { - if (!readImage(&f, pixmap)) { - qWarning() << "Format error loading" << url; - *pixmap = QPixmap(); - } - } else - *pixmap = QPixmap(); - } else -#endif - { - QFxSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key); - if (iter == qfxActiveNetworkReplies.end()) { - // API usage error - qWarning() << "QFxPixmap: URL not loaded" << url; - } else { - if ((*iter)->reply->error()) { - qWarning() << "Network error loading" << url << (*iter)->reply->errorString(); - *pixmap = QPixmap(); - } else - if (!readImage((*iter)->reply, pixmap)) { - qWarning() << "Format error loading" << url; - *pixmap = QPixmap(); - } - (*iter)->release(); - } - } - QPixmapCache::insert(key, *pixmap); - } - return true; -} - -/*! - Starts a network request to load \a url. When the URL is loaded, - the given slot is invoked. Note that if the image is already cached, - the slot may be invoked immediately. - - Returns a QNetworkReply if the image is not immediately available, otherwise - returns 0. The QNetworkReply must not be stored - it may be destroyed at any time. -*/ -QNetworkReply *QFxPixmap::get(QmlEngine *engine, const QUrl& url, QPixmap *pixmap) -{ -#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML - if (url.scheme()==QLatin1String("file")) { - QString key = url.toString(); - if (!QPixmapCache::find(key,pixmap)) { - QFile f(url.toLocalFile()); - if (f.open(QIODevice::ReadOnly)) { - if (!readImage(&f, pixmap)) { - qWarning() << "Format error loading" << url; - *pixmap = QPixmap(); - } - } else - *pixmap = QPixmap(); - QPixmapCache::insert(key, *pixmap); - } - return 0; - } -#endif - - QString key = url.toString(); - if (QPixmapCache::find(key,pixmap)) { - return 0; - } - - QFxSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key); - if (iter == qfxActiveNetworkReplies.end()) { - QNetworkRequest req(url); - req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); - QSharedNetworkReply *item = new QSharedNetworkReply(engine->networkAccessManager()->get(req)); - iter = qfxActiveNetworkReplies.insert(key, item); - } else { - (*iter)->addRef(); - } - - return (*iter)->reply; -} - -/*! - Stops the given slot being invoked if the given url finishes loading. - May also cancel loading (eg. if no other pending request). - - Any connections to the QNetworkReply returned by get() will be - disconnected. -*/ -void QFxPixmap::cancelGet(const QUrl& url, QObject* obj) -{ - QString key = url.toString(); - QFxSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key); - if (iter == qfxActiveNetworkReplies.end()) - return; - QObject::disconnect((*iter)->reply, 0, obj, 0); - (*iter)->release(); -} - -QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxpixmap.h b/src/declarative/fx/qfxpixmap.h deleted file mode 100644 index ec8d2be..0000000 --- a/src/declarative/fx/qfxpixmap.h +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QFXPIXMAP_H -#define QFXPIXMAP_H - -#include -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) -class QmlEngine; -class QNetworkReply; -class Q_DECLARATIVE_EXPORT QFxPixmap //### rename QFxPixmapCache -{ -public: - static QNetworkReply *get(QmlEngine *, const QUrl& url, QPixmap *pixmap); - static void cancelGet(const QUrl& url, QObject* obj); - - static bool find(const QUrl& url, QPixmap *pixmap); // url must have been passed to QFxPixmap::get, and finished. Or must be a local file. -}; - - -QT_END_NAMESPACE - -QT_END_HEADER -#endif // QFXPIXMAP_H diff --git a/src/declarative/fx/qfxpixmapcache.cpp b/src/declarative/fx/qfxpixmapcache.cpp new file mode 100644 index 0000000..5220d15 --- /dev/null +++ b/src/declarative/fx/qfxpixmapcache.cpp @@ -0,0 +1,231 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qfxpixmapcache.h" +#include +#include +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE +class QSharedNetworkReply; +typedef QHash QFxSharedNetworkReplyHash; +static QFxSharedNetworkReplyHash qfxActiveNetworkReplies; + +class QSharedNetworkReply +{ +public: + QSharedNetworkReply(QNetworkReply *r) : reply(r), refCount(1) {} + ~QSharedNetworkReply() + { + reply->deleteLater(); + } + QNetworkReply *reply; + + int refCount; + void addRef() + { + ++refCount; + } + void release() + { + Q_ASSERT(refCount > 0); + --refCount; + if (refCount == 0) { + QString key = reply->url().toString(); + qfxActiveNetworkReplies.remove(key); + delete this; + } + } +}; + +static bool readImage(QIODevice *dev, QPixmap *pixmap) + { + QImageReader imgio(dev); + +//#define QT_TEST_SCALED_SIZE +#ifdef QT_TEST_SCALED_SIZE + /* + Some mechanism is needed for loading images at a limited size, especially + for remote images. Loading only thumbnails of remote progressive JPEG + images can be efficient. (Qt jpeg handler does not do so currently) + */ + + QSize limit(60,60); + QSize sz = imgio.size(); + if (sz.width() > limit.width() || sz.height() > limit.height()) { + sz.scale(limit,Qt::KeepAspectRatio); + imgio.setScaledSize(sz); + } +#endif + + QImage img; + if (imgio.read(&img)) { +#ifdef QT_TEST_SCALED_SIZE + if (!sz.isValid()) + img = img.scaled(limit,Qt::KeepAspectRatio); +#endif + *pixmap = QPixmap::fromImage(img); + return true; + } else { + return false; + } + } + +/*! + \internal + \class QFxPixmapCache + \brief Enacapsultes a pixmap for QFx items. + + This class is NOT reentrant. + */ + + +bool QFxPixmapCache::find(const QUrl& url, QPixmap *pixmap) +{ +#ifdef Q_ENABLE_PERFORMANCE_LOG + QFxPerfTimer perf; +#endif + + QString key = url.toString(); + if (!QPixmapCache::find(key,pixmap)) { +#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML + if (url.scheme()==QLatin1String("file")) { + QFile f(url.toLocalFile()); + if (f.open(QIODevice::ReadOnly)) { + if (!readImage(&f, pixmap)) { + qWarning() << "Format error loading" << url; + *pixmap = QPixmap(); + } + } else + *pixmap = QPixmap(); + } else +#endif + { + QFxSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key); + if (iter == qfxActiveNetworkReplies.end()) { + // API usage error + qWarning() << "QFxPixmapCache: URL not loaded" << url; + } else { + if ((*iter)->reply->error()) { + qWarning() << "Network error loading" << url << (*iter)->reply->errorString(); + *pixmap = QPixmap(); + } else + if (!readImage((*iter)->reply, pixmap)) { + qWarning() << "Format error loading" << url; + *pixmap = QPixmap(); + } + (*iter)->release(); + } + } + QPixmapCache::insert(key, *pixmap); + } + return true; +} + +/*! + Starts a network request to load \a url. When the URL is loaded, + the given slot is invoked. Note that if the image is already cached, + the slot may be invoked immediately. + + Returns a QNetworkReply if the image is not immediately available, otherwise + returns 0. The QNetworkReply must not be stored - it may be destroyed at any time. +*/ +QNetworkReply *QFxPixmapCache::get(QmlEngine *engine, const QUrl& url, QPixmap *pixmap) +{ +#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML + if (url.scheme()==QLatin1String("file")) { + QString key = url.toString(); + if (!QPixmapCache::find(key,pixmap)) { + QFile f(url.toLocalFile()); + if (f.open(QIODevice::ReadOnly)) { + if (!readImage(&f, pixmap)) { + qWarning() << "Format error loading" << url; + *pixmap = QPixmap(); + } + } else + *pixmap = QPixmap(); + QPixmapCache::insert(key, *pixmap); + } + return 0; + } +#endif + + QString key = url.toString(); + if (QPixmapCache::find(key,pixmap)) { + return 0; + } + + QFxSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key); + if (iter == qfxActiveNetworkReplies.end()) { + QNetworkRequest req(url); + req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); + QSharedNetworkReply *item = new QSharedNetworkReply(engine->networkAccessManager()->get(req)); + iter = qfxActiveNetworkReplies.insert(key, item); + } else { + (*iter)->addRef(); + } + + return (*iter)->reply; +} + +/*! + Stops the given slot being invoked if the given url finishes loading. + May also cancel loading (eg. if no other pending request). + + Any connections to the QNetworkReply returned by get() will be + disconnected. +*/ +void QFxPixmapCache::cancelGet(const QUrl& url, QObject* obj) +{ + QString key = url.toString(); + QFxSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key); + if (iter == qfxActiveNetworkReplies.end()) + return; + QObject::disconnect((*iter)->reply, 0, obj, 0); + (*iter)->release(); +} + +QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxpixmapcache.h b/src/declarative/fx/qfxpixmapcache.h new file mode 100644 index 0000000..ca5d47b --- /dev/null +++ b/src/declarative/fx/qfxpixmapcache.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QFXPIXMAPCACHE_H +#define QFXPIXMAPCACHE_H + +#include +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) +class QmlEngine; +class QNetworkReply; +class Q_DECLARATIVE_EXPORT QFxPixmapCache +{ +public: + static QNetworkReply *get(QmlEngine *, const QUrl& url, QPixmap *pixmap); + static void cancelGet(const QUrl& url, QObject* obj); + + static bool find(const QUrl& url, QPixmap *pixmap); // url must have been passed to QFxPixmapCache::get, and finished. Or must be a local file. +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QFXPIXMAPCACHE_H diff --git a/src/declarative/fx/qfxscalegrid_p.h b/src/declarative/fx/qfxscalegrid_p.h index 7df90f1..bae1436 100644 --- a/src/declarative/fx/qfxscalegrid_p.h +++ b/src/declarative/fx/qfxscalegrid_p.h @@ -45,7 +45,7 @@ #include #include #include -#include +#include #include #include "qfxborderimage.h" -- cgit v0.12