summaryrefslogtreecommitdiffstats
path: root/src/declarative
diff options
context:
space:
mode:
authorYann Bodson <yann.bodson@nokia.com>2009-08-07 06:54:32 (GMT)
committerYann Bodson <yann.bodson@nokia.com>2009-08-07 07:01:57 (GMT)
commit7105e534a980554277fbe1da2698fca6a5bc49aa (patch)
tree1dcc1c8dc1aec1f25d2f43fac327fdacb4091149 /src/declarative
parentd93e8b21fafb546c9f8fefbb170bbb2d66fe6e93 (diff)
downloadQt-7105e534a980554277fbe1da2698fca6a5bc49aa.zip
Qt-7105e534a980554277fbe1da2698fca6a5bc49aa.tar.gz
Qt-7105e534a980554277fbe1da2698fca6a5bc49aa.tar.bz2
Start moving code from QFxImage to QFxImageBase
Diffstat (limited to 'src/declarative')
-rw-r--r--src/declarative/fx/qfximage.cpp331
-rw-r--r--src/declarative/fx/qfximage.h26
-rw-r--r--src/declarative/fx/qfximage_p.h35
-rw-r--r--src/declarative/fx/qfximagebase.cpp246
-rw-r--r--src/declarative/fx/qfximagebase.h35
-rw-r--r--src/declarative/fx/qfximagebase_p.h33
6 files changed, 358 insertions, 348 deletions
diff --git a/src/declarative/fx/qfximage.cpp b/src/declarative/fx/qfximage.cpp
index b1c6bda..5c9e1f9 100644
--- a/src/declarative/fx/qfximage.cpp
+++ b/src/declarative/fx/qfximage.cpp
@@ -41,11 +41,6 @@
#include "qfximage.h"
#include "qfximage_p.h"
-//#include <private/qfxperf_p.h>
-#include <QNetworkRequest>
-#include <QNetworkReply>
-#include <QFile>
-#include <QtDeclarative/qmlengine.h>
#include <QKeyEvent>
#include <QPainter>
@@ -157,13 +152,6 @@ QFxImage::QFxImage(QFxImagePrivate &dd, QFxItem *parent)
QFxImage::~QFxImage()
{
- Q_D(QFxImage);
- if (d->sciReply)
- d->sciReply->deleteLater();
- if (!d->url.isEmpty())
- QFxPixmap::cancelGet(d->url, this);
- if (!d->sciurl.isEmpty())
- QFxPixmap::cancelGet(d->sciurl, this);
}
/*!
@@ -194,37 +182,6 @@ void QFxImage::setPixmap(const QPixmap &pix)
}
/*!
- \qmlproperty int Image::scaleGrid.left
- \qmlproperty int Image::scaleGrid.right
- \qmlproperty int Image::scaleGrid.top
- \qmlproperty int Image::scaleGrid.bottom
-
- \target ImagexmlpropertiesscaleGrid
-
- A scale grid uses 4 grid lines (2 horizontal and 2 vertical) to break an image into 9 sections, as shown below:
-
- \image declarative-scalegrid.png
-
- When the image is scaled:
- \list
- \i the corners (sections 1, 3, 7, and 9) are not scaled at all
- \i the middle (section 5) is scaled both horizontally and vertically
- \i sections 2 and 8 are scaled horizontally
- \i sections 4 and 6 are scaled vertically
- \endlist
-
- Each scale grid property (left, right, top, and bottom) specifies an offset from the respective side. For example, \c scaleGrid.bottom="10" sets the bottom scale grid line 10 pixels up from the bottom of the image.
-
- A scale grid can also be specified using a
- \l {Image::source}{.sci file}.
-*/
-QFxScaleGrid *QFxImage::scaleGrid()
-{
- Q_D(QFxImage);
- return d->getScaleGrid();
-}
-
-/*!
\qmlproperty FillMode Image::fillMode
Set this property to define what happens when the image set for the item is smaller
@@ -261,14 +218,50 @@ void QFxImage::setFillMode(FillMode mode)
emit fillModeChanged();
}
-void QFxImage::componentComplete()
-{
- QFxItem::componentComplete();
-}
+/*!
+ \qmlproperty enum Image::status
+
+ This property holds the status of image loading. It can be one of:
+ \list
+ \o Null - no image has been set
+ \o Ready - the image has been loaded
+ \o Loading - the image is currently being loaded
+ \o Error - an error occurred while loading the image
+ \endlist
+
+ \sa progress
+*/
/*!
- \property QFxImage::scaleGrid
- \brief the 3x3 grid used to scale an image, excluding the corners.
+ \qmlproperty real Image::progress
+
+ This property holds the progress of image loading, from 0.0 (nothing loaded)
+ to 1.0 (finished).
+
+ \sa status
+*/
+
+/*!
+ \qmlproperty url Image::source
+
+ Image can handle any image format supported by Qt, loaded from any URL scheme supported by Qt.
+
+ It can also handle .sci files, which are a Qml-specific format. A .sci file uses a simple text-based format that specifies
+ \list
+ \i the grid lines describing a \l {Image::scaleGrid.left}{scale grid}.
+ \i an image file.
+ \endlist
+
+ The following .sci file sets grid line offsets of 10 on each side for the image \c picture.png:
+ \code
+ gridLeft: 10
+ gridTop: 10
+ gridBottom: 10
+ gridRight: 10
+ imageFile: picture.png
+ \endcode
+
+ The URL may be absolute, or relative to the URL of the component.
*/
void QFxImage::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *)
@@ -360,244 +353,4 @@ void QFxImage::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *)
}
}
-/*!
- \qmlproperty enum Image::status
-
- This property holds the status of image loading. It can be one of:
- \list
- \o Null - no image has been set
- \o Ready - the image has been loaded
- \o Loading - the image is currently being loaded
- \o Error - an error occurred while loading the image
- \endlist
-
- \sa progress
-*/
-
-QFxImage::Status QFxImage::status() const
-{
- Q_D(const QFxImage);
- return d->status;
-}
-
-/*!
- \qmlproperty real Image::progress
-
- This property holds the progress of image loading, from 0.0 (nothing loaded)
- to 1.0 (finished).
-
- \sa status
-*/
-
-qreal QFxImage::progress() const
-{
- Q_D(const QFxImage);
- return d->progress;
-}
-
-/*!
- \qmlproperty url Image::source
-
- Image can handle any image format supported by Qt, loaded from any URL scheme supported by Qt.
-
- It can also handle .sci files, which are a Qml-specific format. A .sci file uses a simple text-based format that specifies
- \list
- \i the grid lines describing a \l {Image::scaleGrid.left}{scale grid}.
- \i an image file.
- \endlist
-
- The following .sci file sets grid line offsets of 10 on each side for the image \c picture.png:
- \code
- gridLeft: 10
- gridTop: 10
- gridBottom: 10
- gridRight: 10
- imageFile: picture.png
- \endcode
-
- The URL may be absolute, or relative to the URL of the component.
-*/
-
-/*!
- \property QFxImage::source
- \brief the url of the image to be displayed in this item.
-
- The content specified can be of any image type loadable by QImage. Alternatively,
- you can specify an sci format file, which specifies both an image and it's scale grid.
-*/
-QUrl QFxImage::source() const
-{
- Q_D(const QFxImage);
- return d->url;
-}
-
-void QFxImage::setSource(const QUrl &url)
-{
-#ifdef Q_ENABLE_PERFORMANCE_LOG
- QFxPerfTimer<QFxPerf::PixmapLoad> perf;
-#endif
- Q_D(QFxImage);
- //equality is fairly expensive, so we bypass for simple, common case
- if ((d->url.isEmpty() == url.isEmpty()) && url == d->url)
- return;
-
- if (d->sciReply) {
- d->sciReply->deleteLater();
- d->sciReply = 0;
- }
-
- if (!d->url.isEmpty())
- QFxPixmap::cancelGet(d->url, this);
- if (!d->sciurl.isEmpty())
- QFxPixmap::cancelGet(d->sciurl, this);
-
- d->url = url;
- d->sciurl = QUrl();
- if (d->progress != 0.0) {
- d->progress = 0.0;
- emit progressChanged(d->progress);
- }
-
- if (url.isEmpty()) {
- d->pix = QPixmap();
- d->status = Null;
- d->progress = 1.0;
- setImplicitWidth(0);
- setImplicitHeight(0);
- emit statusChanged(d->status);
- emit sourceChanged(d->url);
- emit progressChanged(1.0);
- update();
- } else {
- d->status = Loading;
- if (d->url.path().endsWith(QLatin1String(".sci"))) {
-#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML
- if (d->url.scheme() == QLatin1String("file")) {
- QFile file(d->url.toLocalFile());
- file.open(QIODevice::ReadOnly);
- setGridScaledImage(QFxGridScaledImage(&file));
- } else
-#endif
- {
- QNetworkRequest req(d->url);
- req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);
- d->sciReply = qmlEngine(this)->networkAccessManager()->get(req);
- QObject::connect(d->sciReply, SIGNAL(finished()),
- this, SLOT(sciRequestFinished()));
- }
- } else {
- d->reply = QFxPixmap::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)),
- this, SLOT(requestProgress(qint64,qint64)));
- } else {
- //### should be unified with requestFinished
- setImplicitWidth(d->pix.width());
- setImplicitHeight(d->pix.height());
-
- if (d->status == Loading)
- d->status = Ready;
- d->progress = 1.0;
- emit statusChanged(d->status);
- emit sourceChanged(d->url);
- emit progressChanged(1.0);
- update();
- }
- }
- }
-
- emit statusChanged(d->status);
-}
-
-void QFxImage::requestFinished()
-{
- Q_D(QFxImage);
- if (d->url.path().endsWith(QLatin1String(".sci"))) {
- QFxPixmap::find(d->sciurl, &d->pix);
- } else {
- if (d->reply) {
- //###disconnect really needed?
- disconnect(d->reply, SIGNAL(downloadProgress(qint64,qint64)),
- this, SLOT(requestProgress(qint64,qint64)));
- if (d->reply->error() != QNetworkReply::NoError)
- d->status = Error;
- }
- QFxPixmap::find(d->url, &d->pix);
- }
- setImplicitWidth(d->pix.width());
- setImplicitHeight(d->pix.height());
-
- if (d->status == Loading)
- d->status = Ready;
- d->progress = 1.0;
- emit statusChanged(d->status);
- emit sourceChanged(d->url);
- emit progressChanged(1.0);
- update();
-}
-
-void QFxImage::sciRequestFinished()
-{
- Q_D(QFxImage);
- if (d->sciReply->error() != QNetworkReply::NoError) {
- d->status = Error;
- d->sciReply->deleteLater();
- d->sciReply = 0;
- emit statusChanged(d->status);
- } else {
- QFxGridScaledImage sci(d->sciReply);
- d->sciReply->deleteLater();
- d->sciReply = 0;
- setGridScaledImage(sci);
- }
-}
-
-void QFxImage::requestProgress(qint64 received, qint64 total)
-{
- Q_D(QFxImage);
- if (d->status == Loading && total > 0) {
- d->progress = qreal(received)/total;
- emit progressChanged(d->progress);
- }
-}
-
-void QFxImage::setGridScaledImage(const QFxGridScaledImage& sci)
-{
- Q_D(QFxImage);
- if (!sci.isValid()) {
- d->status = Error;
- emit statusChanged(d->status);
- } else {
- QFxScaleGrid *sg = scaleGrid();
- sg->setTop(sci.gridTop());
- sg->setBottom(sci.gridBottom());
- sg->setLeft(sci.gridLeft());
- sg->setRight(sci.gridRight());
- sg->setHorizontalTileRule(sci.horizontalTileRule());
- sg->setVerticalTileRule(sci.verticalTileRule());
-
- d->sciurl = d->url.resolved(QUrl(sci.pixmapUrl()));
- d->reply = QFxPixmap::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)),
- this, SLOT(requestProgress(qint64,qint64)));
- } else {
- //### should be unified with requestFinished
- setImplicitWidth(d->pix.width());
- setImplicitHeight(d->pix.height());
-
- if (d->status == Loading)
- d->status = Ready;
- d->progress = 1.0;
- emit statusChanged(d->status);
- emit sourceChanged(d->url);
- emit progressChanged(1.0);
- update();
- }
- }
-}
-
-
QT_END_NAMESPACE
diff --git a/src/declarative/fx/qfximage.h b/src/declarative/fx/qfximage.h
index 642e4c8..b31da29 100644
--- a/src/declarative/fx/qfximage.h
+++ b/src/declarative/fx/qfximage.h
@@ -51,20 +51,12 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
class QFxImagePrivate;
-class QFxScaleGrid;
-class QFxGridScaledImage;
class Q_DECLARATIVE_EXPORT QFxImage : public QFxImageBase
{
Q_OBJECT
- Q_ENUMS(Status)
Q_ENUMS(FillMode)
- Q_PROPERTY(Status status READ status NOTIFY statusChanged)
- Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
- Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged)
-
- Q_PROPERTY(QFxScaleGrid *scaleGrid READ scaleGrid)
Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap DESIGNABLE false)
Q_PROPERTY(FillMode fillMode READ fillMode WRITE setFillMode NOTIFY fillModeChanged);
@@ -79,35 +71,17 @@ public:
QPixmap pixmap() const;
void setPixmap(const QPixmap &);
- enum Status { Null, Ready, Loading, Error };
- Status status() const;
- qreal progress() const;
-
- QUrl source() const;
- virtual void setSource(const QUrl &url);
-
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
Q_SIGNALS:
- void sourceChanged(const QUrl &);
- void statusChanged(Status);
- void progressChanged(qreal progress);
void fillModeChanged();
protected:
QFxImage(QFxImagePrivate &dd, QFxItem *parent);
- virtual void componentComplete();
-
-private Q_SLOTS:
- void requestFinished();
- void sciRequestFinished();
- void requestProgress(qint64,qint64);
private:
Q_DISABLE_COPY(QFxImage)
Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxImage)
- void setGridScaledImage(const QFxGridScaledImage& sci);
- QFxScaleGrid *scaleGrid();
};
QT_END_NAMESPACE
diff --git a/src/declarative/fx/qfximage_p.h b/src/declarative/fx/qfximage_p.h
index d198c27..825da5b 100644
--- a/src/declarative/fx/qfximage_p.h
+++ b/src/declarative/fx/qfximage_p.h
@@ -54,55 +54,24 @@
//
#include "qfxitem_p.h"
-#include "qfxscalegrid_p.h"
#include "qfximagebase_p.h"
#include <QtCore/qpointer.h>
QT_BEGIN_NAMESPACE
-class QSvgRenderer;
-class QWebPage;
-class QNetworkReply;
-class QIODevice;
-
class QFxImagePrivate : public QFxImageBasePrivate
{
Q_DECLARE_PUBLIC(QFxImage)
public:
QFxImagePrivate()
- : scaleGrid(0),
- fillMode(QFxImage::Stretch),
- status(QFxImage::Null), sciReply(0),
- progress(0.0)
- {
- }
-
- ~QFxImagePrivate()
- {
- delete scaleGrid;
- }
-
- void setContent(QIODevice* dev, const QString &url);
-
- QFxScaleGrid *getScaleGrid()
+ : fillMode(QFxImage::Stretch)
{
- if (!scaleGrid)
- scaleGrid = new QFxScaleGrid;
- return scaleGrid;
}
- QFxScaleGrid *scaleGrid;
- QPixmap pix;
-
QFxImage::FillMode fillMode;
- QFxImage::Status status;
- QUrl url;
- QUrl sciurl;
- QNetworkReply *sciReply;
- QPointer<QNetworkReply> reply;
- qreal progress;
+
};
QT_END_NAMESPACE
diff --git a/src/declarative/fx/qfximagebase.cpp b/src/declarative/fx/qfximagebase.cpp
index e0b72c2..39c43d3 100644
--- a/src/declarative/fx/qfximagebase.cpp
+++ b/src/declarative/fx/qfximagebase.cpp
@@ -41,17 +41,263 @@
#include "qfximagebase.h"
#include "qfximagebase_p.h"
+#include <QNetworkRequest>
+#include <QNetworkReply>
+#include <QFile>
+#include <QtDeclarative/qmlengine.h>
QT_BEGIN_NAMESPACE
QFxImageBase::QFxImageBase(QFxItem *parent)
: QFxItem(*(new QFxImageBasePrivate), parent)
{
+ setFlag(QGraphicsItem::ItemHasNoContents, true);
}
QFxImageBase::QFxImageBase(QFxImageBasePrivate &dd, QFxItem *parent)
: QFxItem(dd, parent)
{
+ setFlag(QGraphicsItem::ItemHasNoContents, true);
+}
+
+QFxImageBase::~QFxImageBase()
+{
+ Q_D(QFxImageBase);
+ if (d->sciReply)
+ d->sciReply->deleteLater();
+ if (!d->url.isEmpty())
+ QFxPixmap::cancelGet(d->url, this);
+ if (!d->sciurl.isEmpty())
+ QFxPixmap::cancelGet(d->sciurl, this);
+}
+
+/*!
+ \qmlproperty int Image::scaleGrid.left
+ \qmlproperty int Image::scaleGrid.right
+ \qmlproperty int Image::scaleGrid.top
+ \qmlproperty int Image::scaleGrid.bottom
+
+ \target ImagexmlpropertiesscaleGrid
+
+ A scale grid uses 4 grid lines (2 horizontal and 2 vertical) to break an image into 9 sections, as shown below:
+
+ \image declarative-scalegrid.png
+
+ When the image is scaled:
+ \list
+ \i the corners (sections 1, 3, 7, and 9) are not scaled at all
+ \i the middle (section 5) is scaled both horizontally and vertically
+ \i sections 2 and 8 are scaled horizontally
+ \i sections 4 and 6 are scaled vertically
+ \endlist
+
+ Each scale grid property (left, right, top, and bottom) specifies an offset from the respective side. For example, \c scaleGrid.bottom="10" sets the bottom scale grid line 10 pixels up from the bottom of the image.
+
+ A scale grid can also be specified using a
+ \l {Image::source}{.sci file}.
+*/
+QFxScaleGrid *QFxImageBase::scaleGrid()
+{
+ Q_D(QFxImageBase);
+ return d->getScaleGrid();
+}
+
+void QFxImageBase::componentComplete()
+{
+ QFxItem::componentComplete();
+}
+
+
+QFxImageBase::Status QFxImageBase::status() const
+{
+ Q_D(const QFxImageBase);
+ return d->status;
+}
+
+
+qreal QFxImageBase::progress() const
+{
+ Q_D(const QFxImageBase);
+ return d->progress;
+}
+
+
+/*!
+ \property QFxImage::source
+ \brief the url of the image to be displayed in this item.
+
+ The content specified can be of any image type loadable by QImage. Alternatively,
+ you can specify an sci format file, which specifies both an image and it's scale grid.
+*/
+QUrl QFxImageBase::source() const
+{
+ Q_D(const QFxImageBase);
+ return d->url;
+}
+
+void QFxImageBase::setSource(const QUrl &url)
+{
+ Q_D(QFxImageBase);
+ //equality is fairly expensive, so we bypass for simple, common case
+ if ((d->url.isEmpty() == url.isEmpty()) && url == d->url)
+ return;
+
+ if (d->sciReply) {
+ d->sciReply->deleteLater();
+ d->sciReply = 0;
+ }
+
+ if (!d->url.isEmpty())
+ QFxPixmap::cancelGet(d->url, this);
+ if (!d->sciurl.isEmpty())
+ QFxPixmap::cancelGet(d->sciurl, this);
+
+ d->url = url;
+ d->sciurl = QUrl();
+ if (d->progress != 0.0) {
+ d->progress = 0.0;
+ emit progressChanged(d->progress);
+ }
+
+ if (url.isEmpty()) {
+ d->pix = QPixmap();
+ d->status = Null;
+ d->progress = 1.0;
+ setImplicitWidth(0);
+ setImplicitHeight(0);
+ emit statusChanged(d->status);
+ emit sourceChanged(d->url);
+ emit progressChanged(1.0);
+ update();
+ } else {
+ d->status = Loading;
+ if (d->url.path().endsWith(QLatin1String(".sci"))) {
+#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML
+ if (d->url.scheme() == QLatin1String("file")) {
+ QFile file(d->url.toLocalFile());
+ file.open(QIODevice::ReadOnly);
+ setGridScaledImage(QFxGridScaledImage(&file));
+ } else
+#endif
+ {
+ QNetworkRequest req(d->url);
+ req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);
+ d->sciReply = qmlEngine(this)->networkAccessManager()->get(req);
+ QObject::connect(d->sciReply, SIGNAL(finished()),
+ this, SLOT(sciRequestFinished()));
+ }
+ } else {
+ d->reply = QFxPixmap::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)),
+ this, SLOT(requestProgress(qint64,qint64)));
+ } else {
+ //### should be unified with requestFinished
+ setImplicitWidth(d->pix.width());
+ setImplicitHeight(d->pix.height());
+
+ if (d->status == Loading)
+ d->status = Ready;
+ d->progress = 1.0;
+ emit statusChanged(d->status);
+ emit sourceChanged(d->url);
+ emit progressChanged(1.0);
+ update();
+ }
+ }
+ }
+
+ emit statusChanged(d->status);
+}
+
+void QFxImageBase::requestFinished()
+{
+ Q_D(QFxImageBase);
+ if (d->url.path().endsWith(QLatin1String(".sci"))) {
+ QFxPixmap::find(d->sciurl, &d->pix);
+ } else {
+ if (d->reply) {
+ //###disconnect really needed?
+ disconnect(d->reply, SIGNAL(downloadProgress(qint64,qint64)),
+ this, SLOT(requestProgress(qint64,qint64)));
+ if (d->reply->error() != QNetworkReply::NoError)
+ d->status = Error;
+ }
+ QFxPixmap::find(d->url, &d->pix);
+ }
+ setImplicitWidth(d->pix.width());
+ setImplicitHeight(d->pix.height());
+
+ if (d->status == Loading)
+ d->status = Ready;
+ d->progress = 1.0;
+ emit statusChanged(d->status);
+ emit sourceChanged(d->url);
+ emit progressChanged(1.0);
+ update();
+}
+
+void QFxImageBase::sciRequestFinished()
+{
+ Q_D(QFxImageBase);
+ if (d->sciReply->error() != QNetworkReply::NoError) {
+ d->status = Error;
+ d->sciReply->deleteLater();
+ d->sciReply = 0;
+ emit statusChanged(d->status);
+ } else {
+ QFxGridScaledImage sci(d->sciReply);
+ d->sciReply->deleteLater();
+ d->sciReply = 0;
+ setGridScaledImage(sci);
+ }
+}
+
+void QFxImageBase::requestProgress(qint64 received, qint64 total)
+{
+ Q_D(QFxImageBase);
+ if (d->status == Loading && total > 0) {
+ d->progress = qreal(received)/total;
+ emit progressChanged(d->progress);
+ }
+}
+
+void QFxImageBase::setGridScaledImage(const QFxGridScaledImage& sci)
+{
+ Q_D(QFxImageBase);
+ if (!sci.isValid()) {
+ d->status = Error;
+ emit statusChanged(d->status);
+ } else {
+ QFxScaleGrid *sg = scaleGrid();
+ sg->setTop(sci.gridTop());
+ sg->setBottom(sci.gridBottom());
+ sg->setLeft(sci.gridLeft());
+ sg->setRight(sci.gridRight());
+ sg->setHorizontalTileRule(sci.horizontalTileRule());
+ sg->setVerticalTileRule(sci.verticalTileRule());
+
+ d->sciurl = d->url.resolved(QUrl(sci.pixmapUrl()));
+ d->reply = QFxPixmap::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)),
+ this, SLOT(requestProgress(qint64,qint64)));
+ } else {
+ //### should be unified with requestFinished
+ setImplicitWidth(d->pix.width());
+ setImplicitHeight(d->pix.height());
+
+ if (d->status == Loading)
+ d->status = Ready;
+ d->progress = 1.0;
+ emit statusChanged(d->status);
+ emit sourceChanged(d->url);
+ emit progressChanged(1.0);
+ update();
+ }
+ }
}
QT_END_NAMESPACE
diff --git a/src/declarative/fx/qfximagebase.h b/src/declarative/fx/qfximagebase.h
index 7e04f0d..78e391e 100644
--- a/src/declarative/fx/qfximagebase.h
+++ b/src/declarative/fx/qfximagebase.h
@@ -46,15 +46,50 @@
QT_BEGIN_NAMESPACE
+class QFxScaleGrid;
+class QFxGridScaledImage;
class QFxImageBasePrivate;
class QFxImageBase : public QFxItem
{
+ Q_OBJECT
+ Q_ENUMS(Status)
+
+ Q_PROPERTY(Status status READ status NOTIFY statusChanged)
+ Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
+ Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged)
+ Q_PROPERTY(QFxScaleGrid *scaleGrid READ scaleGrid)
+
public:
QFxImageBase(QFxItem *parent = 0);
+ ~QFxImageBase();
+ enum Status { Null, Ready, Loading, Error };
+ Status status() const;
+ qreal progress() const;
+
+ QUrl source() const;
+ virtual void setSource(const QUrl &url);
+
+Q_SIGNALS:
+ void sourceChanged(const QUrl &);
+ void statusChanged(Status);
+ void progressChanged(qreal progress);
protected:
QFxImageBase(QFxImageBasePrivate &dd, QFxItem *parent);
+ virtual void componentComplete();
+
+private Q_SLOTS:
+ void requestFinished();
+ void sciRequestFinished();
+ void requestProgress(qint64,qint64);
+
+private:
+ void setGridScaledImage(const QFxGridScaledImage& sci);
+ QFxScaleGrid *scaleGrid();
+private:
+ Q_DISABLE_COPY(QFxImageBase)
+ Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxImageBase)
};
QT_END_NAMESPACE
diff --git a/src/declarative/fx/qfximagebase_p.h b/src/declarative/fx/qfximagebase_p.h
index 7e5d722..e84fffe 100644
--- a/src/declarative/fx/qfximagebase_p.h
+++ b/src/declarative/fx/qfximagebase_p.h
@@ -54,17 +54,50 @@
//
#include "qfxitem_p.h"
+#include "qfxscalegrid_p.h"
QT_BEGIN_NAMESPACE
+class QSvgRenderer;
+class QWebPage;
+class QNetworkReply;
+class QIODevice;
+
class QFxImageBasePrivate : public QFxItemPrivate
{
Q_DECLARE_PUBLIC(QFxImageBase)
public:
QFxImageBasePrivate()
+ : scaleGrid(0),
+ status(QFxImageBase::Null), sciReply(0),
+ progress(0.0)
+ {
+ }
+
+ ~QFxImageBasePrivate()
+ {
+ delete scaleGrid;
+ }
+
+ void setContent(QIODevice* dev, const QString &url);
+
+ QFxScaleGrid *getScaleGrid()
{
+ if (!scaleGrid)
+ scaleGrid = new QFxScaleGrid;
+ return scaleGrid;
}
+
+ QFxScaleGrid *scaleGrid;
+ QPixmap pix;
+
+ QFxImageBase::Status status;
+ QUrl url;
+ QUrl sciurl;
+ QNetworkReply *sciReply;
+ QPointer<QNetworkReply> reply;
+ qreal progress;
};
QT_END_NAMESPACE