From fc733f4573f1fe43e0cfe43734623d77f61a4614 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 28 Oct 2009 13:20:15 +1000 Subject: Ensure that the Follows handle the target value changing unexpectedly. If the target's property was changed elsewhere while the Follow wasn't running, it would fail to start when a source identical to its current source valule was set. --- src/declarative/util/qmleasefollow.cpp | 3 +-- src/declarative/util/qmlspringfollow.cpp | 9 +++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/declarative/util/qmleasefollow.cpp b/src/declarative/util/qmleasefollow.cpp index 99720f8..9d17d25 100644 --- a/src/declarative/util/qmleasefollow.cpp +++ b/src/declarative/util/qmleasefollow.cpp @@ -210,7 +210,6 @@ void QmlEaseFollowPrivate::tick(int t) qreal value = 0.5 * a * time_seconds * time_seconds + vi * time_seconds; value = (invert?-1.0:1.0) * value; target.write(initialValue + value); - out = initialValue + value; } else if (time_seconds < td) { @@ -397,7 +396,7 @@ void QmlEaseFollow::setSourceValue(qreal s) { Q_D(QmlEaseFollow); - if (d->source == s) + if (d->clock.state() == QAbstractAnimation::Running && d->source == s) return; d->source = s; diff --git a/src/declarative/util/qmlspringfollow.cpp b/src/declarative/util/qmlspringfollow.cpp index 34ec976..569cc48 100644 --- a/src/declarative/util/qmlspringfollow.cpp +++ b/src/declarative/util/qmlspringfollow.cpp @@ -272,10 +272,11 @@ qreal QmlSpringFollow::sourceValue() const void QmlSpringFollow::setSourceValue(qreal value) { Q_D(QmlSpringFollow); - if (d->sourceValue != value) { - d->sourceValue = value; - d->start(); - } + if (d->clock.state() == QAbstractAnimation::Running && d->sourceValue == value) + return; + + d->sourceValue = value; + d->start(); } /*! -- cgit v0.12 From 486eb1ccb91e239bf4440ec62c221e8af1ffddcc Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 28 Oct 2009 13:23:00 +1000 Subject: Mode improvement to strictly enforced highlight range movement. --- examples/declarative/listview/listview.qml | 1 + examples/declarative/parallax/ParallaxView.qml | 3 +- src/declarative/fx/qfxflickable.cpp | 26 ++++++--- src/declarative/fx/qfxlistview.cpp | 80 ++++++++++++++++++++++---- 4 files changed, 92 insertions(+), 18 deletions(-) diff --git a/examples/declarative/listview/listview.qml b/examples/declarative/listview/listview.qml index b614904..92acce1 100644 --- a/examples/declarative/listview/listview.qml +++ b/examples/declarative/listview/listview.qml @@ -72,5 +72,6 @@ Rectangle { preferredHighlightBegin: 125 preferredHighlightEnd: 125 highlightRangeMode: "StrictlyEnforceRange" + flickDeceleration: 1000 } } diff --git a/examples/declarative/parallax/ParallaxView.qml b/examples/declarative/parallax/ParallaxView.qml index bad9b85..50ab72c 100644 --- a/examples/declarative/parallax/ParallaxView.qml +++ b/examples/declarative/parallax/ParallaxView.qml @@ -25,7 +25,8 @@ Item { anchors.fill: parent model: VisualItemModel { id: visualModel } - highlight: Item { height: 1; width: 1} + highlight: Rectangle { height: 1; width: 1 } + highlightMoveSpeed: 2000 preferredHighlightBegin: 0 preferredHighlightEnd: 0 highlightRangeMode: "StrictlyEnforceRange" diff --git a/src/declarative/fx/qfxflickable.cpp b/src/declarative/fx/qfxflickable.cpp index 92e79dd..659193d 100644 --- a/src/declarative/fx/qfxflickable.cpp +++ b/src/declarative/fx/qfxflickable.cpp @@ -57,6 +57,8 @@ QT_BEGIN_NAMESPACE static const int DragThreshold = 8; static const int FlickThreshold = 20; +// Really slow flicks can be annoying. +static const int minimumFlickVelocity = 200; class QFxFlickableVisibleArea : public QObject { @@ -183,6 +185,8 @@ void QFxFlickablePrivate::flickX(qreal velocity) { Q_Q(QFxFlickable); qreal maxDistance = -1; + if (qAbs(velocity) < minimumFlickVelocity) // Minimum velocity to avoid annoyingly slow flicks. + velocity = velocity < 0 ? -minimumFlickVelocity : minimumFlickVelocity; // -ve velocity means list is moving up if (velocity > 0) { if (_moveX.value() < q->minXExtent()) @@ -686,8 +690,8 @@ void QFxFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event) if (rejectX) velocityX = 0; if (moved) { - q->viewportMoved(); q->movementStarting(); + q->viewportMoved(); } lastPos = event->pos(); @@ -707,15 +711,23 @@ void QFxFlickablePrivate::handleMouseReleaseEvent(QGraphicsSceneMouseEvent *even } vTime = timeline.time(); - if (qAbs(velocityY) > 10 && qAbs(event->pos().y() - pressPos.y()) > FlickThreshold) - flickY(velocityY); - else + if (qAbs(velocityY) > 10 && qAbs(event->pos().y() - pressPos.y()) > FlickThreshold) { + qreal velocity = velocityY; + if (qAbs(velocity) < minimumFlickVelocity) // Minimum velocity to avoid annoyingly slow flicks. + velocity = velocity < 0 ? -minimumFlickVelocity : minimumFlickVelocity; + flickY(velocity); + } else { fixupY(); + } - if (qAbs(velocityX) > 10 && qAbs(event->pos().x() - pressPos.x()) > FlickThreshold) - flickX(velocityX); - else + if (qAbs(velocityX) > 10 && qAbs(event->pos().x() - pressPos.x()) > FlickThreshold) { + qreal velocity = velocityX; + if (qAbs(velocity) < minimumFlickVelocity) // Minimum velocity to avoid annoyingly slow flicks. + velocity = velocity < 0 ? -minimumFlickVelocity : minimumFlickVelocity; + flickX(velocity); + } else { fixupX(); + } stealMouse = false; lastPosTime = QTime(); diff --git a/src/declarative/fx/qfxlistview.cpp b/src/declarative/fx/qfxlistview.cpp index fbb91b1..e970ddd 100644 --- a/src/declarative/fx/qfxlistview.cpp +++ b/src/declarative/fx/qfxlistview.cpp @@ -691,8 +691,7 @@ void QFxListViewPrivate::updateHighlight() { if ((!currentItem && highlight) || (currentItem && !highlight)) createHighlight(); - updateTrackedItem(); - if (currentItem && autoHighlight && highlight && !pressed && moveReason != QFxListViewPrivate::Mouse) { + if (currentItem && autoHighlight && highlight && !moving) { // auto-update highlight highlightPosAnimator->setSourceValue(currentItem->position()); highlightSizeAnimator->setSourceValue(currentItem->size()); @@ -704,6 +703,7 @@ void QFxListViewPrivate::updateHighlight() highlight->item->setHeight(currentItem->item->height()); } } + updateTrackedItem(); } void QFxListViewPrivate::updateSections() @@ -832,8 +832,10 @@ void QFxListViewPrivate::flickX(qreal velocity) { Q_Q(QFxListView); - if (!haveHighlightRange || highlightRange != QFxListView::StrictlyEnforceRange) + if (!haveHighlightRange || highlightRange != QFxListView::StrictlyEnforceRange) { QFxFlickablePrivate::flickX(velocity); + return; + } qreal maxDistance = -1; // -ve velocity means list is moving up @@ -855,19 +857,20 @@ void QFxListViewPrivate::flickX(qreal velocity) v = maxVelocity; } qreal accel = deceleration; - qreal maxAccel = (v * v) / (2.0f * maxDistance); + qreal v2 = v * v; + qreal maxAccel = v2 / (2.0f * maxDistance); if (maxAccel < accel) { // If we are not flicking to the end then attempt to stop exactly on an item boundary - qreal dist = (v * v) / accel / 2.0; + qreal dist = v2 / accel / 2.0; if (v > 0) dist = -dist; - dist = -_moveX.value() - snapPosAt(-_moveX.value() + dist + highlightRangeStart); + dist = -_moveX.value() - snapPosAt(-(_moveX.value() - highlightRangeStart) + dist) + highlightRangeStart; if (v < 0 && dist >= 0 || v > 0 && dist <= 0) { timeline.reset(_moveX); fixupX(); return; } - accel = (v * v) / (2.0f * qAbs(dist)); + accel = v2 / (2.0f * qAbs(dist)); } timeline.reset(_moveX); timeline.accel(_moveX, v, accel, maxDistance); @@ -885,7 +888,60 @@ void QFxListViewPrivate::flickX(qreal velocity) void QFxListViewPrivate::flickY(qreal velocity) { - QFxFlickablePrivate::flickY(velocity); + Q_Q(QFxListView); + + if (!haveHighlightRange || highlightRange != QFxListView::StrictlyEnforceRange) { + QFxFlickablePrivate::flickY(velocity); + return; + } + + qreal maxDistance = -1; + // -ve velocity means list is moving up + if (velocity > 0) { + if (_moveY.value() < q->minYExtent()) + maxDistance = qAbs(q->minYExtent() -_moveY.value() + (overShoot?30:0)); + flickTargetY = q->minYExtent(); + } else { + if (_moveY.value() > q->maxYExtent()) + maxDistance = qAbs(q->maxYExtent() - _moveY.value()) + (overShoot?30:0); + flickTargetY = q->maxYExtent(); + } + if (maxDistance > 0) { + qreal v = velocity; + if (maxVelocity != -1 && maxVelocity < qAbs(v)) { + if (v < 0) + v = -maxVelocity; + else + v = maxVelocity; + } + qreal accel = deceleration; + qreal v2 = v * v; + qreal maxAccel = v2 / (2.0f * maxDistance); + if (maxAccel < accel) { + // If we are not flicking to the end then attempt to stop exactly on an item boundary + qreal dist = v2 / accel / 2.0; + if (v > 0) + dist = -dist; + dist = -_moveY.value() - snapPosAt(-(_moveY.value() - highlightRangeStart) + dist) + highlightRangeStart; + if (v < 0 && dist >= 0 || v > 0 && dist <= 0) { + timeline.reset(_moveY); + fixupY(); + return; + } + accel = v2 / (2.0f * qAbs(dist)); + } + timeline.reset(_moveY); + timeline.accel(_moveY, v, accel, maxDistance); + timeline.execute(fixupYEvent); + if (!flicked) { + flicked = true; + emit q->flickingChanged(); + emit q->flickStarted(); + } + } else { + timeline.reset(_moveY); + fixupY(); + } } //---------------------------------------------------------------------------- @@ -1185,6 +1241,10 @@ void QFxListView::setHighlight(QmlComponent *highlight) \snippet doc/src/snippets/declarative/listview/highlight.qml 1 + Note that the highlight animation also affects the way that the view + is scrolled. This is because the view moves to maintain the + highlight within the preferred highlight range (or visible viewport). + \sa highlight */ bool QFxListView::highlightFollowsCurrentItem() const @@ -1445,7 +1505,7 @@ void QFxListView::viewportMoved() Q_D(QFxListView); QFxFlickable::viewportMoved(); refill(); - if (isFlicking() || d->pressed) + if (isFlicking() || d->moving) d->moveReason = QFxListViewPrivate::Mouse; if (d->moveReason == QFxListViewPrivate::Mouse) { if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange && d->highlight) { @@ -1606,7 +1666,7 @@ void QFxListView::trackedPositionChanged() Q_D(QFxListView); if (!d->trackedItem) return; - if (!isFlicking() && !d->pressed && d->moveReason != QFxListViewPrivate::Mouse) { + if (!isFlicking() && !d->moving && d->moveReason != QFxListViewPrivate::Mouse) { const qreal trackedPos = d->trackedItem->position(); if (d->haveHighlightRange) { if (d->highlightRange == StrictlyEnforceRange) { -- cgit v0.12 From 6be1b102d27610e7d4417222eb4b4dd80d453295 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Wed, 28 Oct 2009 14:21:53 +1000 Subject: Fix bug where repeater would add spacing for 0 sized children --- src/declarative/fx/qfxpositioners.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/declarative/fx/qfxpositioners.cpp b/src/declarative/fx/qfxpositioners.cpp index f8e7213..cc385e0 100644 --- a/src/declarative/fx/qfxpositioners.cpp +++ b/src/declarative/fx/qfxpositioners.cpp @@ -659,8 +659,10 @@ void QFxRow::doPositioning() child->setX(hoffset); setMovingItem(0); } - hoffset += child->width(); - hoffset += spacing(); + if(!child->width() || !child->height()){//don't advance for invisible children + hoffset += child->width(); + hoffset += spacing(); + } } } -- cgit v0.12 From 97fe32132f1e55fddca464404f06ab70d81c56d8 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 28 Oct 2009 14:24:19 +1000 Subject: Doc --- doc/src/declarative/globalobject.qdoc | 26 ++++++++++++++++++++++++++ src/declarative/fx/qfxitem.cpp | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/doc/src/declarative/globalobject.qdoc b/doc/src/declarative/globalobject.qdoc index 2328c8a..afbe3db 100644 --- a/doc/src/declarative/globalobject.qdoc +++ b/doc/src/declarative/globalobject.qdoc @@ -56,6 +56,32 @@ Contains all the properties of the ECMAScript global object, plus: \section1 Qt Object +The Qt object contains functions for + +creating types: +\list +\o hsla +\o rgba +\o rect +\o point +\o size +\o vector3d +\endlist + +manipulating color: +\list +\o lighter +\o darker +\o tint +\endlist + +and playing sound: +\list +\o playSound +\endlist + +It also contains enum values used by some items. + \section1 Asynchronous JavaScript and XML \section1 Offline Storage API diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp index e714494..7d60336 100644 --- a/src/declarative/fx/qfxitem.cpp +++ b/src/declarative/fx/qfxitem.cpp @@ -1199,7 +1199,7 @@ QFxKeysAttached *QFxKeysAttached::qmlAttachedProperties(QObject *obj) /*! \class QFxItem - \brief QFxItem is the most basic of all visual items in QML. + \brief The QFxItem class provides the most basic of all visual items in QML. All visual items in Qt Declarative inherit from QFxItem. Although QFxItem has no visual appearance, it defines all the properties that are -- cgit v0.12