summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/declarative/fx/fx.pri3
-rw-r--r--src/declarative/fx/qfxborderimage.cpp397
-rw-r--r--src/declarative/fx/qfxborderimage.h101
-rw-r--r--src/declarative/fx/qfxborderimage_p.h94
-rw-r--r--src/declarative/fx/qfximage.cpp139
-rw-r--r--src/declarative/fx/qfximage.h5
-rw-r--r--src/declarative/fx/qfximage_p.h2
-rw-r--r--src/declarative/fx/qfximagebase.cpp123
-rw-r--r--src/declarative/fx/qfximagebase.h13
-rw-r--r--src/declarative/fx/qfximagebase_p.h27
-rw-r--r--src/declarative/fx/qfxscalegrid.cpp28
-rw-r--r--src/declarative/fx/qfxscalegrid_p.h24
12 files changed, 667 insertions, 289 deletions
diff --git a/src/declarative/fx/fx.pri b/src/declarative/fx/fx.pri
index 266fd71..34f4f67 100644
--- a/src/declarative/fx/fx.pri
+++ b/src/declarative/fx/fx.pri
@@ -10,9 +10,11 @@ HEADERS += \
fx/qfxgridview.h \
fx/qfximage.h \
fx/qfximagebase.h \
+ fx/qfxborderimage.h \
fx/qfxpainteditem.h \
fx/qfxpainteditem_p.h \
fx/qfximage_p.h \
+ fx/qfxborderimage_p.h \
fx/qfximagebase_p.h \
fx/qfxitem.h \
fx/qfxitem_p.h \
@@ -54,6 +56,7 @@ SOURCES += \
fx/qfxflipable.cpp \
fx/qfxgridview.cpp \
fx/qfximage.cpp \
+ fx/qfxborderimage.cpp \
fx/qfximagebase.cpp \
fx/qfxpainteditem.cpp \
fx/qfxitem.cpp \
diff --git a/src/declarative/fx/qfxborderimage.cpp b/src/declarative/fx/qfxborderimage.cpp
new file mode 100644
index 0000000..34f0e66
--- /dev/null
+++ b/src/declarative/fx/qfxborderimage.cpp
@@ -0,0 +1,397 @@
+/****************************************************************************
+**
+** 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 "qfxborderimage.h"
+#include "qfxborderimage_p.h"
+#include <QNetworkRequest>
+#include <QNetworkReply>
+#include <QFile>
+#include <QtDeclarative/qmlengine.h>
+
+QT_BEGIN_NAMESPACE
+
+QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,BorderImage,QFxBorderImage)
+
+/*!
+ \qmlclass BorderImage QFxBorderImage
+ \brief The BorderImage element allows you to add an image used as a border to a scene.
+ \inherits Item
+
+ Example:
+ \qml
+ BorderImage { border.left: 20; border.right: 10
+ border.top: 14; border.bottom: 14
+ width: 160; height: 160
+ source: "pics/qtlogo.png"
+ }
+ \endqml
+ */
+
+/*!
+ \internal
+ \class QFxBorderImage BorderImage
+ \brief The QFxBorderImage class provides an image item that you can add to a QFxView.
+
+ \ingroup group_coreitems
+
+ Example:
+ \qml
+ BorderImage { source: "pics/star.png" }
+ \endqml
+
+ A QFxBorderImage object can be instantiated in Qml using the tag \l BorderImage.
+*/
+
+QFxBorderImage::QFxBorderImage(QFxItem *parent)
+ : QFxImageBase(*(new QFxBorderImagePrivate), parent)
+{
+ setFlag(QGraphicsItem::ItemHasNoContents, false);
+}
+
+QFxBorderImage::~QFxBorderImage()
+{
+ Q_D(QFxBorderImage);
+ if (d->sciReply)
+ d->sciReply->deleteLater();
+ if (!d->sciurl.isEmpty())
+ QFxPixmap::cancelGet(d->sciurl, this);
+}
+/*!
+ \qmlproperty enum BorderImage::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
+*/
+
+/*!
+ \qmlproperty real BorderImage::progress
+
+ This property holds the progress of image loading, from 0.0 (nothing loaded)
+ to 1.0 (finished).
+
+ \sa status
+*/
+
+/*!
+ \qmlproperty url BorderImage::source
+
+ BorderImage 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 {BorderImage::border.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 QFxBorderImage::setSource(const QUrl &url)
+{
+ Q_D(QFxBorderImage);
+ //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);
+}
+
+/*!
+ \qmlproperty int BorderImage::border.left
+ \qmlproperty int BorderImage::border.right
+ \qmlproperty int BorderImage::border.top
+ \qmlproperty int BorderImage::border.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{border.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 {BorderImage::source}{.sci file}.
+*/
+
+QFxScaleGrid *QFxBorderImage::border()
+{
+ Q_D(QFxBorderImage);
+ return d->getScaleGrid();
+}
+
+/*!
+ \qmlproperty TileMode BorderImage::horizontalTileMode
+ \qmlproperty TileMode BorderImage::verticalTileMode
+
+ This property describes how to repeat or stretch the middle parts of the border image.
+
+ \list
+ \o Stretch - Scale the image to fit to the available area.
+ \o Repeat - Tile the image until there is no more space. May crop the last image.
+ \o Round - Like Repeat, but scales the images down to ensure that the last image is not cropped.
+ \endlist
+
+ \sa examples/declarative/border-image
+*/
+QFxBorderImage::TileMode QFxBorderImage::horizontalTileMode() const
+{
+ Q_D(const QFxBorderImage);
+ return d->horizontalTileMode;
+}
+
+void QFxBorderImage::setHorizontalTileMode(TileMode t)
+{
+ Q_D(QFxBorderImage);
+ d->horizontalTileMode = t;
+}
+
+QFxBorderImage::TileMode QFxBorderImage::verticalTileMode() const
+{
+ Q_D(const QFxBorderImage);
+ return d->verticalTileMode;
+}
+
+void QFxBorderImage::setVerticalTileMode(TileMode t)
+{
+ Q_D(QFxBorderImage);
+ d->verticalTileMode = t;
+}
+
+void QFxBorderImage::setGridScaledImage(const QFxGridScaledImage& sci)
+{
+ Q_D(QFxBorderImage);
+ if (!sci.isValid()) {
+ d->status = Error;
+ emit statusChanged(d->status);
+ } else {
+ QFxScaleGrid *sg = border();
+ sg->setTop(sci.gridTop());
+ sg->setBottom(sci.gridBottom());
+ sg->setLeft(sci.gridLeft());
+ sg->setRight(sci.gridRight());
+ d->horizontalTileMode = sci.horizontalTileRule();
+ d->verticalTileMode = 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();
+ }
+ }
+}
+
+void QFxBorderImage::requestFinished()
+{
+ Q_D(QFxBorderImage);
+ 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 QFxBorderImage::sciRequestFinished()
+{
+ Q_D(QFxBorderImage);
+ 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 QFxBorderImage::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *)
+{
+ Q_D(QFxBorderImage);
+ if (d->pix.isNull())
+ return;
+
+ bool oldAA = p->testRenderHint(QPainter::Antialiasing);
+ bool oldSmooth = p->testRenderHint(QPainter::SmoothPixmapTransform);
+ if (d->smooth)
+ p->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, d->smooth);
+
+ QPixmap pix = d->pix;
+
+ QMargins margins(border()->top(), border()->left(), border()->bottom(), border()->right());
+ QTileRules rules((Qt::TileRule)d->horizontalTileMode, (Qt::TileRule)d->verticalTileMode);
+ qDrawBorderPixmap(p, QRect(0, 0, (int)d->width, (int)d->height), margins, pix, pix.rect(), margins, rules);
+ if (d->smooth) {
+ p->setRenderHint(QPainter::Antialiasing, oldAA);
+ p->setRenderHint(QPainter::SmoothPixmapTransform, oldSmooth);
+ }
+}
+
+QFxBorderImage::QFxBorderImage(QFxBorderImagePrivate &dd, QFxItem *parent)
+ : QFxImageBase(dd, parent)
+{
+ setFlag(QGraphicsItem::ItemHasNoContents, false);
+}
+
+QT_END_NAMESPACE
diff --git a/src/declarative/fx/qfxborderimage.h b/src/declarative/fx/qfxborderimage.h
new file mode 100644
index 0000000..26ba9cf
--- /dev/null
+++ b/src/declarative/fx/qfxborderimage.h
@@ -0,0 +1,101 @@
+/****************************************************************************
+**
+** 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 QFXBORDERIMAGE_H
+#define QFXBORDERIMAGE_H
+
+#include <QtNetwork/qnetworkreply.h>
+#include "qfximagebase.h"
+
+QT_BEGIN_HEADER
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Declarative)
+
+class QFxScaleGrid;
+class QFxGridScaledImage;
+class QFxBorderImagePrivate;
+class Q_DECLARATIVE_EXPORT QFxBorderImage : public QFxImageBase
+{
+ Q_OBJECT
+ Q_ENUMS(TileMode)
+
+ Q_PROPERTY(QFxScaleGrid *border READ border CONSTANT)
+ Q_PROPERTY(TileMode horizontalTileMode READ horizontalTileMode WRITE setHorizontalTileMode)
+ Q_PROPERTY(TileMode verticalTileMode READ verticalTileMode WRITE setVerticalTileMode)
+
+public:
+ QFxBorderImage(QFxItem *parent=0);
+ ~QFxBorderImage();
+
+ QFxScaleGrid *border();
+
+ enum TileMode { Stretch = Qt::Stretch, Repeat = Qt::Repeat, Round = Qt::Round };
+
+ TileMode horizontalTileMode() const;
+ void setHorizontalTileMode(TileMode);
+
+ TileMode verticalTileMode() const;
+ void setVerticalTileMode(TileMode);
+
+ void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
+ void setSource(const QUrl &url);
+
+protected:
+ QFxBorderImage(QFxBorderImagePrivate &dd, QFxItem *parent);
+
+private:
+ void setGridScaledImage(const QFxGridScaledImage& sci);
+
+private Q_SLOTS:
+ void requestFinished();
+ void sciRequestFinished();
+
+private:
+ Q_DISABLE_COPY(QFxBorderImage)
+ Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxBorderImage)
+};
+
+QT_END_NAMESPACE
+QML_DECLARE_TYPE(QFxBorderImage)
+QT_END_HEADER
+
+#endif // QFXBORDERIMAGE_H
diff --git a/src/declarative/fx/qfxborderimage_p.h b/src/declarative/fx/qfxborderimage_p.h
new file mode 100644
index 0000000..50f3311
--- /dev/null
+++ b/src/declarative/fx/qfxborderimage_p.h
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** 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 QFXBORDERIMAGE_P_H
+#define QFXBORDERIMAGE_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qfximagebase_p.h"
+#include "qfxscalegrid_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QNetworkReply;
+class QFxBorderImagePrivate : public QFxImageBasePrivate
+{
+ Q_DECLARE_PUBLIC(QFxBorderImage)
+
+public:
+ QFxBorderImagePrivate()
+ : border(0), sciReply(0),
+ horizontalTileMode(QFxBorderImage::Stretch),
+ verticalTileMode(QFxBorderImage::Stretch)
+ {
+ }
+
+ ~QFxBorderImagePrivate()
+ {
+ }
+
+ QFxScaleGrid *getScaleGrid()
+ {
+ if (!border)
+ border = new QFxScaleGrid;
+ return border;
+ }
+
+ QFxScaleGrid *border;
+ QUrl sciurl;
+ QNetworkReply *sciReply;
+ QFxBorderImage::TileMode horizontalTileMode;
+ QFxBorderImage::TileMode verticalTileMode;
+};
+
+QT_END_NAMESPACE
+
+#endif // QFXBORDERIMAGE_P_H
diff --git a/src/declarative/fx/qfximage.cpp b/src/declarative/fx/qfximage.cpp
index 5c9e1f9..79c11b1 100644
--- a/src/declarative/fx/qfximage.cpp
+++ b/src/declarative/fx/qfximage.cpp
@@ -55,13 +55,10 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Image,QFxImage)
\brief The Image element allows you to add bitmaps to a scene.
\inherits Item
- The Image element supports untransformed, stretched, tiled, and grid-scaled images.
+ The Image element supports untransformed, stretched and tiled.
For an explanation of stretching and tiling, see the fillMode property description.
- For an explanation of grid-scaling see the scaleGrid property description
- or the QFxScaleGrid class description.
-
Examples:
\table
\row
@@ -81,16 +78,6 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Image,QFxImage)
}
\endqml
\row
- \o \image declarative-qtlogo4.png
- \o Grid-scaled (only with fillMode: Stretch)
- \qml
- Image { scaleGrid.left: 20; scaleGrid.right: 10
- scaleGrid.top: 14; scaleGrid.bottom: 14
- width: 160; height: 160
- source: "pics/qtlogo.png"
- }
- \endqml
- \row
\o \image declarative-qtlogo3.png
\o fillMode: Tile
\qml
@@ -155,10 +142,10 @@ QFxImage::~QFxImage()
}
/*!
- \property QFxImage::image
+ \property QFxImage::pixmap
\brief the image displayed in this item.
- This property contains the image currently being displayed by this item,
+ This property contains the pixmap currently being displayed by this item,
which may be empty if nothing is currently displayed. Setting the source
property overrides any setting of this property.
*/
@@ -196,10 +183,6 @@ void QFxImage::setPixmap(const QPixmap &pix)
\endlist
\image declarative-image_fillMode.gif
-
- Only fillMode: Stretch can be used with scaleGrid. Other settings
- will cause a run-time warning.
-
\sa examples/declarative/aspectratio
*/
QFxImage::FillMode QFxImage::fillMode() const
@@ -246,21 +229,6 @@ void QFxImage::setFillMode(FillMode mode)
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.
*/
@@ -277,74 +245,67 @@ void QFxImage::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *)
QPixmap pix = d->pix;
- if (!d->scaleGrid || d->scaleGrid->isNull()) {
- if (width() != pix.width() || height() != pix.height()) {
- if (d->fillMode >= Tile) {
- p->save();
- p->setClipRect(0, 0, width(), height(), Qt::IntersectClip);
-
- if (d->fillMode == Tile) {
- const int pw = pix.width();
- const int ph = pix.height();
- int yy = 0;
-
- while(yy < height()) {
- int xx = 0;
- while(xx < width()) {
- p->drawPixmap(xx, yy, pix);
- xx += pw;
- }
- yy += ph;
- }
- } else if (d->fillMode == TileVertically) {
- const int ph = pix.height();
- int yy = 0;
+ if (width() != pix.width() || height() != pix.height()) {
+ if (d->fillMode >= Tile) {
+ p->save();
+ p->setClipRect(0, 0, width(), height(), Qt::IntersectClip);
- while(yy < height()) {
- p->drawPixmap(QRect(0, yy, width(), ph), pix);
- yy += ph;
- }
- } else {
- const int pw = pix.width();
- int xx = 0;
+ if (d->fillMode == Tile) {
+ const int pw = pix.width();
+ const int ph = pix.height();
+ int yy = 0;
+ while(yy < height()) {
+ int xx = 0;
while(xx < width()) {
- p->drawPixmap(QRect(xx, 0, pw, height()), pix);
+ p->drawPixmap(xx, yy, pix);
xx += pw;
}
+ yy += ph;
}
+ } else if (d->fillMode == TileVertically) {
+ const int ph = pix.height();
+ int yy = 0;
- p->restore();
- } else {
- qreal widthScale = width() / qreal(pix.width());
- qreal heightScale = height() / qreal(pix.height());
-
- QTransform scale;
-
- if (d->fillMode == PreserveAspect) {
- if (widthScale < heightScale) {
- heightScale = widthScale;
- scale.translate(0, (height() - heightScale * pix.height()) / 2);
- } else if(heightScale < widthScale) {
- widthScale = heightScale;
- scale.translate((width() - widthScale * pix.width()) / 2, 0);
- }
+ while(yy < height()) {
+ p->drawPixmap(QRect(0, yy, width(), ph), pix);
+ yy += ph;
}
+ } else {
+ const int pw = pix.width();
+ int xx = 0;
- scale.scale(widthScale, heightScale);
- QTransform old = p->transform();
- p->setWorldTransform(scale * old);
- p->drawPixmap(0, 0, pix);
- p->setWorldTransform(old);
+ while(xx < width()) {
+ p->drawPixmap(QRect(xx, 0, pw, height()), pix);
+ xx += pw;
+ }
}
+
+ p->restore();
} else {
+ qreal widthScale = width() / qreal(pix.width());
+ qreal heightScale = height() / qreal(pix.height());
+
+ QTransform scale;
+
+ if (d->fillMode == PreserveAspect) {
+ if (widthScale < heightScale) {
+ heightScale = widthScale;
+ scale.translate(0, (height() - heightScale * pix.height()) / 2);
+ } else if(heightScale < widthScale) {
+ widthScale = heightScale;
+ scale.translate((width() - widthScale * pix.width()) / 2, 0);
+ }
+ }
+
+ scale.scale(widthScale, heightScale);
+ QTransform old = p->transform();
+ p->setWorldTransform(scale * old);
p->drawPixmap(0, 0, pix);
+ p->setWorldTransform(old);
}
} else {
- QMargins margins(d->scaleGrid->top(), d->scaleGrid->left(), d->scaleGrid->bottom(), d->scaleGrid->right());
- QTileRules rules((Qt::TileRule)d->scaleGrid->horizontalTileRule(),
- (Qt::TileRule)d->scaleGrid->verticalTileRule());
- qDrawBorderPixmap(p, QRect(0, 0, (int)d->width, (int)d->height), margins, pix, pix.rect(), margins, rules);
+ p->drawPixmap(0, 0, pix);
}
if (d->smooth) {
diff --git a/src/declarative/fx/qfximage.h b/src/declarative/fx/qfximage.h
index b31da29..0a9d2df 100644
--- a/src/declarative/fx/qfximage.h
+++ b/src/declarative/fx/qfximage.h
@@ -46,12 +46,11 @@
#include "qfximagebase.h"
QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
-class QFxImagePrivate;
+class QFxImagePrivate;
class Q_DECLARATIVE_EXPORT QFxImage : public QFxImageBase
{
Q_OBJECT
@@ -85,9 +84,7 @@ private:
};
QT_END_NAMESPACE
-
QML_DECLARE_TYPE(QFxImage)
-
QT_END_HEADER
#endif // QFXIMAGE_H
diff --git a/src/declarative/fx/qfximage_p.h b/src/declarative/fx/qfximage_p.h
index 825da5b..8bdcc14 100644
--- a/src/declarative/fx/qfximage_p.h
+++ b/src/declarative/fx/qfximage_p.h
@@ -56,8 +56,6 @@
#include "qfxitem_p.h"
#include "qfximagebase_p.h"
-#include <QtCore/qpointer.h>
-
QT_BEGIN_NAMESPACE
class QFxImagePrivate : public QFxImageBasePrivate
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
diff --git a/src/declarative/fx/qfximagebase.h b/src/declarative/fx/qfximagebase.h
index 78e391e..ce9c0c3 100644
--- a/src/declarative/fx/qfximagebase.h
+++ b/src/declarative/fx/qfximagebase.h
@@ -44,10 +44,9 @@
#include <QtDeclarative/qfxitem.h>
+QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
-class QFxScaleGrid;
-class QFxGridScaledImage;
class QFxImageBasePrivate;
class QFxImageBase : public QFxItem
{
@@ -57,7 +56,6 @@ class QFxImageBase : public QFxItem
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);
@@ -76,22 +74,17 @@ Q_SIGNALS:
protected:
QFxImageBase(QFxImageBasePrivate &dd, QFxItem *parent);
- virtual void componentComplete();
private Q_SLOTS:
- void requestFinished();
- void sciRequestFinished();
+ virtual void requestFinished();
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
+QT_END_HEADER
#endif // QFXIMAGEBASE_H
diff --git a/src/declarative/fx/qfximagebase_p.h b/src/declarative/fx/qfximagebase_p.h
index e84fffe..b468b90 100644
--- a/src/declarative/fx/qfximagebase_p.h
+++ b/src/declarative/fx/qfximagebase_p.h
@@ -54,48 +54,25 @@
//
#include "qfxitem_p.h"
-#include "qfxscalegrid_p.h"
+#include <QtCore/QPointer>
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),
+ : status(QFxImageBase::Null),
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;
};
diff --git a/src/declarative/fx/qfxscalegrid.cpp b/src/declarative/fx/qfxscalegrid.cpp
index 8eb9890..4856c15 100644
--- a/src/declarative/fx/qfxscalegrid.cpp
+++ b/src/declarative/fx/qfxscalegrid.cpp
@@ -74,8 +74,7 @@ QT_BEGIN_NAMESPACE
*/
QML_DEFINE_NOCREATE_TYPE(QFxScaleGrid)
-QFxScaleGrid::QFxScaleGrid() : QObject(), _left(0), _top(0), _right(0), _bottom(0),
- _horizontalTileRule(Stretch), _verticalTileRule(Stretch)
+QFxScaleGrid::QFxScaleGrid() : QObject(), _left(0), _top(0), _right(0), _bottom(0)
{
}
@@ -124,20 +123,9 @@ void QFxScaleGrid::setBottom(int pos)
_bottom = pos;
}
-void QFxScaleGrid::setHorizontalTileRule(TileRule r)
-{
- _horizontalTileRule = r;
-}
-
-void QFxScaleGrid::setVerticalTileRule(TileRule r)
-{
- _verticalTileRule = r;
-}
-
-
QFxGridScaledImage::QFxGridScaledImage()
: _l(-1), _r(-1), _t(-1), _b(-1),
- _h(QFxScaleGrid::Stretch), _v(QFxScaleGrid::Stretch)
+ _h(QFxBorderImage::Stretch), _v(QFxBorderImage::Stretch)
{
}
@@ -159,7 +147,7 @@ QFxGridScaledImage &QFxGridScaledImage::operator=(const QFxGridScaledImage &o)
}
QFxGridScaledImage::QFxGridScaledImage(QIODevice *data)
-: _l(-1), _r(-1), _t(-1), _b(-1), _h(QFxScaleGrid::Stretch), _v(QFxScaleGrid::Stretch)
+: _l(-1), _r(-1), _t(-1), _b(-1), _h(QFxBorderImage::Stretch), _v(QFxBorderImage::Stretch)
{
int l = -1;
int r = -1;
@@ -203,17 +191,17 @@ QFxGridScaledImage::QFxGridScaledImage(QIODevice *data)
_pix = imgFile;
}
-QFxScaleGrid::TileRule QFxGridScaledImage::stringToRule(const QString &s)
+QFxBorderImage::TileMode QFxGridScaledImage::stringToRule(const QString &s)
{
if (s == QLatin1String("Stretch"))
- return QFxScaleGrid::Stretch;
+ return QFxBorderImage::Stretch;
if (s == QLatin1String("Repeat"))
- return QFxScaleGrid::Repeat;
+ return QFxBorderImage::Repeat;
if (s == QLatin1String("Round"))
- return QFxScaleGrid::Round;
+ return QFxBorderImage::Round;
qWarning() << "Unknown tile rule specified. Using Stretch";
- return QFxScaleGrid::Stretch;
+ return QFxBorderImage::Stretch;
}
bool QFxGridScaledImage::isValid() const
diff --git a/src/declarative/fx/qfxscalegrid_p.h b/src/declarative/fx/qfxscalegrid_p.h
index 483ade1..9d0a84c 100644
--- a/src/declarative/fx/qfxscalegrid_p.h
+++ b/src/declarative/fx/qfxscalegrid_p.h
@@ -47,6 +47,7 @@
#include <QtDeclarative/qfxglobal.h>
#include <QtDeclarative/qfxpixmap.h>
#include <QtDeclarative/qml.h>
+#include "qfxborderimage.h"
QT_BEGIN_HEADER
@@ -54,6 +55,7 @@ QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
+
class Q_DECLARATIVE_EXPORT QFxScaleGrid : public QObject
{
Q_OBJECT
@@ -63,8 +65,6 @@ class Q_DECLARATIVE_EXPORT QFxScaleGrid : public QObject
Q_PROPERTY(int top READ top WRITE setTop)
Q_PROPERTY(int right READ right WRITE setRight)
Q_PROPERTY(int bottom READ bottom WRITE setBottom)
- Q_PROPERTY(TileRule horizontalTileRule READ horizontalTileRule WRITE setHorizontalTileRule)
- Q_PROPERTY(TileRule verticalTileRule READ verticalTileRule WRITE setVerticalTileRule)
public:
QFxScaleGrid();
@@ -84,21 +84,11 @@ public:
int bottom() const { return _bottom; }
void setBottom(int);
- enum TileRule { Stretch = Qt::Stretch, Repeat = Qt::Repeat, Round = Qt::Round };
-
- TileRule horizontalTileRule() const { return _horizontalTileRule; }
- void setHorizontalTileRule(TileRule);
-
- TileRule verticalTileRule() const { return _verticalTileRule; }
- void setVerticalTileRule(TileRule);
-
private:
int _left;
int _top;
int _right;
int _bottom;
- TileRule _horizontalTileRule;
- TileRule _verticalTileRule;
};
class Q_DECLARATIVE_EXPORT QFxGridScaledImage
@@ -113,21 +103,21 @@ public:
int gridRight() const;
int gridTop() const;
int gridBottom() const;
- QFxScaleGrid::TileRule horizontalTileRule() const { return _h; }
- QFxScaleGrid::TileRule verticalTileRule() const { return _v; }
+ QFxBorderImage::TileMode horizontalTileRule() const { return _h; }
+ QFxBorderImage::TileMode verticalTileRule() const { return _v; }
QString pixmapUrl() const;
private:
- static QFxScaleGrid::TileRule stringToRule(const QString &);
+ static QFxBorderImage::TileMode stringToRule(const QString &);
private:
int _l;
int _r;
int _t;
int _b;
- QFxScaleGrid::TileRule _h;
- QFxScaleGrid::TileRule _v;
+ QFxBorderImage::TileMode _h;
+ QFxBorderImage::TileMode _v;
QString _pix;
};