summaryrefslogtreecommitdiffstats
path: root/src/declarative
diff options
context:
space:
mode:
authorDavid Boddie <dboddie@trolltech.com>2010-07-12 12:35:27 (GMT)
committerDavid Boddie <dboddie@trolltech.com>2010-07-12 12:35:27 (GMT)
commit55ff179342bfb67b6f2592d7b1df66e1f3c6a350 (patch)
tree266b6e82ae4de9c1eb2f0c2d2c2310f774a55089 /src/declarative
parent0713442baa4120050e85c13998797415bb40efce (diff)
parente4f5a81869e75a998278c19134f2772fefd998fe (diff)
downloadQt-55ff179342bfb67b6f2592d7b1df66e1f3c6a350.zip
Qt-55ff179342bfb67b6f2592d7b1df66e1f3c6a350.tar.gz
Qt-55ff179342bfb67b6f2592d7b1df66e1f3c6a350.tar.bz2
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/oslo-staging-2 into 4.7
Diffstat (limited to 'src/declarative')
-rw-r--r--src/declarative/QmlChanges.txt20
-rw-r--r--src/declarative/debugger/qdeclarativedebug.cpp50
-rw-r--r--src/declarative/debugger/qdeclarativedebug_p.h8
-rw-r--r--src/declarative/graphicsitems/qdeclarativeanimatedimage_p.h2
-rw-r--r--src/declarative/graphicsitems/qdeclarativeborderimage.cpp100
-rw-r--r--src/declarative/graphicsitems/qdeclarativeborderimage_p.h2
-rw-r--r--src/declarative/graphicsitems/qdeclarativeborderimage_p_p.h2
-rw-r--r--src/declarative/graphicsitems/qdeclarativeflickable.cpp85
-rw-r--r--src/declarative/graphicsitems/qdeclarativeflickable_p.h12
-rw-r--r--src/declarative/graphicsitems/qdeclarativeflickable_p_p.h2
-rw-r--r--src/declarative/graphicsitems/qdeclarativeflipable_p.h2
-rw-r--r--src/declarative/graphicsitems/qdeclarativefocuspanel_p.h2
-rw-r--r--src/declarative/graphicsitems/qdeclarativefocusscope.cpp2
-rw-r--r--src/declarative/graphicsitems/qdeclarativefocusscope_p.h2
-rw-r--r--src/declarative/graphicsitems/qdeclarativegridview.cpp105
-rw-r--r--src/declarative/graphicsitems/qdeclarativegridview_p.h5
-rw-r--r--src/declarative/graphicsitems/qdeclarativeimage.cpp45
-rw-r--r--src/declarative/graphicsitems/qdeclarativeimage_p.h4
-rw-r--r--src/declarative/graphicsitems/qdeclarativeimagebase.cpp65
-rw-r--r--src/declarative/graphicsitems/qdeclarativeimagebase_p.h2
-rw-r--r--src/declarative/graphicsitems/qdeclarativeimagebase_p_p.h5
-rw-r--r--src/declarative/graphicsitems/qdeclarativeitem.cpp11
-rw-r--r--src/declarative/graphicsitems/qdeclarativelistview.cpp153
-rw-r--r--src/declarative/graphicsitems/qdeclarativelistview_p.h20
-rw-r--r--src/declarative/graphicsitems/qdeclarativeloader.cpp12
-rw-r--r--src/declarative/graphicsitems/qdeclarativeloader_p.h2
-rw-r--r--src/declarative/graphicsitems/qdeclarativemousearea.cpp6
-rw-r--r--src/declarative/graphicsitems/qdeclarativemousearea_p.h4
-rw-r--r--src/declarative/graphicsitems/qdeclarativepainteditem.cpp4
-rw-r--r--src/declarative/graphicsitems/qdeclarativepainteditem_p.h2
-rw-r--r--src/declarative/graphicsitems/qdeclarativepath_p.h16
-rw-r--r--src/declarative/graphicsitems/qdeclarativepathview.cpp8
-rw-r--r--src/declarative/graphicsitems/qdeclarativepathview_p.h2
-rw-r--r--src/declarative/graphicsitems/qdeclarativepositioners.cpp4
-rw-r--r--src/declarative/graphicsitems/qdeclarativepositioners_p.h10
-rw-r--r--src/declarative/graphicsitems/qdeclarativerectangle.cpp1
-rw-r--r--src/declarative/graphicsitems/qdeclarativerectangle_p.h6
-rw-r--r--src/declarative/graphicsitems/qdeclarativerepeater.cpp38
-rw-r--r--src/declarative/graphicsitems/qdeclarativerepeater_p.h2
-rw-r--r--src/declarative/graphicsitems/qdeclarativetext.cpp306
-rw-r--r--src/declarative/graphicsitems/qdeclarativetext_p.h5
-rw-r--r--src/declarative/graphicsitems/qdeclarativetext_p_p.h7
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextedit.cpp64
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextedit_p.h4
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextinput.cpp108
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextinput_p.h11
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextinput_p_p.h1
-rw-r--r--src/declarative/graphicsitems/qdeclarativetranslate_p.h2
-rw-r--r--src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp8
-rw-r--r--src/declarative/graphicsitems/qdeclarativevisualitemmodel_p.h6
-rw-r--r--src/declarative/qml/qdeclarativecompiler.cpp39
-rw-r--r--src/declarative/qml/qdeclarativecompiler_p.h3
-rw-r--r--src/declarative/qml/qdeclarativecomponent.cpp69
-rw-r--r--src/declarative/qml/qdeclarativecontext.cpp2
-rw-r--r--src/declarative/qml/qdeclarativecustomparser.cpp10
-rw-r--r--src/declarative/qml/qdeclarativecustomparser_p.h14
-rw-r--r--src/declarative/qml/qdeclarativedom.cpp2
-rw-r--r--src/declarative/qml/qdeclarativeengine.cpp102
-rw-r--r--src/declarative/qml/qdeclarativeengine_p.h4
-rw-r--r--src/declarative/qml/qdeclarativeenginedebug.cpp139
-rw-r--r--src/declarative/qml/qdeclarativeenginedebug_p.h3
-rw-r--r--src/declarative/qml/qdeclarativeexpression.cpp24
-rw-r--r--src/declarative/qml/qdeclarativeextensionplugin.cpp4
-rw-r--r--src/declarative/qml/qdeclarativeglobalscriptclass.cpp28
-rw-r--r--src/declarative/qml/qdeclarativeglobalscriptclass_p.h5
-rw-r--r--src/declarative/qml/qdeclarativeimageprovider.cpp162
-rw-r--r--src/declarative/qml/qdeclarativeimageprovider.h18
-rw-r--r--src/declarative/qml/qdeclarativeimport.cpp24
-rw-r--r--src/declarative/qml/qdeclarativeinstruction_p.h2
-rw-r--r--src/declarative/qml/qdeclarativelist.cpp2
-rw-r--r--src/declarative/qml/qdeclarativemetatype.cpp2
-rw-r--r--src/declarative/qml/qdeclarativenetworkaccessmanagerfactory.cpp2
-rw-r--r--src/declarative/qml/qdeclarativeobjectscriptclass.cpp24
-rw-r--r--src/declarative/qml/qdeclarativeobjectscriptclass_p.h2
-rw-r--r--src/declarative/qml/qdeclarativetypenamescriptclass.cpp4
-rw-r--r--src/declarative/qml/qdeclarativevmemetaobject.cpp30
-rw-r--r--src/declarative/qml/qdeclarativevmemetaobject_p.h2
-rw-r--r--src/declarative/qml/qdeclarativeworkerscript_p.h2
-rw-r--r--src/declarative/util/qdeclarativeanimation.cpp12
-rw-r--r--src/declarative/util/qdeclarativeanimation_p.h5
-rw-r--r--src/declarative/util/qdeclarativebehavior.cpp25
-rw-r--r--src/declarative/util/qdeclarativebehavior_p.h2
-rw-r--r--src/declarative/util/qdeclarativebind_p.h2
-rw-r--r--src/declarative/util/qdeclarativeconnections_p.h2
-rw-r--r--src/declarative/util/qdeclarativefontloader_p.h2
-rw-r--r--src/declarative/util/qdeclarativelistaccessor_p.h2
-rw-r--r--src/declarative/util/qdeclarativelistmodel.cpp13
-rw-r--r--src/declarative/util/qdeclarativelistmodel_p.h2
-rw-r--r--src/declarative/util/qdeclarativepackage.cpp4
-rw-r--r--src/declarative/util/qdeclarativepixmapcache.cpp1201
-rw-r--r--src/declarative/util/qdeclarativepixmapcache_p.h85
-rw-r--r--src/declarative/util/qdeclarativepropertychanges.cpp2
-rw-r--r--src/declarative/util/qdeclarativepropertychanges_p.h5
-rw-r--r--src/declarative/util/qdeclarativesmoothedanimation.cpp2
-rw-r--r--src/declarative/util/qdeclarativesmoothedanimation_p.h2
-rw-r--r--src/declarative/util/qdeclarativesmoothedfollow.cpp299
-rw-r--r--src/declarative/util/qdeclarativesmoothedfollow_p.h113
-rw-r--r--src/declarative/util/qdeclarativespringanimation.cpp (renamed from src/declarative/util/qdeclarativespringfollow.cpp)292
-rw-r--r--src/declarative/util/qdeclarativespringanimation_p.h (renamed from src/declarative/util/qdeclarativespringfollow_p.h)42
-rw-r--r--src/declarative/util/qdeclarativestateoperations_p.h6
-rw-r--r--src/declarative/util/qdeclarativestyledtext.cpp6
-rw-r--r--src/declarative/util/qdeclarativestyledtext_p.h2
-rw-r--r--src/declarative/util/qdeclarativesystempalette_p.h2
-rw-r--r--src/declarative/util/qdeclarativetimer.cpp2
-rw-r--r--src/declarative/util/qdeclarativetimer_p.h2
-rw-r--r--src/declarative/util/qdeclarativetransition.cpp2
-rw-r--r--src/declarative/util/qdeclarativeutilmodule.cpp6
-rw-r--r--src/declarative/util/qdeclarativeview.cpp47
-rw-r--r--src/declarative/util/qdeclarativexmllistmodel.cpp6
-rw-r--r--src/declarative/util/qdeclarativexmllistmodel_p.h4
-rw-r--r--src/declarative/util/util.pri6
111 files changed, 2541 insertions, 1733 deletions
diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt
index 432b5d6..872f6cb 100644
--- a/src/declarative/QmlChanges.txt
+++ b/src/declarative/QmlChanges.txt
@@ -1,5 +1,10 @@
=============================================================================
-The changes below are pre Qt 4.7.0 RC
+The changes below are pre Qt 4.7.0 tech preview
+
+TextInput
+ - copy(), cut() and paste() functions added
+
+The changes below are pre Qt 4.7.0 beta 2
QDeclarativeView
- initialSize() function added
@@ -14,8 +19,13 @@ Component:
- isReady, isLoading, isError and isNull properties removed, use
status property instead
- errorsString() renamed to errorString()
-
-TextInput xToPosition -> positionAt (to match TextEdit.positionAt)
+ListView:
+ - ListView.prevSection property changed to ListView.previousSection
+TextInput:
+ - xToPosition -> positionAt (to match TextEdit.positionAt)
+Image:
+ - pixmap property removed, use QDeclarativeImageProvider to serve pixmaps
+ instead
QList<QObject*> models no longer provide properties in model object. The
properties are now updated when the object changes. An object's property
@@ -33,6 +43,10 @@ The QDeclarativeExpression constructor has changed from
to
QDeclarativeExpression(context, scope, expression, parent = 0)
+QDeclarativeImageProvider::request() has been renamed to
+QDeclarativeImageProvider::image() and the class can now provide
+both qimages and qpixmaps, and qimages can be served synchronously
+
QML Viewer
------------
The standalone qml executable has been renamed back to Qml Viewer. Runtime warnings
diff --git a/src/declarative/debugger/qdeclarativedebug.cpp b/src/declarative/debugger/qdeclarativedebug.cpp
index cd5340b..b950aef 100644
--- a/src/declarative/debugger/qdeclarativedebug.cpp
+++ b/src/declarative/debugger/qdeclarativedebug.cpp
@@ -562,6 +562,54 @@ QDeclarativeDebugExpressionQuery *QDeclarativeEngineDebug::queryExpressionResult
return query;
}
+bool QDeclarativeEngineDebug::setBindingForObject(int objectDebugId, const QString &propertyName,
+ const QVariant &bindingExpression,
+ bool isLiteralValue)
+{
+ Q_D(QDeclarativeEngineDebug);
+
+ if (d->client->isConnected() && objectDebugId != -1) {
+ QByteArray message;
+ QDataStream ds(&message, QIODevice::WriteOnly);
+ ds << QByteArray("SET_BINDING") << objectDebugId << propertyName << bindingExpression << isLiteralValue;
+ d->client->sendMessage(message);
+ return true;
+ } else {
+ return false;
+ }
+}
+
+bool QDeclarativeEngineDebug::resetBindingForObject(int objectDebugId, const QString &propertyName)
+{
+ Q_D(QDeclarativeEngineDebug);
+
+ if (d->client->isConnected() && objectDebugId != -1) {
+ QByteArray message;
+ QDataStream ds(&message, QIODevice::WriteOnly);
+ ds << QByteArray("RESET_BINDING") << objectDebugId << propertyName;
+ d->client->sendMessage(message);
+ return true;
+ } else {
+ return false;
+ }
+}
+
+bool QDeclarativeEngineDebug::setMethodBody(int objectDebugId, const QString &methodName,
+ const QString &methodBody)
+{
+ Q_D(QDeclarativeEngineDebug);
+
+ if (d->client->isConnected() && objectDebugId != -1) {
+ QByteArray message;
+ QDataStream ds(&message, QIODevice::WriteOnly);
+ ds << QByteArray("SET_METHOD_BODY") << objectDebugId << methodName << methodBody;
+ d->client->sendMessage(message);
+ return true;
+ } else {
+ return false;
+ }
+}
+
QDeclarativeDebugWatch::QDeclarativeDebugWatch(QObject *parent)
: QObject(parent), m_state(Waiting), m_queryId(-1), m_client(0), m_objectDebugId(-1)
{
@@ -698,7 +746,7 @@ QDeclarativeDebugExpressionQuery::~QDeclarativeDebugExpressionQuery()
QDeclarativeEngineDebugPrivate::remove(m_client, this);
}
-QString QDeclarativeDebugExpressionQuery::expression() const
+QVariant QDeclarativeDebugExpressionQuery::expression() const
{
return m_expr;
}
diff --git a/src/declarative/debugger/qdeclarativedebug_p.h b/src/declarative/debugger/qdeclarativedebug_p.h
index 4ead232..2e79c5d 100644
--- a/src/declarative/debugger/qdeclarativedebug_p.h
+++ b/src/declarative/debugger/qdeclarativedebug_p.h
@@ -94,6 +94,10 @@ public:
QDeclarativeDebugExpressionQuery *queryExpressionResult(int objectDebugId,
const QString &expr,
QObject *parent = 0);
+ bool setBindingForObject(int objectDebugId, const QString &propertyName,
+ const QVariant &bindingExpression, bool isLiteralValue);
+ bool resetBindingForObject(int objectDebugId, const QString &propertyName);
+ bool setMethodBody(int objectDebugId, const QString &methodName, const QString &methodBody);
private:
Q_DECLARE_PRIVATE(QDeclarativeEngineDebug)
@@ -348,7 +352,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativeDebugExpressionQuery : public QDeclarativ
Q_OBJECT
public:
virtual ~QDeclarativeDebugExpressionQuery();
- QString expression() const;
+ QVariant expression() const;
QVariant result() const;
private:
friend class QDeclarativeEngineDebug;
@@ -356,7 +360,7 @@ private:
QDeclarativeDebugExpressionQuery(QObject *);
QDeclarativeEngineDebug *m_client;
int m_queryId;
- QString m_expr;
+ QVariant m_expr;
QVariant m_result;
};
diff --git a/src/declarative/graphicsitems/qdeclarativeanimatedimage_p.h b/src/declarative/graphicsitems/qdeclarativeanimatedimage_p.h
index 5981cd3..ec361ea 100644
--- a/src/declarative/graphicsitems/qdeclarativeanimatedimage_p.h
+++ b/src/declarative/graphicsitems/qdeclarativeanimatedimage_p.h
@@ -55,7 +55,7 @@ QT_MODULE(Declarative)
class QMovie;
class QDeclarativeAnimatedImagePrivate;
-class Q_DECLARATIVE_EXPORT QDeclarativeAnimatedImage : public QDeclarativeImage
+class Q_AUTOTEST_EXPORT QDeclarativeAnimatedImage : public QDeclarativeImage
{
Q_OBJECT
diff --git a/src/declarative/graphicsitems/qdeclarativeborderimage.cpp b/src/declarative/graphicsitems/qdeclarativeborderimage.cpp
index d4ca9eb..44c206b 100644
--- a/src/declarative/graphicsitems/qdeclarativeborderimage.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeborderimage.cpp
@@ -94,8 +94,6 @@ QDeclarativeBorderImage::~QDeclarativeBorderImage()
Q_D(QDeclarativeBorderImage);
if (d->sciReply)
d->sciReply->deleteLater();
- if (d->sciPendingPixmapCache)
- QDeclarativePixmapCache::cancel(d->sciurl, this);
}
/*!
\qmlproperty enumeration BorderImage::status
@@ -164,15 +162,6 @@ void QDeclarativeBorderImage::setSource(const QUrl &url)
d->sciReply = 0;
}
- if (d->pendingPixmapCache) {
- QDeclarativePixmapCache::cancel(d->url, this);
- d->pendingPixmapCache = false;
- }
- if (d->sciPendingPixmapCache) {
- QDeclarativePixmapCache::cancel(d->sciurl, this);
- d->sciPendingPixmapCache = false;
- }
-
d->url = url;
d->sciurl = QUrl();
emit sourceChanged(d->url);
@@ -190,7 +179,7 @@ void QDeclarativeBorderImage::load()
}
if (d->url.isEmpty()) {
- d->pix = QPixmap();
+ d->pix.clear();
d->status = Null;
setImplicitWidth(0);
setImplicitHeight(0);
@@ -224,26 +213,24 @@ void QDeclarativeBorderImage::load()
thisSciRequestFinished, Qt::DirectConnection);
}
} else {
- QSize impsize;
- QString errorString;
- QDeclarativePixmapReply::Status status = QDeclarativePixmapCache::get(d->url, &d->pix, &errorString, &impsize, d->async);
- if (status != QDeclarativePixmapReply::Ready && status != QDeclarativePixmapReply::Error) {
- QDeclarativePixmapReply *reply = QDeclarativePixmapCache::request(qmlEngine(this), d->url);
- d->pendingPixmapCache = true;
- connect(reply, SIGNAL(finished()), this, SLOT(requestFinished()));
- connect(reply, SIGNAL(downloadProgress(qint64,qint64)),
- this, SLOT(requestProgress(qint64,qint64)));
+
+ d->pix.load(qmlEngine(this), d->url, d->async);
+
+ if (d->pix.isLoading()) {
+ d->pix.connectFinished(this, SLOT(requestFinished()));
+ d->pix.connectDownloadProgress(this, SLOT(requestProgress(qint64,qint64)));
} else {
- //### should be unified with requestFinished
+ QSize impsize = d->pix.implicitSize();
setImplicitWidth(impsize.width());
setImplicitHeight(impsize.height());
- if (d->pix.isNull()) {
+ if (d->pix.isReady()) {
+ d->status = Ready;
+ } else {
d->status = Error;
- qmlInfo(this) << errorString;
+ qmlInfo(this) << d->pix.error();
}
- if (d->status == Loading)
- d->status = Ready;
+
d->progress = 1.0;
emit statusChanged(d->status);
emit progressChanged(d->progress);
@@ -343,47 +330,40 @@ void QDeclarativeBorderImage::setGridScaledImage(const QDeclarativeGridScaledIma
d->verticalTileMode = sci.verticalTileRule();
d->sciurl = d->url.resolved(QUrl(sci.pixmapUrl()));
- QSize impsize;
- QString errorString;
- QDeclarativePixmapReply::Status status = QDeclarativePixmapCache::get(d->sciurl, &d->pix, &errorString, &impsize, d->async);
- if (status != QDeclarativePixmapReply::Ready && status != QDeclarativePixmapReply::Error) {
- QDeclarativePixmapReply *reply = QDeclarativePixmapCache::request(qmlEngine(this), d->sciurl);
- d->sciPendingPixmapCache = true;
-
- static int replyDownloadProgress = -1;
- static int replyFinished = -1;
+
+ d->pix.load(qmlEngine(this), d->sciurl, d->async);
+
+ if (d->pix.isLoading()) {
static int thisRequestProgress = -1;
static int thisRequestFinished = -1;
- if (replyDownloadProgress == -1) {
- replyDownloadProgress =
- QDeclarativePixmapReply::staticMetaObject.indexOfSignal("downloadProgress(qint64,qint64)");
- replyFinished =
- QDeclarativePixmapReply::staticMetaObject.indexOfSignal("finished()");
+ if (thisRequestProgress == -1) {
thisRequestProgress =
QDeclarativeBorderImage::staticMetaObject.indexOfSlot("requestProgress(qint64,qint64)");
thisRequestFinished =
QDeclarativeBorderImage::staticMetaObject.indexOfSlot("requestFinished()");
}
- QMetaObject::connect(reply, replyFinished, this,
- thisRequestFinished, Qt::DirectConnection);
- QMetaObject::connect(reply, replyDownloadProgress, this,
- thisRequestProgress, Qt::DirectConnection);
+ d->pix.connectFinished(this, thisRequestFinished);
+ d->pix.connectDownloadProgress(this, thisRequestProgress);
+
} else {
- //### should be unified with requestFinished
+
+ QSize impsize = d->pix.implicitSize();
setImplicitWidth(impsize.width());
setImplicitHeight(impsize.height());
- if (d->pix.isNull()) {
+ if (d->pix.isReady()) {
+ d->status = Ready;
+ } else {
d->status = Error;
- qmlInfo(this) << errorString;
+ qmlInfo(this) << d->pix.error();
}
- if (d->status == Loading)
- d->status = Ready;
+
d->progress = 1.0;
emit statusChanged(d->status);
emit progressChanged(1.0);
update();
+
}
}
}
@@ -392,27 +372,17 @@ void QDeclarativeBorderImage::requestFinished()
{
Q_D(QDeclarativeBorderImage);
- QSize impsize;
- if (d->url.path().endsWith(QLatin1String(".sci"))) {
- d->sciPendingPixmapCache = false;
- QString errorString;
- if (QDeclarativePixmapCache::get(d->sciurl, &d->pix, &errorString, &impsize, d->async) != QDeclarativePixmapReply::Ready) {
- d->status = Error;
- qmlInfo(this) << errorString;
- }
+ QSize impsize = d->pix.implicitSize();
+ if (d->pix.isError()) {
+ d->status = Error;
+ qmlInfo(this) << d->pix.error();
} else {
- d->pendingPixmapCache = false;
- QString errorString;
- if (QDeclarativePixmapCache::get(d->url, &d->pix, &errorString, &impsize, d->async) != QDeclarativePixmapReply::Ready) {
- d->status = Error;
- qmlInfo(this) << errorString;
- }
+ d->status = Ready;
}
+
setImplicitWidth(impsize.width());
setImplicitHeight(impsize.height());
- if (d->status == Loading)
- d->status = Ready;
d->progress = 1.0;
emit statusChanged(d->status);
emit progressChanged(1.0);
diff --git a/src/declarative/graphicsitems/qdeclarativeborderimage_p.h b/src/declarative/graphicsitems/qdeclarativeborderimage_p.h
index 07f049e..9944cbe 100644
--- a/src/declarative/graphicsitems/qdeclarativeborderimage_p.h
+++ b/src/declarative/graphicsitems/qdeclarativeborderimage_p.h
@@ -54,7 +54,7 @@ QT_MODULE(Declarative)
class QDeclarativeScaleGrid;
class QDeclarativeGridScaledImage;
class QDeclarativeBorderImagePrivate;
-class Q_DECLARATIVE_EXPORT QDeclarativeBorderImage : public QDeclarativeImageBase
+class Q_AUTOTEST_EXPORT QDeclarativeBorderImage : public QDeclarativeImageBase
{
Q_OBJECT
Q_ENUMS(TileMode)
diff --git a/src/declarative/graphicsitems/qdeclarativeborderimage_p_p.h b/src/declarative/graphicsitems/qdeclarativeborderimage_p_p.h
index 01e4a00..65583d6 100644
--- a/src/declarative/graphicsitems/qdeclarativeborderimage_p_p.h
+++ b/src/declarative/graphicsitems/qdeclarativeborderimage_p_p.h
@@ -66,7 +66,6 @@ class QDeclarativeBorderImagePrivate : public QDeclarativeImageBasePrivate
public:
QDeclarativeBorderImagePrivate()
: border(0), sciReply(0),
- sciPendingPixmapCache(false),
horizontalTileMode(QDeclarativeBorderImage::Stretch),
verticalTileMode(QDeclarativeBorderImage::Stretch),
redirectCount(0)
@@ -97,7 +96,6 @@ public:
QDeclarativeScaleGrid *border;
QUrl sciurl;
QNetworkReply *sciReply;
- bool sciPendingPixmapCache;
QDeclarativeBorderImage::TileMode horizontalTileMode;
QDeclarativeBorderImage::TileMode verticalTileMode;
int redirectCount;
diff --git a/src/declarative/graphicsitems/qdeclarativeflickable.cpp b/src/declarative/graphicsitems/qdeclarativeflickable.cpp
index 3f681b7..9af5f56 100644
--- a/src/declarative/graphicsitems/qdeclarativeflickable.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeflickable.cpp
@@ -122,7 +122,7 @@ void QDeclarativeFlickableVisibleArea::updateVisible()
QDeclarativeFlickablePrivate::QDeclarativeFlickablePrivate()
- : viewport(new QDeclarativeItem)
+ : contentItem(new QDeclarativeItem)
, hData(this, &QDeclarativeFlickablePrivate::setRoundedViewportX)
, vData(this, &QDeclarativeFlickablePrivate::setRoundedViewportY)
, flickingHorizontally(false), flickingVertically(false)
@@ -140,8 +140,8 @@ QDeclarativeFlickablePrivate::QDeclarativeFlickablePrivate()
void QDeclarativeFlickablePrivate::init()
{
Q_Q(QDeclarativeFlickable);
- QDeclarative_setParent_noEvent(viewport, q);
- viewport->setParentItem(q);
+ QDeclarative_setParent_noEvent(contentItem, q);
+ contentItem->setParentItem(q);
static int timelineUpdatedIdx = -1;
static int timelineCompletedIdx = -1;
static int flickableTickedIdx = -1;
@@ -158,7 +158,7 @@ void QDeclarativeFlickablePrivate::init()
q, flickableMovementEndingIdx, Qt::DirectConnection);
q->setAcceptedMouseButtons(Qt::LeftButton);
q->setFiltersChildEvents(true);
- QDeclarativeItemPrivate *viewportPrivate = static_cast<QDeclarativeItemPrivate*>(QGraphicsItemPrivate::get(viewport));
+ QDeclarativeItemPrivate *viewportPrivate = static_cast<QDeclarativeItemPrivate*>(QGraphicsItemPrivate::get(contentItem));
viewportPrivate->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry);
lastPosTime.invalidate();
}
@@ -182,7 +182,7 @@ qreal QDeclarativeFlickablePrivate::overShootDistance(qreal velocity, qreal size
void QDeclarativeFlickablePrivate::itemGeometryChanged(QDeclarativeItem *item, const QRectF &newGeom, const QRectF &oldGeom)
{
Q_Q(QDeclarativeFlickable);
- if (item == viewport) {
+ if (item == contentItem) {
if (newGeom.x() != oldGeom.x())
emit q->contentXChanged();
if (newGeom.y() != oldGeom.y())
@@ -579,10 +579,28 @@ void QDeclarativeFlickable::ticked()
viewportMoved();
}
-QDeclarativeItem *QDeclarativeFlickable::viewport()
+/*!
+ \qmlproperty Item Flickable::contentItem
+
+ The internal item that contains the Items to be moved in the Flickable.
+
+ Items declared as children of a Flickable are automatically parented to the Flickable's contentItem.
+
+ Items created dynamically need to be explicitly parented to the \e contentItem:
+ \code
+ Flickable {
+ id: myFlickable
+ function addItem(file) {
+ var component = Qt.createComponent(file)
+ component.createObject(myFlickable.contentItem);
+ }
+ }
+ \endcode
+*/
+QDeclarativeItem *QDeclarativeFlickable::contentItem()
{
Q_D(QDeclarativeFlickable);
- return d->viewport;
+ return d->contentItem;
}
QDeclarativeFlickableVisibleArea *QDeclarativeFlickable::visibleArea()
@@ -623,18 +641,6 @@ void QDeclarativeFlickable::setFlickableDirection(FlickableDirection direction)
}
}
-QDeclarativeFlickable::FlickableDirection QDeclarativeFlickable::flickDirection() const
-{
- qmlInfo(this) << "'flickDirection' is deprecated. Please use 'flickableDirection' instead.";
- return flickableDirection();
-}
-
-void QDeclarativeFlickable::setFlickDirection(FlickableDirection direction)
-{
- qmlInfo(this) << "'flickDirection' is deprecated. Please use 'flickableDirection' instead.";
- setFlickableDirection(direction);
-}
-
void QDeclarativeFlickablePrivate::handleMousePressEvent(QGraphicsSceneMouseEvent *event)
{
if (interactive && timeline.isActive() && (qAbs(hData.velocity) > 10 || qAbs(vData.velocity) > 10))
@@ -899,12 +905,12 @@ void QDeclarativeFlickablePrivate::clearDelayedPress()
void QDeclarativeFlickablePrivate::setRoundedViewportX(qreal x)
{
- viewport->setX(qRound(x));
+ contentItem->setX(qRound(x));
}
void QDeclarativeFlickablePrivate::setRoundedViewportY(qreal y)
{
- viewport->setY(qRound(y));
+ contentItem->setY(qRound(y));
}
void QDeclarativeFlickable::timerEvent(QTimerEvent *event)
@@ -953,20 +959,19 @@ void QDeclarativeFlickable::viewportMoved()
{
Q_D(QDeclarativeFlickable);
- int elapsed = QDeclarativeItemPrivate::restart(d->velocityTime);
- if (!elapsed)
- return;
-
qreal prevY = d->lastFlickablePosition.x();
qreal prevX = d->lastFlickablePosition.y();
d->velocityTimeline.clear();
if (d->pressed) {
- qreal horizontalVelocity = (prevX - d->hData.move.value()) * 1000 / elapsed;
- qreal verticalVelocity = (prevY - d->vData.move.value()) * 1000 / elapsed;
- d->velocityTimeline.move(d->hData.smoothVelocity, horizontalVelocity, d->reportedVelocitySmoothing);
- d->velocityTimeline.move(d->hData.smoothVelocity, 0, d->reportedVelocitySmoothing);
- d->velocityTimeline.move(d->vData.smoothVelocity, verticalVelocity, d->reportedVelocitySmoothing);
- d->velocityTimeline.move(d->vData.smoothVelocity, 0, d->reportedVelocitySmoothing);
+ int elapsed = QDeclarativeItemPrivate::restart(d->velocityTime);
+ if (elapsed > 0) {
+ qreal horizontalVelocity = (prevX - d->hData.move.value()) * 1000 / elapsed;
+ qreal verticalVelocity = (prevY - d->vData.move.value()) * 1000 / elapsed;
+ d->velocityTimeline.move(d->hData.smoothVelocity, horizontalVelocity, d->reportedVelocitySmoothing);
+ d->velocityTimeline.move(d->hData.smoothVelocity, 0, d->reportedVelocitySmoothing);
+ d->velocityTimeline.move(d->vData.smoothVelocity, verticalVelocity, d->reportedVelocitySmoothing);
+ d->velocityTimeline.move(d->vData.smoothVelocity, 0, d->reportedVelocitySmoothing);
+ }
} else {
if (d->timeline.time() > d->vTime) {
qreal horizontalVelocity = (prevX - d->hData.move.value()) * 1000 / (d->timeline.time() - d->vTime);
@@ -991,13 +996,13 @@ void QDeclarativeFlickable::geometryChanged(const QRectF &newGeometry,
bool changed = false;
if (newGeometry.width() != oldGeometry.width()) {
if (d->hData.viewSize < 0) {
- d->viewport->setWidth(width());
+ d->contentItem->setWidth(width());
emit contentWidthChanged();
}
}
if (newGeometry.height() != oldGeometry.height()) {
if (d->vData.viewSize < 0) {
- d->viewport->setHeight(height());
+ d->contentItem->setHeight(height());
emit contentHeightChanged();
}
}
@@ -1018,7 +1023,7 @@ void QDeclarativeFlickablePrivate::data_append(QDeclarativeListProperty<QObject>
{
QDeclarativeItem *i = qobject_cast<QDeclarativeItem *>(o);
if (i)
- i->setParentItem(static_cast<QDeclarativeFlickablePrivate*>(prop->data)->viewport);
+ i->setParentItem(static_cast<QDeclarativeFlickablePrivate*>(prop->data)->contentItem);
else
o->setParent(prop->object);
}
@@ -1032,7 +1037,7 @@ QDeclarativeListProperty<QObject> QDeclarativeFlickable::flickableData()
QDeclarativeListProperty<QGraphicsObject> QDeclarativeFlickable::flickableChildren()
{
Q_D(QDeclarativeFlickable);
- return QGraphicsItemPrivate::get(d->viewport)->childrenList();
+ return QGraphicsItemPrivate::get(d->contentItem)->childrenList();
}
/*!
@@ -1102,9 +1107,9 @@ void QDeclarativeFlickable::setContentWidth(qreal w)
return;
d->hData.viewSize = w;
if (w < 0)
- d->viewport->setWidth(width());
+ d->contentItem->setWidth(width());
else
- d->viewport->setWidth(w);
+ d->contentItem->setWidth(w);
// Make sure that we're entirely in view.
if (!d->pressed && !d->movingHorizontally && !d->movingVertically) {
int oldDuration = d->fixupDuration;
@@ -1129,9 +1134,9 @@ void QDeclarativeFlickable::setContentHeight(qreal h)
return;
d->vData.viewSize = h;
if (h < 0)
- d->viewport->setHeight(height());
+ d->contentItem->setHeight(height());
else
- d->viewport->setHeight(h);
+ d->contentItem->setHeight(h);
// Make sure that we're entirely in view.
if (!d->pressed && !d->movingHorizontally && !d->movingVertically) {
int oldDuration = d->fixupDuration;
@@ -1337,7 +1342,7 @@ bool QDeclarativeFlickable::isFlickingVertically() const
This property holds the time to delay (ms) delivering a press to
children of the Flickable. This can be useful where reacting
- to a press before a flicking action has undesireable effects.
+ to a press before a flicking action has undesirable effects.
If the flickable is dragged/flicked before the delay times out
the press event will not be delivered. If the button is released
diff --git a/src/declarative/graphicsitems/qdeclarativeflickable_p.h b/src/declarative/graphicsitems/qdeclarativeflickable_p.h
index d40a0dc..44f2bcf 100644
--- a/src/declarative/graphicsitems/qdeclarativeflickable_p.h
+++ b/src/declarative/graphicsitems/qdeclarativeflickable_p.h
@@ -52,7 +52,7 @@ QT_MODULE(Declarative)
class QDeclarativeFlickablePrivate;
class QDeclarativeFlickableVisibleArea;
-class Q_DECLARATIVE_EXPORT QDeclarativeFlickable : public QDeclarativeItem
+class Q_AUTOTEST_EXPORT QDeclarativeFlickable : public QDeclarativeItem
{
Q_OBJECT
@@ -60,6 +60,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativeFlickable : public QDeclarativeItem
Q_PROPERTY(qreal contentHeight READ contentHeight WRITE setContentHeight NOTIFY contentHeightChanged)
Q_PROPERTY(qreal contentX READ contentX WRITE setContentX NOTIFY contentXChanged)
Q_PROPERTY(qreal contentY READ contentY WRITE setContentY NOTIFY contentYChanged)
+ Q_PROPERTY(QDeclarativeItem *contentItem READ contentItem CONSTANT)
Q_PROPERTY(qreal horizontalVelocity READ horizontalVelocity NOTIFY horizontalVelocityChanged)
Q_PROPERTY(qreal verticalVelocity READ verticalVelocity NOTIFY verticalVelocityChanged)
@@ -73,7 +74,6 @@ class Q_DECLARATIVE_EXPORT QDeclarativeFlickable : public QDeclarativeItem
Q_PROPERTY(bool flicking READ isFlicking NOTIFY flickingChanged)
Q_PROPERTY(bool flickingHorizontally READ isFlickingHorizontally NOTIFY flickingHorizontallyChanged)
Q_PROPERTY(bool flickingVertically READ isFlickingVertically NOTIFY flickingVerticallyChanged)
- Q_PROPERTY(FlickableDirection flickDirection READ flickDirection WRITE setFlickDirection NOTIFY flickableDirectionChanged) // deprecated
Q_PROPERTY(FlickableDirection flickableDirection READ flickableDirection WRITE setFlickableDirection NOTIFY flickableDirectionChanged)
Q_PROPERTY(bool interactive READ isInteractive WRITE setInteractive NOTIFY interactiveChanged)
@@ -111,10 +111,10 @@ public:
void setContentHeight(qreal);
qreal contentX() const;
- void setContentX(qreal pos);
+ virtual void setContentX(qreal pos);
qreal contentY() const;
- void setContentY(qreal pos);
+ virtual void setContentY(qreal pos);
bool isMoving() const;
bool isMovingHorizontally() const;
@@ -143,11 +143,9 @@ public:
bool isAtYEnd() const;
bool isAtYBeginning() const;
- QDeclarativeItem *viewport();
+ QDeclarativeItem *contentItem();
enum FlickableDirection { AutoFlickDirection=0x00, HorizontalFlick=0x01, VerticalFlick=0x02, HorizontalAndVerticalFlick=0x03 };
- FlickableDirection flickDirection() const; // deprecated
- void setFlickDirection(FlickableDirection); // deprecated
FlickableDirection flickableDirection() const;
void setFlickableDirection(FlickableDirection);
diff --git a/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h b/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h
index 66d2678..b919e1b 100644
--- a/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h
+++ b/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h
@@ -125,7 +125,7 @@ public:
void itemGeometryChanged(QDeclarativeItem *, const QRectF &, const QRectF &);
public:
- QDeclarativeItem *viewport;
+ QDeclarativeItem *contentItem;
AxisData hData;
AxisData vData;
diff --git a/src/declarative/graphicsitems/qdeclarativeflipable_p.h b/src/declarative/graphicsitems/qdeclarativeflipable_p.h
index fd0119b..78eaf53 100644
--- a/src/declarative/graphicsitems/qdeclarativeflipable_p.h
+++ b/src/declarative/graphicsitems/qdeclarativeflipable_p.h
@@ -55,7 +55,7 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
class QDeclarativeFlipablePrivate;
-class Q_DECLARATIVE_EXPORT QDeclarativeFlipable : public QDeclarativeItem
+class Q_AUTOTEST_EXPORT QDeclarativeFlipable : public QDeclarativeItem
{
Q_OBJECT
diff --git a/src/declarative/graphicsitems/qdeclarativefocuspanel_p.h b/src/declarative/graphicsitems/qdeclarativefocuspanel_p.h
index d9ca0b0..99bd540 100644
--- a/src/declarative/graphicsitems/qdeclarativefocuspanel_p.h
+++ b/src/declarative/graphicsitems/qdeclarativefocuspanel_p.h
@@ -50,7 +50,7 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
-class Q_DECLARATIVE_EXPORT QDeclarativeFocusPanel : public QDeclarativeItem
+class Q_AUTOTEST_EXPORT QDeclarativeFocusPanel : public QDeclarativeItem
{
Q_OBJECT
Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged)
diff --git a/src/declarative/graphicsitems/qdeclarativefocusscope.cpp b/src/declarative/graphicsitems/qdeclarativefocusscope.cpp
index 4bd2a86..e8e6fa2 100644
--- a/src/declarative/graphicsitems/qdeclarativefocusscope.cpp
+++ b/src/declarative/graphicsitems/qdeclarativefocusscope.cpp
@@ -54,6 +54,8 @@ QT_BEGIN_NAMESPACE
Focus scopes assist in keyboard focus handling when building reusable QML
components. All the details are covered in the
\l {qmlfocus}{keyboard focus documentation}.
+
+ \sa {declarative/keyinteraction/focus}{Keyboard focus example}
*/
/*!
diff --git a/src/declarative/graphicsitems/qdeclarativefocusscope_p.h b/src/declarative/graphicsitems/qdeclarativefocusscope_p.h
index c65a07c..363167e 100644
--- a/src/declarative/graphicsitems/qdeclarativefocusscope_p.h
+++ b/src/declarative/graphicsitems/qdeclarativefocusscope_p.h
@@ -51,7 +51,7 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
//### set component root as focusscope
-class Q_DECLARATIVE_EXPORT QDeclarativeFocusScope : public QDeclarativeItem
+class Q_AUTOTEST_EXPORT QDeclarativeFocusScope : public QDeclarativeItem
{
Q_OBJECT
Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeItem)
diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp
index 3792595..dce6f0e 100644
--- a/src/declarative/graphicsitems/qdeclarativegridview.cpp
+++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp
@@ -151,9 +151,9 @@ public:
void setPosition(qreal pos) {
Q_Q(QDeclarativeGridView);
if (flow == QDeclarativeGridView::LeftToRight)
- q->setContentY(pos);
+ q->QDeclarativeFlickable::setContentY(pos);
else
- q->setContentX(pos);
+ q->QDeclarativeFlickable::setContentX(pos);
}
int size() const {
Q_Q(const QDeclarativeGridView);
@@ -421,10 +421,10 @@ FxGridItem *QDeclarativeGridViewPrivate::createItem(int modelIndex)
if (model->completePending()) {
// complete
listItem->item->setZValue(1);
- listItem->item->setParentItem(q->viewport());
+ listItem->item->setParentItem(q->contentItem());
model->completeItem();
} else {
- listItem->item->setParentItem(q->viewport());
+ listItem->item->setParentItem(q->contentItem());
}
unrequestedItems.remove(listItem->item);
}
@@ -716,12 +716,12 @@ void QDeclarativeGridViewPrivate::createHighlight()
}
} else {
item = new QDeclarativeItem;
- QDeclarative_setParent_noEvent(item, q->viewport());
- item->setParentItem(q->viewport());
+ QDeclarative_setParent_noEvent(item, q->contentItem());
+ item->setParentItem(q->contentItem());
}
if (item) {
- QDeclarative_setParent_noEvent(item, q->viewport());
- item->setParentItem(q->viewport());
+ QDeclarative_setParent_noEvent(item, q->contentItem());
+ item->setParentItem(q->contentItem());
highlight = new FxGridItem(item, q);
highlightXAnimator = new QSmoothedAnimation(q);
highlightXAnimator->target = QDeclarativeProperty(highlight->item, QLatin1String("x"));
@@ -808,8 +808,8 @@ void QDeclarativeGridViewPrivate::updateFooter()
delete context;
}
if (item) {
- QDeclarative_setParent_noEvent(item, q->viewport());
- item->setParentItem(q->viewport());
+ QDeclarative_setParent_noEvent(item, q->contentItem());
+ item->setParentItem(q->contentItem());
item->setZValue(1);
QDeclarativeItemPrivate *itemPrivate = static_cast<QDeclarativeItemPrivate*>(QGraphicsItemPrivate::get(item));
itemPrivate->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry);
@@ -854,8 +854,8 @@ void QDeclarativeGridViewPrivate::updateHeader()
delete context;
}
if (item) {
- QDeclarative_setParent_noEvent(item, q->viewport());
- item->setParentItem(q->viewport());
+ QDeclarative_setParent_noEvent(item, q->contentItem());
+ item->setParentItem(q->contentItem());
item->setZValue(1);
QDeclarativeItemPrivate *itemPrivate = static_cast<QDeclarativeItemPrivate*>(QGraphicsItemPrivate::get(item));
itemPrivate->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry);
@@ -1099,6 +1099,8 @@ void QDeclarativeGridViewPrivate::flick(AxisData &data, qreal minExtent, qreal m
is not clipped by another item or the screen, it will be necessary
to set \e {clip: true} in order to have the out of view items clipped
nicely.
+
+ \sa {declarative/modelviews/gridview}{GridView example}
*/
QDeclarativeGridView::QDeclarativeGridView(QDeclarativeItem *parent)
: QDeclarativeFlickable(*(new QDeclarativeGridViewPrivate), parent)
@@ -1214,6 +1216,11 @@ void QDeclarativeGridView::setModel(const QVariant &model)
} else {
d->moveReason = QDeclarativeGridViewPrivate::SetIndex;
d->updateCurrent(d->currentIndex);
+ if (d->highlight && d->currentItem) {
+ d->highlight->setPosition(d->currentItem->colPos(), d->currentItem->rowPos());
+ d->updateTrackedItem();
+ }
+ d->moveReason = QDeclarativeGridViewPrivate::Other;
}
}
connect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int)));
@@ -1272,6 +1279,11 @@ void QDeclarativeGridView::setDelegate(QDeclarativeComponent *delegate)
refill();
d->moveReason = QDeclarativeGridViewPrivate::SetIndex;
d->updateCurrent(d->currentIndex);
+ if (d->highlight && d->currentItem) {
+ d->highlight->setPosition(d->currentItem->colPos(), d->currentItem->rowPos());
+ d->updateTrackedItem();
+ }
+ d->moveReason = QDeclarativeGridViewPrivate::Other;
}
emit delegateChanged();
}
@@ -1298,7 +1310,6 @@ void QDeclarativeGridView::setCurrentIndex(int index)
return;
if (isComponentComplete() && d->isValid() && index != d->currentIndex && index < d->model->count() && index >= 0) {
d->moveReason = QDeclarativeGridViewPrivate::SetIndex;
- cancelFlick();
d->updateCurrent(index);
} else if (index != d->currentIndex) {
d->currentIndex = index;
@@ -1379,7 +1390,7 @@ void QDeclarativeGridView::setHighlight(QDeclarativeComponent *highlight)
highlight is not moved by the view, and any movement must be implemented
by the highlight.
- Here is a highlight with its motion defined by a \l {SpringFollow} item:
+ Here is a highlight with its motion defined by a \l {SpringAnimation} item:
\snippet doc/src/snippets/declarative/gridview/gridview.qml highlightFollowsCurrentItem
*/
@@ -1742,6 +1753,22 @@ void QDeclarativeGridView::setHeader(QDeclarativeComponent *header)
}
}
+void QDeclarativeGridView::setContentX(qreal pos)
+{
+ Q_D(QDeclarativeGridView);
+ // Positioning the view manually should override any current movement state
+ d->moveReason = QDeclarativeGridViewPrivate::Other;
+ QDeclarativeFlickable::setContentX(pos);
+}
+
+void QDeclarativeGridView::setContentY(qreal pos)
+{
+ Q_D(QDeclarativeGridView);
+ // Positioning the view manually should override any current movement state
+ d->moveReason = QDeclarativeGridViewPrivate::Other;
+ QDeclarativeFlickable::setContentY(pos);
+}
+
bool QDeclarativeGridView::event(QEvent *event)
{
Q_D(QDeclarativeGridView);
@@ -1919,6 +1946,8 @@ void QDeclarativeGridView::keyPressEvent(QKeyEvent *event)
Move the currentIndex up one item in the view.
The current index will wrap if keyNavigationWraps is true and it
is currently at the end.
+
+ \bold Note: methods should only be called after the Component has completed.
*/
void QDeclarativeGridView::moveCurrentIndexUp()
{
@@ -1942,6 +1971,8 @@ void QDeclarativeGridView::moveCurrentIndexUp()
Move the currentIndex down one item in the view.
The current index will wrap if keyNavigationWraps is true and it
is currently at the end.
+
+ \bold Note: methods should only be called after the Component has completed.
*/
void QDeclarativeGridView::moveCurrentIndexDown()
{
@@ -1965,6 +1996,8 @@ void QDeclarativeGridView::moveCurrentIndexDown()
Move the currentIndex left one item in the view.
The current index will wrap if keyNavigationWraps is true and it
is currently at the end.
+
+ \bold Note: methods should only be called after the Component has completed.
*/
void QDeclarativeGridView::moveCurrentIndexLeft()
{
@@ -1988,6 +2021,8 @@ void QDeclarativeGridView::moveCurrentIndexLeft()
Move the currentIndex right one item in the view.
The current index will wrap if keyNavigationWraps is true and it
is currently at the end.
+
+ \bold Note: methods should only be called after the Component has completed.
*/
void QDeclarativeGridView::moveCurrentIndexRight()
{
@@ -2028,6 +2063,14 @@ void QDeclarativeGridView::moveCurrentIndexRight()
at a particular index. This is unreliable since removing items from the start
of the view does not cause all other items to be repositioned.
The correct way to bring an item into view is with \c positionViewAtIndex.
+
+ \bold Note: methods should only be called after the Component has completed. To position
+ the view at startup, this method should be called by Component.onCompleted. For
+ example, to position the view at the end:
+
+ \code
+ Component.onCompleted: positionViewAtIndex(count - 1, GridView.Beginning)
+ \endcode
*/
void QDeclarativeGridView::positionViewAtIndex(int index, int mode)
{
@@ -2037,6 +2080,8 @@ void QDeclarativeGridView::positionViewAtIndex(int index, int mode)
if (mode < Beginning || mode > Contain)
return;
+ if (d->layoutScheduled)
+ d->layout();
qreal pos = d->position();
FxGridItem *item = d->visibleItem(index);
if (!item) {
@@ -2079,6 +2124,8 @@ void QDeclarativeGridView::positionViewAtIndex(int index, int mode)
pos = qMin(pos, maxExtent);
qreal minExtent = d->flow == QDeclarativeGridView::LeftToRight ? -minYExtent() : -minXExtent();
pos = qMax(pos, minExtent);
+ d->moveReason = QDeclarativeGridViewPrivate::Other;
+ cancelFlick();
d->setPosition(pos);
}
d->fixupPosition();
@@ -2093,6 +2140,8 @@ void QDeclarativeGridView::positionViewAtIndex(int index, int mode)
If the item is outside the visible area, -1 is returned, regardless of
whether an item will exist at that point when scrolled into view.
+
+ \bold Note: methods should only be called after the Component has completed.
*/
int QDeclarativeGridView::indexAt(int x, int y) const
{
@@ -2113,10 +2162,16 @@ void QDeclarativeGridView::componentComplete()
d->updateGrid();
if (d->isValid()) {
refill();
+ d->moveReason = QDeclarativeGridViewPrivate::SetIndex;
if (d->currentIndex < 0)
d->updateCurrent(0);
else
d->updateCurrent(d->currentIndex);
+ if (d->highlight && d->currentItem) {
+ d->highlight->setPosition(d->currentItem->colPos(), d->currentItem->rowPos());
+ d->updateTrackedItem();
+ }
+ d->moveReason = QDeclarativeGridViewPrivate::Other;
d->fixupPosition();
}
}
@@ -2126,20 +2181,17 @@ void QDeclarativeGridView::trackedPositionChanged()
Q_D(QDeclarativeGridView);
if (!d->trackedItem || !d->currentItem)
return;
- if (!d->flickingHorizontally && !d->flickingVertically && !d->movingHorizontally && !d->movingVertically
- && d->moveReason == QDeclarativeGridViewPrivate::SetIndex) {
+ if (d->moveReason == QDeclarativeGridViewPrivate::SetIndex) {
const qreal trackedPos = d->trackedItem->rowPos();
const qreal viewPos = d->position();
+ qreal pos = viewPos;
if (d->haveHighlightRange) {
if (d->highlightRange == StrictlyEnforceRange) {
- qreal pos = viewPos;
if (trackedPos > pos + d->highlightRangeEnd - d->rowSize())
pos = trackedPos - d->highlightRangeEnd + d->rowSize();
if (trackedPos < pos + d->highlightRangeStart)
pos = trackedPos - d->highlightRangeStart;
- d->setPosition(pos);
} else {
- qreal pos = viewPos;
if (trackedPos < d->startPosition() + d->highlightRangeStart) {
pos = d->startPosition();
} else if (d->trackedItem->endRowPos() > d->endPosition() - d->size() + d->highlightRangeEnd) {
@@ -2153,14 +2205,12 @@ void QDeclarativeGridView::trackedPositionChanged()
pos = trackedPos - d->highlightRangeEnd + d->rowSize();
}
}
- d->setPosition(pos);
}
} else {
if (trackedPos < viewPos && d->currentItem->rowPos() < viewPos) {
- d->setPosition(d->currentItem->rowPos() < trackedPos ? trackedPos : d->currentItem->rowPos());
+ pos = d->currentItem->rowPos() < trackedPos ? trackedPos : d->currentItem->rowPos();
} else if (d->trackedItem->endRowPos() > viewPos + d->size()
&& d->currentItem->endRowPos() > viewPos + d->size()) {
- qreal pos;
if (d->trackedItem->endRowPos() < d->currentItem->endRowPos()) {
pos = d->trackedItem->endRowPos() - d->size();
if (d->rowSize() > d->size())
@@ -2170,9 +2220,12 @@ void QDeclarativeGridView::trackedPositionChanged()
if (d->rowSize() > d->size())
pos = d->currentItem->rowPos();
}
- d->setPosition(pos);
}
}
+ if (viewPos != pos) {
+ cancelFlick();
+ d->setPosition(pos);
+ }
}
}
@@ -2517,6 +2570,12 @@ void QDeclarativeGridView::modelReset()
refill();
d->moveReason = QDeclarativeGridViewPrivate::SetIndex;
d->updateCurrent(d->currentIndex);
+ if (d->highlight && d->currentItem) {
+ d->highlight->setPosition(d->currentItem->colPos(), d->currentItem->rowPos());
+ d->updateTrackedItem();
+ }
+ d->moveReason = QDeclarativeGridViewPrivate::Other;
+
emit countChanged();
}
diff --git a/src/declarative/graphicsitems/qdeclarativegridview_p.h b/src/declarative/graphicsitems/qdeclarativegridview_p.h
index 021aad9..d6bbaf3 100644
--- a/src/declarative/graphicsitems/qdeclarativegridview_p.h
+++ b/src/declarative/graphicsitems/qdeclarativegridview_p.h
@@ -52,7 +52,7 @@ QT_MODULE(Declarative)
class QDeclarativeVisualModel;
class QDeclarativeGridViewAttached;
class QDeclarativeGridViewPrivate;
-class Q_DECLARATIVE_EXPORT QDeclarativeGridView : public QDeclarativeFlickable
+class Q_AUTOTEST_EXPORT QDeclarativeGridView : public QDeclarativeFlickable
{
Q_OBJECT
Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeGridView)
@@ -151,6 +151,9 @@ public:
QDeclarativeComponent *header() const;
void setHeader(QDeclarativeComponent *);
+ virtual void setContentX(qreal pos);
+ virtual void setContentY(qreal pos);
+
enum PositionMode { Beginning, Center, End, Visible, Contain };
Q_INVOKABLE void positionViewAtIndex(int index, int mode);
diff --git a/src/declarative/graphicsitems/qdeclarativeimage.cpp b/src/declarative/graphicsitems/qdeclarativeimage.cpp
index ec08517..34d33f5 100644
--- a/src/declarative/graphicsitems/qdeclarativeimage.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeimage.cpp
@@ -65,18 +65,20 @@ QT_BEGIN_NAMESPACE
Image { source: "qtlogo.png" }
\endqml
\endtable
-
- If a size is not specified explicitly, the Image element is sized to the loaded image.
- Image elements can be stretched and tiled using the \l fillMode property.
- If the image \l source is a network resource, the image is loaded asynchronous and the
- \l progress and \l status properties are updated appropriately. Otherwise, if the image is
- available locally, it is loaded immediately and the user interface is blocked until loading is
- complete. (This is typically the correct behavior for user interface elements.)
- For large local images, which do not need to be visible immediately, it may be preferable to
- enable \l asynchronous loading. This loads the image in the background using a low priority thread.
+ If the \l {Image::width}{width} and \l{Image::height}{height} properties are not specified,
+ the Image element is automatically sized to the loaded image. Image elements can be
+ stretched and tiled using the \l fillMode property.
+
+ By default, locally available images are loaded immediately, and the user interface
+ is blocked until loading is complete. If a large image is to be loaded, it may be
+ preferable to load the image in a low priority thread, by enabling the \l asynchronous
+ property.
- Images are cached and shared internally, so if several Image elements have the same source
+ If the image is from a network rather than a local resource, it is automatically loaded
+ asynchronously, and the \l progress and \l status properties are updated as appropriate.
+
+ Images are cached and shared internally, so if several Image elements have the same \l source,
only one copy of the image will be loaded.
\bold Note: Images are often the greatest user of memory in QML user interfaces. It is recommended
@@ -84,7 +86,7 @@ QT_BEGIN_NAMESPACE
size bounded via the \l sourceSize property. This is especially important for content
that is loaded from external sources or provided by the user.
- \sa {declarative/imageelements/image}{Image example}
+ \sa {declarative/imageelements/image}{Image example}, QDeclarativeImageProvider
*/
/*!
@@ -114,19 +116,10 @@ QDeclarativeImage::~QDeclarativeImage()
{
}
-/*!
- \qmlproperty QPixmap Image::pixmap
-
- This property holds the QPixmap image to display.
-
- This is useful for displaying images provided by a C++ implementation,
- for example, a model may provide a data role of type QPixmap.
-*/
-
QPixmap QDeclarativeImage::pixmap() const
{
Q_D(const QDeclarativeImage);
- return d->pix;
+ return d->pix.pixmap();
}
void QDeclarativeImage::setPixmap(const QPixmap &pix)
@@ -140,7 +133,7 @@ void QDeclarativeImage::setPixmap(const QPixmap &pix)
void QDeclarativeImagePrivate::setPixmap(const QPixmap &pixmap)
{
Q_Q(QDeclarativeImage);
- pix = pixmap;
+ pix.setPixmap(pixmap);
q->setImplicitWidth(pix.width());
q->setImplicitHeight(pix.height());
@@ -199,6 +192,7 @@ void QDeclarativeImagePrivate::setPixmap(const QPixmap &pixmap)
fillMode: Image.PreserveAspectCrop
smooth: true
source: "qtlogo.png"
+ clip: true
}
\endqml
@@ -220,6 +214,7 @@ void QDeclarativeImagePrivate::setPixmap(const QPixmap &pixmap)
Image {
width: 120; height: 120
fillMode: Image.TileVertically
+ smooth: true
source: "qtlogo.png"
}
\endqml
@@ -231,11 +226,14 @@ void QDeclarativeImagePrivate::setPixmap(const QPixmap &pixmap)
Image {
width: 120; height: 120
fillMode: Image.TileHorizontally
+ smooth: true
source: "qtlogo.png"
}
\endqml
\endtable
+
+ \sa {declarative/imageelements/image}{Image example}
*/
QDeclarativeImage::FillMode QDeclarativeImage::fillMode() const
{
@@ -426,7 +424,7 @@ void QDeclarativeImage::geometryChanged(const QRectF &newGeometry, const QRectF
asynchronously in a separate thread. The default value is
false, causing the user interface thread to block while the
image is loaded. Setting \a asynchronous to true is useful where
- maintaining a responsive user interface is more desireable
+ maintaining a responsive user interface is more desirable
than having images immediately visible.
Note that this property is only valid for images read from the
@@ -517,7 +515,6 @@ void QDeclarativeImage::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWi
void QDeclarativeImage::pixmapChange()
{
updatePaintedGeometry();
- emit pixmapChanged();
}
QT_END_NAMESPACE
diff --git a/src/declarative/graphicsitems/qdeclarativeimage_p.h b/src/declarative/graphicsitems/qdeclarativeimage_p.h
index fa5b2a9..c8bb30b 100644
--- a/src/declarative/graphicsitems/qdeclarativeimage_p.h
+++ b/src/declarative/graphicsitems/qdeclarativeimage_p.h
@@ -52,12 +52,11 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
class QDeclarativeImagePrivate;
-class Q_DECLARATIVE_EXPORT QDeclarativeImage : public QDeclarativeImageBase
+class Q_AUTOTEST_EXPORT QDeclarativeImage : public QDeclarativeImageBase
{
Q_OBJECT
Q_ENUMS(FillMode)
- Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap NOTIFY pixmapChanged DESIGNABLE false)
Q_PROPERTY(FillMode fillMode READ fillMode WRITE setFillMode NOTIFY fillModeChanged)
Q_PROPERTY(qreal paintedWidth READ paintedWidth NOTIFY paintedGeometryChanged)
Q_PROPERTY(qreal paintedHeight READ paintedHeight NOTIFY paintedGeometryChanged)
@@ -79,7 +78,6 @@ public:
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
Q_SIGNALS:
- void pixmapChanged();
void fillModeChanged();
void paintedGeometryChanged();
diff --git a/src/declarative/graphicsitems/qdeclarativeimagebase.cpp b/src/declarative/graphicsitems/qdeclarativeimagebase.cpp
index c3f8195..67f2327 100644
--- a/src/declarative/graphicsitems/qdeclarativeimagebase.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeimagebase.cpp
@@ -57,9 +57,6 @@ QDeclarativeImageBase::QDeclarativeImageBase(QDeclarativeImageBasePrivate &dd, Q
QDeclarativeImageBase::~QDeclarativeImageBase()
{
- Q_D(QDeclarativeImageBase);
- if (d->pendingPixmapCache)
- QDeclarativePixmapCache::cancel(d->url, this);
}
QDeclarativeImageBase::Status QDeclarativeImageBase::status() const
@@ -91,7 +88,6 @@ void QDeclarativeImageBase::setAsynchronous(bool async)
}
}
-
QUrl QDeclarativeImageBase::source() const
{
Q_D(const QDeclarativeImageBase);
@@ -105,11 +101,6 @@ void QDeclarativeImageBase::setSource(const QUrl &url)
if ((d->url.isEmpty() == url.isEmpty()) && url == d->url)
return;
- if (d->pendingPixmapCache) {
- QDeclarativePixmapCache::cancel(d->url, this);
- d->pendingPixmapCache = false;
- }
-
d->url = url;
emit sourceChanged(d->url);
@@ -122,6 +113,7 @@ void QDeclarativeImageBase::setSourceSize(const QSize& size)
Q_D(QDeclarativeImageBase);
if (d->sourcesize == size)
return;
+
d->sourcesize = size;
emit sourceSizeChanged();
if (isComponentComplete())
@@ -143,7 +135,7 @@ void QDeclarativeImageBase::load()
}
if (d->url.isEmpty()) {
- d->pix = QPixmap();
+ d->pix.clear();
d->status = Null;
setImplicitWidth(0);
setImplicitHeight(0);
@@ -152,48 +144,37 @@ void QDeclarativeImageBase::load()
update();
} else {
d->status = Loading;
- int reqwidth = d->sourcesize.width();
- int reqheight = d->sourcesize.height();
- QSize impsize;
- QString errorString;
- QDeclarativePixmapReply::Status status = QDeclarativePixmapCache::get(d->url, &d->pix, &errorString, &impsize, d->async, reqwidth, reqheight);
- if (status != QDeclarativePixmapReply::Ready && status != QDeclarativePixmapReply::Error) {
- QDeclarativePixmapReply *reply = QDeclarativePixmapCache::request(qmlEngine(this), d->url, reqwidth, reqheight);
- d->pendingPixmapCache = true;
-
- static int replyDownloadProgress = -1;
- static int replyFinished = -1;
+
+ d->pix.load(qmlEngine(this), d->url, d->sourcesize, d->async);
+
+ if (d->pix.isLoading()) {
+
static int thisRequestProgress = -1;
static int thisRequestFinished = -1;
- if (replyDownloadProgress == -1) {
- replyDownloadProgress =
- QDeclarativePixmapReply::staticMetaObject.indexOfSignal("downloadProgress(qint64,qint64)");
- replyFinished =
- QDeclarativePixmapReply::staticMetaObject.indexOfSignal("finished()");
+ if (thisRequestProgress == -1) {
thisRequestProgress =
QDeclarativeImageBase::staticMetaObject.indexOfSlot("requestProgress(qint64,qint64)");
thisRequestFinished =
QDeclarativeImageBase::staticMetaObject.indexOfSlot("requestFinished()");
}
- QMetaObject::connect(reply, replyFinished, this,
- thisRequestFinished, Qt::DirectConnection);
- QMetaObject::connect(reply, replyDownloadProgress, this,
- thisRequestProgress, Qt::DirectConnection);
+ d->pix.connectFinished(this, thisRequestFinished);
+ d->pix.connectDownloadProgress(this, thisRequestProgress);
+
} else {
- //### should be unified with requestFinished
- if (status == QDeclarativePixmapReply::Ready) {
- setImplicitWidth(impsize.width());
- setImplicitHeight(impsize.height());
+ QSize impsize = d->pix.implicitSize();
+ setImplicitWidth(impsize.width());
+ setImplicitHeight(impsize.height());
- if (d->status == Loading)
- d->status = Ready;
+ if (d->pix.isReady()) {
+ d->status = Ready;
if (!d->sourcesize.isValid())
emit sourceSizeChanged();
+
} else {
d->status = Error;
- qmlInfo(this) << errorString;
+ qmlInfo(this) << d->pix.error();
}
d->progress = 1.0;
emit statusChanged(d->status);
@@ -201,6 +182,7 @@ void QDeclarativeImageBase::load()
pixmapChange();
update();
}
+
}
emit statusChanged(d->status);
@@ -210,14 +192,13 @@ void QDeclarativeImageBase::requestFinished()
{
Q_D(QDeclarativeImageBase);
- d->pendingPixmapCache = false;
+ QSize impsize = d->pix.implicitSize();
- QSize impsize;
- QString errorString;
- if (QDeclarativePixmapCache::get(d->url, &d->pix, &errorString, &impsize, d->async, d->sourcesize.width(), d->sourcesize.height()) != QDeclarativePixmapReply::Ready) {
+ if (d->pix.isError()) {
d->status = Error;
- qmlInfo(this) << errorString;
+ qmlInfo(this) << d->pix.error();
}
+
setImplicitWidth(impsize.width());
setImplicitHeight(impsize.height());
diff --git a/src/declarative/graphicsitems/qdeclarativeimagebase_p.h b/src/declarative/graphicsitems/qdeclarativeimagebase_p.h
index 49b1c58..f5896b1 100644
--- a/src/declarative/graphicsitems/qdeclarativeimagebase_p.h
+++ b/src/declarative/graphicsitems/qdeclarativeimagebase_p.h
@@ -49,7 +49,7 @@ QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
class QDeclarativeImageBasePrivate;
-class Q_DECLARATIVE_EXPORT QDeclarativeImageBase : public QDeclarativeItem
+class Q_AUTOTEST_EXPORT QDeclarativeImageBase : public QDeclarativeItem
{
Q_OBJECT
Q_ENUMS(Status)
diff --git a/src/declarative/graphicsitems/qdeclarativeimagebase_p_p.h b/src/declarative/graphicsitems/qdeclarativeimagebase_p_p.h
index 392c1db..aee8b28 100644
--- a/src/declarative/graphicsitems/qdeclarativeimagebase_p_p.h
+++ b/src/declarative/graphicsitems/qdeclarativeimagebase_p_p.h
@@ -54,6 +54,7 @@
//
#include "private/qdeclarativeitem_p.h"
+#include "private/qdeclarativepixmapcache_p.h"
#include <QtCore/QPointer>
@@ -68,18 +69,16 @@ public:
QDeclarativeImageBasePrivate()
: status(QDeclarativeImageBase::Null),
progress(0.0),
- pendingPixmapCache(false),
async(false)
{
QGraphicsItemPrivate::flags = QGraphicsItemPrivate::flags & ~QGraphicsItem::ItemHasNoContents;
}
- QPixmap pix;
+ QDeclarativePixmap pix;
QDeclarativeImageBase::Status status;
QUrl url;
qreal progress;
QSize sourcesize;
- bool pendingPixmapCache : 1;
bool async : 1;
};
diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp
index 336010f..f5ea537 100644
--- a/src/declarative/graphicsitems/qdeclarativeitem.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp
@@ -149,7 +149,7 @@ QT_BEGIN_NAMESPACE
}
\endqml
- \sa Rotate, Translate
+ \sa Rotation, Translate
*/
/*!
@@ -196,6 +196,8 @@ QT_BEGIN_NAMESPACE
\snippet doc/src/snippets/declarative/rotation.qml 0
\image axisrotation.png
+
+ \sa {declarative/ui-components/dialcontrol}{Dial Control example}, {declarative/toys/clocks}{Clocks example}
*/
/*!
@@ -345,6 +347,7 @@ void QDeclarativeContents::complete()
void QDeclarativeContents::itemGeometryChanged(QDeclarativeItem *changed, const QRectF &newGeometry, const QRectF &oldGeometry)
{
+ Q_UNUSED(changed)
//### we can only pass changed if the left edge has moved left, or the right edge has moved right
if (newGeometry.width() != oldGeometry.width() || newGeometry.x() != oldGeometry.x())
calcWidth(/*changed*/);
@@ -1598,7 +1601,7 @@ QDeclarativeItem *QDeclarativeItem::parentItem() const
Returns true if construction of the QML component is complete; otherwise
returns false.
- It is often desireable to delay some processing until the component is
+ It is often desirable to delay some processing until the component is
completed.
\sa componentComplete()
@@ -2142,7 +2145,7 @@ QDeclarativeAnchorLine QDeclarativeItemPrivate::baseline() const
\property QDeclarativeItem::baselineOffset
\brief The position of the item's baseline in local coordinates.
- The baseline of a Text item is the imaginary line on which the text
+ The baseline of a \l Text item is the imaginary line on which the text
sits. Controls containing text usually set their baseline to the
baseline of their text.
@@ -2598,7 +2601,7 @@ void QDeclarativeItem::classBegin()
\internal
componentComplete() is called when all items in the component
- have been constructed. It is often desireable to delay some
+ have been constructed. It is often desirable to delay some
processing until the component is complete an all bindings in the
component have been resolved.
*/
diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp
index 06a3239..91e9995 100644
--- a/src/declarative/graphicsitems/qdeclarativelistview.cpp
+++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp
@@ -105,7 +105,7 @@ public:
else
return (view->orientation() == QDeclarativeListView::Vertical ? item->y() : item->x());
}
- int size() const {
+ qreal size() const {
if (section)
return (view->orientation() == QDeclarativeListView::Vertical ? item->height()+section->height() : item->width()+section->height());
else
@@ -216,9 +216,9 @@ public:
void setPosition(qreal pos) {
Q_Q(QDeclarativeListView);
if (orient == QDeclarativeListView::Vertical)
- q->setContentY(pos);
+ q->QDeclarativeFlickable::setContentY(pos);
else
- q->setContentX(pos);
+ q->QDeclarativeFlickable::setContentX(pos);
}
qreal size() const {
Q_Q(const QDeclarativeListView);
@@ -421,7 +421,7 @@ public:
void itemGeometryChanged(QDeclarativeItem *item, const QRectF &newGeometry, const QRectF &oldGeometry) {
Q_Q(QDeclarativeListView);
QDeclarativeFlickablePrivate::itemGeometryChanged(item, newGeometry, oldGeometry);
- if (item != viewport && (!highlight || item != highlight->item)) {
+ if (item != contentItem && (!highlight || item != highlight->item)) {
if ((orient == QDeclarativeListView::Vertical && newGeometry.height() != oldGeometry.height())
|| (orient == QDeclarativeListView::Horizontal && newGeometry.width() != oldGeometry.width())) {
scheduleLayout();
@@ -476,7 +476,7 @@ public:
QHash<QDeclarativeItem*,int> unrequestedItems;
FxListItem *currentItem;
QDeclarativeListView::Orientation orient;
- int visiblePos;
+ qreal visiblePos;
int visibleIndex;
qreal averageSize;
int currentIndex;
@@ -575,15 +575,19 @@ FxListItem *QDeclarativeListViewPrivate::createItem(int modelIndex)
listItem->attached->m_prevSection = item->attached->section();
else
listItem->attached->m_prevSection = sectionAt(modelIndex-1);
+ if (FxListItem *item = visibleItem(modelIndex+1))
+ listItem->attached->m_nextSection = item->attached->section();
+ else
+ listItem->attached->m_nextSection = sectionAt(modelIndex+1);
}
}
if (model->completePending()) {
// complete
listItem->item->setZValue(1);
- listItem->item->setParentItem(q->viewport());
+ listItem->item->setParentItem(q->contentItem());
model->completeItem();
} else {
- listItem->item->setParentItem(q->viewport());
+ listItem->item->setParentItem(q->contentItem());
}
QDeclarativeItemPrivate *itemPrivate = static_cast<QDeclarativeItemPrivate*>(QGraphicsItemPrivate::get(item));
itemPrivate->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry);
@@ -655,7 +659,7 @@ void QDeclarativeListViewPrivate::refill(qreal from, qreal to, bool doBuffer)
bool changed = false;
FxListItem *item = 0;
- int pos = itemEnd + 1;
+ qreal pos = itemEnd + 1;
while (modelIndex < model->count() && pos <= fillTo) {
// qDebug() << "refill: append item" << modelIndex << "pos" << pos;
if (!(item = createItem(modelIndex)))
@@ -744,8 +748,8 @@ void QDeclarativeListViewPrivate::layout()
}
updateSections();
if (!visibleItems.isEmpty()) {
- int oldEnd = visibleItems.last()->endPosition();
- int pos = visibleItems.first()->endPosition() + spacing + 1;
+ qreal oldEnd = visibleItems.last()->endPosition();
+ qreal pos = visibleItems.first()->endPosition() + spacing + 1;
for (int i=1; i < visibleItems.count(); ++i) {
FxListItem *item = visibleItems.at(i);
item->setPosition(pos);
@@ -840,8 +844,8 @@ void QDeclarativeListViewPrivate::createHighlight()
item = new QDeclarativeItem;
}
if (item) {
- QDeclarative_setParent_noEvent(item, q->viewport());
- item->setParentItem(q->viewport());
+ QDeclarative_setParent_noEvent(item, q->contentItem());
+ item->setParentItem(q->contentItem());
highlight = new FxListItem(item, q);
if (currentItem && autoHighlight) {
if (orient == QDeclarativeListView::Vertical) {
@@ -921,8 +925,8 @@ void QDeclarativeListViewPrivate::createSection(FxListItem *listItem)
delete nobj;
} else {
listItem->section->setZValue(1);
- QDeclarative_setParent_noEvent(listItem->section, q->viewport());
- listItem->section->setParentItem(q->viewport());
+ QDeclarative_setParent_noEvent(listItem->section, q->contentItem());
+ listItem->section->setParentItem(q->contentItem());
}
} else {
delete context;
@@ -951,14 +955,26 @@ void QDeclarativeListViewPrivate::updateSections()
QString prevSection;
if (visibleIndex > 0)
prevSection = sectionAt(visibleIndex-1);
+ QDeclarativeListViewAttached *prevAtt = 0;
+ int idx = -1;
for (int i = 0; i < visibleItems.count(); ++i) {
if (visibleItems.at(i)->index != -1) {
QDeclarativeListViewAttached *attached = visibleItems.at(i)->attached;
attached->setPrevSection(prevSection);
+ if (prevAtt)
+ prevAtt->setNextSection(attached->section());
createSection(visibleItems.at(i));
prevSection = attached->section();
+ prevAtt = attached;
+ idx = visibleItems.at(i)->index;
}
}
+ if (prevAtt) {
+ if (idx > 0 && idx < model->count()-1)
+ prevAtt->setNextSection(sectionAt(idx+1));
+ else
+ prevAtt->setNextSection(QString());
+ }
}
}
@@ -1027,7 +1043,7 @@ void QDeclarativeListViewPrivate::updateAverage()
qreal sum = 0.0;
for (int i = 0; i < visibleItems.count(); ++i)
sum += visibleItems.at(i)->size();
- averageSize = sum / visibleItems.count();
+ averageSize = qRound(sum / visibleItems.count());
}
void QDeclarativeListViewPrivate::updateFooter()
@@ -1046,8 +1062,8 @@ void QDeclarativeListViewPrivate::updateFooter()
delete context;
}
if (item) {
- QDeclarative_setParent_noEvent(item, q->viewport());
- item->setParentItem(q->viewport());
+ QDeclarative_setParent_noEvent(item, q->contentItem());
+ item->setParentItem(q->contentItem());
item->setZValue(1);
QDeclarativeItemPrivate *itemPrivate = static_cast<QDeclarativeItemPrivate*>(QGraphicsItemPrivate::get(item));
itemPrivate->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry);
@@ -1086,8 +1102,8 @@ void QDeclarativeListViewPrivate::updateHeader()
delete context;
}
if (item) {
- QDeclarative_setParent_noEvent(item, q->viewport());
- item->setParentItem(q->viewport());
+ QDeclarative_setParent_noEvent(item, q->contentItem());
+ item->setParentItem(q->contentItem());
item->setZValue(1);
QDeclarativeItemPrivate *itemPrivate = static_cast<QDeclarativeItemPrivate*>(QGraphicsItemPrivate::get(item));
itemPrivate->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry);
@@ -1379,7 +1395,7 @@ void QDeclarativeListViewPrivate::flick(AxisData &data, qreal minExtent, qreal m
to set \e {clip: true} in order to have the out of view items clipped
nicely.
- \sa ListModel, GridView, {declarative/modelviews/listview}{ListView examples}
+ \sa {Data Models}, GridView, {declarative/modelviews/listview}{ListView examples}
*/
QDeclarativeListView::QDeclarativeListView(QDeclarativeItem *parent)
@@ -1418,7 +1434,7 @@ QDeclarativeListView::~QDeclarativeListView()
*/
/*!
- \qmlattachedproperty string ListView::prevSection
+ \qmlattachedproperty string ListView::previousSection
This attached property holds the section of the previous element.
It is attached to each instance of the delegate.
@@ -1427,6 +1443,15 @@ QDeclarativeListView::~QDeclarativeListView()
*/
/*!
+ \qmlattachedproperty string ListView::nextSection
+ This attached property holds the section of the next element.
+
+ It is attached to each instance of the delegate.
+
+ The section is evaluated using the \l {ListView::section.property}{section} properties.
+*/
+
+/*!
\qmlattachedproperty string ListView::section
This attached property holds the section of this element.
@@ -1522,6 +1547,10 @@ void QDeclarativeListView::setModel(const QVariant &model)
} else {
d->moveReason = QDeclarativeListViewPrivate::SetIndex;
d->updateCurrent(d->currentIndex);
+ if (d->highlight && d->currentItem) {
+ d->highlight->setPosition(d->currentItem->position());
+ d->updateTrackedItem();
+ }
}
}
connect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int)));
@@ -1547,9 +1576,12 @@ void QDeclarativeListView::setModel(const QVariant &model)
that is not needed for the normal display of the delegate in a \l Loader which
can load additional elements when needed.
- Tthe ListView will lay out the items based on the size of the root item
+ The ListView will lay out the items based on the size of the root item
in the delegate.
+ It is recommended that the delagate's size be a whole number to avoid sub-pixel
+ alignment of items.
+
\note Delegates are instantiated as needed and may be destroyed at any time.
State should \e never be stored in a delegate.
*/
@@ -1582,6 +1614,10 @@ void QDeclarativeListView::setDelegate(QDeclarativeComponent *delegate)
refill();
d->moveReason = QDeclarativeListViewPrivate::SetIndex;
d->updateCurrent(d->currentIndex);
+ if (d->highlight && d->currentItem) {
+ d->highlight->setPosition(d->currentItem->position());
+ d->updateTrackedItem();
+ }
}
}
emit delegateChanged();
@@ -1608,7 +1644,6 @@ void QDeclarativeListView::setCurrentIndex(int index)
return;
if (isComponentComplete() && d->isValid() && index != d->currentIndex && index < d->model->count() && index >= 0) {
d->moveReason = QDeclarativeListViewPrivate::SetIndex;
- cancelFlick();
d->updateCurrent(index);
} else if (index != d->currentIndex) {
d->currentIndex = index;
@@ -1692,7 +1727,7 @@ void QDeclarativeListView::setHighlight(QDeclarativeComponent *highlight)
highlight is not moved by the view, and any movement must be implemented
by the highlight.
- Here is a highlight with its motion defined by a \l {SpringFollow} item:
+ Here is a highlight with its motion defined by a \l {SpringAniamtion} item:
\snippet doc/src/snippets/declarative/listview/listview.qml highlightFollowsCurrentItem
@@ -1960,9 +1995,9 @@ void QDeclarativeListView::setCacheBuffer(int b)
\c section.delegate holds the delegate component for each section.
- Each item in the list has attached properties named \c ListView.section and
- \c ListView.prevSection. These may be used to place a section header for
- related items.
+ Each item in the list has attached properties named \c ListView.section,
+ \c ListView.previousSection and \c ListView.nextSection. These may be
+ used to place a section header for related items.
For example, here is a ListView that displays a list of animals, separated
into sections. Each item in the ListView is placed in a different section
@@ -2182,6 +2217,22 @@ void QDeclarativeListView::setHeader(QDeclarativeComponent *header)
}
}
+void QDeclarativeListView::setContentX(qreal pos)
+{
+ Q_D(QDeclarativeListView);
+ // Positioning the view manually should override any current movement state
+ d->moveReason = QDeclarativeListViewPrivate::Other;
+ QDeclarativeFlickable::setContentX(pos);
+}
+
+void QDeclarativeListView::setContentY(qreal pos)
+{
+ Q_D(QDeclarativeListView);
+ // Positioning the view manually should override any current movement state
+ d->moveReason = QDeclarativeListViewPrivate::Other;
+ QDeclarativeFlickable::setContentY(pos);
+}
+
bool QDeclarativeListView::event(QEvent *event)
{
Q_D(QDeclarativeListView);
@@ -2386,6 +2437,8 @@ void QDeclarativeListView::keyPressEvent(QKeyEvent *event)
Increments the current index. The current index will wrap
if keyNavigationWraps is true and it is currently at the end.
+
+ \bold Note: methods should only be called after the Component has completed.
*/
void QDeclarativeListView::incrementCurrentIndex()
{
@@ -2393,7 +2446,6 @@ void QDeclarativeListView::incrementCurrentIndex()
if (currentIndex() < d->model->count() - 1 || d->wrap) {
d->moveReason = QDeclarativeListViewPrivate::SetIndex;
int index = currentIndex()+1;
- cancelFlick();
d->updateCurrent(index < d->model->count() ? index : 0);
}
}
@@ -2403,6 +2455,8 @@ void QDeclarativeListView::incrementCurrentIndex()
Decrements the current index. The current index will wrap
if keyNavigationWraps is true and it is currently at the beginning.
+
+ \bold Note: methods should only be called after the Component has completed.
*/
void QDeclarativeListView::decrementCurrentIndex()
{
@@ -2410,7 +2464,6 @@ void QDeclarativeListView::decrementCurrentIndex()
if (currentIndex() > 0 || d->wrap) {
d->moveReason = QDeclarativeListViewPrivate::SetIndex;
int index = currentIndex()-1;
- cancelFlick();
d->updateCurrent(index >= 0 ? index : d->model->count()-1);
}
}
@@ -2439,6 +2492,14 @@ void QDeclarativeListView::decrementCurrentIndex()
of the list does not cause all other items to be repositioned, and because
the actual start of the view can vary based on the size of the delegates.
The correct way to bring an item into view is with \c positionViewAtIndex.
+
+ \bold Note: methods should only be called after the Component has completed. To position
+ the view at startup, this method should be called by Component.onCompleted. For
+ example, to position the view at the end:
+
+ \code
+ Component.onCompleted: positionViewAtIndex(count - 1, ListView.Beginning)
+ \endcode
*/
void QDeclarativeListView::positionViewAtIndex(int index, int mode)
{
@@ -2448,6 +2509,8 @@ void QDeclarativeListView::positionViewAtIndex(int index, int mode)
if (mode < Beginning || mode > Contain)
return;
+ if (d->layoutScheduled)
+ d->layout();
qreal pos = d->position();
FxListItem *item = d->visibleItem(index);
if (!item) {
@@ -2491,6 +2554,8 @@ void QDeclarativeListView::positionViewAtIndex(int index, int mode)
pos = qMin(pos, maxExtent);
qreal minExtent = d->orient == QDeclarativeListView::Vertical ? -minYExtent() : -minXExtent();
pos = qMax(pos, minExtent);
+ d->moveReason = QDeclarativeListViewPrivate::Other;
+ cancelFlick();
d->setPosition(pos);
}
d->fixupPosition();
@@ -2505,6 +2570,8 @@ void QDeclarativeListView::positionViewAtIndex(int index, int mode)
If the item is outside the visible area, -1 is returned, regardless of
whether an item will exist at that point when scrolled into view.
+
+ \bold Note: methods should only be called after the Component has completed.
*/
int QDeclarativeListView::indexAt(int x, int y) const
{
@@ -2529,6 +2596,11 @@ void QDeclarativeListView::componentComplete()
d->updateCurrent(0);
else
d->updateCurrent(d->currentIndex);
+ if (d->highlight && d->currentItem) {
+ d->highlight->setPosition(d->currentItem->position());
+ d->updateTrackedItem();
+ }
+ d->moveReason = QDeclarativeListViewPrivate::Other;
d->fixupPosition();
}
}
@@ -2544,20 +2616,17 @@ void QDeclarativeListView::trackedPositionChanged()
Q_D(QDeclarativeListView);
if (!d->trackedItem || !d->currentItem)
return;
- if (!d->flickingHorizontally && !d->flickingVertically && !d->movingHorizontally && !d->movingVertically
- && d->moveReason == QDeclarativeListViewPrivate::SetIndex) {
+ if (d->moveReason == QDeclarativeListViewPrivate::SetIndex) {
const qreal trackedPos = qCeil(d->trackedItem->position());
const qreal viewPos = d->position();
+ qreal pos = viewPos;
if (d->haveHighlightRange) {
if (d->highlightRange == StrictlyEnforceRange) {
- qreal pos = viewPos;
if (trackedPos > pos + d->highlightRangeEnd - d->trackedItem->size())
pos = trackedPos - d->highlightRangeEnd + d->trackedItem->size();
if (trackedPos < pos + d->highlightRangeStart)
pos = trackedPos - d->highlightRangeStart;
- d->setPosition(pos);
} else {
- qreal pos = viewPos;
if (trackedPos < d->startPosition() + d->highlightRangeStart) {
pos = d->startPosition();
} else if (d->trackedItem->endPosition() > d->endPosition() - d->size() + d->highlightRangeEnd) {
@@ -2571,14 +2640,12 @@ void QDeclarativeListView::trackedPositionChanged()
pos = trackedPos - d->highlightRangeEnd + d->trackedItem->size();
}
}
- d->setPosition(pos);
}
} else {
if (trackedPos < viewPos && d->currentItem->position() < viewPos) {
- d->setPosition(d->currentItem->position() < trackedPos ? trackedPos : d->currentItem->position());
+ pos = d->currentItem->position() < trackedPos ? trackedPos : d->currentItem->position();
} else if (d->trackedItem->endPosition() > viewPos + d->size()
&& d->currentItem->endPosition() > viewPos + d->size()) {
- qreal pos;
if (d->trackedItem->endPosition() < d->currentItem->endPosition()) {
pos = d->trackedItem->endPosition() - d->size();
if (d->trackedItem->size() > d->size())
@@ -2588,9 +2655,12 @@ void QDeclarativeListView::trackedPositionChanged()
if (d->currentItem->size() > d->size())
pos = d->currentItem->position();
}
- d->setPosition(pos);
}
}
+ if (viewPos != pos) {
+ cancelFlick();
+ d->setPosition(pos);
+ }
}
}
@@ -2954,6 +3024,11 @@ void QDeclarativeListView::modelReset()
refill();
d->moveReason = QDeclarativeListViewPrivate::SetIndex;
d->updateCurrent(d->currentIndex);
+ if (d->highlight && d->currentItem) {
+ d->highlight->setPosition(d->currentItem->position());
+ d->updateTrackedItem();
+ }
+ d->moveReason = QDeclarativeListViewPrivate::Other;
emit countChanged();
}
@@ -2961,7 +3036,7 @@ void QDeclarativeListView::createdItem(int index, QDeclarativeItem *item)
{
Q_D(QDeclarativeListView);
if (d->requestedIndex != index) {
- item->setParentItem(viewport());
+ item->setParentItem(contentItem());
d->unrequestedItems.insert(item, index);
if (d->orient == QDeclarativeListView::Vertical)
item->setY(d->positionAt(index));
diff --git a/src/declarative/graphicsitems/qdeclarativelistview_p.h b/src/declarative/graphicsitems/qdeclarativelistview_p.h
index d6e8023..9941040 100644
--- a/src/declarative/graphicsitems/qdeclarativelistview_p.h
+++ b/src/declarative/graphicsitems/qdeclarativelistview_p.h
@@ -50,7 +50,7 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
-class Q_DECLARATIVE_EXPORT QDeclarativeViewSection : public QObject
+class Q_AUTOTEST_EXPORT QDeclarativeViewSection : public QObject
{
Q_OBJECT
Q_PROPERTY(QString property READ property WRITE setProperty NOTIFY changed)
@@ -86,7 +86,7 @@ private:
class QDeclarativeVisualModel;
class QDeclarativeListViewAttached;
class QDeclarativeListViewPrivate;
-class Q_DECLARATIVE_EXPORT QDeclarativeListView : public QDeclarativeFlickable
+class Q_AUTOTEST_EXPORT QDeclarativeListView : public QDeclarativeFlickable
{
Q_OBJECT
Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeListView)
@@ -198,6 +198,9 @@ public:
QDeclarativeComponent *header() const;
void setHeader(QDeclarativeComponent *);
+ virtual void setContentX(qreal pos);
+ virtual void setContentY(qreal pos);
+
static QDeclarativeListViewAttached *qmlAttachedProperties(QObject *);
enum PositionMode { Beginning, Center, End, Visible, Contain };
@@ -276,7 +279,7 @@ public:
}
}
- Q_PROPERTY(QString prevSection READ prevSection NOTIFY prevSectionChanged)
+ Q_PROPERTY(QString previousSection READ prevSection NOTIFY prevSectionChanged)
QString prevSection() const { return m_prevSection; }
void setPrevSection(const QString &sect) {
if (m_prevSection != sect) {
@@ -285,6 +288,15 @@ public:
}
}
+ Q_PROPERTY(QString nextSection READ nextSection NOTIFY nextSectionChanged)
+ QString nextSection() const { return m_nextSection; }
+ void setNextSection(const QString &sect) {
+ if (m_nextSection != sect) {
+ m_nextSection = sect;
+ emit nextSectionChanged();
+ }
+ }
+
Q_PROPERTY(QString section READ section NOTIFY sectionChanged)
QString section() const { return m_section; }
void setSection(const QString &sect) {
@@ -310,6 +322,7 @@ Q_SIGNALS:
void currentItemChanged();
void sectionChanged();
void prevSectionChanged();
+ void nextSectionChanged();
void delayRemoveChanged();
void add();
void remove();
@@ -318,6 +331,7 @@ public:
QDeclarativeListView *m_view;
mutable QString m_section;
QString m_prevSection;
+ QString m_nextSection;
bool m_isCurrent : 1;
bool m_delayRemove : 1;
};
diff --git a/src/declarative/graphicsitems/qdeclarativeloader.cpp b/src/declarative/graphicsitems/qdeclarativeloader.cpp
index 25b1119..e745ca6 100644
--- a/src/declarative/graphicsitems/qdeclarativeloader.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeloader.cpp
@@ -119,7 +119,7 @@ void QDeclarativeLoaderPrivate::initResize()
property, or loaded from a URL via the \l source property.
Loader can be used to delay the creation of a component until it is required.
- For example, this loads "Page1.qml" as a component into the \l Loader element
+ For example, this loads "Page1.qml" as a component into the Loader element
when the \l MouseArea is clicked:
\code
@@ -174,7 +174,7 @@ void QDeclarativeLoaderPrivate::initResize()
QDeclarativeLoader::QDeclarativeLoader(QDeclarativeItem *parent)
: QDeclarativeItem(*(new QDeclarativeLoaderPrivate), parent)
{
- Q_D(QDeclarativeItem);
+ Q_D(QDeclarativeLoader);
d->flags |= QGraphicsItem::ItemIsFocusScope;
}
@@ -183,6 +183,14 @@ QDeclarativeLoader::QDeclarativeLoader(QDeclarativeItem *parent)
*/
QDeclarativeLoader::~QDeclarativeLoader()
{
+ Q_D(QDeclarativeLoader);
+ if (d->item) {
+ if (QDeclarativeItem *qmlItem = qobject_cast<QDeclarativeItem*>(d->item)) {
+ QDeclarativeItemPrivate *p =
+ static_cast<QDeclarativeItemPrivate *>(QGraphicsItemPrivate::get(qmlItem));
+ p->removeItemChangeListener(d, QDeclarativeItemPrivate::Geometry);
+ }
+ }
}
/*!
diff --git a/src/declarative/graphicsitems/qdeclarativeloader_p.h b/src/declarative/graphicsitems/qdeclarativeloader_p.h
index ec7ffe9..d63eaf7 100644
--- a/src/declarative/graphicsitems/qdeclarativeloader_p.h
+++ b/src/declarative/graphicsitems/qdeclarativeloader_p.h
@@ -51,7 +51,7 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
class QDeclarativeLoaderPrivate;
-class Q_DECLARATIVE_EXPORT QDeclarativeLoader : public QDeclarativeItem
+class Q_AUTOTEST_EXPORT QDeclarativeLoader : public QDeclarativeItem
{
Q_OBJECT
Q_ENUMS(Status)
diff --git a/src/declarative/graphicsitems/qdeclarativemousearea.cpp b/src/declarative/graphicsitems/qdeclarativemousearea.cpp
index 0bed41b..7b65ca7 100644
--- a/src/declarative/graphicsitems/qdeclarativemousearea.cpp
+++ b/src/declarative/graphicsitems/qdeclarativemousearea.cpp
@@ -192,7 +192,7 @@ QDeclarativeMouseAreaPrivate::~QDeclarativeMouseAreaPrivate()
MouseArea is an invisible item: it is never painted.
- \sa MouseEvent
+ \sa MouseEvent, {declarative/touchinteraction/mousearea}{MouseArea example}
*/
/*!
@@ -443,7 +443,7 @@ void QDeclarativeMouseArea::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
QPointF startLocalPos;
QPointF curLocalPos;
- if (drag()->target()->parent()) {
+ if (drag()->target()->parentItem()) {
startLocalPos = drag()->target()->parentItem()->mapFromScene(d->startScene);
curLocalPos = drag()->target()->parentItem()->mapFromScene(event->scenePos());
} else {
@@ -761,7 +761,7 @@ QDeclarativeDrag *QDeclarativeMouseArea::drag()
\c drag provides a convenient way to make an item draggable.
\list
- \i \c drag.target specifies the item to drag.
+ \i \c drag.target specifies the id of the item to drag.
\i \c drag.active specifies if the target item is currently being dragged.
\i \c drag.axis specifies whether dragging can be done horizontally (\c Drag.XAxis), vertically (\c Drag.YAxis), or both (\c Drag.XandYAxis)
\i \c drag.minimum and \c drag.maximum limit how far the target can be dragged along the corresponding axes.
diff --git a/src/declarative/graphicsitems/qdeclarativemousearea_p.h b/src/declarative/graphicsitems/qdeclarativemousearea_p.h
index df77ac6..4fe3fcb 100644
--- a/src/declarative/graphicsitems/qdeclarativemousearea_p.h
+++ b/src/declarative/graphicsitems/qdeclarativemousearea_p.h
@@ -50,7 +50,7 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
-class Q_DECLARATIVE_EXPORT QDeclarativeDrag : public QObject
+class Q_AUTOTEST_EXPORT QDeclarativeDrag : public QObject
{
Q_OBJECT
@@ -110,7 +110,7 @@ private:
class QDeclarativeMouseEvent;
class QDeclarativeMouseAreaPrivate;
-class Q_DECLARATIVE_EXPORT QDeclarativeMouseArea : public QDeclarativeItem
+class Q_AUTOTEST_EXPORT QDeclarativeMouseArea : public QDeclarativeItem
{
Q_OBJECT
diff --git a/src/declarative/graphicsitems/qdeclarativepainteditem.cpp b/src/declarative/graphicsitems/qdeclarativepainteditem.cpp
index 13d1b61..3b9b8df 100644
--- a/src/declarative/graphicsitems/qdeclarativepainteditem.cpp
+++ b/src/declarative/graphicsitems/qdeclarativepainteditem.cpp
@@ -151,6 +151,7 @@ void QDeclarativePaintedItem::setContentsSize(const QSize &size)
{
Q_D(QDeclarativePaintedItem);
if (d->contentsSize == size) return;
+ prepareGeometryChange();
d->contentsSize = size;
clearCache();
update();
@@ -247,8 +248,7 @@ QRectF QDeclarativePaintedItem::boundingRect() const
void QDeclarativePaintedItem::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *)
{
Q_D(QDeclarativePaintedItem);
- const QRect content(0,0,qCeil(d->contentsSize.width()*d->contentsScale),
- qCeil(d->contentsSize.height()*d->contentsScale));
+ const QRect content = boundingRect().toRect();
if (content.width() <= 0 || content.height() <= 0)
return;
diff --git a/src/declarative/graphicsitems/qdeclarativepainteditem_p.h b/src/declarative/graphicsitems/qdeclarativepainteditem_p.h
index 86f065a..8142986 100644
--- a/src/declarative/graphicsitems/qdeclarativepainteditem_p.h
+++ b/src/declarative/graphicsitems/qdeclarativepainteditem_p.h
@@ -51,7 +51,7 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
class QDeclarativePaintedItemPrivate;
-class Q_DECLARATIVE_EXPORT QDeclarativePaintedItem : public QDeclarativeItem
+class Q_AUTOTEST_EXPORT QDeclarativePaintedItem : public QDeclarativeItem
{
Q_OBJECT
diff --git a/src/declarative/graphicsitems/qdeclarativepath_p.h b/src/declarative/graphicsitems/qdeclarativepath_p.h
index dad43e6..001bcdf 100644
--- a/src/declarative/graphicsitems/qdeclarativepath_p.h
+++ b/src/declarative/graphicsitems/qdeclarativepath_p.h
@@ -54,7 +54,7 @@ QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
-class Q_DECLARATIVE_EXPORT QDeclarativePathElement : public QObject
+class Q_AUTOTEST_EXPORT QDeclarativePathElement : public QObject
{
Q_OBJECT
public:
@@ -63,7 +63,7 @@ Q_SIGNALS:
void changed();
};
-class Q_DECLARATIVE_EXPORT QDeclarativePathAttribute : public QDeclarativePathElement
+class Q_AUTOTEST_EXPORT QDeclarativePathAttribute : public QDeclarativePathElement
{
Q_OBJECT
@@ -87,7 +87,7 @@ private:
qreal _value;
};
-class Q_DECLARATIVE_EXPORT QDeclarativeCurve : public QDeclarativePathElement
+class Q_AUTOTEST_EXPORT QDeclarativeCurve : public QDeclarativePathElement
{
Q_OBJECT
@@ -109,7 +109,7 @@ private:
qreal _y;
};
-class Q_DECLARATIVE_EXPORT QDeclarativePathLine : public QDeclarativeCurve
+class Q_AUTOTEST_EXPORT QDeclarativePathLine : public QDeclarativeCurve
{
Q_OBJECT
public:
@@ -118,7 +118,7 @@ public:
void addToPath(QPainterPath &path);
};
-class Q_DECLARATIVE_EXPORT QDeclarativePathQuad : public QDeclarativeCurve
+class Q_AUTOTEST_EXPORT QDeclarativePathQuad : public QDeclarativeCurve
{
Q_OBJECT
@@ -140,7 +140,7 @@ private:
qreal _controlY;
};
-class Q_DECLARATIVE_EXPORT QDeclarativePathCubic : public QDeclarativeCurve
+class Q_AUTOTEST_EXPORT QDeclarativePathCubic : public QDeclarativeCurve
{
Q_OBJECT
@@ -172,7 +172,7 @@ private:
int _control2Y;
};
-class Q_DECLARATIVE_EXPORT QDeclarativePathPercent : public QDeclarativePathElement
+class Q_AUTOTEST_EXPORT QDeclarativePathPercent : public QDeclarativePathElement
{
Q_OBJECT
Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY changed)
@@ -187,7 +187,7 @@ private:
};
class QDeclarativePathPrivate;
-class Q_DECLARATIVE_EXPORT QDeclarativePath : public QObject, public QDeclarativeParserStatus
+class Q_AUTOTEST_EXPORT QDeclarativePath : public QObject, public QDeclarativeParserStatus
{
Q_OBJECT
diff --git a/src/declarative/graphicsitems/qdeclarativepathview.cpp b/src/declarative/graphicsitems/qdeclarativepathview.cpp
index 0c2d249..f4ebd13 100644
--- a/src/declarative/graphicsitems/qdeclarativepathview.cpp
+++ b/src/declarative/graphicsitems/qdeclarativepathview.cpp
@@ -329,6 +329,10 @@ void QDeclarativePathViewPrivate::regenerate()
\image pathview.gif
+ (Note the above example uses PathAttribute to scale and modify the
+ opacity of the items as they rotate. This additional code can be seen in the
+ PathAttribute documentation.)
+
Delegates are instantiated as needed and may be destroyed at any time.
State should \e never be stored in a delegate.
@@ -552,6 +556,8 @@ void QDeclarativePathView::setCurrentIndex(int idx)
\qmlmethod PathView::incrementCurrentIndex()
Increments the current index.
+
+ \bold Note: methods should only be called after the Component has completed.
*/
void QDeclarativePathView::incrementCurrentIndex()
{
@@ -563,6 +569,8 @@ void QDeclarativePathView::incrementCurrentIndex()
\qmlmethod PathView::decrementCurrentIndex()
Decrements the current index.
+
+ \bold Note: methods should only be called after the Component has completed.
*/
void QDeclarativePathView::decrementCurrentIndex()
{
diff --git a/src/declarative/graphicsitems/qdeclarativepathview_p.h b/src/declarative/graphicsitems/qdeclarativepathview_p.h
index 8a6f53f..d2980c6 100644
--- a/src/declarative/graphicsitems/qdeclarativepathview_p.h
+++ b/src/declarative/graphicsitems/qdeclarativepathview_p.h
@@ -53,7 +53,7 @@ QT_MODULE(Declarative)
class QDeclarativePathViewPrivate;
class QDeclarativePathViewAttached;
-class Q_DECLARATIVE_EXPORT QDeclarativePathView : public QDeclarativeItem
+class Q_AUTOTEST_EXPORT QDeclarativePathView : public QDeclarativeItem
{
Q_OBJECT
diff --git a/src/declarative/graphicsitems/qdeclarativepositioners.cpp b/src/declarative/graphicsitems/qdeclarativepositioners.cpp
index b9231a1..179f13d 100644
--- a/src/declarative/graphicsitems/qdeclarativepositioners.cpp
+++ b/src/declarative/graphicsitems/qdeclarativepositioners.cpp
@@ -1027,13 +1027,13 @@ void QDeclarativeFlow::doPositioning(QSizeF *contentSize)
continue;
if (d->flow == LeftToRight) {
- if (hoffset && hoffset + child.item->width() > width()) {
+ if (widthValid() && hoffset && hoffset + child.item->width() > width()) {
hoffset = 0;
voffset += linemax + spacing();
linemax = 0;
}
} else {
- if (voffset && voffset + child.item->height() > height()) {
+ if (heightValid() && voffset && voffset + child.item->height() > height()) {
voffset = 0;
hoffset += linemax + spacing();
linemax = 0;
diff --git a/src/declarative/graphicsitems/qdeclarativepositioners_p.h b/src/declarative/graphicsitems/qdeclarativepositioners_p.h
index 787dcd3..c03e518 100644
--- a/src/declarative/graphicsitems/qdeclarativepositioners_p.h
+++ b/src/declarative/graphicsitems/qdeclarativepositioners_p.h
@@ -57,7 +57,7 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
class QDeclarativeBasePositionerPrivate;
-class Q_DECLARATIVE_EXPORT QDeclarativeBasePositioner : public QDeclarativeItem
+class Q_AUTOTEST_EXPORT QDeclarativeBasePositioner : public QDeclarativeItem
{
Q_OBJECT
@@ -112,7 +112,7 @@ private:
Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeBasePositioner)
};
-class Q_DECLARATIVE_EXPORT QDeclarativeColumn : public QDeclarativeBasePositioner
+class Q_AUTOTEST_EXPORT QDeclarativeColumn : public QDeclarativeBasePositioner
{
Q_OBJECT
public:
@@ -124,7 +124,7 @@ private:
Q_DISABLE_COPY(QDeclarativeColumn)
};
-class Q_DECLARATIVE_EXPORT QDeclarativeRow: public QDeclarativeBasePositioner
+class Q_AUTOTEST_EXPORT QDeclarativeRow: public QDeclarativeBasePositioner
{
Q_OBJECT
public:
@@ -136,7 +136,7 @@ private:
Q_DISABLE_COPY(QDeclarativeRow)
};
-class Q_DECLARATIVE_EXPORT QDeclarativeGrid : public QDeclarativeBasePositioner
+class Q_AUTOTEST_EXPORT QDeclarativeGrid : public QDeclarativeBasePositioner
{
Q_OBJECT
Q_PROPERTY(int rows READ rows WRITE setRows NOTIFY rowsChanged)
@@ -174,7 +174,7 @@ private:
};
class QDeclarativeFlowPrivate;
-class Q_DECLARATIVE_EXPORT QDeclarativeFlow: public QDeclarativeBasePositioner
+class Q_AUTOTEST_EXPORT QDeclarativeFlow: public QDeclarativeBasePositioner
{
Q_OBJECT
Q_PROPERTY(Flow flow READ flow WRITE setFlow NOTIFY flowChanged)
diff --git a/src/declarative/graphicsitems/qdeclarativerectangle.cpp b/src/declarative/graphicsitems/qdeclarativerectangle.cpp
index 2756877..c49be46 100644
--- a/src/declarative/graphicsitems/qdeclarativerectangle.cpp
+++ b/src/declarative/graphicsitems/qdeclarativerectangle.cpp
@@ -446,6 +446,7 @@ void QDeclarativeRectangle::drawRect(QPainter &p)
p.setRenderHint(QPainter::Antialiasing);
if (d->pen && d->pen->isValid()) {
QPen pn(QColor(d->pen->color()), d->pen->width());
+ pn.setJoinStyle(Qt::MiterJoin);
p.setPen(pn);
} else {
p.setPen(Qt::NoPen);
diff --git a/src/declarative/graphicsitems/qdeclarativerectangle_p.h b/src/declarative/graphicsitems/qdeclarativerectangle_p.h
index 7272962..ecc3fbf 100644
--- a/src/declarative/graphicsitems/qdeclarativerectangle_p.h
+++ b/src/declarative/graphicsitems/qdeclarativerectangle_p.h
@@ -68,7 +68,7 @@ public:
QColor color() const { return _color; }
void setColor(const QColor &c);
- bool isValid() { return _valid; };
+ bool isValid() { return _valid; }
Q_SIGNALS:
void penChanged();
@@ -79,7 +79,7 @@ private:
bool _valid;
};
-class Q_DECLARATIVE_EXPORT QDeclarativeGradientStop : public QObject
+class Q_AUTOTEST_EXPORT QDeclarativeGradientStop : public QObject
{
Q_OBJECT
@@ -103,7 +103,7 @@ private:
QColor m_color;
};
-class Q_DECLARATIVE_EXPORT QDeclarativeGradient : public QObject
+class Q_AUTOTEST_EXPORT QDeclarativeGradient : public QObject
{
Q_OBJECT
diff --git a/src/declarative/graphicsitems/qdeclarativerepeater.cpp b/src/declarative/graphicsitems/qdeclarativerepeater.cpp
index 87da904..3be4014 100644
--- a/src/declarative/graphicsitems/qdeclarativerepeater.cpp
+++ b/src/declarative/graphicsitems/qdeclarativerepeater.cpp
@@ -85,6 +85,19 @@ QDeclarativeRepeaterPrivate::~QDeclarativeRepeaterPrivate()
The \l model of a Repeater can be any of the supported \l {qmlmodels}{Data Models}.
+ Items instantiated by the Repeater are inserted, in order, as
+ children of the Repeater's parent. The insertion starts immediately after
+ the repeater's position in its parent stacking list. This allows
+ a Repeater to be used inside a layout. For example, the following Repeater's
+ items are stacked between a red rectangle and a blue rectangle:
+
+ \snippet doc/src/snippets/declarative/repeater.qml layout
+
+ \image repeater.png
+
+
+ \section2 The \c index and \c modelData properties
+
The index of a delegate is exposed as an accessible \c index property in the delegate.
Properties of the model are also available depending upon the type of \l {qmlmodels}{Data Model}.
@@ -105,25 +118,22 @@ QDeclarativeRepeaterPrivate::~QDeclarativeRepeaterPrivate()
\o \image repeater-modeldata.png
\endtable
- Items instantiated by the Repeater are inserted, in order, as
- children of the Repeater's parent. The insertion starts immediately after
- the repeater's position in its parent stacking list. This allows
- a Repeater to be used inside a layout. For example, the following Repeater's
- items are stacked between a red rectangle and a blue rectangle:
-
- \snippet doc/src/snippets/declarative/repeater.qml layout
-
- \image repeater.png
A Repeater item owns all items it instantiates. Removing or dynamically destroying
an item created by a Repeater results in unpredictable behavior.
- Note that if a repeater is
- required to instantiate a large number of items, it may be more efficient to
- use other view elements such as ListView.
- \note Repeater is \l {Item}-based, and can only repeat \l {Item}-derived objects.
- For example, it cannot be used to repeat QtObjects.
+ \section2 Considerations when using Repeater
+
+ The Repeater element creates all of its delegate items when the repeater is first
+ created. This can be inefficient if there are a large number of delegate items and
+ not all of the items are required to be visible at the same time. If this is the case,
+ consider using other view elements like ListView (which only creates delegate items
+ when they are scrolled into view) or use the \l {Dynamic Object Creation} methods to
+ create items as they are required.
+
+ Also, note that Repeater is \l {Item}-based, and can only repeat \l {Item}-derived objects.
+ For example, it cannot be used to repeat QtObjects:
\badcode
Item {
//XXX does not work! Can't repeat QtObject as it doesn't derive from Item.
diff --git a/src/declarative/graphicsitems/qdeclarativerepeater_p.h b/src/declarative/graphicsitems/qdeclarativerepeater_p.h
index db46699..ff58fa0 100644
--- a/src/declarative/graphicsitems/qdeclarativerepeater_p.h
+++ b/src/declarative/graphicsitems/qdeclarativerepeater_p.h
@@ -51,7 +51,7 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
class QDeclarativeRepeaterPrivate;
-class Q_DECLARATIVE_EXPORT QDeclarativeRepeater : public QDeclarativeItem
+class Q_AUTOTEST_EXPORT QDeclarativeRepeater : public QDeclarativeItem
{
Q_OBJECT
diff --git a/src/declarative/graphicsitems/qdeclarativetext.cpp b/src/declarative/graphicsitems/qdeclarativetext.cpp
index c2e0d67..9a281e5 100644
--- a/src/declarative/graphicsitems/qdeclarativetext.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetext.cpp
@@ -61,52 +61,100 @@ class QTextDocumentWithImageResources : public QTextDocument {
Q_OBJECT
public:
- QTextDocumentWithImageResources(QDeclarativeText *parent) :
- QTextDocument(parent),
- outstanding(0)
- {
- }
+ QTextDocumentWithImageResources(QDeclarativeText *parent);
+ virtual ~QTextDocumentWithImageResources();
+ void setText(const QString &);
int resourcesLoading() const { return outstanding; }
protected:
- QVariant loadResource(int type, const QUrl &name)
- {
- QUrl url = qmlContext(parent())->resolvedUrl(name);
-
- if (type == QTextDocument::ImageResource) {
- QPixmap pm;
- QString errorString;
- QDeclarativePixmapReply::Status status = QDeclarativePixmapCache::get(url, &pm, &errorString, 0, false, 0, 0);
- if (status == QDeclarativePixmapReply::Ready)
- return pm;
- if (status == QDeclarativePixmapReply::Error) {
- if (!errors.contains(url)) {
- errors.insert(url);
- qmlInfo(parent()) << errorString;
- }
- } else {
- QDeclarativePixmapReply *reply = QDeclarativePixmapCache::request(qmlEngine(parent()), url);
- connect(reply, SIGNAL(finished()), this, SLOT(requestFinished()));
+ QVariant loadResource(int type, const QUrl &name);
+
+private slots:
+ void requestFinished();
+
+private:
+ QHash<QUrl, QDeclarativePixmap *> m_resources;
+
+ int outstanding;
+ static QSet<QUrl> errors;
+};
+
+QTextDocumentWithImageResources::QTextDocumentWithImageResources(QDeclarativeText *parent)
+: QTextDocument(parent), outstanding(0)
+{
+}
+
+QTextDocumentWithImageResources::~QTextDocumentWithImageResources()
+{
+ if (!m_resources.isEmpty())
+ qDeleteAll(m_resources);
+}
+
+QVariant QTextDocumentWithImageResources::loadResource(int type, const QUrl &name)
+{
+ QDeclarativeContext *context = qmlContext(parent());
+ QUrl url = context->resolvedUrl(name);
+
+ if (type == QTextDocument::ImageResource) {
+ QHash<QUrl, QDeclarativePixmap *>::Iterator iter = m_resources.find(url);
+
+ if (iter == m_resources.end()) {
+ QDeclarativePixmap *p = new QDeclarativePixmap(context->engine(), url);
+ iter = m_resources.insert(name, p);
+
+ if (p->isLoading()) {
+ p->connectFinished(this, SLOT(requestFinished()));
outstanding++;
}
}
- return QTextDocument::loadResource(type,url); // The *resolved* URL
+ QDeclarativePixmap *p = *iter;
+ if (p->isReady()) {
+ return p->pixmap();
+ } else if (p->isError()) {
+ if (!errors.contains(url)) {
+ errors.insert(url);
+ qmlInfo(parent()) << p->error();
+ }
+ }
}
-private slots:
- void requestFinished()
- {
- outstanding--;
- if (outstanding == 0)
- static_cast<QDeclarativeText*>(parent())->reloadWithResources();
+ return QTextDocument::loadResource(type,url); // The *resolved* URL
+}
+
+void QTextDocumentWithImageResources::requestFinished()
+{
+ outstanding--;
+ if (outstanding == 0) {
+ QDeclarativeText *textItem = static_cast<QDeclarativeText*>(parent());
+ QString text = textItem->text();
+#ifndef QT_NO_TEXTHTMLPARSER
+ setHtml(text);
+#else
+ setPlainText(text);
+#endif
+ QDeclarativeTextPrivate *d = QDeclarativeTextPrivate::get(textItem);
+ d->updateLayout();
+ d->markImgDirty();
}
+}
-private:
- int outstanding;
- static QSet<QUrl> errors;
-};
+void QTextDocumentWithImageResources::setText(const QString &text)
+{
+ if (!m_resources.isEmpty()) {
+ qWarning("CLEAR");
+ qDeleteAll(m_resources);
+ m_resources.clear();
+ outstanding = 0;
+ }
+
+#ifndef QT_NO_TEXTHTMLPARSER
+ setHtml(text);
+#else
+ setPlainText(text);
+#endif
+}
QSet<QUrl> QTextDocumentWithImageResources::errors;
@@ -136,6 +184,8 @@ QSet<QUrl> QTextDocumentWithImageResources::errors;
HTML img tags that load remote images, the text is reloaded.
Text provides read-only text. For editable text, see \l TextEdit.
+
+ \sa {declarative/text/fonts}{Fonts example}
*/
/*!
@@ -225,12 +275,6 @@ QDeclarativeTextPrivate::~QDeclarativeTextPrivate()
*/
/*!
- \qmlproperty bool Text::font.outline
-
- Sets whether the font has an outline style.
-*/
-
-/*!
\qmlproperty bool Text::font.strikeout
Sets whether the font has a strikeout style.
@@ -318,11 +362,7 @@ void QDeclarativeText::setText(const QString &n)
if (d->richText) {
if (isComponentComplete()) {
d->ensureDoc();
-#ifndef QT_NO_TEXTHTMLPARSER
- d->doc->setHtml(n);
-#else
- d->doc->setPlainText(n);
-#endif
+ d->doc->setText(n);
}
}
@@ -441,6 +481,8 @@ void QDeclarativeText::setStyleColor(const QColor &color)
\qml
Text { font.pointSize: 18; text: "hello"; style: Text.Raised; styleColor: "gray" }
\endqml
+
+ \sa style
*/
QColor QDeclarativeText::styleColor() const
{
@@ -609,11 +651,7 @@ void QDeclarativeText::setTextFormat(TextFormat format)
} else if (!wasRich && d->richText) {
if (isComponentComplete()) {
d->ensureDoc();
-#ifndef QT_NO_TEXTHTMLPARSER
- d->doc->setHtml(d->text);
-#else
- d->doc->setPlainText(d->text);
-#endif
+ d->doc->setText(d->text);
}
d->updateLayout();
d->markImgDirty();
@@ -663,11 +701,78 @@ void QDeclarativeText::setElideMode(QDeclarativeText::TextElideMode mode)
emit elideModeChanged(d->elideMode);
}
+QRectF QDeclarativeText::boundingRect() const
+{
+ Q_D(const QDeclarativeText);
+
+ int w = width();
+ int h = height();
+
+ int x = 0;
+ int y = 0;
+
+ // Could include font max left/right bearings to either side of rectangle.
+
+ if (d->cache || d->style != Normal) {
+ switch (d->hAlign) {
+ case AlignLeft:
+ x = 0;
+ break;
+ case AlignRight:
+ x = w - d->imgCache.width();
+ break;
+ case AlignHCenter:
+ x = (w - d->imgCache.width()) / 2;
+ break;
+ }
+
+ switch (d->vAlign) {
+ case AlignTop:
+ y = 0;
+ break;
+ case AlignBottom:
+ y = h - d->imgCache.height();
+ break;
+ case AlignVCenter:
+ y = (h - d->imgCache.height()) / 2;
+ break;
+ }
+
+ return QRectF(x,y,d->imgCache.width(),d->imgCache.height());
+ } else {
+ switch (d->hAlign) {
+ case AlignLeft:
+ x = 0;
+ break;
+ case AlignRight:
+ x = w - d->cachedLayoutSize.width();
+ break;
+ case AlignHCenter:
+ x = (w - d->cachedLayoutSize.width()) / 2;
+ break;
+ }
+
+ switch (d->vAlign) {
+ case AlignTop:
+ y = 0;
+ break;
+ case AlignBottom:
+ y = h - d->cachedLayoutSize.height();
+ break;
+ case AlignVCenter:
+ y = (h - d->cachedLayoutSize.height()) / 2;
+ break;
+ }
+
+ return QRectF(x,y,d->cachedLayoutSize.width(),d->cachedLayoutSize.height());
+ }
+}
+
void QDeclarativeText::geometryChanged(const QRectF &newGeometry,
const QRectF &oldGeometry)
{
Q_D(QDeclarativeText);
- if (newGeometry.width() != oldGeometry.width()) {
+ if (!d->internalWidthUpdate && newGeometry.width() != oldGeometry.width()) {
if (d->wrapMode != QDeclarativeText::NoWrap || d->elideMode != QDeclarativeText::ElideNone) {
//re-elide if needed
if (d->singleline && d->elideMode != QDeclarativeText::ElideNone &&
@@ -713,6 +818,7 @@ void QDeclarativeTextPrivate::updateLayout()
}
}
+
void QDeclarativeTextPrivate::updateSize()
{
Q_Q(QDeclarativeText);
@@ -730,7 +836,10 @@ void QDeclarativeTextPrivate::updateSize()
//setup instance of QTextLayout for all cases other than richtext
if (!richText) {
size = setupTextLayout(&layout);
- cachedLayoutSize = size;
+ if (cachedLayoutSize != size) {
+ q->prepareGeometryChange();
+ cachedLayoutSize = size;
+ }
dy -= size.height();
} else {
singleline = false; // richtext can't elide or be optimized for single-line case
@@ -744,7 +853,13 @@ void QDeclarativeTextPrivate::updateSize()
else
doc->setTextWidth(doc->idealWidth()); // ### Text does not align if width is not set (QTextDoc bug)
dy -= (int)doc->size().height();
- cachedLayoutSize = doc->size().toSize();
+ q->prepareGeometryChange();
+ QSize dsize = doc->size().toSize();
+ if (dsize != cachedLayoutSize) {
+ q->prepareGeometryChange();
+ cachedLayoutSize = dsize;
+ }
+ size = QSize(int(doc->idealWidth()),dsize.height());
}
int yoff = 0;
@@ -757,8 +872,10 @@ void QDeclarativeTextPrivate::updateSize()
q->setBaselineOffset(fm.ascent() + yoff);
//### need to comfirm cost of always setting these for richText
- q->setImplicitWidth(richText ? (int)doc->idealWidth() : size.width());
- q->setImplicitHeight(richText ? (int)doc->size().height() : size.height());
+ internalWidthUpdate = true;
+ q->setImplicitWidth(size.width());
+ internalWidthUpdate = false;
+ q->setImplicitHeight(size.height());
emit q->paintedSizeChanged();
} else {
dirty = true;
@@ -813,6 +930,8 @@ void QDeclarativeTextPrivate::drawOutline()
ppm.drawPixmap(pos, imgCache);
ppm.end();
+ if (imgCache.size() != img.size())
+ q_func()->prepareGeometryChange();
imgCache = img;
}
@@ -831,6 +950,8 @@ void QDeclarativeTextPrivate::drawOutline(int yOffset)
ppm.drawPixmap(pos, imgCache);
ppm.end();
+ if (imgCache.size() != img.size())
+ q_func()->prepareGeometryChange();
imgCache = img;
}
@@ -955,18 +1076,21 @@ void QDeclarativeTextPrivate::checkImgCache()
return;
bool empty = text.isEmpty();
+ QPixmap newImgCache;
if (empty) {
- imgCache = QPixmap();
imgStyleCache = QPixmap();
} else if (richText) {
- imgCache = richTextImage(false);
+ newImgCache = richTextImage(false);
if (style != QDeclarativeText::Normal)
imgStyleCache = richTextImage(true); //### should use styleColor
} else {
- imgCache = wrappedTextImage(false);
+ newImgCache = wrappedTextImage(false);
if (style != QDeclarativeText::Normal)
imgStyleCache = wrappedTextImage(true); //### should use styleColor
}
+ if (imgCache.size() != newImgCache.size())
+ q_func()->prepareGeometryChange();
+ imgCache = newImgCache;
if (!empty)
switch (style) {
case QDeclarativeText::Outline:
@@ -994,20 +1118,6 @@ void QDeclarativeTextPrivate::ensureDoc()
}
}
-void QDeclarativeText::reloadWithResources()
-{
- Q_D(QDeclarativeText);
- if (!d->richText)
- return;
-#ifndef QT_NO_TEXTHTMLPARSER
- d->doc->setHtml(d->text);
-#else
- d->doc->setPlainText(d->text);
-#endif
- d->updateLayout();
- d->markImgDirty();
-}
-
/*!
Returns the number of resources (images) that are being loaded asynchronously.
*/
@@ -1031,35 +1141,7 @@ void QDeclarativeText::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWid
if (d->smooth)
p->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, d->smooth);
- int w = width();
- int h = height();
-
- int x = 0;
- int y = 0;
-
- switch (d->hAlign) {
- case AlignLeft:
- x = 0;
- break;
- case AlignRight:
- x = w - d->imgCache.width();
- break;
- case AlignHCenter:
- x = (w - d->imgCache.width()) / 2;
- break;
- }
-
- switch (d->vAlign) {
- case AlignTop:
- y = 0;
- break;
- case AlignBottom:
- y = h - d->imgCache.height();
- break;
- case AlignVCenter:
- y = (h - d->imgCache.height()) / 2;
- break;
- }
+ QRect br = boundingRect().toRect();
bool needClip = clip() && (d->imgCache.width() > width() ||
d->imgCache.height() > height());
@@ -1068,7 +1150,7 @@ void QDeclarativeText::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWid
p->save();
p->setClipRect(boundingRect(), Qt::IntersectClip);
}
- p->drawPixmap(x, y, d->imgCache);
+ p->drawPixmap(br.x(), br.y(), d->imgCache);
if (needClip)
p->restore();
@@ -1077,20 +1159,8 @@ void QDeclarativeText::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWid
p->setRenderHint(QPainter::SmoothPixmapTransform, oldSmooth);
}
} else {
- int h = height();
- int y = 0;
+ qreal y = boundingRect().y();
- switch (d->vAlign) {
- case AlignTop:
- y = 0;
- break;
- case AlignBottom:
- y = h - d->cachedLayoutSize.height();
- break;
- case AlignVCenter:
- y = (h - d->cachedLayoutSize.height()) / 2;
- break;
- }
bool needClip = !clip() && (d->cachedLayoutSize.width() > width() ||
d->cachedLayoutSize.height() > height());
@@ -1133,11 +1203,7 @@ void QDeclarativeText::componentComplete()
if (d->dirty) {
if (d->richText) {
d->ensureDoc();
-#ifndef QT_NO_TEXTHTMLPARSER
- d->doc->setHtml(d->text);
-#else
- d->doc->setPlainText(d->text);
-#endif
+ d->doc->setText(d->text);
}
d->updateLayout();
d->dirty = false;
diff --git a/src/declarative/graphicsitems/qdeclarativetext_p.h b/src/declarative/graphicsitems/qdeclarativetext_p.h
index db21140..2cc4d52 100644
--- a/src/declarative/graphicsitems/qdeclarativetext_p.h
+++ b/src/declarative/graphicsitems/qdeclarativetext_p.h
@@ -143,6 +143,8 @@ public:
qreal paintedWidth() const;
qreal paintedHeight() const;
+ QRectF boundingRect() const;
+
Q_SIGNALS:
void textChanged(const QString &text);
void linkActivated(const QString &link);
@@ -166,9 +168,6 @@ protected:
private:
Q_DISABLE_COPY(QDeclarativeText)
Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeText)
-
- friend class QTextDocumentWithImageResources;
- void reloadWithResources();
};
QT_END_NAMESPACE
diff --git a/src/declarative/graphicsitems/qdeclarativetext_p_p.h b/src/declarative/graphicsitems/qdeclarativetext_p_p.h
index 332f99e..48552a7 100644
--- a/src/declarative/graphicsitems/qdeclarativetext_p_p.h
+++ b/src/declarative/graphicsitems/qdeclarativetext_p_p.h
@@ -72,7 +72,7 @@ public:
QDeclarativeTextPrivate()
: color((QRgb)0), style(QDeclarativeText::Normal),
hAlign(QDeclarativeText::AlignLeft), vAlign(QDeclarativeText::AlignTop), elideMode(QDeclarativeText::ElideNone),
- imgDirty(true), dirty(true), richText(false), singleline(false), cache(true), doc(0),
+ imgDirty(true), dirty(true), richText(false), singleline(false), cache(true), internalWidthUpdate(false), doc(0),
format(QDeclarativeText::AutoText), wrapMode(QDeclarativeText::NoWrap)
{
#if defined(QML_NO_TEXT_CACHE)
@@ -119,11 +119,16 @@ public:
bool richText:1;
bool singleline:1;
bool cache:1;
+ bool internalWidthUpdate:1;
QTextDocumentWithImageResources *doc;
QTextLayout layout;
QSize cachedLayoutSize;
QDeclarativeText::TextFormat format;
QDeclarativeText::WrapMode wrapMode;
+
+ static inline QDeclarativeTextPrivate *get(QDeclarativeText *t) {
+ return t->d_func();
+ }
};
QT_END_NAMESPACE
diff --git a/src/declarative/graphicsitems/qdeclarativetextedit.cpp b/src/declarative/graphicsitems/qdeclarativetextedit.cpp
index 3106daf..f3eef23 100644
--- a/src/declarative/graphicsitems/qdeclarativetextedit.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetextedit.cpp
@@ -99,7 +99,7 @@ TextEdit {
You can translate between cursor positions (characters from the start of the document) and pixel
points using positionAt() and positionToRectangle().
- \sa Text, TextInput
+ \sa Text, TextInput, {declarative/text/textselection}{Text Selection example}
*/
/*!
@@ -186,12 +186,6 @@ QString QDeclarativeTextEdit::text() const
*/
/*!
- \qmlproperty bool TextEdit::font.outline
-
- Sets whether the font has an outline style.
-*/
-
-/*!
\qmlproperty bool TextEdit::font.strikeout
Sets whether the font has a strikeout style.
@@ -209,7 +203,7 @@ QString QDeclarativeTextEdit::text() const
Sets the font size in pixels.
Using this function makes the font device dependent.
- Use \l pointSize to set the size of the font in a device independent manner.
+ Use \l font.pointSize to set the size of the font in a device independent manner.
*/
/*!
@@ -1231,8 +1225,13 @@ void QDeclarativeTextEdit::updateImgCache(const QRectF &rf)
r = QRect(0,0,INT_MAX,INT_MAX);
} else {
r = rf.toRect();
- if (r != QRect(0,0,INT_MAX,INT_MAX)) // Don't translate "everything"
+ if (r.height() > INT_MAX/2) {
+ // Take care of overflow when translating "everything"
+ r.setTop(r.y() + d->yoff);
+ r.setBottom(INT_MAX/2);
+ } else {
r = r.translated(0,d->yoff);
+ }
}
dirtyCache(r);
emit update();
@@ -1264,6 +1263,15 @@ void QDeclarativeTextEditPrivate::init()
control = new QTextControl(q);
control->setIgnoreUnusedNavigationEvents(true);
+ // QTextControl follows the default text color
+ // defined by the platform, declarative text
+ // should be black by default
+ QPalette pal = control->palette();
+ if (pal.color(QPalette::Text) != color) {
+ pal.setColor(QPalette::Text, color);
+ control->setPalette(pal);
+ }
+
QObject::connect(control, SIGNAL(updateRequest(QRectF)), q, SLOT(updateImgCache(QRectF)));
QObject::connect(control, SIGNAL(textChanged()), q, SLOT(q_textChanged()));
@@ -1284,6 +1292,7 @@ void QDeclarativeTextEditPrivate::init()
void QDeclarativeTextEdit::q_textChanged()
{
updateSize();
+ updateMicroFocus();
emit textChanged(text());
}
@@ -1325,8 +1334,26 @@ void QDeclarativeTextEdit::updateSelectionMarkers()
d->lastSelectionEnd = d->control->textCursor().selectionEnd();
emit selectionEndChanged();
}
+ updateMicroFocus();
}
+QRectF QDeclarativeTextEdit::boundingRect() const
+{
+ Q_D(const QDeclarativeTextEdit);
+ QRectF r = QDeclarativePaintedItem::boundingRect();
+ int cursorWidth = 1;
+ if(d->cursor)
+ cursorWidth = d->cursor->width();
+ if(!d->document->isEmpty())
+ cursorWidth += 3;// ### Need a better way of accounting for space between char and cursor
+
+ // Could include font max left/right bearings to either side of rectangle.
+
+ r.setRight(r.right() + cursorWidth);
+ return r.translated(0,d->yoff);
+}
+
+
//### we should perhaps be a bit smarter here -- depending on what has changed, we shouldn't
// need to do all the calculations each time
void QDeclarativeTextEdit::updateSize()
@@ -1341,13 +1368,20 @@ void QDeclarativeTextEdit::updateSize()
d->document->setTextWidth(width());
dy -= (int)d->document->size().height();
+ int nyoff;
if (heightValid()) {
if (d->vAlign == AlignBottom)
- d->yoff = dy;
+ nyoff = dy;
else if (d->vAlign == AlignVCenter)
- d->yoff = dy/2;
+ nyoff = dy/2;
+ else
+ nyoff = 0;
} else {
- d->yoff = 0;
+ nyoff = 0;
+ }
+ if (nyoff != d->yoff) {
+ prepareGeometryChange();
+ d->yoff = nyoff;
}
setBaselineOffset(fm.ascent() + d->yoff + d->textMargin);
@@ -1355,12 +1389,6 @@ void QDeclarativeTextEdit::updateSize()
int newWidth = qCeil(d->document->idealWidth());
if (!widthValid() && d->document->textWidth() != newWidth)
d->document->setTextWidth(newWidth); // ### Text does not align if width is not set (QTextDoc bug)
- int cursorWidth = 1;
- if(d->cursor)
- cursorWidth = d->cursor->width();
- newWidth += cursorWidth;
- if(!d->document->isEmpty())
- newWidth += 3;// ### Need a better way of accounting for space between char and cursor
// ### Setting the implicitWidth triggers another updateSize(), and unless there are bindings nothing has changed.
setImplicitWidth(newWidth);
qreal newHeight = d->document->isEmpty() ? fm.height() : (int)d->document->size().height();
diff --git a/src/declarative/graphicsitems/qdeclarativetextedit_p.h b/src/declarative/graphicsitems/qdeclarativetextedit_p.h
index d08f607..279af78 100644
--- a/src/declarative/graphicsitems/qdeclarativetextedit_p.h
+++ b/src/declarative/graphicsitems/qdeclarativetextedit_p.h
@@ -58,7 +58,7 @@ QT_MODULE(Declarative)
class QDeclarativeTextEditPrivate;
-class Q_DECLARATIVE_EXPORT QDeclarativeTextEdit : public QDeclarativePaintedItem
+class Q_AUTOTEST_EXPORT QDeclarativeTextEdit : public QDeclarativePaintedItem
{
Q_OBJECT
Q_ENUMS(VAlignment)
@@ -195,6 +195,8 @@ public:
Q_INVOKABLE int positionAt(int x, int y) const;
Q_INVOKABLE void moveCursorSelection(int pos);
+ QRectF boundingRect() const;
+
Q_SIGNALS:
void textChanged(const QString &);
void paintedSizeChanged();
diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp
index ec14c78..f6af1f4 100644
--- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp
@@ -69,7 +69,7 @@ QT_BEGIN_NAMESPACE
On Mac OS X, the Up/Down key bindings for Home/End are explicitly disabled.
If you want such bindings (on any platform), you will need to construct them in QML.
- \sa TextEdit, Text
+ \sa TextEdit, Text, {declarative/text/textselection}{Text Selection example}
*/
QDeclarativeTextInput::QDeclarativeTextInput(QDeclarativeItem* parent)
: QDeclarativePaintedItem(*(new QDeclarativeTextInputPrivate), parent)
@@ -100,8 +100,6 @@ void QDeclarativeTextInput::setText(const QString &s)
if(s == text())
return;
d->control->setText(s);
- d->updateHorizontalScroll();
- //emit textChanged();
}
/*!
@@ -152,12 +150,6 @@ void QDeclarativeTextInput::setText(const QString &s)
*/
/*!
- \qmlproperty bool TextInput::font.outline
-
- Sets whether the font has an outline style.
-*/
-
-/*!
\qmlproperty bool TextInput::font.strikeout
Sets whether the font has a strikeout style.
@@ -556,9 +548,9 @@ void QDeclarativeTextInput::setAutoScroll(bool b)
return;
d->autoScroll = b;
- d->updateHorizontalScroll();
//We need to repaint so that the scrolling is taking into account.
updateSize(true);
+ d->updateHorizontalScroll();
emit autoScrollChanged(d->autoScroll);
}
@@ -832,7 +824,7 @@ void QDeclarativeTextInput::createCursor()
QDeclarative_setParent_noEvent(d->cursorItem, this);
d->cursorItem->setParentItem(this);
d->cursorItem->setX(d->control->cursorToX());
- d->cursorItem->setHeight(d->control->height());
+ d->cursorItem->setHeight(d->control->height()-1); // -1 to counter QLineControl's +1 which is not consistent with Text.
}
void QDeclarativeTextInput::moveCursor()
@@ -916,6 +908,7 @@ void QDeclarativeTextInput::keyPressEvent(QKeyEvent* ev)
void QDeclarativeTextInput::inputMethodEvent(QInputMethodEvent *ev)
{
Q_D(QDeclarativeTextInput);
+ ev->ignore();
inputMethodPreHandler(ev);
if (ev->isAccepted())
return;
@@ -1026,27 +1019,31 @@ bool QDeclarativeTextInput::event(QEvent* ev)
void QDeclarativeTextInput::geometryChanged(const QRectF &newGeometry,
const QRectF &oldGeometry)
{
- if (newGeometry.width() != oldGeometry.width())
+ Q_D(QDeclarativeTextInput);
+ if (newGeometry.width() != oldGeometry.width()) {
updateSize();
+ d->updateHorizontalScroll();
+ }
QDeclarativePaintedItem::geometryChanged(newGeometry, oldGeometry);
}
+int QDeclarativeTextInputPrivate::calculateTextWidth()
+{
+ return qRound(control->naturalTextWidth());
+}
+
void QDeclarativeTextInputPrivate::updateHorizontalScroll()
{
Q_Q(QDeclarativeTextInput);
- QFontMetrics fm = QFontMetrics(font);
int cix = qRound(control->cursorToX());
QRect br(q->boundingRect().toRect());
- //###Is this using bearing appropriately?
- int minLB = qMax(0, -fm.minLeftBearing());
- int minRB = qMax(0, -fm.minRightBearing());
- int widthUsed = qRound(control->naturalTextWidth()) + 1 + minRB;
+ int widthUsed = calculateTextWidth();
if (autoScroll) {
- if ((minLB + widthUsed) <= br.width()) {
+ if (widthUsed <= br.width()) {
// text fits in br; use hscroll for alignment
switch (hAlign & ~(Qt::AlignAbsolute|Qt::AlignVertical_Mask)) {
case Qt::AlignRight:
- hscroll = widthUsed - br.width() + 1;
+ hscroll = widthUsed - br.width() - 1;
break;
case Qt::AlignHCenter:
hscroll = (widthUsed - br.width()) / 2;
@@ -1056,7 +1053,6 @@ void QDeclarativeTextInputPrivate::updateHorizontalScroll()
hscroll = 0;
break;
}
- hscroll -= minLB;
} else if (cix - hscroll >= br.width()) {
// text doesn't fit, cursor is to the right of br (scroll right)
hscroll = cix - br.width() + 1;
@@ -1076,7 +1072,6 @@ void QDeclarativeTextInputPrivate::updateHorizontalScroll()
} else {
hscroll = 0;
}
- hscroll -= minLB;
}
}
@@ -1101,7 +1096,6 @@ void QDeclarativeTextInput::drawContents(QPainter *p, const QRect &r)
offset = QPoint(d->hscroll, 0);
}
d->control->draw(p, offset, r, flags);
-
p->restore();
}
@@ -1148,6 +1142,42 @@ void QDeclarativeTextInput::selectAll()
d->control->setSelection(0, d->control->text().length());
}
+#ifndef QT_NO_CLIPBOARD
+/*!
+ \qmlmethod TextInput::cut()
+
+ Moves the currently selected text to the system clipboard.
+*/
+void QDeclarativeTextInput::cut()
+{
+ Q_D(QDeclarativeTextInput);
+ d->control->copy();
+ d->control->del();
+}
+
+/*!
+ \qmlmethod TextInput::copy()
+
+ Copies the currently selected text to the system clipboard.
+*/
+void QDeclarativeTextInput::copy()
+{
+ Q_D(QDeclarativeTextInput);
+ d->control->copy();
+}
+
+/*!
+ \qmlmethod TextInput::paste()
+
+ Replaces the currently selected text by the contents of the system clipboard.
+*/
+void QDeclarativeTextInput::paste()
+{
+ Q_D(QDeclarativeTextInput);
+ d->control->paste();
+}
+#endif // QT_NO_CLIPBOARD
+
/*!
\qmlmethod void TextInput::selectWord()
@@ -1398,18 +1428,11 @@ void QDeclarativeTextInputPrivate::init()
q->connect(control, SIGNAL(selectionChanged()),
q, SLOT(selectionChanged()));
q->connect(control, SIGNAL(textChanged(const QString &)),
- q, SIGNAL(displayTextChanged(const QString &)));
- q->connect(control, SIGNAL(textChanged(const QString &)),
q, SLOT(q_textChanged()));
q->connect(control, SIGNAL(accepted()),
q, SIGNAL(accepted()));
q->connect(control, SIGNAL(updateNeeded(QRect)),
q, SLOT(updateRect(QRect)));
- q->connect(control, SIGNAL(cursorPositionChanged(int,int)),
- q, SLOT(updateRect()));//TODO: Only update rect between pos's
- q->connect(control, SIGNAL(selectionChanged()),
- q, SLOT(updateRect()));//TODO: Only update rect in selection
- //Note that above TODOs probably aren't that big a savings
q->updateSize();
oldValidity = control->hasAcceptableInput();
lastSelectionStart = 0;
@@ -1422,6 +1445,8 @@ void QDeclarativeTextInputPrivate::init()
void QDeclarativeTextInput::cursorPosChanged()
{
Q_D(QDeclarativeTextInput);
+ updateRect();//TODO: Only update rect between pos's
+ updateMicroFocus();
emit cursorPositionChanged();
if(!d->control->hasSelectedText()){
@@ -1439,6 +1464,7 @@ void QDeclarativeTextInput::cursorPosChanged()
void QDeclarativeTextInput::selectionChanged()
{
Q_D(QDeclarativeTextInput);
+ updateRect();//TODO: Only update rect in selection
emit selectedTextChanged();
if(d->lastSelectionStart != d->control->selectionStart()){
@@ -1458,9 +1484,11 @@ void QDeclarativeTextInput::selectionChanged()
void QDeclarativeTextInput::q_textChanged()
{
Q_D(QDeclarativeTextInput);
- d->updateHorizontalScroll();
updateSize();
+ d->updateHorizontalScroll();
+ updateMicroFocus();
emit textChanged();
+ emit displayTextChanged();
if(hasAcceptableInput() != d->oldValidity){
d->oldValidity = hasAcceptableInput();
emit acceptableInputChanged();
@@ -1477,16 +1505,26 @@ void QDeclarativeTextInput::updateRect(const QRect &r)
update();
}
+QRectF QDeclarativeTextInput::boundingRect() const
+{
+ Q_D(const QDeclarativeTextInput);
+ QRectF r = QDeclarativePaintedItem::boundingRect();
+
+ int cursorWidth = d->cursorItem ? d->cursorItem->width() : d->control->cursorWidth();
+
+ // Could include font max left/right bearings to either side of rectangle.
+
+ r.setRight(r.right() + cursorWidth);
+ return r;
+}
+
void QDeclarativeTextInput::updateSize(bool needsRedraw)
{
Q_D(QDeclarativeTextInput);
int w = width();
int h = height();
- setImplicitHeight(d->control->height());
- int cursorWidth = d->control->cursorWidth();
- if(d->cursorItem)
- cursorWidth = d->cursorItem->width();
- setImplicitWidth(d->control->naturalTextWidth() + cursorWidth);
+ setImplicitHeight(d->control->height()-1); // -1 to counter QLineControl's +1 which is not consistent with Text.
+ setImplicitWidth(d->calculateTextWidth());
setContentsSize(QSize(width(), height()));//Repaints if changed
if(w==width() && h==height() && needsRedraw){
clearCache();
diff --git a/src/declarative/graphicsitems/qdeclarativetextinput_p.h b/src/declarative/graphicsitems/qdeclarativetextinput_p.h
index 6934da4..b1862c6 100644
--- a/src/declarative/graphicsitems/qdeclarativetextinput_p.h
+++ b/src/declarative/graphicsitems/qdeclarativetextinput_p.h
@@ -56,7 +56,7 @@ QT_MODULE(Declarative)
class QDeclarativeTextInputPrivate;
class QValidator;
-class Q_DECLARATIVE_EXPORT QDeclarativeTextInput : public QDeclarativePaintedItem
+class Q_AUTOTEST_EXPORT QDeclarativeTextInput : public QDeclarativePaintedItem
{
Q_OBJECT
Q_ENUMS(HAlignment)
@@ -187,6 +187,8 @@ public:
void drawContents(QPainter *p,const QRect &r);
QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
+ QRectF boundingRect() const;
+
Q_SIGNALS:
void textChanged();
void cursorPositionChanged();
@@ -208,7 +210,7 @@ Q_SIGNALS:
void inputMaskChanged(const QString &inputMask);
void echoModeChanged(EchoMode echoMode);
void passwordCharacterChanged();
- void displayTextChanged(const QString &text);
+ void displayTextChanged();
void focusOnPressChanged(bool focusOnPress);
void autoScrollChanged(bool autoScroll);
void selectByMouseChanged(bool selectByMouse);
@@ -230,6 +232,11 @@ public Q_SLOTS:
void selectAll();
void selectWord();
void select(int start, int end);
+#ifndef QT_NO_CLIPBOARD
+ void cut();
+ void copy();
+ void paste();
+#endif
private Q_SLOTS:
void updateSize(bool needsRedraw = true);
diff --git a/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h b/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h
index 8b74bcc..4ac5134 100644
--- a/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h
+++ b/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h
@@ -100,6 +100,7 @@ public:
void startCreatingCursor();
void focusChanged(bool hasFocus);
void updateHorizontalScroll();
+ int calculateTextWidth();
QLineControl* control;
diff --git a/src/declarative/graphicsitems/qdeclarativetranslate_p.h b/src/declarative/graphicsitems/qdeclarativetranslate_p.h
index 939692b..0207dce 100644
--- a/src/declarative/graphicsitems/qdeclarativetranslate_p.h
+++ b/src/declarative/graphicsitems/qdeclarativetranslate_p.h
@@ -52,7 +52,7 @@ QT_MODULE(Declarative)
class QDeclarativeTranslatePrivate;
-class Q_DECLARATIVE_EXPORT QDeclarativeTranslate : public QGraphicsTransform
+class Q_AUTOTEST_EXPORT QDeclarativeTranslate : public QGraphicsTransform
{
Q_OBJECT
diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp
index 5092349..786d6f9 100644
--- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp
+++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp
@@ -283,7 +283,7 @@ public:
if (m_roles.count() == 1)
m_roleNames.insert("modelData", m_roles.at(0));
if (m_roles.count())
- m_roleNames.insert("hasModelChildren", 0);
+ m_roleNames.insert("hasModelChildren", -1);
} else if (m_listAccessor) {
m_roleNames.insert("modelData", 0);
if (m_listAccessor->type() == QDeclarativeListAccessor::Instance) {
@@ -818,6 +818,12 @@ void QDeclarativeVisualDataModel::setDelegate(QDeclarativeComponent *delegate)
\c view.qml:
\snippet doc/src/snippets/declarative/visualdatamodel_rootindex/view.qml 0
+ If the \l model is a QAbstractItemModel subclass, the delegate can also
+ reference a \c hasModelChildren property (optionally qualified by a
+ \e model. prefix) that indicates whether the delegate's model item has
+ any child nodes.
+
+
\sa modelIndex(), parentModelIndex()
*/
QVariant QDeclarativeVisualDataModel::rootIndex() const
diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel_p.h b/src/declarative/graphicsitems/qdeclarativevisualitemmodel_p.h
index 079c9e6..d5c0de2 100644
--- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel_p.h
+++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel_p.h
@@ -60,7 +60,7 @@ class QDeclarativeComponent;
class QDeclarativePackage;
class QDeclarativeVisualDataModelPrivate;
-class Q_DECLARATIVE_EXPORT QDeclarativeVisualModel : public QObject
+class Q_AUTOTEST_EXPORT QDeclarativeVisualModel : public QObject
{
Q_OBJECT
@@ -103,7 +103,7 @@ private:
class QDeclarativeVisualItemModelAttached;
class QDeclarativeVisualItemModelPrivate;
-class Q_DECLARATIVE_EXPORT QDeclarativeVisualItemModel : public QDeclarativeVisualModel
+class Q_AUTOTEST_EXPORT QDeclarativeVisualItemModel : public QDeclarativeVisualModel
{
Q_OBJECT
Q_DECLARE_PRIVATE(QDeclarativeVisualItemModel)
@@ -138,7 +138,7 @@ private:
};
-class Q_DECLARATIVE_EXPORT QDeclarativeVisualDataModel : public QDeclarativeVisualModel
+class Q_AUTOTEST_EXPORT QDeclarativeVisualDataModel : public QDeclarativeVisualModel
{
Q_OBJECT
Q_DECLARE_PRIVATE(QDeclarativeVisualDataModel)
diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp
index 80a1093..23307c9 100644
--- a/src/declarative/qml/qdeclarativecompiler.cpp
+++ b/src/declarative/qml/qdeclarativecompiler.cpp
@@ -228,10 +228,10 @@ bool QDeclarativeCompiler::testLiteralAssignment(const QMetaProperty &prop,
}
break;
case QMetaType::Float:
- if (!v->value.isNumber()) COMPILE_EXCEPTION(v, tr("Invalid property assignment: float expected"));
+ if (!v->value.isNumber()) COMPILE_EXCEPTION(v, tr("Invalid property assignment: number expected"));
break;
case QVariant::Double:
- if (!v->value.isNumber()) COMPILE_EXCEPTION(v, tr("Invalid property assignment: double expected"));
+ if (!v->value.isNumber()) COMPILE_EXCEPTION(v, tr("Invalid property assignment: number expected"));
break;
case QVariant::Color:
{
@@ -815,6 +815,10 @@ bool QDeclarativeCompiler::buildObject(Object *obj, const BindingContext &ctxt)
}
}
+ QDeclarativeCustomParser *cp = 0;
+ if (isCustomParser)
+ cp = output->types.at(obj->type).type->customParser();
+
// Build all explicit properties specified
foreach(Property *prop, obj->properties) {
@@ -825,7 +829,9 @@ bool QDeclarativeCompiler::buildObject(Object *obj, const BindingContext &ctxt)
bool canDefer = false;
if (isCustomParser) {
- if (doesPropertyExist(prop, obj)) {
+ if (doesPropertyExist(prop, obj) &&
+ (!(cp->flags() & QDeclarativeCustomParser::AcceptsAttachedProperties) ||
+ !isAttachedPropertyName(prop->name))) {
int ids = compileState.ids.count();
COMPILE_CHECK(buildProperty(prop, obj, objCtxt));
canDefer = ids == compileState.ids.count();
@@ -876,8 +882,7 @@ bool QDeclarativeCompiler::buildObject(Object *obj, const BindingContext &ctxt)
defaultProperty->release();
// Compile custom parser parts
- if (isCustomParser/* && !customProps.isEmpty()*/) {
- QDeclarativeCustomParser *cp = output->types.at(obj->type).type->customParser();
+ if (isCustomParser && !customProps.isEmpty()) {
cp->clearErrors();
cp->compiler = this;
cp->object = obj;
@@ -1356,7 +1361,7 @@ bool QDeclarativeCompiler::buildSignal(QDeclarativeParser::Property *prop, QDecl
Returns true if (value) property \a prop exists on obj, false otherwise.
*/
bool QDeclarativeCompiler::doesPropertyExist(QDeclarativeParser::Property *prop,
- QDeclarativeParser::Object *obj)
+ QDeclarativeParser::Object *obj)
{
if(isAttachedPropertyName(prop->name) || prop->name == "id")
return true;
@@ -2176,6 +2181,18 @@ int QDeclarativeCompiler::evaluateEnum(const QByteArray& script) const
return -1;
}
+const QMetaObject *QDeclarativeCompiler::resolveType(const QByteArray& name) const
+{
+ QDeclarativeType *qmltype = 0;
+ if (!enginePrivate->importDatabase.resolveType(unit->imports, name, &qmltype,
+ 0, 0, 0, 0))
+ return 0;
+ if (!qmltype)
+ return 0;
+ return qmltype->metaObject();
+}
+
+
// Ensures that the dynamic meta specification on obj is valid
bool QDeclarativeCompiler::checkDynamicMeta(QDeclarativeParser::Object *obj)
{
@@ -2199,6 +2216,10 @@ bool QDeclarativeCompiler::checkDynamicMeta(QDeclarativeParser::Object *obj)
if (QString::fromUtf8(prop.name).at(0).isUpper())
COMPILE_EXCEPTION(&prop, tr("Property names cannot begin with an upper case letter"));
+
+ if (QDeclarativeEnginePrivate::get(engine)->globalClass->illegalNames().contains(prop.name))
+ COMPILE_EXCEPTION(&prop, tr("Illegal property name"));
+
propNames.insert(prop.name);
}
@@ -2208,6 +2229,8 @@ bool QDeclarativeCompiler::checkDynamicMeta(QDeclarativeParser::Object *obj)
COMPILE_EXCEPTION(obj, tr("Duplicate signal name"));
if (QString::fromUtf8(name).at(0).isUpper())
COMPILE_EXCEPTION(obj, tr("Signal names cannot begin with an upper case letter"));
+ if (QDeclarativeEnginePrivate::get(engine)->globalClass->illegalNames().contains(name))
+ COMPILE_EXCEPTION(obj, tr("Illegal signal name"));
methodNames.insert(name);
}
for (int ii = 0; ii < obj->dynamicSlots.count(); ++ii) {
@@ -2216,6 +2239,8 @@ bool QDeclarativeCompiler::checkDynamicMeta(QDeclarativeParser::Object *obj)
COMPILE_EXCEPTION(obj, tr("Duplicate method name"));
if (QString::fromUtf8(name).at(0).isUpper())
COMPILE_EXCEPTION(obj, tr("Method names cannot begin with an upper case letter"));
+ if (QDeclarativeEnginePrivate::get(engine)->globalClass->illegalNames().contains(name))
+ COMPILE_EXCEPTION(obj, tr("Illegal method name"));
methodNames.insert(name);
}
@@ -2424,7 +2449,7 @@ bool QDeclarativeCompiler::buildDynamicMeta(QDeclarativeParser::Object *obj, Dyn
for (int ii = 0; ii < obj->dynamicSlots.count(); ++ii) {
Object::DynamicSlot &s = obj->dynamicSlots[ii];
QByteArray sig(s.name + '(');
- QString funcScript(QLatin1String("(function("));
+ QString funcScript(QLatin1String("(function ") + s.name + QLatin1Char('('));
for (int jj = 0; jj < s.parameterNames.count(); ++jj) {
if (jj) {
diff --git a/src/declarative/qml/qdeclarativecompiler_p.h b/src/declarative/qml/qdeclarativecompiler_p.h
index 908c703..49dc53f 100644
--- a/src/declarative/qml/qdeclarativecompiler_p.h
+++ b/src/declarative/qml/qdeclarativecompiler_p.h
@@ -146,7 +146,7 @@ private:
};
class QMetaObjectBuilder;
-class Q_DECLARATIVE_EXPORT QDeclarativeCompiler
+class Q_AUTOTEST_EXPORT QDeclarativeCompiler
{
Q_DECLARE_TR_FUNCTIONS(QDeclarativeCompiler)
public:
@@ -161,6 +161,7 @@ public:
static bool isSignalPropertyName(const QByteArray &);
int evaluateEnum(const QByteArray& script) const; // for QDeclarativeCustomParser::evaluateEnum
+ const QMetaObject *resolveType(const QByteArray& name) const; // for QDeclarativeCustomParser::resolveType
private:
static void reset(QDeclarativeCompiledData *);
diff --git a/src/declarative/qml/qdeclarativecomponent.cpp b/src/declarative/qml/qdeclarativecomponent.cpp
index b4919ff..36c4b49 100644
--- a/src/declarative/qml/qdeclarativecomponent.cpp
+++ b/src/declarative/qml/qdeclarativecomponent.cpp
@@ -68,37 +68,85 @@ class QByteArray;
/*!
\class QDeclarativeComponent
\since 4.7
- \brief The QDeclarativeComponent class encapsulates a QML component description.
+ \brief The QDeclarativeComponent class encapsulates a QML component definition.
\mainclass
+
+ Components are reusable, encapsulated QML elements with well-defined interfaces.
+ They are often defined in \l {qdeclarativedocuments.html}{Component Files}.
+
+ A QDeclarativeComponent instance can be created from a QML file.
+ For example, if there is a \c main.qml file like this:
+
+ \qml
+ import Qt 4.7
+
+ Item {
+ width: 200
+ height: 200
+ }
+ \endqml
+
+ The following code loads this QML file as a component, creates an instance of
+ this component using create(), and then queries the \l Item's \l {Item::}{width}
+ value:
+
+ \code
+ QDeclarativeEngine *engine = new QDeclarativeEngine;
+ QDeclarativeComponent component(engine, QUrl::fromLocalFile("main.qml"));
+
+ QObject *myObject = component.create();
+ QDeclarativeItem *item = qobject_cast<QDeclarativeItem*>(myObject);
+ int width = item->width(); // width = 200
+ \endcode
+
+ \sa {Using QML in C++ Applications}, {Integrating QML with existing Qt UI code}
*/
/*!
\qmlclass Component QDeclarativeComponent
\since 4.7
- \brief The Component element encapsulates a QML component description.
+ \brief The Component element encapsulates a QML component definition.
Components are reusable, encapsulated QML elements with well-defined interfaces.
- They are often defined in \l {qdeclarativedocuments.html}{Component Files}.
- The \e Component element allows defining components within a QML file.
- This can be useful for reusing a small component within a single QML
- file, or for defining a component that logically belongs with the
- file containing it.
+ Components are often defined by \l {qdeclarativedocuments.html}{component files} -
+ that is, \c .qml files. The \e Component element allows components to be defined
+ within QML items rather than in a separate file. This may be useful for reusing
+ a small component within a QML file, or for defining a component that logically
+ belongs with other QML components within a file.
+
+ For example, here is a component that is used by multiple \l Loader objects:
\qml
Item {
Component {
id: redSquare
+
Rectangle {
color: "red"
width: 10
height: 10
}
}
+
Loader { sourceComponent: redSquare }
Loader { sourceComponent: redSquare; x: 20 }
}
\endqml
+
+ Notice that while a \l Rectangle by itself would be automatically
+ rendered and displayed, this is not the case for the above rectangle
+ because it is defined inside a \c Component. The component encapsulates the
+ QML elements within, as if they were defined in a separate \c .qml
+ file, and is not loaded until requested (in this case, by the
+ two \l Loader objects).
+
+ The Component element is commonly used to provide graphical components
+ for views. For example, the ListView::delegate property requires a Component
+ to specify how each list item is to be displayed.
+
+ Component objects can also be dynamically generated using
+ \l{Qt::createComponent}{Qt.createComponent()}.
*/
/*!
@@ -448,7 +496,8 @@ void QDeclarativeComponent::loadUrl(const QUrl &url)
d->clear();
- if (url.isRelative() && !url.isEmpty())
+ if ((url.isRelative() && !url.isEmpty())
+ || url.scheme() == QLatin1String("file")) // Workaround QTBUG-11929
d->url = d->engine->baseUrl().resolved(url);
else
d->url = url;
@@ -572,7 +621,9 @@ QScriptValue QDeclarativeComponent::createObject(QObject* parent)
{
Q_D(QDeclarativeComponent);
QDeclarativeContext* ctxt = creationContext();
- if(!ctxt)
+ if(!ctxt && d->engine)
+ ctxt = d->engine->rootContext();
+ if (!ctxt)
return QScriptValue(QScriptValue::NullValue);
QObject* ret = create(ctxt);
if (!ret)
diff --git a/src/declarative/qml/qdeclarativecontext.cpp b/src/declarative/qml/qdeclarativecontext.cpp
index 60e9dd3..3d25291 100644
--- a/src/declarative/qml/qdeclarativecontext.cpp
+++ b/src/declarative/qml/qdeclarativecontext.cpp
@@ -145,6 +145,8 @@ QDeclarativeContextPrivate::QDeclarativeContextPrivate()
has been created in that context is an expensive operation (essentially forcing all bindings
to reevaluate). Thus whenever possible you should complete "setup" of the context
before using it to create any objects.
+
+ \sa {Using QML in C++ Applications}
*/
/*! \internal */
diff --git a/src/declarative/qml/qdeclarativecustomparser.cpp b/src/declarative/qml/qdeclarativecustomparser.cpp
index 472a883..97a6a00 100644
--- a/src/declarative/qml/qdeclarativecustomparser.cpp
+++ b/src/declarative/qml/qdeclarativecustomparser.cpp
@@ -295,4 +295,14 @@ int QDeclarativeCustomParser::evaluateEnum(const QByteArray& script) const
return compiler->evaluateEnum(script);
}
+/*!
+ Resolves \a name to a type, or 0 if it is not a type. This can be used
+ to type-check object nodes.
+*/
+const QMetaObject *QDeclarativeCustomParser::resolveType(const QByteArray& name) const
+{
+ return compiler->resolveType(name);
+}
+
+
QT_END_NAMESPACE
diff --git a/src/declarative/qml/qdeclarativecustomparser_p.h b/src/declarative/qml/qdeclarativecustomparser_p.h
index 0e397c5..509e30a 100644
--- a/src/declarative/qml/qdeclarativecustomparser_p.h
+++ b/src/declarative/qml/qdeclarativecustomparser_p.h
@@ -113,10 +113,18 @@ private:
class Q_DECLARATIVE_EXPORT QDeclarativeCustomParser
{
public:
- QDeclarativeCustomParser() : compiler(0), object(0) {}
+ enum Flag {
+ NoFlag = 0x00000000,
+ AcceptsAttachedProperties = 0x00000001
+ };
+ Q_DECLARE_FLAGS(Flags, Flag);
+
+ QDeclarativeCustomParser() : compiler(0), object(0), m_flags(NoFlag) {}
+ QDeclarativeCustomParser(Flags f) : compiler(0), object(0), m_flags(f) {}
virtual ~QDeclarativeCustomParser() {}
void clearErrors();
+ Flags flags() const { return m_flags; }
virtual QByteArray compile(const QList<QDeclarativeCustomParserProperty> &)=0;
virtual void setCustomData(QObject *, const QByteArray &)=0;
@@ -130,12 +138,16 @@ protected:
int evaluateEnum(const QByteArray&) const;
+ const QMetaObject *resolveType(const QByteArray&) const;
+
private:
QList<QDeclarativeError> exceptions;
QDeclarativeCompiler *compiler;
QDeclarativeParser::Object *object;
+ Flags m_flags;
friend class QDeclarativeCompiler;
};
+Q_DECLARE_OPERATORS_FOR_FLAGS(QDeclarativeCustomParser::Flags);
#if 0
#define QML_REGISTER_CUSTOM_TYPE(URI, VERSION_MAJ, VERSION_MIN, NAME, TYPE, CUSTOMTYPE) \
diff --git a/src/declarative/qml/qdeclarativedom.cpp b/src/declarative/qml/qdeclarativedom.cpp
index a3cddb5..5b30bde 100644
--- a/src/declarative/qml/qdeclarativedom.cpp
+++ b/src/declarative/qml/qdeclarativedom.cpp
@@ -493,7 +493,7 @@ int QDeclarativeDomDynamicProperty::propertyType() const
return QMetaType::type("int");
case QDeclarativeParser::Object::DynamicProperty::Real:
- return QMetaType::type("double");
+ return sizeof(qreal) == sizeof(double) ? QMetaType::type("double") : QMetaType::type("float");
case QDeclarativeParser::Object::DynamicProperty::String:
return QMetaType::type("QString");
diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp
index 86053c4..00bc1b7 100644
--- a/src/declarative/qml/qdeclarativeengine.cpp
+++ b/src/declarative/qml/qdeclarativeengine.cpp
@@ -151,6 +151,7 @@ void QDeclarativeEnginePrivate::defineModule()
}
/*!
+\keyword QmlGlobalQtObject
\qmlclass Qt QDeclarativeEnginePrivate
\brief The QML global Qt object provides useful enums and functions from Qt.
@@ -620,24 +621,16 @@ QNetworkAccessManager *QDeclarativeEngine::networkAccessManager() const
/*!
Sets the \a provider to use for images requested via the \e
- image: url scheme, with host \a providerId.
+ image: url scheme, with host \a providerId. The QDeclarativeEngine
+ takes ownership of \a provider.
- QDeclarativeImageProvider allows images to be provided to QML
- asynchronously. The image request will be run in a low priority
- thread. This allows potentially costly image loading to be done in
- the background, without affecting the performance of the UI.
+ Image providers enable support for pixmap and threaded image
+ requests. See the QDeclarativeImageProvider documentation for details on
+ implementing and using image providers.
Note that images loaded from a QDeclarativeImageProvider are cached
by QPixmapCache, similar to any image loaded by QML.
- The QDeclarativeEngine assumes ownership of the provider.
-
- This example creates a provider with id \e colors:
-
- \snippet examples/declarative/cppextensions/imageprovider/imageprovider.cpp 0
-
- \snippet examples/declarative/cppextensions/imageprovider/imageprovider-example.qml 0
-
\sa removeImageProvider()
*/
void QDeclarativeEngine::addImageProvider(const QString &providerId, QDeclarativeImageProvider *provider)
@@ -671,16 +664,35 @@ void QDeclarativeEngine::removeImageProvider(const QString &providerId)
delete d->imageProviders.take(providerId);
}
+QDeclarativeImageProvider::ImageType QDeclarativeEnginePrivate::getImageProviderType(const QUrl &url)
+{
+ QMutexLocker locker(&mutex);
+ QDeclarativeImageProvider *provider = imageProviders.value(url.host());
+ if (provider)
+ return provider->imageType();
+ return static_cast<QDeclarativeImageProvider::ImageType>(-1);
+}
+
QImage QDeclarativeEnginePrivate::getImageFromProvider(const QUrl &url, QSize *size, const QSize& req_size)
{
QMutexLocker locker(&mutex);
QImage image;
QDeclarativeImageProvider *provider = imageProviders.value(url.host());
if (provider)
- image = provider->request(url.path().mid(1), size, req_size);
+ image = provider->requestImage(url.path().mid(1), size, req_size);
return image;
}
+QPixmap QDeclarativeEnginePrivate::getPixmapFromProvider(const QUrl &url, QSize *size, const QSize& req_size)
+{
+ QMutexLocker locker(&mutex);
+ QPixmap pixmap;
+ QDeclarativeImageProvider *provider = imageProviders.value(url.host());
+ if (provider)
+ pixmap = provider->requestPixmap(url.path().mid(1), size, req_size);
+ return pixmap;
+}
+
/*!
Return the base URL for this engine. The base URL is only used to
resolve components when a relative URL is passed to the
@@ -1033,6 +1045,17 @@ QDeclarativeContextData *QDeclarativeEnginePrivate::getContext(QScriptContext *c
return contextClass->contextFromValue(scopeNode);
}
+/*!
+ Returns the QUrl associated with the script \a ctxt for the case that there is
+ no QDeclarativeContext.
+*/
+QUrl QDeclarativeEnginePrivate::getUrl(QScriptContext *ctxt)
+{
+ QScriptValue scopeNode = QScriptDeclarativeClass::scopeChainValue(ctxt, -3);
+ Q_ASSERT(scopeNode.isValid());
+ Q_ASSERT(QScriptDeclarativeClass::scriptClass(scopeNode) == contextClass);
+ return contextClass->urlFromValue(scopeNode);
+}
QString QDeclarativeEnginePrivate::urlToLocalFileOrQrc(const QUrl& url)
{
@@ -1066,7 +1089,9 @@ If you are certain the files will be local, you could simplify to:
\snippet doc/src/snippets/declarative/componentCreation.js 2
To create a QML object from an arbitrary string of QML (instead of a file),
-use \l{Qt::createQmlObject()}{Qt.createQmlObject()}.
+use \l{QML:Qt::createQmlObject()}{Qt.createQmlObject()}.
+
+\sa {Dynamic Object Management}
*/
QScriptValue QDeclarativeEnginePrivate::createComponent(QScriptContext *ctxt, QScriptEngine *engine)
@@ -1075,16 +1100,19 @@ QScriptValue QDeclarativeEnginePrivate::createComponent(QScriptContext *ctxt, QS
static_cast<QDeclarativeScriptEngine*>(engine)->p;
QDeclarativeEngine* activeEngine = activeEnginePriv->q_func();
- QDeclarativeContextData* context = activeEnginePriv->getContext(ctxt);
- Q_ASSERT(context);
-
if(ctxt->argumentCount() != 1) {
return ctxt->throwError(QLatin1String("Qt.createComponent(): Invalid arguments"));
- }else{
+ } else {
+
QString arg = ctxt->argument(0).toString();
if (arg.isEmpty())
return engine->nullValue();
- QUrl url = QUrl(context->resolvedUrl(QUrl(arg)));
+ QUrl url;
+ QDeclarativeContextData* context = activeEnginePriv->getContext(ctxt);
+ if (context)
+ url = QUrl(context->resolvedUrl(QUrl(arg)));
+ else
+ url = activeEnginePriv->getUrl(ctxt).resolved(QUrl(arg));
QDeclarativeComponent *c = new QDeclarativeComponent(activeEngine, url, activeEngine);
QDeclarativeComponentPrivate::get(c)->creationContext = context;
QDeclarativeData::get(c, true)->setImplicitDestructible();
@@ -1110,7 +1138,9 @@ Each object in this array has the members \c lineNumber, \c columnNumber, \c fil
Note that this function returns immediately, and therefore may not work if
the \a qml string loads new components (that is, external QML files that have not yet been loaded).
-If this is the case, consider using \l{Qt::createComponent()}{Qt.createComponent()} instead.
+If this is the case, consider using \l{QML:Qt::createComponent()}{Qt.createComponent()} instead.
+
+\sa {Dynamic Object Management}
*/
QScriptValue QDeclarativeEnginePrivate::createQmlObject(QScriptContext *ctxt, QScriptEngine *engine)
@@ -1245,11 +1275,12 @@ QScriptValue QDeclarativeEnginePrivate::formatDate(QScriptContext*ctxt, QScriptE
QDate date = ctxt->argument(0).toDateTime().date();
Qt::DateFormat enumFormat = Qt::DefaultLocaleShortDate;
if (argCount == 2) {
- if (ctxt->argument(1).isString()) {
- QString format = ctxt->argument(1).toString();
+ QScriptValue formatArg = ctxt->argument(1);
+ if (formatArg.isString()) {
+ QString format = formatArg.toString();
return engine->newVariant(qVariantFromValue(date.toString(format)));
- } else if (ctxt->argument(1).isNumber()) {
- enumFormat = Qt::DateFormat(ctxt->argument(1).toUInt32());
+ } else if (formatArg.isNumber()) {
+ enumFormat = Qt::DateFormat(formatArg.toUInt32());
} else {
return ctxt->throwError(QLatin1String("Qt.formatDate(): Invalid date format"));
}
@@ -1272,11 +1303,12 @@ QScriptValue QDeclarativeEnginePrivate::formatTime(QScriptContext*ctxt, QScriptE
QTime date = ctxt->argument(0).toDateTime().time();
Qt::DateFormat enumFormat = Qt::DefaultLocaleShortDate;
if (argCount == 2) {
- if (ctxt->argument(1).isString()) {
- QString format = ctxt->argument(1).toString();
+ QScriptValue formatArg = ctxt->argument(1);
+ if (formatArg.isString()) {
+ QString format = formatArg.toString();
return engine->newVariant(qVariantFromValue(date.toString(format)));
- } else if (ctxt->argument(1).isNumber()) {
- enumFormat = Qt::DateFormat(ctxt->argument(1).toUInt32());
+ } else if (formatArg.isNumber()) {
+ enumFormat = Qt::DateFormat(formatArg.toUInt32());
} else {
return ctxt->throwError(QLatin1String("Qt.formatTime(): Invalid time format"));
}
@@ -1362,11 +1394,12 @@ QScriptValue QDeclarativeEnginePrivate::formatDateTime(QScriptContext*ctxt, QScr
QDateTime date = ctxt->argument(0).toDateTime();
Qt::DateFormat enumFormat = Qt::DefaultLocaleShortDate;
if (argCount == 2) {
- if (ctxt->argument(1).isString()) {
- QString format = ctxt->argument(1).toString();
+ QScriptValue formatArg = ctxt->argument(1);
+ if (formatArg.isString()) {
+ QString format = formatArg.toString();
return engine->newVariant(qVariantFromValue(date.toString(format)));
- } else if (ctxt->argument(1).isNumber()) {
- enumFormat = Qt::DateFormat(ctxt->argument(1).toUInt32());
+ } else if (formatArg.isNumber()) {
+ enumFormat = Qt::DateFormat(formatArg.toUInt32());
} else {
return ctxt->throwError(QLatin1String("Qt.formatDateTime(): Invalid datetime format"));
}
@@ -1714,8 +1747,7 @@ void QDeclarativeEnginePrivate::warning(QDeclarativeEnginePrivate *engine, const
/*!
\qmlmethod Qt::quit()
This function causes the QDeclarativeEngine::quit() signal to be emitted.
-Within the \l {Qt Declarative UI Runtime}{qml} application this causes the
-launcher application to exit.
+Within the \l {QML Viewer}, this causes the launcher application to exit.
*/
QScriptValue QDeclarativeEnginePrivate::quit(QScriptContext * /*ctxt*/, QScriptEngine *e)
diff --git a/src/declarative/qml/qdeclarativeengine_p.h b/src/declarative/qml/qdeclarativeengine_p.h
index 3269e98..f457b53 100644
--- a/src/declarative/qml/qdeclarativeengine_p.h
+++ b/src/declarative/qml/qdeclarativeengine_p.h
@@ -64,6 +64,7 @@
#include "qdeclarativecontext.h"
#include "private/qdeclarativecontext_p.h"
#include "qdeclarativeexpression.h"
+#include "qdeclarativeimageprovider.h"
#include "private/qdeclarativeproperty_p.h"
#include "private/qdeclarativepropertycache_p.h"
#include "private/qdeclarativeobjectscriptclass_p.h"
@@ -233,7 +234,9 @@ public:
mutable QDeclarativeNetworkAccessManagerFactory *networkAccessManagerFactory;
QHash<QString,QDeclarativeImageProvider*> imageProviders;
+ QDeclarativeImageProvider::ImageType getImageProviderType(const QUrl &url);
QImage getImageFromProvider(const QUrl &url, QSize *size, const QSize& req_size);
+ QPixmap getPixmapFromProvider(const QUrl &url, QSize *size, const QSize& req_size);
mutable QMutex mutex;
@@ -315,6 +318,7 @@ public:
static QDeclarativeEnginePrivate *get(QScriptEngine *e) { return static_cast<QDeclarativeScriptEngine*>(e)->p; }
static QDeclarativeEngine *get(QDeclarativeEnginePrivate *p) { return p->q_func(); }
QDeclarativeContextData *getContext(QScriptContext *);
+ QUrl getUrl(QScriptContext *);
static QString urlToLocalFileOrQrc(const QUrl& url);
diff --git a/src/declarative/qml/qdeclarativeenginedebug.cpp b/src/declarative/qml/qdeclarativeenginedebug.cpp
index 7ae0050..001da46 100644
--- a/src/declarative/qml/qdeclarativeenginedebug.cpp
+++ b/src/declarative/qml/qdeclarativeenginedebug.cpp
@@ -50,6 +50,8 @@
#include "private/qdeclarativecontext_p.h"
#include "private/qdeclarativewatcher_p.h"
#include "private/qdeclarativevaluetype_p.h"
+#include "private/qdeclarativevmemetaobject_p.h"
+#include "private/qdeclarativeexpression_p.h"
#include <QtCore/qdebug.h>
#include <QtCore/qmetaobject.h>
@@ -59,7 +61,7 @@ QT_BEGIN_NAMESPACE
QList<QDeclarativeEngine *> QDeclarativeEngineDebugServer::m_engines;
QDeclarativeEngineDebugServer::QDeclarativeEngineDebugServer(QObject *parent)
: QDeclarativeDebugService(QLatin1String("QDeclarativeEngine"), parent),
- m_watch(new QDeclarativeWatcher(this))
+ m_watch(new QDeclarativeWatcher(this))
{
QObject::connect(m_watch, SIGNAL(propertyChanged(int,int,QMetaProperty,QVariant)),
this, SLOT(propertyChanged(int,int,QMetaProperty,QVariant)));
@@ -99,6 +101,29 @@ QDataStream &operator>>(QDataStream &ds,
return ds;
}
+static inline bool isSignalPropertyName(const QString &signalName)
+{
+ // see QmlCompiler::isSignalPropertyName
+ return signalName.length() >= 3 && signalName.startsWith(QLatin1String("on")) &&
+ signalName.at(2).isLetter() && signalName.at(2).isUpper();
+}
+
+static bool hasValidSignal(QObject *object, const QString &propertyName)
+{
+ if (!isSignalPropertyName(propertyName))
+ return false;
+
+ QString signalName = propertyName.mid(2);
+ signalName[0] = signalName.at(0).toLower();
+
+ int sigIdx = QDeclarativePropertyPrivate::findSignalByName(object->metaObject(), signalName.toLatin1()).methodIndex();
+
+ if (sigIdx == -1)
+ return false;
+
+ return true;
+}
+
QDeclarativeEngineDebugServer::QDeclarativeObjectProperty
QDeclarativeEngineDebugServer::propertyData(QObject *obj, int propIdx)
{
@@ -396,7 +421,6 @@ void QDeclarativeEngineDebugServer::messageReceived(const QByteArray &message)
QByteArray reply;
QDataStream rs(&reply, QIODevice::WriteOnly);
rs << QByteArray("WATCH_EXPR_OBJECT_R") << queryId << ok;
-
sendMessage(reply);
} else if (type == "NO_WATCH") {
int queryId;
@@ -430,9 +454,120 @@ void QDeclarativeEngineDebugServer::messageReceived(const QByteArray &message)
rs << QByteArray("EVAL_EXPRESSION_R") << queryId << result;
sendMessage(reply);
+ } else if (type == "SET_BINDING") {
+ int objectId;
+ QString propertyName;
+ QVariant expr;
+ bool isLiteralValue;
+ ds >> objectId >> propertyName >> expr >> isLiteralValue;
+ setBinding(objectId, propertyName, expr, isLiteralValue);
+ } else if (type == "RESET_BINDING") {
+ int objectId;
+ QString propertyName;
+ ds >> objectId >> propertyName;
+ resetBinding(objectId, propertyName);
+ } else if (type == "SET_METHOD_BODY") {
+ int objectId;
+ QString methodName;
+ QString methodBody;
+ ds >> objectId >> methodName >> methodBody;
+ setMethodBody(objectId, methodName, methodBody);
}
}
+void QDeclarativeEngineDebugServer::setBinding(int objectId,
+ const QString &propertyName,
+ const QVariant &expression,
+ bool isLiteralValue)
+{
+ QObject *object = objectForId(objectId);
+ QDeclarativeContext *context = qmlContext(object);
+
+ if (object && context) {
+
+ if (isLiteralValue) {
+ QDeclarativeProperty literalProperty(object, propertyName, context);
+ literalProperty.write(expression);
+ } else {
+ if (hasValidSignal(object, propertyName)) {
+ QDeclarativeProperty property(object, propertyName);
+ QDeclarativeExpression *declarativeExpression = new QDeclarativeExpression(context, object, expression.toString());
+ QDeclarativePropertyPrivate::setSignalExpression(property, declarativeExpression);
+ } else {
+ QDeclarativeBinding *binding = new QDeclarativeBinding(expression.toString(), object, context);
+ QDeclarativeProperty property(object, propertyName);
+ binding->setTarget(property);
+ binding->setNotifyOnValueChanged(true);
+ QDeclarativeAbstractBinding *oldBinding = QDeclarativePropertyPrivate::setBinding(property, binding);
+ if (oldBinding)
+ oldBinding->destroy();
+ binding->update();
+ }
+ }
+ }
+}
+
+void QDeclarativeEngineDebugServer::resetBinding(int objectId, const QString &propertyName)
+{
+ QObject *object = objectForId(objectId);
+ QDeclarativeContext *context = qmlContext(object);
+
+ if (object && context) {
+ if (object->property(propertyName.toLatin1()).isValid()) {
+ QDeclarativeProperty property(object, propertyName);
+ QDeclarativeAbstractBinding *oldBinding = QDeclarativePropertyPrivate::binding(property);
+ if (oldBinding) {
+ QDeclarativeAbstractBinding *oldBinding = QDeclarativePropertyPrivate::setBinding(property, 0);
+ if (oldBinding)
+ oldBinding->destroy();
+ } else {
+ if (property.isResettable()) {
+ property.reset();
+ }
+ }
+ }
+ }
+}
+
+void QDeclarativeEngineDebugServer::setMethodBody(int objectId, const QString &method, const QString &body)
+{
+ QObject *object = objectForId(objectId);
+ QDeclarativeContext *context = qmlContext(object);
+ if (!object || !context || !context->engine())
+ return;
+ QDeclarativeContextData *contextData = QDeclarativeContextData::get(context);
+ if (!contextData)
+ return;
+
+ QDeclarativePropertyCache::Data dummy;
+ QDeclarativePropertyCache::Data *prop =
+ QDeclarativePropertyCache::property(context->engine(), object, method, dummy);
+
+ if (!prop || !(prop->flags & QDeclarativePropertyCache::Data::IsVMEFunction))
+ return;
+
+ QMetaMethod metaMethod = object->metaObject()->method(prop->coreIndex);
+ QList<QByteArray> paramNames = metaMethod.parameterNames();
+
+ QString paramStr;
+ for (int ii = 0; ii < paramNames.count(); ++ii) {
+ if (ii != 0) paramStr.append(QLatin1String(","));
+ paramStr.append(QString::fromUtf8(paramNames.at(ii)));
+ }
+
+ QString jsfunction = QLatin1String("(function ") + method + QLatin1String("(") + paramStr +
+ QLatin1String(") {");
+ jsfunction += body;
+ jsfunction += QLatin1String("\n})");
+
+ QDeclarativeVMEMetaObject *vmeMetaObject =
+ static_cast<QDeclarativeVMEMetaObject*>(QObjectPrivate::get(object)->metaObject);
+ Q_ASSERT(vmeMetaObject); // the fact we found the property above should guarentee this
+
+ int lineNumber = vmeMetaObject->vmeMethodLineNumber(prop->coreIndex);
+ vmeMetaObject->setVmeMethod(prop->coreIndex, QDeclarativeExpressionPrivate::evalInObjectScope(contextData, object, jsfunction, contextData->url.toString(), lineNumber, 0));
+}
+
void QDeclarativeEngineDebugServer::propertyChanged(int id, int objectId, const QMetaProperty &property, const QVariant &value)
{
QByteArray reply;
diff --git a/src/declarative/qml/qdeclarativeenginedebug_p.h b/src/declarative/qml/qdeclarativeenginedebug_p.h
index 9491411..ea35b40 100644
--- a/src/declarative/qml/qdeclarativeenginedebug_p.h
+++ b/src/declarative/qml/qdeclarativeenginedebug_p.h
@@ -107,6 +107,9 @@ private:
QDeclarativeObjectData objectData(QObject *);
QDeclarativeObjectProperty propertyData(QObject *, int);
QVariant valueContents(const QVariant &defaultValue) const;
+ void setBinding(int objectId, const QString &propertyName, const QVariant &expression, bool isLiteralValue);
+ void resetBinding(int objectId, const QString &propertyName);
+ void setMethodBody(int objectId, const QString &method, const QString &body);
static QList<QDeclarativeEngine *> m_engines;
QDeclarativeWatcher *m_watch;
diff --git a/src/declarative/qml/qdeclarativeexpression.cpp b/src/declarative/qml/qdeclarativeexpression.cpp
index 8ae5f2f..96cdec1 100644
--- a/src/declarative/qml/qdeclarativeexpression.cpp
+++ b/src/declarative/qml/qdeclarativeexpression.cpp
@@ -214,8 +214,30 @@ QScriptValue QDeclarativeExpressionPrivate::evalInObjectScope(QDeclarativeContex
/*!
\class QDeclarativeExpression
- \since 4.7
+ \since 4.7
\brief The QDeclarativeExpression class evaluates JavaScript in a QML context.
+
+ For example, given a file \c main.qml like this:
+
+ \qml
+ import Qt 4.7
+
+ Item {
+ width: 200; height: 200
+ }
+ \endqml
+
+ The following code evaluates a JavaScript expression in the context of the
+ above QML:
+
+ \code
+ QDeclarativeEngine *engine = new QDeclarativeEngine;
+ QDeclarativeComponent component(engine, QUrl::fromLocalFile("main.qml"));
+
+ QObject *myObject = component.create();
+ QDeclarativeExpression *expr = new QDeclarativeExpression(engine->rootContext(), myObject, "width * 2");
+ int result = expr->evaluate().toInt(); // result = 400
+ \endcode
*/
/*!
diff --git a/src/declarative/qml/qdeclarativeextensionplugin.cpp b/src/declarative/qml/qdeclarativeextensionplugin.cpp
index c2e8300..0660599 100644
--- a/src/declarative/qml/qdeclarativeextensionplugin.cpp
+++ b/src/declarative/qml/qdeclarativeextensionplugin.cpp
@@ -67,10 +67,8 @@ QT_BEGIN_NAMESPACE
See \l {Tutorial: Writing QML extensions with C++} for details on creating
QML extensions, including how to build a plugin with with QDeclarativeExtensionPlugin.
For a simple overview, see the \l{declarative/cppextensions/plugins}{plugins} example.
-
- Also see \l {How to Create Qt Plugins} for general Qt plugin documentation.
- \sa QDeclarativeEngine::importPlugin()
+ \sa QDeclarativeEngine::importPlugin(), {How to Create Qt Plugins}
*/
/*!
diff --git a/src/declarative/qml/qdeclarativeglobalscriptclass.cpp b/src/declarative/qml/qdeclarativeglobalscriptclass.cpp
index 39ea101..d43443d 100644
--- a/src/declarative/qml/qdeclarativeglobalscriptclass.cpp
+++ b/src/declarative/qml/qdeclarativeglobalscriptclass.cpp
@@ -41,6 +41,7 @@
#include "private/qdeclarativeglobalscriptclass_p.h"
+#include <QtCore/qstringlist.h>
#include <QtCore/qvector.h>
#include <QtScript/qscriptstring.h>
#include <QtScript/qscriptengine.h>
@@ -57,6 +58,7 @@ QDeclarativeGlobalScriptClass::QDeclarativeGlobalScriptClass(QScriptEngine *engi
: QScriptClass(engine)
{
QString eval = QLatin1String("eval");
+ QString version = QLatin1String("version");
QScriptValue originalGlobalObject = engine->globalObject();
@@ -72,6 +74,9 @@ QDeclarativeGlobalScriptClass::QDeclarativeGlobalScriptClass(QScriptEngine *engi
QString name = iter.name();
+ if (name == version)
+ continue;
+
if (name != eval) {
names.append(name);
values.append(iter.value());
@@ -98,18 +103,7 @@ QDeclarativeGlobalScriptClass::queryProperty(const QScriptValue &object,
Q_UNUSED(name);
Q_UNUSED(flags);
Q_UNUSED(id);
- return HandlesReadAccess | HandlesWriteAccess;
-}
-
-QScriptValue
-QDeclarativeGlobalScriptClass::property(const QScriptValue &object,
- const QScriptString &name,
- uint id)
-{
- Q_UNUSED(object);
- Q_UNUSED(name);
- Q_UNUSED(id);
- return engine()->undefinedValue();
+ return HandlesWriteAccess;
}
void QDeclarativeGlobalScriptClass::setProperty(QScriptValue &object,
@@ -125,8 +119,9 @@ void QDeclarativeGlobalScriptClass::setProperty(QScriptValue &object,
}
/* This method is for the use of tst_qdeclarativeecmascript::callQtInvokables() only */
-void QDeclarativeGlobalScriptClass::explicitSetProperty(const QString &name, const QScriptValue &value)
+void QDeclarativeGlobalScriptClass::explicitSetProperty(const QStringList &names, const QList<QScriptValue> &values)
{
+ Q_ASSERT(names.count() == values.count());
QScriptValue globalObject = engine()->globalObject();
QScriptValue v = engine()->newObject();
@@ -137,7 +132,12 @@ void QDeclarativeGlobalScriptClass::explicitSetProperty(const QString &name, con
v.setProperty(iter.scriptName(), iter.value());
}
- v.setProperty(name, value);
+ for (int ii = 0; ii < names.count(); ++ii) {
+ const QString &name = names.at(ii);
+ const QScriptValue &value = values.at(ii);
+ v.setProperty(name, value);
+ }
+
v.setScriptClass(this);
engine()->setGlobalObject(v);
diff --git a/src/declarative/qml/qdeclarativeglobalscriptclass_p.h b/src/declarative/qml/qdeclarativeglobalscriptclass_p.h
index 414bf02..b42b7bd 100644
--- a/src/declarative/qml/qdeclarativeglobalscriptclass_p.h
+++ b/src/declarative/qml/qdeclarativeglobalscriptclass_p.h
@@ -67,13 +67,10 @@ public:
const QScriptString &name,
QueryFlags flags, uint *id);
- virtual QScriptValue property(const QScriptValue &object,
- const QScriptString &name, uint id);
-
virtual void setProperty(QScriptValue &object, const QScriptString &name,
uint id, const QScriptValue &value);
- void explicitSetProperty(const QString &, const QScriptValue &);
+ void explicitSetProperty(const QStringList &, const QList<QScriptValue> &);
const QScriptValue &staticGlobalObject() const { return m_staticGlobalObject; }
diff --git a/src/declarative/qml/qdeclarativeimageprovider.cpp b/src/declarative/qml/qdeclarativeimageprovider.cpp
index 4be3472..f38da4e 100644
--- a/src/declarative/qml/qdeclarativeimageprovider.cpp
+++ b/src/declarative/qml/qdeclarativeimageprovider.cpp
@@ -43,35 +43,142 @@
QT_BEGIN_NAMESPACE
+class QDeclarativeImageProviderPrivate
+{
+public:
+ QDeclarativeImageProvider::ImageType type;
+};
+
/*!
\class QDeclarativeImageProvider
\since 4.7
- \brief The QDeclarativeImageProvider class provides an interface for threaded image requests in QML.
+ \brief The QDeclarativeImageProvider class provides an interface for supporting pixmaps and threaded image requests in QML.
- QDeclarativeImageProvider can be used by a QDeclarativeEngine to provide images to QML asynchronously.
- The image request will be run in a low priority thread, allowing potentially costly image
- loading to be done in the background, without affecting the performance of the UI.
+ QDeclarativeImageProvider is used to provide advanced image loading features
+ in QML applications. It allows images in QML to be:
- See the QDeclarativeEngine::addImageProvider() documentation for an
- example of how a custom QDeclarativeImageProvider can be constructed and used.
+ \list
+ \o Loaded using QPixmaps rather than actual image files
+ \o Loaded asynchronously in a separate thread, if imageType() is \l ImageType::Image
+ \endlist
- \note the request() method may be called by multiple threads, so ensure the
- implementation of this method is reentrant.
+ To specify that an image should be loaded by an image provider, use the
+ \bold {"image:"} scheme for the URL source of the image, followed by the
+ identifiers of the image provider and the requested image. For example:
+
+ \qml
+ Image { source: "image://myimageprovider/image.png" }
+ \endqml
+
+ This specifies that the image should be loaded by the image provider named
+ "myimageprovider", and the image to be loaded is named "image.png". The QML engine
+ invokes the appropriate image provider according to the providers that have
+ been registered through QDeclarativeEngine::addImageProvider().
+
+
+ \section2 An example
+
+ Here are two images. Their \c source values indicate they should be loaded by
+ an image provider named "colors", and the images to be loaded are "yellow"
+ and "red", respectively:
+
+ \snippet examples/declarative/cppextensions/imageprovider/imageprovider-example.qml 0
+
+ When these images are loaded by QML, it looks for a matching image provider
+ and calls its requestImage() or requestPixmap() method (depending on its
+ imageType()) to load the image. The method is called with the \c id
+ parameter set to "yellow" for the first image, and "red" for the second.
+
+ Here is an image provider implementation that can load the images
+ requested by the above QML. This implementation dynamically
+ generates QPixmap images that are filled with the requested color:
+
+ \snippet examples/declarative/cppextensions/imageprovider/imageprovider.cpp 0
+ \codeline
+ \snippet examples/declarative/cppextensions/imageprovider/imageprovider.cpp 1
+
+ To make this provider accessible to QML, it is registered with the QML engine
+ with a "colors" identifier:
+
+ \code
+ int main(int argc, char *argv[])
+ {
+ ...
+
+ QDeclarativeEngine engine;
+ engine->addImageProvider(QLatin1String("colors"), new ColorPixmapProvider);
+ ...
+ }
+ \endcode
+
+ Now the images can be succesfully loaded in QML:
+
+ \image imageprovider.png
+
+ A complete example is available in Qt's
+ \l {declarative/cppextensions/imageprovider}{examples/declarative/cppextensions/imageprovider}
+ directory. Note the example registers the provider via a \l{QDeclarativeExtensionPlugin}{plugin}
+ instead of registering it in the application \c main() function as shown above.
+
+
+ \section2 Asynchronous image loading
+
+ Image providers that support QImage loading automatically include support
+ for asychronous loading of images. To enable asynchronous loading for an
+ \l Image source, set \l Image::asynchronous to \c true. When this is enabled,
+ the image request to the provider is run in a low priority thread,
+ allowing image loading to be executed in the background, and reducing the
+ performance impact on the user interface.
+
+ Asynchronous loading is not supported for image providers that provide
+ QPixmap rather than QImage values, as pixmaps can only be created in the
+ main thread. In this case, if \l {Image::}{asynchronous} is set to
+ \c true, the value is ignored and the image is loaded
+ synchronously.
+
\sa QDeclarativeEngine::addImageProvider()
*/
/*!
- Destroys the image provider.
- */
+ \enum QDeclarativeImageProvider::ImageType
+
+ Defines the type of image supported by this image provider.
+
+ \value Image The Image Provider provides QImage images. The
+ requestImage() method will be called for all image requests.
+ \value Pixmap The Image Provider provides QPixmap images. The
+ requestPixmap() method will be called for all image requests.
+*/
+
+/*!
+ Creates an image provider that will provide images of the given \a type.
+*/
+QDeclarativeImageProvider::QDeclarativeImageProvider(ImageType type)
+ : d(new QDeclarativeImageProviderPrivate)
+{
+ d->type = type;
+}
+
+/*!
+ \internal
+*/
QDeclarativeImageProvider::~QDeclarativeImageProvider()
{
+ delete d;
}
/*!
- \fn QImage QDeclarativeImageProvider::request(const QString &id, QSize *size, const QSize& requestedSize)
+ Returns the image type supported by this provider.
+*/
+QDeclarativeImageProvider::ImageType QDeclarativeImageProvider::imageType() const
+{
+ return d->type;
+}
- Implement this method to return the image with \a id.
+/*!
+ Implement this method to return the image with \a id. The default
+ implementation returns an empty image.
If \a requestedSize is a valid size, the image returned should be of that size.
@@ -80,5 +187,36 @@ QDeclarativeImageProvider::~QDeclarativeImageProvider()
\note this method may be called by multiple threads, so ensure the
implementation of this method is reentrant.
*/
+QImage QDeclarativeImageProvider::requestImage(const QString &id, QSize *size, const QSize& requestedSize)
+{
+ Q_UNUSED(id);
+ Q_UNUSED(size);
+ Q_UNUSED(requestedSize);
+ if (d->type == Image)
+ qWarning("ImageProvider supports Image type but has not implemented requestImage()");
+ return QImage();
+}
+
+/*!
+ Implement this method to return the pixmap with \a id. The default
+ implementation returns an empty pixmap.
+
+ If \a requestedSize is a valid size, the image returned should be of that size.
+
+ In all cases, \a size must be set to the original size of the image.
+
+ \note this method may be called by multiple threads, so ensure the
+ implementation of this method is reentrant.
+*/
+QPixmap QDeclarativeImageProvider::requestPixmap(const QString &id, QSize *size, const QSize& requestedSize)
+{
+ Q_UNUSED(id);
+ Q_UNUSED(size);
+ Q_UNUSED(requestedSize);
+ if (d->type == Pixmap)
+ qWarning("ImageProvider supports Pixmap type but has not implemented requestPixmap()");
+ return QPixmap();
+}
QT_END_NAMESPACE
+
diff --git a/src/declarative/qml/qdeclarativeimageprovider.h b/src/declarative/qml/qdeclarativeimageprovider.h
index cc9c9af..5a72943 100644
--- a/src/declarative/qml/qdeclarativeimageprovider.h
+++ b/src/declarative/qml/qdeclarativeimageprovider.h
@@ -43,6 +43,7 @@
#define QDECLARATIVEIMAGEPROVIDER_H
#include <QtGui/qimage.h>
+#include <QtGui/qpixmap.h>
QT_BEGIN_HEADER
@@ -50,11 +51,26 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
+class QDeclarativeImageProviderPrivate;
+
class Q_DECLARATIVE_EXPORT QDeclarativeImageProvider
{
public:
+ enum ImageType {
+ Image,
+ Pixmap
+ };
+
+ QDeclarativeImageProvider(ImageType type);
virtual ~QDeclarativeImageProvider();
- virtual QImage request(const QString &id, QSize *size, const QSize& requestedSize) = 0;
+
+ ImageType imageType() const;
+
+ virtual QImage requestImage(const QString &id, QSize *size, const QSize& requestedSize);
+ virtual QPixmap requestPixmap(const QString &id, QSize *size, const QSize& requestedSize);
+
+private:
+ QDeclarativeImageProviderPrivate *d;
};
QT_END_NAMESPACE
diff --git a/src/declarative/qml/qdeclarativeimport.cpp b/src/declarative/qml/qdeclarativeimport.cpp
index a2e3831..8d81b34 100644
--- a/src/declarative/qml/qdeclarativeimport.cpp
+++ b/src/declarative/qml/qdeclarativeimport.cpp
@@ -409,7 +409,8 @@ bool QDeclarativeImportsPrivate::add(const QDeclarativeDirComponents &qmldircomp
QString localFileOrQrc = QDeclarativeEnginePrivate::urlToLocalFileOrQrc(importUrl);
if (!localFileOrQrc.isEmpty()) {
QString dir = QDeclarativeEnginePrivate::urlToLocalFileOrQrc(base.resolved(QUrl(uri)));
- if (dir.isEmpty() || !QDir().exists(dir)) {
+ QFileInfo dirinfo(dir);
+ if (dir.isEmpty() || !dirinfo.exists() || !dirinfo.isDir()) {
if (errorString)
*errorString = QDeclarativeImportDatabase::tr("\"%1\": no such directory").arg(uri_arg);
return false; // local import dirs must exist
@@ -425,7 +426,8 @@ bool QDeclarativeImportsPrivate::add(const QDeclarativeDirComponents &qmldircomp
if (prefix.isEmpty()) {
// directory must at least exist for valid import
QString localFileOrQrc = QDeclarativeEnginePrivate::urlToLocalFileOrQrc(base.resolved(QUrl(uri)));
- if (localFileOrQrc.isEmpty() || !QDir().exists(localFileOrQrc)) {
+ QFileInfo dirinfo(localFileOrQrc);
+ if (localFileOrQrc.isEmpty() || !dirinfo.exists() || !dirinfo.isDir()) {
if (errorString) {
if (localFileOrQrc.isEmpty())
*errorString = QDeclarativeImportDatabase::tr("import \"%1\" has no qmldir and no namespace").arg(uri);
@@ -445,11 +447,23 @@ bool QDeclarativeImportsPrivate::add(const QDeclarativeDirComponents &qmldircomp
if (vmaj > -1 && vmin > -1 && !qmldircomponents.isEmpty()) {
QList<QDeclarativeDirParser::Component>::ConstIterator it = qmldircomponents.begin();
+ int lowest_maj = INT_MAX;
+ int lowest_min = INT_MAX;
+ int highest_maj = INT_MIN;
+ int highest_min = INT_MIN;
for (; it != qmldircomponents.end(); ++it) {
- if (it->majorVersion > vmaj || (it->majorVersion == vmaj && it->minorVersion >= vmin))
- break;
+ if (it->majorVersion > highest_maj || (it->majorVersion == highest_maj && it->minorVersion > highest_min)) {
+ highest_maj = it->majorVersion;
+ highest_min = it->minorVersion;
+ }
+ if (it->majorVersion < lowest_maj || (it->majorVersion == lowest_maj && it->minorVersion < lowest_min)) {
+ lowest_maj = it->majorVersion;
+ lowest_min = it->minorVersion;
+ }
}
- if (it == qmldircomponents.end()) {
+ if (lowest_maj > vmaj || (lowest_maj == vmaj && lowest_min > vmin)
+ || highest_maj < vmaj || (highest_maj == vmaj && highest_min < vmin))
+ {
*errorString = QDeclarativeImportDatabase::tr("module \"%1\" version %2.%3 is not installed").arg(uri_arg).arg(vmaj).arg(vmin);
return false;
}
diff --git a/src/declarative/qml/qdeclarativeinstruction_p.h b/src/declarative/qml/qdeclarativeinstruction_p.h
index 4627eb3..d1a0a0a 100644
--- a/src/declarative/qml/qdeclarativeinstruction_p.h
+++ b/src/declarative/qml/qdeclarativeinstruction_p.h
@@ -58,7 +58,7 @@
QT_BEGIN_NAMESPACE
class QDeclarativeCompiledData;
-class Q_DECLARATIVE_EXPORT QDeclarativeInstruction
+class Q_AUTOTEST_EXPORT QDeclarativeInstruction
{
public:
enum Type {
diff --git a/src/declarative/qml/qdeclarativelist.cpp b/src/declarative/qml/qdeclarativelist.cpp
index 31ef4c2..7c89672 100644
--- a/src/declarative/qml/qdeclarativelist.cpp
+++ b/src/declarative/qml/qdeclarativelist.cpp
@@ -341,6 +341,8 @@ QML list properties are typesafe - in this case \c {Fruit} is a QObject type tha
\note QDeclarativeListProperty can only be used for lists of QObject-derived object pointers.
+\sa {Object and List Property Types}
+
*/
/*!
diff --git a/src/declarative/qml/qdeclarativemetatype.cpp b/src/declarative/qml/qdeclarativemetatype.cpp
index c32cab6..153e2be 100644
--- a/src/declarative/qml/qdeclarativemetatype.cpp
+++ b/src/declarative/qml/qdeclarativemetatype.cpp
@@ -1152,7 +1152,7 @@ bool QDeclarativeMetaType::copy(int type, void *data, const void *copy)
*static_cast<float *>(data) = float(0);
return true;
case QMetaType::Double:
- *static_cast<double *>(data) = double();
+ *static_cast<double *>(data) = double(0);
return true;
case QMetaType::QChar:
*static_cast<NS(QChar) *>(data) = NS(QChar)();
diff --git a/src/declarative/qml/qdeclarativenetworkaccessmanagerfactory.cpp b/src/declarative/qml/qdeclarativenetworkaccessmanagerfactory.cpp
index 399831d..d22798d 100644
--- a/src/declarative/qml/qdeclarativenetworkaccessmanagerfactory.cpp
+++ b/src/declarative/qml/qdeclarativenetworkaccessmanagerfactory.cpp
@@ -62,7 +62,7 @@ QT_BEGIN_NAMESPACE
Note: the create() method may be called by multiple threads, so ensure the
implementation of this method is reentrant.
- \sa QDeclarativeEngine::setNetworkAccessManagerFactory()
+ \sa QDeclarativeEngine::setNetworkAccessManagerFactory(), {declarative/cppextensions/networkaccessmanagerfactory}{NetworkAccessManagerFactory example}
*/
/*!
diff --git a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp
index aca01b2..3af892d 100644
--- a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp
+++ b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp
@@ -797,6 +797,26 @@ QScriptDeclarativeClass::Value MetaCallArgument::toValue(QDeclarativeEngine *e)
}
}
+int QDeclarativeObjectMethodScriptClass::enumType(const QMetaObject *meta, const QString &strname)
+{
+ QByteArray str = strname.toUtf8();
+ QByteArray scope;
+ QByteArray name;
+ int scopeIdx = str.lastIndexOf("::");
+ if (scopeIdx != -1) {
+ scope = str.left(scopeIdx);
+ name = str.mid(scopeIdx + 2);
+ } else {
+ name = str;
+ }
+ for (int i = meta->enumeratorCount() - 1; i >= 0; --i) {
+ QMetaEnum m = meta->enumerator(i);
+ if ((m.name() == name) && (scope.isEmpty() || (m.scope() == scope)))
+ return QVariant::Int;
+ }
+ return QVariant::Invalid;
+}
+
QDeclarativeObjectMethodScriptClass::Value QDeclarativeObjectMethodScriptClass::call(Object *o, QScriptContext *ctxt)
{
MethodData *method = static_cast<MethodData *>(o);
@@ -810,7 +830,9 @@ QDeclarativeObjectMethodScriptClass::Value QDeclarativeObjectMethodScriptClass::
// ### Cache
for (int ii = 0; ii < argTypeNames.count(); ++ii) {
argTypes[ii] = QMetaType::type(argTypeNames.at(ii));
- if (argTypes[ii] == QVariant::Invalid)
+ if (argTypes[ii] == QVariant::Invalid)
+ argTypes[ii] = enumType(method->object->metaObject(), argTypeNames.at(ii));
+ if (argTypes[ii] == QVariant::Invalid)
return Value(ctxt, ctxt->throwError(QString::fromLatin1("Unknown method parameter type: %1").arg(QLatin1String(argTypeNames.at(ii)))));
}
diff --git a/src/declarative/qml/qdeclarativeobjectscriptclass_p.h b/src/declarative/qml/qdeclarativeobjectscriptclass_p.h
index 4b27e53..75e384c 100644
--- a/src/declarative/qml/qdeclarativeobjectscriptclass_p.h
+++ b/src/declarative/qml/qdeclarativeobjectscriptclass_p.h
@@ -80,6 +80,8 @@ protected:
virtual Value property(Object *, const Identifier &);
private:
+ int enumType(const QMetaObject *, const QString &);
+
PersistentIdentifier m_connectId;
PersistentIdentifier m_disconnectId;
QScriptValue m_connect;
diff --git a/src/declarative/qml/qdeclarativetypenamescriptclass.cpp b/src/declarative/qml/qdeclarativetypenamescriptclass.cpp
index 2a3417a..764a8db 100644
--- a/src/declarative/qml/qdeclarativetypenamescriptclass.cpp
+++ b/src/declarative/qml/qdeclarativetypenamescriptclass.cpp
@@ -107,8 +107,7 @@ QDeclarativeTypeNameScriptClass::queryProperty(Object *obj, const Identifier &na
return 0;
}
- } else {
- Q_ASSERT(data->type);
+ } else if (data->type) {
QString strName = toString(name);
@@ -134,6 +133,7 @@ QDeclarativeTypeNameScriptClass::queryProperty(Object *obj, const Identifier &na
if (!object) return 0;
return ep->objectClass->queryProperty(object, name, flags, 0);
}
+
}
return 0;
diff --git a/src/declarative/qml/qdeclarativevmemetaobject.cpp b/src/declarative/qml/qdeclarativevmemetaobject.cpp
index 7aea7cb..689ed92 100644
--- a/src/declarative/qml/qdeclarativevmemetaobject.cpp
+++ b/src/declarative/qml/qdeclarativevmemetaobject.cpp
@@ -751,6 +751,22 @@ void QDeclarativeVMEMetaObject::registerInterceptor(int index, int valueIndex, Q
interceptors.insert(index, qMakePair(valueIndex, interceptor));
}
+int QDeclarativeVMEMetaObject::vmeMethodLineNumber(int index)
+{
+ if (index < methodOffset) {
+ Q_ASSERT(parent);
+ return static_cast<QDeclarativeVMEMetaObject *>(parent)->vmeMethodLineNumber(index);
+ }
+
+ int plainSignals = metaData->signalCount + metaData->propertyCount + metaData->aliasCount;
+ Q_ASSERT(index >= (methodOffset + plainSignals) && index < (methodOffset + plainSignals + metaData->methodCount));
+
+ int rawIndex = index - methodOffset - plainSignals;
+
+ QDeclarativeVMEMetaData::MethodData *data = metaData->methodData() + rawIndex;
+ return data->lineNumber;
+}
+
QScriptValue QDeclarativeVMEMetaObject::vmeMethod(int index)
{
if (index < methodOffset) {
@@ -762,6 +778,20 @@ QScriptValue QDeclarativeVMEMetaObject::vmeMethod(int index)
return method(index - methodOffset - plainSignals);
}
+void QDeclarativeVMEMetaObject::setVmeMethod(int index, const QScriptValue &value)
+{
+ if (index < methodOffset) {
+ Q_ASSERT(parent);
+ return static_cast<QDeclarativeVMEMetaObject *>(parent)->setVmeMethod(index, value);
+ }
+ int plainSignals = metaData->signalCount + metaData->propertyCount + metaData->aliasCount;
+ Q_ASSERT(index >= (methodOffset + plainSignals) && index < (methodOffset + plainSignals + metaData->methodCount));
+
+ if (!methods)
+ methods = new QScriptValue[metaData->methodCount];
+ methods[index - methodOffset - plainSignals] = value;
+}
+
QScriptValue QDeclarativeVMEMetaObject::vmeProperty(int index)
{
if (index < propOffset) {
diff --git a/src/declarative/qml/qdeclarativevmemetaobject_p.h b/src/declarative/qml/qdeclarativevmemetaobject_p.h
index 4fc3269..20ca80b 100644
--- a/src/declarative/qml/qdeclarativevmemetaobject_p.h
+++ b/src/declarative/qml/qdeclarativevmemetaobject_p.h
@@ -121,6 +121,8 @@ public:
void registerInterceptor(int index, int valueIndex, QDeclarativePropertyValueInterceptor *interceptor);
QScriptValue vmeMethod(int index);
+ int vmeMethodLineNumber(int index);
+ void setVmeMethod(int index, const QScriptValue &);
QScriptValue vmeProperty(int index);
void setVMEProperty(int index, const QScriptValue &);
diff --git a/src/declarative/qml/qdeclarativeworkerscript_p.h b/src/declarative/qml/qdeclarativeworkerscript_p.h
index dc73811..2b1f9f9 100644
--- a/src/declarative/qml/qdeclarativeworkerscript_p.h
+++ b/src/declarative/qml/qdeclarativeworkerscript_p.h
@@ -87,7 +87,7 @@ private:
QDeclarativeWorkerScriptEnginePrivate *d;
};
-class Q_DECLARATIVE_EXPORT QDeclarativeWorkerScript : public QObject, public QDeclarativeParserStatus
+class Q_AUTOTEST_EXPORT QDeclarativeWorkerScript : public QObject, public QDeclarativeParserStatus
{
Q_OBJECT
Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
diff --git a/src/declarative/util/qdeclarativeanimation.cpp b/src/declarative/util/qdeclarativeanimation.cpp
index f807866..bdb9510 100644
--- a/src/declarative/util/qdeclarativeanimation.cpp
+++ b/src/declarative/util/qdeclarativeanimation.cpp
@@ -142,6 +142,16 @@ bool QDeclarativeAbstractAnimation::isRunning() const
return d->running;
}
+// the behavior calls this function
+void QDeclarativeAbstractAnimation::notifyRunningChanged(bool running)
+{
+ Q_D(QDeclarativeAbstractAnimation);
+ if (d->disableUserControl && d->running != running) {
+ d->running = running;
+ emit runningChanged(running);
+ }
+}
+
//commence is called to start an animation when it is used as a
//simple animation, and not as part of a transition
void QDeclarativeAbstractAnimationPrivate::commence()
@@ -176,6 +186,8 @@ void QDeclarativeAbstractAnimation::setRunning(bool r)
{
Q_D(QDeclarativeAbstractAnimation);
if (!d->componentComplete) {
+ if (d->running && r == d->running) //don't re-register
+ return;
d->running = r;
if (r == false)
d->avoidPropertyValueSourceStart = true;
diff --git a/src/declarative/util/qdeclarativeanimation_p.h b/src/declarative/util/qdeclarativeanimation_p.h
index 3f8fbdd..59bd465 100644
--- a/src/declarative/util/qdeclarativeanimation_p.h
+++ b/src/declarative/util/qdeclarativeanimation_p.h
@@ -134,9 +134,12 @@ public:
private Q_SLOTS:
void timelineComplete();
void componentFinalized();
-
private:
virtual void setTarget(const QDeclarativeProperty &);
+ void notifyRunningChanged(bool running);
+ friend class QDeclarativeBehavior;
+
+
};
class QDeclarativePauseAnimationPrivate;
diff --git a/src/declarative/util/qdeclarativebehavior.cpp b/src/declarative/util/qdeclarativebehavior.cpp
index 90e0ca3..2bb28c3 100644
--- a/src/declarative/util/qdeclarativebehavior.cpp
+++ b/src/declarative/util/qdeclarativebehavior.cpp
@@ -58,7 +58,8 @@ class QDeclarativeBehaviorPrivate : public QObjectPrivate
{
Q_DECLARE_PUBLIC(QDeclarativeBehavior)
public:
- QDeclarativeBehaviorPrivate() : animation(0), enabled(true), finalized(false) {}
+ QDeclarativeBehaviorPrivate() : animation(0), enabled(true), finalized(false)
+ , blockRunningChanged(false) {}
QDeclarativeProperty property;
QVariant currentValue;
@@ -66,6 +67,7 @@ public:
QDeclarativeGuard<QDeclarativeAbstractAnimation> animation;
bool enabled;
bool finalized;
+ bool blockRunningChanged;
};
/*!
@@ -94,7 +96,7 @@ public:
Currently only a single Behavior may be specified for a property;
this Behavior can be enabled and disabled via the \l{enabled} property.
- \sa QtDeclarative
+ \sa {declarative/animation/behaviors}{Behavior example}, QtDeclarative
*/
@@ -132,9 +134,22 @@ void QDeclarativeBehavior::setAnimation(QDeclarativeAbstractAnimation *animation
if (d->animation) {
d->animation->setDefaultTarget(d->property);
d->animation->setDisableUserControl();
+ connect(d->animation->qtAnimation(),
+ SIGNAL(stateChanged(QAbstractAnimation::State,QAbstractAnimation::State)),
+ this,
+ SLOT(qtAnimationStateChanged(QAbstractAnimation::State,QAbstractAnimation::State)));
}
}
+
+void QDeclarativeBehavior::qtAnimationStateChanged(QAbstractAnimation::State newState,QAbstractAnimation::State)
+{
+ Q_D(QDeclarativeBehavior);
+ if (!d->blockRunningChanged)
+ d->animation->notifyRunningChanged(newState == QAbstractAnimation::Running);
+}
+
+
/*!
\qmlproperty bool Behavior::enabled
Whether the Behavior will be triggered when the property it is tracking changes.
@@ -173,8 +188,11 @@ void QDeclarativeBehavior::write(const QVariant &value)
d->currentValue = d->property.read();
d->targetValue = value;
- if (d->animation->qtAnimation()->duration() != -1)
+ if (d->animation->qtAnimation()->duration() != -1
+ && d->animation->qtAnimation()->state() != QAbstractAnimation::Stopped) {
+ d->blockRunningChanged = true;
d->animation->qtAnimation()->stop();
+ }
QDeclarativeStateOperation::ActionList actions;
QDeclarativeAction action;
@@ -186,6 +204,7 @@ void QDeclarativeBehavior::write(const QVariant &value)
QList<QDeclarativeProperty> after;
d->animation->transition(actions, after, QDeclarativeAbstractAnimation::Forward);
d->animation->qtAnimation()->start();
+ d->blockRunningChanged = false;
if (!after.contains(d->property))
QDeclarativePropertyPrivate::write(d->property, value, QDeclarativePropertyPrivate::BypassInterceptor | QDeclarativePropertyPrivate::DontRemoveBinding);
}
diff --git a/src/declarative/util/qdeclarativebehavior_p.h b/src/declarative/util/qdeclarativebehavior_p.h
index 6c10eec..9801fb2 100644
--- a/src/declarative/util/qdeclarativebehavior_p.h
+++ b/src/declarative/util/qdeclarativebehavior_p.h
@@ -47,6 +47,7 @@
#include <qdeclarativepropertyvaluesource.h>
#include <qdeclarativepropertyvalueinterceptor.h>
#include <qdeclarative.h>
+#include <QtCore/QAbstractAnimation>
QT_BEGIN_HEADER
@@ -85,6 +86,7 @@ Q_SIGNALS:
private Q_SLOTS:
void componentFinalized();
+ void qtAnimationStateChanged(QAbstractAnimation::State,QAbstractAnimation::State);
};
QT_END_NAMESPACE
diff --git a/src/declarative/util/qdeclarativebind_p.h b/src/declarative/util/qdeclarativebind_p.h
index f89c2eb..3dc7dba 100644
--- a/src/declarative/util/qdeclarativebind_p.h
+++ b/src/declarative/util/qdeclarativebind_p.h
@@ -53,7 +53,7 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
class QDeclarativeBindPrivate;
-class Q_DECLARATIVE_EXPORT QDeclarativeBind : public QObject, public QDeclarativeParserStatus
+class Q_AUTOTEST_EXPORT QDeclarativeBind : public QObject, public QDeclarativeParserStatus
{
Q_OBJECT
Q_DECLARE_PRIVATE(QDeclarativeBind)
diff --git a/src/declarative/util/qdeclarativeconnections_p.h b/src/declarative/util/qdeclarativeconnections_p.h
index a914166..e8105b4 100644
--- a/src/declarative/util/qdeclarativeconnections_p.h
+++ b/src/declarative/util/qdeclarativeconnections_p.h
@@ -58,7 +58,7 @@ QT_MODULE(Declarative)
class QDeclarativeBoundSignal;
class QDeclarativeContext;
class QDeclarativeConnectionsPrivate;
-class Q_DECLARATIVE_EXPORT QDeclarativeConnections : public QObject, public QDeclarativeParserStatus
+class Q_AUTOTEST_EXPORT QDeclarativeConnections : public QObject, public QDeclarativeParserStatus
{
Q_OBJECT
Q_DECLARE_PRIVATE(QDeclarativeConnections)
diff --git a/src/declarative/util/qdeclarativefontloader_p.h b/src/declarative/util/qdeclarativefontloader_p.h
index 14335ab..6947547 100644
--- a/src/declarative/util/qdeclarativefontloader_p.h
+++ b/src/declarative/util/qdeclarativefontloader_p.h
@@ -54,7 +54,7 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
class QDeclarativeFontLoaderPrivate;
-class Q_DECLARATIVE_EXPORT QDeclarativeFontLoader : public QObject
+class Q_AUTOTEST_EXPORT QDeclarativeFontLoader : public QObject
{
Q_OBJECT
Q_DECLARE_PRIVATE(QDeclarativeFontLoader)
diff --git a/src/declarative/util/qdeclarativelistaccessor_p.h b/src/declarative/util/qdeclarativelistaccessor_p.h
index d8bb8af..41aacb9 100644
--- a/src/declarative/util/qdeclarativelistaccessor_p.h
+++ b/src/declarative/util/qdeclarativelistaccessor_p.h
@@ -51,7 +51,7 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
class QDeclarativeEngine;
-class Q_DECLARATIVE_EXPORT QDeclarativeListAccessor
+class Q_AUTOTEST_EXPORT QDeclarativeListAccessor
{
public:
QDeclarativeListAccessor();
diff --git a/src/declarative/util/qdeclarativelistmodel.cpp b/src/declarative/util/qdeclarativelistmodel.cpp
index 9ed21a6..3ede335 100644
--- a/src/declarative/util/qdeclarativelistmodel.cpp
+++ b/src/declarative/util/qdeclarativelistmodel.cpp
@@ -551,9 +551,13 @@ bool QDeclarativeListModelParser::compileProperty(const QDeclarativeCustomParser
QDeclarativeCustomParserNode node =
qvariant_cast<QDeclarativeCustomParserNode>(value);
- if (node.name() != "ListElement") {
- error(node, QDeclarativeListModel::tr("ListElement: cannot contain nested elements"));
- return false;
+ if (node.name() != listElementTypeName) {
+ const QMetaObject *mo = resolveType(node.name());
+ if (mo != &QDeclarativeListElement::staticMetaObject) {
+ error(node, QDeclarativeListModel::tr("ListElement: cannot contain nested elements"));
+ return false;
+ }
+ listElementTypeName = node.name(); // cache right name for next time
}
{
@@ -650,6 +654,7 @@ QByteArray QDeclarativeListModelParser::compile(const QList<QDeclarativeCustomPa
{
QList<ListInstruction> instr;
QByteArray data;
+ listElementTypeName = QByteArray(); // unknown
for(int ii = 0; ii < customProps.count(); ++ii) {
const QDeclarativeCustomParserProperty &prop = customProps.at(ii);
@@ -1017,6 +1022,8 @@ QVariant NestedListModel::data(int index, int role) const
Q_ASSERT(_root && index >= 0 && index < _root->values.count());
checkRoles();
QVariant rv;
+ if (roleStrings.count() < role)
+ return rv;
ModelNode *node = qvariant_cast<ModelNode *>(_root->values.at(index));
if (!node)
diff --git a/src/declarative/util/qdeclarativelistmodel_p.h b/src/declarative/util/qdeclarativelistmodel_p.h
index d09062e..6aff9c6 100644
--- a/src/declarative/util/qdeclarativelistmodel_p.h
+++ b/src/declarative/util/qdeclarativelistmodel_p.h
@@ -135,6 +135,8 @@ private:
bool compileProperty(const QDeclarativeCustomParserProperty &prop, QList<ListInstruction> &instr, QByteArray &data);
bool definesEmptyList(const QString &);
+
+ QByteArray listElementTypeName;
};
diff --git a/src/declarative/util/qdeclarativepackage.cpp b/src/declarative/util/qdeclarativepackage.cpp
index 1e49ad9..1a4f2a7 100644
--- a/src/declarative/util/qdeclarativepackage.cpp
+++ b/src/declarative/util/qdeclarativepackage.cpp
@@ -65,12 +65,12 @@ QT_BEGIN_NAMESPACE
\snippet examples/declarative/modelviews/package/Delegate.qml 0
These named items are used as the delegates by the two views who
- reference the special VisualDataModel.parts property to select
+ reference the special \l{VisualDataModel::parts} property to select
a model which provides the chosen delegate.
\snippet examples/declarative/modelviews/package/view.qml 0
- \sa {declarative/modelviews/package}{Package example}, QtDeclarative
+ \sa {declarative/modelviews/package}{Package example}, {demos/declarative/photoviewer}{Photo Viewer demo}, QtDeclarative
*/
/*!
diff --git a/src/declarative/util/qdeclarativepixmapcache.cpp b/src/declarative/util/qdeclarativepixmapcache.cpp
index a4ddf46..00dd922 100644
--- a/src/declarative/util/qdeclarativepixmapcache.cpp
+++ b/src/declarative/util/qdeclarativepixmapcache.cpp
@@ -55,104 +55,209 @@
#include <QFile>
#include <QThread>
#include <QMutex>
+#include <QMutexLocker>
+#include <QWaitCondition>
#include <QBuffer>
#include <QWaitCondition>
#include <QtCore/qdebug.h>
#include <private/qobject_p.h>
#include <QSslError>
-// Maximum number of simultaneous image requests to send.
-static const int maxImageRequestCount = 8;
+#define IMAGEREQUEST_MAX_REQUEST_COUNT 8
+#define IMAGEREQUEST_MAX_REDIRECT_RECURSION 16
+#define CACHE_EXPIRE_TIME 30
+#define CACHE_REMOVAL_FRACTION 4
QT_BEGIN_NAMESPACE
-class QDeclarativeImageReaderEvent : public QEvent
+class QDeclarativePixmapReader;
+class QDeclarativePixmapData;
+class QDeclarativePixmapReply : public QObject
{
+ Q_OBJECT
public:
enum ReadError { NoError, Loading, Decoding };
- QDeclarativeImageReaderEvent(QDeclarativeImageReaderEvent::ReadError err, const QString &errStr, const QImage &img)
- : QEvent(QEvent::User), error(err), errorString(errStr), image(img) {}
+ QDeclarativePixmapReply(QDeclarativePixmapData *);
+ ~QDeclarativePixmapReply();
- ReadError error;
- QString errorString;
- QImage image;
+ QDeclarativePixmapData *data;
+ QDeclarativePixmapReader *reader;
+
+ bool loading;
+ int redirectCount;
+
+ class Event : public QEvent {
+ public:
+ Event(ReadError, const QString &, const QSize &, const QImage &);
+
+ ReadError error;
+ QString errorString;
+ QSize implicitSize;
+ QImage image;
+ };
+ void postReply(ReadError, const QString &, const QSize &, const QImage &);
+
+
+Q_SIGNALS:
+ void finished();
+ void downloadProgress(qint64, qint64);
+
+protected:
+ bool event(QEvent *event);
+
+private:
+ Q_DISABLE_COPY(QDeclarativePixmapReply)
+
+public:
+ static int finishedIndex;
+ static int downloadProgressIndex;
};
-class QDeclarativeImageRequestHandler;
-class QDeclarativeImageReader : public QThread
+class QDeclarativePixmapData;
+class QDeclarativePixmapReader : public QThread
{
Q_OBJECT
public:
- QDeclarativeImageReader(QDeclarativeEngine *eng);
- ~QDeclarativeImageReader();
+ QDeclarativePixmapReader(QDeclarativeEngine *eng);
+ ~QDeclarativePixmapReader();
- QDeclarativePixmapReply *getImage(const QUrl &url, int req_width, int req_height);
+ QDeclarativePixmapReply *getImage(QDeclarativePixmapData *);
void cancel(QDeclarativePixmapReply *rep);
- static QDeclarativeImageReader *instance(QDeclarativeEngine *engine);
+ static QDeclarativePixmapReader *instance(QDeclarativeEngine *engine);
protected:
void run();
+private slots:
+ void networkRequestDone();
+
private:
+ void processJobs();
+ void processJob(QDeclarativePixmapReply *);
+
QList<QDeclarativePixmapReply*> jobs;
QList<QDeclarativePixmapReply*> cancelled;
QDeclarativeEngine *engine;
- QDeclarativeImageRequestHandler *handler;
QObject *eventLoopQuitHack;
+
QMutex mutex;
+ class ThreadObject : public QObject {
+ public:
+ ThreadObject(QDeclarativePixmapReader *);
+ void processJobs();
+ virtual bool event(QEvent *e);
+ private:
+ QDeclarativePixmapReader *reader;
+ } *threadObject;
+ QWaitCondition waitCondition;
+
+ QNetworkAccessManager *networkAccessManager();
+ QNetworkAccessManager *accessManager;
- static QHash<QDeclarativeEngine *,QDeclarativeImageReader*> readers;
+ QHash<QNetworkReply*,QDeclarativePixmapReply*> replies;
+
+ static int replyDownloadProgress;
+ static int replyFinished;
+ static int downloadProgress;
+ static int thisNetworkRequestDone;
+ static QHash<QDeclarativeEngine *,QDeclarativePixmapReader*> readers;
static QMutex readerMutex;
- friend class QDeclarativeImageRequestHandler;
};
-QHash<QDeclarativeEngine *,QDeclarativeImageReader*> QDeclarativeImageReader::readers;
-QMutex QDeclarativeImageReader::readerMutex;
-
-
-class QDeclarativeImageRequestHandler : public QObject
+class QDeclarativePixmapData
{
- Q_OBJECT
public:
- QDeclarativeImageRequestHandler(QDeclarativeImageReader *read, QDeclarativeEngine *eng)
- : QObject(), accessManager(0), engine(eng), reader(read), redirectCount(0)
+ QDeclarativePixmapData(const QUrl &u, const QSize &s, const QString &e)
+ : refCount(1), inCache(false), pixmapStatus(QDeclarativePixmap::Error),
+ url(u), errorString(e), requestSize(s), reply(0), prevUnreferenced(0),
+ prevUnreferencedPtr(0), nextUnreferenced(0)
{
- QCoreApplication::postEvent(this, new QEvent(QEvent::User));
}
- QDeclarativePixmapReply *getImage(const QUrl &url, int req_width, int req_height);
- void cancel(QDeclarativePixmapReply *reply);
-
-protected:
- bool event(QEvent *event);
+ QDeclarativePixmapData(const QUrl &u, const QSize &r)
+ : refCount(1), inCache(false), pixmapStatus(QDeclarativePixmap::Loading),
+ url(u), requestSize(r), reply(0), prevUnreferenced(0), prevUnreferencedPtr(0),
+ nextUnreferenced(0)
+ {
+ }
-private slots:
- void networkRequestDone();
+ QDeclarativePixmapData(const QUrl &u, const QPixmap &p, const QSize &s, const QSize &r)
+ : refCount(1), inCache(false), privatePixmap(false), pixmapStatus(QDeclarativePixmap::Ready),
+ url(u), pixmap(p), implicitSize(s), requestSize(r), reply(0), prevUnreferenced(0),
+ prevUnreferencedPtr(0), nextUnreferenced(0)
+ {
+ }
-private:
- QNetworkAccessManager *networkAccessManager() {
- if (!accessManager)
- accessManager = QDeclarativeEnginePrivate::get(engine)->createNetworkAccessManager(this);
- return accessManager;
+ QDeclarativePixmapData(const QPixmap &p)
+ : refCount(1), inCache(false), privatePixmap(true), pixmapStatus(QDeclarativePixmap::Ready),
+ pixmap(p), implicitSize(p.size()), requestSize(p.size()), reply(0), prevUnreferenced(0),
+ prevUnreferencedPtr(0), nextUnreferenced(0)
+ {
}
- QHash<QNetworkReply*,QDeclarativePixmapReply*> replies;
- QNetworkAccessManager *accessManager;
- QDeclarativeEngine *engine;
- QDeclarativeImageReader *reader;
- int redirectCount;
+ int cost() const;
+ void addref();
+ void release();
+ void addToCache();
+ void removeFromCache();
- static int replyDownloadProgress;
- static int replyFinished;
- static int downloadProgress;
- static int thisNetworkRequestDone;
+ uint refCount;
+
+ bool inCache:1;
+ bool privatePixmap:1;
+
+ QDeclarativePixmap::Status pixmapStatus;
+ QUrl url;
+ QString errorString;
+ QPixmap pixmap;
+ QSize implicitSize;
+ QSize requestSize;
+
+ QDeclarativePixmapReply *reply;
+
+ QDeclarativePixmapData *prevUnreferenced;
+ QDeclarativePixmapData**prevUnreferencedPtr;
+ QDeclarativePixmapData *nextUnreferenced;
};
-//===========================================================================
+int QDeclarativePixmapReply::finishedIndex = -1;
+int QDeclarativePixmapReply::downloadProgressIndex = -1;
+
+// XXX
+QHash<QDeclarativeEngine *,QDeclarativePixmapReader*> QDeclarativePixmapReader::readers;
+QMutex QDeclarativePixmapReader::readerMutex;
+
+int QDeclarativePixmapReader::replyDownloadProgress = -1;
+int QDeclarativePixmapReader::replyFinished = -1;
+int QDeclarativePixmapReader::downloadProgress = -1;
+int QDeclarativePixmapReader::thisNetworkRequestDone = -1;
-static bool readImage(const QUrl& url, QIODevice *dev, QImage *image, QString *errorString, QSize *impsize, int req_width, int req_height)
+
+void QDeclarativePixmapReply::postReply(ReadError error, const QString &errorString,
+ const QSize &implicitSize, const QImage &image)
+{
+ loading = false;
+ QCoreApplication::postEvent(this, new Event(error, errorString, implicitSize, image));
+}
+
+QDeclarativePixmapReply::Event::Event(ReadError e, const QString &s, const QSize &iSize, const QImage &i)
+: QEvent(QEvent::User), error(e), errorString(s), implicitSize(iSize), image(i)
+{
+}
+
+QNetworkAccessManager *QDeclarativePixmapReader::networkAccessManager()
+{
+ if (!accessManager) {
+ Q_ASSERT(threadObject);
+ accessManager = QDeclarativeEnginePrivate::get(engine)->createNetworkAccessManager(threadObject);
+ }
+ return accessManager;
+}
+
+static bool readImage(const QUrl& url, QIODevice *dev, QImage *image, QString *errorString, QSize *impsize,
+ const QSize &requestSize)
{
QImageReader imgio(dev);
@@ -163,17 +268,17 @@ static bool readImage(const QUrl& url, QIODevice *dev, QImage *image, QString *e
}
bool scaled = false;
- if (req_width > 0 || req_height > 0) {
+ if (requestSize.width() > 0 || requestSize.height() > 0) {
QSize s = imgio.size();
- if (req_width && (force_scale || req_width < s.width())) {
- if (req_height <= 0)
- s.setHeight(s.height()*req_width/s.width());
- s.setWidth(req_width); scaled = true;
+ if (requestSize.width() && (force_scale || requestSize.width() < s.width())) {
+ if (requestSize.height() <= 0)
+ s.setHeight(s.height()*requestSize.width()/s.width());
+ s.setWidth(requestSize.width()); scaled = true;
}
- if (req_height && (force_scale || req_height < s.height())) {
- if (req_width <= 0)
- s.setWidth(s.width()*req_height/s.height());
- s.setHeight(req_height); scaled = true;
+ if (requestSize.height() && (force_scale || requestSize.height() < s.height())) {
+ if (requestSize.width() <= 0)
+ s.setWidth(s.width()*requestSize.height()/s.height());
+ s.setHeight(requestSize.height()); scaled = true;
}
if (scaled) { imgio.setScaledSize(s); }
}
@@ -187,200 +292,196 @@ static bool readImage(const QUrl& url, QIODevice *dev, QImage *image, QString *e
return true;
} else {
if (errorString)
- *errorString = QDeclarativePixmapCache::tr("Error decoding: %1: %2").arg(url.toString())
+ *errorString = QDeclarativePixmap::tr("Error decoding: %1: %2").arg(url.toString())
.arg(imgio.errorString());
return false;
}
}
-
-//===========================================================================
-
-int QDeclarativeImageRequestHandler::replyDownloadProgress = -1;
-int QDeclarativeImageRequestHandler::replyFinished = -1;
-int QDeclarativeImageRequestHandler::downloadProgress = -1;
-int QDeclarativeImageRequestHandler::thisNetworkRequestDone = -1;
-
-typedef QHash<QUrl, QSize> QDeclarativePixmapSizeHash;
-Q_GLOBAL_STATIC(QDeclarativePixmapSizeHash, qmlOriginalSizes);
-
-bool QDeclarativeImageRequestHandler::event(QEvent *event)
+QDeclarativePixmapReader::QDeclarativePixmapReader(QDeclarativeEngine *eng)
+: QThread(eng), engine(eng), threadObject(0), accessManager(0)
{
- if (event->type() == QEvent::User) {
- if (replyDownloadProgress == -1) {
- replyDownloadProgress = QNetworkReply::staticMetaObject.indexOfSignal("downloadProgress(qint64,qint64)");
- replyFinished = QNetworkReply::staticMetaObject.indexOfSignal("finished()");
- downloadProgress = QDeclarativePixmapReply::staticMetaObject.indexOfSignal("downloadProgress(qint64,qint64)");
- thisNetworkRequestDone = QDeclarativeImageRequestHandler::staticMetaObject.indexOfSlot("networkRequestDone()");
- }
-
- while (1) {
- reader->mutex.lock();
-
- if (reader->cancelled.count()) {
- for (int i = 0; i < reader->cancelled.count(); ++i) {
- QDeclarativePixmapReply *job = reader->cancelled.at(i);
- // cancel any jobs already started
- QNetworkReply *reply = replies.key(job, 0);
- if (reply && reply->isRunning()) {
- replies.remove(reply);
- reply->close();
- }
- // remove from pending job list
- for (int j = 0; j < reader->jobs.count(); ++j) {
- if (reader->jobs.at(j) == job) {
- reader->jobs.removeAt(j);
- job->release(true);
- break;
- }
- }
- }
- reader->cancelled.clear();
- }
-
- if (!reader->jobs.count() || replies.count() > maxImageRequestCount) {
- reader->mutex.unlock();
- break;
- }
+ eventLoopQuitHack = new QObject;
+ eventLoopQuitHack->moveToThread(this);
+ connect(eventLoopQuitHack, SIGNAL(destroyed(QObject*)), SLOT(quit()), Qt::DirectConnection);
+ start(QThread::IdlePriority);
+}
- QDeclarativePixmapReply *runningJob = reader->jobs.takeLast();
- QUrl url = runningJob->url();
- reader->mutex.unlock();
-
- // fetch
- if (url.scheme() == QLatin1String("image")) {
- // Use QmlImageProvider
- QSize read_impsize;
- QImage image = QDeclarativeEnginePrivate::get(engine)->getImageFromProvider(url, &read_impsize, QSize(runningJob->forcedWidth(),runningJob->forcedHeight()));
- qmlOriginalSizes()->insert(url, read_impsize);
- QDeclarativeImageReaderEvent::ReadError errorCode = QDeclarativeImageReaderEvent::NoError;
- QString errorStr;
- if (image.isNull()) {
- errorCode = QDeclarativeImageReaderEvent::Loading;
- errorStr = QDeclarativePixmapCache::tr("Failed to get image from provider: %1").arg(url.toString());
- }
- QCoreApplication::postEvent(runningJob, new QDeclarativeImageReaderEvent(errorCode, errorStr, image));
- } else {
- QString lf = QDeclarativeEnginePrivate::urlToLocalFileOrQrc(url);
- if (!lf.isEmpty()) {
- // Image is local - load/decode immediately
- QImage image;
- QDeclarativeImageReaderEvent::ReadError errorCode = QDeclarativeImageReaderEvent::NoError;
- QString errorStr;
- QFile f(lf);
- if (f.open(QIODevice::ReadOnly)) {
- QSize read_impsize;
- if (readImage(url, &f, &image, &errorStr, &read_impsize, runningJob->forcedWidth(),runningJob->forcedHeight())) {
- qmlOriginalSizes()->insert(url, read_impsize);
- } else {
- errorCode = QDeclarativeImageReaderEvent::Loading;
- }
- } else {
- errorStr = QDeclarativePixmapCache::tr("Cannot open: %1").arg(url.toString());
- errorCode = QDeclarativeImageReaderEvent::Loading;
- }
- QCoreApplication::postEvent(runningJob, new QDeclarativeImageReaderEvent(errorCode, errorStr, image));
- } else {
- // Network resource
- QNetworkRequest req(url);
- req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true);
- QNetworkReply *reply = networkAccessManager()->get(req);
-
- QMetaObject::connect(reply, replyDownloadProgress, runningJob, downloadProgress);
- QMetaObject::connect(reply, replyFinished, this, thisNetworkRequestDone);
-
- replies.insert(reply, runningJob);
- }
- }
- }
- return true;
- }
+QDeclarativePixmapReader::~QDeclarativePixmapReader()
+{
+ readerMutex.lock();
+ readers.remove(engine);
+ readerMutex.unlock();
- return QObject::event(event);
+ eventLoopQuitHack->deleteLater();
+ wait();
}
-#define IMAGEREQUESTHANDLER_MAX_REDIRECT_RECURSION 16
-
-void QDeclarativeImageRequestHandler::networkRequestDone()
+void QDeclarativePixmapReader::networkRequestDone()
{
QNetworkReply *reply = static_cast<QNetworkReply *>(sender());
QDeclarativePixmapReply *job = replies.take(reply);
- redirectCount++;
- if (redirectCount < IMAGEREQUESTHANDLER_MAX_REDIRECT_RECURSION) {
- QVariant redirect = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
- if (redirect.isValid()) {
- QUrl url = reply->url().resolved(redirect.toUrl());
- QNetworkRequest req(url);
- req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true);
-
- reply->deleteLater();
- reply = networkAccessManager()->get(req);
-
- QMetaObject::connect(reply, replyDownloadProgress, job, downloadProgress);
- QMetaObject::connect(reply, replyFinished, this, thisNetworkRequestDone);
-
- replies.insert(reply, job);
- return;
+ if (job) {
+ job->redirectCount++;
+ if (job->redirectCount < IMAGEREQUEST_MAX_REDIRECT_RECURSION) {
+ QVariant redirect = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
+ if (redirect.isValid()) {
+ QUrl url = reply->url().resolved(redirect.toUrl());
+ QNetworkRequest req(url);
+ req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true);
+
+ reply->deleteLater();
+ reply = networkAccessManager()->get(req);
+
+ QMetaObject::connect(reply, replyDownloadProgress, job, downloadProgress);
+ QMetaObject::connect(reply, replyFinished, this, thisNetworkRequestDone);
+
+ replies.insert(reply, job);
+ return;
+ }
}
- }
- redirectCount=0;
- if (job) {
QImage image;
- QDeclarativeImageReaderEvent::ReadError error;
+ QDeclarativePixmapReply::ReadError error = QDeclarativePixmapReply::NoError;
QString errorString;
+ QSize readSize;
if (reply->error()) {
- error = QDeclarativeImageReaderEvent::Loading;
+ error = QDeclarativePixmapReply::Loading;
errorString = reply->errorString();
} else {
- QSize read_impsize;
QByteArray all = reply->readAll();
QBuffer buff(&all);
buff.open(QIODevice::ReadOnly);
- if (readImage(reply->url(), &buff, &image, &errorString, &read_impsize, job->forcedWidth(), job->forcedHeight())) {
- qmlOriginalSizes()->insert(reply->url(), read_impsize);
- error = QDeclarativeImageReaderEvent::NoError;
- } else {
- error = QDeclarativeImageReaderEvent::Decoding;
+ if (!readImage(reply->url(), &buff, &image, &errorString, &readSize, job->data->requestSize)) {
+ error = QDeclarativePixmapReply::Decoding;
}
}
// send completion event to the QDeclarativePixmapReply
- QCoreApplication::postEvent(job, new QDeclarativeImageReaderEvent(error, errorString, image));
+ mutex.lock();
+ if (!cancelled.contains(job)) job->postReply(error, errorString, readSize, image);
+ mutex.unlock();
}
- // kick off event loop again if we have dropped below max request count
- if (replies.count() == maxImageRequestCount)
- QCoreApplication::postEvent(this, new QEvent(QEvent::User));
reply->deleteLater();
+
+ // kick off event loop again incase we have dropped below max request count
+ threadObject->processJobs();
}
-//===========================================================================
+QDeclarativePixmapReader::ThreadObject::ThreadObject(QDeclarativePixmapReader *i)
+: reader(i)
+{
+}
-QDeclarativeImageReader::QDeclarativeImageReader(QDeclarativeEngine *eng)
- : QThread(eng), engine(eng), handler(0)
+void QDeclarativePixmapReader::ThreadObject::processJobs()
+{
+ QCoreApplication::postEvent(this, new QEvent(QEvent::User));
+}
+
+bool QDeclarativePixmapReader::ThreadObject::event(QEvent *e)
{
- eventLoopQuitHack = new QObject;
- eventLoopQuitHack->moveToThread(this);
- connect(eventLoopQuitHack, SIGNAL(destroyed(QObject*)), SLOT(quit()), Qt::DirectConnection);
- start(QThread::IdlePriority);
+ if (e->type() == QEvent::User) {
+ reader->processJobs();
+ return true;
+ } else {
+ return QObject::event(e);
+ }
}
-QDeclarativeImageReader::~QDeclarativeImageReader()
+void QDeclarativePixmapReader::processJobs()
{
- readerMutex.lock();
- readers.remove(engine);
- readerMutex.unlock();
+ QMutexLocker locker(&mutex);
+
+ while (true) {
+ if (cancelled.isEmpty() && (jobs.isEmpty() || replies.count() >= IMAGEREQUEST_MAX_REQUEST_COUNT))
+ return; // Nothing else to do
+
+ // Clean cancelled jobs
+ if (cancelled.count()) {
+ for (int i = 0; i < cancelled.count(); ++i) {
+ QDeclarativePixmapReply *job = cancelled.at(i);
+ QNetworkReply *reply = replies.key(job, 0);
+ if (reply && reply->isRunning()) {
+ // cancel any jobs already started
+ replies.remove(reply);
+ reply->close();
+ }
+ delete job;
+ }
+ cancelled.clear();
+ }
- eventLoopQuitHack->deleteLater();
- wait();
+ if (!jobs.isEmpty() && replies.count() < IMAGEREQUEST_MAX_REQUEST_COUNT) {
+ QDeclarativePixmapReply *runningJob = jobs.takeLast();
+ runningJob->loading = true;
+
+ locker.unlock();
+ processJob(runningJob);
+ locker.relock();
+ }
+ }
+}
+
+void QDeclarativePixmapReader::processJob(QDeclarativePixmapReply *runningJob)
+{
+ QUrl url = runningJob->data->url;
+
+ // fetch
+ if (url.scheme() == QLatin1String("image")) {
+ // Use QmlImageProvider
+ QSize readSize;
+ QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine);
+ QImage image = ep->getImageFromProvider(url, &readSize, runningJob->data->requestSize);
+
+ QDeclarativePixmapReply::ReadError errorCode = QDeclarativePixmapReply::NoError;
+ QString errorStr;
+ if (image.isNull()) {
+ errorCode = QDeclarativePixmapReply::Loading;
+ errorStr = QDeclarativePixmap::tr("Failed to get image from provider: %1").arg(url.toString());
+ }
+
+ mutex.lock();
+ if (!cancelled.contains(runningJob)) runningJob->postReply(errorCode, errorStr, readSize, image);
+ mutex.unlock();
+ } else {
+ QString lf = QDeclarativeEnginePrivate::urlToLocalFileOrQrc(url);
+ if (!lf.isEmpty()) {
+ // Image is local - load/decode immediately
+ QImage image;
+ QDeclarativePixmapReply::ReadError errorCode = QDeclarativePixmapReply::NoError;
+ QString errorStr;
+ QFile f(lf);
+ QSize readSize;
+ if (f.open(QIODevice::ReadOnly)) {
+ if (!readImage(url, &f, &image, &errorStr, &readSize, runningJob->data->requestSize))
+ errorCode = QDeclarativePixmapReply::Loading;
+ } else {
+ errorStr = QDeclarativePixmap::tr("Cannot open: %1").arg(url.toString());
+ errorCode = QDeclarativePixmapReply::Loading;
+ }
+ mutex.lock();
+ if (!cancelled.contains(runningJob)) runningJob->postReply(errorCode, errorStr, readSize, image);
+ mutex.unlock();
+ } else {
+ // Network resource
+ QNetworkRequest req(url);
+ req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true);
+ QNetworkReply *reply = networkAccessManager()->get(req);
+
+ QMetaObject::connect(reply, replyDownloadProgress, runningJob, downloadProgress);
+ QMetaObject::connect(reply, replyFinished, this, thisNetworkRequestDone);
+
+ replies.insert(reply, runningJob);
+ }
+ }
}
-QDeclarativeImageReader *QDeclarativeImageReader::instance(QDeclarativeEngine *engine)
+QDeclarativePixmapReader *QDeclarativePixmapReader::instance(QDeclarativeEngine *engine)
{
readerMutex.lock();
- QDeclarativeImageReader *reader = readers.value(engine);
+ QDeclarativePixmapReader *reader = readers.value(engine);
if (!reader) {
- reader = new QDeclarativeImageReader(engine);
+ reader = new QDeclarativePixmapReader(engine);
readers.insert(engine, reader);
}
readerMutex.unlock();
@@ -388,342 +489,558 @@ QDeclarativeImageReader *QDeclarativeImageReader::instance(QDeclarativeEngine *e
return reader;
}
-QDeclarativePixmapReply *QDeclarativeImageReader::getImage(const QUrl &url, int req_width, int req_height)
+QDeclarativePixmapReply *QDeclarativePixmapReader::getImage(QDeclarativePixmapData *data)
{
mutex.lock();
- QDeclarativePixmapReply *reply = new QDeclarativePixmapReply(this, url, req_width, req_height);
- reply->addRef();
- reply->setLoading();
+ QDeclarativePixmapReply *reply = new QDeclarativePixmapReply(data);
+ reply->reader = this;
jobs.append(reply);
- if (jobs.count() == 1 && handler)
- QCoreApplication::postEvent(handler, new QEvent(QEvent::User));
+ // XXX
+ if (threadObject) threadObject->processJobs();
mutex.unlock();
return reply;
}
-void QDeclarativeImageReader::cancel(QDeclarativePixmapReply *reply)
+void QDeclarativePixmapReader::cancel(QDeclarativePixmapReply *reply)
{
mutex.lock();
- if (reply->isLoading()) {
- // Add to cancel list to be cancelled in reader thread.
+ if (reply->loading) {
cancelled.append(reply);
- if (cancelled.count() == 1 && handler)
- QCoreApplication::postEvent(handler, new QEvent(QEvent::User));
+ // XXX
+ if (threadObject) threadObject->processJobs();
+ } else {
+ jobs.removeAll(reply);
+ delete reply;
}
mutex.unlock();
}
-void QDeclarativeImageReader::run()
+void QDeclarativePixmapReader::run()
{
- readerMutex.lock();
- handler = new QDeclarativeImageRequestHandler(this, engine);
- readerMutex.unlock();
+ if (replyDownloadProgress == -1) {
+ const QMetaObject *nr = &QNetworkReply::staticMetaObject;
+ const QMetaObject *pr = &QDeclarativePixmapReply::staticMetaObject;
+ const QMetaObject *ir = &QDeclarativePixmapReader::staticMetaObject;
+ replyDownloadProgress = nr->indexOfSignal("downloadProgress(qint64,qint64)");
+ replyFinished = nr->indexOfSignal("finished()");
+ downloadProgress = pr->indexOfSignal("downloadProgress(qint64,qint64)");
+ thisNetworkRequestDone = ir->indexOfSlot("networkRequestDone()");
+ }
+ mutex.lock();
+ threadObject = new ThreadObject(this);
+ mutex.unlock();
+
+ processJobs();
exec();
- delete handler;
- handler = 0;
+ delete threadObject;
+ threadObject = 0;
}
-//===========================================================================
-
-/*!
- \internal
- \class QDeclarativePixmapCache
- \brief Enacapsultes a pixmap for QDeclarativeGraphics items.
+class QDeclarativePixmapKey
+{
+public:
+ const QUrl *url;
+ const QSize *size;
+};
- This class is NOT reentrant.
- */
+inline bool operator==(const QDeclarativePixmapKey &lhs, const QDeclarativePixmapKey &rhs)
+{
+ return *lhs.size == *rhs.size && *lhs.url == *rhs.url;
+}
-typedef QHash<QUrl, QDeclarativePixmapReply *> QDeclarativePixmapReplyHash;
-Q_GLOBAL_STATIC(QDeclarativePixmapReplyHash, qmlActivePixmapReplies);
+inline uint qHash(const QDeclarativePixmapKey &key)
+{
+ return qHash(*key.url) ^ key.size->width() ^ key.size->height();
+}
-class QDeclarativePixmapReplyPrivate : public QObjectPrivate
+class QDeclarativePixmapStore : public QObject
{
- Q_DECLARE_PUBLIC(QDeclarativePixmapReply)
+ Q_OBJECT
+public:
+ QDeclarativePixmapStore();
+
+ void unreferencePixmap(QDeclarativePixmapData *);
+ void referencePixmap(QDeclarativePixmapData *);
+
+protected:
+ virtual void timerEvent(QTimerEvent *);
public:
- QDeclarativePixmapReplyPrivate(QDeclarativeImageReader *r, const QUrl &u, int req_width, int req_height)
- : QObjectPrivate(), refCount(1), url(u), status(QDeclarativePixmapReply::Loading), loading(false), reader(r),
- forced_width(req_width), forced_height(req_height)
- {
- }
+ QHash<QDeclarativePixmapKey, QDeclarativePixmapData *> m_cache;
- int refCount;
- QUrl url;
- QPixmap pixmap; // ensure reference to pixmap so QPixmapCache does not discard
- QDeclarativePixmapReply::Status status;
- bool loading;
- QDeclarativeImageReader *reader;
- int forced_width, forced_height;
- QString errorString;
-};
+private:
+ QDeclarativePixmapData *m_unreferencedPixmaps;
+ QDeclarativePixmapData *m_lastUnreferencedPixmap;
+ int m_unreferencedCost;
+ int m_timerId;
+};
+Q_GLOBAL_STATIC(QDeclarativePixmapStore, pixmapStore);
-QDeclarativePixmapReply::QDeclarativePixmapReply(QDeclarativeImageReader *reader, const QUrl &url, int req_width, int req_height)
- : QObject(*new QDeclarativePixmapReplyPrivate(reader, url, req_width, req_height), 0)
+QDeclarativePixmapStore::QDeclarativePixmapStore()
+: m_unreferencedPixmaps(0), m_lastUnreferencedPixmap(0), m_unreferencedCost(0), m_timerId(-1)
{
}
-QDeclarativePixmapReply::~QDeclarativePixmapReply()
+void QDeclarativePixmapStore::unreferencePixmap(QDeclarativePixmapData *data)
{
+ Q_ASSERT(data->prevUnreferenced == 0);
+ Q_ASSERT(data->prevUnreferencedPtr == 0);
+ Q_ASSERT(data->nextUnreferenced == 0);
+
+ data->nextUnreferenced = m_unreferencedPixmaps;
+ data->prevUnreferencedPtr = &m_unreferencedPixmaps;
+
+ m_unreferencedPixmaps = data;
+ if (m_unreferencedPixmaps->nextUnreferenced) {
+ m_unreferencedPixmaps->nextUnreferenced->prevUnreferenced = m_unreferencedPixmaps;
+ m_unreferencedPixmaps->nextUnreferenced->prevUnreferencedPtr = &m_unreferencedPixmaps->nextUnreferenced;
+ }
+
+ if (!m_lastUnreferencedPixmap)
+ m_lastUnreferencedPixmap = data;
+
+ m_unreferencedCost += data->cost();
+
+ if (m_timerId == -1)
+ startTimer(CACHE_EXPIRE_TIME * 1000);
}
-const QUrl &QDeclarativePixmapReply::url() const
+void QDeclarativePixmapStore::referencePixmap(QDeclarativePixmapData *data)
{
- Q_D(const QDeclarativePixmapReply);
- return d->url;
+ Q_ASSERT(data->prevUnreferencedPtr);
+
+ *data->prevUnreferencedPtr = data->nextUnreferenced;
+ if (data->nextUnreferenced) {
+ data->nextUnreferenced->prevUnreferencedPtr = data->prevUnreferencedPtr;
+ data->nextUnreferenced->prevUnreferenced = data->prevUnreferenced;
+ }
+ if (m_lastUnreferencedPixmap == data)
+ m_lastUnreferencedPixmap = data->prevUnreferenced;
+
+ data->nextUnreferenced = 0;
+ data->prevUnreferencedPtr = 0;
+ data->prevUnreferenced = 0;
+
+ m_unreferencedCost -= data->cost();
}
-int QDeclarativePixmapReply::forcedWidth() const
+void QDeclarativePixmapStore::timerEvent(QTimerEvent *)
{
- Q_D(const QDeclarativePixmapReply);
- return d->forced_width;
+ int removalCost = m_unreferencedCost / CACHE_REMOVAL_FRACTION;
+
+ while (removalCost > 0 && m_lastUnreferencedPixmap) {
+ QDeclarativePixmapData *data = m_lastUnreferencedPixmap;
+ Q_ASSERT(data->nextUnreferenced == 0);
+
+ *data->prevUnreferencedPtr = 0;
+ m_lastUnreferencedPixmap = data->prevUnreferenced;
+ data->prevUnreferencedPtr = 0;
+ data->prevUnreferenced = 0;
+
+ removalCost -= data->cost();
+ data->removeFromCache();
+ delete data;
+ }
+
+ if (m_unreferencedPixmaps == 0) {
+ killTimer(m_timerId);
+ m_timerId = -1;
+ }
}
-int QDeclarativePixmapReply::forcedHeight() const
+QDeclarativePixmapReply::QDeclarativePixmapReply(QDeclarativePixmapData *d)
+: data(d), reader(0), loading(false), redirectCount(0)
{
- Q_D(const QDeclarativePixmapReply);
- return d->forced_height;
+ if (finishedIndex == -1) {
+ finishedIndex = QDeclarativePixmapReply::staticMetaObject.indexOfSignal("finished()");
+ downloadProgressIndex = QDeclarativePixmapReply::staticMetaObject.indexOfSignal("downloadProgress(qint64,qint64)");
+ }
}
-QSize QDeclarativePixmapReply::implicitSize() const
+QDeclarativePixmapReply::~QDeclarativePixmapReply()
{
- Q_D(const QDeclarativePixmapReply);
- QDeclarativePixmapSizeHash::Iterator iter = qmlOriginalSizes()->find(d->url);
- if (iter != qmlOriginalSizes()->end())
- return *iter;
- else
- return QSize();
}
bool QDeclarativePixmapReply::event(QEvent *event)
{
- Q_D(QDeclarativePixmapReply);
if (event->type() == QEvent::User) {
- d->loading = false;
- if (!release(true)) {
- QDeclarativeImageReaderEvent *de = static_cast<QDeclarativeImageReaderEvent*>(event);
- d->status = (de->error == QDeclarativeImageReaderEvent::NoError) ? Ready : Error;
- if (d->status == Ready)
- d->pixmap = QPixmap::fromImage(de->image);
- else
- d->errorString = de->errorString;
- QByteArray key = d->url.toEncoded(QUrl::FormattingOption(0x100));
- QString strKey = QString::fromLatin1(key.constData(), key.count());
- QPixmapCache::insert(strKey, d->pixmap); // note: may fail (returns false)
+
+ if (data) {
+ Event *de = static_cast<Event *>(event);
+ data->pixmapStatus = (de->error == NoError) ? QDeclarativePixmap::Ready : QDeclarativePixmap::Error;
+
+ if (data->pixmapStatus == QDeclarativePixmap::Ready) {
+ data->pixmap = QPixmap::fromImage(de->image);
+ data->implicitSize = de->implicitSize;
+ } else {
+ data->errorString = de->errorString;
+ data->removeFromCache(); // We don't continue to cache error'd pixmaps
+ }
+
+ data->reply = 0;
emit finished();
}
+
+ delete this;
return true;
+ } else {
+ return QObject::event(event);
}
-
- return QObject::event(event);
}
-QString QDeclarativePixmapReply::errorString() const
+int QDeclarativePixmapData::cost() const
{
- Q_D(const QDeclarativePixmapReply);
- return d->errorString;
+ return pixmap.width() * pixmap.height() * pixmap.depth();
}
-QDeclarativePixmapReply::Status QDeclarativePixmapReply::status() const
+void QDeclarativePixmapData::addref()
{
- Q_D(const QDeclarativePixmapReply);
- return d->status;
+ ++refCount;
+ if (prevUnreferencedPtr)
+ pixmapStore()->referencePixmap(this);
}
-bool QDeclarativePixmapReply::isLoading() const
+void QDeclarativePixmapData::release()
{
- Q_D(const QDeclarativePixmapReply);
- return d->loading;
+ Q_ASSERT(refCount > 0);
+ --refCount;
+
+ if (refCount == 0) {
+ if (reply) {
+ reply->data = 0;
+ reply->reader->cancel(reply);
+ reply = 0;
+ }
+
+ if (pixmapStatus == QDeclarativePixmap::Ready) {
+ pixmapStore()->unreferencePixmap(this);
+ } else {
+ removeFromCache();
+ delete this;
+ }
+ }
}
-void QDeclarativePixmapReply::setLoading()
+void QDeclarativePixmapData::addToCache()
{
- Q_D(QDeclarativePixmapReply);
- d->loading = true;
+ if (!inCache) {
+ QDeclarativePixmapKey key = { &url, &requestSize };
+ pixmapStore()->m_cache.insert(key, this);
+ inCache = true;
+ }
}
-void QDeclarativePixmapReply::addRef()
+void QDeclarativePixmapData::removeFromCache()
{
- Q_D(QDeclarativePixmapReply);
- ++d->refCount;
+ if (inCache) {
+ QDeclarativePixmapKey key = { &url, &requestSize };
+ pixmapStore()->m_cache.remove(key);
+ inCache = false;
+ }
}
-bool QDeclarativePixmapReply::release(bool defer)
+static QDeclarativePixmapData* createPixmapDataSync(QDeclarativeEngine *engine, const QUrl &url, const QSize &requestSize, bool *ok)
{
- Q_D(QDeclarativePixmapReply);
- Q_ASSERT(d->refCount > 0);
- --d->refCount;
- if (d->refCount == 0) {
- qmlActivePixmapReplies()->remove(d->url);
- if (defer)
- deleteLater();
- else
- delete this;
- return true;
- } else if (d->refCount == 1 && d->loading) {
- // The only reference left is the reader thread.
- qmlActivePixmapReplies()->remove(d->url);
- d->reader->cancel(this);
+ if (url.scheme() == QLatin1String("image")) {
+ QSize readSize;
+ QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine);
+ QDeclarativeImageProvider::ImageType imageType = ep->getImageProviderType(url);
+
+ switch (imageType) {
+ case QDeclarativeImageProvider::Image:
+ {
+ QImage image = ep->getImageFromProvider(url, &readSize, requestSize);
+ if (!image.isNull()) {
+ *ok = true;
+ return new QDeclarativePixmapData(url, QPixmap::fromImage(image), readSize, requestSize);
+ }
+ }
+ case QDeclarativeImageProvider::Pixmap:
+ {
+ QPixmap pixmap = ep->getPixmapFromProvider(url, &readSize, requestSize);
+ if (!pixmap.isNull()) {
+ *ok = true;
+ return new QDeclarativePixmapData(url, pixmap, readSize, requestSize);
+ }
+ }
+ }
+
+ // no matching provider, or provider has bad image type, or provider returned null image
+ return new QDeclarativePixmapData(url, requestSize,
+ QDeclarativePixmap::tr("Failed to get image from provider: %1").arg(url.toString()));
}
- return false;
+ QString localFile = QDeclarativeEnginePrivate::urlToLocalFileOrQrc(url);
+ if (localFile.isEmpty())
+ return 0;
+
+ QFile f(localFile);
+ QSize readSize;
+ QString errorString;
+
+ if (f.open(QIODevice::ReadOnly)) {
+ QImage image;
+ if (readImage(url, &f, &image, &errorString, &readSize, requestSize)) {
+ *ok = true;
+ return new QDeclarativePixmapData(url, QPixmap::fromImage(image), readSize, requestSize);
+ }
+ } else {
+ errorString = QDeclarativePixmap::tr("Cannot open: %1").arg(url.toString());
+ }
+ return new QDeclarativePixmapData(url, requestSize, errorString);
}
-/*!
- Finds the cached pixmap corresponding to \a url.
- If the image is a network resource and has not yet
- been retrieved and cached, request() must be called.
- Returns Ready, or Error if the image has been retrieved,
- otherwise the current retrieval status.
+struct QDeclarativePixmapNull {
+ QUrl url;
+ QPixmap pixmap;
+ QSize size;
+};
+Q_GLOBAL_STATIC(QDeclarativePixmapNull, nullPixmap);
- If \a async is false the image will be loaded and decoded immediately;
- otherwise the image will be loaded and decoded in a separate thread.
+QDeclarativePixmap::QDeclarativePixmap()
+: d(0)
+{
+}
- If \a req_width and \a req_height are non-zero, they are used for
- the size of the rendered pixmap rather than the intrinsic size of the image.
- Different request sizes add different cache items.
+QDeclarativePixmap::QDeclarativePixmap(QDeclarativeEngine *engine, const QUrl &url)
+: d(0)
+{
+ load(engine, url);
+}
- Note that images sourced from the network will always be loaded and
- decoded asynchonously.
-*/
-QDeclarativePixmapReply::Status QDeclarativePixmapCache::get(const QUrl& url, QPixmap *pixmap, QString *errorString, QSize *impsize, bool async, int req_width, int req_height)
+QDeclarativePixmap::QDeclarativePixmap(QDeclarativeEngine *engine, const QUrl &url, const QSize &size)
+: d(0)
{
- QDeclarativePixmapReply::Status status = QDeclarativePixmapReply::Unrequested;
- QByteArray key = url.toEncoded(QUrl::FormattingOption(0x100));
+ load(engine, url, size);
+}
- if (req_width > 0 || req_height > 0) {
- key += ':';
- key += QByteArray::number(req_width);
- key += 'x';
- key += QByteArray::number(req_height);
+QDeclarativePixmap::~QDeclarativePixmap()
+{
+ if (d) {
+ d->release();
+ d = 0;
}
+}
- QString strKey = QString::fromLatin1(key.constData(), key.count());
+bool QDeclarativePixmap::isNull() const
+{
+ return d == 0;
+}
-#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML
- if (!async) {
- QString lf = QDeclarativeEnginePrivate::urlToLocalFileOrQrc(url);
- if (!lf.isEmpty()) {
- status = QDeclarativePixmapReply::Ready;
- if (!QPixmapCache::find(strKey,pixmap)) {
- QFile f(lf);
- QSize read_impsize;
- if (f.open(QIODevice::ReadOnly)) {
- QImage image;
- if (readImage(url, &f, &image, errorString, &read_impsize, req_width, req_height)) {
- *pixmap = QPixmap::fromImage(image);
- } else {
- *pixmap = QPixmap();
- status = QDeclarativePixmapReply::Error;
- }
- } else {
- if (errorString)
- *errorString = tr("Cannot open: %1").arg(url.toString());
- *pixmap = QPixmap();
- status = QDeclarativePixmapReply::Error;
- }
- if (status == QDeclarativePixmapReply::Ready) {
- QPixmapCache::insert(strKey, *pixmap);
- qmlOriginalSizes()->insert(url, read_impsize);
- }
- if (impsize)
- *impsize = read_impsize;
- } else {
- if (impsize) {
- QDeclarativePixmapSizeHash::Iterator iter = qmlOriginalSizes()->find(url);
- if (iter != qmlOriginalSizes()->end())
- *impsize = *iter;
- }
+bool QDeclarativePixmap::isReady() const
+{
+ return status() == Ready;
+}
+
+bool QDeclarativePixmap::isError() const
+{
+ return status() == Error;
+}
+
+bool QDeclarativePixmap::isLoading() const
+{
+ return status() == Loading;
+}
+
+QString QDeclarativePixmap::error() const
+{
+ if (d)
+ return d->errorString;
+ else
+ return QString();
+}
+
+QDeclarativePixmap::Status QDeclarativePixmap::status() const
+{
+ if (d)
+ return d->pixmapStatus;
+ else
+ return Null;
+}
+
+const QUrl &QDeclarativePixmap::url() const
+{
+ if (d)
+ return d->url;
+ else
+ return nullPixmap()->url;
+}
+
+const QSize &QDeclarativePixmap::implicitSize() const
+{
+ if (d)
+ return d->implicitSize;
+ else
+ return nullPixmap()->size;
+}
+
+const QSize &QDeclarativePixmap::requestSize() const
+{
+ if (d)
+ return d->requestSize;
+ else
+ return nullPixmap()->size;
+}
+
+const QPixmap &QDeclarativePixmap::pixmap() const
+{
+ if (d)
+ return d->pixmap;
+ else
+ return nullPixmap()->pixmap;
+}
+
+void QDeclarativePixmap::setPixmap(const QPixmap &p)
+{
+ clear();
+
+ if (!p.isNull())
+ d = new QDeclarativePixmapData(p);
+}
+
+int QDeclarativePixmap::width() const
+{
+ if (d)
+ return d->pixmap.width();
+ else
+ return 0;
+}
+
+int QDeclarativePixmap::height() const
+{
+ if (d)
+ return d->pixmap.height();
+ else
+ return 0;
+}
+
+QRect QDeclarativePixmap::rect() const
+{
+ if (d)
+ return d->pixmap.rect();
+ else
+ return QRect();
+}
+
+void QDeclarativePixmap::load(QDeclarativeEngine *engine, const QUrl &url)
+{
+ load(engine, url, QSize(), false);
+}
+
+void QDeclarativePixmap::load(QDeclarativeEngine *engine, const QUrl &url, bool async)
+{
+ load(engine, url, QSize(), async);
+}
+
+void QDeclarativePixmap::load(QDeclarativeEngine *engine, const QUrl &url, const QSize &size)
+{
+ load(engine, url, size, false);
+}
+
+void QDeclarativePixmap::load(QDeclarativeEngine *engine, const QUrl &url, const QSize &requestSize, bool async)
+{
+ if (d) { d->release(); d = 0; }
+
+ QDeclarativePixmapKey key = { &url, &requestSize };
+ QDeclarativePixmapStore *store = pixmapStore();
+
+ QHash<QDeclarativePixmapKey, QDeclarativePixmapData *>::Iterator iter = store->m_cache.find(key);
+
+ if (iter == store->m_cache.end()) {
+ if (async) {
+ // pixmaps can only be loaded synchronously
+ if (url.scheme() == QLatin1String("image")
+ && QDeclarativeEnginePrivate::get(engine)->getImageProviderType(url) == QDeclarativeImageProvider::Pixmap) {
+ async = false;
}
- return status;
}
- }
-#endif
-
- QDeclarativePixmapReplyHash::Iterator iter = qmlActivePixmapReplies()->find(url);
- if (iter != qmlActivePixmapReplies()->end() && (*iter)->status() == QDeclarativePixmapReply::Ready) {
- // Must check this, since QPixmapCache::insert may have failed.
- *pixmap = (*iter)->d_func()->pixmap;
- status = (*iter)->status();
- (*iter)->release();
- } else if (QPixmapCache::find(strKey, pixmap)) {
- if (iter != qmlActivePixmapReplies()->end()) {
- status = (*iter)->status();
- if (errorString)
- *errorString = (*iter)->errorString();
- (*iter)->release();
- } else if (pixmap->isNull()) {
- status = QDeclarativePixmapReply::Error;
- if (errorString)
- *errorString = tr("Unknown Error loading %1").arg(url.toString());
- } else {
- status = QDeclarativePixmapReply::Ready;
- }
- } else if (iter != qmlActivePixmapReplies()->end()) {
- status = QDeclarativePixmapReply::Loading;
- }
- if (impsize) {
- QDeclarativePixmapSizeHash::Iterator iter = qmlOriginalSizes()->find(url);
- if (iter != qmlOriginalSizes()->end())
- *impsize = *iter;
- }
- return status;
+ if (!async) {
+ bool ok = false;
+ d = createPixmapDataSync(engine, url, requestSize, &ok);
+ if (ok) {
+ d->addToCache();
+ return;
+ }
+ if (d) // loadable, but encountered error while loading
+ return;
+ }
+
+ if (!engine)
+ return;
+
+ QDeclarativePixmapReader *reader = QDeclarativePixmapReader::instance(engine);
+
+ d = new QDeclarativePixmapData(url, requestSize);
+ d->addToCache();
+
+ d->reply = reader->getImage(d);
+ } else {
+ d = *iter;
+ d->addref();
+ }
}
-/*!
- Starts a network request to load \a url.
+void QDeclarativePixmap::clear()
+{
+ if (d) {
+ d->release();
+ d = 0;
+ }
+}
- Returns a QDeclarativePixmapReply. Caller should connect to QDeclarativePixmapReply::finished()
- and call get() when the image is available.
+void QDeclarativePixmap::clear(QObject *obj)
+{
+ if (d) {
+ if (d->reply)
+ QObject::disconnect(d->reply, 0, obj, 0);
+ d->release();
+ d = 0;
+ }
+}
- The returned QDeclarativePixmapReply will be deleted when all request() calls are
- matched by a corresponding get() call.
-*/
-QDeclarativePixmapReply *QDeclarativePixmapCache::request(QDeclarativeEngine *engine, const QUrl &url, int req_width, int req_height)
+bool QDeclarativePixmap::connectFinished(QObject *object, const char *method)
{
- QDeclarativePixmapReplyHash::Iterator iter = qmlActivePixmapReplies()->find(url);
- if (iter == qmlActivePixmapReplies()->end()) {
- QDeclarativeImageReader *reader = QDeclarativeImageReader::instance(engine);
- QDeclarativePixmapReply *item = reader->getImage(url, req_width, req_height);
- iter = qmlActivePixmapReplies()->insert(url, item);
- } else {
- (*iter)->addRef();
+ if (!d || !d->reply) {
+ qWarning("QDeclarativePixmap: connectFinished() called when not loading.");
+ return false;
}
- return (*iter);
+ return QObject::connect(d->reply, SIGNAL(finished()), object, method);
}
-/*!
- Cancels a previous call to request().
+bool QDeclarativePixmap::connectFinished(QObject *object, int method)
+{
+ if (!d || !d->reply) {
+ qWarning("QDeclarativePixmap: connectFinished() called when not loading.");
+ return false;
+ }
- May also cancel loading (eg. if no other pending request).
+ return QMetaObject::connect(d->reply, QDeclarativePixmapReply::finishedIndex, object, method);
+}
- Any connections from the QDeclarativePixmapReply returned by request() to \a obj will be
- disconnected.
-*/
-void QDeclarativePixmapCache::cancel(const QUrl& url, QObject *obj)
+bool QDeclarativePixmap::connectDownloadProgress(QObject *object, const char *method)
{
- QDeclarativePixmapReplyHash::Iterator iter = qmlActivePixmapReplies()->find(url);
- if (iter == qmlActivePixmapReplies()->end())
- return;
+ if (!d || !d->reply) {
+ qWarning("QDeclarativePixmap: connectDownloadProgress() called when not loading.");
+ return false;
+ }
- QDeclarativePixmapReply *reply = *iter;
- if (obj)
- QObject::disconnect(reply, 0, obj, 0);
- reply->release();
+ return QObject::connect(d->reply, SIGNAL(downloadProgress(qint64,qint64)), object, method);
}
-/*!
- This function is mainly for test verification. It returns the number of
- requests that are still unfinished.
-*/
-int QDeclarativePixmapCache::pendingRequests()
+bool QDeclarativePixmap::connectDownloadProgress(QObject *object, int method)
{
- return qmlActivePixmapReplies()->count();
+ if (!d || !d->reply) {
+ qWarning("QDeclarativePixmap: connectDownloadProgress() called when not loading.");
+ return false;
+ }
+
+ return QMetaObject::connect(d->reply, QDeclarativePixmapReply::downloadProgressIndex, object, method);
}
QT_END_NAMESPACE
diff --git a/src/declarative/util/qdeclarativepixmapcache_p.h b/src/declarative/util/qdeclarativepixmapcache_p.h
index 33d9de1..b4d88bd 100644
--- a/src/declarative/util/qdeclarativepixmapcache_p.h
+++ b/src/declarative/util/qdeclarativepixmapcache_p.h
@@ -42,69 +42,70 @@
#ifndef QDECLARATIVEPIXMAPCACHE_H
#define QDECLARATIVEPIXMAPCACHE_H
-#include <QtCore/QString>
-#include <QtGui/QPixmap>
+#include <QtCore/qcoreapplication.h>
+#include <QtCore/qstring.h>
+#include <QtGui/qpixmap.h>
#include <QtCore/qurl.h>
-#include <QtCore/QCoreApplication>
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
-class QDeclarativeEngine;
-class QNetworkReply;
-class QDeclarativeImageReader;
-class QDeclarativePixmapReplyPrivate;
-class Q_DECLARATIVE_EXPORT QDeclarativePixmapReply : public QObject
+class QDeclarativeEngine;
+class QDeclarativePixmapData;
+class Q_DECLARATIVE_EXPORT QDeclarativePixmap
{
- Q_OBJECT
+ Q_DECLARE_TR_FUNCTIONS(QDeclarativePixmap)
public:
- ~QDeclarativePixmapReply();
+ QDeclarativePixmap();
+ QDeclarativePixmap(QDeclarativeEngine *, const QUrl &);
+ QDeclarativePixmap(QDeclarativeEngine *, const QUrl &, const QSize &);
+ ~QDeclarativePixmap();
- enum Status { Ready, Error, Unrequested, Loading };
- Status status() const;
- QString errorString() const;
+ enum Status { Null, Ready, Error, Loading };
+ bool isNull() const;
+ bool isReady() const;
+ bool isError() const;
+ bool isLoading() const;
+
+ Status status() const;
+ QString error() const;
const QUrl &url() const;
- int forcedWidth() const;
- int forcedHeight() const;
- QSize implicitSize() const;
+ const QSize &implicitSize() const;
+ const QSize &requestSize() const;
+ const QPixmap &pixmap() const;
+ void setPixmap(const QPixmap &);
-Q_SIGNALS:
- void finished();
- void downloadProgress(qint64, qint64);
+ QRect rect() const;
+ int width() const;
+ int height() const;
+ inline operator const QPixmap &() const;
-protected:
- bool event(QEvent *event);
+ void load(QDeclarativeEngine *, const QUrl &);
+ void load(QDeclarativeEngine *, const QUrl &, bool);
+ void load(QDeclarativeEngine *, const QUrl &, const QSize &);
+ void load(QDeclarativeEngine *, const QUrl &, const QSize &, bool);
-private:
- void addRef();
- bool release(bool defer=false);
- bool isLoading() const;
- void setLoading();
+ void clear();
+ void clear(QObject *);
+
+ bool connectFinished(QObject *, const char *);
+ bool connectFinished(QObject *, int);
+ bool connectDownloadProgress(QObject *, const char *);
+ bool connectDownloadProgress(QObject *, int);
private:
- QDeclarativePixmapReply(QDeclarativeImageReader *reader, const QUrl &url, int req_width, int req_height);
- Q_DISABLE_COPY(QDeclarativePixmapReply)
- Q_DECLARE_PRIVATE(QDeclarativePixmapReply)
- friend class QDeclarativeImageRequestHandler;
- friend class QDeclarativeImageReader;
- friend class QDeclarativePixmapCache;
+ Q_DISABLE_COPY(QDeclarativePixmap);
+ QDeclarativePixmapData *d;
};
-class Q_DECLARATIVE_EXPORT QDeclarativePixmapCache
+inline QDeclarativePixmap::operator const QPixmap &() const
{
- Q_DECLARE_TR_FUNCTIONS(QDeclarativePixmapCache)
-public:
- static QDeclarativePixmapReply::Status get(const QUrl& url, QPixmap *pixmap, QString *errorString, QSize *impsize=0, bool async=false, int req_width=0, int req_height=0);
- static QDeclarativePixmapReply *request(QDeclarativeEngine *, const QUrl& url, int req_width=0, int req_height=0);
- static void cancel(const QUrl& url, QObject *obj);
- static int pendingRequests();
-};
-
-
+ return pixmap();
+}
QT_END_NAMESPACE
diff --git a/src/declarative/util/qdeclarativepropertychanges.cpp b/src/declarative/util/qdeclarativepropertychanges.cpp
index 8e3ec82..12c6353 100644
--- a/src/declarative/util/qdeclarativepropertychanges.cpp
+++ b/src/declarative/util/qdeclarativepropertychanges.cpp
@@ -145,7 +145,7 @@ QT_BEGIN_NAMESPACE
an Item's parent should be done using the associated change elements
(ParentChange and AnchorChanges, respectively).
- \sa {qmlstate}{States}, QtDeclarative
+ \sa {declarative/animation/states}{states example}, {qmlstate}{States}, QtDeclarative
*/
/*!
diff --git a/src/declarative/util/qdeclarativepropertychanges_p.h b/src/declarative/util/qdeclarativepropertychanges_p.h
index c2ed466..8578086 100644
--- a/src/declarative/util/qdeclarativepropertychanges_p.h
+++ b/src/declarative/util/qdeclarativepropertychanges_p.h
@@ -52,7 +52,7 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
class QDeclarativePropertyChangesPrivate;
-class Q_DECLARATIVE_EXPORT QDeclarativePropertyChanges : public QDeclarativeStateOperation
+class Q_AUTOTEST_EXPORT QDeclarativePropertyChanges : public QDeclarativeStateOperation
{
Q_OBJECT
Q_DECLARE_PRIVATE(QDeclarativePropertyChanges)
@@ -79,6 +79,9 @@ public:
class QDeclarativePropertyChangesParser : public QDeclarativeCustomParser
{
public:
+ QDeclarativePropertyChangesParser()
+ : QDeclarativeCustomParser(AcceptsAttachedProperties) {}
+
void compileList(QList<QPair<QByteArray, QVariant> > &list, const QByteArray &pre, const QDeclarativeCustomParserProperty &prop);
virtual QByteArray compile(const QList<QDeclarativeCustomParserProperty> &);
diff --git a/src/declarative/util/qdeclarativesmoothedanimation.cpp b/src/declarative/util/qdeclarativesmoothedanimation.cpp
index 6b6df4d..5d47c30 100644
--- a/src/declarative/util/qdeclarativesmoothedanimation.cpp
+++ b/src/declarative/util/qdeclarativesmoothedanimation.cpp
@@ -307,7 +307,7 @@ Rectangle {
set to a value such as 0.5 units/second. Animating from 0 to 1.0 with a velocity
of 0.5 will take 2000 ms to complete.
- \sa SpringFollow, {QML Animation}, {declarative/animation/basics}{Animation basics example}
+ \sa {QML Animation}, {declarative/animation/basics}{Animation basics example}
*/
QDeclarativeSmoothedAnimation::QDeclarativeSmoothedAnimation(QObject *parent)
diff --git a/src/declarative/util/qdeclarativesmoothedanimation_p.h b/src/declarative/util/qdeclarativesmoothedanimation_p.h
index f45d19f..8b51209 100644
--- a/src/declarative/util/qdeclarativesmoothedanimation_p.h
+++ b/src/declarative/util/qdeclarativesmoothedanimation_p.h
@@ -55,7 +55,7 @@ QT_MODULE(Declarative)
class QDeclarativeProperty;
class QDeclarativeSmoothedAnimationPrivate;
-class Q_DECLARATIVE_EXPORT QDeclarativeSmoothedAnimation : public QDeclarativeNumberAnimation
+class Q_AUTOTEST_EXPORT QDeclarativeSmoothedAnimation : public QDeclarativeNumberAnimation
{
Q_OBJECT
Q_DECLARE_PRIVATE(QDeclarativeSmoothedAnimation)
diff --git a/src/declarative/util/qdeclarativesmoothedfollow.cpp b/src/declarative/util/qdeclarativesmoothedfollow.cpp
deleted file mode 100644
index f70df9d..0000000
--- a/src/declarative/util/qdeclarativesmoothedfollow.cpp
+++ /dev/null
@@ -1,299 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying
-** this package.
-**
-** 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.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qdeclarativesmoothedfollow_p.h"
-#include "qdeclarativesmoothedanimation_p_p.h"
-
-#include <private/qobject_p.h>
-#include <QtCore/qnumeric.h>
-
-#include "qdeclarativeglobal_p.h"
-
-
-QT_BEGIN_NAMESPACE
-
-class QDeclarativeSmoothedFollowPrivate : public QObjectPrivate
-{
- Q_DECLARE_PUBLIC(QDeclarativeSmoothedFollow)
-public:
- QDeclarativeSmoothedFollowPrivate();
-
- bool enabled;
- QSmoothedAnimation *anim;
-};
-
-/*!
- \qmlclass SmoothedFollow QDeclarativeSmoothedFollow
- \since 4.7
- \inherits NumberAnimation
- \brief The SmoothedFollow element allows a property to smoothly track a value.
-
- The SmoothedFollow animates a property's value to a set target value
- using an ease in/out quad easing curve. If the animation is restarted
- with a different target value, the easing curves used to animate to the old
- and the new target values are smoothly spliced together to avoid any obvious
- visual glitches by maintaining the current velocity.
-
- The property animation is configured by setting the velocity at which the
- animation should occur, or the duration that the animation should take.
- If both a velocity and a duration are specified, the one that results in
- the quickest animation is chosen for each change in the target value.
-
- For example, animating from 0 to 800 will take 4 seconds if a velocity
- of 200 is set, will take 8 seconds with a duration of 8000 set, and will
- take 4 seconds with both a velocity of 200 and a duration of 8000 set.
- Animating from 0 to 20000 will take 10 seconds if a velocity of 200 is set,
- will take 8 seconds with a duration of 8000 set, and will take 8 seconds
- with both a velocity of 200 and a duration of 8000 set.
-
- The follow example shows one rectangle tracking the position of another.
-\code
-import Qt 4.7
-
-Rectangle {
- width: 800; height: 600; color: "blue"
-
- Rectangle {
- color: "green"
- width: 60; height: 60;
- SmoothedFollow on x { to: rect1.x - 5; velocity: 200 }
- SmoothedFollow on y { to: rect1.y - 5; velocity: 200 }
- }
-
- Rectangle {
- id: rect1
- color: "red"
- width: 50; height: 50;
- }
-
- focus: true
- Keys.onRightPressed: rect1.x = rect1.x + 100
- Keys.onLeftPressed: rect1.x = rect1.x - 100
- Keys.onUpPressed: rect1.y = rect1.y - 100
- Keys.onDownPressed: rect1.y = rect1.y + 100
-}
-\endcode
-
- The default velocity of SmoothedFollow is 200 units/second. Note that if the range of the
- value being animated is small, then the velocity will need to be adjusted
- appropriately. For example, the opacity of an item ranges from 0 - 1.0.
- To enable a smooth animation in this range the velocity will need to be
- set to a value such as 0.5 units/second. Animating from 0 to 1.0 with a velocity
- of 0.5 will take 2000 ms to complete.
-
- \sa SpringFollow
-*/
-
-QDeclarativeSmoothedFollow::QDeclarativeSmoothedFollow(QObject *parent)
- : QObject(*(new QDeclarativeSmoothedFollowPrivate), parent)
-{
-}
-
-QDeclarativeSmoothedFollow::~QDeclarativeSmoothedFollow()
-{
-}
-
-QDeclarativeSmoothedFollowPrivate::QDeclarativeSmoothedFollowPrivate()
- : enabled(true), anim(new QSmoothedAnimation)
-{
- Q_Q(QDeclarativeSmoothedFollow);
- QDeclarative_setParent_noEvent(anim, q);
-}
-
-/*!
- \qmlproperty enumeration SmoothedFollow::reversingMode
-
- Sets how the SmoothedFollow behaves if an animation direction is reversed.
-
- If reversing mode is \c SmoothedFollow.Eased, the animation will smoothly decelerate, and
- then reverse direction. If the reversing mode is \c SmoothedFollow.Immediate, the
- animation will immediately begin accelerating in the reverse direction,
- begining with a velocity of 0. If the reversing mode is \c SmoothedFollow.Sync, the
- property is immediately set to the target value.
-*/
-QDeclarativeSmoothedFollow::ReversingMode QDeclarativeSmoothedFollow::reversingMode() const
-{
- Q_D(const QDeclarativeSmoothedFollow);
- return (ReversingMode) d->anim->reversingMode;
-}
-
-void QDeclarativeSmoothedFollow::setReversingMode(ReversingMode m)
-{
- Q_D(QDeclarativeSmoothedFollow);
- if (d->anim->reversingMode == (QDeclarativeSmoothedAnimation::ReversingMode) m)
- return;
-
- d->anim->reversingMode = (QDeclarativeSmoothedAnimation::ReversingMode) m;
- emit reversingModeChanged();
-}
-
-/*!
- \qmlproperty int SmoothedFollow::duration
-
- This property holds the animation duration, in msecs, used when tracking the source.
-
- Setting this to -1 (the default) disables the duration value.
-*/
-int QDeclarativeSmoothedFollow::duration() const
-{
- Q_D(const QDeclarativeSmoothedFollow);
- return d->anim->userDuration;
-}
-
-void QDeclarativeSmoothedFollow::setDuration(int duration)
-{
- Q_D(QDeclarativeSmoothedFollow);
- if (duration == d->anim->duration())
- return;
-
- d->anim->userDuration = duration;
- emit durationChanged();
-}
-
-qreal QDeclarativeSmoothedFollow::velocity() const
-{
- Q_D(const QDeclarativeSmoothedFollow);
- return d->anim->velocity;
-}
-
-/*!
- \qmlproperty real SmoothedFollow::velocity
-
- This property holds the average velocity allowed when tracking the 'to' value.
-
- The default velocity of SmoothedFollow is 200 units/second.
-
- Setting this to -1 disables the velocity value.
-*/
-void QDeclarativeSmoothedFollow::setVelocity(qreal v)
-{
- Q_D(QDeclarativeSmoothedFollow);
- if (d->anim->velocity == v)
- return;
-
- d->anim->velocity = v;
- emit velocityChanged();
-}
-
-/*!
- \qmlproperty int SmoothedFollow::maximumEasingTime
-
- This property specifies the maximum time, in msecs, an "eases" during the follow should take.
- Setting this property causes the velocity to "level out" after at a time. Setting
- a negative value reverts to the normal mode of easing over the entire animation
- duration.
-
- The default value is -1.
-*/
-int QDeclarativeSmoothedFollow::maximumEasingTime() const
-{
- Q_D(const QDeclarativeSmoothedFollow);
- return d->anim->maximumEasingTime;
-}
-
-void QDeclarativeSmoothedFollow::setMaximumEasingTime(int v)
-{
- Q_D(QDeclarativeSmoothedFollow);
- d->anim->maximumEasingTime = v;
- emit maximumEasingTimeChanged();
-}
-
-/*!
- \qmlproperty real SmoothedFollow::to
- This property holds the ending value.
- If not set, then the value defined in the end state of the transition or Behavior.
-*/
-qreal QDeclarativeSmoothedFollow::to() const
-{
- Q_D(const QDeclarativeSmoothedFollow);
- return d->anim->to;
-}
-
-void QDeclarativeSmoothedFollow::setTo(qreal t)
-{
- Q_D(QDeclarativeSmoothedFollow);
-
- if (qIsNaN(t))
- return;
-
- if (d->anim->to == t)
- return;
-
- d->anim->to = t;
-
- if (d->enabled)
- d->anim->restart();
-}
-
-/*!
- \qmlproperty bool SmoothedFollow::enabled
- This property whether this animation should automatically restart when
- the 'to' property is upated.
-
- The default value of this property is 'true'.
-*/
-bool QDeclarativeSmoothedFollow::enabled() const
-{
- Q_D(const QDeclarativeSmoothedFollow);
- return d->enabled;
-}
-
-void QDeclarativeSmoothedFollow::setEnabled(bool e)
-{
- Q_D(QDeclarativeSmoothedFollow);
- if (d->enabled == e)
- return;
- d->enabled = e;
-
- if (d->enabled)
- d->anim->restart();
- else
- d->anim->stop();
- emit enabledChanged();
-}
-
-void QDeclarativeSmoothedFollow::setTarget(const QDeclarativeProperty &t)
-{
- Q_D(QDeclarativeSmoothedFollow);
- d->anim->target = t;
-}
-
-QT_END_NAMESPACE
diff --git a/src/declarative/util/qdeclarativesmoothedfollow_p.h b/src/declarative/util/qdeclarativesmoothedfollow_p.h
deleted file mode 100644
index 6319192..0000000
--- a/src/declarative/util/qdeclarativesmoothedfollow_p.h
+++ /dev/null
@@ -1,113 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying
-** this package.
-**
-** 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.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QDECLARATIVESMOOTHEDFOLLOW_H
-#define QDECLARATIVESMOOTHEDFOLLOW_H
-
-#include <qdeclarative.h>
-#include <qdeclarativepropertyvaluesource.h>
-
-#include <QtCore/qobject.h>
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Declarative)
-
-class QDeclarativeProperty;
-class QDeclarativeSmoothedFollowPrivate;
-class Q_DECLARATIVE_EXPORT QDeclarativeSmoothedFollow : public QObject,
- public QDeclarativePropertyValueSource
-{
- Q_OBJECT
- Q_DECLARE_PRIVATE(QDeclarativeSmoothedFollow)
- Q_INTERFACES(QDeclarativePropertyValueSource)
- Q_ENUMS(ReversingMode)
-
- Q_PROPERTY(qreal to READ to WRITE setTo NOTIFY toChanged)
- Q_PROPERTY(qreal velocity READ velocity WRITE setVelocity NOTIFY velocityChanged)
- Q_PROPERTY(int duration READ duration WRITE setDuration NOTIFY durationChanged)
- Q_PROPERTY(ReversingMode reversingMode READ reversingMode WRITE setReversingMode NOTIFY reversingModeChanged)
- Q_PROPERTY(qreal maximumEasingTime READ maximumEasingTime WRITE setMaximumEasingTime NOTIFY maximumEasingTimeChanged)
- Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
-
-public:
- enum ReversingMode { Eased, Immediate, Sync };
-
- QDeclarativeSmoothedFollow(QObject *parent = 0);
- ~QDeclarativeSmoothedFollow();
-
- qreal to() const;
- void setTo(qreal);
-
- ReversingMode reversingMode() const;
- void setReversingMode(ReversingMode);
-
- int duration() const;
- void setDuration(int);
-
- qreal velocity() const;
- void setVelocity(qreal);
-
- int maximumEasingTime() const;
- void setMaximumEasingTime(int);
-
- bool enabled() const;
- void setEnabled(bool);
-
- virtual void setTarget(const QDeclarativeProperty &);
-
-Q_SIGNALS:
- void velocityChanged();
- void durationChanged();
- void reversingModeChanged();
- void maximumEasingTimeChanged();
- void enabledChanged();
-};
-
-QT_END_NAMESPACE
-
-QML_DECLARE_TYPE(QDeclarativeSmoothedFollow)
-
-QT_END_HEADER
-
-#endif // QDECLARATIVESMOOTHEDFOLLOW_H
diff --git a/src/declarative/util/qdeclarativespringfollow.cpp b/src/declarative/util/qdeclarativespringanimation.cpp
index aae66ac..4cf2fc0 100644
--- a/src/declarative/util/qdeclarativespringfollow.cpp
+++ b/src/declarative/util/qdeclarativespringanimation.cpp
@@ -39,9 +39,10 @@
**
****************************************************************************/
-#include "private/qdeclarativespringfollow_p.h"
+#include "private/qdeclarativespringanimation_p.h"
#include "private/qdeclarativeanimation_p_p.h"
+#include <qdeclarativeproperty_p.h>
#include <QtCore/qdebug.h>
@@ -54,18 +55,20 @@ QT_BEGIN_NAMESPACE
-class QDeclarativeSpringFollowPrivate : public QObjectPrivate
+class QDeclarativeSpringAnimationPrivate : public QDeclarativeAbstractAnimationPrivate
{
- Q_DECLARE_PUBLIC(QDeclarativeSpringFollow)
+ Q_DECLARE_PUBLIC(QDeclarativeSpringAnimation)
public:
- QDeclarativeSpringFollowPrivate()
- : currentValue(0), to(0), maxVelocity(0), lastTime(0)
+ QDeclarativeSpringAnimationPrivate()
+ : currentValue(0), to(0), from(0), maxVelocity(0), lastTime(0)
, mass(1.0), spring(0.), damping(0.), velocity(0), epsilon(0.01)
- , modulus(0.0), useMass(false), haveModulus(false), enabled(true), mode(Track), clock(this) {}
+ , modulus(0.0), useMass(false), haveModulus(false), enabled(true)
+ , fromDefined(false), toDefined(false)
+ , mode(Track), clock(this) {}
- QDeclarativeProperty property;
qreal currentValue;
qreal to;
+ qreal from;
qreal maxVelocity;
qreal velocityms;
int lastTime;
@@ -79,6 +82,8 @@ public:
bool useMass : 1;
bool haveModulus : 1;
bool enabled : 1;
+ bool fromDefined : 1;
+ bool toDefined : 1;
enum Mode {
Track,
@@ -89,20 +94,24 @@ public:
void tick(int);
void updateMode();
- void start();
- void stop();
- QTickAnimationProxy<QDeclarativeSpringFollowPrivate, &QDeclarativeSpringFollowPrivate::tick> clock;
+ QTickAnimationProxy<QDeclarativeSpringAnimationPrivate, &QDeclarativeSpringAnimationPrivate::tick> clock;
};
-void QDeclarativeSpringFollowPrivate::tick(int time)
+void QDeclarativeSpringAnimationPrivate::tick(int time)
{
- Q_Q(QDeclarativeSpringFollow);
+ if (mode == Track) {
+ clock.stop();
+ return;
+ }
int elapsed = time - lastTime;
if (!elapsed)
return;
qreal srcVal = to;
+
+ bool stop = false;
+
if (haveModulus) {
currentValue = fmod(currentValue, modulus);
srcVal = fmod(srcVal, modulus);
@@ -142,7 +151,7 @@ void QDeclarativeSpringFollowPrivate::tick(int time)
if (qAbs(velocity) < epsilon && qAbs(srcVal - currentValue) < epsilon) {
velocity = 0.0;
currentValue = srcVal;
- clock.stop();
+ stop = true;
}
lastTime = time - (elapsed - count * 16);
} else {
@@ -160,7 +169,7 @@ void QDeclarativeSpringFollowPrivate::tick(int time)
currentValue = fmod(currentValue, modulus);
if (currentValue > to) {
currentValue = to;
- clock.stop();
+ stop = true;
}
} else {
currentValue -= moveBy;
@@ -168,18 +177,23 @@ void QDeclarativeSpringFollowPrivate::tick(int time)
currentValue = fmod(currentValue, modulus) + modulus;
if (currentValue < to) {
currentValue = to;
- clock.stop();
+ stop = true;
}
}
lastTime = time;
}
- property.write(currentValue);
- emit q->valueChanged(currentValue);
- if (clock.state() != QAbstractAnimation::Running)
- emit q->syncChanged();
+
+ qreal old_to = to;
+
+ QDeclarativePropertyPrivate::write(defaultProperty, currentValue,
+ QDeclarativePropertyPrivate::BypassInterceptor |
+ QDeclarativePropertyPrivate::DontRemoveBinding);
+
+ if (stop && old_to == to) // do not stop if we got restarted
+ clock.stop();
}
-void QDeclarativeSpringFollowPrivate::updateMode()
+void QDeclarativeSpringAnimationPrivate::updateMode()
{
if (spring == 0. && maxVelocity == 0.)
mode = Track;
@@ -189,121 +203,105 @@ void QDeclarativeSpringFollowPrivate::updateMode()
mode = Velocity;
}
-void QDeclarativeSpringFollowPrivate::start()
-{
- if (!enabled)
- return;
+/*!
+ \qmlclass SpringAnimation QDeclarativeSpringAnimation
+ \since 4.7
- Q_Q(QDeclarativeSpringFollow);
- if (mode == QDeclarativeSpringFollowPrivate::Track) {
- currentValue = to;
- property.write(currentValue);
- } else if (to != currentValue && clock.state() != QAbstractAnimation::Running) {
- lastTime = 0;
- currentValue = property.read().toReal();
- clock.start(); // infinity??
- emit q->syncChanged();
- }
-}
+ \brief The SpringAnimation element allows a property to track a value in a spring-like motion
+
+ SpringAnimation mimics the oscillatory behavior of a spring, with the appropriate \l spring constant to
+ control the acceleration and the \l damping to control how quickly the effect dies away.
+
+ You can also limit the maximum \l velocity of the animation.
-void QDeclarativeSpringFollowPrivate::stop()
-{
- clock.stop();
-}
-/*!
- \qmlclass SpringFollow QDeclarativeSpringFollow
- \since 4.7
- \brief The SpringFollow element allows a property to track a value.
-
- In example below, \e rect2 will follow \e rect1 moving with a velocity of up to 200:
- \code
- Rectangle {
- id: rect1
- width: 20; height: 20
- color: "#00ff00"
- y: 200 // initial value
- SequentialAnimation on y {
- loops: Animation.Infinite
- NumberAnimation {
- to: 200
- easing.type: Easing.OutBounce
- easing.amplitude: 100
- duration: 2000
- }
- PauseAnimation { duration: 1000 }
- }
- }
- Rectangle {
- id: rect2
- x: rect1.width
- width: 20; height: 20
- color: "#ff0000"
- SpringFollow on y { to: rect1.y; velocity: 200 }
- }
- \endcode
*/
-QDeclarativeSpringFollow::QDeclarativeSpringFollow(QObject *parent)
-: QObject(*(new QDeclarativeSpringFollowPrivate),parent)
+QDeclarativeSpringAnimation::QDeclarativeSpringAnimation(QObject *parent)
+: QDeclarativeAbstractAnimation(*(new QDeclarativeSpringAnimationPrivate),parent)
{
}
-QDeclarativeSpringFollow::~QDeclarativeSpringFollow()
+QDeclarativeSpringAnimation::~QDeclarativeSpringAnimation()
{
}
-void QDeclarativeSpringFollow::setTarget(const QDeclarativeProperty &property)
+void QDeclarativeSpringAnimation::setTarget(const QDeclarativeProperty &property)
{
- Q_D(QDeclarativeSpringFollow);
- d->property = property;
+ Q_D(QDeclarativeSpringAnimation);
+ d->defaultProperty = property;
d->currentValue = property.read().toReal();
+ if (!d->avoidPropertyValueSourceStart) {
+ setRunning(true);
+ }
}
-qreal QDeclarativeSpringFollow::to() const
+qreal QDeclarativeSpringAnimation::to() const
{
- Q_D(const QDeclarativeSpringFollow);
- return d->to;
+ Q_D(const QDeclarativeSpringAnimation);
+ return d->toDefined ? d->to : 0;
}
/*!
- \qmlproperty real SpringFollow::to
- This property holds the target value which will be tracked.
-
- Bind to a property in order to track its changes.
+ \qmlproperty real SpringAnimation::to
*/
-void QDeclarativeSpringFollow::setTo(qreal value)
+void QDeclarativeSpringAnimation::setTo(qreal value)
{
- Q_D(QDeclarativeSpringFollow);
- if (d->clock.state() == QAbstractAnimation::Running && d->to == value)
+ Q_D(QDeclarativeSpringAnimation);
+ if (d->to == value)
return;
d->to = value;
- d->start();
+ d->toDefined = true;
+ d->lastTime = 0;
+ emit toChanged(value);
+}
+
+qreal QDeclarativeSpringAnimation::from() const
+{
+ Q_D(const QDeclarativeSpringAnimation);
+ return d->fromDefined ? d->from : 0;
}
/*!
- \qmlproperty real SpringFollow::velocity
+ \qmlproperty real SpringAnimation::from
+*/
+
+void QDeclarativeSpringAnimation::setFrom(qreal value)
+{
+ Q_D(QDeclarativeSpringAnimation);
+ if (d->from == value)
+ return;
+
+ d->currentValue = d->from = value;
+ d->fromDefined = true;
+ d->lastTime = 0;
+ emit fromChanged(value);
+}
+
+
+/*!
+ \qmlproperty real SpringAnimation::velocity
This property holds the maximum velocity allowed when tracking the source.
*/
-qreal QDeclarativeSpringFollow::velocity() const
+qreal QDeclarativeSpringAnimation::velocity() const
{
- Q_D(const QDeclarativeSpringFollow);
+ Q_D(const QDeclarativeSpringAnimation);
return d->maxVelocity;
}
-void QDeclarativeSpringFollow::setVelocity(qreal velocity)
+void QDeclarativeSpringAnimation::setVelocity(qreal velocity)
{
- Q_D(QDeclarativeSpringFollow);
+ Q_D(QDeclarativeSpringAnimation);
d->maxVelocity = velocity;
d->velocityms = velocity / 1000.0;
d->updateMode();
}
/*!
- \qmlproperty real SpringFollow::spring
+ \qmlproperty real SpringAnimation::spring
This property holds the spring constant
The spring constant describes how strongly the target is pulled towards the
@@ -312,35 +310,35 @@ void QDeclarativeSpringFollow::setVelocity(qreal velocity)
When a spring constant is set and the velocity property is greater than 0,
velocity limits the maximum speed.
*/
-qreal QDeclarativeSpringFollow::spring() const
+qreal QDeclarativeSpringAnimation::spring() const
{
- Q_D(const QDeclarativeSpringFollow);
+ Q_D(const QDeclarativeSpringAnimation);
return d->spring;
}
-void QDeclarativeSpringFollow::setSpring(qreal spring)
+void QDeclarativeSpringAnimation::setSpring(qreal spring)
{
- Q_D(QDeclarativeSpringFollow);
+ Q_D(QDeclarativeSpringAnimation);
d->spring = spring;
d->updateMode();
}
/*!
- \qmlproperty real SpringFollow::damping
+ \qmlproperty real SpringAnimation::damping
This property holds the spring damping constant
The damping constant describes how quickly a sprung follower comes to rest.
Useful range is 0 - 1.0
*/
-qreal QDeclarativeSpringFollow::damping() const
+qreal QDeclarativeSpringAnimation::damping() const
{
- Q_D(const QDeclarativeSpringFollow);
+ Q_D(const QDeclarativeSpringAnimation);
return d->damping;
}
-void QDeclarativeSpringFollow::setDamping(qreal damping)
+void QDeclarativeSpringAnimation::setDamping(qreal damping)
{
- Q_D(QDeclarativeSpringFollow);
+ Q_D(QDeclarativeSpringAnimation);
if (damping > 1.)
damping = 1.;
@@ -349,7 +347,7 @@ void QDeclarativeSpringFollow::setDamping(qreal damping)
/*!
- \qmlproperty real SpringFollow::epsilon
+ \qmlproperty real SpringAnimation::epsilon
This property holds the spring epsilon
The epsilon is the rate and amount of change in the value which is close enough
@@ -358,34 +356,34 @@ void QDeclarativeSpringFollow::setDamping(qreal damping)
The default is 0.01. Tuning this value can provide small performance improvements.
*/
-qreal QDeclarativeSpringFollow::epsilon() const
+qreal QDeclarativeSpringAnimation::epsilon() const
{
- Q_D(const QDeclarativeSpringFollow);
+ Q_D(const QDeclarativeSpringAnimation);
return d->epsilon;
}
-void QDeclarativeSpringFollow::setEpsilon(qreal epsilon)
+void QDeclarativeSpringAnimation::setEpsilon(qreal epsilon)
{
- Q_D(QDeclarativeSpringFollow);
+ Q_D(QDeclarativeSpringAnimation);
d->epsilon = epsilon;
}
/*!
- \qmlproperty real SpringFollow::modulus
+ \qmlproperty real SpringAnimation::modulus
This property holds the modulus value.
Setting a \a modulus forces the target value to "wrap around" at the modulus.
For example, setting the modulus to 360 will cause a value of 370 to wrap around to 10.
*/
-qreal QDeclarativeSpringFollow::modulus() const
+qreal QDeclarativeSpringAnimation::modulus() const
{
- Q_D(const QDeclarativeSpringFollow);
+ Q_D(const QDeclarativeSpringAnimation);
return d->modulus;
}
-void QDeclarativeSpringFollow::setModulus(qreal modulus)
+void QDeclarativeSpringAnimation::setModulus(qreal modulus)
{
- Q_D(QDeclarativeSpringFollow);
+ Q_D(QDeclarativeSpringAnimation);
if (d->modulus != modulus) {
d->haveModulus = modulus != 0.0;
d->modulus = modulus;
@@ -394,21 +392,21 @@ void QDeclarativeSpringFollow::setModulus(qreal modulus)
}
/*!
- \qmlproperty real SpringFollow::mass
+ \qmlproperty real SpringAnimation::mass
This property holds the "mass" of the property being moved.
mass is 1.0 by default. Setting a different mass changes the dynamics of
a \l spring follow.
*/
-qreal QDeclarativeSpringFollow::mass() const
+qreal QDeclarativeSpringAnimation::mass() const
{
- Q_D(const QDeclarativeSpringFollow);
+ Q_D(const QDeclarativeSpringAnimation);
return d->mass;
}
-void QDeclarativeSpringFollow::setMass(qreal mass)
+void QDeclarativeSpringAnimation::setMass(qreal mass)
{
- Q_D(QDeclarativeSpringFollow);
+ Q_D(QDeclarativeSpringAnimation);
if (d->mass != mass && mass > 0.0) {
d->useMass = mass != 1.0;
d->mass = mass;
@@ -416,49 +414,33 @@ void QDeclarativeSpringFollow::setMass(qreal mass)
}
}
-/*!
- \qmlproperty bool SpringFollow::enabled
- This property holds whether the target will track the source.
-
- The default value of this property is 'true'.
-*/
-bool QDeclarativeSpringFollow::enabled() const
-{
- Q_D(const QDeclarativeSpringFollow);
- return d->enabled;
-}
-
-void QDeclarativeSpringFollow::setEnabled(bool enabled)
+void QDeclarativeSpringAnimation::transition(QDeclarativeStateActions &actions,
+ QDeclarativeProperties &modified,
+ TransitionDirection direction)
{
- Q_D(QDeclarativeSpringFollow);
- d->enabled = enabled;
- if (enabled)
- d->start();
- else
- d->stop();
+ Q_D(QDeclarativeSpringAnimation);
+ Q_UNUSED(direction);
+
+ if (d->clock.state() != QAbstractAnimation::Running)
+ d->lastTime = 0;
+
+ if (!actions.isEmpty()) {
+ for (int i = 0; i < actions.size(); ++i) {
+ if (!d->toDefined)
+ d->to = actions.at(i).toValue.toReal();
+ if (!d->fromDefined)
+ d->currentValue = actions.at(i).fromValue.toReal();
+ if (d->mode != QDeclarativeSpringAnimationPrivate::Track)
+ modified << d->defaultProperty;
+ }
+ }
}
-/*!
- \qmlproperty bool SpringFollow::inSync
- This property is true when target is equal to the source; otherwise
- false. If inSync is true the target is not being animated.
- If \l enabled is false then inSync will also be false.
-*/
-bool QDeclarativeSpringFollow::inSync() const
-{
- Q_D(const QDeclarativeSpringFollow);
- return d->enabled && d->clock.state() != QAbstractAnimation::Running;
-}
-
-/*!
- \qmlproperty real SpringFollow::value
- The current value.
-*/
-qreal QDeclarativeSpringFollow::value() const
+QAbstractAnimation *QDeclarativeSpringAnimation::qtAnimation()
{
- Q_D(const QDeclarativeSpringFollow);
- return d->currentValue;
+ Q_D(QDeclarativeSpringAnimation);
+ return &d->clock;
}
QT_END_NAMESPACE
diff --git a/src/declarative/util/qdeclarativespringfollow_p.h b/src/declarative/util/qdeclarativespringanimation_p.h
index b829c57..6f574ef 100644
--- a/src/declarative/util/qdeclarativespringfollow_p.h
+++ b/src/declarative/util/qdeclarativespringanimation_p.h
@@ -39,11 +39,13 @@
**
****************************************************************************/
-#ifndef QDECLARATIVESMOOTHFOLLOW_H
-#define QDECLARATIVESMOOTHFOLLOW_H
+#ifndef QDECLARATIVESPRINGANIMATION_H
+#define QDECLARATIVESPRINGANIMATION_H
-#include <qdeclarativepropertyvaluesource.h>
#include <qdeclarative.h>
+#include "private/qdeclarativeanimation_p.h"
+
+#include <QtCore/qobject.h>
QT_BEGIN_HEADER
@@ -51,34 +53,34 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
-class QDeclarativeSpringFollowPrivate;
-class Q_DECLARATIVE_EXPORT QDeclarativeSpringFollow : public QObject,
- public QDeclarativePropertyValueSource
+class QDeclarativeSpringAnimationPrivate;
+class Q_AUTOTEST_EXPORT QDeclarativeSpringAnimation : public QDeclarativeAbstractAnimation
{
Q_OBJECT
- Q_DECLARE_PRIVATE(QDeclarativeSpringFollow)
+ Q_DECLARE_PRIVATE(QDeclarativeSpringAnimation)
Q_INTERFACES(QDeclarativePropertyValueSource)
- Q_PROPERTY(qreal to READ to WRITE setTo)
+ Q_PROPERTY(qreal to READ to WRITE setTo NOTIFY toChanged)
+ Q_PROPERTY(qreal from READ from WRITE setFrom NOTIFY fromChanged)
Q_PROPERTY(qreal velocity READ velocity WRITE setVelocity)
Q_PROPERTY(qreal spring READ spring WRITE setSpring)
Q_PROPERTY(qreal damping READ damping WRITE setDamping)
Q_PROPERTY(qreal epsilon READ epsilon WRITE setEpsilon)
- Q_PROPERTY(bool enabled READ enabled WRITE setEnabled)
- Q_PROPERTY(qreal value READ value NOTIFY valueChanged)
Q_PROPERTY(qreal modulus READ modulus WRITE setModulus NOTIFY modulusChanged)
Q_PROPERTY(qreal mass READ mass WRITE setMass NOTIFY massChanged)
- Q_PROPERTY(bool inSync READ inSync NOTIFY syncChanged)
public:
- QDeclarativeSpringFollow(QObject *parent=0);
- ~QDeclarativeSpringFollow();
+ QDeclarativeSpringAnimation(QObject *parent=0);
+ ~QDeclarativeSpringAnimation();
virtual void setTarget(const QDeclarativeProperty &);
qreal to() const;
void setTo(qreal value);
+ qreal from() const;
+ void setFrom(qreal value);
+
qreal velocity() const;
void setVelocity(qreal velocity);
@@ -100,12 +102,16 @@ public:
bool enabled() const;
void setEnabled(bool enabled);
- bool inSync() const;
+ virtual void transition(QDeclarativeStateActions &actions,
+ QDeclarativeProperties &modified,
+ TransitionDirection direction);
- qreal value() const;
+protected:
+ virtual QAbstractAnimation *qtAnimation();
Q_SIGNALS:
- void valueChanged(qreal);
+ void toChanged(qreal);
+ void fromChanged(qreal);
void modulusChanged();
void massChanged();
void syncChanged();
@@ -113,8 +119,8 @@ Q_SIGNALS:
QT_END_NAMESPACE
-QML_DECLARE_TYPE(QDeclarativeSpringFollow)
+QML_DECLARE_TYPE(QDeclarativeSpringAnimation)
QT_END_HEADER
-#endif // QDECLARATIVESMOOTHFOLLOW_H
+#endif // QDECLARATIVESPRINGANIMATION_H
diff --git a/src/declarative/util/qdeclarativestateoperations_p.h b/src/declarative/util/qdeclarativestateoperations_p.h
index 05ad052..4f905b6 100644
--- a/src/declarative/util/qdeclarativestateoperations_p.h
+++ b/src/declarative/util/qdeclarativestateoperations_p.h
@@ -55,7 +55,7 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
class QDeclarativeParentChangePrivate;
-class Q_DECLARATIVE_EXPORT QDeclarativeParentChange : public QDeclarativeStateOperation, public QDeclarativeActionEvent
+class Q_AUTOTEST_EXPORT QDeclarativeParentChange : public QDeclarativeStateOperation, public QDeclarativeActionEvent
{
Q_OBJECT
Q_DECLARE_PRIVATE(QDeclarativeParentChange)
@@ -118,7 +118,7 @@ public:
};
class QDeclarativeStateChangeScriptPrivate;
-class Q_DECLARATIVE_EXPORT QDeclarativeStateChangeScript : public QDeclarativeStateOperation, public QDeclarativeActionEvent
+class Q_AUTOTEST_EXPORT QDeclarativeStateChangeScript : public QDeclarativeStateOperation, public QDeclarativeActionEvent
{
Q_OBJECT
Q_DECLARE_PRIVATE(QDeclarativeStateChangeScript)
@@ -251,7 +251,7 @@ private:
};
class QDeclarativeAnchorChangesPrivate;
-class Q_DECLARATIVE_EXPORT QDeclarativeAnchorChanges : public QDeclarativeStateOperation, public QDeclarativeActionEvent
+class Q_AUTOTEST_EXPORT QDeclarativeAnchorChanges : public QDeclarativeStateOperation, public QDeclarativeActionEvent
{
Q_OBJECT
Q_DECLARE_PRIVATE(QDeclarativeAnchorChanges)
diff --git a/src/declarative/util/qdeclarativestyledtext.cpp b/src/declarative/util/qdeclarativestyledtext.cpp
index babd71b..91566bc 100644
--- a/src/declarative/util/qdeclarativestyledtext.cpp
+++ b/src/declarative/util/qdeclarativestyledtext.cpp
@@ -152,8 +152,6 @@ void QDeclarativeStyledTextPrivate::parse()
QTextCharFormat format;
if (formatStack.count())
format = formatStack.top();
- else
- format.setFont(baseFont);
if (parseTag(ch, text, drawText, format))
formatStack.push(format);
}
@@ -198,8 +196,10 @@ bool QDeclarativeStyledTextPrivate::parseTag(const QChar *&ch, const QString &te
if (char0 == QLatin1Char('b')) {
if (tagLength == 1)
format.setFontWeight(QFont::Bold);
- else if (tagLength == 2 && tag.at(1) == QLatin1Char('r'))
+ else if (tagLength == 2 && tag.at(1) == QLatin1Char('r')) {
textOut.append(QChar(QChar::LineSeparator));
+ return false;
+ }
} else if (char0 == QLatin1Char('i')) {
if (tagLength == 1)
format.setFontItalic(true);
diff --git a/src/declarative/util/qdeclarativestyledtext_p.h b/src/declarative/util/qdeclarativestyledtext_p.h
index 8d2c42d..d80ff9d 100644
--- a/src/declarative/util/qdeclarativestyledtext_p.h
+++ b/src/declarative/util/qdeclarativestyledtext_p.h
@@ -52,7 +52,7 @@ class QString;
class QDeclarativeStyledTextPrivate;
class QTextLayout;
-class Q_DECLARATIVE_EXPORT QDeclarativeStyledText
+class Q_AUTOTEST_EXPORT QDeclarativeStyledText
{
public:
static void parse(const QString &string, QTextLayout &layout);
diff --git a/src/declarative/util/qdeclarativesystempalette_p.h b/src/declarative/util/qdeclarativesystempalette_p.h
index 9fa6b08..4dfbeff 100644
--- a/src/declarative/util/qdeclarativesystempalette_p.h
+++ b/src/declarative/util/qdeclarativesystempalette_p.h
@@ -54,7 +54,7 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
class QDeclarativeSystemPalettePrivate;
-class Q_DECLARATIVE_EXPORT QDeclarativeSystemPalette : public QObject
+class Q_AUTOTEST_EXPORT QDeclarativeSystemPalette : public QObject
{
Q_OBJECT
Q_ENUMS(ColorGroup)
diff --git a/src/declarative/util/qdeclarativetimer.cpp b/src/declarative/util/qdeclarativetimer.cpp
index 9e18eb5..576995f 100644
--- a/src/declarative/util/qdeclarativetimer.cpp
+++ b/src/declarative/util/qdeclarativetimer.cpp
@@ -103,6 +103,8 @@ public:
1000ms has its \e repeat property changed 500ms after starting, the
elapsed time will be reset to 0, and the Timer will be triggered
1000ms later.
+
+ \sa {declarative/toys/clocks}{Clocks example}
*/
QDeclarativeTimer::QDeclarativeTimer(QObject *parent)
diff --git a/src/declarative/util/qdeclarativetimer_p.h b/src/declarative/util/qdeclarativetimer_p.h
index 08c3d4e..93b0965 100644
--- a/src/declarative/util/qdeclarativetimer_p.h
+++ b/src/declarative/util/qdeclarativetimer_p.h
@@ -54,7 +54,7 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
class QDeclarativeTimerPrivate;
-class Q_DECLARATIVE_EXPORT QDeclarativeTimer : public QObject, public QDeclarativeParserStatus
+class Q_AUTOTEST_EXPORT QDeclarativeTimer : public QObject, public QDeclarativeParserStatus
{
Q_OBJECT
Q_DECLARE_PRIVATE(QDeclarativeTimer)
diff --git a/src/declarative/util/qdeclarativetransition.cpp b/src/declarative/util/qdeclarativetransition.cpp
index ab8b116..38ed97e 100644
--- a/src/declarative/util/qdeclarativetransition.cpp
+++ b/src/declarative/util/qdeclarativetransition.cpp
@@ -56,7 +56,7 @@ QT_BEGIN_NAMESPACE
\since 4.7
\brief The Transition element defines animated transitions that occur on state changes.
- \sa {qmlstates}{States}, {state-transitions}{Transitions}, {QtDeclarative}
+ \sa {declarative/animation/states}{states example}, {qmlstates}{States}, {state-transitions}{Transitions}, {QtDeclarative}
*/
/*!
diff --git a/src/declarative/util/qdeclarativeutilmodule.cpp b/src/declarative/util/qdeclarativeutilmodule.cpp
index 3cf07a7..c5bfebd 100644
--- a/src/declarative/util/qdeclarativeutilmodule.cpp
+++ b/src/declarative/util/qdeclarativeutilmodule.cpp
@@ -46,7 +46,6 @@
#include "private/qdeclarativebind_p.h"
#include "private/qdeclarativeconnections_p.h"
#include "private/qdeclarativesmoothedanimation_p.h"
-#include "private/qdeclarativesmoothedfollow_p.h"
#include "private/qdeclarativefontloader_p.h"
#include "private/qdeclarativelistaccessor_p.h"
#include "private/qdeclarativelistmodel_p.h"
@@ -56,7 +55,7 @@
#include "private/qdeclarativepixmapcache_p.h"
#include "private/qdeclarativepropertychanges_p.h"
#include "qdeclarativepropertymap.h"
-#include "private/qdeclarativespringfollow_p.h"
+#include "private/qdeclarativespringanimation_p.h"
#include "private/qdeclarativestategroup_p.h"
#include "private/qdeclarativestateoperations_p.h"
#include "private/qdeclarativestate_p.h"
@@ -83,7 +82,6 @@ void QDeclarativeUtilModule::defineModule()
qmlRegisterType<QDeclarativeColorAnimation>("Qt",4,7,"ColorAnimation");
qmlRegisterType<QDeclarativeConnections>("Qt",4,7,"Connections");
qmlRegisterType<QDeclarativeSmoothedAnimation>("Qt",4,7,"SmoothedAnimation");
- qmlRegisterType<QDeclarativeSmoothedFollow>("Qt",4,7,"SmoothedFollow");
qmlRegisterType<QDeclarativeFontLoader>("Qt",4,7,"FontLoader");
qmlRegisterType<QDeclarativeListElement>("Qt",4,7,"ListElement");
qmlRegisterType<QDeclarativeNumberAnimation>("Qt",4,7,"NumberAnimation");
@@ -97,7 +95,7 @@ void QDeclarativeUtilModule::defineModule()
qmlRegisterType<QDeclarativeRotationAnimation>("Qt",4,7,"RotationAnimation");
qmlRegisterType<QDeclarativeScriptAction>("Qt",4,7,"ScriptAction");
qmlRegisterType<QDeclarativeSequentialAnimation>("Qt",4,7,"SequentialAnimation");
- qmlRegisterType<QDeclarativeSpringFollow>("Qt",4,7,"SpringFollow");
+ qmlRegisterType<QDeclarativeSpringAnimation>("Qt",4,7,"SpringAnimation");
qmlRegisterType<QDeclarativeStateChangeScript>("Qt",4,7,"StateChangeScript");
qmlRegisterType<QDeclarativeStateGroup>("Qt",4,7,"StateGroup");
qmlRegisterType<QDeclarativeState>("Qt",4,7,"State");
diff --git a/src/declarative/util/qdeclarativeview.cpp b/src/declarative/util/qdeclarativeview.cpp
index 0414e65..496f2ad 100644
--- a/src/declarative/util/qdeclarativeview.cpp
+++ b/src/declarative/util/qdeclarativeview.cpp
@@ -194,45 +194,46 @@ void QDeclarativeViewPrivate::itemGeometryChanged(QDeclarativeItem *resizeItem,
\since 4.7
\brief The QDeclarativeView class provides a widget for displaying a Qt Declarative user interface.
- Any QGraphicsObject or QDeclarativeItem
- created via QML can be placed on a standard QGraphicsScene and viewed with a standard
- QGraphicsView.
+ QDeclarativeItem objects can be placed on a standard QGraphicsScene and
+ displayed with QGraphicsView. QDeclarativeView is a QGraphicsView subclass
+ provided as a convenience for displaying QML files, and connecting between
+ QML and C++ Qt objects.
- QDeclarativeView is a QGraphicsView subclass provided as a convenience for displaying QML
- files, and connecting between QML and C++ Qt objects.
-
- QDeclarativeView performs the following functions:
+ QDeclarativeView provides:
\list
- \o Manages QDeclarativeComponent loading and object creation.
- \o Initializes QGraphicsView for optimal performance with QML:
+ \o Management of QDeclarativeComponent loading and object creation
+ \o Initialization of QGraphicsView for optimal performance with QML using these settings:
\list
- \o QGraphicsView::setOptimizationFlags(QGraphicsView::DontSavePainterState);
- \o QGraphicsView::setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
- \o QGraphicsScene::setItemIndexMethod(QGraphicsScene::NoIndex);
+ \o QGraphicsView::setOptimizationFlags(QGraphicsView::DontSavePainterState)
+ \o QGraphicsView::setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate)
+ \o QGraphicsScene::setItemIndexMethod(QGraphicsScene::NoIndex)
\endlist
- \o Initializes QGraphicsView for QML key handling:
+ \o Initialization of QGraphicsView for QML key handling using these settings:
\list
- \o QGraphicsView::viewport()->setFocusPolicy(Qt::NoFocus);
- \o QGraphicsView::setFocusPolicy(Qt::StrongFocus);
- \o QGraphicsScene::setStickyFocus(true);
+ \o QGraphicsView::viewport()->setFocusPolicy(Qt::NoFocus)
+ \o QGraphicsView::setFocusPolicy(Qt::StrongFocus)
+ \o QGraphicsScene::setStickyFocus(true)
\endlist
\endlist
Typical usage:
- \code
- ...
- QDeclarativeView *view = new QDeclarativeView(this);
- vbox->addWidget(view);
- QUrl url = QUrl::fromLocalFile(fileName);
- view->setSource(url);
+ \code
+ QDeclarativeView *view = new QDeclarativeView;
+ view->setSource(QUrl::fromLocalFile("myqmlfile.qml"));
view->show();
\endcode
+ Since QDeclarativeView is a QWidget-based class, it can be used to
+ display QML interfaces within QWidget-based GUI applications that do not
+ use the Graphics View framework.
+
To receive errors related to loading and executing QML with QDeclarativeView,
you can connect to the statusChanged() signal and monitor for QDeclarativeView::Error.
The errors are available via QDeclarativeView::errors().
+
+ \sa {Integrating QML with existing Qt UI code}, {Using QML in C++ Applications}
*/
@@ -611,7 +612,7 @@ void QDeclarativeView::timerEvent(QTimerEvent* e)
}
}
-/*! \reimp */
+/*! \internal */
bool QDeclarativeView::eventFilter(QObject *watched, QEvent *e)
{
Q_D(QDeclarativeView);
diff --git a/src/declarative/util/qdeclarativexmllistmodel.cpp b/src/declarative/util/qdeclarativexmllistmodel.cpp
index bfd25be..00169db 100644
--- a/src/declarative/util/qdeclarativexmllistmodel.cpp
+++ b/src/declarative/util/qdeclarativexmllistmodel.cpp
@@ -588,6 +588,8 @@ void QDeclarativeXmlListModelPrivate::clear_role(QDeclarativeListProperty<QDecla
If multiple key roles are specified, the model only adds and reload items
with a combined value of all key roles that is not already present in
the model.
+
+ \sa {demos/declarative/rssnews}{RSS News demo}
*/
QDeclarativeXmlListModel::QDeclarativeXmlListModel(QObject *parent)
@@ -665,7 +667,7 @@ QString QDeclarativeXmlListModel::toString(int role) const
\qmlproperty url XmlListModel::source
The location of the XML data source.
- If both source and xml are set, xml will be used.
+ If both \c source and \l xml are set, \l xml is used.
*/
QUrl QDeclarativeXmlListModel::source() const
{
@@ -690,7 +692,7 @@ void QDeclarativeXmlListModel::setSource(const QUrl &src)
The text is assumed to be UTF-8 encoded.
- If both \l source and \c xml are set, \c xml will be used.
+ If both \l source and \c xml are set, \c xml is used.
*/
QString QDeclarativeXmlListModel::xml() const
{
diff --git a/src/declarative/util/qdeclarativexmllistmodel_p.h b/src/declarative/util/qdeclarativexmllistmodel_p.h
index 8d848c8..832847e 100644
--- a/src/declarative/util/qdeclarativexmllistmodel_p.h
+++ b/src/declarative/util/qdeclarativexmllistmodel_p.h
@@ -70,7 +70,7 @@ struct QDeclarativeXmlQueryResult {
QStringList keyRoleResultsCache;
};
-class Q_DECLARATIVE_EXPORT QDeclarativeXmlListModel : public QListModelInterface, public QDeclarativeParserStatus
+class Q_AUTOTEST_EXPORT QDeclarativeXmlListModel : public QListModelInterface, public QDeclarativeParserStatus
{
Q_OBJECT
Q_INTERFACES(QDeclarativeParserStatus)
@@ -149,7 +149,7 @@ private:
Q_DISABLE_COPY(QDeclarativeXmlListModel)
};
-class Q_DECLARATIVE_EXPORT QDeclarativeXmlListModelRole : public QObject
+class Q_AUTOTEST_EXPORT QDeclarativeXmlListModelRole : public QObject
{
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
diff --git a/src/declarative/util/util.pri b/src/declarative/util/util.pri
index 04cfc68..fd57144 100644
--- a/src/declarative/util/util.pri
+++ b/src/declarative/util/util.pri
@@ -7,9 +7,8 @@ SOURCES += \
$$PWD/qdeclarativepackage.cpp \
$$PWD/qdeclarativeanimation.cpp \
$$PWD/qdeclarativesystempalette.cpp \
- $$PWD/qdeclarativespringfollow.cpp \
+ $$PWD/qdeclarativespringanimation.cpp \
$$PWD/qdeclarativesmoothedanimation.cpp \
- $$PWD/qdeclarativesmoothedfollow.cpp \
$$PWD/qdeclarativestate.cpp\
$$PWD/qdeclarativetransitionmanager.cpp \
$$PWD/qdeclarativestateoperations.cpp \
@@ -38,9 +37,8 @@ HEADERS += \
$$PWD/qdeclarativeanimation_p.h \
$$PWD/qdeclarativeanimation_p_p.h \
$$PWD/qdeclarativesystempalette_p.h \
- $$PWD/qdeclarativespringfollow_p.h \
+ $$PWD/qdeclarativespringanimation_p.h \
$$PWD/qdeclarativesmoothedanimation_p.h \
- $$PWD/qdeclarativesmoothedfollow_p.h \
$$PWD/qdeclarativesmoothedanimation_p_p.h \
$$PWD/qdeclarativestate_p.h\
$$PWD/qdeclarativestateoperations_p.h \