diff options
author | Martin Jones <martin.jones@nokia.com> | 2009-08-28 06:42:02 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2009-08-28 06:42:02 (GMT) |
commit | 67ca33d53ff805ca33ba775524086a89cb975df9 (patch) | |
tree | 04e02fc9a2ac0c6832c5189022b49a3419d9d762 /src/declarative | |
parent | d7400c910765bcbff6927143c348c771310b9d44 (diff) | |
download | Qt-67ca33d53ff805ca33ba775524086a89cb975df9.zip Qt-67ca33d53ff805ca33ba775524086a89cb975df9.tar.gz Qt-67ca33d53ff805ca33ba775524086a89cb975df9.tar.bz2 |
Make a number of Flickable API changes following review.
Diffstat (limited to 'src/declarative')
-rw-r--r-- | src/declarative/QmlChanges.txt | 5 | ||||
-rw-r--r-- | src/declarative/fx/qfxflickable.cpp | 98 | ||||
-rw-r--r-- | src/declarative/fx/qfxflickable.h | 55 | ||||
-rw-r--r-- | src/declarative/fx/qfxflickable_p.h | 12 | ||||
-rw-r--r-- | src/declarative/fx/qfxgridview.cpp | 6 | ||||
-rw-r--r-- | src/declarative/fx/qfxlistview.cpp | 6 |
6 files changed, 96 insertions, 86 deletions
diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt index e01b9af..e760037 100644 --- a/src/declarative/QmlChanges.txt +++ b/src/declarative/QmlChanges.txt @@ -42,6 +42,11 @@ Transition: operations -> animations Transition: fromState -> from Transition: toState -> to Follow: followValue -> value +Flickable: xPosition -> viewportX +Flickable: yPosition -> viewportY +Flickable: xVelocity -> horizontalVelocity +Flickable: yVelocity -> verticalVelocity +Flickable: velocityDecay -> reportedVelocitySmoothing Additions: MouseRegion: add "acceptedButtons" property diff --git a/src/declarative/fx/qfxflickable.cpp b/src/declarative/fx/qfxflickable.cpp index ea38026..07df799 100644 --- a/src/declarative/fx/qfxflickable.cpp +++ b/src/declarative/fx/qfxflickable.cpp @@ -96,7 +96,7 @@ QFxFlickablePrivate::QFxFlickablePrivate() : _flick(new QFxItem), _moveX(_flick, &QFxItem::setX), _moveY(_flick, &QFxItem::setY) , vWidth(-1), vHeight(-1), overShoot(true), flicked(false), moving(false), stealMouse(false) , pressed(false), maxVelocity(-1), locked(false), dragMode(QFxFlickable::Hard) - , elasticY(_moveY), elasticX(_moveX), velocityDecay(100), xVelocity(this), yVelocity(this) + , elasticY(_moveY), elasticX(_moveX), reportedVelocitySmoothing(100), horizontalVelocity(this), verticalVelocity(this) , vTime(0), atXEnd(false), atXBeginning(true), pageXPosition(0.), pageWidth(0.) , atYEnd(false), atYBeginning(true), pageYPosition(0.), pageHeight(0.) { @@ -112,8 +112,8 @@ void QFxFlickablePrivate::init() QObject::connect(&_tl, SIGNAL(completed()), q, SLOT(movementEnding())); q->setAcceptedMouseButtons(Qt::LeftButton); q->setFiltersChildEvents(true); - QObject::connect(_flick, SIGNAL(xChanged()), q, SIGNAL(positionChanged())); - QObject::connect(_flick, SIGNAL(yChanged()), q, SIGNAL(positionChanged())); + QObject::connect(_flick, SIGNAL(xChanged()), q, SIGNAL(positionXChanged())); + QObject::connect(_flick, SIGNAL(yChanged()), q, SIGNAL(positionYChanged())); QObject::connect(&elasticX, SIGNAL(updated()), q, SLOT(ticked())); QObject::connect(&elasticY, SIGNAL(updated()), q, SLOT(ticked())); QObject::connect(q, SIGNAL(heightChanged()), q, SLOT(heightChange())); @@ -369,20 +369,20 @@ QFxFlickable::~QFxFlickable() } /*! - \qmlproperty int Flickable::xPosition - \qmlproperty int Flickable::yPosition + \qmlproperty int Flickable::viewportX + \qmlproperty int Flickable::viewportY These properties hold the surface coordinate currently at the top-left corner of the Flickable. For example, if you flick an image up 100 pixels, \c yPosition will be 100. */ -qreal QFxFlickable::xPosition() const +qreal QFxFlickable::viewportX() const { Q_D(const QFxFlickable); return -d->_moveX.value(); } -void QFxFlickable::setXPosition(qreal pos) +void QFxFlickable::setViewportX(qreal pos) { Q_D(QFxFlickable); pos = qRound(pos); @@ -393,13 +393,13 @@ void QFxFlickable::setXPosition(qreal pos) } } -qreal QFxFlickable::yPosition() const +qreal QFxFlickable::viewportY() const { Q_D(const QFxFlickable); return -d->_moveY.value(); } -void QFxFlickable::setYPosition(qreal pos) +void QFxFlickable::setViewportY(qreal pos) { Q_D(QFxFlickable); pos = qRound(pos); @@ -454,21 +454,25 @@ void QFxFlickable::setDragMode(DragMode mode) } /*! - \qmlproperty real Flickable::xVelocity - \qmlproperty real Flickable::yVelocity + \qmlproperty real Flickable::horizontalVelocity + \qmlproperty real Flickable::verticalVelocity + \qmlproperty real Flickable::reportedVelocitySmoothing The instantaneous velocity of movement along the x and y axes, in pixels/sec. + + The reported velocity is smoothed to avoid erratic output. + reportedVelocitySmoothing determines how much smoothing is applied. */ -qreal QFxFlickable::xVelocity() const +qreal QFxFlickable::horizontalVelocity() const { Q_D(const QFxFlickable); - return d->xVelocity.value(); + return d->horizontalVelocity.value(); } -qreal QFxFlickable::yVelocity() const +qreal QFxFlickable::verticalVelocity() const { Q_D(const QFxFlickable); - return d->yVelocity.value(); + return d->verticalVelocity.value(); } /*! @@ -760,18 +764,18 @@ void QFxFlickable::viewportMoved() qreal prevX = d->lastFlickablePosition.y(); d->velocityTimeline.clear(); if (d->pressed) { - qreal xVelocity = (prevX - d->_moveX.value()) * 1000 / elapsed; - qreal yVelocity = (prevY - d->_moveY.value()) * 1000 / elapsed; - d->velocityTimeline.move(d->xVelocity, xVelocity, d->velocityDecay); - d->velocityTimeline.move(d->xVelocity, 0, d->velocityDecay); - d->velocityTimeline.move(d->yVelocity, yVelocity, d->velocityDecay); - d->velocityTimeline.move(d->yVelocity, 0, d->velocityDecay); + qreal horizontalVelocity = (prevX - d->_moveX.value()) * 1000 / elapsed; + qreal verticalVelocity = (prevY - d->_moveY.value()) * 1000 / elapsed; + d->velocityTimeline.move(d->horizontalVelocity, horizontalVelocity, d->reportedVelocitySmoothing); + d->velocityTimeline.move(d->horizontalVelocity, 0, d->reportedVelocitySmoothing); + d->velocityTimeline.move(d->verticalVelocity, verticalVelocity, d->reportedVelocitySmoothing); + d->velocityTimeline.move(d->verticalVelocity, 0, d->reportedVelocitySmoothing); } else { if (d->_tl.time() != d->vTime) { - qreal xVelocity = (prevX - d->_moveX.value()) * 1000 / (d->_tl.time() - d->vTime); - qreal yVelocity = (prevY - d->_moveY.value()) * 1000 / (d->_tl.time() - d->vTime); - d->xVelocity.setValue(xVelocity); - d->yVelocity.setValue(yVelocity); + qreal horizontalVelocity = (prevX - d->_moveX.value()) * 1000 / (d->_tl.time() - d->vTime); + qreal verticalVelocity = (prevY - d->_moveY.value()) * 1000 / (d->_tl.time() - d->vTime); + d->horizontalVelocity.setValue(horizontalVelocity); + d->verticalVelocity.setValue(verticalVelocity); } d->vTime = d->_tl.time(); } @@ -787,21 +791,21 @@ void QFxFlickable::viewportMoved() if (d->velocityY > 0) { const qreal minY = minYExtent(); if (minY - d->_moveY.value() < height()/3 && minY != d->flickTargetY) - d->flickY(-d->yVelocity.value()); + d->flickY(-d->verticalVelocity.value()); } else { const qreal maxY = maxYExtent(); if (d->_moveY.value() - maxY < height()/3 && maxY != d->flickTargetY) - d->flickY(-d->yVelocity.value()); + d->flickY(-d->verticalVelocity.value()); } if (d->velocityX > 0) { const qreal minX = minXExtent(); if (minX - d->_moveX.value() < height()/3 && minX != d->flickTargetX) - d->flickX(-d->xVelocity.value()); + d->flickX(-d->horizontalVelocity.value()); } else { const qreal maxX = maxXExtent(); if (d->_moveX.value() - maxX < height()/3 && maxX != d->flickTargetX) - d->flickX(-d->xVelocity.value()); + d->flickX(-d->horizontalVelocity.value()); } } } @@ -892,13 +896,13 @@ void QFxFlickable::setOverShoot(bool o) } \endcode */ -int QFxFlickable::viewportWidth() const +qreal QFxFlickable::viewportWidth() const { Q_D(const QFxFlickable); return d->vWidth; } -void QFxFlickable::setViewportWidth(int w) +void QFxFlickable::setViewportWidth(qreal w) { Q_D(QFxFlickable); if (d->vWidth == w) @@ -935,13 +939,13 @@ void QFxFlickable::heightChange() } } -int QFxFlickable::viewportHeight() const +qreal QFxFlickable::viewportHeight() const { Q_D(const QFxFlickable); return d->vHeight; } -void QFxFlickable::setViewportHeight(int h) +void QFxFlickable::setViewportHeight(qreal h) { Q_D(QFxFlickable); if (d->vHeight == h) @@ -958,7 +962,7 @@ void QFxFlickable::setViewportHeight(int h) d->updateBeginningEnd(); } -int QFxFlickable::vWidth() const +qreal QFxFlickable::vWidth() const { Q_D(const QFxFlickable); if (d->vWidth < 0) @@ -967,7 +971,7 @@ int QFxFlickable::vWidth() const return d->vWidth; } -int QFxFlickable::vHeight() const +qreal QFxFlickable::vHeight() const { Q_D(const QFxFlickable); if (d->vHeight < 0) @@ -1049,15 +1053,15 @@ bool QFxFlickable::sceneEventFilter(QGraphicsItem *i, QEvent *e) /*! \qmlproperty int Flickable::maximumFlickVelocity - This property holds the maximum velocity that the user can flick the view. + This property holds the maximum velocity that the user can flick the view in pixels/second. */ -int QFxFlickable::maximumFlickVelocity() const +qreal QFxFlickable::maximumFlickVelocity() const { Q_D(const QFxFlickable); return d->maxVelocity; } -void QFxFlickable::setMaximumFlickVelocity(int v) +void QFxFlickable::setMaximumFlickVelocity(qreal v) { Q_D(QFxFlickable); if (v == d->maxVelocity) @@ -1071,20 +1075,20 @@ bool QFxFlickable::isFlicking() const return d->flicked; } -int QFxFlickable::velocityDecay() const +qreal QFxFlickable::reportedVelocitySmoothing() const { Q_D(const QFxFlickable); - return d->velocityDecay; + return d->reportedVelocitySmoothing; } -void QFxFlickable::setVelocityDecay(int decay) +void QFxFlickable::setReportedVelocitySmoothing(qreal reportedVelocitySmoothing) { Q_D(QFxFlickable); - Q_ASSERT(decay >= 0); - if (decay == d->velocityDecay) + Q_ASSERT(reportedVelocitySmoothing >= 0); + if (reportedVelocitySmoothing == d->reportedVelocitySmoothing) return; - d->velocityDecay = decay; - emit velocityDecayChanged(decay); + d->reportedVelocitySmoothing = reportedVelocitySmoothing; + emit reportedVelocitySmoothingChanged(reportedVelocitySmoothing); } bool QFxFlickable::isMoving() const @@ -1116,13 +1120,13 @@ void QFxFlickable::movementEnding() emit flickingChanged(); emit flickEnded(); } - d->xVelocity.setValue(0); + d->horizontalVelocity.setValue(0); } void QFxFlickablePrivate::updateVelocity() { Q_Q(QFxFlickable); - emit q->velocityChanged(q->xVelocity(), q->yVelocity()); + emit q->velocityChanged(q->horizontalVelocity(), q->verticalVelocity()); } QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxflickable.h b/src/declarative/fx/qfxflickable.h index 13d793f..c27b29f 100644 --- a/src/declarative/fx/qfxflickable.h +++ b/src/declarative/fx/qfxflickable.h @@ -55,17 +55,17 @@ class Q_DECLARATIVE_EXPORT QFxFlickable : public QFxItem { Q_OBJECT - Q_PROPERTY(bool overShoot READ overShoot WRITE setOverShoot) - Q_PROPERTY(int viewportWidth READ viewportWidth WRITE setViewportWidth NOTIFY viewportWidthChanged) //### qreal - Q_PROPERTY(int viewportHeight READ viewportHeight WRITE setViewportHeight NOTIFY viewportHeightChanged) - Q_PROPERTY(qreal xPosition READ xPosition WRITE setXPosition NOTIFY positionChanged) //### viewportX, positionXChannged - Q_PROPERTY(qreal yPosition READ yPosition WRITE setYPosition NOTIFY positionChanged) //### ^^^ + Q_PROPERTY(qreal viewportWidth READ viewportWidth WRITE setViewportWidth NOTIFY viewportWidthChanged) + Q_PROPERTY(qreal viewportHeight READ viewportHeight WRITE setViewportHeight NOTIFY viewportHeightChanged) + Q_PROPERTY(qreal viewportX READ viewportX WRITE setViewportX NOTIFY positionXChanged) + Q_PROPERTY(qreal viewportY READ viewportY WRITE setViewportY NOTIFY positionYChanged) - Q_PROPERTY(int velocityDecay READ velocityDecay WRITE setVelocityDecay NOTIFY velocityDecayChanged) //### qreal deceleration - Q_PROPERTY(int maximumFlickVelocity READ maximumFlickVelocity WRITE setMaximumFlickVelocity) ///### qreal, use same units as follow (pixels/s) + Q_PROPERTY(qreal horizontalVelocity READ horizontalVelocity NOTIFY horizontalVelocityChanged) + Q_PROPERTY(qreal verticalVelocity READ verticalVelocity NOTIFY verticalVelocityChanged) + Q_PROPERTY(qreal reportedVelocitySmoothing READ reportedVelocitySmoothing WRITE setReportedVelocitySmoothing NOTIFY reportedVelocitySmoothingChanged) - Q_PROPERTY(qreal xVelocity READ xVelocity NOTIFY velocityChanged) //### horizontalVelocity - Q_PROPERTY(qreal yVelocity READ yVelocity NOTIFY velocityChanged) //### verticalVelocity + Q_PROPERTY(bool overShoot READ overShoot WRITE setOverShoot) + Q_PROPERTY(qreal maximumFlickVelocity READ maximumFlickVelocity WRITE setMaximumFlickVelocity) Q_PROPERTY(bool moving READ isMoving NOTIFY movingChanged) Q_PROPERTY(bool flicking READ isFlicking NOTIFY flickingChanged) @@ -96,26 +96,26 @@ public: bool overShoot() const; void setOverShoot(bool); - int viewportWidth() const; - void setViewportWidth(int); + qreal viewportWidth() const; + void setViewportWidth(qreal); - int viewportHeight() const; - void setViewportHeight(int); + qreal viewportHeight() const; + void setViewportHeight(qreal); - qreal xPosition() const; - void setXPosition(qreal pos); + qreal viewportX() const; + void setViewportX(qreal pos); - qreal yPosition() const; - void setYPosition(qreal pos); + qreal viewportY() const; + void setViewportY(qreal pos); bool isMoving() const; bool isFlicking() const; - int velocityDecay() const; - void setVelocityDecay(int); + qreal reportedVelocitySmoothing() const; + void setReportedVelocitySmoothing(qreal); - int maximumFlickVelocity() const; - void setMaximumFlickVelocity(int); + qreal maximumFlickVelocity() const; + void setMaximumFlickVelocity(qreal); bool isLocked() const; void setLocked(bool); @@ -125,8 +125,8 @@ public: DragMode dragMode() const; void setDragMode(DragMode mode); - qreal xVelocity() const; - qreal yVelocity() const; + qreal horizontalVelocity() const; + qreal verticalVelocity() const; bool isAtXEnd() const; bool isAtXBeginning() const; @@ -143,14 +143,15 @@ public: Q_SIGNALS: void viewportWidthChanged(); void viewportHeightChanged(); - void positionChanged(); + void positionXChanged(); + void positionYChanged(); void movingChanged(); void flickingChanged(); void movementStarted(); void movementEnded(); void flickStarted(); void flickEnded(); - void velocityDecayChanged(int); + void reportedVelocitySmoothingChanged(int); void velocityChanged(qreal, qreal); void isAtBoundaryChanged(); void pageChanged(); @@ -176,8 +177,8 @@ protected: virtual qreal minYExtent() const; virtual qreal maxXExtent() const; virtual qreal maxYExtent() const; - int vWidth() const; - int vHeight() const; + qreal vWidth() const; + qreal vHeight() const; virtual void viewportMoved(); bool sendMouseEvent(QGraphicsSceneMouseEvent *event); diff --git a/src/declarative/fx/qfxflickable_p.h b/src/declarative/fx/qfxflickable_p.h index 00d5423..a0ac011 100644 --- a/src/declarative/fx/qfxflickable_p.h +++ b/src/declarative/fx/qfxflickable_p.h @@ -103,8 +103,8 @@ public: QmlTimeLineValueProxy<QFxItem> _moveX; QmlTimeLineValueProxy<QFxItem> _moveY; QmlTimeLine _tl; - int vWidth; - int vHeight; + qreal vWidth; + qreal vHeight; bool overShoot; bool flicked; bool moving; @@ -120,14 +120,14 @@ public: QTime pressTime; QmlTimeLineEvent fixupXEvent; QmlTimeLineEvent fixupYEvent; - int maxVelocity; + qreal maxVelocity; bool locked; QFxFlickable::DragMode dragMode; ElasticValue elasticY; ElasticValue elasticX; QTime velocityTime; QPointF lastFlickablePosition; - int velocityDecay; + qreal reportedVelocitySmoothing; int flickTargetX; int flickTargetY; @@ -142,8 +142,8 @@ public: } QFxFlickablePrivate *parent; }; - Velocity xVelocity; - Velocity yVelocity; + Velocity horizontalVelocity; + Velocity verticalVelocity; int vTime; QmlTimeLine velocityTimeline; bool atXEnd; diff --git a/src/declarative/fx/qfxgridview.cpp b/src/declarative/fx/qfxgridview.cpp index bf6e863..138a8ae 100644 --- a/src/declarative/fx/qfxgridview.cpp +++ b/src/declarative/fx/qfxgridview.cpp @@ -185,14 +185,14 @@ public: qreal position() const { Q_Q(const QFxGridView); - return flow == QFxGridView::LeftToRight ? q->yPosition() : q->xPosition(); + return flow == QFxGridView::LeftToRight ? q->viewportY() : q->viewportX(); } void setPosition(qreal pos) { Q_Q(QFxGridView); if (flow == QFxGridView::LeftToRight) - q->setYPosition(pos); + q->setViewportY(pos); else - q->setXPosition(pos); + q->setViewportX(pos); } int size() const { Q_Q(const QFxGridView); diff --git a/src/declarative/fx/qfxlistview.cpp b/src/declarative/fx/qfxlistview.cpp index c1e03dd..147c977 100644 --- a/src/declarative/fx/qfxlistview.cpp +++ b/src/declarative/fx/qfxlistview.cpp @@ -196,14 +196,14 @@ public: qreal position() const { Q_Q(const QFxListView); - return orient == Qt::Vertical ? q->yPosition() : q->xPosition(); + return orient == Qt::Vertical ? q->viewportY() : q->viewportX(); } void setPosition(qreal pos) { Q_Q(QFxListView); if (orient == Qt::Vertical) - q->setYPosition(pos); + q->setViewportY(pos); else - q->setXPosition(pos); + q->setViewportX(pos); } int size() const { Q_Q(const QFxListView); |