diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2018-05-16 14:52:32 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2018-07-12 20:25:04 +0000 |
commit | 1bf1a1c460fcfb1555026cbb1127cfc6daee7ca0 (patch) | |
tree | 7135a86b43680bbbbef24b327f8811c69a78b027 /src | |
parent | 8092c5617092195d7df02775f423f5e420eb764f (diff) |
Add Flickable.synchronousDrag property
When it is set true, Flickable begins dragging by making the content
jump to the position where it would have been if there was no drag
threshold: that is, the content moves exactly in sync with the mouse
cursor or finger (as long as it's not hitting the bounds).
[ChangeLog][QtQuick][Flickable] Added a synchronousDrag property that
makes the content jump to the position it would have had if there was
no drag threshold, as soon as dragging begins.
Task-number: QTBUG-62902
Change-Id: I5f3b530956363172167896b0f19aec4a41bf82b3
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/quick/items/qquickflickable.cpp | 32 | ||||
-rw-r--r-- | src/quick/items/qquickflickable_p.h | 5 | ||||
-rw-r--r-- | src/quick/items/qquickflickable_p_p.h | 1 | ||||
-rw-r--r-- | src/quick/items/qquickitemsmodule.cpp | 1 |
4 files changed, 37 insertions, 2 deletions
diff --git a/src/quick/items/qquickflickable.cpp b/src/quick/items/qquickflickable.cpp index d892e3b490..5a3db5e1eb 100644 --- a/src/quick/items/qquickflickable.cpp +++ b/src/quick/items/qquickflickable.cpp @@ -248,6 +248,7 @@ QQuickFlickablePrivate::QQuickFlickablePrivate() , stealMouse(false), pressed(false) , scrollingPhase(false), interactive(true), calcVelocity(false) , pixelAligned(false) + , syncDrag(false) , lastPosTime(-1) , lastPressTime(0) , deceleration(QML_FLICK_DEFAULTDECELERATION) @@ -959,6 +960,33 @@ void QQuickFlickable::setPixelAligned(bool align) } } +/*! + \qmlproperty bool QtQuick::Flickable::synchronousDrag + \since 5.12 + + If this property is set to true, then when the mouse or touchpoint moves + far enough to begin dragging the content, the content will jump, such that + the content pixel which was under the cursor or touchpoint when pressed + remains under that point. + + The default is \c false, which provides a smoother experience (no jump) + at the cost that some of the drag distance is "lost" at the beginning. +*/ +bool QQuickFlickable::synchronousDrag() const +{ + Q_D(const QQuickFlickable); + return d->syncDrag; +} + +void QQuickFlickable::setSynchronousDrag(bool v) +{ + Q_D(QQuickFlickable); + if (v != d->syncDrag) { + d->syncDrag = v; + emit synchronousDragChanged(); + } +} + qint64 QQuickFlickablePrivate::computeCurrentTime(QInputEvent *event) const { if (0 != event->timestamp()) @@ -1075,7 +1103,7 @@ void QQuickFlickablePrivate::drag(qint64 currentTimestamp, QEvent::Type eventTyp if (overThreshold || elapsedSincePress > 200) { if (!vMoved) vData.dragStartOffset = dy; - qreal newY = dy + vData.pressPos - vData.dragStartOffset; + qreal newY = dy + vData.pressPos - (syncDrag ? 0 : vData.dragStartOffset); // Recalculate bounds in case margins have changed, but use the content // size estimate taken at the start of the drag in case the drag causes // the estimate to be altered @@ -1151,7 +1179,7 @@ void QQuickFlickablePrivate::drag(qint64 currentTimestamp, QEvent::Type eventTyp if (overThreshold || elapsedSincePress > 200) { if (!hMoved) hData.dragStartOffset = dx; - qreal newX = dx + hData.pressPos - hData.dragStartOffset; + qreal newX = dx + hData.pressPos - (syncDrag ? 0 : hData.dragStartOffset); const qreal minX = hData.dragMinBound + hData.startMargin; const qreal maxX = hData.dragMaxBound - hData.endMargin; if (!(boundsBehavior & QQuickFlickable::DragOverBounds)) { diff --git a/src/quick/items/qquickflickable_p.h b/src/quick/items/qquickflickable_p.h index 939e3af698..45921c8b86 100644 --- a/src/quick/items/qquickflickable_p.h +++ b/src/quick/items/qquickflickable_p.h @@ -106,6 +106,7 @@ class Q_QUICK_PRIVATE_EXPORT QQuickFlickable : public QQuickItem Q_PROPERTY(QQuickFlickableVisibleArea *visibleArea READ visibleArea CONSTANT) Q_PROPERTY(bool pixelAligned READ pixelAligned WRITE setPixelAligned NOTIFY pixelAlignedChanged) + Q_PROPERTY(bool synchronousDrag READ synchronousDrag WRITE setSynchronousDrag NOTIFY synchronousDragChanged REVISION 12) Q_PROPERTY(qreal horizontalOvershoot READ horizontalOvershoot NOTIFY horizontalOvershootChanged REVISION 9) Q_PROPERTY(qreal verticalOvershoot READ verticalOvershoot NOTIFY verticalOvershootChanged REVISION 9) @@ -213,6 +214,9 @@ public: bool pixelAligned() const; void setPixelAligned(bool align); + bool synchronousDrag() const; + void setSynchronousDrag(bool v); + qreal horizontalOvershoot() const; qreal verticalOvershoot() const; @@ -259,6 +263,7 @@ Q_SIGNALS: void dragStarted(); void dragEnded(); void pixelAlignedChanged(); + Q_REVISION(12) void synchronousDragChanged(); Q_REVISION(9) void horizontalOvershootChanged(); Q_REVISION(9) void verticalOvershootChanged(); diff --git a/src/quick/items/qquickflickable_p_p.h b/src/quick/items/qquickflickable_p_p.h index 08f069e830..dfb943d710 100644 --- a/src/quick/items/qquickflickable_p_p.h +++ b/src/quick/items/qquickflickable_p_p.h @@ -221,6 +221,7 @@ public: bool interactive : 1; bool calcVelocity : 1; bool pixelAligned : 1; + bool syncDrag : 1; QElapsedTimer timer; QBasicTimer movementEndingTimer; qint64 lastPosTime; diff --git a/src/quick/items/qquickitemsmodule.cpp b/src/quick/items/qquickitemsmodule.cpp index 96927dd37a..806fd9e465 100644 --- a/src/quick/items/qquickitemsmodule.cpp +++ b/src/quick/items/qquickitemsmodule.cpp @@ -425,6 +425,7 @@ static void qt_quickitems_defineModule(const char *uri, int major, int minor) qmlRegisterType<QQuickAnimatedSprite, 12>("QtQuick", 2, 12, "AnimatedSprite"); qmlRegisterType<QQuickGradient, 12>(uri, 2, 12, "Gradient"); + qmlRegisterType<QQuickFlickable, 12>(uri, 2, 12, "Flickable"); } static void initResources() |