From 47862497693ffac597557f940535909df549d897 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 22 Apr 2010 13:35:10 +1000 Subject: Replace Flickable overshoot property with boundsBehavior Task-number: QTBUG-9993 --- examples/declarative/parallax/qml/ParallaxView.qml | 2 +- src/declarative/QmlChanges.txt | 5 ++ .../graphicsitems/qdeclarativeflickable.cpp | 62 ++++++++++++++++------ .../graphicsitems/qdeclarativeflickable_p.h | 9 +++- .../graphicsitems/qdeclarativeflickable_p_p.h | 2 +- .../graphicsitems/qdeclarativegridview.cpp | 1 + .../graphicsitems/qdeclarativelistview.cpp | 1 + .../qdeclarativeflickable/data/flickable04.qml | 2 +- .../tst_qdeclarativeflickable.cpp | 32 ++++++----- .../qdeclarativeflickable/flickable-vertical.qml | 5 +- 10 files changed, 86 insertions(+), 35 deletions(-) diff --git a/examples/declarative/parallax/qml/ParallaxView.qml b/examples/declarative/parallax/qml/ParallaxView.qml index 8f5f290..4b38d45 100644 --- a/examples/declarative/parallax/qml/ParallaxView.qml +++ b/examples/declarative/parallax/qml/ParallaxView.qml @@ -21,7 +21,7 @@ Item { onCurrentIndexChanged: root.currentIndex = currentIndex orientation: "Horizontal" - overShoot: false + boundsBehavior: Flickable.DragOverBounds anchors.fill: parent model: VisualItemModel { id: visualModel } diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt index 2cae293..55f7b21 100644 --- a/src/declarative/QmlChanges.txt +++ b/src/declarative/QmlChanges.txt @@ -1,4 +1,9 @@ ============================================================================= +The changes below are pre Qt 4.7.0 RC + +Flickable: overShoot is replaced by boundsBehavior enumeration. + +============================================================================= The changes below are pre Qt 4.7.0 beta TextEdit: wrap property is replaced by wrapMode enumeration. diff --git a/src/declarative/graphicsitems/qdeclarativeflickable.cpp b/src/declarative/graphicsitems/qdeclarativeflickable.cpp index 7b9b5e0..b462443 100644 --- a/src/declarative/graphicsitems/qdeclarativeflickable.cpp +++ b/src/declarative/graphicsitems/qdeclarativeflickable.cpp @@ -41,7 +41,7 @@ #include "private/qdeclarativeflickable_p.h" #include "private/qdeclarativeflickable_p_p.h" - +#include #include #include #include @@ -125,12 +125,13 @@ QDeclarativeFlickablePrivate::QDeclarativeFlickablePrivate() : viewport(new QDeclarativeItem) , hData(this, &QDeclarativeFlickablePrivate::setRoundedViewportX) , vData(this, &QDeclarativeFlickablePrivate::setRoundedViewportY) - , overShoot(true), flicked(false), moving(false), stealMouse(false) + , flicked(false), moving(false), stealMouse(false) , pressed(false) , interactive(true), deceleration(500), maxVelocity(2000), reportedVelocitySmoothing(100) , delayedPressEvent(0), delayedPressTarget(0), pressDelay(0), fixupDuration(600) , vTime(0), visibleArea(0) , flickDirection(QDeclarativeFlickable::AutoFlickDirection) + , boundsBehavior(QDeclarativeFlickable::DragAndOvershootBounds) { } @@ -203,6 +204,7 @@ void QDeclarativeFlickablePrivate::flick(AxisData &data, qreal minExtent, qreal { Q_Q(QDeclarativeFlickable); qreal maxDistance = -1; + bool overShoot = boundsBehavior == QDeclarativeFlickable::DragAndOvershootBounds; // -ve velocity means list is moving up if (velocity > 0) { if (data.move.value() < minExtent) @@ -646,7 +648,7 @@ void QDeclarativeFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent newY = minY + (newY - minY) / 2; if (newY < maxY && maxY - minY <= 0) newY = maxY + (newY - maxY) / 2; - if (!q->overShoot() && (newY > minY || newY < maxY)) { + if (boundsBehavior == QDeclarativeFlickable::StopAtBounds && (newY > minY || newY < maxY)) { if (newY > minY) newY = minY; else if (newY < maxY) @@ -673,7 +675,7 @@ void QDeclarativeFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent newX = minX + (newX - minX) / 2; if (newX < maxX && maxX - minX <= 0) newX = maxX + (newX - maxX) / 2; - if (!q->overShoot() && (newX > minX || newX < maxX)) { + if (boundsBehavior == QDeclarativeFlickable::StopAtBounds && (newX > minX || newX < maxX)) { if (newX > minX) newX = minX; else if (newX < maxX) @@ -997,28 +999,58 @@ QDeclarativeListProperty QDeclarativeFlickable::flickableChildr return QGraphicsItemPrivate::get(d->viewport)->childrenList(); } +bool QDeclarativeFlickable::overShoot() const +{ + Q_D(const QDeclarativeFlickable); + return d->boundsBehavior == DragAndOvershootBounds; +} + +void QDeclarativeFlickable::setOverShoot(bool o) +{ + Q_D(QDeclarativeFlickable); + if ((o && d->boundsBehavior == DragAndOvershootBounds) + || (!o && d->boundsBehavior == StopAtBounds)) + return; + qmlInfo(this) << "overshoot is deprecated and will be removed imminently - use boundsBehavior."; + d->boundsBehavior = o ? DragAndOvershootBounds : StopAtBounds; + emit boundsBehaviorChanged(); + emit overShootChanged(); +} + /*! - \qmlproperty bool Flickable::overShoot - This property holds whether the surface may overshoot the + \qmlproperty enumeration Flickable::boundsBehavior + This property holds whether the surface may be dragged + beyond the Fickable's boundaries, or overshoot the Flickable's boundaries when flicked. - If overShoot is true the contents can be flicked beyond the boundary - of the Flickable before being moved back to the boundary. This provides - the feeling that the edges of the view are soft, rather than a hard - physical boundary. + This enables the feeling that the edges of the view are soft, + rather than a hard physical boundary. + + boundsBehavior can be one of: + + \list + \o \e StopAtBounds - the contents can not be dragged beyond the boundary + of the flickable, and flicks will not overshoot. + \o \e DragOverBounds - the contents can be dragged beyond the boundary + of the Flickable, but flicks will not overshoot. + \o \e DragAndOvershootBounds (default) - the contents can be dragged + beyond the boundary of the Flickable, and can overshoot the + boundary when flicked. + \endlist */ -bool QDeclarativeFlickable::overShoot() const +QDeclarativeFlickable::BoundsBehavior QDeclarativeFlickable::boundsBehavior() const { Q_D(const QDeclarativeFlickable); - return d->overShoot; + return d->boundsBehavior; } -void QDeclarativeFlickable::setOverShoot(bool o) +void QDeclarativeFlickable::setBoundsBehavior(BoundsBehavior b) { Q_D(QDeclarativeFlickable); - if (d->overShoot == o) + if (b == d->boundsBehavior) return; - d->overShoot = o; + d->boundsBehavior = b; + emit boundsBehaviorChanged(); emit overShootChanged(); } diff --git a/src/declarative/graphicsitems/qdeclarativeflickable_p.h b/src/declarative/graphicsitems/qdeclarativeflickable_p.h index 1fa2c74..f031a24 100644 --- a/src/declarative/graphicsitems/qdeclarativeflickable_p.h +++ b/src/declarative/graphicsitems/qdeclarativeflickable_p.h @@ -64,7 +64,8 @@ class Q_DECLARATIVE_EXPORT QDeclarativeFlickable : public QDeclarativeItem Q_PROPERTY(qreal horizontalVelocity READ horizontalVelocity NOTIFY horizontalVelocityChanged) Q_PROPERTY(qreal verticalVelocity READ verticalVelocity NOTIFY verticalVelocityChanged) - Q_PROPERTY(bool overShoot READ overShoot WRITE setOverShoot NOTIFY overShootChanged) + Q_PROPERTY(bool overShoot READ overShoot WRITE setOverShoot NOTIFY overShootChanged) // deprecated + Q_PROPERTY(BoundsBehavior boundsBehavior READ boundsBehavior WRITE setBoundsBehavior NOTIFY boundsBehaviorChanged) Q_PROPERTY(qreal maximumFlickVelocity READ maximumFlickVelocity WRITE setMaximumFlickVelocity NOTIFY maximumFlickVelocityChanged) Q_PROPERTY(qreal flickDeceleration READ flickDeceleration WRITE setFlickDeceleration NOTIFY flickDecelerationChanged) Q_PROPERTY(bool moving READ isMoving NOTIFY movingChanged) @@ -86,6 +87,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativeFlickable : public QDeclarativeItem Q_CLASSINFO("DefaultProperty", "flickableData") Q_ENUMS(FlickDirection) + Q_ENUMS(BoundsBehavior) public: QDeclarativeFlickable(QDeclarativeItem *parent=0); @@ -97,6 +99,10 @@ public: bool overShoot() const; void setOverShoot(bool); + enum BoundsBehavior { StopAtBounds, DragOverBounds, DragAndOvershootBounds }; + BoundsBehavior boundsBehavior() const; + void setBoundsBehavior(BoundsBehavior); + qreal contentWidth() const; void setContentWidth(qreal); @@ -156,6 +162,7 @@ Q_SIGNALS: void flickDirectionChanged(); void interactiveChanged(); void overShootChanged(); + void boundsBehaviorChanged(); void maximumFlickVelocityChanged(); void flickDecelerationChanged(); void pressDelayChanged(); diff --git a/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h b/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h index 1a04091..01cfb18 100644 --- a/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h @@ -131,7 +131,6 @@ public: AxisData vData; QDeclarativeTimeLine timeline; - bool overShoot : 1; bool flicked : 1; bool moving : 1; bool stealMouse : 1; @@ -160,6 +159,7 @@ public: QDeclarativeTimeLine velocityTimeline; QDeclarativeFlickableVisibleArea *visibleArea; QDeclarativeFlickable::FlickDirection flickDirection; + QDeclarativeFlickable::BoundsBehavior boundsBehavior; void handleMousePressEvent(QGraphicsSceneMouseEvent *); void handleMouseMoveEvent(QGraphicsSceneMouseEvent *); diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index f6666f2..f8b773e 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -831,6 +831,7 @@ void QDeclarativeGridViewPrivate::flick(AxisData &data, qreal minExtent, qreal m if (snapMode == QDeclarativeGridView::NoSnap && highlightRange != QDeclarativeGridView::StrictlyEnforceRange) data.flickTarget = maxExtent; } + bool overShoot = boundsBehavior == QDeclarativeFlickable::DragAndOvershootBounds; if (maxDistance > 0 || overShoot) { // This mode requires the grid to stop exactly on a row boundary. qreal v = velocity; diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index a4ca651..60e8f6c 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -1190,6 +1190,7 @@ void QDeclarativeListViewPrivate::flick(AxisData &data, qreal minExtent, qreal m if (snapMode == QDeclarativeListView::NoSnap && highlightRange != QDeclarativeListView::StrictlyEnforceRange) data.flickTarget = maxExtent; } + bool overShoot = boundsBehavior == QDeclarativeFlickable::DragAndOvershootBounds; if (maxDistance > 0 || overShoot) { // These modes require the list to stop exactly on an item boundary. // The initial flick will estimate the boundary to stop on. diff --git a/tests/auto/declarative/qdeclarativeflickable/data/flickable04.qml b/tests/auto/declarative/qdeclarativeflickable/data/flickable04.qml index ff742f0..aa156ed 100644 --- a/tests/auto/declarative/qdeclarativeflickable/data/flickable04.qml +++ b/tests/auto/declarative/qdeclarativeflickable/data/flickable04.qml @@ -3,7 +3,7 @@ import Qt 4.7 Flickable { width: 100; height: 100 contentWidth: column.width; contentHeight: column.height - pressDelay: 200; overShoot: false; interactive: false + pressDelay: 200; boundsBehavior: Flickable.StopAtBounds; interactive: false maximumFlickVelocity: 2000 Column { diff --git a/tests/auto/declarative/qdeclarativeflickable/tst_qdeclarativeflickable.cpp b/tests/auto/declarative/qdeclarativeflickable/tst_qdeclarativeflickable.cpp index a345a60..9ce9c49 100644 --- a/tests/auto/declarative/qdeclarativeflickable/tst_qdeclarativeflickable.cpp +++ b/tests/auto/declarative/qdeclarativeflickable/tst_qdeclarativeflickable.cpp @@ -57,7 +57,7 @@ private slots: void horizontalViewportSize(); void verticalViewportSize(); void properties(); - void overShoot(); + void boundsBehavior(); void maximumFlickVelocity(); void flickDeceleration(); void pressDelay(); @@ -88,7 +88,7 @@ void tst_qdeclarativeflickable::create() QCOMPARE(obj->verticalVelocity(), 0.); QCOMPARE(obj->isInteractive(), true); - QCOMPARE(obj->overShoot(), true); + QCOMPARE(obj->boundsBehavior(), QDeclarativeFlickable::DragAndOvershootBounds); QCOMPARE(obj->pressDelay(), 0); QCOMPARE(obj->maximumFlickVelocity(), 2000.); @@ -137,34 +137,40 @@ void tst_qdeclarativeflickable::properties() QVERIFY(obj != 0); QCOMPARE(obj->isInteractive(), false); - QCOMPARE(obj->overShoot(), false); + QCOMPARE(obj->boundsBehavior(), QDeclarativeFlickable::StopAtBounds); QCOMPARE(obj->pressDelay(), 200); QCOMPARE(obj->maximumFlickVelocity(), 2000.); delete obj; } -void tst_qdeclarativeflickable::overShoot() +void tst_qdeclarativeflickable::boundsBehavior() { QDeclarativeComponent component(&engine); - component.setData("import Qt 4.7; Flickable { overShoot: false; }", QUrl::fromLocalFile("")); + component.setData("import Qt 4.7; Flickable { boundsBehavior: Flickable.StopAtBounds }", QUrl::fromLocalFile("")); QDeclarativeFlickable *flickable = qobject_cast(component.create()); - QSignalSpy spy(flickable, SIGNAL(overShootChanged())); + QSignalSpy spy(flickable, SIGNAL(boundsBehaviorChanged())); QVERIFY(flickable); - QVERIFY(!flickable->overShoot()); + QVERIFY(flickable->boundsBehavior() == QDeclarativeFlickable::StopAtBounds); - flickable->setOverShoot(true); - QVERIFY(flickable->overShoot()); + flickable->setBoundsBehavior(QDeclarativeFlickable::DragAndOvershootBounds); + QVERIFY(flickable->boundsBehavior() == QDeclarativeFlickable::DragAndOvershootBounds); QCOMPARE(spy.count(),1); - flickable->setOverShoot(true); + flickable->setBoundsBehavior(QDeclarativeFlickable::DragAndOvershootBounds); QCOMPARE(spy.count(),1); - flickable->setOverShoot(false); - QVERIFY(!flickable->overShoot()); + flickable->setBoundsBehavior(QDeclarativeFlickable::DragOverBounds); + QVERIFY(flickable->boundsBehavior() == QDeclarativeFlickable::DragOverBounds); QCOMPARE(spy.count(),2); - flickable->setOverShoot(false); + flickable->setBoundsBehavior(QDeclarativeFlickable::DragOverBounds); QCOMPARE(spy.count(),2); + + flickable->setBoundsBehavior(QDeclarativeFlickable::StopAtBounds); + QVERIFY(flickable->boundsBehavior() == QDeclarativeFlickable::StopAtBounds); + QCOMPARE(spy.count(),3); + flickable->setBoundsBehavior(QDeclarativeFlickable::StopAtBounds); + QCOMPARE(spy.count(),3); } void tst_qdeclarativeflickable::maximumFlickVelocity() diff --git a/tests/auto/declarative/qmlvisual/qdeclarativeflickable/flickable-vertical.qml b/tests/auto/declarative/qmlvisual/qdeclarativeflickable/flickable-vertical.qml index 09e414d..d845353 100644 --- a/tests/auto/declarative/qmlvisual/qdeclarativeflickable/flickable-vertical.qml +++ b/tests/auto/declarative/qmlvisual/qdeclarativeflickable/flickable-vertical.qml @@ -15,7 +15,7 @@ Rectangle { ListElement { dayColor: "orange" } } - flickable { + Flickable { id: flick height: parent.height-50 width: parent.width; contentHeight: column.height @@ -33,7 +33,6 @@ Rectangle { } } clip: true - reportedVelocitySmoothing: 1000 } Rectangle { radius: 3 @@ -77,7 +76,7 @@ Rectangle { color: "yellow" MouseArea { anchors.fill: parent - onClicked: flick.overShoot = flick.overShoot > 0 ? 0 : 30 + onClicked: flick.boundsBehavior = flick.boundsBehavior == Flickable.StopAtBounds ? Flickable.DragAndOvershootBounds : Flickable.StopAtBounds } } -- cgit v0.12