diff options
Diffstat (limited to 'src/declarative/graphicsitems')
38 files changed, 620 insertions, 1931 deletions
diff --git a/src/declarative/graphicsitems/graphicsitems.pri b/src/declarative/graphicsitems/graphicsitems.pri index 3ff92b1..d30651b 100644 --- a/src/declarative/graphicsitems/graphicsitems.pri +++ b/src/declarative/graphicsitems/graphicsitems.pri @@ -48,7 +48,6 @@ HEADERS += \ $$PWD/qdeclarativevisualitemmodel_p.h \ $$PWD/qdeclarativelistview_p.h \ $$PWD/qdeclarativegraphicsobjectcontainer_p.h \ - $$PWD/qdeclarativeparticles_p.h \ $$PWD/qdeclarativelayoutitem_p.h \ $$PWD/qdeclarativeitemchangelistener_p.h \ $$PWD/qdeclarativeeffects.cpp @@ -82,5 +81,4 @@ SOURCES += \ $$PWD/qdeclarativevisualitemmodel.cpp \ $$PWD/qdeclarativelistview.cpp \ $$PWD/qdeclarativegraphicsobjectcontainer.cpp \ - $$PWD/qdeclarativeparticles.cpp \ - $$PWD/qdeclarativelayoutitem.cpp \ + $$PWD/qdeclarativelayoutitem.cpp diff --git a/src/declarative/graphicsitems/qdeclarativeanchors_p.h b/src/declarative/graphicsitems/qdeclarativeanchors_p.h index 0b97e8c..1961fdd 100644 --- a/src/declarative/graphicsitems/qdeclarativeanchors_p.h +++ b/src/declarative/graphicsitems/qdeclarativeanchors_p.h @@ -55,7 +55,7 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) class QDeclarativeAnchorsPrivate; -class QDeclarativeAnchorLine; +struct QDeclarativeAnchorLine; class Q_DECLARATIVE_EXPORT QDeclarativeAnchors : public QObject { Q_OBJECT diff --git a/src/declarative/graphicsitems/qdeclarativeanimatedimage.cpp b/src/declarative/graphicsitems/qdeclarativeanimatedimage.cpp index 20b1de3..2c2e034 100644 --- a/src/declarative/graphicsitems/qdeclarativeanimatedimage.cpp +++ b/src/declarative/graphicsitems/qdeclarativeanimatedimage.cpp @@ -247,9 +247,25 @@ void QDeclarativeAnimatedImage::setSource(const QUrl &url) emit statusChanged(d->status); } +#define ANIMATEDIMAGE_MAXIMUM_REDIRECT_RECURSION 16 + void QDeclarativeAnimatedImage::movieRequestFinished() { Q_D(QDeclarativeAnimatedImage); + + d->redirectCount++; + if (d->redirectCount < ANIMATEDIMAGE_MAXIMUM_REDIRECT_RECURSION) { + QVariant redirect = d->reply->attribute(QNetworkRequest::RedirectionTargetAttribute); + if (redirect.isValid()) { + QUrl url = d->reply->url().resolved(redirect.toUrl()); + d->reply->deleteLater(); + d->reply = 0; + setSource(url); + return; + } + } + d->redirectCount=0; + d->_movie = new QMovie(d->reply); if (!d->_movie->isValid()){ qWarning() << "Error Reading Animated Image File " << d->url; diff --git a/src/declarative/graphicsitems/qdeclarativeanimatedimage_p_p.h b/src/declarative/graphicsitems/qdeclarativeanimatedimage_p_p.h index 39bb3e5..273c1d6 100644 --- a/src/declarative/graphicsitems/qdeclarativeanimatedimage_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativeanimatedimage_p_p.h @@ -66,7 +66,7 @@ class QDeclarativeAnimatedImagePrivate : public QDeclarativeImagePrivate public: QDeclarativeAnimatedImagePrivate() - : playing(true), paused(false), preset_currentframe(0), _movie(0), reply(0) + : playing(true), paused(false), preset_currentframe(0), _movie(0), reply(0), redirectCount(0) { } @@ -75,6 +75,7 @@ public: int preset_currentframe; QMovie *_movie; QNetworkReply *reply; + int redirectCount; }; QT_END_NAMESPACE diff --git a/src/declarative/graphicsitems/qdeclarativeborderimage.cpp b/src/declarative/graphicsitems/qdeclarativeborderimage.cpp index de16668..a7534b8 100644 --- a/src/declarative/graphicsitems/qdeclarativeborderimage.cpp +++ b/src/declarative/graphicsitems/qdeclarativeborderimage.cpp @@ -191,7 +191,7 @@ void QDeclarativeBorderImage::load() update(); } else { d->status = Loading; - if (d->url.path().endsWith(QLatin1String(".sci"))) { + if (d->url.path().endsWith(QLatin1String("sci"))) { #ifndef QT_NO_LOCALFILE_OPTIMIZED_QML QString lf = toLocalFileOrQrc(d->url); if (!lf.isEmpty()) { @@ -400,9 +400,23 @@ void QDeclarativeBorderImage::requestFinished() update(); } +#define BORDERIMAGE_MAX_REDIRECT 16 + void QDeclarativeBorderImage::sciRequestFinished() { Q_D(QDeclarativeBorderImage); + + d->redirectCount++; + if (d->redirectCount < BORDERIMAGE_MAX_REDIRECT) { + QVariant redirect = d->sciReply->attribute(QNetworkRequest::RedirectionTargetAttribute); + if (redirect.isValid()) { + QUrl url = d->sciReply->url().resolved(redirect.toUrl()); + setSource(url); + return; + } + } + d->redirectCount=0; + if (d->sciReply->error() != QNetworkReply::NoError) { d->status = Error; d->sciReply->deleteLater(); diff --git a/src/declarative/graphicsitems/qdeclarativeborderimage_p_p.h b/src/declarative/graphicsitems/qdeclarativeborderimage_p_p.h index b9cf73a..82b9ebf 100644 --- a/src/declarative/graphicsitems/qdeclarativeborderimage_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativeborderimage_p_p.h @@ -68,7 +68,8 @@ public: : border(0), sciReply(0), sciPendingPixmapCache(false), horizontalTileMode(QDeclarativeBorderImage::Stretch), - verticalTileMode(QDeclarativeBorderImage::Stretch) + verticalTileMode(QDeclarativeBorderImage::Stretch), + redirectCount(0) { } @@ -90,6 +91,7 @@ public: bool sciPendingPixmapCache; QDeclarativeBorderImage::TileMode horizontalTileMode; QDeclarativeBorderImage::TileMode verticalTileMode; + int redirectCount; }; QT_END_NAMESPACE diff --git a/src/declarative/graphicsitems/qdeclarativeflickable.cpp b/src/declarative/graphicsitems/qdeclarativeflickable.cpp index 67068a0..9ccb3b6 100644 --- a/src/declarative/graphicsitems/qdeclarativeflickable.cpp +++ b/src/declarative/graphicsitems/qdeclarativeflickable.cpp @@ -264,6 +264,7 @@ void QDeclarativeFlickablePrivate::fixupY() void QDeclarativeFlickablePrivate::fixup(AxisData &data, qreal minExtent, qreal maxExtent) { + Q_Q(QDeclarativeFlickable); if (data.move.value() > minExtent || maxExtent > minExtent) { timeline.reset(data.move); if (data.move.value() != minExtent) { @@ -273,6 +274,7 @@ void QDeclarativeFlickablePrivate::fixup(AxisData &data, qreal minExtent, qreal timeline.move(data.move, minExtent, QEasingCurve(QEasingCurve::OutQuint), 3*fixupDuration/4); } else { data.move.setValue(minExtent); + q->viewportMoved(); } } //emit flickingChanged(); @@ -284,6 +286,7 @@ void QDeclarativeFlickablePrivate::fixup(AxisData &data, qreal minExtent, qreal timeline.move(data.move, maxExtent, QEasingCurve(QEasingCurve::OutQuint), 3*fixupDuration/4); } else { data.move.setValue(maxExtent); + q->viewportMoved(); } //emit flickingChanged(); } else { diff --git a/src/declarative/graphicsitems/qdeclarativefocuspanel.cpp b/src/declarative/graphicsitems/qdeclarativefocuspanel.cpp index 0323a59..20524b6 100644 --- a/src/declarative/graphicsitems/qdeclarativefocuspanel.cpp +++ b/src/declarative/graphicsitems/qdeclarativefocuspanel.cpp @@ -41,6 +41,8 @@ #include "qdeclarativefocuspanel_p.h" +#include "qdeclarativeitem_p.h" + #include <QtGui/qgraphicsscene.h> #include <QEvent> @@ -65,7 +67,8 @@ QT_BEGIN_NAMESPACE QDeclarativeFocusPanel::QDeclarativeFocusPanel(QDeclarativeItem *parent) : QDeclarativeItem(parent) { - setFlag(ItemIsPanel); + Q_D(QDeclarativeItem); + d->flags |= QGraphicsItem::ItemIsPanel; } QDeclarativeFocusPanel::~QDeclarativeFocusPanel() diff --git a/src/declarative/graphicsitems/qdeclarativefocuspanel_p.h b/src/declarative/graphicsitems/qdeclarativefocuspanel_p.h index 1ad8b6e..d9ca0b0 100644 --- a/src/declarative/graphicsitems/qdeclarativefocuspanel_p.h +++ b/src/declarative/graphicsitems/qdeclarativefocuspanel_p.h @@ -66,6 +66,7 @@ protected: private: Q_DISABLE_COPY(QDeclarativeFocusPanel) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeItem) }; QT_END_NAMESPACE diff --git a/src/declarative/graphicsitems/qdeclarativefocusscope.cpp b/src/declarative/graphicsitems/qdeclarativefocusscope.cpp index 384a47b..484df13 100644 --- a/src/declarative/graphicsitems/qdeclarativefocusscope.cpp +++ b/src/declarative/graphicsitems/qdeclarativefocusscope.cpp @@ -41,6 +41,8 @@ #include "qdeclarativefocusscope_p.h" +#include "qdeclarativeitem_p.h" + QT_BEGIN_NAMESPACE /*! @@ -62,7 +64,8 @@ QT_BEGIN_NAMESPACE QDeclarativeFocusScope::QDeclarativeFocusScope(QDeclarativeItem *parent) : QDeclarativeItem(parent) { - setFlag(QGraphicsItem::ItemIsFocusScope); + Q_D(QDeclarativeItem); + d->flags |= QGraphicsItem::ItemIsFocusScope; } QDeclarativeFocusScope::~QDeclarativeFocusScope() diff --git a/src/declarative/graphicsitems/qdeclarativefocusscope_p.h b/src/declarative/graphicsitems/qdeclarativefocusscope_p.h index cd480b4..c65a07c 100644 --- a/src/declarative/graphicsitems/qdeclarativefocusscope_p.h +++ b/src/declarative/graphicsitems/qdeclarativefocusscope_p.h @@ -54,6 +54,7 @@ QT_MODULE(Declarative) class Q_DECLARATIVE_EXPORT QDeclarativeFocusScope : public QDeclarativeItem { Q_OBJECT + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeItem) public: QDeclarativeFocusScope(QDeclarativeItem *parent=0); virtual ~QDeclarativeFocusScope(); diff --git a/src/declarative/graphicsitems/qdeclarativegraphicsobjectcontainer.cpp b/src/declarative/graphicsitems/qdeclarativegraphicsobjectcontainer.cpp index 1977817..eb5b6ce 100644 --- a/src/declarative/graphicsitems/qdeclarativegraphicsobjectcontainer.cpp +++ b/src/declarative/graphicsitems/qdeclarativegraphicsobjectcontainer.cpp @@ -65,12 +65,12 @@ public: if (graphicsObject && graphicsObject->isWidget()) { if (!on) { graphicsObject->removeEventFilter(q); - QObject::disconnect(q, SIGNAL(widthChanged()), q, SLOT(_q_updateSize())); - QObject::disconnect(q, SIGNAL(heightChanged()), q, SLOT(_q_updateSize())); + QObject::disconnect(q, SIGNAL(widthChanged(qreal)), q, SLOT(_q_updateSize())); + QObject::disconnect(q, SIGNAL(heightChanged(qreal)), q, SLOT(_q_updateSize())); } else { graphicsObject->installEventFilter(q); - QObject::connect(q, SIGNAL(widthChanged()), q, SLOT(_q_updateSize())); - QObject::connect(q, SIGNAL(heightChanged()), q, SLOT(_q_updateSize())); + QObject::connect(q, SIGNAL(widthChanged(qreal)), q, SLOT(_q_updateSize())); + QObject::connect(q, SIGNAL(heightChanged(qreal)), q, SLOT(_q_updateSize())); } } } diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index 60ffbe2..93f8d06 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -81,6 +81,10 @@ public: item->setPos(QPointF(row, col)); } } + bool contains(int x, int y) const { + return (x >= item->x() && x < item->x() + view->cellWidth() && + y >= item->y() && y < item->y() + view->cellHeight()); + } QDeclarativeItem *item; QDeclarativeGridView *view; @@ -97,7 +101,7 @@ class QDeclarativeGridViewPrivate : public QDeclarativeFlickablePrivate public: QDeclarativeGridViewPrivate() : currentItem(0), flow(QDeclarativeGridView::LeftToRight) - , visiblePos(0), visibleIndex(0) , currentIndex(-1) + , visibleIndex(0) , currentIndex(-1) , cellWidth(100), cellHeight(100), columns(1), requestedIndex(-1) , highlightRangeStart(0), highlightRangeEnd(0), highlightRange(QDeclarativeGridView::NoHighlightRange) , highlightComponent(0), highlight(0), trackedItem(0) @@ -115,7 +119,7 @@ public: void updateGrid(); void scheduleLayout(); - void layout(bool removed=false); + void layout(); void updateUnrequestedIndexes(); void updateUnrequestedPositions(); void updateTrackedItem(); @@ -274,7 +278,7 @@ public: || newGeometry.width() != oldGeometry.width()) { if (q->isComponentComplete()) { updateGrid(); - layout(); + scheduleLayout(); } } } @@ -305,7 +309,6 @@ public: QHash<QDeclarativeItem*,int> unrequestedItems; FxGridItem *currentItem; QDeclarativeGridView::Flow flow; - int visiblePos; int visibleIndex; int currentIndex; int cellWidth; @@ -350,7 +353,6 @@ void QDeclarativeGridViewPrivate::clear() for (int i = 0; i < visibleItems.count(); ++i) releaseItem(visibleItems.at(i)); visibleItems.clear(); - visiblePos = 0; visibleIndex = 0; releaseItem(currentItem); currentItem = 0; @@ -536,11 +538,11 @@ void QDeclarativeGridViewPrivate::scheduleLayout() Q_Q(QDeclarativeGridView); if (!layoutScheduled) { layoutScheduled = true; - QMetaObject::invokeMethod(q, "layout", Qt::QueuedConnection); + QCoreApplication::postEvent(q, new QEvent(QEvent::User), Qt::HighEventPriority); } } -void QDeclarativeGridViewPrivate::layout(bool removed) +void QDeclarativeGridViewPrivate::layout() { Q_Q(QDeclarativeGridView); layoutScheduled = false; @@ -549,8 +551,6 @@ void QDeclarativeGridViewPrivate::layout(bool removed) qreal colPos = visibleItems.first()->colPos(); int col = visibleIndex % columns; if (colPos != col * colSize()) { - if (removed) - rowPos -= rowSize(); colPos = col * colSize(); visibleItems.first()->setPosition(colPos, rowPos); } @@ -748,21 +748,26 @@ void QDeclarativeGridViewPrivate::fixup(AxisData &data, qreal minExtent, qreal m if (currentItem && currentItem->rowPos() - position() != highlightRangeStart) { qreal pos = currentItem->rowPos() - highlightRangeStart; timeline.reset(data.move); - if (fixupDuration) + if (fixupDuration) { timeline.move(data.move, -pos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration/2); - else + } else { data.move.setValue(-pos); + q->viewportMoved(); + } vTime = timeline.time(); } } else if (snapMode != QDeclarativeGridView::NoSnap) { - qreal pos = qMax(qMin(snapPosAt(position()) - highlightRangeStart, -maxExtent), -minExtent); - qreal dist = qAbs(data.move + pos); + qreal pos = -snapPosAt(-(data.move.value() - highlightRangeStart)) + highlightRangeStart; + pos = qMin(qMax(pos, maxExtent), minExtent); + qreal dist = qAbs(data.move.value() - pos); if (dist > 0) { timeline.reset(data.move); - if (fixupDuration) - timeline.move(data.move, -pos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration/2); - else - data.move.setValue(-pos); + if (fixupDuration) { + timeline.move(data.move, pos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration/2); + } else { + data.move.setValue(pos); + q->viewportMoved(); + } vTime = timeline.time(); } } else { @@ -788,7 +793,7 @@ void QDeclarativeGridViewPrivate::flick(AxisData &data, qreal minExtent, qreal m if (FxGridItem *item = firstVisibleItem()) maxDistance = qAbs(item->rowPos() + data.move.value()); } else if (data.move.value() < minExtent) { - maxDistance = qAbs(minExtent - data.move.value() + (overShoot?overShootDistance(velocity, vSize):0)); + maxDistance = qAbs(minExtent - data.move.value()); } if (snapMode != QDeclarativeGridView::SnapToRow && highlightRange != QDeclarativeGridView::StrictlyEnforceRange) data.flickTarget = minExtent; @@ -797,7 +802,7 @@ void QDeclarativeGridViewPrivate::flick(AxisData &data, qreal minExtent, qreal m qreal pos = snapPosAt(-data.move.value()) + rowSize(); maxDistance = qAbs(pos + data.move.value()); } else if (data.move.value() > maxExtent) { - maxDistance = qAbs(maxExtent - data.move.value()) + (overShoot?overShootDistance(velocity, vSize):0); + maxDistance = qAbs(maxExtent - data.move.value()); } if (snapMode != QDeclarativeGridView::SnapToRow && highlightRange != QDeclarativeGridView::StrictlyEnforceRange) data.flickTarget = maxExtent; @@ -816,7 +821,8 @@ void QDeclarativeGridViewPrivate::flick(AxisData &data, qreal minExtent, qreal m qreal maxAccel = v2 / (2.0f * maxDistance); qreal overshootDist = 0.0; if (maxAccel < accel) { - qreal dist = v2 / (accel * 2.0); + // + rowSize()/4 to encourage moving at least one item in the flick direction + qreal dist = v2 / (accel * 2.0) + rowSize()/4; if (v > 0) dist = -dist; data.flickTarget = -snapPosAt(-(data.move.value() - highlightRangeStart) + dist) + highlightRangeStart; @@ -1421,6 +1427,17 @@ void QDeclarativeGridView::setSnapMode(SnapMode mode) } } +bool QDeclarativeGridView::event(QEvent *event) +{ + Q_D(QDeclarativeGridView); + if (event->type() == QEvent::User) { + d->layout(); + return true; + } + + return QDeclarativeFlickable::event(event); +} + void QDeclarativeGridView::viewportMoved() { Q_D(QDeclarativeGridView); @@ -1488,7 +1505,7 @@ qreal QDeclarativeGridView::maxYExtent() const return QDeclarativeFlickable::maxYExtent(); qreal extent; if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) - extent = -(d->rowPosAt(count()-1) - d->highlightRangeEnd); + extent = -(d->endPosition() - d->highlightRangeEnd); else extent = -(d->endPosition() - height()); const qreal minY = minYExtent(); @@ -1515,7 +1532,7 @@ qreal QDeclarativeGridView::maxXExtent() const return QDeclarativeFlickable::maxXExtent(); qreal extent; if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) - extent = -(d->rowPosAt(count()-1) - d->highlightRangeEnd); + extent = -(d->endPosition() - d->highlightRangeEnd); else extent = -(d->endPosition() - height()); const qreal minX = minXExtent(); @@ -1651,46 +1668,105 @@ void QDeclarativeGridView::moveCurrentIndexRight() } /*! - \qmlmethod GridView::positionViewAtIndex(int index) + \qmlmethod GridView::positionViewAtIndex(int index, PositionMode mode) + + Positions the view such that the \a index is at the position specified by + \a mode: + + \list + \o Beginning - position item at the top (or left for TopToBottom flow) of the view. + \o Center- position item in the center of the view. + \o End - position item at bottom (or right for horizontal orientation) of the view. + \o Visible - if any part of the item is visible then take no action, otherwise + bring the item into view. + \o Contain - ensure the entire item is visible. If the item is larger than + the view the item is positioned at the top (or left for TopToBottom flow) of the view. + \endlist - Positions the view such that the \a index is at the top (or left for horizontal orientation) of the view. If positioning the view at the index would cause empty space to be displayed at - the end of the view, the view will be positioned at the end. + the beginning or end of the view, the view will be positioned at the boundary. It is not recommended to use contentX or contentY to position the view at a particular index. This is unreliable since removing items from the start - of the list does not cause all other items to be repositioned. + of the view does not cause all other items to be repositioned. The correct way to bring an item into view is with positionViewAtIndex. */ -void QDeclarativeGridView::positionViewAtIndex(int index) +void QDeclarativeGridView::positionViewAtIndex(int index, int mode) { Q_D(QDeclarativeGridView); if (!d->isValid() || index < 0 || index >= d->model->count()) return; + if (mode < Beginning || mode > Contain) + return; - qreal maxExtent = d->flow == QDeclarativeGridView::LeftToRight ? -maxYExtent() : -maxXExtent(); + qreal pos = d->position(); FxGridItem *item = d->visibleItem(index); - if (item) { - // Already created - just move to top of view - int pos = qMin(item->rowPos(), maxExtent); - d->setPosition(pos); - } else { - int pos = d->rowPosAt(index); + if (!item) { + int itemPos = d->rowPosAt(index); // save the currently visible items in case any of them end up visible again QList<FxGridItem*> oldVisible = d->visibleItems; d->visibleItems.clear(); d->visibleIndex = index - index % d->columns; - d->setPosition(pos); - // setPosition() will cause refill. Adjust if we have moved beyond range - if (d->position() > maxExtent) - d->setPosition(maxExtent); + d->setPosition(itemPos); // now release the reference to all the old visible items. for (int i = 0; i < oldVisible.count(); ++i) d->releaseItem(oldVisible.at(i)); + item = d->visibleItem(index); + } + if (item) { + qreal itemPos = item->rowPos(); + switch (mode) { + case Beginning: + pos = itemPos; + break; + case Center: + pos = itemPos - (d->size() - d->rowSize())/2; + break; + case End: + pos = itemPos - d->size() + d->rowSize(); + break; + case Visible: + if (itemPos > pos + d->size()) + pos = itemPos - d->size() + d->rowSize(); + else if (item->endRowPos() < pos) + pos = itemPos; + break; + case Contain: + if (item->endRowPos() > pos + d->size()) + pos = itemPos - d->size() + d->rowSize(); + if (itemPos < pos) + pos = itemPos; + } + qreal maxExtent = d->flow == QDeclarativeGridView::LeftToRight ? -maxYExtent() : -maxXExtent(); + pos = qMin(pos, maxExtent); + qreal minExtent = d->flow == QDeclarativeGridView::LeftToRight ? -minYExtent() : -minXExtent(); + pos = qMax(pos, minExtent); + d->setPosition(pos); } d->fixupPosition(); } +/*! + \qmlmethod int GridView::indexAt(int x, int y) + + Returns the index of the visible item containing the point \a x, \a y in content + coordinates. If there is no item at the point specified, or the item is + not visible -1 is returned. + + 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. +*/ +int QDeclarativeGridView::indexAt(int x, int y) const +{ + Q_D(const QDeclarativeGridView); + for (int i = 0; i < d->visibleItems.count(); ++i) { + const FxGridItem *listItem = d->visibleItems.at(i); + if(listItem->contains(x, y)) + return listItem->index; + } + + return -1; +} void QDeclarativeGridView::componentComplete() { @@ -1763,7 +1839,7 @@ void QDeclarativeGridView::itemsInserted(int modelIndex, int count) { Q_D(QDeclarativeGridView); if (!d->visibleItems.count() || d->model->count() <= 1) { - refill(); + d->scheduleLayout(); d->updateCurrent(qMax(0, qMin(d->currentIndex, d->model->count()-1))); emit countChanged(); return; @@ -1792,8 +1868,9 @@ void QDeclarativeGridView::itemsInserted(int modelIndex, int count) d->currentIndex += count; if (d->currentItem) d->currentItem->index = d->currentIndex; + emit currentIndexChanged(); } - d->layout(); + d->scheduleLayout(); emit countChanged(); return; } @@ -1823,9 +1900,21 @@ void QDeclarativeGridView::itemsInserted(int modelIndex, int count) } } + // Update the indexes of the following visible items. + for (int i = 0; i < d->visibleItems.count(); ++i) { + FxGridItem *listItem = d->visibleItems.at(i); + if (listItem->index != -1 && listItem->index >= modelIndex) + listItem->index += count; + } + + bool addedVisible = false; QList<FxGridItem*> added; int i = 0; while (i < insertCount && rowPos <= to + d->rowSize()*(d->columns - (colPos/d->colSize()))/qreal(d->columns)) { + if (!addedVisible) { + d->scheduleLayout(); + addedVisible = true; + } FxGridItem *item = d->createItem(modelIndex + i); d->visibleItems.insert(index, item); item->setPosition(colPos, rowPos); @@ -1846,6 +1935,15 @@ void QDeclarativeGridView::itemsInserted(int modelIndex, int count) } } + // update visibleIndex + d->visibleIndex = 0; + for (QList<FxGridItem*>::Iterator it = d->visibleItems.begin(); it != d->visibleItems.end(); ++it) { + if ((*it)->index != -1) { + d->visibleIndex = (*it)->index; + break; + } + } + if (d->currentIndex >= modelIndex) { // adjust current item index d->currentIndex += count; @@ -1853,18 +1951,13 @@ void QDeclarativeGridView::itemsInserted(int modelIndex, int count) d->currentItem->index = d->currentIndex; d->currentItem->setPosition(d->colPosAt(d->currentIndex), d->rowPosAt(d->currentIndex)); } - } - // Update the indexes of the following visible items. - for (; index < d->visibleItems.count(); ++index) { - FxGridItem *listItem = d->visibleItems.at(index); - if (listItem->index != -1) - listItem->index += count; + emit currentIndexChanged(); } // everything is in order now - emit add() signal for (int j = 0; j < added.count(); ++j) added.at(j)->attached->emitAdd(); - d->layout(); + emit countChanged(); } @@ -1880,8 +1973,10 @@ void QDeclarativeGridView::itemsRemoved(int modelIndex, int count) FxGridItem *item = *it; if (item->index == -1 || item->index < modelIndex) { // already removed, or before removed items - if (item->index < modelIndex) + if (item->index < modelIndex && !removedVisible) { + d->scheduleLayout(); removedVisible = true; + } ++it; } else if (item->index >= modelIndex + count) { // after removed items @@ -1889,7 +1984,10 @@ void QDeclarativeGridView::itemsRemoved(int modelIndex, int count) ++it; } else { // removed item - removedVisible = true; + if (!removedVisible) { + d->scheduleLayout(); + removedVisible = true; + } item->attached->emitRemove(); if (item->attached->delayRemove()) { item->index = -1; @@ -1907,6 +2005,7 @@ void QDeclarativeGridView::itemsRemoved(int modelIndex, int count) d->currentIndex -= count; if (d->currentItem) d->currentItem->index -= count; + emit currentIndexChanged(); } else if (currentRemoved) { // current item has been removed. d->releaseItem(d->currentItem); @@ -1916,6 +2015,7 @@ void QDeclarativeGridView::itemsRemoved(int modelIndex, int count) } // update visibleIndex + d->visibleIndex = 0; for (it = d->visibleItems.begin(); it != d->visibleItems.end(); ++it) { if ((*it)->index != -1) { d->visibleIndex = (*it)->index; @@ -1923,27 +2023,16 @@ void QDeclarativeGridView::itemsRemoved(int modelIndex, int count) } } - if (removedVisible) { - if (d->visibleItems.isEmpty()) { - d->visibleIndex = 0; - d->setPosition(0); - refill(); - } else { - // Correct the positioning of the items - d->scheduleLayout(); - } + if (removedVisible && d->visibleItems.isEmpty()) { + d->timeline.clear(); + d->setPosition(0); + if (d->model->count() == 0) + update(); } emit countChanged(); } -void QDeclarativeGridView::layout() -{ - Q_D(QDeclarativeGridView); - if (d->layoutScheduled) - d->layout(); -} - void QDeclarativeGridView::destroyRemoved() { Q_D(QDeclarativeGridView); @@ -2055,7 +2144,7 @@ void QDeclarativeGridView::itemsMoved(int from, int to, int count) d->releaseItem(item); } - d->layout(removedBeforeVisible); + d->layout(); } void QDeclarativeGridView::modelReset() diff --git a/src/declarative/graphicsitems/qdeclarativegridview_p.h b/src/declarative/graphicsitems/qdeclarativegridview_p.h index 787c04c..90f13d2 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview_p.h +++ b/src/declarative/graphicsitems/qdeclarativegridview_p.h @@ -137,6 +137,12 @@ public: SnapMode snapMode() const; void setSnapMode(SnapMode mode); + enum PositionMode { Beginning, Center, End, Visible, Contain }; + Q_ENUMS(PositionMode); + + Q_INVOKABLE void positionViewAtIndex(int index, int mode); + Q_INVOKABLE int indexAt(int x, int y) const; + static QDeclarativeGridViewAttached *qmlAttachedProperties(QObject *); public Q_SLOTS: @@ -144,7 +150,6 @@ public Q_SLOTS: void moveCurrentIndexDown(); void moveCurrentIndexLeft(); void moveCurrentIndexRight(); - void positionViewAtIndex(int index); Q_SIGNALS: void countChanged(); @@ -164,6 +169,7 @@ Q_SIGNALS: void snapModeChanged(); protected: + virtual bool event(QEvent *event); virtual void viewportMoved(); virtual qreal minYExtent() const; virtual qreal maxYExtent() const; @@ -181,7 +187,6 @@ private Q_SLOTS: void destroyRemoved(); void createdItem(int index, QDeclarativeItem *item); void destroyingItem(QDeclarativeItem *item); - void layout(); private: void refill(); @@ -192,7 +197,7 @@ class QDeclarativeGridViewAttached : public QObject Q_OBJECT public: QDeclarativeGridViewAttached(QObject *parent) - : QObject(parent), m_isCurrent(false), m_delayRemove(false) {} + : QObject(parent), m_view(0), m_isCurrent(false), m_delayRemove(false) {} ~QDeclarativeGridViewAttached() {} Q_PROPERTY(QDeclarativeGridView *view READ view CONSTANT) diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp index c7d7a4c..4ba80ad 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp @@ -273,7 +273,7 @@ void QDeclarativeContents::calcHeight() m_height = qMax(bottom - top, qreal(0.0)); if (m_height != oldheight || m_y != oldy) - emit rectChanged(); + emit rectChanged(rectF()); } //TODO: optimization: only check sender(), if there is one @@ -301,7 +301,7 @@ void QDeclarativeContents::calcWidth() m_width = qMax(right - left, qreal(0.0)); if (m_width != oldwidth || m_x != oldx) - emit rectChanged(); + emit rectChanged(rectF()); } void QDeclarativeContents::setItem(QDeclarativeItem *item) @@ -313,11 +313,11 @@ void QDeclarativeContents::setItem(QDeclarativeItem *item) QDeclarativeItem *child = qobject_cast<QDeclarativeItem *>(children.at(i)); if(!child)//### Should this be ignoring non-QDeclarativeItem graphicsobjects? continue; - connect(child, SIGNAL(heightChanged()), this, SLOT(calcHeight())); + connect(child, SIGNAL(heightChanged(qreal)), this, SLOT(calcHeight())); connect(child, SIGNAL(yChanged()), this, SLOT(calcHeight())); - connect(child, SIGNAL(widthChanged()), this, SLOT(calcWidth())); + connect(child, SIGNAL(widthChanged(qreal)), this, SLOT(calcWidth())); connect(child, SIGNAL(xChanged()), this, SLOT(calcWidth())); - connect(this, SIGNAL(rectChanged()), m_item, SIGNAL(childrenRectChanged())); + connect(this, SIGNAL(rectChanged(QRectF)), m_item, SIGNAL(childrenRectChanged(QRectF))); } calcHeight(); @@ -1662,7 +1662,7 @@ void QDeclarativeItem::setClip(bool c) if (clip() == c) return; setFlag(ItemClipsChildrenToShape, c); - emit clipChanged(); + emit clipChanged(c); } /*! @@ -1802,11 +1802,11 @@ void QDeclarativeItem::geometryChanged(const QRectF &newGeometry, if (newGeometry.x() != oldGeometry.x()) emit xChanged(); if (newGeometry.width() != oldGeometry.width()) - emit widthChanged(); + emit widthChanged(newGeometry.width()); if (newGeometry.y() != oldGeometry.y()) emit yChanged(); if (newGeometry.height() != oldGeometry.height()) - emit heightChanged(); + emit heightChanged(newGeometry.height()); for(int ii = 0; ii < d->changeListeners.count(); ++ii) { const QDeclarativeItemPrivate::ChangeListener &change = d->changeListeners.at(ii); @@ -2068,7 +2068,6 @@ void QDeclarativeItem::setBaselineOffset(qreal offset) return; d->_baselineOffset = offset; - emit baselineOffsetChanged(); for(int ii = 0; ii < d->changeListeners.count(); ++ii) { const QDeclarativeItemPrivate::ChangeListener &change = d->changeListeners.at(ii); @@ -2078,6 +2077,7 @@ void QDeclarativeItem::setBaselineOffset(qreal offset) anchor->updateVerticalAnchors(); } } + emit baselineOffsetChanged(offset); } /*! @@ -2224,7 +2224,7 @@ void QDeclarativeItem::setKeepMouseGrab(bool keep) } /*! - \qmlmethod object Item::mapFromItem(Item item, int x, int y) + \qmlmethod object Item::mapFromItem(Item item, real x, real y) Maps the point (\a x, \a y), which is in \a item's coordinate system, to this item's coordinate system, and returns an object with \c x and \c y @@ -2233,7 +2233,7 @@ void QDeclarativeItem::setKeepMouseGrab(bool keep) If \a item is a \c null value, this maps the point from the coordinate system of the root QML view. */ -QScriptValue QDeclarativeItem::mapFromItem(const QScriptValue &item, int x, int y) const +QScriptValue QDeclarativeItem::mapFromItem(const QScriptValue &item, qreal x, qreal y) const { QScriptValue sv = QDeclarativeEnginePrivate::getScriptEngine(qmlEngine(this))->newObject(); QDeclarativeItem *itemObj = qobject_cast<QDeclarativeItem*>(item.toQObject()); @@ -2244,13 +2244,13 @@ QScriptValue QDeclarativeItem::mapFromItem(const QScriptValue &item, int x, int // If QGraphicsItem::mapFromItem() is called with 0, behaves the same as mapFromScene() QPointF p = qobject_cast<QGraphicsItem*>(this)->mapFromItem(itemObj, x, y); - sv.setProperty("x", p.x()); - sv.setProperty("y", p.y()); + sv.setProperty(QLatin1String("x"), p.x()); + sv.setProperty(QLatin1String("y"), p.y()); return sv; } /*! - \qmlmethod object Item::mapToItem(Item item, int x, int y) + \qmlmethod object Item::mapToItem(Item item, real x, real y) Maps the point (\a x, \a y), which is in this item's coordinate system, to \a item's coordinate system, and returns an object with \c x and \c y @@ -2259,7 +2259,7 @@ QScriptValue QDeclarativeItem::mapFromItem(const QScriptValue &item, int x, int If \a item is a \c null value, this maps \a x and \a y to the coordinate system of the root QML view. */ -QScriptValue QDeclarativeItem::mapToItem(const QScriptValue &item, int x, int y) const +QScriptValue QDeclarativeItem::mapToItem(const QScriptValue &item, qreal x, qreal y) const { QScriptValue sv = QDeclarativeEnginePrivate::getScriptEngine(qmlEngine(this))->newObject(); QDeclarativeItem *itemObj = qobject_cast<QDeclarativeItem*>(item.toQObject()); @@ -2270,23 +2270,15 @@ QScriptValue QDeclarativeItem::mapToItem(const QScriptValue &item, int x, int y) // If QGraphicsItem::mapToItem() is called with 0, behaves the same as mapToScene() QPointF p = qobject_cast<QGraphicsItem*>(this)->mapToItem(itemObj, x, y); - sv.setProperty("x", p.x()); - sv.setProperty("y", p.y()); + sv.setProperty(QLatin1String("x"), p.x()); + sv.setProperty(QLatin1String("y"), p.y()); return sv; } -/*! - \internal - - This function emits the \e focusChanged signal. - - Subclasses overriding this function should call up - to their base class. -*/ -void QDeclarativeItem::focusChanged(bool flag) +void QDeclarativeItemPrivate::focusChanged(bool flag) { - Q_UNUSED(flag); - emit focusChanged(); + Q_Q(QDeclarativeItem); + emit q->focusChanged(flag); } /*! \internal */ @@ -2579,14 +2571,16 @@ QPointF QDeclarativeItemPrivate::computeTransformOrigin() const /*! \internal */ bool QDeclarativeItem::sceneEvent(QEvent *event) { + Q_D(QDeclarativeItem); if (event->type() == QEvent::KeyPress) { QKeyEvent *k = static_cast<QKeyEvent *>(event); - if ((k->key() == Qt::Key_Tab || k->key() == Qt::Key_Backtab) && !(k->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) { keyPressEvent(static_cast<QKeyEvent *>(event)); if (!event->isAccepted()) return QGraphicsItem::sceneEvent(event); + else + return true; } else { return QGraphicsItem::sceneEvent(event); } @@ -2595,7 +2589,7 @@ bool QDeclarativeItem::sceneEvent(QEvent *event) if (event->type() == QEvent::FocusIn || event->type() == QEvent::FocusOut) { - focusChanged(hasFocus()); + d->focusChanged(hasFocus()); } return rv; } @@ -2608,7 +2602,7 @@ QVariant QDeclarativeItem::itemChange(GraphicsItemChange change, Q_D(const QDeclarativeItem); switch (change) { case ItemParentHasChanged: - emit parentChanged(); + emit parentChanged(parentItem()); break; case ItemChildAddedChange: case ItemChildRemovedChange: @@ -2721,7 +2715,7 @@ void QDeclarativeItem::setSmooth(bool smooth) if (d->smooth == smooth) return; d->smooth = smooth; - emit smoothChanged(); + emit smoothChanged(smooth); update(); } diff --git a/src/declarative/graphicsitems/qdeclarativeitem.h b/src/declarative/graphicsitems/qdeclarativeitem.h index 2053eba..c88b1db 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.h +++ b/src/declarative/graphicsitems/qdeclarativeitem.h @@ -42,8 +42,8 @@ #ifndef QDECLARATIVEITEM_H #define QDECLARATIVEITEM_H -#include <qdeclarative.h> -#include <qdeclarativecomponent.h> +#include <QtDeclarative/qdeclarative.h> +#include <QtDeclarative/qdeclarativecomponent.h> #include <QtCore/QObject> #include <QtCore/QList> @@ -59,7 +59,7 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) class QDeclarativeState; -class QDeclarativeAnchorLine; +struct QDeclarativeAnchorLine; class QDeclarativeTransition; class QDeclarativeKeyEvent; class QDeclarativeAnchors; @@ -161,8 +161,8 @@ public: bool keepMouseGrab() const; void setKeepMouseGrab(bool); - Q_INVOKABLE QScriptValue mapFromItem(const QScriptValue &item, int x, int y) const; - Q_INVOKABLE QScriptValue mapToItem(const QScriptValue &item, int x, int y) const; + Q_INVOKABLE QScriptValue mapFromItem(const QScriptValue &item, qreal x, qreal y) const; + Q_INVOKABLE QScriptValue mapToItem(const QScriptValue &item, qreal x, qreal y) const; QDeclarativeAnchorLine left() const; QDeclarativeAnchorLine right() const; @@ -173,18 +173,18 @@ public: QDeclarativeAnchorLine baseline() const; Q_SIGNALS: - void widthChanged(); - void heightChanged(); + void widthChanged(qreal); + void heightChanged(qreal); void childrenChanged(); - void childrenRectChanged(); - void baselineOffsetChanged(); + void childrenRectChanged(const QRectF &); + void baselineOffsetChanged(qreal); void stateChanged(const QString &); - void focusChanged(); - void wantsFocusChanged(); - void parentChanged(); + void focusChanged(bool); + void wantsFocusChanged(bool); + void parentChanged(QDeclarativeItem *); void transformOriginChanged(TransformOrigin); - void smoothChanged(); - void clipChanged(); + void smoothChanged(bool); + void clipChanged(bool); protected: bool isComponentComplete() const; @@ -199,7 +199,6 @@ protected: virtual void classBegin(); virtual void componentComplete(); - virtual void focusChanged(bool); virtual void keyPressEvent(QKeyEvent *event); virtual void keyReleaseEvent(QKeyEvent *event); virtual void inputMethodEvent(QInputMethodEvent *); diff --git a/src/declarative/graphicsitems/qdeclarativeitem_p.h b/src/declarative/graphicsitems/qdeclarativeitem_p.h index e424970..55df063 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem_p.h +++ b/src/declarative/graphicsitems/qdeclarativeitem_p.h @@ -91,7 +91,7 @@ public Q_SLOTS: void calcWidth(); Q_SIGNALS: - void rectChanged(); + void rectChanged(QRectF); private: QDeclarativeItem *m_item; @@ -101,7 +101,7 @@ private: qreal m_height; }; -class QDeclarativeItemPrivate : public QGraphicsItemPrivate +class Q_DECLARATIVE_EXPORT QDeclarativeItemPrivate : public QGraphicsItemPrivate { Q_DECLARE_PUBLIC(QDeclarativeItem) @@ -240,7 +240,7 @@ public: // Reimplemented from QGraphicsItemPrivate virtual void subFocusItemChange() { - emit q_func()->wantsFocusChanged(); + emit q_func()->wantsFocusChanged(subFocusItem != 0); } // Reimplemented from QGraphicsItemPrivate @@ -255,9 +255,11 @@ public: } } + virtual void focusChanged(bool); + static int consistentTime; static QTime currentTime(); - static void Q_DECLARATIVE_EXPORT setConsistentTime(int t); + static void setConsistentTime(int t); static void start(QTime &); static int elapsed(QTime &); static int restart(QTime &); diff --git a/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp b/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp index 25660f8..1a48cbd 100644 --- a/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp @@ -65,7 +65,6 @@ #include "qdeclarativelistview_p.h" #include "qdeclarativeloader_p.h" #include "qdeclarativemousearea_p.h" -#include "qdeclarativeparticles_p.h" #include "qdeclarativepath_p.h" #include "qdeclarativepathview_p.h" #include "qdeclarativerectangle_p.h" @@ -82,76 +81,72 @@ void QDeclarativeItemModule::defineModule() { - QML_REGISTER_TYPE(Qt,4,6,AnimatedImage,QDeclarativeAnimatedImage); - QML_REGISTER_TYPE(Qt,4,6,Blur,QGraphicsBlurEffect); - QML_REGISTER_TYPE(Qt,4,6,BorderImage,QDeclarativeBorderImage); - QML_REGISTER_TYPE(Qt,4,6,Colorize,QGraphicsColorizeEffect); - QML_REGISTER_TYPE(Qt,4,6,Column,QDeclarativeColumn); - QML_REGISTER_TYPE(Qt,4,6,Drag,QDeclarativeDrag); - QML_REGISTER_TYPE(Qt,4,6,DropShadow,QGraphicsDropShadowEffect); - QML_REGISTER_TYPE(Qt,4,6,Flickable,QDeclarativeFlickable); - QML_REGISTER_TYPE(Qt,4,6,Flipable,QDeclarativeFlipable); - QML_REGISTER_TYPE(Qt,4,6,Flow,QDeclarativeFlow); - QML_REGISTER_TYPE(Qt,4,6,FocusPanel,QDeclarativeFocusPanel); - QML_REGISTER_TYPE(Qt,4,6,FocusScope,QDeclarativeFocusScope); - QML_REGISTER_TYPE(Qt,4,6,Gradient,QDeclarativeGradient); - QML_REGISTER_TYPE(Qt,4,6,GradientStop,QDeclarativeGradientStop); - QML_REGISTER_TYPE(Qt,4,6,GraphicsObjectContainer,QDeclarativeGraphicsObjectContainer); - QML_REGISTER_TYPE(Qt,4,6,Grid,QDeclarativeGrid); - QML_REGISTER_TYPE(Qt,4,6,GridView,QDeclarativeGridView); - QML_REGISTER_TYPE(Qt,4,6,Image,QDeclarativeImage); - QML_REGISTER_TYPE(Qt,4,6,Item,QDeclarativeItem); - QML_REGISTER_TYPE(Qt,4,6,KeyNavigation,QDeclarativeKeyNavigationAttached); - QML_REGISTER_TYPE(Qt,4,6,Keys,QDeclarativeKeysAttached); - QML_REGISTER_TYPE(Qt,4,6,LayoutItem,QDeclarativeLayoutItem); - QML_REGISTER_TYPE(Qt,4,6,ListView,QDeclarativeListView); - QML_REGISTER_TYPE(Qt,4,6,Loader,QDeclarativeLoader); - QML_REGISTER_TYPE(Qt,4,6,MouseArea,QDeclarativeMouseArea); - QML_REGISTER_TYPE(Qt,4,6,Opacity,QGraphicsOpacityEffect); - QML_REGISTER_TYPE(Qt,4,6,ParticleMotion,QDeclarativeParticleMotion); - QML_REGISTER_TYPE(Qt,4,6,ParticleMotionGravity,QDeclarativeParticleMotionGravity); - QML_REGISTER_TYPE(Qt,4,6,ParticleMotionLinear,QDeclarativeParticleMotionLinear); - QML_REGISTER_TYPE(Qt,4,6,ParticleMotionWander,QDeclarativeParticleMotionWander); - QML_REGISTER_TYPE(Qt,4,6,Particles,QDeclarativeParticles); - QML_REGISTER_TYPE(Qt,4,6,Path,QDeclarativePath); - QML_REGISTER_TYPE(Qt,4,6,PathAttribute,QDeclarativePathAttribute); - QML_REGISTER_TYPE(Qt,4,6,PathCubic,QDeclarativePathCubic); - QML_REGISTER_TYPE(Qt,4,6,PathLine,QDeclarativePathLine); - QML_REGISTER_TYPE(Qt,4,6,PathPercent,QDeclarativePathPercent); - QML_REGISTER_TYPE(Qt,4,6,PathQuad,QDeclarativePathQuad); - QML_REGISTER_TYPE(Qt,4,6,PathView,QDeclarativePathView); - QML_REGISTER_TYPE(Qt,4,6,Pen,QDeclarativePen); - QML_REGISTER_TYPE(Qt,4,6,QIntValidator,QIntValidator); + qmlRegisterType<QDeclarativeAnimatedImage>("Qt",4,6,"AnimatedImage"); + qmlRegisterType<QGraphicsBlurEffect>("Qt",4,6,"Blur"); + qmlRegisterType<QDeclarativeBorderImage>("Qt",4,6,"BorderImage"); + qmlRegisterType<QGraphicsColorizeEffect>("Qt",4,6,"Colorize"); + qmlRegisterType<QDeclarativeColumn>("Qt",4,6,"Column"); + qmlRegisterType<QDeclarativeDrag>("Qt",4,6,"Drag"); + qmlRegisterType<QGraphicsDropShadowEffect>("Qt",4,6,"DropShadow"); + qmlRegisterType<QDeclarativeFlickable>("Qt",4,6,"Flickable"); + qmlRegisterType<QDeclarativeFlipable>("Qt",4,6,"Flipable"); + qmlRegisterType<QDeclarativeFlow>("Qt",4,6,"Flow"); + qmlRegisterType<QDeclarativeFocusPanel>("Qt",4,6,"FocusPanel"); + qmlRegisterType<QDeclarativeFocusScope>("Qt",4,6,"FocusScope"); + qmlRegisterType<QDeclarativeGradient>("Qt",4,6,"Gradient"); + qmlRegisterType<QDeclarativeGradientStop>("Qt",4,6,"GradientStop"); + qmlRegisterType<QDeclarativeGraphicsObjectContainer>("Qt",4,6,"GraphicsObjectContainer"); + qmlRegisterType<QDeclarativeGrid>("Qt",4,6,"Grid"); + qmlRegisterType<QDeclarativeGridView>("Qt",4,6,"GridView"); + qmlRegisterType<QDeclarativeImage>("Qt",4,6,"Image"); + qmlRegisterType<QDeclarativeItem>("Qt",4,6,"Item"); + qmlRegisterType<QDeclarativeKeyNavigationAttached>("Qt",4,6,"KeyNavigation"); + qmlRegisterType<QDeclarativeKeysAttached>("Qt",4,6,"Keys"); + qmlRegisterType<QDeclarativeLayoutItem>("Qt",4,6,"LayoutItem"); + qmlRegisterType<QDeclarativeListView>("Qt",4,6,"ListView"); + qmlRegisterType<QDeclarativeLoader>("Qt",4,6,"Loader"); + qmlRegisterType<QDeclarativeMouseArea>("Qt",4,6,"MouseArea"); + qmlRegisterType<QGraphicsOpacityEffect>("Qt",4,6,"Opacity"); + qmlRegisterType<QDeclarativePath>("Qt",4,6,"Path"); + qmlRegisterType<QDeclarativePathAttribute>("Qt",4,6,"PathAttribute"); + qmlRegisterType<QDeclarativePathCubic>("Qt",4,6,"PathCubic"); + qmlRegisterType<QDeclarativePathLine>("Qt",4,6,"PathLine"); + qmlRegisterType<QDeclarativePathPercent>("Qt",4,6,"PathPercent"); + qmlRegisterType<QDeclarativePathQuad>("Qt",4,6,"PathQuad"); + qmlRegisterType<QDeclarativePathView>("Qt",4,6,"PathView"); + qmlRegisterType<QDeclarativePen>("Qt",4,6,"Pen"); + qmlRegisterType<QIntValidator>("Qt",4,6,"QIntValidator"); #if (QT_VERSION >= QT_VERSION_CHECK(4,7,0)) - QML_REGISTER_TYPE(Qt,4,7,QDoubleValidator,QDoubleValidator); - QML_REGISTER_TYPE(Qt,4,7,QRegExpValidator,QRegExpValidator); + qmlRegisterType<QDoubleValidator>("Qt",4,7,"QDoubleValidator"); + qmlRegisterType<QRegExpValidator>("Qt",4,7,"QRegExpValidator"); #endif - QML_REGISTER_TYPE(Qt,4,6,Rectangle,QDeclarativeRectangle); - QML_REGISTER_TYPE(Qt,4,6,Repeater,QDeclarativeRepeater); - QML_REGISTER_TYPE(Qt,4,6,Rotation,QGraphicsRotation); - QML_REGISTER_TYPE(Qt,4,6,Row,QDeclarativeRow); - QML_REGISTER_TYPE(Qt,4,6,Scale,QGraphicsScale); - QML_REGISTER_TYPE(Qt,4,6,Text,QDeclarativeText); - QML_REGISTER_TYPE(Qt,4,6,TextEdit,QDeclarativeTextEdit); - QML_REGISTER_TYPE(Qt,4,6,TextInput,QDeclarativeTextInput); - QML_REGISTER_TYPE(Qt,4,6,ViewSection,QDeclarativeViewSection); - QML_REGISTER_TYPE(Qt,4,6,VisibleArea,QDeclarativeFlickableVisibleArea); - QML_REGISTER_TYPE(Qt,4,6,VisualDataModel,QDeclarativeVisualDataModel); - QML_REGISTER_TYPE(Qt,4,6,VisualItemModel,QDeclarativeVisualItemModel); + qmlRegisterType<QDeclarativeRectangle>("Qt",4,6,"Rectangle"); + qmlRegisterType<QDeclarativeRepeater>("Qt",4,6,"Repeater"); + qmlRegisterType<QGraphicsRotation>("Qt",4,6,"Rotation"); + qmlRegisterType<QDeclarativeRow>("Qt",4,6,"Row"); + qmlRegisterType<QGraphicsScale>("Qt",4,6,"Scale"); + qmlRegisterType<QDeclarativeText>("Qt",4,6,"Text"); + qmlRegisterType<QDeclarativeTextEdit>("Qt",4,6,"TextEdit"); + qmlRegisterType<QDeclarativeTextInput>("Qt",4,6,"TextInput"); + qmlRegisterType<QDeclarativeViewSection>("Qt",4,6,"ViewSection"); + qmlRegisterType<QDeclarativeFlickableVisibleArea>("Qt",4,6,"VisibleArea"); + qmlRegisterType<QDeclarativeVisualDataModel>("Qt",4,6,"VisualDataModel"); + qmlRegisterType<QDeclarativeVisualItemModel>("Qt",4,6,"VisualItemModel"); - QML_REGISTER_NOCREATE_TYPE(QDeclarativeAnchors); - QML_REGISTER_NOCREATE_TYPE(QGraphicsEffect); - QML_REGISTER_NOCREATE_TYPE(QDeclarativeKeyEvent); - QML_REGISTER_NOCREATE_TYPE(QDeclarativeMouseEvent); - QML_REGISTER_NOCREATE_TYPE(QGraphicsObject); - QML_REGISTER_NOCREATE_TYPE(QGraphicsTransform); - QML_REGISTER_NOCREATE_TYPE(QDeclarativePathElement); - QML_REGISTER_NOCREATE_TYPE(QDeclarativeCurve); - QML_REGISTER_NOCREATE_TYPE(QDeclarativeScaleGrid); - QML_REGISTER_NOCREATE_TYPE(QValidator); - QML_REGISTER_NOCREATE_TYPE(QDeclarativeVisualModel); - QML_REGISTER_NOCREATE_TYPE(QAction); + qmlRegisterType<QDeclarativeAnchors>(); + qmlRegisterType<QGraphicsEffect>(); + qmlRegisterType<QDeclarativeKeyEvent>(); + qmlRegisterType<QDeclarativeMouseEvent>(); + qmlRegisterType<QGraphicsObject>(); + qmlRegisterType<QGraphicsWidget>(); + qmlRegisterType<QGraphicsTransform>(); + qmlRegisterType<QDeclarativePathElement>(); + qmlRegisterType<QDeclarativeCurve>(); + qmlRegisterType<QDeclarativeScaleGrid>(); + qmlRegisterType<QValidator>(); + qmlRegisterType<QDeclarativeVisualModel>(); + qmlRegisterType<QAction>(); #ifdef QT_WEBKIT_LIB - QML_REGISTER_NOCREATE_TYPE(QDeclarativeWebSettings); + qmlRegisterType<QDeclarativeWebSettings>(); #endif } diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index d54bb70..84281c8 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -129,6 +129,10 @@ public: item->setX(pos); } } + bool contains(int x, int y) const { + return (x >= item->x() && x < item->x() + item->width() && + y >= item->y() && y < item->y() + item->height()); + } QDeclarativeItem *item; QDeclarativeItem *section; @@ -158,7 +162,7 @@ public: , bufferMode(NoBuffer) , ownModel(false), wrap(false), autoHighlight(true), haveHighlightRange(false) , correctFlick(true), inFlickCorrection(false), lazyRelease(false) - , deferredRelease(false), minExtentDirty(true), maxExtentDirty(true) + , deferredRelease(false), layoutScheduled(false), minExtentDirty(true), maxExtentDirty(true) {} void init(); @@ -393,9 +397,8 @@ public: QDeclarativeFlickablePrivate::itemGeometryChanged(item, newGeometry, oldGeometry); if (item != viewport) { if ((orient == QDeclarativeListView::Vertical && newGeometry.height() != oldGeometry.height()) - || newGeometry.width() != oldGeometry.width()) { - layout(); - fixupPosition(); + || (orient == QDeclarativeListView::Horizontal && newGeometry.width() != oldGeometry.width())) { + scheduleLayout(); } } } @@ -414,6 +417,7 @@ public: } void refill(qreal from, qreal to, bool doBuffer = false); + void scheduleLayout(); void layout(); void updateUnrequestedIndexes(); void updateUnrequestedPositions(); @@ -480,6 +484,7 @@ public: bool inFlickCorrection : 1; bool lazyRelease : 1; bool deferredRelease : 1; + bool layoutScheduled : 1; mutable bool minExtentDirty : 1; mutable bool maxExtentDirty : 1; }; @@ -557,7 +562,7 @@ void QDeclarativeListViewPrivate::releaseItem(FxListItem *item) return; if (trackedItem == item) { const char *notifier1 = orient == QDeclarativeListView::Vertical ? SIGNAL(yChanged()) : SIGNAL(xChanged()); - const char *notifier2 = orient == QDeclarativeListView::Vertical ? SIGNAL(heightChanged()) : SIGNAL(widthChanged()); + const char *notifier2 = orient == QDeclarativeListView::Vertical ? SIGNAL(heightChanged(qreal)) : SIGNAL(widthChanged(qreal)); QObject::disconnect(trackedItem->item, notifier1, q, SLOT(trackedPositionChanged())); QObject::disconnect(trackedItem->item, notifier2, q, SLOT(trackedPositionChanged())); trackedItem = 0; @@ -680,9 +685,19 @@ void QDeclarativeListViewPrivate::refill(qreal from, qreal to, bool doBuffer) lazyRelease = false; } +void QDeclarativeListViewPrivate::scheduleLayout() +{ + Q_Q(QDeclarativeListView); + if (!layoutScheduled) { + layoutScheduled = true; + QCoreApplication::postEvent(q, new QEvent(QEvent::User), Qt::HighEventPriority); + } +} + void QDeclarativeListViewPrivate::layout() { Q_Q(QDeclarativeListView); + layoutScheduled = false; updateSections(); if (!visibleItems.isEmpty()) { int oldEnd = visibleItems.last()->endPosition(); @@ -748,7 +763,7 @@ void QDeclarativeListViewPrivate::updateTrackedItem() FxListItem *oldTracked = trackedItem; const char *notifier1 = orient == QDeclarativeListView::Vertical ? SIGNAL(yChanged()) : SIGNAL(xChanged()); - const char *notifier2 = orient == QDeclarativeListView::Vertical ? SIGNAL(heightChanged()) : SIGNAL(widthChanged()); + const char *notifier2 = orient == QDeclarativeListView::Vertical ? SIGNAL(heightChanged(qreal)) : SIGNAL(widthChanged(qreal)); if (trackedItem && item != trackedItem) { QObject::disconnect(trackedItem->item, notifier1, q, SLOT(trackedPositionChanged())); @@ -1082,10 +1097,12 @@ void QDeclarativeListViewPrivate::fixup(AxisData &data, qreal minExtent, qreal m if (currentItem && currentItem->position() - position() != highlightRangeStart) { qreal pos = currentItem->position() - highlightRangeStart; timeline.reset(data.move); - if (fixupDuration) + if (fixupDuration) { timeline.move(data.move, -pos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration/2); - else + } else { data.move.setValue(-pos); + q->viewportMoved(); + } vTime = timeline.time(); } } else if (snapMode != QDeclarativeListView::NoSnap) { @@ -1094,10 +1111,12 @@ void QDeclarativeListViewPrivate::fixup(AxisData &data, qreal minExtent, qreal m qreal dist = qAbs(data.move + pos); if (dist > 0) { timeline.reset(data.move); - if (fixupDuration) + if (fixupDuration) { timeline.move(data.move, -pos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration/2); - else + } else { data.move.setValue(-pos); + q->viewportMoved(); + } vTime = timeline.time(); } } @@ -1124,7 +1143,7 @@ void QDeclarativeListViewPrivate::flick(AxisData &data, qreal minExtent, qreal m if (FxListItem *item = firstVisibleItem()) maxDistance = qAbs(item->position() + data.move.value()); } else if (data.move.value() < minExtent) { - maxDistance = qAbs(minExtent - data.move.value() + (overShoot?overShootDistance(velocity, vSize):0)); + maxDistance = qAbs(minExtent - data.move.value()); } if (snapMode != QDeclarativeListView::SnapToItem && highlightRange != QDeclarativeListView::StrictlyEnforceRange) data.flickTarget = minExtent; @@ -1133,7 +1152,7 @@ void QDeclarativeListViewPrivate::flick(AxisData &data, qreal minExtent, qreal m if (FxListItem *item = nextVisibleItem()) maxDistance = qAbs(item->position() + data.move.value()); } else if (data.move.value() > maxExtent) { - maxDistance = qAbs(maxExtent - data.move.value()) + (overShoot?overShootDistance(velocity, vSize):0); + maxDistance = qAbs(maxExtent - data.move.value()); } if (snapMode != QDeclarativeListView::SnapToItem && highlightRange != QDeclarativeListView::StrictlyEnforceRange) data.flickTarget = maxExtent; @@ -1156,7 +1175,8 @@ void QDeclarativeListViewPrivate::flick(AxisData &data, qreal minExtent, qreal m qreal v2 = v * v; qreal maxAccel = v2 / (2.0f * maxDistance); if (maxAccel < accel) { - qreal dist = v2 / (accel * 2.0); + // + averageSize/4 to encourage moving at least one item in the flick direction + qreal dist = v2 / (accel * 2.0) + averageSize/4; if (v > 0) dist = -dist; data.flickTarget = -snapPosAt(-(data.move.value() - highlightRangeStart) + dist) + highlightRangeStart; @@ -1944,6 +1964,17 @@ void QDeclarativeListView::setHeader(QDeclarativeComponent *header) } } +bool QDeclarativeListView::event(QEvent *event) +{ + Q_D(QDeclarativeListView); + if (event->type() == QEvent::User) { + d->layout(); + return true; + } + + return QDeclarativeFlickable::event(event); +} + void QDeclarativeListView::viewportMoved() { Q_D(QDeclarativeListView); @@ -1956,10 +1987,11 @@ void QDeclarativeListView::viewportMoved() if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange && d->highlight) { // reposition highlight qreal pos = d->highlight->position(); - if (pos > d->position() + d->highlightRangeEnd - 1 - d->highlight->size()) - pos = d->position() + d->highlightRangeEnd - 1 - d->highlight->size(); - if (pos < d->position() + d->highlightRangeStart) - pos = d->position() + d->highlightRangeStart; + qreal viewPos = qRound(d->position()); + if (pos > viewPos + d->highlightRangeEnd - 1 - d->highlight->size()) + pos = viewPos + d->highlightRangeEnd - 1 - d->highlight->size(); + if (pos < viewPos + d->highlightRangeStart) + pos = viewPos + d->highlightRangeStart; d->highlight->setPosition(pos); // update current index @@ -2032,7 +2064,7 @@ qreal QDeclarativeListView::maxYExtent() const return height(); if (d->maxExtentDirty) { if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) - d->maxExtent = -(d->positionAt(count()-1) - d->highlightRangeEnd); + d->maxExtent = -(d->endPosition() - d->highlightRangeEnd); else d->maxExtent = -(d->endPosition() - height() + 1); if (d->footer) @@ -2069,7 +2101,7 @@ qreal QDeclarativeListView::maxXExtent() const return width(); if (d->maxExtentDirty) { if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) - d->maxExtent = -(d->positionAt(count()-1) - d->highlightRangeEnd); + d->maxExtent = -(d->endPosition() - d->highlightRangeEnd); else d->maxExtent = -(d->endPosition() - width() + 1); if (d->footer) @@ -2151,11 +2183,23 @@ void QDeclarativeListView::decrementCurrentIndex() } /*! - \qmlmethod ListView::positionViewAtIndex(int index) + \qmlmethod ListView::positionViewAtIndex(int index, PositionMode mode) + + Positions the view such that the \a index is at the position specified by + \a mode: + + \list + \o Beginning - position item at the top (or left for horizontal orientation) of the view. + \o Center- position item in the center of the view. + \o End - position item at bottom (or right for horizontal orientation) of the view. + \o Visible - if any part of the item is visible then take no action, otherwise + bring the item into view. + \o Contain - ensure the entire item is visible. If the item is larger than + the view the item is positioned at the top (or left for horizontal orientation) of the view. + \endlist - Positions the view such that the \a index is at the top (or left for horizontal orientation) of the view. If positioning the view at the index would cause empty space to be displayed at - the end of the view, the view will be positioned at the end. + the beginning or end of the view, the view will be positioned at the boundary. It is not recommended to use contentX or contentY to position the view at a particular index. This is unreliable since removing items from the start @@ -2163,36 +2207,83 @@ void QDeclarativeListView::decrementCurrentIndex() 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 positionViewAtIndex. */ -void QDeclarativeListView::positionViewAtIndex(int index) +void QDeclarativeListView::positionViewAtIndex(int index, int mode) { Q_D(QDeclarativeListView); if (!d->isValid() || index < 0 || index >= d->model->count()) return; + if (mode < Beginning || mode > Contain) + return; - qreal maxExtent = d->orient == QDeclarativeListView::Vertical ? -maxYExtent() : -maxXExtent(); + qreal pos = d->position(); FxListItem *item = d->visibleItem(index); - if (item) { - // Already created - just move to top of view - int pos = qMin(item->position(), maxExtent); - d->setPosition(pos); - } else { - int pos = d->positionAt(index); + if (!item) { + int itemPos = d->positionAt(index); // save the currently visible items in case any of them end up visible again QList<FxListItem*> oldVisible = d->visibleItems; d->visibleItems.clear(); - d->visiblePos = pos; + d->visiblePos = itemPos; d->visibleIndex = index; - d->setPosition(pos); - // setPosition() will cause refill. Adjust if we have moved beyond range. - if (d->position() > maxExtent) - d->setPosition(maxExtent); + d->setPosition(itemPos); // now release the reference to all the old visible items. for (int i = 0; i < oldVisible.count(); ++i) d->releaseItem(oldVisible.at(i)); + item = d->visibleItem(index); + } + if (item) { + const qreal itemPos = item->position(); + switch (mode) { + case Beginning: + pos = itemPos; + break; + case Center: + pos = itemPos - (d->size() - item->size())/2; + break; + case End: + pos = itemPos - d->size() + item->size(); + break; + case Visible: + if (itemPos > pos + d->size()) + pos = itemPos - d->size() + item->size(); + else if (item->endPosition() < pos) + pos = itemPos; + break; + case Contain: + if (item->endPosition() > pos + d->size()) + pos = itemPos - d->size() + item->size(); + if (itemPos < pos) + pos = itemPos; + } + qreal maxExtent = d->orient == QDeclarativeListView::Vertical ? -maxYExtent() : -maxXExtent(); + pos = qMin(pos, maxExtent); + qreal minExtent = d->orient == QDeclarativeListView::Vertical ? -minYExtent() : -minXExtent(); + pos = qMax(pos, minExtent); + d->setPosition(pos); } d->fixupPosition(); } +/*! + \qmlmethod int ListView::indexAt(int x, int y) + + Returns the index of the visible item containing the point \a x, \a y in content + coordinates. If there is no item at the point specified, or the item is + not visible -1 is returned. + + 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. +*/ +int QDeclarativeListView::indexAt(int x, int y) const +{ + Q_D(const QDeclarativeListView); + for (int i = 0; i < d->visibleItems.count(); ++i) { + const FxListItem *listItem = d->visibleItems.at(i); + if(listItem->contains(x, y)) + return listItem->index; + } + + return -1; +} void QDeclarativeListView::componentComplete() { @@ -2273,7 +2364,7 @@ void QDeclarativeListView::itemsInserted(int modelIndex, int count) d->updateUnrequestedIndexes(); d->moveReason = QDeclarativeListViewPrivate::Other; if (!d->visibleItems.count() || d->model->count() <= 1) { - d->layout(); + d->scheduleLayout(); d->updateCurrent(qMax(0, qMin(d->currentIndex, d->model->count()-1))); emit countChanged(); return; @@ -2303,8 +2394,9 @@ void QDeclarativeListView::itemsInserted(int modelIndex, int count) d->currentIndex += count; if (d->currentItem) d->currentItem->index = d->currentIndex; + emit currentIndexChanged(); } - d->layout(); + d->scheduleLayout(); emit countChanged(); return; } @@ -2327,7 +2419,10 @@ void QDeclarativeListView::itemsInserted(int modelIndex, int count) int i = 0; int from = d->position() - d->buffer; for (i = count-1; i >= 0 && pos > from; --i) { - addedVisible = true; + if (!addedVisible) { + d->scheduleLayout(); + addedVisible = true; + } FxListItem *item = d->createItem(modelIndex + i); d->visibleItems.insert(insertionIdx, item); pos -= item->size() + d->spacing; @@ -2354,7 +2449,10 @@ void QDeclarativeListView::itemsInserted(int modelIndex, int count) int i = 0; int to = d->buffer+d->position()+d->size()-1; for (i = 0; i < count && pos <= to; ++i) { - addedVisible = true; + if (!addedVisible) { + d->scheduleLayout(); + addedVisible = true; + } FxListItem *item = d->createItem(modelIndex + i); d->visibleItems.insert(index, item); item->setPosition(pos); @@ -2377,6 +2475,7 @@ void QDeclarativeListView::itemsInserted(int modelIndex, int count) d->currentItem->index = d->currentIndex; d->currentItem->setPosition(d->currentItem->position() + diff); } + emit currentIndexChanged(); } // Update the indexes of the following visible items. for (; index < d->visibleItems.count(); ++index) { @@ -2390,8 +2489,6 @@ void QDeclarativeListView::itemsInserted(int modelIndex, int count) for (int j = 0; j < added.count(); ++j) added.at(j)->attached->emitAdd(); - if (addedVisible) - d->layout(); emit countChanged(); } @@ -2417,7 +2514,10 @@ void QDeclarativeListView::itemsRemoved(int modelIndex, int count) ++it; } else { // removed item - removedVisible = true; + if (!removedVisible) { + d->scheduleLayout(); + removedVisible = true; + } item->attached->emitRemove(); if (item->attached->delayRemove()) { item->index = -1; @@ -2442,6 +2542,7 @@ void QDeclarativeListView::itemsRemoved(int modelIndex, int count) d->currentIndex -= count; if (d->currentItem) d->currentItem->index -= count; + emit currentIndexChanged(); } else if (d->currentIndex >= modelIndex && d->currentIndex < modelIndex + count) { // current item has been removed. d->currentItem->attached->setIsCurrentItem(false); @@ -2459,20 +2560,13 @@ void QDeclarativeListView::itemsRemoved(int modelIndex, int count) } } - if (removedVisible) { - if (d->visibleItems.isEmpty()) { - d->visibleIndex = 0; - d->visiblePos = d->header ? d->header->size() : 0; - d->timeline.clear(); - d->setPosition(0); - if (d->model->count() == 0) - update(); - else - refill(); - } else { - // Correct the positioning of the items - d->layout(); - } + if (removedVisible && d->visibleItems.isEmpty()) { + d->visibleIndex = 0; + d->visiblePos = d->header ? d->header->size() : 0; + d->timeline.clear(); + d->setPosition(0); + if (d->model->count() == 0) + update(); } emit countChanged(); diff --git a/src/declarative/graphicsitems/qdeclarativelistview_p.h b/src/declarative/graphicsitems/qdeclarativelistview_p.h index d66ac2b..3635b39 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview_p.h +++ b/src/declarative/graphicsitems/qdeclarativelistview_p.h @@ -191,10 +191,15 @@ public: static QDeclarativeListViewAttached *qmlAttachedProperties(QObject *); + enum PositionMode { Beginning, Center, End, Visible, Contain }; + Q_ENUMS(PositionMode); + + Q_INVOKABLE void positionViewAtIndex(int index, int mode); + Q_INVOKABLE int indexAt(int x, int y) const; + public Q_SLOTS: void incrementCurrentIndex(); void decrementCurrentIndex(); - void positionViewAtIndex(int index); Q_SIGNALS: void countChanged(); @@ -219,6 +224,7 @@ Q_SIGNALS: void footerChanged(); protected: + virtual bool event(QEvent *event); virtual void viewportMoved(); virtual qreal minYExtent() const; virtual qreal maxYExtent() const; diff --git a/src/declarative/graphicsitems/qdeclarativeloader.cpp b/src/declarative/graphicsitems/qdeclarativeloader.cpp index b0499d7..6dbcd16 100644 --- a/src/declarative/graphicsitems/qdeclarativeloader.cpp +++ b/src/declarative/graphicsitems/qdeclarativeloader.cpp @@ -155,6 +155,8 @@ void QDeclarativeLoaderPrivate::initResize() QDeclarativeLoader::QDeclarativeLoader(QDeclarativeItem *parent) : QDeclarativeItem(*(new QDeclarativeLoaderPrivate), parent) { + Q_D(QDeclarativeItem); + d->flags |= QGraphicsItem::ItemIsFocusScope; } /*! @@ -273,7 +275,7 @@ void QDeclarativeLoaderPrivate::_q_sourceLoaded() if (component) { QDeclarativeContext *ctxt = new QDeclarativeContext(qmlContext(q)); - ctxt->addDefaultObject(q); + ctxt->setContextObject(q); if (!component->errors().isEmpty()) { qWarning() << component->errors(); @@ -346,12 +348,13 @@ QDeclarativeLoader::Status QDeclarativeLoader::status() const } /*! - \qmlproperty real Loader::progress +\qmlproperty real Loader::progress - This property holds the progress of QML data loading, from 0.0 (nothing loaded) - to 1.0 (finished). +This property holds the progress of loading QML data from the network, from +0.0 (nothing loaded) to 1.0 (finished). Most QML files are quite small, so +this value will rapidly change from 0 to 1. - \sa status +\sa status */ qreal QDeclarativeLoader::progress() const { diff --git a/src/declarative/graphicsitems/qdeclarativemousearea.cpp b/src/declarative/graphicsitems/qdeclarativemousearea.cpp index ec7aa62..26242bc 100644 --- a/src/declarative/graphicsitems/qdeclarativemousearea.cpp +++ b/src/declarative/graphicsitems/qdeclarativemousearea.cpp @@ -58,12 +58,12 @@ QDeclarativeDrag::~QDeclarativeDrag() { } -QDeclarativeItem *QDeclarativeDrag::target() const +QGraphicsObject *QDeclarativeDrag::target() const { return _target; } -void QDeclarativeDrag::setTarget(QDeclarativeItem *t) +void QDeclarativeDrag::setTarget(QGraphicsObject *t) { if (_target == t) return; @@ -383,7 +383,6 @@ void QDeclarativeMouseArea::mousePressEvent(QGraphicsSceneMouseEvent *event) } d->dragged = false; setHovered(true); - d->start = event->pos(); d->startScene = event->scenePos(); // we should only start timer if pressAndHold is connected to. if (d->isConnected("pressAndHold(QDeclarativeMouseEvent*)")) diff --git a/src/declarative/graphicsitems/qdeclarativemousearea_p.h b/src/declarative/graphicsitems/qdeclarativemousearea_p.h index 33422e2..db49b57 100644 --- a/src/declarative/graphicsitems/qdeclarativemousearea_p.h +++ b/src/declarative/graphicsitems/qdeclarativemousearea_p.h @@ -55,7 +55,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativeDrag : public QObject Q_OBJECT Q_ENUMS(Axis) - Q_PROPERTY(QDeclarativeItem *target READ target WRITE setTarget NOTIFY targetChanged) + Q_PROPERTY(QGraphicsObject *target READ target WRITE setTarget NOTIFY targetChanged) Q_PROPERTY(Axis axis READ axis WRITE setAxis NOTIFY axisChanged) Q_PROPERTY(qreal minimumX READ xmin WRITE setXmin NOTIFY minimumXChanged) Q_PROPERTY(qreal maximumX READ xmax WRITE setXmax NOTIFY maximumXChanged) @@ -67,8 +67,8 @@ public: QDeclarativeDrag(QObject *parent=0); ~QDeclarativeDrag(); - QDeclarativeItem *target() const; - void setTarget(QDeclarativeItem *); + QGraphicsObject *target() const; + void setTarget(QGraphicsObject *); enum Axis { XAxis=0x01, YAxis=0x02, XandYAxis=0x03 }; Axis axis() const; @@ -92,7 +92,7 @@ Q_SIGNALS: void maximumYChanged(); private: - QDeclarativeItem *_target; + QGraphicsObject *_target; Axis _axis; qreal _xmin; qreal _xmax; diff --git a/src/declarative/graphicsitems/qdeclarativemousearea_p_p.h b/src/declarative/graphicsitems/qdeclarativemousearea_p_p.h index d4871f2..88206cd 100644 --- a/src/declarative/graphicsitems/qdeclarativemousearea_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativemousearea_p_p.h @@ -101,7 +101,6 @@ public: bool dragY : 1; bool dragged : 1; QDeclarativeDrag *drag; - QPointF start; QPointF startScene; qreal startX; qreal startY; diff --git a/src/declarative/graphicsitems/qdeclarativepainteditem.cpp b/src/declarative/graphicsitems/qdeclarativepainteditem.cpp index ab6007a..28a93d2 100644 --- a/src/declarative/graphicsitems/qdeclarativepainteditem.cpp +++ b/src/declarative/graphicsitems/qdeclarativepainteditem.cpp @@ -211,8 +211,8 @@ QDeclarativePaintedItem::~QDeclarativePaintedItem() */ void QDeclarativePaintedItem::init() { - connect(this,SIGNAL(widthChanged()),this,SLOT(clearCache())); - connect(this,SIGNAL(heightChanged()),this,SLOT(clearCache())); + connect(this,SIGNAL(widthChanged(qreal)),this,SLOT(clearCache())); + connect(this,SIGNAL(heightChanged(qreal)),this,SLOT(clearCache())); connect(this,SIGNAL(visibleChanged()),this,SLOT(clearCache())); } diff --git a/src/declarative/graphicsitems/qdeclarativeparticles.cpp b/src/declarative/graphicsitems/qdeclarativeparticles.cpp deleted file mode 100644 index 593c80a..0000000 --- a/src/declarative/graphicsitems/qdeclarativeparticles.cpp +++ /dev/null @@ -1,1317 +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 "qdeclarativeparticles_p.h" - -#include "qdeclarativeitem_p.h" - -#include <qdeclarativepixmapcache_p.h> -#include <qfxperf_p_p.h> -#include <qdeclarativeanimation_p_p.h> - -#include <QNetworkReply> -#include <QPainter> -#include <QtGui/qdrawutil.h> -#include <QVarLengthArray> - -#include <stdlib.h> -#include <math.h> - -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#define M_PI_2 (M_PI / 2.) -#endif -#ifndef INT_MAX -#define INT_MAX 2147483647 -#endif - -QT_BEGIN_NAMESPACE -#define PI_SQR 9.8696044 -// parabolic approximation -inline qreal fastSin(qreal theta) -{ - const qreal b = 4 / M_PI; - const qreal c = -4 / PI_SQR; - - qreal y = b * theta + c * theta * qAbs(theta); - return y; -} - -inline qreal fastCos(qreal theta) -{ - theta += M_PI_2; - if (theta > M_PI) - theta -= 2 * M_PI; - - return fastSin(theta); -} - -class QDeclarativeParticle -{ -public: - QDeclarativeParticle(int time) : lifeSpan(1000), fadeOutAge(800) - , opacity(0), birthTime(time), x_velocity(0), y_velocity(0) - , state(FadeIn), data(0) - { - } - - int lifeSpan; - int fadeOutAge; - qreal x; - qreal y; - qreal opacity; - int birthTime; - qreal x_velocity; - qreal y_velocity; - enum State { FadeIn, Solid, FadeOut }; - State state; - void *data; -}; - -//--------------------------------------------------------------------------- - -/*! - \class QDeclarativeParticleMotion - \ingroup group_effects - \brief The QDeclarativeParticleMotion class is the base class for particle motion. - \internal - - This class causes the particles to remain static. -*/ - -/*! - Constructs a QDeclarativeParticleMotion with parent object \a parent. -*/ -QDeclarativeParticleMotion::QDeclarativeParticleMotion(QObject *parent) : - QObject(parent) -{ -} - -/*! - Move the \a particle to its new position. \a interval is the number of - milliseconds elapsed since it was last moved. -*/ -void QDeclarativeParticleMotion::advance(QDeclarativeParticle &particle, int interval) -{ - Q_UNUSED(particle); - Q_UNUSED(interval); -} - -/*! - The \a particle has just been created. Some motion strategies require - additional state information. This can be allocated by this function. -*/ -void QDeclarativeParticleMotion::created(QDeclarativeParticle &particle) -{ - Q_UNUSED(particle); -} - -/*! - The \a particle is about to be destroyed. Any additional memory - that has been allocated for the particle should be freed. -*/ -void QDeclarativeParticleMotion::destroy(QDeclarativeParticle &particle) -{ - Q_UNUSED(particle); -} - -/*! - \qmlclass ParticleMotionLinear - \since 4.7 - \brief The ParticleMotionLinear object moves particles linearly. - - \sa Particles -*/ - -/*! - \internal - \class QDeclarativeParticleMotionLinear - \ingroup group_effects - \brief The QDeclarativeParticleMotionLinear class moves the particles linearly. -*/ - -void QDeclarativeParticleMotionLinear::advance(QDeclarativeParticle &p, int interval) -{ - p.x += interval * p.x_velocity; - p.y += interval * p.y_velocity; -} - -/*! - \qmlclass ParticleMotionGravity - \since 4.7 - \brief The ParticleMotionGravity object moves particles towards a point. - - \sa Particles -*/ - -/*! - \internal - \class QDeclarativeParticleMotionGravity - \ingroup group_effects - \brief The QDeclarativeParticleMotionGravity class moves the particles towards a point. -*/ - -/*! - \qmlproperty qreal ParticleMotionGravity::xattractor - \qmlproperty qreal ParticleMotionGravity::yattractor - These properties hold the x and y coordinates of the point attracting the particles. -*/ - -/*! - \qmlproperty qreal ParticleMotionGravity::acceleration - This property holds the acceleration to apply to the particles. -*/ - -/*! - \property QDeclarativeParticleMotionGravity::xattractor - \brief the x coordinate of the point attracting the particles. -*/ - -/*! - \property QDeclarativeParticleMotionGravity::yattractor - \brief the y coordinate of the point attracting the particles. -*/ - -/*! - \property QDeclarativeParticleMotionGravity::acceleration - \brief the acceleration to apply to the particles. -*/ - -void QDeclarativeParticleMotionGravity::setXAttractor(qreal x) -{ - if (qFuzzyCompare(x, _xAttr)) - return; - _xAttr = x; - emit xattractorChanged(); -} - -void QDeclarativeParticleMotionGravity::setYAttractor(qreal y) -{ - if (qFuzzyCompare(y, _yAttr)) - return; - _yAttr = y; - emit yattractorChanged(); -} - -void QDeclarativeParticleMotionGravity::setAcceleration(qreal accel) -{ - qreal scaledAccel = accel/1000000.0; - if (qFuzzyCompare(scaledAccel, _accel)) - return; - _accel = scaledAccel; - emit accelerationChanged(); -} - -void QDeclarativeParticleMotionGravity::advance(QDeclarativeParticle &p, int interval) -{ - qreal xdiff = p.x - _xAttr; - qreal ydiff = p.y - _yAttr; - - qreal xcomp = xdiff / (xdiff + ydiff); - qreal ycomp = ydiff / (xdiff + ydiff); - - p.x_velocity += xcomp * _accel * interval; - p.y_velocity += ycomp * _accel * interval; - - p.x += interval * p.x_velocity; - p.y += interval * p.y_velocity; -} - -/*! - \qmlclass ParticleMotionWander - \since 4.7 - \brief The ParticleMotionWander object moves particles in a somewhat random fashion. - - The particles will continue roughly in the original direction, however will randomly - drift to each side. - - The code below produces an effect similar to falling snow. - - \qml -Rectangle { - width: 240 - height: 320 - color: "black" - - Particles { - y: 0 - width: parent.width - height: 30 - source: "star.png" - lifeSpan: 5000 - count: 50 - angle: 70 - angleDeviation: 36 - velocity: 30 - velocityDeviation: 10 - ParticleMotionWander { - xvariance: 30 - pace: 100 - } - } -} - \endqml - - \sa Particles -*/ - -/*! - \internal - \class QDeclarativeParticleMotionWander - \ingroup group_effects - \brief The QDeclarativeParticleMotionWander class moves particles in a somewhat random fashion. - - The particles will continue roughly in the original direction, however will randomly - drift to each side. -*/ - -/*! - \qmlproperty qreal QDeclarativeParticleMotionWander::xvariance - \qmlproperty qreal QDeclarativeParticleMotionWander::yvariance - - These properties set the amount to wander in the x and y directions. -*/ - -/*! - \qmlproperty qreal QDeclarativeParticleMotionWander::pace - This property holds how quickly the paricles will move from side to side. -*/ - -void QDeclarativeParticleMotionWander::advance(QDeclarativeParticle &p, int interval) -{ - if (!particles) - particles = qobject_cast<QDeclarativeParticles*>(parent()); - if (particles) { - Data *d = (Data*)p.data; - if (_xvariance != 0.) { - qreal xdiff = p.x_velocity - d->x_targetV; - if ((xdiff > d->x_peak && d->x_var > 0.0) || (xdiff < -d->x_peak && d->x_var < 0.0)) { - d->x_var = -d->x_var; - d->x_peak = _xvariance + _xvariance * qreal(qrand()) / RAND_MAX; - } - p.x_velocity += d->x_var * interval; - } - p.x += interval * p.x_velocity; - - if (_yvariance != 0.) { - qreal ydiff = p.y_velocity - d->y_targetV; - if ((ydiff > d->y_peak && d->y_var > 0.0) || (ydiff < -d->y_peak && d->y_var < 0.0)) { - d->y_var = -d->y_var; - d->y_peak = _yvariance + _yvariance * qreal(qrand()) / RAND_MAX; - } - p.y_velocity += d->y_var * interval; - } - p.y += interval * p.y_velocity; - } -} - -void QDeclarativeParticleMotionWander::created(QDeclarativeParticle &p) -{ - if (!p.data) { - Data *d = new Data; - p.data = (void*)d; - d->x_targetV = p.x_velocity; - d->y_targetV = p.y_velocity; - d->x_peak = _xvariance; - d->y_peak = _yvariance; - d->x_var = _pace * qreal(qrand()) / RAND_MAX / 1000.0; - d->y_var = _pace * qreal(qrand()) / RAND_MAX / 1000.0; - } -} - -void QDeclarativeParticleMotionWander::destroy(QDeclarativeParticle &p) -{ - if (p.data) - delete (Data*)p.data; -} - -void QDeclarativeParticleMotionWander::setXVariance(qreal var) -{ - qreal scaledVar = var / 1000.0; - if (qFuzzyCompare(scaledVar, _xvariance)) - return; - _xvariance = scaledVar; - emit xvarianceChanged(); -} - -void QDeclarativeParticleMotionWander::setYVariance(qreal var) -{ - qreal scaledVar = var / 1000.0; - if (qFuzzyCompare(scaledVar, _yvariance)) - return; - _yvariance = scaledVar; - emit yvarianceChanged(); -} - -void QDeclarativeParticleMotionWander::setPace(qreal pace) -{ - qreal scaledPace = pace / 1000.0; - if (qFuzzyCompare(scaledPace, _pace)) - return; - _pace = scaledPace; - emit paceChanged(); -} - -//--------------------------------------------------------------------------- -class QDeclarativeParticlesPainter : public QDeclarativeItem -{ -public: - QDeclarativeParticlesPainter(QDeclarativeParticlesPrivate *p, QDeclarativeItem* parent) - : QDeclarativeItem(parent), d(p) - { - setFlag(QGraphicsItem::ItemHasNoContents, false); - maxX = minX = maxY = minY = 0; - } - - void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); - - void updateSize(); - - qreal maxX; - qreal minX; - qreal maxY; - qreal minY; - QDeclarativeParticlesPrivate* d; -}; - -//--------------------------------------------------------------------------- -class QDeclarativeParticlesPrivate : public QDeclarativeItemPrivate -{ - Q_DECLARE_PUBLIC(QDeclarativeParticles) -public: - QDeclarativeParticlesPrivate() - : count(1), emissionRate(-1), emissionVariance(0.5), lifeSpan(1000) - , lifeSpanDev(1000), fadeInDur(200), fadeOutDur(300) - , angle(0), angleDev(0), velocity(0), velocityDev(0), emissionCarry(0.) - , addParticleTime(0), addParticleCount(0), lastAdvTime(0) - , motion(0), pendingPixmapCache(false), clock(this) - { - } - - ~QDeclarativeParticlesPrivate() - { - } - - void init() - { - Q_Q(QDeclarativeParticles); - paintItem = new QDeclarativeParticlesPainter(this, q); - } - - void tick(int time); - void createParticle(int time); - void updateOpacity(QDeclarativeParticle &p, int age); - - QUrl url; - QPixmap image; - int count; - int emissionRate; - qreal emissionVariance; - int lifeSpan; - int lifeSpanDev; - int fadeInDur; - int fadeOutDur; - qreal angle; - qreal angleDev; - qreal velocity; - qreal velocityDev; - qreal emissionCarry; - int addParticleTime; - int addParticleCount; - int lastAdvTime; - QDeclarativeParticleMotion *motion; - QDeclarativeParticlesPainter *paintItem; - - bool pendingPixmapCache; - - QList<QPair<int, int> > bursts;//countLeft, emissionRate pairs - QList<QDeclarativeParticle> particles; - QTickAnimationProxy<QDeclarativeParticlesPrivate, &QDeclarativeParticlesPrivate::tick> clock; - -}; - -void QDeclarativeParticlesPrivate::tick(int time) -{ - Q_Q(QDeclarativeParticles); - if (!motion) - motion = new QDeclarativeParticleMotionLinear(q); - - int oldCount = particles.count(); - int removed = 0; - int interval = time - lastAdvTime; - for (int i = 0; i < particles.count(); ) { - QDeclarativeParticle &particle = particles[i]; - int age = time - particle.birthTime; - if (age >= particle.lifeSpan) { - QDeclarativeParticle part = particles.takeAt(i); - motion->destroy(part); - ++removed; - } else { - updateOpacity(particle, age); - motion->advance(particle, interval); - ++i; - } - } - - if(emissionRate == -1)//Otherwise leave emission to the emission rate - while(removed-- && ((count == -1) || particles.count() < count)) - createParticle(time); - - if (!addParticleTime) - addParticleTime = time; - - //Possibly emit new particles - if (((count == -1) || particles.count() < count) && emissionRate - && !(count==-1 && emissionRate==-1)) { - int emissionCount = -1; - if (emissionRate != -1){ - qreal variance = 1.; - if (emissionVariance > 0.){ - variance += (qreal(qrand())/RAND_MAX) * emissionVariance * (qrand()%2?-1.:1.); - } - qreal emission = emissionRate * (qreal(interval)/1000.); - emission = emission * variance + emissionCarry; - double tmpDbl; - emissionCarry = modf(emission, &tmpDbl); - emissionCount = (int)tmpDbl; - emissionCount = qMax(0,emissionCount); - } - while(((count == -1) || particles.count() < count) && - (emissionRate==-1 || emissionCount--)) - createParticle(time); - } - - //Deal with emissions from requested bursts - for(int i=0; i<bursts.size(); i++){ - int emission = 0; - if(bursts[i].second == -1){ - emission = bursts[i].first; - }else{ - qreal variance = 1.; - if (emissionVariance > 0.){ - variance += (qreal(qrand())/RAND_MAX) * emissionVariance * (qrand()%2?-1.:1.); - } - qreal workingEmission = bursts[i].second * (qreal(interval)/1000.); - workingEmission *= variance; - emission = (int)workingEmission; - emission = qMax(emission, 0); - } - emission = qMin(emission, bursts[i].first); - bursts[i].first -= emission; - while(emission--) - createParticle(time); - } - for(int i=bursts.size()-1; i>=0; i--) - if(bursts[i].first <= 0) - bursts.removeAt(i); - - lastAdvTime = time; - paintItem->updateSize(); - paintItem->update(); - if (!(oldCount || particles.count()) && (!count || !emissionRate) && bursts.isEmpty()) { - lastAdvTime = 0; - clock.stop(); - } -} - -void QDeclarativeParticlesPrivate::createParticle(int time) -{ -#ifdef Q_ENABLE_PERFORMANCE_LOG - QDeclarativePerfTimer<QDeclarativePerf::CreateParticle> x; -#endif - Q_Q(QDeclarativeParticles); - QDeclarativeParticle p(time); - p.x = q->x() + q->width() * qreal(qrand()) / RAND_MAX - image.width()/2.0; - p.y = q->y() + q->height() * qreal(qrand()) / RAND_MAX - image.height()/2.0; - p.lifeSpan = lifeSpan; - if (lifeSpanDev) - p.lifeSpan += int(lifeSpanDev/2 - lifeSpanDev * qreal(qrand()) / RAND_MAX); - p.fadeOutAge = p.lifeSpan - fadeOutDur; - if (fadeInDur == 0.) { - p.state= QDeclarativeParticle::Solid; - p.opacity = 1.0; - } - qreal a = angle; - if (angleDev) - a += angleDev/2 - angleDev * qreal(qrand()) / RAND_MAX; - if (a > M_PI) - a = a - 2 * M_PI; - qreal v = velocity; - if (velocityDev) - v += velocityDev/2 - velocityDev * qreal(qrand()) / RAND_MAX; - p.x_velocity = v * fastCos(a); - p.y_velocity = v * fastSin(a); - particles.append(p); - motion->created(particles.last()); -} - -void QDeclarativeParticlesPrivate::updateOpacity(QDeclarativeParticle &p, int age) -{ - switch (p.state) { - case QDeclarativeParticle::FadeIn: - if (age <= fadeInDur) { - p.opacity = qreal(age) / fadeInDur; - break; - } else { - p.opacity = 1.0; - p.state = QDeclarativeParticle::Solid; - // Fall through - } - case QDeclarativeParticle::Solid: - if (age <= p.fadeOutAge) { - break; - } else { - p.state = QDeclarativeParticle::FadeOut; - // Fall through - } - case QDeclarativeParticle::FadeOut: - p.opacity = qreal(p.lifeSpan - age) / fadeOutDur; - break; - } -} - -/*! - \qmlclass Particles - \since 4.7 - \brief The Particles object generates and moves particles. - \inherits Item - - This element provides preliminary support for particles in QML, - and may be heavily changed or removed in later versions. - - The particles created by this object cannot be dealt with - directly, they can only be controlled through the parameters of - the Particles object. The particles are all the same pixmap, - specified by the user. - - The particles are painted relative to the parent of the Particles - object. Moving the Particles object will not move the particles - already emitted. - - The below example creates two differently behaving particle - sources. The top one has particles falling from the top like - snow, the lower one has particles expelled up like a fountain. - - \qml -Rectangle { - width: 240 - height: 320 - color: "black" - Particles { - y: 0 - width: parent.width - height: 30 - source: "star.png" - lifeSpan: 5000 - count: 50 - angle: 70 - angleDeviation: 36 - velocity: 30 - velocityDeviation: 10 - ParticleMotionWander { - xvariance: 30 - pace: 100 - } - } - Particles { - y: 300 - x: 120 - width: 1 - height: 1 - source: "star.png" - lifeSpan: 5000 - count: 200 - angle: 270 - angleDeviation: 45 - velocity: 50 - velocityDeviation: 30 - ParticleMotionGravity { - yattractor: 1000 - xattractor: 0 - acceleration: 25 - } - } -} - \endqml - \image particles.gif -*/ - -/*! - \internal - \class QDeclarativeParticles - \ingroup group_effects - \brief The QDeclarativeParticles class generates and moves particles. -*/ - -QDeclarativeParticles::QDeclarativeParticles(QDeclarativeItem *parent) - : QDeclarativeItem(*(new QDeclarativeParticlesPrivate), parent) -{ - Q_D(QDeclarativeParticles); - d->init(); -} - -QDeclarativeParticles::~QDeclarativeParticles() -{ - Q_D(QDeclarativeParticles); - if (d->pendingPixmapCache) - QDeclarativePixmapCache::cancel(d->url, this); -} - -/*! - \qmlproperty string Particles::source - This property holds the URL of the particle image. -*/ - -/*! - \property QDeclarativeParticles::source - \brief the URL of the particle image. -*/ -QUrl QDeclarativeParticles::source() const -{ - Q_D(const QDeclarativeParticles); - return d->url; -} - -void QDeclarativeParticles::imageLoaded() -{ - Q_D(QDeclarativeParticles); - d->pendingPixmapCache = false; - QDeclarativePixmapCache::get(d->url, &d->image); - d->paintItem->updateSize(); - d->paintItem->update(); -} - -void QDeclarativeParticles::setSource(const QUrl &name) -{ - Q_D(QDeclarativeParticles); - - if ((d->url.isEmpty() == name.isEmpty()) && name == d->url) - return; - - if (d->pendingPixmapCache) { - QDeclarativePixmapCache::cancel(d->url, this); - d->pendingPixmapCache = false; - } - if (name.isEmpty()) { - d->url = name; - d->image = QPixmap(); - d->paintItem->updateSize(); - d->paintItem->update(); - } else { - d->url = name; - Q_ASSERT(!name.isRelative()); - QDeclarativePixmapReply::Status status = QDeclarativePixmapCache::get(d->url, &d->image); - if (status != QDeclarativePixmapReply::Ready && status != QDeclarativePixmapReply::Error) { - QDeclarativePixmapReply *reply = QDeclarativePixmapCache::request(qmlEngine(this), d->url); - connect(reply, SIGNAL(finished()), this, SLOT(imageLoaded())); - d->pendingPixmapCache = true; - } else { - //### unify with imageLoaded - d->paintItem->updateSize(); - d->paintItem->update(); - } - } - emit sourceChanged(); -} - -/*! - \qmlproperty int Particles::count - This property holds the maximum number of particles - - The particles element emits particles until it has count active - particles. When this number is reached, new particles are not emitted until - some of the current particles reach the end of their lifespan. - - If count is -1 then there is no maximum number of active particles, and - particles will be constantly emitted at the rate specified by emissionRate. - - The default value for count is 1. - - If both count and emissionRate are set to -1, nothing will be emitted. - -*/ - -/*! - \property QDeclarativeParticles::count - \brief the maximum number of particles -*/ -int QDeclarativeParticles::count() const -{ - Q_D(const QDeclarativeParticles); - return d->count; -} - -void QDeclarativeParticles::setCount(int cnt) -{ - Q_D(QDeclarativeParticles); - if (cnt == d->count) - return; - - int oldCount = d->count; - d->count = cnt; - d->addParticleTime = 0; - d->addParticleCount = d->particles.count(); - if (!oldCount && d->clock.state() != QAbstractAnimation::Running && d->count && d->emissionRate) { - d->clock.start(); - } - d->paintItem->updateSize(); - d->paintItem->update(); - emit countChanged(); -} - - -/*! - \qmlproperty int Particles::emissionRate - This property holds the target number of particles to emit every second. - - The particles element will emit up to emissionRate particles every - second. Fewer particles may be emitted per second if the maximum number of - particles has been reached. - - If emissionRate is set to -1 there is no limit to the number of - particles emitted per second, and particles will be instantly emitted to - reach the maximum number of particles specified by count. - - The default value for emissionRate is -1. - - If both count and emissionRate are set to -1, nothing will be emitted. -*/ - -/*! - \property QDeclarativeParticles::emissionRate - \brief the emission rate of particles -*/ -int QDeclarativeParticles::emissionRate() const -{ - Q_D(const QDeclarativeParticles); - return d->emissionRate; -} -void QDeclarativeParticles::setEmissionRate(int er) -{ - Q_D(QDeclarativeParticles); - if(er == d->emissionRate) - return; - d->emissionRate = er; - if (d->clock.state() != QAbstractAnimation::Running && d->count && d->emissionRate) { - d->clock.start(); - } - emit emissionRateChanged(); -} - -/*! - \qmlproperty qreal Particles::emissionVariance - This property holds how inconsistent the rate of particle emissions are. - It is a number between 0 (no variance) and 1 (some variance). - - The expected number of particles emitted per second is emissionRate. If - emissionVariance is 0 then particles will be emitted consistently throughout - each second to reach that number. If emissionVariance is greater than 0 the - rate of particle emission will vary randomly throughout the second, with the - consequence that the actual number of particles emitted in one second will - vary randomly as well. - - emissionVariance is the maximum deviation from emitting - emissionRate particles per second. An emissionVariance of 0 means you should - get exactly emissionRate particles emitted per second, - and an emissionVariance of 1 means you will get between zero and two times - emissionRate particles per second, but you should get emissionRate particles - per second on average. - - Note that even with an emissionVariance of 0 there may be some variance due - to performance and hardware constraints. - - The default value of emissionVariance is 0.5 -*/ - -/*! - \property QDeclarativeParticles::emissionVariance - \brief how much the particle emission amounts vary per tick -*/ - -qreal QDeclarativeParticles::emissionVariance() const -{ - Q_D(const QDeclarativeParticles); - return d->emissionVariance; -} - -void QDeclarativeParticles::setEmissionVariance(qreal ev) -{ - Q_D(QDeclarativeParticles); - if(d->emissionVariance == ev) - return; - d->emissionVariance = ev; - emit emissionVarianceChanged(); -} - -/*! - \qmlproperty int Particles::lifeSpan - \qmlproperty int Particles::lifeSpanDeviation - - These properties describe the life span of each particle. - - The default lifespan for a particle is 1000ms. - - lifeSpanDeviation randomly varies the lifeSpan up to the specified variation. For - example, the following creates particles whose lifeSpan will vary - from 150ms to 250ms: - - \qml -Particles { - source: "star.png" - lifeSpan: 200 - lifeSpanDeviation: 100 -} - \endqml -*/ - -/*! - \property QDeclarativeParticles::lifeSpan - \brief the life span of each particle. - - Default value is 1000ms. - - \sa QDeclarativeParticles::lifeSpanDeviation -*/ -int QDeclarativeParticles::lifeSpan() const -{ - Q_D(const QDeclarativeParticles); - return d->lifeSpan; -} - -void QDeclarativeParticles::setLifeSpan(int ls) -{ - Q_D(QDeclarativeParticles); - if(d->lifeSpan == ls) - return; - d->lifeSpan = ls; - emit lifeSpanChanged(); -} - -/*! - \property QDeclarativeParticles::lifeSpanDeviation - \brief the maximum possible deviation from the set lifeSpan. - - Randomly varies the lifeSpan up to the specified variation. For - example, the following creates particles whose lifeSpan will vary - from 150ms to 250ms: - -\qml -Particles { - source: "star.png" - lifeSpan: 200 - lifeSpanDeviation: 100 -} -\endqml - - \sa QDeclarativeParticles::lifeSpan -*/ -int QDeclarativeParticles::lifeSpanDeviation() const -{ - Q_D(const QDeclarativeParticles); - return d->lifeSpanDev; -} - -void QDeclarativeParticles::setLifeSpanDeviation(int dev) -{ - Q_D(QDeclarativeParticles); - if(d->lifeSpanDev == dev) - return; - d->lifeSpanDev = dev; - emit lifeSpanDeviationChanged(); -} - -/*! - \qmlproperty int Particles::fadeInDuration - \qmlproperty int Particles::fadeOutDuration - These properties hold the time taken to fade the particles in and out. - - By default fade in is 200ms and fade out is 300ms. -*/ - -/*! - \property QDeclarativeParticles::fadeInDuration - \brief the time taken to fade in the particles. - - Default value is 200ms. -*/ -int QDeclarativeParticles::fadeInDuration() const -{ - Q_D(const QDeclarativeParticles); - return d->fadeInDur; -} - -void QDeclarativeParticles::setFadeInDuration(int dur) -{ - Q_D(QDeclarativeParticles); - if (dur < 0.0 || dur == d->fadeInDur) - return; - d->fadeInDur = dur; - emit fadeInDurationChanged(); -} - -/*! - \property QDeclarativeParticles::fadeOutDuration - \brief the time taken to fade out the particles. - - Default value is 300ms. -*/ -int QDeclarativeParticles::fadeOutDuration() const -{ - Q_D(const QDeclarativeParticles); - return d->fadeOutDur; -} - -void QDeclarativeParticles::setFadeOutDuration(int dur) -{ - Q_D(QDeclarativeParticles); - if (dur < 0.0 || d->fadeOutDur == dur) - return; - d->fadeOutDur = dur; - emit fadeOutDurationChanged(); -} - -/*! - \qmlproperty real Particles::angle - \qmlproperty real Particles::angleDeviation - - These properties control particle direction. - - angleDeviation randomly varies the direction up to the specified variation. For - example, the following creates particles whose initial direction will - vary from 15 degrees to 105 degrees: - - \qml -Particles { - source: "star.png" - angle: 60 - angleDeviation: 90 -} - \endqml -*/ - -/*! - \property QDeclarativeParticles::angle - \brief the initial angle of direction. - - \sa QDeclarativeParticles::angleDeviation -*/ -qreal QDeclarativeParticles::angle() const -{ - Q_D(const QDeclarativeParticles); - return d->angle * 180.0 / M_PI; -} - -void QDeclarativeParticles::setAngle(qreal angle) -{ - Q_D(QDeclarativeParticles); - qreal radAngle = angle * M_PI / 180.0; - if(radAngle == d->angle) - return; - d->angle = radAngle; - emit angleChanged(); -} - -/*! - \property QDeclarativeParticles::angleDeviation - \brief the maximum possible deviation from the set angle. - - Randomly varies the direction up to the specified variation. For - example, the following creates particles whose initial direction will - vary from 15 degrees to 105 degrees: - -\qml -Particles { - source: "star.png" - angle: 60 - angleDeviation: 90 -} -\endqml - - \sa QDeclarativeParticles::angle -*/ -qreal QDeclarativeParticles::angleDeviation() const -{ - Q_D(const QDeclarativeParticles); - return d->angleDev * 180.0 / M_PI; -} - -void QDeclarativeParticles::setAngleDeviation(qreal dev) -{ - Q_D(QDeclarativeParticles); - qreal radDev = dev * M_PI / 180.0; - if(radDev == d->angleDev) - return; - d->angleDev = radDev; - emit angleDeviationChanged(); -} - -/*! - \qmlproperty real Particles::velocity - \qmlproperty real Particles::velocityDeviation - - These properties control the velocity of the particles. - - velocityDeviation randomly varies the velocity up to the specified variation. For - example, the following creates particles whose initial velocity will - vary from 40 to 60. - - \qml -Particles { - source: "star.png" - velocity: 50 - velocityDeviation: 20 -} - \endqml -*/ - -/*! - \property QDeclarativeParticles::velocity - \brief the initial velocity of the particles. - - \sa QDeclarativeParticles::velocityDeviation -*/ -qreal QDeclarativeParticles::velocity() const -{ - Q_D(const QDeclarativeParticles); - return d->velocity * 1000.0; -} - -void QDeclarativeParticles::setVelocity(qreal velocity) -{ - Q_D(QDeclarativeParticles); - qreal realVel = velocity / 1000.0; - if(realVel == d->velocity) - return; - d->velocity = realVel; - emit velocityChanged(); -} - -/*! - \property QDeclarativeParticles::velocityDeviation - \brief the maximum possible deviation from the set velocity. - - Randomly varies the velocity up to the specified variation. For - example, the following creates particles whose initial velocity will - vary from 40 to 60. - -\qml -Particles { - source: "star.png" - velocity: 50 - velocityDeviation: 20 -} -\endqml - - \sa QDeclarativeParticles::velocity -*/ -qreal QDeclarativeParticles::velocityDeviation() const -{ - Q_D(const QDeclarativeParticles); - return d->velocityDev * 1000.0; -} - -void QDeclarativeParticles::setVelocityDeviation(qreal velocity) -{ - Q_D(QDeclarativeParticles); - qreal realDev = velocity / 1000.0; - if(realDev == d->velocityDev) - return; - d->velocityDev = realDev; - emit velocityDeviationChanged(); -} - -/*! - \qmlproperty ParticleMotion Particles::motion - This property sets the type of motion to apply to the particles. - - When a particle is created it will have an initial direction and velocity. - The motion of the particle during its lifeSpan is then influenced by the - motion property. - - Default motion is ParticleMotionLinear. -*/ - -/*! - \property QDeclarativeParticles::motion - \brief sets the type of motion to apply to the particles. - - When a particle is created it will have an initial direction and velocity. - The motion of the particle during its lifeSpan is then influenced by the - motion property. - - Default motion is QDeclarativeParticleMotionLinear. -*/ -QDeclarativeParticleMotion *QDeclarativeParticles::motion() const -{ - Q_D(const QDeclarativeParticles); - return d->motion; -} - -void QDeclarativeParticles::setMotion(QDeclarativeParticleMotion *motion) -{ - Q_D(QDeclarativeParticles); - if (motion == d->motion) - return; - d->motion = motion; - emit motionChanged(); -} - -/*! - \qmlmethod Particles::burst(int count, int emissionRate) - - Initiates a burst of particles. - - This method takes two arguments. The first argument is the number - of particles to emit and the second argument is the emissionRate for the - burst. If the second argument is omitted, it is treated as -1. The burst - of particles has a separate emissionRate and count to the normal emission of - particles. The burst uses the same values as normal emission for all other - properties, including emissionVariance. - - The normal emission of particles will continue during the burst, however - the particles created by the burst count towards the maximum number used by - normal emission. To avoid this behavior, use two Particles elements. - -*/ -void QDeclarativeParticles::burst(int count, int emissionRate) -{ - Q_D(QDeclarativeParticles); - d->bursts << qMakePair(count, emissionRate); - if (d->clock.state() != QAbstractAnimation::Running) - d->clock.start(); -} - -void QDeclarativeParticlesPainter::updateSize() -{ - if (!d->_componentComplete) - return; - - const int parentX = parentItem()->x(); - const int parentY = parentItem()->y(); - for (int i = 0; i < d->particles.count(); ++i) { - const QDeclarativeParticle &particle = d->particles.at(i); - if(particle.x > maxX) - maxX = particle.x; - if(particle.x < minX) - minX = particle.x; - if(particle.y > maxY) - maxY = particle.y; - if(particle.y < minY) - minY = particle.y; - } - - int myWidth = (int)(maxX-minX+0.5)+d->image.width(); - int myX = (int)(minX - parentX); - int myHeight = (int)(maxY-minY+0.5)+d->image.height(); - int myY = (int)(minY - parentY); - setWidth(myWidth); - setHeight(myHeight); - setX(myX); - setY(myY); -} - -void QDeclarativeParticles::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) -{ - Q_UNUSED(p); - //painting is done by the ParticlesPainter, so it can have the right size -} - -void QDeclarativeParticlesPainter::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) -{ - if (d->image.isNull() || d->particles.isEmpty()) - return; - - const int myX = x() + parentItem()->x(); - const int myY = y() + parentItem()->y(); - -#if (QT_VERSION >= QT_VERSION_CHECK(4,7,0)) - QVarLengthArray<QPainter::PixmapFragment, 256> pixmapData; -#else - QVarLengthArray<QDrawPixmaps::Data, 256> pixmapData; -#endif - pixmapData.resize(d->particles.count()); - - const QRectF sourceRect = d->image.rect(); - qreal halfPWidth = sourceRect.width()/2.; - qreal halfPHeight = sourceRect.height()/2.; - for (int i = 0; i < d->particles.count(); ++i) { - const QDeclarativeParticle &particle = d->particles.at(i); -#if (QT_VERSION >= QT_VERSION_CHECK(4,7,0)) - pixmapData[i].x = particle.x - myX + halfPWidth; - pixmapData[i].y = particle.y - myY + halfPHeight; -#else - pixmapData[i].point = QPointF(particle.x - myX + halfPWidth, particle.y - myY + halfPHeight); -#endif - pixmapData[i].opacity = particle.opacity; - - //these never change - pixmapData[i].rotation = 0; - pixmapData[i].scaleX = 1; - pixmapData[i].scaleY = 1; -#if (QT_VERSION >= QT_VERSION_CHECK(4,7,0)) - pixmapData[i].sourceLeft = sourceRect.left(); - pixmapData[i].sourceTop = sourceRect.top(); - pixmapData[i].width = sourceRect.width(); - pixmapData[i].height = sourceRect.height(); -#else - pixmapData[i].source = sourceRect; -#endif - } -#if (QT_VERSION >= QT_VERSION_CHECK(4,7,0)) - p->drawPixmapFragments(pixmapData.data(), d->particles.count(), d->image); -#else - qDrawPixmaps(p, pixmapData.data(), d->particles.count(), d->image); -#endif -} - -void QDeclarativeParticles::componentComplete() -{ - Q_D(QDeclarativeParticles); - QDeclarativeItem::componentComplete(); - if (d->count && d->emissionRate) { - d->paintItem->updateSize(); - d->clock.start(); - } - if (d->lifeSpanDev > d->lifeSpan) - d->lifeSpanDev = d->lifeSpan; -} - -QT_END_NAMESPACE diff --git a/src/declarative/graphicsitems/qdeclarativeparticles_p.h b/src/declarative/graphicsitems/qdeclarativeparticles_p.h deleted file mode 100644 index 06acbb9..0000000 --- a/src/declarative/graphicsitems/qdeclarativeparticles_p.h +++ /dev/null @@ -1,258 +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 QDECLARATIVEPARTICLES_H -#define QDECLARATIVEPARTICLES_H - -#include "qdeclarativeitem.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QDeclarativeParticle; -class QDeclarativeParticles; -class Q_DECLARATIVE_EXPORT QDeclarativeParticleMotion : public QObject -{ - Q_OBJECT -public: - QDeclarativeParticleMotion(QObject *parent=0); - - virtual void advance(QDeclarativeParticle &, int interval); - virtual void created(QDeclarativeParticle &); - virtual void destroy(QDeclarativeParticle &); -}; - -class Q_DECLARATIVE_EXPORT QDeclarativeParticleMotionLinear : public QDeclarativeParticleMotion -{ - Q_OBJECT -public: - QDeclarativeParticleMotionLinear(QObject *parent=0) - : QDeclarativeParticleMotion(parent) {} - - virtual void advance(QDeclarativeParticle &, int interval); -}; - -class Q_DECLARATIVE_EXPORT QDeclarativeParticleMotionGravity : public QDeclarativeParticleMotion -{ - Q_OBJECT - - Q_PROPERTY(qreal xattractor READ xAttractor WRITE setXAttractor NOTIFY xattractorChanged) - Q_PROPERTY(qreal yattractor READ yAttractor WRITE setYAttractor NOTIFY yattractorChanged) - Q_PROPERTY(qreal acceleration READ acceleration WRITE setAcceleration NOTIFY accelerationChanged) -public: - QDeclarativeParticleMotionGravity(QObject *parent=0) - : QDeclarativeParticleMotion(parent), _xAttr(0.0), _yAttr(0.0), _accel(0.00005) {} - - qreal xAttractor() const { return _xAttr; } - void setXAttractor(qreal x); - - qreal yAttractor() const { return _yAttr; } - void setYAttractor(qreal y); - - qreal acceleration() const { return _accel * 1000000; } - void setAcceleration(qreal accel); - - virtual void advance(QDeclarativeParticle &, int interval); - -Q_SIGNALS: - void xattractorChanged(); - void yattractorChanged(); - void accelerationChanged(); - -private: - qreal _xAttr; - qreal _yAttr; - qreal _accel; -}; - -class Q_DECLARATIVE_EXPORT QDeclarativeParticleMotionWander : public QDeclarativeParticleMotion -{ - Q_OBJECT -public: - QDeclarativeParticleMotionWander() - : QDeclarativeParticleMotion(), particles(0), _xvariance(0), _yvariance(0) {} - - virtual void advance(QDeclarativeParticle &, int interval); - virtual void created(QDeclarativeParticle &); - virtual void destroy(QDeclarativeParticle &); - - struct Data { - qreal x_targetV; - qreal y_targetV; - qreal x_peak; - qreal y_peak; - qreal x_var; - qreal y_var; - }; - - Q_PROPERTY(qreal xvariance READ xVariance WRITE setXVariance NOTIFY xvarianceChanged) - qreal xVariance() const { return _xvariance * 1000.0; } - void setXVariance(qreal var); - - Q_PROPERTY(qreal yvariance READ yVariance WRITE setYVariance NOTIFY yvarianceChanged) - qreal yVariance() const { return _yvariance * 1000.0; } - void setYVariance(qreal var); - - Q_PROPERTY(qreal pace READ pace WRITE setPace NOTIFY paceChanged) - qreal pace() const { return _pace * 1000.0; } - void setPace(qreal pace); - -Q_SIGNALS: - void xvarianceChanged(); - void yvarianceChanged(); - void paceChanged(); - -private: - QDeclarativeParticles *particles; - qreal _xvariance; - qreal _yvariance; - qreal _pace; -}; - -class QDeclarativeParticlesPrivate; -class Q_DECLARATIVE_EXPORT QDeclarativeParticles : public QDeclarativeItem -{ - Q_OBJECT - - Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) - Q_PROPERTY(int count READ count WRITE setCount NOTIFY countChanged) - Q_PROPERTY(int emissionRate READ emissionRate WRITE setEmissionRate NOTIFY emissionRateChanged) - Q_PROPERTY(qreal emissionVariance READ emissionVariance WRITE setEmissionVariance NOTIFY emissionVarianceChanged) - Q_PROPERTY(int lifeSpan READ lifeSpan WRITE setLifeSpan NOTIFY lifeSpanChanged) - Q_PROPERTY(int lifeSpanDeviation READ lifeSpanDeviation WRITE setLifeSpanDeviation NOTIFY lifeSpanDeviationChanged) - Q_PROPERTY(int fadeInDuration READ fadeInDuration WRITE setFadeInDuration NOTIFY fadeInDurationChanged) - Q_PROPERTY(int fadeOutDuration READ fadeOutDuration WRITE setFadeOutDuration NOTIFY fadeOutDurationChanged) - Q_PROPERTY(qreal angle READ angle WRITE setAngle NOTIFY angleChanged) - Q_PROPERTY(qreal angleDeviation READ angleDeviation WRITE setAngleDeviation NOTIFY angleDeviationChanged) - Q_PROPERTY(qreal velocity READ velocity WRITE setVelocity NOTIFY velocityChanged) - Q_PROPERTY(qreal velocityDeviation READ velocityDeviation WRITE setVelocityDeviation NOTIFY velocityDeviationChanged) - Q_PROPERTY(QDeclarativeParticleMotion *motion READ motion WRITE setMotion NOTIFY motionChanged) - Q_CLASSINFO("DefaultProperty", "motion") - -public: - QDeclarativeParticles(QDeclarativeItem *parent=0); - ~QDeclarativeParticles(); - - QUrl source() const; - void setSource(const QUrl &); - - int count() const; - void setCount(int cnt); - - int emissionRate() const; - void setEmissionRate(int); - - qreal emissionVariance() const; - void setEmissionVariance(qreal); - - int lifeSpan() const; - void setLifeSpan(int); - - int lifeSpanDeviation() const; - void setLifeSpanDeviation(int); - - int fadeInDuration() const; - void setFadeInDuration(int); - - int fadeOutDuration() const; - void setFadeOutDuration(int); - - qreal angle() const; - void setAngle(qreal); - - qreal angleDeviation() const; - void setAngleDeviation(qreal); - - qreal velocity() const; - void setVelocity(qreal); - - qreal velocityDeviation() const; - void setVelocityDeviation(qreal); - - QDeclarativeParticleMotion *motion() const; - void setMotion(QDeclarativeParticleMotion *); - - void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); - -public Q_SLOTS: - void burst(int count, int emissionRate=-1); - -protected: - virtual void componentComplete(); - -Q_SIGNALS: - void sourceChanged(); - void countChanged(); - void emissionRateChanged(); - void emissionVarianceChanged(); - void lifeSpanChanged(); - void lifeSpanDeviationChanged(); - void fadeInDurationChanged(); - void fadeOutDurationChanged(); - void angleChanged(); - void angleDeviationChanged(); - void velocityChanged(); - void velocityDeviationChanged(); - void emittingChanged(); - void motionChanged(); - -private Q_SLOTS: - void imageLoaded(); - -private: - Q_DISABLE_COPY(QDeclarativeParticles) - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeParticles) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QDeclarativeParticleMotion) -QML_DECLARE_TYPE(QDeclarativeParticleMotionLinear) -QML_DECLARE_TYPE(QDeclarativeParticleMotionGravity) -QML_DECLARE_TYPE(QDeclarativeParticleMotionWander) -QML_DECLARE_TYPE(QDeclarativeParticles) - -QT_END_HEADER - -#endif diff --git a/src/declarative/graphicsitems/qdeclarativepathview.cpp b/src/declarative/graphicsitems/qdeclarativepathview.cpp index cc17157..b9c8971 100644 --- a/src/declarative/graphicsitems/qdeclarativepathview.cpp +++ b/src/declarative/graphicsitems/qdeclarativepathview.cpp @@ -354,7 +354,7 @@ void QDeclarativePathView::setCurrentIndex(int idx) /*! \qmlproperty real PathView::offset - The offset specifies how far along the path the items are from their initial positions. + The offset specifies how far along the path (0.0-1.0) the items are from their initial positions. */ qreal QDeclarativePathView::offset() const { @@ -373,9 +373,9 @@ void QDeclarativePathViewPrivate::setOffset(qreal o) { Q_Q(QDeclarativePathView); if (_offset != o) { - _offset = qmlMod(o, qreal(100.0)); + _offset = qmlMod(o, qreal(1.0)); if (_offset < 0) - _offset = 100.0 + _offset; + _offset = 1.0 + _offset; q->refill(); } } @@ -503,7 +503,7 @@ QPointF QDeclarativePathViewPrivate::pointNear(const QPointF &point, qreal *near } if (nearPercent) - *nearPercent = nearPc / 10.0; + *nearPercent = nearPc / 1000.0; return nearPoint; } @@ -559,10 +559,10 @@ void QDeclarativePathView::mouseMoveEvent(QGraphicsSceneMouseEvent *event) if (diff) { setOffset(d->_offset + diff); - if (diff > 50) - diff -= 100; - else if (diff < -50) - diff += 100; + if (diff > 0.5) + diff -= 1.0; + else if (diff < -0.5) + diff += 1.0; d->lastElapsed = QDeclarativeItemPrivate::restart(d->lastPosTime); d->lastDist = diff; @@ -579,15 +579,15 @@ void QDeclarativePathView::mouseReleaseEvent(QGraphicsSceneMouseEvent *) qreal elapsed = qreal(d->lastElapsed + QDeclarativeItemPrivate::elapsed(d->lastPosTime)) / 1000.; qreal velocity = elapsed > 0. ? d->lastDist / elapsed : 0; - if (d->model && d->model->count() && qAbs(velocity) > 5) { - if (velocity > 100) - velocity = 100; - else if (velocity < -100) - velocity = -100; - qreal inc = qmlMod(d->_offset - d->snapPos, qreal(100.0 / d->model->count())); - qreal dist = qAbs(velocity/2 - qmlMod(velocity/2, qreal(100.0 / d->model->count()) - inc)); + if (d->model && d->model->count() && qAbs(velocity) > 0.05) { + if (velocity > 1.5) + velocity = 1.5; + else if (velocity < -1.5) + velocity = -1.5; + qreal inc = qmlMod(d->_offset - d->snapPos, qreal(1.0 / d->model->count())); + qreal dist = qAbs(velocity/2 - qmlMod(velocity/2, qreal(1.0 / d->model->count()) - inc)); d->moveOffset.setValue(d->_offset); - d->tl.accel(d->moveOffset, velocity, 10, dist); + d->tl.accel(d->moveOffset, velocity, 0.1, dist); d->tl.callback(QDeclarativeTimeLineCallback(&d->moveOffset, d->fixOffsetCallback, d)); } else { d->fixOffset(); @@ -676,10 +676,10 @@ void QDeclarativePathView::componentComplete() itemIndex += d->pathOffset; itemIndex %= d->items.count(); - qreal targetOffset = qmlMod(100 + (d->snapPos*100) - 100.0 * itemIndex / d->items.count(), qreal(100.0)); + qreal targetOffset = qmlMod(1.0 + d->snapPos - qreal(itemIndex) / d->items.count(), qreal(1.0)); if (targetOffset < 0) - targetOffset = 100.0 + targetOffset; + targetOffset = 1.0 + targetOffset; if (targetOffset != d->_offset) { d->moveOffset.setValue(targetOffset); } @@ -712,8 +712,8 @@ void QDeclarativePathViewPrivate::regenerate() } items.append(item); item->setZValue(i); - qreal percent = i * (100. / numItems) + _offset; - percent = qAbs(qmlMod(percent, qreal(100.0))/100.0); + qreal percent = qreal(i) / numItems + _offset; + percent = qAbs(qmlMod(percent, qreal(1.0))); updateItem(item, percent); model->completeItem(); if (currentIndex == index) { @@ -745,10 +745,10 @@ void QDeclarativePathView::refill() QList<qreal> positions; for (int i=0; i<d->items.count(); i++){ - qreal percent = i * (100. / d->items.count()); + qreal percent = qreal(i) / d->items.count(); percent = percent + d->_offset; - percent = qmlMod(percent, qreal(100.0)); - positions << qAbs(percent/100.0); + percent = qmlMod(percent, qreal(1.0)); + positions << qAbs(percent); } if (d->pathItems==-1) { @@ -843,10 +843,10 @@ void QDeclarativePathView::itemsInserted(int modelIndex, int count) int itemIndex = (d->currentIndex - d->firstIndex + d->model->count())%d->model->count(); itemIndex += d->pathOffset; itemIndex %= d->items.count(); - qreal targetOffset = qmlMod(100 + (d->snapPos*100) - 100.0 * itemIndex / d->items.count(), qreal(100.0)); + qreal targetOffset = qmlMod(1.0 + d->snapPos - qreal(itemIndex) / d->items.count(), qreal(1.0)); if (targetOffset < 0) - targetOffset = 100.0 + targetOffset; + targetOffset = 1.0 + targetOffset; if (targetOffset != d->_offset) d->moveOffset.setValue(targetOffset); } @@ -880,10 +880,10 @@ void QDeclarativePathView::itemsRemoved(int modelIndex, int count) int itemIndex = (d->currentIndex - d->firstIndex + d->model->count())%d->model->count(); itemIndex += d->pathOffset; itemIndex %= d->items.count(); - qreal targetOffset = qmlMod(100 + (d->snapPos*100) - 100.0 * itemIndex / d->items.count(), qreal(100.0)); + qreal targetOffset = qmlMod(1.0 + d->snapPos - qreal(itemIndex) / d->items.count(), qreal(1.0)); if (targetOffset < 0) - targetOffset = 100.0 + targetOffset; + targetOffset = 1.0 + targetOffset; if (targetOffset != d->_offset) d->moveOffset.setValue(targetOffset); } @@ -919,15 +919,15 @@ int QDeclarativePathViewPrivate::calcCurrentIndex() { int current = -1; if (model && items.count()) { - _offset = qmlMod(_offset, qreal(100.0)); + _offset = qmlMod(_offset, qreal(1.0)); if (_offset < 0) - _offset += 100.0; + _offset += 1.0; if (pathItems == -1) { - qreal delta = qmlMod(_offset - snapPos, qreal(100.0)); + qreal delta = qmlMod(_offset - snapPos, qreal(1.0)); if (delta < 0) - delta = 100.0 + delta; - int ii = model->count() - qRound(delta * model->count() / 100); + delta = 1.0 + delta; + int ii = model->count() - qRound(delta * model->count()); if (ii < 0) ii = 0; current = ii; @@ -935,10 +935,10 @@ int QDeclarativePathViewPrivate::calcCurrentIndex() qreal bestDiff=1e9; int bestI=-1; for (int i=0; i<items.count(); i++){ - qreal percent = i * (100. / items.count()); + qreal percent = qreal(i) / items.count(); percent = percent + _offset; - percent = qmlMod(percent, qreal(100.0)); - qreal diff = qAbs(snapPos - (percent/100.0)); + percent = qmlMod(percent, qreal(1.0)); + qreal diff = qAbs(snapPos - percent); if (diff < bestDiff){ bestDiff = diff; bestI = i; @@ -1017,10 +1017,10 @@ void QDeclarativePathViewPrivate::snapToCurrent() itemIndex = itemIndex - model->count() + items.count(); } itemIndex %= items.count(); - qreal targetOffset = qmlMod(100 + (snapPos*100) - 100.0 * itemIndex / items.count(), qreal(100.0)); + qreal targetOffset = qmlMod(1.0 + snapPos - qreal(itemIndex) / items.count(), qreal(1.0)); if (targetOffset < 0) - targetOffset = 100.0 + targetOffset; + targetOffset = 1.0 + targetOffset; if (targetOffset == _offset && rounds == 0) return; @@ -1031,24 +1031,24 @@ void QDeclarativePathViewPrivate::snapToCurrent() if (rounds!=0){ //Compensate if the targetOffset would bring the target in from off the screen qreal distance = targetOffset - _offset; - if (distance <= -50) + if (distance <= -0.5) rounds--; - if (distance > 50) + if (distance > 0.5) rounds++; - tl.move(moveOffset, targetOffset + 100.0*(-rounds), QEasingCurve(QEasingCurve::InOutQuad), - int(100*items.count()*qMax((qreal)(2.0/items.count()),(qreal)qAbs(rounds)))); + tl.move(moveOffset, targetOffset -rounds, QEasingCurve(QEasingCurve::InOutQuad), + int(items.count()*qMax((qreal)(2.0/items.count()),(qreal)qAbs(rounds)))); tl.callback(QDeclarativeTimeLineCallback(&moveOffset, fixOffsetCallback, this)); return; } - if (targetOffset - _offset > 50.0) { - qreal distance = 100 - targetOffset + _offset; + if (targetOffset - _offset > 0.5) { + qreal distance = 1 - targetOffset + _offset; tl.move(moveOffset, 0.0, QEasingCurve(QEasingCurve::OutQuad), int(200 * _offset / distance)); - tl.set(moveOffset, 100.0); - tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::InQuad), int(200 * (100-targetOffset) / distance)); - } else if (targetOffset - _offset <= -50.0) { - qreal distance = 100 - _offset + targetOffset; - tl.move(moveOffset, 100.0, QEasingCurve(QEasingCurve::OutQuad), int(200 * (100-_offset) / distance)); + tl.set(moveOffset, 1.0); + tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::InQuad), int(200 * (1.0-targetOffset) / distance)); + } else if (targetOffset - _offset <= -0.5) { + qreal distance = 1 - _offset + targetOffset; + tl.move(moveOffset, 1.0, QEasingCurve(QEasingCurve::OutQuad), int(200 * (1.0-_offset) / distance)); tl.set(moveOffset, 0.0); tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::InQuad), int(200 * targetOffset / distance)); } else { diff --git a/src/declarative/graphicsitems/qdeclarativepathview_p_p.h b/src/declarative/graphicsitems/qdeclarativepathview_p_p.h index 4083ab5..62f7d95 100644 --- a/src/declarative/graphicsitems/qdeclarativepathview_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativepathview_p_p.h @@ -66,11 +66,6 @@ QT_BEGIN_NAMESPACE -typedef struct PathViewItem{ - int index; - QDeclarativeItem* item; -}PathViewItem; - class QDeclarativeOpenMetaObjectType; class QDeclarativePathViewAttached; class QDeclarativePathViewPrivate : public QDeclarativeItemPrivate diff --git a/src/declarative/graphicsitems/qdeclarativepositioners.cpp b/src/declarative/graphicsitems/qdeclarativepositioners.cpp index 1212e89..0f59a70 100644 --- a/src/declarative/graphicsitems/qdeclarativepositioners.cpp +++ b/src/declarative/graphicsitems/qdeclarativepositioners.cpp @@ -212,19 +212,22 @@ void QDeclarativeBasePositioner::prePositioning() QList<QGraphicsItem *> children = d->QGraphicsItemPrivate::children; qSort(children.begin(), children.end(), d->insertionOrder); + QPODVector<PositionedItem,8> oldItems; + positionedItems.copyAndClear(oldItems); for (int ii = 0; ii < children.count(); ++ii) { QDeclarativeItem *child = qobject_cast<QDeclarativeItem *>(children.at(ii)); if (!child) continue; PositionedItem *item = 0; PositionedItem posItem(child); - int wIdx = positionedItems.find(posItem); + int wIdx = oldItems.find(posItem); if (wIdx < 0) { d->watchChanges(child); positionedItems.append(posItem); item = &positionedItems[positionedItems.count()-1]; } else { - item = &positionedItems[wIdx]; + item = &oldItems[wIdx]; + positionedItems.append(*item); } if (child->opacity() <= 0.0 || !child->isVisible()) { item->isVisible = false; diff --git a/src/declarative/graphicsitems/qdeclarativerepeater.cpp b/src/declarative/graphicsitems/qdeclarativerepeater.cpp index e4cd499..b9696c8 100644 --- a/src/declarative/graphicsitems/qdeclarativerepeater.cpp +++ b/src/declarative/graphicsitems/qdeclarativerepeater.cpp @@ -296,6 +296,8 @@ void QDeclarativeRepeater::clear() void QDeclarativeRepeater::regenerate() { Q_D(QDeclarativeRepeater); + if (!isComponentComplete()) + return; clear(); @@ -312,23 +314,65 @@ void QDeclarativeRepeater::regenerate() } } -void QDeclarativeRepeater::itemsInserted(int, int) +void QDeclarativeRepeater::itemsInserted(int index, int count) { - regenerate(); + Q_D(QDeclarativeRepeater); + if (!isComponentComplete()) + return; + for (int i = 0; i < count; ++i) { + int modelIndex = index + i; + QDeclarativeItem *item = d->model->item(modelIndex); + if (item) { + item->setParent(parentItem()); + if (modelIndex < d->deletables.count()) + item->stackBefore(d->deletables.at(modelIndex)); + else + item->stackBefore(this); + d->deletables.insert(modelIndex, item); + } + } } -void QDeclarativeRepeater::itemsRemoved(int, int) +void QDeclarativeRepeater::itemsRemoved(int index, int count) { - regenerate(); + Q_D(QDeclarativeRepeater); + if (!isComponentComplete()) + return; + while (count--) { + QDeclarativeItem *item = d->deletables.takeAt(index); + if (item) { + item->setParentItem(this); + d->model->release(item); + } + } } -void QDeclarativeRepeater::itemsMoved(int,int,int) +void QDeclarativeRepeater::itemsMoved(int from, int to, int count) { - regenerate(); + Q_D(QDeclarativeRepeater); + if (!isComponentComplete()) + return; + QList<QDeclarativeItem*> removed; + int removedCount = count; + while (removedCount--) + removed << d->deletables.takeAt(from); + for (int i = 0; i < count; ++i) + d->deletables.insert(to + i, removed.at(i)); + for (int i = 0; i < d->model->count(); ++i) { + if (i < from && i < to) + continue; + QDeclarativeItem *item = d->deletables.at(i); + if (i < d->deletables.count()-1) + item->stackBefore(d->deletables.at(i+1)); + else + item->stackBefore(this); + } } void QDeclarativeRepeater::modelReset() { + if (!isComponentComplete()) + return; regenerate(); } diff --git a/src/declarative/graphicsitems/qdeclarativetextedit.cpp b/src/declarative/graphicsitems/qdeclarativetextedit.cpp index be73b39..dbae47d 100644 --- a/src/declarative/graphicsitems/qdeclarativetextedit.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextedit.cpp @@ -760,17 +760,11 @@ void QDeclarativeTextEdit::keyReleaseEvent(QKeyEvent *event) QDeclarativePaintedItem::keyReleaseEvent(event); } -/*! - \overload - Handles changing of the focus property. Focus is applied to the control - even if the edit does not have active focus. This is because things - like KeyProxy can give the behavior of focus even when hasFocus() isn't - true. -*/ -void QDeclarativeTextEdit::focusChanged(bool hasFocus) +void QDeclarativeTextEditPrivate::focusChanged(bool hasFocus) { - setCursorVisible(hasFocus); - QDeclarativeItem::focusChanged(hasFocus); + Q_Q(QDeclarativeTextEdit); + q->setCursorVisible(hasFocus); + QDeclarativeItemPrivate::focusChanged(hasFocus); } /*! diff --git a/src/declarative/graphicsitems/qdeclarativetextedit_p.h b/src/declarative/graphicsitems/qdeclarativetextedit_p.h index 6183b1d..b1682c4 100644 --- a/src/declarative/graphicsitems/qdeclarativetextedit_p.h +++ b/src/declarative/graphicsitems/qdeclarativetextedit_p.h @@ -215,8 +215,6 @@ protected: void keyPressEvent(QKeyEvent *); void keyReleaseEvent(QKeyEvent *); - void focusChanged(bool); - // mouse filter? void mousePressEvent(QGraphicsSceneMouseEvent *event); void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); diff --git a/src/declarative/graphicsitems/qdeclarativetextedit_p_p.h b/src/declarative/graphicsitems/qdeclarativetextedit_p_p.h index 002fac4..dd2a29d 100644 --- a/src/declarative/graphicsitems/qdeclarativetextedit_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativetextedit_p_p.h @@ -80,6 +80,7 @@ public: void updateDefaultTextOption(); void relayoutDocument(); void updateSelection(); + void focusChanged(bool); QString text; QFont font; diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp index 3382628..01167dc 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp @@ -636,12 +636,12 @@ int QDeclarativeTextInput::xToPos(int x) return d->control->xToPos(x - d->hscroll); } -void QDeclarativeTextInput::focusChanged(bool hasFocus) +void QDeclarativeTextInputPrivate::focusChanged(bool hasFocus) { - Q_D(QDeclarativeTextInput); - d->focused = hasFocus; - setCursorVisible(hasFocus); - QDeclarativeItem::focusChanged(hasFocus); + Q_Q(QDeclarativeTextInput); + focused = hasFocus; + q->setCursorVisible(hasFocus); + QDeclarativeItemPrivate::focusChanged(hasFocus); } void QDeclarativeTextInput::keyPressEvent(QKeyEvent* ev) @@ -834,6 +834,9 @@ void QDeclarativeTextInputPrivate::init() oldValidity = control->hasAcceptableInput(); lastSelectionStart = 0; lastSelectionEnd = 0; + QPalette p = control->palette(); + selectedTextColor = p.color(QPalette::HighlightedText); + selectionColor = p.color(QPalette::Highlight); } void QDeclarativeTextInput::cursorPosChanged() diff --git a/src/declarative/graphicsitems/qdeclarativetextinput_p.h b/src/declarative/graphicsitems/qdeclarativetextinput_p.h index f690ae2..6a61c2d 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput_p.h +++ b/src/declarative/graphicsitems/qdeclarativetextinput_p.h @@ -199,8 +199,6 @@ protected: void keyPressEvent(QKeyEvent* ev); bool event(QEvent *e); - void focusChanged(bool hasFocus); - public Q_SLOTS: void selectAll(); diff --git a/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h b/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h index 3d28f40..5d17a55 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h @@ -83,6 +83,7 @@ public: void init(); void startCreatingCursor(); + void focusChanged(bool hasFocus); QLineControl* control; diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp index 6bad4da..6341764 100644 --- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp @@ -196,7 +196,7 @@ QVariant QDeclarativeVisualItemModel::evaluate(int index, const QString &express return QVariant(); QDeclarativeContext *ccontext = qmlContext(this); QDeclarativeContext *ctxt = new QDeclarativeContext(ccontext); - ctxt->addDefaultObject(d->children.at(index)); + ctxt->setContextObject(d->children.at(index)); QDeclarativeExpression e(ctxt, expression, objectContext); QVariant value = e.value(); delete ctxt; @@ -991,7 +991,7 @@ QDeclarativeItem *QDeclarativeVisualDataModel::item(int index, const QByteArray QDeclarativeContext *ctxt = new QDeclarativeContext(ccontext); QDeclarativeVisualDataModelData *data = new QDeclarativeVisualDataModelData(index, this); ctxt->setContextProperty(QLatin1String("model"), data); - ctxt->addDefaultObject(data); + ctxt->setContextObject(data); nobj = d->m_delegate->beginCreate(ctxt); if (complete) d->m_delegate->completeCreate(); @@ -1104,7 +1104,7 @@ QVariant QDeclarativeVisualDataModel::evaluate(int index, const QString &express if (!ccontext) ccontext = qmlContext(this); QDeclarativeContext *ctxt = new QDeclarativeContext(ccontext); QDeclarativeVisualDataModelData *data = new QDeclarativeVisualDataModelData(index, this); - ctxt->addDefaultObject(data); + ctxt->setContextObject(data); QDeclarativeExpression e(ctxt, expression, objectContext); value = e.value(); delete data; |