diff options
author | Martin Jones <martin.jones@nokia.com> | 2009-09-03 02:45:38 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2009-09-03 02:45:38 (GMT) |
commit | 844fdfe196885e4554e77c37ff4680f2bdd5c36e (patch) | |
tree | d3731522288e2b7f2fa7615beb189cce1bd79ea1 /src/declarative | |
parent | c7f516b14aaffaadfdcfd31feded7119be6bf1ec (diff) | |
download | Qt-844fdfe196885e4554e77c37ff4680f2bdd5c36e.zip Qt-844fdfe196885e4554e77c37ff4680f2bdd5c36e.tar.gz Qt-844fdfe196885e4554e77c37ff4680f2bdd5c36e.tar.bz2 |
Remove dragMode property from Flickable.
Diffstat (limited to 'src/declarative')
-rw-r--r-- | src/declarative/QmlChanges.txt | 1 | ||||
-rw-r--r-- | src/declarative/fx/qfxflickable.cpp | 182 | ||||
-rw-r--r-- | src/declarative/fx/qfxflickable.h | 6 | ||||
-rw-r--r-- | src/declarative/fx/qfxflickable_p.h | 50 | ||||
-rw-r--r-- | src/declarative/fx/qfxlistview.cpp | 18 |
5 files changed, 71 insertions, 186 deletions
diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt index 98eb660..b24f6fe 100644 --- a/src/declarative/QmlChanges.txt +++ b/src/declarative/QmlChanges.txt @@ -71,6 +71,7 @@ Column/VerticalPositioner: lost "margins" property Row/HorizontalPositioner: lost "margins" property Grid/Positioner/Layout: lost "margins" property WebView: lost "interactive" property (always true now) +Flickable: removed "dragMode" property Other Changes: Drag: axis becomes an enum with values "XAxis", "YAxis", "XandYAxis" diff --git a/src/declarative/fx/qfxflickable.cpp b/src/declarative/fx/qfxflickable.cpp index 16c7fff..0ea50b8 100644 --- a/src/declarative/fx/qfxflickable.cpp +++ b/src/declarative/fx/qfxflickable.cpp @@ -48,51 +48,6 @@ QT_BEGIN_NAMESPACE -ElasticValue::ElasticValue(QmlTimeLineValue &val) - : _value(val) -{ - _to = _value.value(); - _myValue = _to; - _velocity = 0; -} - -void ElasticValue::setValue(qreal to) -{ - if (_to != to) { - _to = to; - _startTime.start(); - if (state() != Running) - start(); - } -} - -void ElasticValue::clear() -{ - stop(); - _velocity = 0.0; - _myValue = _value.value(); -} - -void ElasticValue::updateCurrentTime(int) -{ - const qreal Tension = 0.1; - int elapsed = _startTime.restart(); - if (!elapsed) - return; - qreal dist = _to - _value.value(); - qreal move = Tension * dist * qAbs(dist); - if (elapsed < 100 && _velocity != 0.0) - move = (elapsed * move + (100 - elapsed) * _velocity) / 100; - _myValue += move * elapsed / 1000; - _value.setValue(qRound(_myValue)); // moving sub-pixel can be ugly. -// _value.setValue(_myValue); - _velocity = move; - if (qAbs(_velocity) < 5.0) - clear(); - emit updated(); -} - - class QFxFlickableVisibleArea : public QObject { Q_OBJECT @@ -189,11 +144,11 @@ void QFxFlickableVisibleArea::updateVisible() QFxFlickablePrivate::QFxFlickablePrivate() - : _flick(new QFxItem), _moveX(_flick, &QFxItem::setX), _moveY(_flick, &QFxItem::setY) + : viewport(new QFxItem), _moveX(viewport, &QFxItem::setX), _moveY(viewport, &QFxItem::setY) , vWidth(-1), vHeight(-1), overShoot(true), flicked(false), moving(false), stealMouse(false) - , pressed(false), maxVelocity(-1), interactive(true), dragMode(QFxFlickable::Hard) - , elasticY(_moveY), elasticX(_moveX), reportedVelocitySmoothing(100), horizontalVelocity(this), verticalVelocity(this) - , vTime(0), atXEnd(false), atXBeginning(true), atYEnd(false), atYBeginning(true), visibleArea(0) + , pressed(false), atXEnd(false), atXBeginning(true), atYEnd(false), atYBeginning(true) + , interactive(true), maxVelocity(-1), reportedVelocitySmoothing(100) + , horizontalVelocity(this), verticalVelocity(this), vTime(0), visibleArea(0) { fixupXEvent = QmlTimeLineEvent::timeLineEvent<QFxFlickablePrivate, &QFxFlickablePrivate::fixupX>(&_moveX, this); fixupYEvent = QmlTimeLineEvent::timeLineEvent<QFxFlickablePrivate, &QFxFlickablePrivate::fixupY>(&_moveY, this); @@ -202,15 +157,13 @@ QFxFlickablePrivate::QFxFlickablePrivate() void QFxFlickablePrivate::init() { Q_Q(QFxFlickable); - _flick->setParent(q); - QObject::connect(&_tl, SIGNAL(updated()), q, SLOT(ticked())); - QObject::connect(&_tl, SIGNAL(completed()), q, SLOT(movementEnding())); + viewport->setParent(q); + QObject::connect(&timeline, SIGNAL(updated()), q, SLOT(ticked())); + QObject::connect(&timeline, SIGNAL(completed()), q, SLOT(movementEnding())); q->setAcceptedMouseButtons(Qt::LeftButton); q->setFiltersChildEvents(true); - 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(viewport, SIGNAL(xChanged()), q, SIGNAL(positionXChanged())); + QObject::connect(viewport, SIGNAL(yChanged()), q, SIGNAL(positionYChanged())); QObject::connect(q, SIGNAL(heightChanged()), q, SLOT(heightChange())); QObject::connect(q, SIGNAL(widthChanged()), q, SLOT(widthChange())); } @@ -237,16 +190,16 @@ void QFxFlickablePrivate::flickX(qreal velocity) else v = maxVelocity; } - _tl.reset(_moveX); - _tl.accel(_moveX, v, 500, maxDistance); - _tl.execute(fixupXEvent); + timeline.reset(_moveX); + timeline.accel(_moveX, v, 500, maxDistance); + timeline.execute(fixupXEvent); if (!flicked) { flicked = true; emit q->flickingChanged(); emit q->flickStarted(); } } else { - _tl.reset(_moveX); + timeline.reset(_moveX); fixupX(); } } @@ -273,16 +226,16 @@ void QFxFlickablePrivate::flickY(qreal velocity) else v = maxVelocity; } - _tl.reset(_moveY); - _tl.accel(_moveY, v, 500, maxDistance); - _tl.execute(fixupYEvent); + timeline.reset(_moveY); + timeline.accel(_moveY, v, 500, maxDistance); + timeline.execute(fixupYEvent); if (!flicked) { flicked = true; emit q->flickingChanged(); emit q->flickStarted(); } } else { - _tl.reset(_moveY); + timeline.reset(_moveY); fixupY(); } } @@ -293,16 +246,16 @@ void QFxFlickablePrivate::fixupX() if (!q->xflick() || _moveX.timeLine()) return; - vTime = _tl.time(); + vTime = timeline.time(); if (_moveX.value() > q->minXExtent() || (q->maxXExtent() > q->minXExtent())) { - _tl.reset(_moveX); + timeline.reset(_moveX); if (_moveX.value() != q->minXExtent()) - _tl.move(_moveX, q->minXExtent(), QEasingCurve(QEasingCurve::InOutQuad), 200); + timeline.move(_moveX, q->minXExtent(), QEasingCurve(QEasingCurve::InOutQuad), 200); //emit flickingChanged(); } else if (_moveX.value() < q->maxXExtent()) { - _tl.reset(_moveX); - _tl.move(_moveX, q->maxXExtent(), QEasingCurve(QEasingCurve::InOutQuad), 200); + timeline.reset(_moveX); + timeline.move(_moveX, q->maxXExtent(), QEasingCurve(QEasingCurve::InOutQuad), 200); //emit flickingChanged(); } else { flicked = false; @@ -315,16 +268,16 @@ void QFxFlickablePrivate::fixupY() if (!q->yflick() || _moveY.timeLine()) return; - vTime = _tl.time(); + vTime = timeline.time(); if (_moveY.value() > q->minYExtent() || (q->maxYExtent() > q->minYExtent())) { - _tl.reset(_moveY); + timeline.reset(_moveY); if (_moveY.value() != q->minYExtent()) - _tl.move(_moveY, q->minYExtent(), QEasingCurve(QEasingCurve::InOutQuad), 200); + timeline.move(_moveY, q->minYExtent(), QEasingCurve(QEasingCurve::InOutQuad), 200); //emit flickingChanged(); } else if (_moveY.value() < q->maxYExtent()) { - _tl.reset(_moveY); - _tl.move(_moveY, q->maxYExtent(), QEasingCurve(QEasingCurve::InOutQuad), 200); + timeline.reset(_moveY); + timeline.move(_moveY, q->maxYExtent(), QEasingCurve(QEasingCurve::InOutQuad), 200); //emit flickingChanged(); } else { flicked = false; @@ -481,7 +434,7 @@ void QFxFlickable::setViewportX(qreal pos) Q_D(QFxFlickable); pos = qRound(pos); if (-pos != d->_moveX.value()) { - d->_tl.reset(d->_moveX); + d->timeline.reset(d->_moveX); d->_moveX.setValue(-pos); viewportMoved(); } @@ -498,7 +451,7 @@ void QFxFlickable::setViewportY(qreal pos) Q_D(QFxFlickable); pos = qRound(pos); if (-pos != d->_moveY.value()) { - d->_tl.reset(d->_moveY); + d->timeline.reset(d->_moveY); d->_moveY.setValue(-pos); viewportMoved(); } @@ -524,7 +477,7 @@ void QFxFlickable::setInteractive(bool interactive) Q_D(QFxFlickable); d->interactive = interactive; if (!interactive && d->flicked) { - d->_tl.clear(); + d->timeline.clear(); d->flicked = false; emit flickingChanged(); emit flickEnded(); @@ -532,28 +485,6 @@ void QFxFlickable::setInteractive(bool interactive) } /*! - \qmlproperty enumeration Flickable::dragMode - This property contains the kind of 'physics' applied when dragging the surface. - - Two modes are supported: - \list - \i Hard - the view follows the user's input exactly. - \i Elastic - the view moves elastically in response to the user's input. - \endlist -*/ -QFxFlickable::DragMode QFxFlickable::dragMode() const -{ - Q_D(const QFxFlickable); - return d->dragMode; -} - -void QFxFlickable::setDragMode(DragMode mode) -{ - Q_D(QFxFlickable); - d->dragMode = mode; -} - -/*! \qmlproperty real Flickable::horizontalVelocity \qmlproperty real Flickable::verticalVelocity \qmlproperty real Flickable::reportedVelocitySmoothing @@ -616,7 +547,7 @@ void QFxFlickable::ticked() QFxItem *QFxFlickable::viewport() { Q_D(QFxFlickable); - return d->_flick; + return d->viewport; } qreal QFxFlickable::visibleX() const @@ -641,12 +572,12 @@ QFxFlickableVisibleArea *QFxFlickable::visibleArea() void QFxFlickablePrivate::handleMousePressEvent(QGraphicsSceneMouseEvent *event) { - if (interactive && _tl.isActive() && (qAbs(velocityX) > 10 || qAbs(velocityY) > 10)) + if (interactive && timeline.isActive() && (qAbs(velocityX) > 10 || qAbs(velocityY) > 10)) stealMouse = true; // If we've been flicked then steal the click. else stealMouse = false; pressed = true; - _tl.clear(); + timeline.clear(); velocityX = -1; velocityY = -1; lastPos = QPoint(); @@ -656,10 +587,6 @@ void QFxFlickablePrivate::handleMousePressEvent(QGraphicsSceneMouseEvent *event) pressY = _moveY.value(); flicked = false; pressTime.start(); - if (dragMode == QFxFlickable::Elastic) { - elasticX.clear(); - elasticY.clear(); - } velocityTime.start(); } @@ -683,10 +610,7 @@ void QFxFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event) if (newY < maxY && maxY - minY < 0) newY = maxY + (newY - maxY) / 2; if (q->overShoot() || (newY <= minY && newY >= maxY)) { - if (dragMode == QFxFlickable::Hard) - _moveY.setValue(newY); - else - elasticY.setValue(newY); + _moveY.setValue(newY); moved = true; } else if (!q->overShoot()) rejectY = true; @@ -706,10 +630,7 @@ void QFxFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event) if (newX < maxX && maxX - minX < 0) newX = maxX + (newX - maxX) / 2; if (q->overShoot() || (newX <= minX && newX >= maxX)) { - if (dragMode == QFxFlickable::Hard) - _moveX.setValue(newX); - else - elasticX.setValue(newX); + _moveX.setValue(newX); moved = true; } else if (!q->overShoot()) rejectX = true; @@ -751,12 +672,7 @@ void QFxFlickablePrivate::handleMouseReleaseEvent(QGraphicsSceneMouseEvent *) if (lastPosTime.isNull()) return; - if (dragMode == QFxFlickable::Elastic) { - elasticY.clear(); - elasticX.clear(); - } - - vTime = _tl.time(); + vTime = timeline.time(); if (qAbs(velocityY) > 10) flickY(velocityY); else @@ -770,7 +686,7 @@ void QFxFlickablePrivate::handleMouseReleaseEvent(QGraphicsSceneMouseEvent *) stealMouse = false; lastPosTime = QTime(); - if (!_tl.isActive()) + if (!timeline.isActive()) q->movementEnding(); } @@ -835,13 +751,13 @@ void QFxFlickable::viewportMoved() d->velocityTimeline.move(d->verticalVelocity, verticalVelocity, d->reportedVelocitySmoothing); d->velocityTimeline.move(d->verticalVelocity, 0, d->reportedVelocitySmoothing); } else { - if (d->_tl.time() != d->vTime) { - qreal horizontalVelocity = (prevX - d->_moveX.value()) * 1000 / (d->_tl.time() - d->vTime); - qreal verticalVelocity = (prevY - d->_moveY.value()) * 1000 / (d->_tl.time() - d->vTime); + if (d->timeline.time() != d->vTime) { + qreal horizontalVelocity = (prevX - d->_moveX.value()) * 1000 / (d->timeline.time() - d->vTime); + qreal verticalVelocity = (prevY - d->_moveY.value()) * 1000 / (d->timeline.time() - d->vTime); d->horizontalVelocity.setValue(horizontalVelocity); d->verticalVelocity.setValue(verticalVelocity); } - d->vTime = d->_tl.time(); + d->vTime = d->timeline.time(); } } @@ -890,7 +806,7 @@ void QFxFlickablePrivate::data_append(QObject *o) Q_Q(QFxFlickable); QFxItem *i = qobject_cast<QFxItem *>(o); if (i) - _flick->children()->append(i); + viewport->children()->append(i); else o->setParent(q); } @@ -921,7 +837,7 @@ QmlList<QObject *> *QFxFlickable::flickableData() QmlList<QFxItem *> *QFxFlickable::flickableChildren() { Q_D(QFxFlickable); - return d->_flick->children(); + return d->viewport->children(); } /*! @@ -973,9 +889,9 @@ void QFxFlickable::setViewportWidth(qreal w) return; d->vWidth = w; if (w < 0) - d->_flick->setWidth(width()); + d->viewport->setWidth(width()); else - d->_flick->setWidth(w); + d->viewport->setWidth(w); // Make sure that we're entirely in view. if (!d->pressed) d->fixupX(); @@ -987,7 +903,7 @@ void QFxFlickable::widthChange() { Q_D(QFxFlickable); if (d->vWidth < 0) { - d->_flick->setWidth(width()); + d->viewport->setWidth(width()); emit viewportWidthChanged(); } d->updateBeginningEnd(); @@ -997,7 +913,7 @@ void QFxFlickable::heightChange() { Q_D(QFxFlickable); if (d->vHeight < 0) { - d->_flick->setHeight(height()); + d->viewport->setHeight(height()); emit viewportHeightChanged(); } d->updateBeginningEnd(); @@ -1016,9 +932,9 @@ void QFxFlickable::setViewportHeight(qreal h) return; d->vHeight = h; if (h < 0) - d->_flick->setHeight(height()); + d->viewport->setHeight(height()); else - d->_flick->setHeight(h); + d->viewport->setHeight(h); // Make sure that we're entirely in view. if (!d->pressed) d->fixupY(); diff --git a/src/declarative/fx/qfxflickable.h b/src/declarative/fx/qfxflickable.h index 17f2107..4905101 100644 --- a/src/declarative/fx/qfxflickable.h +++ b/src/declarative/fx/qfxflickable.h @@ -71,7 +71,6 @@ class Q_DECLARATIVE_EXPORT QFxFlickable : public QFxItem Q_PROPERTY(bool flicking READ isFlicking NOTIFY flickingChanged) Q_PROPERTY(bool interactive READ isInteractive WRITE setInteractive) - Q_PROPERTY(DragMode dragMode READ dragMode WRITE setDragMode) //### remove. Consider a better way to implement different drag behavior Q_PROPERTY(bool atXEnd READ isAtXEnd NOTIFY isAtBoundaryChanged) Q_PROPERTY(bool atYEnd READ isAtYEnd NOTIFY isAtBoundaryChanged) @@ -118,11 +117,6 @@ public: bool isInteractive() const; void setInteractive(bool); - Q_ENUMS(DragMode) - enum DragMode { Hard, Elastic }; - DragMode dragMode() const; - void setDragMode(DragMode mode); - qreal horizontalVelocity() const; qreal verticalVelocity() const; diff --git a/src/declarative/fx/qfxflickable_p.h b/src/declarative/fx/qfxflickable_p.h index 882bec8..a506027 100644 --- a/src/declarative/fx/qfxflickable_p.h +++ b/src/declarative/fx/qfxflickable_p.h @@ -62,29 +62,6 @@ QT_BEGIN_NAMESPACE -class ElasticValue : public QAbstractAnimation { - Q_OBJECT -public: - ElasticValue(QmlTimeLineValue &); - void setValue(qreal to); - void clear(); - - virtual int duration() const { return 10000; } - -protected: - virtual void updateCurrentTime(int); - -Q_SIGNALS: - void updated(); - -private: - qreal _to; - qreal _myValue; - qreal _velocity; - QmlTimeLineValue &_value; - QTime _startTime; -}; - class QFxFlickableVisibleArea; class QFxFlickablePrivate : public QFxItemPrivate { @@ -100,17 +77,22 @@ public: void updateBeginningEnd(); public: - QFxItem *_flick; + QFxItem *viewport; QmlTimeLineValueProxy<QFxItem> _moveX; QmlTimeLineValueProxy<QFxItem> _moveY; - QmlTimeLine _tl; + QmlTimeLine timeline; qreal vWidth; qreal vHeight; - bool overShoot; - bool flicked; - bool moving; - bool stealMouse; - bool pressed; + bool overShoot : 1; + bool flicked : 1; + bool moving : 1; + bool stealMouse : 1; + bool pressed : 1; + bool atXEnd : 1; + bool atXBeginning : 1; + bool atYEnd : 1; + bool atYBeginning : 1; + bool interactive : 1; QTime lastPosTime; QPointF lastPos; QPointF pressPos; @@ -122,10 +104,6 @@ public: QmlTimeLineEvent fixupXEvent; QmlTimeLineEvent fixupYEvent; qreal maxVelocity; - bool interactive; - QFxFlickable::DragMode dragMode; - ElasticValue elasticY; - ElasticValue elasticX; QTime velocityTime; QPointF lastFlickablePosition; qreal reportedVelocitySmoothing; @@ -147,10 +125,6 @@ public: Velocity verticalVelocity; int vTime; QmlTimeLine velocityTimeline; - bool atXEnd; - bool atXBeginning; - bool atYEnd; - bool atYBeginning; QFxFlickableVisibleArea *visibleArea; void handleMousePressEvent(QGraphicsSceneMouseEvent *); diff --git a/src/declarative/fx/qfxlistview.cpp b/src/declarative/fx/qfxlistview.cpp index 34fe827..523786f 100644 --- a/src/declarative/fx/qfxlistview.cpp +++ b/src/declarative/fx/qfxlistview.cpp @@ -801,8 +801,8 @@ void QFxListViewPrivate::fixupY() if (currItemMode == QFxListView::SnapAuto) { if (currentItem) { moveReason = Mouse; - _tl.clear(); - _tl.move(_moveY, -(currentItem->position() - snapPos), QEasingCurve(QEasingCurve::InOutQuad), 200); + timeline.clear(); + timeline.move(_moveY, -(currentItem->position() - snapPos), QEasingCurve(QEasingCurve::InOutQuad), 200); } } else if (currItemMode == QFxListView::Snap) { moveReason = Mouse; @@ -813,8 +813,8 @@ void QFxListViewPrivate::fixupY() pos = -q->maxYExtent(); else if (pos < -q->minYExtent()) pos = -q->minYExtent(); - _tl.clear(); - _tl.move(_moveY, -(pos), QEasingCurve(QEasingCurve::InOutQuad), 200); + timeline.clear(); + timeline.move(_moveY, -(pos), QEasingCurve(QEasingCurve::InOutQuad), 200); } } } @@ -828,8 +828,8 @@ void QFxListViewPrivate::fixupX() if (currItemMode == QFxListView::SnapAuto) { if (currentItem) { moveReason = Mouse; - _tl.clear(); - _tl.move(_moveX, -(currentItem->position() - snapPos), QEasingCurve(QEasingCurve::InOutQuad), 200); + timeline.clear(); + timeline.move(_moveX, -(currentItem->position() - snapPos), QEasingCurve(QEasingCurve::InOutQuad), 200); } } else if (currItemMode == QFxListView::Snap) { moveReason = Mouse; @@ -840,8 +840,8 @@ void QFxListViewPrivate::fixupX() pos = -q->maxXExtent(); else if (pos < -q->minXExtent()) pos = -q->minXExtent(); - _tl.clear(); - _tl.move(_moveX, -(pos), QEasingCurve(QEasingCurve::InOutQuad), 200); + timeline.clear(); + timeline.move(_moveX, -(pos), QEasingCurve(QEasingCurve::InOutQuad), 200); } } } @@ -1600,7 +1600,7 @@ void QFxListView::itemsRemoved(int modelIndex, int count) if (d->visibleItems.isEmpty()) { d->visibleIndex = 0; d->visiblePos = 0; - d->_tl.clear(); + d->timeline.clear(); d->setPosition(0); if (d->model->count() == 0) update(); |