diff options
author | Yann Bodson <yann.bodson@nokia.com> | 2009-08-09 22:35:18 (GMT) |
---|---|---|
committer | Yann Bodson <yann.bodson@nokia.com> | 2009-08-09 22:35:18 (GMT) |
commit | 1a05457011ca570b1f082f2e4312ad4897fbeb2d (patch) | |
tree | 2aa9de11974cf98a684e027e6991ec3411ff4d80 /src/declarative/fx/qfximagebase.cpp | |
parent | 7105e534a980554277fbe1da2698fca6a5bc49aa (diff) | |
download | Qt-1a05457011ca570b1f082f2e4312ad4897fbeb2d.zip Qt-1a05457011ca570b1f082f2e4312ad4897fbeb2d.tar.gz Qt-1a05457011ca570b1f082f2e4312ad4897fbeb2d.tar.bz2 |
Add new class QFxBorderImage.
* Move scalegrid code into QFxBorderImage
* Update examples
Diffstat (limited to 'src/declarative/fx/qfximagebase.cpp')
-rw-r--r-- | src/declarative/fx/qfximagebase.cpp | 123 |
1 files changed, 1 insertions, 122 deletions
diff --git a/src/declarative/fx/qfximagebase.cpp b/src/declarative/fx/qfximagebase.cpp index 39c43d3..f96ff6f 100644 --- a/src/declarative/fx/qfximagebase.cpp +++ b/src/declarative/fx/qfximagebase.cpp @@ -45,6 +45,7 @@ #include <QNetworkReply> #include <QFile> #include <QtDeclarative/qmlengine.h> +#include <QtDeclarative/qfxpixmap.h> QT_BEGIN_NAMESPACE @@ -63,51 +64,10 @@ QFxImageBase::QFxImageBase(QFxImageBasePrivate &dd, QFxItem *parent) 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); @@ -142,18 +102,10 @@ void QFxImageBase::setSource(const QUrl &url) 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); @@ -171,22 +123,6 @@ void QFxImageBase::setSource(const QUrl &url) 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())); @@ -206,7 +142,6 @@ void QFxImageBase::setSource(const QUrl &url) update(); } } - } emit statusChanged(d->status); } @@ -214,9 +149,6 @@ void QFxImageBase::setSource(const QUrl &url) 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)), @@ -225,7 +157,6 @@ void QFxImageBase::requestFinished() d->status = Error; } QFxPixmap::find(d->url, &d->pix); - } setImplicitWidth(d->pix.width()); setImplicitHeight(d->pix.height()); @@ -238,22 +169,6 @@ void QFxImageBase::requestFinished() 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); @@ -263,41 +178,5 @@ void QFxImageBase::requestProgress(qint64 received, qint64 total) } } -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 |