Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquickflickable.cpp
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
7#include "qquickwindow.h"
10#if QT_CONFIG(quick_draganddrop)
11#include "qquickdrag_p.h"
12#endif
13
14#include <QtQuick/private/qquickpointerhandler_p.h>
15#include <QtQuick/private/qquicktransition_p.h>
16#include <private/qqmlglobal_p.h>
17
18#include <QtQml/qqmlinfo.h>
19#include <QtGui/qevent.h>
20#include <QtGui/qguiapplication.h>
21#include <QtGui/private/qguiapplication_p.h>
22#include <QtGui/private/qeventpoint_p.h>
23#include <QtGui/qstylehints.h>
24#include <QtGui/qaccessible.h>
25#include <QtCore/qmath.h>
26#include <qpa/qplatformtheme.h>
27
28#include <math.h>
29#include <cmath>
30
32
33Q_STATIC_LOGGING_CATEGORY(lcFlickable, "qt.quick.flickable")
34Q_STATIC_LOGGING_CATEGORY(lcFilter, "qt.quick.flickable.filter")
35Q_STATIC_LOGGING_CATEGORY(lcReplay, "qt.quick.flickable.replay")
36Q_STATIC_LOGGING_CATEGORY(lcWheel, "qt.quick.flickable.wheel")
37Q_STATIC_LOGGING_CATEGORY(lcVel, "qt.quick.flickable.velocity")
38
39// RetainGrabVelocity is the maxmimum instantaneous velocity that
40// will ensure the Flickable retains the grab on consecutive flicks.
41static const int RetainGrabVelocity = 100;
42
43static qreal EaseOvershoot(qreal t) {
44 return qAtan(t);
45}
46
47QQuickFlickableVisibleArea::QQuickFlickableVisibleArea(QQuickFlickable *parent)
48 : QObject(parent), flickable(parent), m_xPosition(0.), m_widthRatio(0.)
49 , m_yPosition(0.), m_heightRatio(0.)
50{
51}
52
53qreal QQuickFlickableVisibleArea::widthRatio() const
54{
55 return m_widthRatio;
56}
57
58qreal QQuickFlickableVisibleArea::xPosition() const
59{
60 return m_xPosition;
61}
62
63qreal QQuickFlickableVisibleArea::heightRatio() const
64{
65 return m_heightRatio;
66}
67
68qreal QQuickFlickableVisibleArea::yPosition() const
69{
70 return m_yPosition;
71}
72
73void QQuickFlickableVisibleArea::updateVisible()
74{
75 QQuickFlickablePrivate *p = QQuickFlickablePrivate::get(flickable);
76
77 bool changeX = false;
78 bool changeY = false;
79 bool changeWidth = false;
80 bool changeHeight = false;
81
82 // Vertical
83 const qreal viewheight = flickable->height();
84 const qreal maxyextent = -flickable->maxYExtent() + flickable->minYExtent();
85 const qreal maxYBounds = maxyextent + viewheight;
86 qreal pagePos = 0;
87 qreal pageSize = 0;
88 if (!qFuzzyIsNull(maxYBounds)) {
89 qreal y = p->pixelAligned ? std::round(p->vData.move.value()) : p->vData.move.value();
90 pagePos = (-y + flickable->minYExtent()) / maxYBounds;
91 pageSize = viewheight / maxYBounds;
92 }
93
94 if (pageSize != m_heightRatio) {
95 m_heightRatio = pageSize;
96 changeHeight = true;
97 }
98 if (pagePos != m_yPosition) {
99 m_yPosition = pagePos;
100 changeY = true;
101 }
102
103 // Horizontal
104 const qreal viewwidth = flickable->width();
105 const qreal maxxextent = -flickable->maxXExtent() + flickable->minXExtent();
106 const qreal maxXBounds = maxxextent + viewwidth;
107 if (!qFuzzyIsNull(maxXBounds)) {
108 qreal x = p->pixelAligned ? std::round(p->hData.move.value()) : p->hData.move.value();
109 pagePos = (-x + flickable->minXExtent()) / maxXBounds;
110 pageSize = viewwidth / maxXBounds;
111 } else {
112 pagePos = 0;
113 pageSize = 0;
114 }
115
116 if (pageSize != m_widthRatio) {
117 m_widthRatio = pageSize;
118 changeWidth = true;
119 }
120 if (pagePos != m_xPosition) {
121 m_xPosition = pagePos;
122 changeX = true;
123 }
124
125 if (changeX)
126 emit xPositionChanged(m_xPosition);
127 if (changeY)
128 emit yPositionChanged(m_yPosition);
129 if (changeWidth)
130 emit widthRatioChanged(m_widthRatio);
131 if (changeHeight)
132 emit heightRatioChanged(m_heightRatio);
133}
134
135
137{
138public:
139 QQuickFlickableReboundTransition(QQuickFlickable *f, const QString &name)
140 : flickable(f), axisData(nullptr), propName(name), active(false)
141 {
142 }
143
145 {
146 flickable = nullptr;
147 }
148
149 bool startTransition(QQuickFlickablePrivate::AxisData *data, qreal toPos) {
150 QQuickFlickablePrivate *fp = QQuickFlickablePrivate::get(flickable);
151 if (!fp->rebound || !fp->rebound->enabled())
152 return false;
153 active = true;
154 axisData = data;
155 axisData->transitionTo = toPos;
156 axisData->transitionToSet = true;
157
158 actions.clear();
159 actions << QQuickStateAction(fp->contentItem, propName, toPos);
160 QQuickTransitionManager::transition(actions, fp->rebound, fp->contentItem);
161 return true;
162 }
163
164 bool isActive() const {
165 return active;
166 }
167
169 if (!flickable || !isRunning())
170 return;
171 QQuickFlickablePrivate *fp = QQuickFlickablePrivate::get(flickable);
172 if (axisData == &fp->hData)
173 axisData->move.setValue(-flickable->contentX());
174 else
175 axisData->move.setValue(-flickable->contentY());
176 active = false;
177 cancel();
178 }
179
180protected:
182 if (!flickable)
183 return;
184 axisData->move.setValue(axisData->transitionTo);
185 QQuickFlickablePrivate *fp = QQuickFlickablePrivate::get(flickable);
186 active = false;
187
188 if (!fp->hData.transitionToBounds->isActive()
189 && !fp->vData.transitionToBounds->isActive()) {
190 flickable->movementEnding();
191 }
192 }
193
194private:
195 QQuickStateOperation::ActionList actions;
196 QQuickFlickable *flickable;
197 QQuickFlickablePrivate::AxisData *axisData;
198 QString propName;
199 bool active;
200};
201
202QQuickFlickablePrivate::AxisData::~AxisData()
203{
204 delete transitionToBounds;
205}
206
208{
209public:
210 explicit QQuickFlickableContentItem(QQuickItem *parent = nullptr) : QQuickItem(parent)
211 {
212 auto *d = QQuickItemPrivate::get(this);
213 // A user can set contentWidth/contentHeight to make this item
214 // arbitrarily small (or large); yet, the expectation is that pointer handlers
215 // declared in the Flickable react to events within the whole Flickable.
216 // So assume the contentItem doesn't fully contain all its children (don't check).
217 d->eventHandlingChildrenWithinBounds = false;
218 d->eventHandlingChildrenWithinBoundsSet = true;
219 }
220
221private:
222 /*!
223 \internal
224 The flickable area inside the viewport can be bigger than the bounds of the
225 content item itself, if the flickable is using non-zero extents (as returned
226 by e.g minXExtent()). Since the default implementation in QQuickItem::contains()
227 only checks if the point is inside the bounds of the item, we need to override it
228 to check the extents as well. The easist way to do this is to simply check if the
229 point is inside the bounds of the flickable rather than the content item.
230 */
231 bool contains(const QPointF &point) const override
232 {
233 const QQuickItem *flickable = parentItem();
234 const QPointF posInFlickable = flickable->mapFromItem(this, point);
235 return flickable->contains(posInFlickable);
236 }
237};
238
239QQuickFlickablePrivate::QQuickFlickablePrivate()
240 : contentItem(new QQuickFlickableContentItem)
241 , hData(this, &QQuickFlickablePrivate::setViewportX)
242 , vData(this, &QQuickFlickablePrivate::setViewportY)
243 , hMoved(false), vMoved(false)
244 , stealGrab(false), pressed(false)
245 , scrollingPhase(false), interactive(true), calcVelocity(false)
246 , pixelAligned(false)
247 , syncDrag(false)
248 , acceptedButtons(Qt::LeftButton)
249 , lastPosTime(-1)
250 , lastPressTime(0)
251 , deceleration(QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::FlickDeceleration).toReal())
252 , wheelDeceleration(15000)
253 , maxVelocity(QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::FlickMaximumVelocity).toReal())
254 , delayedPressEvent(nullptr), pressDelay(0), fixupDuration(400)
255 , flickBoost(1.0), initialWheelFlickDistance(qApp->styleHints()->wheelScrollLines() * 24)
256 , fixupMode(Normal), vTime(0), visibleArea(nullptr)
257 , flickableDirection(QQuickFlickable::AutoFlickDirection)
258 , boundsBehavior(QQuickFlickable::DragAndOvershootBounds)
259 , boundsMovement(QQuickFlickable::FollowBoundsBehavior)
260 , rebound(nullptr)
261{
262 const int wheelDecelerationEnv = qEnvironmentVariableIntValue("QT_QUICK_FLICKABLE_WHEEL_DECELERATION");
263 if (wheelDecelerationEnv > 0)
264 wheelDeceleration = wheelDecelerationEnv;
265}
266
267void QQuickFlickablePrivate::init()
268{
269 Q_Q(QQuickFlickable);
270 QQml_setParent_noEvent(contentItem, q);
271 contentItem->setParentItem(q);
272 qmlobject_connect(&timeline, QQuickTimeLine, SIGNAL(completed()),
273 q, QQuickFlickable, SLOT(timelineCompleted()));
274 qmlobject_connect(&velocityTimeline, QQuickTimeLine, SIGNAL(completed()),
275 q, QQuickFlickable, SLOT(velocityTimelineCompleted()));
276 q->setAcceptedMouseButtons(acceptedButtons);
277 q->setAcceptTouchEvents(true);
278 q->setFiltersChildMouseEvents(true);
279 q->setFlag(QQuickItem::ItemIsViewport);
280 QQuickItemPrivate *viewportPrivate = QQuickItemPrivate::get(contentItem);
281 viewportPrivate->addItemChangeListener(this, QQuickItemPrivate::Geometry);
282 setSizePolicy(QLayoutPolicy::Expanding, QLayoutPolicy::Expanding);
283}
284
285/*!
286 \internal
287 Returns the distance to overshoot, given \a velocity.
288 Will be in range 0 - velocity / 3, but limited to a max of QML_FLICK_OVERSHOOT
289*/
290qreal QQuickFlickablePrivate::overShootDistance(qreal velocity) const
291{
292 if (maxVelocity <= 0)
293 return 0;
294
295 return qMin(qreal(QML_FLICK_OVERSHOOT), velocity / 3);
296}
297
298void QQuickFlickablePrivate::AxisData::addVelocitySample(qreal v, qreal maxVelocity)
299{
300 if (v > maxVelocity)
301 v = maxVelocity;
302 else if (v < -maxVelocity)
303 v = -maxVelocity;
304
305 velocityBuffer[velocityWritePos] = v;
306 velocityWritePos = (velocityWritePos + 1) % QML_FLICK_SAMPLEBUFFER;
307 if (velocitySamples < QML_FLICK_SAMPLEBUFFER)
308 ++velocitySamples;
309}
310
311void QQuickFlickablePrivate::AxisData::updateVelocity()
312{
313 velocity = 0;
314 if (velocitySamples > QML_FLICK_DISCARDSAMPLES) {
315 int count = velocitySamples - QML_FLICK_DISCARDSAMPLES;
316 // velocityBuffer is a ring; read oldest-first so DISCARDSAMPLES drops the
317 // newest (least reliable, taken as the finger lifts) samples.
318 const int oldest = (velocityWritePos - velocitySamples + QML_FLICK_SAMPLEBUFFER)
320 for (int i = 0; i < count; ++i) {
321 qreal v = velocityBuffer[(oldest + i) % QML_FLICK_SAMPLEBUFFER];
322 velocity += v;
323 }
324 velocity /= count;
325 }
326}
327
328void QQuickFlickablePrivate::itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change, const QRectF &oldGeom)
329{
330 Q_Q(QQuickFlickable);
331 if (item == contentItem) {
332 Qt::Orientations orient;
333 if (change.xChange())
334 orient |= Qt::Horizontal;
335 if (change.yChange())
336 orient |= Qt::Vertical;
337 if (orient) {
338 q->viewportMoved(orient);
339 const QPointF deltaMoved = item->position() - oldGeom.topLeft();
340 if (hData.contentPositionChangedExternallyDuringDrag)
341 hData.pressPos += deltaMoved.x();
342 if (vData.contentPositionChangedExternallyDuringDrag)
343 vData.pressPos += deltaMoved.y();
344 }
345#if QT_CONFIG(accessibility)
346 bool updateAccessibility = false;
347#endif
348 if (orient & Qt::Horizontal) {
349 emit q->contentXChanged();
350#if QT_CONFIG(accessibility)
351 updateAccessibility = true;
352#endif
353 }
354 if (orient & Qt::Vertical) {
355 emit q->contentYChanged();
356#if QT_CONFIG(accessibility)
357 updateAccessibility = true;
358#endif
359 }
360#if QT_CONFIG(accessibility)
361 if (updateAccessibility && QAccessible::isActive()) {
362 if (!m_scrollEventTimer.isValid() || m_scrollEventTimer.elapsed() >= 250) {
363 m_scrollEventTimer.restart();
364 QAccessibleEvent ev(q, QAccessible::ScrollingPositionChanged);
365 QAccessible::updateAccessibility(&ev);
366 }
367 }
368#endif
369 }
370}
371
372bool QQuickFlickablePrivate::flickX(QEvent::Type eventType, qreal velocity)
373{
374 Q_Q(QQuickFlickable);
375 return flick(hData, q->minXExtent(), q->maxXExtent(), q->width(), fixupX_callback, eventType, velocity);
376}
377
378bool QQuickFlickablePrivate::flickY(QEvent::Type eventType, qreal velocity)
379{
380 Q_Q(QQuickFlickable);
381 return flick(vData, q->minYExtent(), q->maxYExtent(), q->height(), fixupY_callback, eventType, velocity);
382}
383
384bool QQuickFlickablePrivate::flick(AxisData &data, qreal minExtent, qreal maxExtent, qreal,
385 QQuickTimeLineCallback::Callback fixupCallback,
386 QEvent::Type eventType, qreal velocity)
387{
388 Q_Q(QQuickFlickable);
389 qreal maxDistance = -1;
390 data.fixingUp = false;
391 // -ve velocity means list is moving up
392 if (velocity > 0) {
393 maxDistance = qAbs(minExtent - data.move.value());
394 data.flickTarget = minExtent;
395 } else {
396 maxDistance = qAbs(maxExtent - data.move.value());
397 data.flickTarget = maxExtent;
398 }
399 if (maxDistance > 0 || boundsBehavior & QQuickFlickable::OvershootBounds) {
400 qreal v = velocity;
401 if (maxVelocity != -1 && maxVelocity < qAbs(v)) {
402 if (v < 0)
403 v = -maxVelocity;
404 else
405 v = maxVelocity;
406 }
407
408 qreal accel = eventType == QEvent::Wheel ? wheelDeceleration : deceleration;
409 qCDebug(lcFlickable) << "choosing deceleration" << accel << "for" << eventType;
410 // adjust accel so that we hit a full pixel
411 qreal v2 = v * v;
412 qreal dist = v2 / (accel * 2.0);
413 if (v > 0)
414 dist = -dist;
415 qreal target = std::round(data.move.value() - dist);
416 dist = -target + data.move.value();
417 accel = v2 / (2.0f * qAbs(dist));
418
419 resetTimeline(data);
420 if (!data.inOvershoot) {
421 if (boundsBehavior & QQuickFlickable::OvershootBounds)
422 timeline.accel(data.move, v, accel);
423 else
424 timeline.accel(data.move, v, accel, maxDistance);
425 }
426 timeline.callback(QQuickTimeLineCallback(&data.move, fixupCallback, this));
427
428 if (&data == &hData)
429 return !hData.flicking && q->xflick();
430 else if (&data == &vData)
431 return !vData.flicking && q->yflick();
432 return false;
433 } else {
434 resetTimeline(data);
435 fixup(data, minExtent, maxExtent);
436 return false;
437 }
438}
439
440void QQuickFlickablePrivate::fixupY_callback(void *data)
441{
442 ((QQuickFlickablePrivate *)data)->fixupY();
443}
444
445void QQuickFlickablePrivate::fixupX_callback(void *data)
446{
447 ((QQuickFlickablePrivate *)data)->fixupX();
448}
449
450void QQuickFlickablePrivate::fixupX()
451{
452 Q_Q(QQuickFlickable);
453 if (!q->isComponentComplete())
454 return; //Do not fixup from initialization values
455 fixup(hData, q->minXExtent(), q->maxXExtent());
456}
457
458void QQuickFlickablePrivate::fixupY()
459{
460 Q_Q(QQuickFlickable);
461 if (!q->isComponentComplete())
462 return; //Do not fixup from initialization values
463 fixup(vData, q->minYExtent(), q->maxYExtent());
464}
465
466/*!
467 \internal
468
469 Adjusts the contentItem's position via the timeline.
470 This function is used by QQuickFlickablePrivate::fixup in order to
471 position the contentItem back into the viewport, in case flicking,
472 dragging or geometry adjustments moved it outside of bounds.
473*/
474void QQuickFlickablePrivate::adjustContentPos(AxisData &data, qreal toPos)
475{
476 Q_Q(QQuickFlickable);
477 switch (fixupMode) {
478 case Immediate:
479 timeline.set(data.move, toPos);
480 break;
481 case ExtentChanged:
482 // The target has changed. Don't start from the beginning; just complete the
483 // second half of the animation using the new extent.
484 timeline.move(data.move, toPos, QEasingCurve(QEasingCurve::OutExpo), 3*fixupDuration/4);
485 data.fixingUp = true;
486 break;
487 default: {
488 if (data.transitionToBounds && data.transitionToBounds->startTransition(&data, toPos)) {
489 q->movementStarting();
490 data.fixingUp = true;
491 } else {
492 qreal dist = toPos - data.move;
493 timeline.move(data.move, toPos - dist/2, QEasingCurve(QEasingCurve::InQuad), fixupDuration/4);
494 timeline.move(data.move, toPos, QEasingCurve(QEasingCurve::OutExpo), 3*fixupDuration/4);
495 data.fixingUp = true;
496 }
497 }
498 }
499}
500
501void QQuickFlickablePrivate::resetTimeline(AxisData &data)
502{
503 timeline.reset(data.move);
504 if (data.transitionToBounds)
505 data.transitionToBounds->stopTransition();
506}
507
508void QQuickFlickablePrivate::clearTimeline()
509{
510 timeline.clear();
511 if (hData.transitionToBounds)
512 hData.transitionToBounds->stopTransition();
513 if (vData.transitionToBounds)
514 vData.transitionToBounds->stopTransition();
515}
516
517/*!
518 \internal
519
520 This function should be called after the contentItem has been moved, either programmatically,
521 or by the timeline (as a result of a flick).
522 It ensures that the contentItem will be moved back into bounds,
523 in case it was flicked outside of the visible area.
524
525 The positional adjustment will usually be animated by the timeline, unless the fixupMode is set to Immediate.
526*/
527void QQuickFlickablePrivate::fixup(AxisData &data, qreal minExtent, qreal maxExtent)
528{
529 // If the timeline animation is running and calling resetTimeline, one must also
530 // call timeline.move so that the animation keeps running. Otherwise timelineCompleted
531 // signal won't get emitted.
532 if (data.move.value() >= minExtent || maxExtent > minExtent) {
533 const bool wasActive = timeline.isActive();
534 resetTimeline(data);
535 if (data.move.value() != minExtent)
536 adjustContentPos(data, minExtent);
537 else if (wasActive)
538 timeline.move(data.move, data.move.value(), QEasingCurve(QEasingCurve::Linear), 1);
539 } else if (data.move.value() <= maxExtent) {
540 resetTimeline(data);
541 adjustContentPos(data, maxExtent);
542 } else if (-std::round(-data.move.value()) != data.move.value()) {
543 // We could animate, but since it is less than 0.5 pixel it's probably not worthwhile.
544 resetTimeline(data);
545 qreal val = data.move.value();
546 if (std::abs(std::round(val) - val) < 0.25) // round small differences
547 val = std::round(val);
548 else if (data.smoothVelocity.value() > 0) // continue direction of motion for larger
549 val = std::ceil(val);
550 else if (data.smoothVelocity.value() < 0)
551 val = std::floor(val);
552 else // otherwise round
553 val = std::round(val);
554 timeline.set(data.move, val);
555 }
556 data.inOvershoot = false;
557 fixupMode = Normal;
558 data.vTime = timeline.time();
559}
560
561static bool fuzzyLessThanOrEqualTo(qreal a, qreal b)
562{
563 if (a == 0.0 || b == 0.0) {
564 // qFuzzyCompare is broken
565 a += 1.0;
566 b += 1.0;
567 }
568 return a <= b || qFuzzyCompare(a, b);
569}
570
571/*!
572 \internal
573
574 This function's main purpose is to update the atBeginning and atEnd flags
575 in hData and vData. It should be called when the contentItem has moved,
576 to ensure that hData and vData are up to date.
577
578 The origin will also be updated, if AxisData::markExtentsDirty has been called
579*/
580void QQuickFlickablePrivate::updateBeginningEnd()
581{
582 Q_Q(QQuickFlickable);
583 bool atXBeginningChange = false, atXEndChange = false;
584 bool atYBeginningChange = false, atYEndChange = false;
585
586 // Vertical
587 const qreal maxyextent = -q->maxYExtent();
588 const qreal minyextent = -q->minYExtent();
589 const qreal ypos = pixelAligned ? -std::round(vData.move.value()) : -vData.move.value();
590 bool atBeginning = fuzzyLessThanOrEqualTo(ypos, std::ceil(minyextent));
591 bool atEnd = fuzzyLessThanOrEqualTo(std::floor(maxyextent), ypos);
592
593 if (atBeginning != vData.atBeginning) {
594 vData.atBeginning = atBeginning;
595 atYBeginningChange = true;
596 if (!vData.moving && atBeginning)
597 vData.smoothVelocity.setValue(0);
598 }
599 if (atEnd != vData.atEnd) {
600 vData.atEnd = atEnd;
601 atYEndChange = true;
602 if (!vData.moving && atEnd)
603 vData.smoothVelocity.setValue(0);
604 }
605
606 // Horizontal
607 const qreal maxxextent = -q->maxXExtent();
608 const qreal minxextent = -q->minXExtent();
609 const qreal xpos = pixelAligned ? -std::round(hData.move.value()) : -hData.move.value();
610 atBeginning = fuzzyLessThanOrEqualTo(xpos, std::ceil(minxextent));
611 atEnd = fuzzyLessThanOrEqualTo(std::floor(maxxextent), xpos);
612
613 if (atBeginning != hData.atBeginning) {
614 hData.atBeginning = atBeginning;
615 atXBeginningChange = true;
616 if (!hData.moving && atBeginning)
617 hData.smoothVelocity.setValue(0);
618 }
619 if (atEnd != hData.atEnd) {
620 hData.atEnd = atEnd;
621 atXEndChange = true;
622 if (!hData.moving && atEnd)
623 hData.smoothVelocity.setValue(0);
624 }
625
626 if (vData.extentsChanged) {
627 vData.extentsChanged = false;
628 qreal originY = q->originY();
629 if (vData.origin != originY) {
630 vData.origin = originY;
631 emit q->originYChanged();
632 }
633 }
634
635 if (hData.extentsChanged) {
636 hData.extentsChanged = false;
637 qreal originX = q->originX();
638 if (hData.origin != originX) {
639 hData.origin = originX;
640 emit q->originXChanged();
641 }
642 }
643
644 if (atXEndChange || atYEndChange || atXBeginningChange || atYBeginningChange)
645 emit q->isAtBoundaryChanged();
646 if (atXEndChange)
647 emit q->atXEndChanged();
648 if (atXBeginningChange)
649 emit q->atXBeginningChanged();
650 if (atYEndChange)
651 emit q->atYEndChanged();
652 if (atYBeginningChange)
653 emit q->atYBeginningChanged();
654
655 if (visibleArea)
656 visibleArea->updateVisible();
657}
658
659/*!
660 \qmlsignal QtQuick::Flickable::dragStarted()
661
662 This signal is emitted when the view starts to be dragged due to user
663 interaction.
664*/
665
666/*!
667 \qmlsignal QtQuick::Flickable::dragEnded()
668
669 This signal is emitted when the user stops dragging the view.
670
671 If the velocity of the drag is sufficient at the time the
672 touch/mouse button is released then a flick will start.
673*/
674
675/*!
676 \qmltype Flickable
677 \nativetype QQuickFlickable
678 \inqmlmodule QtQuick
679 \ingroup qtquick-input
680 \ingroup qtquick-containers
681
682 \brief Provides a surface that can be "flicked".
683 \inherits Item
684
685 The Flickable item places its children on a surface that can be dragged
686 and flicked, causing the view onto the child items to scroll. This
687 behavior forms the basis of Items that are designed to show large numbers
688 of child items, such as \l ListView and \l GridView.
689
690 In traditional user interfaces, views can be scrolled using standard
691 controls, such as scroll bars and arrow buttons. In some situations, it
692 is also possible to drag the view directly by pressing and holding a
693 mouse button while moving the cursor. In touch-based user interfaces,
694 this dragging action is often complemented with a flicking action, where
695 scrolling continues after the user has stopped touching the view.
696
697 Flickable does not automatically clip its contents. If it is not used as
698 a full-screen item, you should consider setting the \l{Item::}{clip} property
699 to true.
700
701 \section1 Example Usage
702
703 \div {class="float-right"}
704 \inlineimage flickable.gif
705 {Animated view of an image being flicked and dragged}
706 \enddiv
707
708 The following example shows a small view onto a large image in which the
709 user can drag or flick the image in order to view different parts of it.
710
711 \snippet qml/flickable.qml document
712
713 \clearfloat
714
715 Items declared as children of a Flickable are automatically parented to the
716 Flickable's \l contentItem. This should be taken into account when
717 operating on the children of the Flickable; it is usually the children of
718 \c contentItem that are relevant. For example, the bound of Items added
719 to the Flickable will be available by \c contentItem.childrenRect
720
721 \section1 Examples of contentX and contentY
722
723 The following images demonstrate a flickable being flicked in various
724 directions and the resulting \l contentX and \l contentY values.
725 The blue square represents the flickable's content, and the black
726 border represents the bounds of the flickable.
727
728 \table
729 \row
730 \li \image flickable-contentXY-resting.png {Blue content square
731 at rest within flickable bounds}
732 \li The \c contentX and \c contentY are both \c 0.
733 \row
734 \li \image flickable-contentXY-top-left.png {Blue content square
735 dragged toward top-left corner}
736 \li The \c contentX and the \c contentY are both \c 50.
737 \row
738 \li \image flickable-contentXY-top-right.png {Blue content square
739 dragged toward top-right corner}
740 \li The \c contentX is \c -50 and the \c contentY is \c 50.
741 \row
742 \li \image flickable-contentXY-bottom-right.png {Blue content square
743 dragged toward bottom-right corner}
744 \li The \c contentX and the \c contentY are both \c -50.
745 \row
746 \li \image flickable-contentXY-bottom-left.png {Blue content square
747 dragged toward bottom-left corner}
748 \li The \c contentX is \c 50 and the \c contentY is \c -50.
749 \endtable
750
751 \section1 Limitations
752
753 \note Due to an implementation detail, items placed inside a Flickable
754 cannot anchor to the Flickable. Instead, use \l {Item::}{parent}, which
755 refers to the Flickable's \l contentItem. The size of the content item is
756 determined by \l contentWidth and \l contentHeight.
757*/
758
759/*!
760 \qmlsignal QtQuick::Flickable::movementStarted()
761
762 This signal is emitted when the view begins moving due to user
763 interaction or a generated flick().
764*/
765
766/*!
767 \qmlsignal QtQuick::Flickable::movementEnded()
768
769 This signal is emitted when the view stops moving due to user
770 interaction or a generated flick(). If a flick was active, this signal will
771 be emitted once the flick stops. If a flick was not
772 active, this signal will be emitted when the
773 user stops dragging - i.e. a mouse or touch release.
774*/
775
776/*!
777 \qmlsignal QtQuick::Flickable::flickStarted()
778
779 This signal is emitted when the view is flicked. A flick
780 starts from the point that the mouse or touch is released,
781 while still in motion.
782*/
783
784/*!
785 \qmlsignal QtQuick::Flickable::flickEnded()
786
787 This signal is emitted when the view stops moving after a flick
788 or a series of flicks.
789*/
790
791/*!
792 \qmlpropertygroup QtQuick::Flickable::visibleArea
793 \qmlproperty real QtQuick::Flickable::visibleArea.xPosition
794 \qmlproperty real QtQuick::Flickable::visibleArea.widthRatio
795 \qmlproperty real QtQuick::Flickable::visibleArea.yPosition
796 \qmlproperty real QtQuick::Flickable::visibleArea.heightRatio
797
798 These properties describe the position and size of the currently viewed area.
799 The size is defined as the percentage of the full view currently visible,
800 scaled to 0.0 - 1.0. The page position is usually in the range 0.0 (beginning) to
801 1.0 minus size ratio (end), i.e. \c yPosition is in the range 0.0 to 1.0-\c heightRatio.
802 However, it is possible for the contents to be dragged outside of the normal
803 range, resulting in the page positions also being outside the normal range.
804
805 These properties are typically used to draw a scrollbar. For example:
806
807 \snippet qml/flickableScrollbar.qml 0
808 \dots 8
809 \snippet qml/flickableScrollbar.qml 1
810*/
811QQuickFlickable::QQuickFlickable(QQuickItem *parent)
812 : QQuickItem(*(new QQuickFlickablePrivate), parent)
813{
814 Q_D(QQuickFlickable);
815 d->init();
816}
817
818QQuickFlickable::QQuickFlickable(QQuickFlickablePrivate &dd, QQuickItem *parent)
819 : QQuickItem(dd, parent)
820{
821 Q_D(QQuickFlickable);
822 d->init();
823}
824
825QQuickFlickable::~QQuickFlickable()
826{
827}
828
829/*!
830 \qmlproperty real QtQuick::Flickable::contentX
831 \qmlproperty real QtQuick::Flickable::contentY
832
833 These properties hold the surface coordinate currently at the top-left
834 corner of the Flickable. For example, if you flick an image up 100 pixels,
835 \c contentY will increase by 100.
836
837 \note If you flick back to the origin (the top-left corner), after the
838 rebound animation, \c contentX will settle to the same value as \c originX,
839 and \c contentY to \c originY. These are usually (0,0), however ListView
840 and GridView may have an arbitrary origin due to delegate size variation,
841 or item insertion/removal outside the visible region. So if you want to
842 implement something like a vertical scrollbar, one way is to use
843 \c {y: (contentY - originY) * (height / contentHeight)}
844 for the position; another way is to use the normalized values in
845 \l {QtQuick::Flickable::visibleArea}{visibleArea}.
846
847 \sa {Examples of contentX and contentY}, originX, originY
848*/
849qreal QQuickFlickable::contentX() const
850{
851 Q_D(const QQuickFlickable);
852 return -d->contentItem->x();
853}
854
855void QQuickFlickable::setContentX(qreal pos)
856{
857 Q_D(QQuickFlickable);
858 d->hData.explicitValue = true;
859 d->resetTimeline(d->hData);
860 d->hData.vTime = d->timeline.time();
861 const bool wasMovingOrFlicking = isMoving() || isFlicking();
862 if (wasMovingOrFlicking)
863 movementEnding(true, false);
864 if (!qFuzzyCompare(-pos, d->hData.move.value())) {
865 d->hData.contentPositionChangedExternallyDuringDrag = d->hData.dragging;
866 d->hData.move.setValue(-pos);
867 d->hData.contentPositionChangedExternallyDuringDrag = false;
868#if QT_CONFIG(accessibility)
869 if (!wasMovingOrFlicking && QAccessible::isActive()) {
870 QAccessibleEvent event(this, QAccessible::ScrollingEnd);
871 QAccessible::updateAccessibility(&event);
872 }
873#endif
874 }
875}
876
877qreal QQuickFlickable::contentY() const
878{
879 Q_D(const QQuickFlickable);
880 return -d->contentItem->y();
881}
882
883void QQuickFlickable::setContentY(qreal pos)
884{
885 Q_D(QQuickFlickable);
886 d->vData.explicitValue = true;
887 d->resetTimeline(d->vData);
888 d->vData.vTime = d->timeline.time();
889 const bool wasMovingOrFlicking = isMoving() || isFlicking();
890 if (wasMovingOrFlicking)
891 movementEnding(false, true);
892 if (!qFuzzyCompare(-pos, d->vData.move.value())) {
893 d->vData.contentPositionChangedExternallyDuringDrag = d->vData.dragging;
894 d->vData.move.setValue(-pos);
895 d->vData.contentPositionChangedExternallyDuringDrag = false;
896#if QT_CONFIG(accessibility)
897 if (!wasMovingOrFlicking && QAccessible::isActive()) {
898 QAccessibleEvent event(this, QAccessible::ScrollingEnd);
899 QAccessible::updateAccessibility(&event);
900 }
901#endif
902 }
903}
904
905/*!
906 \qmlproperty bool QtQuick::Flickable::interactive
907
908 This property describes whether the user can interact with the Flickable.
909 A user cannot drag or flick a Flickable that is not interactive.
910
911 By default, this property is true.
912
913 This property is useful for temporarily disabling flicking. This allows
914 special interaction with Flickable's children; for example, you might want
915 to freeze a flickable map while scrolling through a pop-up dialog that
916 is a child of the Flickable.
917*/
918bool QQuickFlickable::isInteractive() const
919{
920 Q_D(const QQuickFlickable);
921 return d->interactive;
922}
923
924void QQuickFlickable::setInteractive(bool interactive)
925{
926 Q_D(QQuickFlickable);
927 if (interactive != d->interactive) {
928 d->interactive = interactive;
929 if (!interactive) {
930 d->cancelInteraction();
931 }
932 emit interactiveChanged();
933 }
934}
935
936/*!
937 \qmlproperty real QtQuick::Flickable::horizontalVelocity
938 \qmlproperty real QtQuick::Flickable::verticalVelocity
939
940 The instantaneous velocity of movement along the x and y axes, in pixels/sec.
941
942 The reported velocity is smoothed to avoid erratic output.
943
944 Note that for views with a large content size (more than 10 times the view size),
945 the velocity of the flick may exceed the velocity of the touch in the case
946 of multiple quick consecutive flicks. This allows the user to flick faster
947 through large content.
948*/
949qreal QQuickFlickable::horizontalVelocity() const
950{
951 Q_D(const QQuickFlickable);
952 return d->hData.smoothVelocity.value();
953}
954
955qreal QQuickFlickable::verticalVelocity() const
956{
957 Q_D(const QQuickFlickable);
958 return d->vData.smoothVelocity.value();
959}
960
961/*!
962 \qmlproperty bool QtQuick::Flickable::atXBeginning
963 \qmlproperty bool QtQuick::Flickable::atXEnd
964 \qmlproperty bool QtQuick::Flickable::atYBeginning
965 \qmlproperty bool QtQuick::Flickable::atYEnd
966
967 These properties are true if the flickable view is positioned at the beginning,
968 or end respectively.
969*/
970bool QQuickFlickable::isAtXEnd() const
971{
972 Q_D(const QQuickFlickable);
973 return d->hData.atEnd;
974}
975
976bool QQuickFlickable::isAtXBeginning() const
977{
978 Q_D(const QQuickFlickable);
979 return d->hData.atBeginning;
980}
981
982bool QQuickFlickable::isAtYEnd() const
983{
984 Q_D(const QQuickFlickable);
985 return d->vData.atEnd;
986}
987
988bool QQuickFlickable::isAtYBeginning() const
989{
990 Q_D(const QQuickFlickable);
991 return d->vData.atBeginning;
992}
993
994/*!
995 \qmlproperty Item QtQuick::Flickable::contentItem
996
997 The internal item that contains the Items to be moved in the Flickable.
998
999 Items declared as children of a Flickable are automatically parented to the Flickable's contentItem.
1000
1001 Items created dynamically need to be explicitly parented to the \e contentItem:
1002 \code
1003 Flickable {
1004 id: myFlickable
1005 function addItem(file) {
1006 var component = Qt.createComponent(file)
1007 component.createObject(myFlickable.contentItem);
1008 }
1009 }
1010 \endcode
1011*/
1012QQuickItem *QQuickFlickable::contentItem() const
1013{
1014 Q_D(const QQuickFlickable);
1015 return d->contentItem;
1016}
1017
1018QQuickFlickableVisibleArea *QQuickFlickable::visibleArea()
1019{
1020 Q_D(QQuickFlickable);
1021 if (!d->visibleArea) {
1022 d->visibleArea = new QQuickFlickableVisibleArea(this);
1023 d->visibleArea->updateVisible(); // calculate initial ratios
1024 }
1025 return d->visibleArea;
1026}
1027
1028/*!
1029 \qmlproperty enumeration QtQuick::Flickable::flickableDirection
1030
1031 This property determines which directions the view can be flicked.
1032
1033 \list
1034 \li Flickable.AutoFlickDirection (default) - allows flicking vertically if the
1035 \e contentHeight is not equal to the \e height of the Flickable.
1036 Allows flicking horizontally if the \e contentWidth is not equal
1037 to the \e width of the Flickable.
1038 \li Flickable.AutoFlickIfNeeded - allows flicking vertically if the
1039 \e contentHeight is greater than the \e height of the Flickable.
1040 Allows flicking horizontally if the \e contentWidth is greater than
1041 to the \e width of the Flickable. (since \c{QtQuick 2.7})
1042 \li Flickable.HorizontalFlick - allows flicking horizontally.
1043 \li Flickable.VerticalFlick - allows flicking vertically.
1044 \li Flickable.HorizontalAndVerticalFlick - allows flicking in both directions.
1045 \endlist
1046*/
1047QQuickFlickable::FlickableDirection QQuickFlickable::flickableDirection() const
1048{
1049 Q_D(const QQuickFlickable);
1050 return d->flickableDirection;
1051}
1052
1053void QQuickFlickable::setFlickableDirection(FlickableDirection direction)
1054{
1055 Q_D(QQuickFlickable);
1056 if (direction != d->flickableDirection) {
1057 d->flickableDirection = direction;
1058 emit flickableDirectionChanged();
1059 }
1060}
1061
1062/*!
1063 \qmlproperty bool QtQuick::Flickable::pixelAligned
1064
1065 This property sets the alignment of \l contentX and \l contentY to
1066 pixels (\c true) or subpixels (\c false).
1067
1068 Enable pixelAligned to optimize for still content or moving content with
1069 high constrast edges, such as one-pixel-wide lines, text or vector graphics.
1070 Disable pixelAligned when optimizing for animation quality.
1071
1072 The default is \c false.
1073*/
1074bool QQuickFlickable::pixelAligned() const
1075{
1076 Q_D(const QQuickFlickable);
1077 return d->pixelAligned;
1078}
1079
1080void QQuickFlickable::setPixelAligned(bool align)
1081{
1082 Q_D(QQuickFlickable);
1083 if (align != d->pixelAligned) {
1084 d->pixelAligned = align;
1085 emit pixelAlignedChanged();
1086 }
1087}
1088
1089/*!
1090 \qmlproperty bool QtQuick::Flickable::synchronousDrag
1091 \since 5.12
1092
1093 If this property is set to true, then when the mouse or touchpoint moves
1094 far enough to begin dragging the content, the content will jump, such that
1095 the content pixel which was under the cursor or touchpoint when pressed
1096 remains under that point.
1097
1098 The default is \c false, which provides a smoother experience (no jump)
1099 at the cost that some of the drag distance is "lost" at the beginning.
1100*/
1101bool QQuickFlickable::synchronousDrag() const
1102{
1103 Q_D(const QQuickFlickable);
1104 return d->syncDrag;
1105}
1106
1107void QQuickFlickable::setSynchronousDrag(bool v)
1108{
1109 Q_D(QQuickFlickable);
1110 if (v != d->syncDrag) {
1111 d->syncDrag = v;
1112 emit synchronousDragChanged();
1113 }
1114}
1115
1116/*!
1117 \qmlproperty flags QtQuick::Flickable::acceptedButtons
1118 \since 6.9
1119
1120 The mouse buttons that can be used to scroll this Flickable by dragging.
1121
1122 By default, this property is set to \l {QtQuick::MouseEvent::button} {Qt.LeftButton},
1123 which provides the same behavior as in previous Qt versions; but in most
1124 user interfaces, this behavior is unexpected. Users expect to flick only on
1125 a touchscreen, and to use the mouse wheel, touchpad gestures or a scroll
1126 bar with mouse or touchpad. Set it to \c Qt.NoButton to disable dragging.
1127
1128 It can be set to an OR combination of mouse buttons, and will ignore events
1129 from other buttons.
1130*/
1131Qt::MouseButtons QQuickFlickable::acceptedButtons() const
1132{
1133 Q_D(const QQuickFlickable);
1134 return d->acceptedButtons;
1135}
1136
1137void QQuickFlickable::setAcceptedButtons(Qt::MouseButtons buttons)
1138{
1139 Q_D(QQuickFlickable);
1140 if (d->acceptedButtons == buttons)
1141 return;
1142
1143 d->acceptedButtons = buttons;
1144 setAcceptedMouseButtons(buttons);
1145 emit acceptedButtonsChanged();
1146}
1147
1148/*! \internal
1149 Take the velocity of the first point from the given \a event and transform
1150 it to the local coordinate system (taking scale and rotation into account).
1151*/
1152QVector2D QQuickFlickablePrivate::firstPointLocalVelocity(QPointerEvent *event)
1153{
1154 QTransform transform = windowToItemTransform();
1155 // rotate and scale the velocity vector from scene to local
1156 return QVector2D(transform.map(event->point(0).velocity().toPointF()) - transform.map(QPointF()));
1157}
1158
1159qint64 QQuickFlickablePrivate::computeCurrentTime(QInputEvent *event) const
1160{
1161 if (0 != event->timestamp())
1162 return event->timestamp();
1163 if (!timer.isValid())
1164 return 0LL;
1165 return timer.elapsed();
1166}
1167
1168void QQuickFlickablePrivate::handlePressEvent(QPointerEvent *event)
1169{
1170 Q_Q(QQuickFlickable);
1171 timer.start();
1172 if (interactive && timeline.isActive()
1173 && ((qAbs(hData.smoothVelocity.value()) > RetainGrabVelocity && !hData.fixingUp && !hData.inOvershoot)
1174 || (qAbs(vData.smoothVelocity.value()) > RetainGrabVelocity && !vData.fixingUp && !vData.inOvershoot))) {
1175 // If flicked and still moving, prepare to handle the gesture: the user is probably
1176 // trying to speed up or slow down, not click some child item.
1177 stealGrab = true;
1178 int flickTime = timeline.time();
1179 if (flickTime > 600) {
1180 // too long between flicks - cancel boost
1181 hData.continuousFlickVelocity = 0;
1182 vData.continuousFlickVelocity = 0;
1183 flickBoost = 1.0;
1184 } else {
1185 hData.continuousFlickVelocity = -hData.smoothVelocity.value();
1186 vData.continuousFlickVelocity = -vData.smoothVelocity.value();
1187 if (flickTime > 300) // slower flicking - reduce boost
1188 flickBoost = qMax(1.0, flickBoost - 0.5);
1189 }
1190 } else {
1191 stealGrab = false;
1192 hData.continuousFlickVelocity = 0;
1193 vData.continuousFlickVelocity = 0;
1194 flickBoost = 1.0;
1195 }
1196 if (event->isSinglePointEvent())
1197 q->setKeepMouseGrab(stealGrab);
1198 else
1199 q->setKeepTouchGrab(stealGrab);
1200
1201 maybeBeginDrag(computeCurrentTime(event), event->points().first().position(),
1202 event->isSinglePointEvent() ? static_cast<QSinglePointEvent *>(event)->buttons()
1203 : Qt::NoButton);
1204}
1205
1206void QQuickFlickablePrivate::maybeBeginDrag(qint64 currentTimestamp, const QPointF &pressPosn, Qt::MouseButtons buttons)
1207{
1208 Q_Q(QQuickFlickable);
1209 clearDelayedPress();
1210 // consider dragging only when buttons intersect acceptedButtons, or it's a touch event which has no button
1211 pressed = (buttons == Qt::NoButton) || (acceptedButtons != Qt::NoButton && (buttons & acceptedButtons) != 0);
1212
1213 if (hData.transitionToBounds)
1214 hData.transitionToBounds->stopTransition();
1215 if (vData.transitionToBounds)
1216 vData.transitionToBounds->stopTransition();
1217 if (!hData.fixingUp)
1218 resetTimeline(hData);
1219 if (!vData.fixingUp)
1220 resetTimeline(vData);
1221
1222 hData.reset();
1223 vData.reset();
1224 hData.dragMinBound = q->minXExtent() - hData.startMargin;
1225 vData.dragMinBound = q->minYExtent() - vData.startMargin;
1226 hData.dragMaxBound = q->maxXExtent() + hData.endMargin;
1227 vData.dragMaxBound = q->maxYExtent() + vData.endMargin;
1228 fixupMode = Normal;
1229 lastPos = QPointF();
1230 pressPos = pressPosn;
1231 hData.pressPos = hData.move.value();
1232 vData.pressPos = vData.move.value();
1233 const bool wasFlicking = hData.flicking || vData.flicking;
1234 hData.flickingWhenDragBegan = hData.flicking;
1235 vData.flickingWhenDragBegan = vData.flicking;
1236 if (hData.flicking) {
1237 hData.flicking = false;
1238 emit q->flickingHorizontallyChanged();
1239 }
1240 if (vData.flicking) {
1241 vData.flicking = false;
1242 emit q->flickingVerticallyChanged();
1243 }
1244 if (wasFlicking)
1245 emit q->flickingChanged();
1246 lastPosTime = lastPressTime = currentTimestamp;
1247 vData.velocityTime.start();
1248 hData.velocityTime.start();
1249}
1250
1251void QQuickFlickablePrivate::drag(qint64 currentTimestamp, QEvent::Type eventType, const QPointF &localPos,
1252 const QVector2D &deltas, bool overThreshold, bool momentum,
1253 bool velocitySensitiveOverBounds, const QVector2D &velocity)
1254{
1255 Q_Q(QQuickFlickable);
1256 bool rejectY = false;
1257 bool rejectX = false;
1258
1259 bool keepY = q->yflick();
1260 bool keepX = q->xflick();
1261
1262 bool stealY = false;
1263 bool stealX = false;
1264 bool isTouchEvent = false;
1265 switch (eventType) {
1266 case QEvent::MouseMove:
1267 stealX = stealY = stealGrab;
1268 break;
1269 case QEvent::Wheel:
1270 stealX = stealY = scrollingPhase;
1271 break;
1272 case QEvent::TouchUpdate:
1273 stealX = stealY = stealGrab;
1274 isTouchEvent = true;
1275 break;
1276 default:
1277 break;
1278 }
1279
1280 bool prevHMoved = hMoved;
1281 bool prevVMoved = vMoved;
1282
1283 qint64 elapsedSincePress = currentTimestamp - lastPressTime;
1284 qCDebug(lcFlickable).nospace() << currentTimestamp << ' ' << eventType << " drag @ " << localPos.x() << ',' << localPos.y()
1285 << " \u0394 " << deltas.x() << ',' << deltas.y() << " vel " << velocity.x() << ',' << velocity.y()
1286 << " thrsld? " << overThreshold << " momentum? " << momentum << " velSens? " << velocitySensitiveOverBounds
1287 << " sincePress " << elapsedSincePress;
1288
1289 if (q->yflick()) {
1290 qreal dy = deltas.y();
1291 if (overThreshold || elapsedSincePress > 200) {
1292 if (!vMoved && !vData.dragging)
1293 vData.dragStartOffset = dy;
1294 qreal newY = dy + vData.pressPos - (syncDrag ? 0 : vData.dragStartOffset);
1295 // Recalculate bounds in case margins have changed, but use the content
1296 // size estimate taken at the start of the drag in case the drag causes
1297 // the estimate to be altered
1298 const qreal minY = vData.dragMinBound + vData.startMargin;
1299 const qreal maxY = vData.dragMaxBound - vData.endMargin;
1300 if (!(boundsBehavior & QQuickFlickable::DragOverBounds)) {
1301 if (fuzzyLessThanOrEqualTo(newY, maxY)) {
1302 newY = maxY;
1303 rejectY = vData.pressPos == maxY && vData.move.value() == maxY && dy < 0;
1304 }
1305 if (fuzzyLessThanOrEqualTo(minY, newY)) {
1306 newY = minY;
1307 rejectY |= vData.pressPos == minY && vData.move.value() == minY && dy > 0;
1308 }
1309 } else {
1310 qreal vel = velocity.y() / QML_FLICK_OVERSHOOTFRICTION;
1311 if (vel > 0. && vel > vData.velocity)
1312 vData.velocity = qMin(velocity.y() / QML_FLICK_OVERSHOOTFRICTION, maxVelocity);
1313 else if (vel < 0. && vel < vData.velocity)
1314 vData.velocity = qMax(velocity.y() / QML_FLICK_OVERSHOOTFRICTION, -maxVelocity);
1315 if (newY > minY) {
1316 // Overshoot beyond the top. But don't wait for momentum phase to end before returning to bounds.
1317 if (momentum && vData.atBeginning) {
1318 if (!vData.inRebound) {
1319 vData.inRebound = true;
1320 q->returnToBounds();
1321 }
1322 return;
1323 }
1324 if (velocitySensitiveOverBounds) {
1325 qreal overshoot = (newY - minY) * vData.velocity / maxVelocity / QML_FLICK_OVERSHOOTFRICTION;
1326 overshoot = QML_FLICK_OVERSHOOT * effectiveDevicePixelRatio() * EaseOvershoot(overshoot / QML_FLICK_OVERSHOOT / effectiveDevicePixelRatio());
1327 newY = minY + overshoot;
1328 } else {
1329 newY = minY + (newY - minY) / 2;
1330 }
1331 } else if (newY < maxY && maxY - minY <= 0) {
1332 // Overshoot beyond the bottom. But don't wait for momentum phase to end before returning to bounds.
1333 if (momentum && vData.atEnd) {
1334 if (!vData.inRebound) {
1335 vData.inRebound = true;
1336 q->returnToBounds();
1337 }
1338 return;
1339 }
1340 if (velocitySensitiveOverBounds) {
1341 qreal overshoot = (newY - maxY) * vData.velocity / maxVelocity / QML_FLICK_OVERSHOOTFRICTION;
1342 overshoot = QML_FLICK_OVERSHOOT * effectiveDevicePixelRatio() * EaseOvershoot(overshoot / QML_FLICK_OVERSHOOT / effectiveDevicePixelRatio());
1343 newY = maxY - overshoot;
1344 } else {
1345 newY = maxY + (newY - maxY) / 2;
1346 }
1347 }
1348 }
1349 if (!rejectY && stealGrab && dy != vData.previousDragDelta) {
1350 clearTimeline();
1351 vData.move.setValue(newY);
1352 vMoved = true;
1353 }
1354 if (!rejectY && overThreshold)
1355 stealY = true;
1356
1357 if ((newY >= minY && vData.pressPos == minY && vData.move.value() == minY && dy > 0)
1358 || (newY <= maxY && vData.pressPos == maxY && vData.move.value() == maxY && dy < 0)) {
1359 keepY = false;
1360 }
1361 }
1362 vData.previousDragDelta = dy;
1363 }
1364
1365 if (q->xflick()) {
1366 qreal dx = deltas.x();
1367 if (overThreshold || elapsedSincePress > 200) {
1368 if (!hMoved && !hData.dragging)
1369 hData.dragStartOffset = dx;
1370 qreal newX = dx + hData.pressPos - (syncDrag ? 0 : hData.dragStartOffset);
1371 const qreal minX = hData.dragMinBound + hData.startMargin;
1372 const qreal maxX = hData.dragMaxBound - hData.endMargin;
1373 if (!(boundsBehavior & QQuickFlickable::DragOverBounds)) {
1374 if (fuzzyLessThanOrEqualTo(newX, maxX)) {
1375 newX = maxX;
1376 rejectX = hData.pressPos == maxX && hData.move.value() == maxX && dx < 0;
1377 }
1378 if (fuzzyLessThanOrEqualTo(minX, newX)) {
1379 newX = minX;
1380 rejectX |= hData.pressPos == minX && hData.move.value() == minX && dx > 0;
1381 }
1382 } else {
1383 qreal vel = velocity.x() / QML_FLICK_OVERSHOOTFRICTION;
1384 if (vel > 0. && vel > hData.velocity)
1385 hData.velocity = qMin(velocity.x() / QML_FLICK_OVERSHOOTFRICTION, maxVelocity);
1386 else if (vel < 0. && vel < hData.velocity)
1387 hData.velocity = qMax(velocity.x() / QML_FLICK_OVERSHOOTFRICTION, -maxVelocity);
1388 if (newX > minX) {
1389 // Overshoot beyond the left. But don't wait for momentum phase to end before returning to bounds.
1390 if (momentum && hData.atBeginning) {
1391 if (!hData.inRebound) {
1392 hData.inRebound = true;
1393 q->returnToBounds();
1394 }
1395 return;
1396 }
1397 if (velocitySensitiveOverBounds) {
1398 qreal overshoot = (newX - minX) * hData.velocity / maxVelocity / QML_FLICK_OVERSHOOTFRICTION;
1399 overshoot = QML_FLICK_OVERSHOOT * effectiveDevicePixelRatio() * EaseOvershoot(overshoot / QML_FLICK_OVERSHOOT / effectiveDevicePixelRatio());
1400 newX = minX + overshoot;
1401 } else {
1402 newX = minX + (newX - minX) / 2;
1403 }
1404 } else if (newX < maxX && maxX - minX <= 0) {
1405 // Overshoot beyond the right. But don't wait for momentum phase to end before returning to bounds.
1406 if (momentum && hData.atEnd) {
1407 if (!hData.inRebound) {
1408 hData.inRebound = true;
1409 q->returnToBounds();
1410 }
1411 return;
1412 }
1413 if (velocitySensitiveOverBounds) {
1414 qreal overshoot = (newX - maxX) * hData.velocity / maxVelocity / QML_FLICK_OVERSHOOTFRICTION;
1415 overshoot = QML_FLICK_OVERSHOOT * effectiveDevicePixelRatio() * EaseOvershoot(overshoot / QML_FLICK_OVERSHOOT / effectiveDevicePixelRatio());
1416 newX = maxX - overshoot;
1417 } else {
1418 newX = maxX + (newX - maxX) / 2;
1419 }
1420 }
1421 }
1422 if (!rejectX && stealGrab && dx != hData.previousDragDelta) {
1423 clearTimeline();
1424 hData.move.setValue(newX);
1425 hMoved = true;
1426 }
1427
1428 if (!rejectX && overThreshold)
1429 stealX = true;
1430
1431 if ((newX >= minX && vData.pressPos == minX && vData.move.value() == minX && dx > 0)
1432 || (newX <= maxX && vData.pressPos == maxX && vData.move.value() == maxX && dx < 0)) {
1433 keepX = false;
1434 }
1435 }
1436 hData.previousDragDelta = dx;
1437 }
1438
1439 stealGrab = stealX || stealY;
1440 if (stealGrab) {
1441 if ((stealX && keepX) || (stealY && keepY)) {
1442 if (isTouchEvent)
1443 q->setKeepTouchGrab(true);
1444 else
1445 q->setKeepMouseGrab(true);
1446 }
1447 clearDelayedPress();
1448 }
1449
1450 if (rejectY) {
1451 vData.velocitySamples = 0;
1452 vData.velocityWritePos = 0;
1453 vData.velocity = 0;
1454 }
1455 if (rejectX) {
1456 hData.velocitySamples = 0;
1457 hData.velocityWritePos = 0;
1458 hData.velocity = 0;
1459 }
1460
1461 if (momentum && !hData.flicking && !vData.flicking)
1462 flickingStarted(hData.velocity != 0, vData.velocity != 0);
1463 draggingStarting();
1464
1465 if ((hMoved && !prevHMoved) || (vMoved && !prevVMoved))
1466 q->movementStarting();
1467
1468 lastPosTime = currentTimestamp;
1469 if (q->yflick() && !rejectY)
1470 vData.addVelocitySample(velocity.y(), maxVelocity);
1471 if (q->xflick() && !rejectX)
1472 hData.addVelocitySample(velocity.x(), maxVelocity);
1473 lastPos = localPos;
1474}
1475
1476void QQuickFlickablePrivate::handleMoveEvent(QPointerEvent *event)
1477{
1478 Q_Q(QQuickFlickable);
1479 if (!interactive || lastPosTime == -1 ||
1480 (event->isSinglePointEvent() && !buttonsAccepted(static_cast<QSinglePointEvent *>(event))))
1481 return;
1482
1483 qint64 currentTimestamp = computeCurrentTime(event);
1484 const auto &firstPoint = event->points().first();
1485 const auto &pos = firstPoint.position();
1486 const QVector2D deltas = QVector2D(pos - q->mapFromGlobal(firstPoint.globalPressPosition()));
1487 const QVector2D velocity = firstPointLocalVelocity(event);
1488 bool overThreshold = false;
1489
1490 if (q->isMoving()) {
1491 /*
1492 Only the first drag should be used to determine if the Flickable should start moving,
1493 to the exclusion of some inner Control (such as Slider) or a child Flickable.
1494 If the user releases the mouse or finger and drags again, this Flickable is the only
1495 sensible recipient as long as it's still moving.
1496 We also only care about the drag threshold for the first drag. If it's already moving,
1497 every subsequent move event (however small) should move the content item immediately.
1498 */
1499 overThreshold = true;
1500 } else if (event->pointCount() == 1) {
1501 if (q->yflick())
1502 overThreshold |= QQuickDeliveryAgentPrivate::dragOverThreshold(deltas.y(), Qt::YAxis, firstPoint);
1503 if (q->xflick())
1504 overThreshold |= QQuickDeliveryAgentPrivate::dragOverThreshold(deltas.x(), Qt::XAxis, firstPoint);
1505 } else {
1506 qCDebug(lcFilter) << q->objectName() << "ignoring multi-touch" << event;
1507 }
1508
1509 drag(currentTimestamp, event->type(), pos, deltas, overThreshold, false, false, velocity);
1510}
1511
1512void QQuickFlickablePrivate::handleReleaseEvent(QPointerEvent *event)
1513{
1514 Q_Q(QQuickFlickable);
1515 stealGrab = false;
1516 q->setKeepMouseGrab(false);
1517 q->setKeepTouchGrab(false);
1518 pressed = false;
1519
1520 // if we drag then pause before release we should not cause a flick.
1521 qint64 elapsed = computeCurrentTime(event) - lastPosTime;
1522
1523 vData.updateVelocity();
1524 hData.updateVelocity();
1525
1526 draggingEnding();
1527
1528 if (lastPosTime == -1)
1529 return;
1530
1531 hData.vTime = vData.vTime = timeline.time();
1532
1533 bool canBoost = false;
1534 const auto pos = event->points().first().position();
1535 const auto pressPos = q->mapFromGlobal(event->points().first().globalPressPosition());
1536 const QVector2D eventVelocity = firstPointLocalVelocity(event);
1537 qCDebug(lcVel) << event->deviceType() << event->type() << "velocity" << event->points().first().velocity() << "transformed to local" << eventVelocity;
1538
1539 qreal vVelocity = 0;
1540 if (elapsed < 100 && vData.velocity != 0.) {
1541 vVelocity = (event->device()->capabilities().testFlag(QInputDevice::Capability::Velocity)
1542 ? eventVelocity.y() : vData.velocity);
1543 }
1544 if ((vData.atBeginning && vVelocity > 0.) || (vData.atEnd && vVelocity < 0.)) {
1545 vVelocity /= 2;
1546 } else if (vData.continuousFlickVelocity != 0.0
1547 && vData.viewSize/q->height() > QML_FLICK_MULTIFLICK_RATIO
1548 && ((vVelocity > 0) == (vData.continuousFlickVelocity > 0))
1549 && qAbs(vVelocity) > QML_FLICK_MULTIFLICK_THRESHOLD) {
1550 // accelerate flick for large view flicked quickly
1551 canBoost = true;
1552 }
1553
1554 qreal hVelocity = 0;
1555 if (elapsed < 100 && hData.velocity != 0.) {
1556 hVelocity = (event->device()->capabilities().testFlag(QInputDevice::Capability::Velocity)
1557 ? eventVelocity.x() : hData.velocity);
1558 }
1559 if ((hData.atBeginning && hVelocity > 0.) || (hData.atEnd && hVelocity < 0.)) {
1560 hVelocity /= 2;
1561 } else if (hData.continuousFlickVelocity != 0.0
1562 && hData.viewSize/q->width() > QML_FLICK_MULTIFLICK_RATIO
1563 && ((hVelocity > 0) == (hData.continuousFlickVelocity > 0))
1564 && qAbs(hVelocity) > QML_FLICK_MULTIFLICK_THRESHOLD) {
1565 // accelerate flick for large view flicked quickly
1566 canBoost = true;
1567 }
1568
1569 flickBoost = canBoost ? qBound(1.0, flickBoost+0.25, QML_FLICK_MULTIFLICK_MAXBOOST) : 1.0;
1570 const int flickThreshold = QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::FlickStartDistance).toInt();
1571
1572 bool anyPointGrabbed = event->points().constEnd() !=
1573 std::find_if(event->points().constBegin(),event->points().constEnd(),
1574 [q, event](const QEventPoint &point) { return event->exclusiveGrabber(point) == q; });
1575
1576 bool flickedVertically = false;
1577 vVelocity *= flickBoost;
1578 const bool isVerticalFlickAllowed = anyPointGrabbed &&
1579 q->yflick() && qAbs(vVelocity) > _q_MinimumFlickVelocity &&
1580 qAbs(pos.y() - pressPos.y()) > flickThreshold;
1581 if (isVerticalFlickAllowed) {
1582 velocityTimeline.reset(vData.smoothVelocity);
1583 vData.smoothVelocity.setValue(-vVelocity);
1584 flickedVertically = flickY(event->type(), vVelocity);
1585 }
1586
1587 bool flickedHorizontally = false;
1588 hVelocity *= flickBoost;
1589 const bool isHorizontalFlickAllowed = anyPointGrabbed &&
1590 q->xflick() && qAbs(hVelocity) > _q_MinimumFlickVelocity &&
1591 qAbs(pos.x() - pressPos.x()) > flickThreshold;
1592 if (isHorizontalFlickAllowed) {
1593 velocityTimeline.reset(hData.smoothVelocity);
1594 hData.smoothVelocity.setValue(-hVelocity);
1595 flickedHorizontally = flickX(event->type(), hVelocity);
1596 }
1597
1598 if (!isVerticalFlickAllowed)
1599 fixupY();
1600
1601 if (!isHorizontalFlickAllowed)
1602 fixupX();
1603
1604 flickingStarted(flickedHorizontally, flickedVertically);
1605 if (!isViewMoving()) {
1606 q->movementEnding();
1607 } else {
1608 if (flickedVertically)
1609 vMoved = true;
1610 if (flickedHorizontally)
1611 hMoved = true;
1612 q->movementStarting();
1613 }
1614}
1615
1616bool QQuickFlickablePrivate::buttonsAccepted(const QSinglePointEvent *event)
1617{
1618 return !((event->button() & acceptedButtons) == 0 && (event->buttons() & acceptedButtons) == 0);
1619}
1620
1621void QQuickFlickable::mousePressEvent(QMouseEvent *event)
1622{
1623 Q_D(QQuickFlickable);
1624 if (d->interactive && !d->replayingPressEvent && d->buttonsAccepted(event) && d->wantsPointerEvent(event)) {
1625 if (!d->pressed)
1626 d->handlePressEvent(event);
1627 event->accept();
1628 } else {
1629 QQuickItem::mousePressEvent(event);
1630 }
1631}
1632
1633void QQuickFlickable::mouseMoveEvent(QMouseEvent *event)
1634{
1635 Q_D(QQuickFlickable);
1636 if (d->interactive && d->buttonsAccepted(event) && d->wantsPointerEvent(event)) {
1637 d->handleMoveEvent(event);
1638 event->accept();
1639 } else {
1640 QQuickItem::mouseMoveEvent(event);
1641 }
1642}
1643
1644void QQuickFlickable::mouseReleaseEvent(QMouseEvent *event)
1645{
1646 Q_D(QQuickFlickable);
1647 if (d->interactive && d->buttonsAccepted(event) && d->wantsPointerEvent(event)) {
1648 if (d->delayedPressEvent) {
1649 d->replayDelayedPress();
1650
1651 auto &firstPoint = event->point(0);
1652 if (const auto *grabber = event->exclusiveGrabber(firstPoint); grabber && grabber->isQuickItemType()) {
1653 // Since we sent the delayed press to the window, we need to resend the release to the window too.
1654 // We're not copying or detaching, so restore the original event position afterwards.
1655 const auto oldPosition = firstPoint.position();
1656 QMutableEventPoint::setPosition(firstPoint, event->scenePosition());
1657 QCoreApplication::sendEvent(window(), event);
1658 QMutableEventPoint::setPosition(firstPoint, oldPosition);
1659 }
1660
1661 // And the event has been consumed
1662 d->stealGrab = false;
1663 d->pressed = false;
1664 return;
1665 }
1666
1667 d->handleReleaseEvent(event);
1668 event->accept();
1669 } else {
1670 QQuickItem::mouseReleaseEvent(event);
1671 }
1672}
1673
1674void QQuickFlickable::touchEvent(QTouchEvent *event)
1675{
1676 Q_D(QQuickFlickable);
1677
1678 if (event->type() == QEvent::TouchCancel) {
1679 if (d->interactive && d->wantsPointerEvent(event))
1680 d->cancelInteraction();
1681 else
1682 QQuickItem::touchEvent(event);
1683 return;
1684 }
1685
1686 bool unhandled = false;
1687 const auto &firstPoint = event->points().first();
1688 switch (firstPoint.state()) {
1689 case QEventPoint::State::Pressed:
1690 if (d->interactive && !d->replayingPressEvent && d->wantsPointerEvent(event)) {
1691 if (!d->pressed)
1692 d->handlePressEvent(event);
1693 event->accept();
1694 } else {
1695 unhandled = true;
1696 }
1697 break;
1698 case QEventPoint::State::Updated:
1699 if (d->interactive && d->wantsPointerEvent(event)) {
1700 d->handleMoveEvent(event);
1701 event->accept();
1702 } else {
1703 unhandled = true;
1704 }
1705 break;
1706 case QEventPoint::State::Released:
1707 if (d->interactive && d->wantsPointerEvent(event)) {
1708 if (d->delayedPressEvent) {
1709 d->replayDelayedPress();
1710
1711 const auto &firstPoint = event->point(0);
1712 if (const auto *grabber = event->exclusiveGrabber(firstPoint); grabber && grabber->isQuickItemType()) {
1713 // Since we sent the delayed press to the window, we need to resend the release to the window too.
1714 QScopedPointer<QPointerEvent> localizedEvent(
1715 QQuickDeliveryAgentPrivate::clonePointerEvent(event, firstPoint.scenePosition()));
1716 QCoreApplication::sendEvent(window(), localizedEvent.data());
1717 }
1718
1719 // And the event has been consumed
1720 d->stealGrab = false;
1721 d->pressed = false;
1722 return;
1723 }
1724
1725 d->handleReleaseEvent(event);
1726 event->accept();
1727 } else {
1728 unhandled = true;
1729 }
1730 break;
1731 case QEventPoint::State::Stationary:
1732 case QEventPoint::State::Unknown:
1733 break;
1734 }
1735 if (unhandled)
1736 QQuickItem::touchEvent(event);
1737}
1738
1739#if QT_CONFIG(wheelevent)
1740void QQuickFlickable::wheelEvent(QWheelEvent *event)
1741{
1742 Q_D(QQuickFlickable);
1743 if (!d->interactive || !d->wantsPointerEvent(event)) {
1744 QQuickItem::wheelEvent(event);
1745 return;
1746 }
1747 qCDebug(lcWheel) << event->device() << event << event->source();
1748 event->setAccepted(false);
1749 qint64 currentTimestamp = d->computeCurrentTime(event);
1750 switch (event->phase()) {
1751 case Qt::ScrollBegin:
1752 d->scrollingPhase = true;
1753 d->accumulatedWheelPixelDelta = QVector2D();
1754 d->vData.velocity = 0;
1755 d->hData.velocity = 0;
1756 d->timer.start();
1757 d->maybeBeginDrag(currentTimestamp, event->position());
1758 d->lastPosTime = -1;
1759 break;
1760 case Qt::NoScrollPhase: // default phase with an ordinary wheel mouse
1761 case Qt::ScrollUpdate:
1762 if (d->scrollingPhase)
1763 d->pressed = true;
1764 break;
1765 case Qt::ScrollMomentum:
1766 d->pressed = false;
1767 d->scrollingPhase = false;
1768 d->draggingEnding();
1769 if (isMoving())
1770 event->accept();
1771 d->lastPosTime = -1;
1772 break;
1773 case Qt::ScrollEnd:
1774 d->pressed = false;
1775 d->scrollingPhase = false;
1776 d->draggingEnding();
1777 returnToBounds();
1778 d->lastPosTime = -1;
1779 d->stealGrab = false;
1780 if (!d->velocityTimeline.isActive() && !d->timeline.isActive())
1781 movementEnding(true, true);
1782 return;
1783 }
1784
1785 qreal elapsed = qreal(currentTimestamp - d->lastPosTime) / qreal(1000);
1786 if (elapsed <= 0) {
1787 d->lastPosTime = currentTimestamp;
1788 qCDebug(lcWheel) << "insufficient elapsed time: can't calculate velocity" << elapsed;
1789 return;
1790 }
1791
1792 // Within a touchpad gesture, pixelDelta rounds down to (0, 0) whenever the fingers
1793 // moved less than one pixel since the previous frame. Keep such a frame on the
1794 // pixelDelta path: falling back to angleDelta would start a wheel flick in the
1795 // middle of the ongoing drag.
1796 const bool isTouchpadFrameWithLostPixelDelta =
1797 event->deviceType() == QInputDevice::DeviceType::TouchPad
1798 && !event->angleDelta().isNull();
1799 if (event->source() == Qt::MouseEventNotSynthesized || event->phase() == Qt::NoScrollPhase
1800 || (event->pixelDelta().isNull() && !isTouchpadFrameWithLostPixelDelta)) {
1801 // no pixel delta (physical mouse wheel, or "dumb" touchpad), so use angleDelta
1802 int xDelta = event->angleDelta().x();
1803 int yDelta = event->angleDelta().y();
1804
1805 if (d->wheelDeceleration > _q_MaximumWheelDeceleration) {
1806 const qreal wheelScroll = -qApp->styleHints()->wheelScrollLines() * 24;
1807 // If wheelDeceleration is very large, i.e. the user or the platform does not want to have any mouse wheel
1808 // acceleration behavior, we want to move a distance proportional to QStyleHints::wheelScrollLines()
1809 if (yflick() && yDelta != 0) {
1810 d->moveReason = QQuickFlickablePrivate::Mouse; // ItemViews will set fixupMode to Immediate in fixup() without this.
1811 d->vMoved = true;
1812 qreal scrollPixel = (-yDelta / 120.0 * wheelScroll);
1813 bool acceptEvent = true; // Set to false if event should propagate to parent
1814 if (scrollPixel > 0) { // Forward direction (away from user)
1815 if (d->vData.move.value() >= minYExtent()) {
1816 d->vMoved = false;
1817 acceptEvent = false;
1818 }
1819 } else { // Backward direction (towards user)
1820 if (d->vData.move.value() <= maxYExtent()) {
1821 d->vMoved = false;
1822 acceptEvent = false;
1823 }
1824 }
1825 if (d->vMoved) {
1826 if (d->boundsBehavior == QQuickFlickable::StopAtBounds) {
1827 const qreal estContentPos = scrollPixel + d->vData.move.value();
1828 if (scrollPixel > 0) { // Forward direction (away from user)
1829 if (estContentPos > minYExtent()) {
1830 scrollPixel = minYExtent() - d->vData.move.value();
1831 acceptEvent = false;
1832 }
1833 } else { // Backward direction (towards user)
1834 if (estContentPos < maxYExtent()) {
1835 scrollPixel = maxYExtent() - d->vData.move.value();
1836 acceptEvent = false;
1837 }
1838 }
1839 }
1840 d->resetTimeline(d->vData);
1841 movementStarting();
1842 d->timeline.moveBy(d->vData.move, scrollPixel, QEasingCurve(QEasingCurve::OutExpo), 3*d->fixupDuration/4);
1843 d->vData.fixingUp = true;
1844 d->timeline.callback(QQuickTimeLineCallback(&d->vData.move, QQuickFlickablePrivate::fixupY_callback, d));
1845 }
1846 if (acceptEvent)
1847 event->accept();
1848 }
1849 if (xflick() && xDelta != 0) {
1850 d->moveReason = QQuickFlickablePrivate::Mouse; // ItemViews will set fixupMode to Immediate in fixup() without this.
1851 d->hMoved = true;
1852 qreal scrollPixel = (-xDelta / 120.0 * wheelScroll);
1853 bool acceptEvent = true; // Set to false if event should propagate to parent
1854 if (scrollPixel > 0) { // Forward direction (away from user)
1855 if (d->hData.move.value() >= minXExtent()) {
1856 d->hMoved = false;
1857 acceptEvent = false;
1858 }
1859 } else { // Backward direction (towards user)
1860 if (d->hData.move.value() <= maxXExtent()) {
1861 d->hMoved = false;
1862 acceptEvent = false;
1863 }
1864 }
1865 if (d->hMoved) {
1866 if (d->boundsBehavior == QQuickFlickable::StopAtBounds) {
1867 const qreal estContentPos = scrollPixel + d->hData.move.value();
1868 if (scrollPixel > 0) { // Forward direction (away from user)
1869 if (estContentPos > minXExtent()) {
1870 scrollPixel = minXExtent() - d->hData.move.value();
1871 acceptEvent = false;
1872 }
1873 } else { // Backward direction (towards user)
1874 if (estContentPos < maxXExtent()) {
1875 scrollPixel = maxXExtent() - d->hData.move.value();
1876 acceptEvent = false;
1877 }
1878 }
1879 }
1880 d->resetTimeline(d->hData);
1881 movementStarting();
1882 d->timeline.moveBy(d->hData.move, scrollPixel, QEasingCurve(QEasingCurve::OutExpo), 3*d->fixupDuration/4);
1883 d->hData.fixingUp = true;
1884 d->timeline.callback(QQuickTimeLineCallback(&d->hData.move, QQuickFlickablePrivate::fixupX_callback, d));
1885 }
1886 if (acceptEvent)
1887 event->accept();
1888 }
1889 } else {
1890 // wheelDeceleration is set to some reasonable value: the user or the platform wants to have
1891 // the classic Qt Quick mouse wheel acceleration behavior.
1892 // For a single "clicky" wheel event (angleDelta +/- 120),
1893 // we want flick() to end up moving a distance proportional to QStyleHints::wheelScrollLines().
1894 // The decel algo from there is
1895 // qreal dist = v2 / (accel * 2.0);
1896 // i.e. initialWheelFlickDistance = (120 / dt)^2 / (deceleration * 2)
1897 // now solve for dt:
1898 // dt = 120 / sqrt(deceleration * 2 * initialWheelFlickDistance)
1899 if (!isMoving())
1900 elapsed = 120 / qSqrt(d->wheelDeceleration * 2 * d->initialWheelFlickDistance);
1901 if (yflick() && yDelta != 0) {
1902 qreal instVelocity = yDelta / elapsed;
1903 // if the direction has changed, start over with filtering, to allow instant movement in the opposite direction
1904 if ((instVelocity < 0 && d->vData.velocity > 0) || (instVelocity > 0 && d->vData.velocity < 0)) {
1905 d->vData.velocitySamples = 0;
1906 d->vData.velocityWritePos = 0;
1907 }
1908 d->vData.addVelocitySample(instVelocity, d->maxVelocity);
1909 d->vData.updateVelocity();
1910 if ((yDelta > 0 && contentY() > -minYExtent()) || (yDelta < 0 && contentY() < -maxYExtent())) {
1911 const bool newFlick = d->flickY(event->type(), d->vData.velocity);
1912 if (newFlick && (d->vData.atBeginning != (yDelta > 0) || d->vData.atEnd != (yDelta < 0))) {
1913 d->flickingStarted(false, true);
1914 d->vMoved = true;
1915 movementStarting();
1916 }
1917 event->accept();
1918 }
1919 }
1920 if (xflick() && xDelta != 0) {
1921 qreal instVelocity = xDelta / elapsed;
1922 // if the direction has changed, start over with filtering, to allow instant movement in the opposite direction
1923 if ((instVelocity < 0 && d->hData.velocity > 0) || (instVelocity > 0 && d->hData.velocity < 0)) {
1924 d->hData.velocitySamples = 0;
1925 d->hData.velocityWritePos = 0;
1926 }
1927 d->hData.addVelocitySample(instVelocity, d->maxVelocity);
1928 d->hData.updateVelocity();
1929 if ((xDelta > 0 && contentX() > -minXExtent()) || (xDelta < 0 && contentX() < -maxXExtent())) {
1930 const bool newFlick = d->flickX(event->type(), d->hData.velocity);
1931 if (newFlick && (d->hData.atBeginning != (xDelta > 0) || d->hData.atEnd != (xDelta < 0))) {
1932 d->flickingStarted(true, false);
1933 d->hMoved = true;
1934 movementStarting();
1935 }
1936 event->accept();
1937 }
1938 }
1939 }
1940 } else {
1941 // use pixelDelta (probably from a trackpad): this is where we want to be on most platforms eventually
1942 int xDelta = event->pixelDelta().x();
1943 int yDelta = event->pixelDelta().y();
1944
1945 QVector2D velocity(xDelta / elapsed, yDelta / elapsed);
1946 d->accumulatedWheelPixelDelta += QVector2D(event->pixelDelta());
1947 // Try to drag if 1) we already are dragging or flicking, or
1948 // 2) the flickable is free to flick both directions, or
1949 // 3) the movement so far has been mostly horizontal AND it's free to flick horizontally, or
1950 // 4) the movement so far has been mostly vertical AND it's free to flick vertically.
1951 // Otherwise, wait until the next event. Wheel events with pixel deltas tend to come frequently.
1952 if (isMoving() || isFlicking() || (yflick() && xflick())
1953 || (xflick() && qAbs(d->accumulatedWheelPixelDelta.x()) > qAbs(d->accumulatedWheelPixelDelta.y() * 2))
1954 || (yflick() && qAbs(d->accumulatedWheelPixelDelta.y()) > qAbs(d->accumulatedWheelPixelDelta.x() * 2))) {
1955 d->drag(currentTimestamp, event->type(), event->position(), d->accumulatedWheelPixelDelta,
1956 true, !d->scrollingPhase, true, velocity);
1957 d->updateBeginningEnd();
1958 if ((xflick() && !isAtXBeginning() && !isAtXEnd()) || (yflick() && !isAtYBeginning() && !isAtYEnd()))
1959 event->accept();
1960 } else {
1961 qCDebug(lcWheel) << "not dragging: accumulated deltas" << d->accumulatedWheelPixelDelta <<
1962 "moving?" << isMoving() << "can flick horizontally?" << xflick() << "vertically?" << yflick();
1963 }
1964 }
1965 d->lastPosTime = currentTimestamp;
1966
1967 if (!event->isAccepted())
1968 QQuickItem::wheelEvent(event);
1969}
1970#endif
1971
1972bool QQuickFlickablePrivate::isInnermostPressDelay(QQuickItem *i) const
1973{
1974 Q_Q(const QQuickFlickable);
1975 QQuickItem *item = i;
1976 while (item) {
1977 QQuickFlickable *flick = qobject_cast<QQuickFlickable*>(item);
1978 if (flick && flick->pressDelay() > 0 && flick->isInteractive()) {
1979 // Found the innermost flickable with press delay - is it me?
1980 return (flick == q);
1981 }
1982 item = item->parentItem();
1983 }
1984 return false;
1985}
1986
1987void QQuickFlickablePrivate::captureDelayedPress(QQuickItem *item, QPointerEvent *event)
1988{
1989 Q_Q(QQuickFlickable);
1990 if (!q->window() || pressDelay <= 0)
1991 return;
1992
1993 // Only the innermost flickable should handle the delayed press; this allows
1994 // flickables up the parent chain to all see the events in their filter functions
1995 if (!isInnermostPressDelay(item))
1996 return;
1997
1998 delayedPressEvent = QQuickDeliveryAgentPrivate::clonePointerEvent(event);
1999 delayedPressEvent->setAccepted(false);
2000 delayedPressTimer.start(pressDelay, q);
2001 qCDebug(lcReplay) << "begin press delay" << pressDelay << "ms with" << delayedPressEvent;
2002}
2003
2004void QQuickFlickablePrivate::clearDelayedPress()
2005{
2006 if (delayedPressEvent) {
2007 delayedPressTimer.stop();
2008 qCDebug(lcReplay) << "clear delayed press" << delayedPressEvent;
2009 delete delayedPressEvent;
2010 delayedPressEvent = nullptr;
2011 }
2012}
2013
2014void QQuickFlickablePrivate::replayDelayedPress()
2015{
2016 Q_Q(QQuickFlickable);
2017 if (delayedPressEvent) {
2018 // Losing the grab will clear the delayed press event; take control of it here
2019 QScopedPointer<QPointerEvent> event(delayedPressEvent);
2020 delayedPressEvent = nullptr;
2021 delayedPressTimer.stop();
2022
2023 // If we have the grab, release before delivering the event
2024 if (QQuickWindow *window = q->window()) {
2025 auto da = deliveryAgentPrivate();
2026 da->allowChildEventFiltering = false; // don't allow re-filtering during replay
2027 replayingPressEvent = true;
2028 auto &firstPoint = event->point(0);
2029 // At first glance, it's weird for delayedPressEvent to already have a grabber;
2030 // but on press, filterMouseEvent() took the exclusive grab, and that's stored
2031 // in the device-specific EventPointData instance in QPointingDevicePrivate::activePoints,
2032 // not in the event itself. If this Flickable is still the grabber of that point on that device,
2033 // that's the reason; but now it doesn't need that grab anymore.
2034 if (event->exclusiveGrabber(firstPoint) == q)
2035 event->setExclusiveGrabber(firstPoint, nullptr);
2036
2037 qCDebug(lcReplay) << "replaying" << event.data();
2038 // Put scenePosition into position, for the sake of QQuickWindowPrivate::translateTouchEvent()
2039 // TODO remove this if we remove QQuickWindowPrivate::translateTouchEvent()
2040 QMutableEventPoint::setPosition(firstPoint, firstPoint.scenePosition());
2041 // Send it through like a fresh press event, and let QQuickWindow
2042 // (more specifically, QQuickWindowPrivate::deliverPressOrReleaseEvent)
2043 // find the item or handler that should receive it, as usual.
2044 QCoreApplication::sendEvent(window, event.data());
2045 qCDebug(lcReplay) << "replay done";
2046
2047 // We're done with replay, go back to normal delivery behavior
2048 replayingPressEvent = false;
2049 da->allowChildEventFiltering = true;
2050 }
2051 }
2052}
2053
2054//XXX pixelAligned ignores the global position of the Flickable, i.e. assumes Flickable itself is pixel aligned.
2055
2056/*!
2057 \internal
2058
2059 This function is called from the timeline,
2060 when advancement in the timeline is modifying the hData.move value.
2061 The \a x argument is the newly updated value in hData.move.
2062 The purpose of the function is to update the x position of the contentItem.
2063*/
2064void QQuickFlickablePrivate::setViewportX(qreal x)
2065{
2066 Q_Q(QQuickFlickable);
2067 qreal effectiveX = pixelAligned ? -std::round(-x) : x;
2068
2069 const qreal maxX = q->maxXExtent();
2070 const qreal minX = q->minXExtent();
2071
2072 if (boundsMovement == int(QQuickFlickable::StopAtBounds))
2073 effectiveX = qBound(maxX, effectiveX, minX);
2074
2075 contentItem->setX(effectiveX);
2076 if (contentItem->x() != effectiveX)
2077 return; // reentered
2078
2079 qreal overshoot = 0.0;
2080 if (x <= maxX)
2081 overshoot = maxX - x;
2082 else if (x >= minX)
2083 overshoot = minX - x;
2084
2085 if (overshoot != hData.overshoot) {
2086 hData.overshoot = overshoot;
2087 emit q->horizontalOvershootChanged();
2088 }
2089}
2090
2091/*!
2092 \internal
2093
2094 This function is called from the timeline,
2095 when advancement in the timeline is modifying the vData.move value.
2096 The \a y argument is the newly updated value in vData.move.
2097 The purpose of the function is to update the y position of the contentItem.
2098*/
2099void QQuickFlickablePrivate::setViewportY(qreal y)
2100{
2101 Q_Q(QQuickFlickable);
2102 qreal effectiveY = pixelAligned ? -std::round(-y) : y;
2103
2104 const qreal maxY = q->maxYExtent();
2105 const qreal minY = q->minYExtent();
2106
2107 if (boundsMovement == int(QQuickFlickable::StopAtBounds))
2108 effectiveY = qBound(maxY, effectiveY, minY);
2109
2110 contentItem->setY(effectiveY);
2111 if (contentItem->y() != effectiveY)
2112 return; // reentered
2113
2114 qreal overshoot = 0.0;
2115 if (y <= maxY)
2116 overshoot = maxY - y;
2117 else if (y >= minY)
2118 overshoot = minY - y;
2119
2120 if (overshoot != vData.overshoot) {
2121 vData.overshoot = overshoot;
2122 emit q->verticalOvershootChanged();
2123 }
2124}
2125
2126void QQuickFlickable::timerEvent(QTimerEvent *event)
2127{
2128 Q_D(QQuickFlickable);
2129 if (event->timerId() == d->delayedPressTimer.timerId()) {
2130 d->delayedPressTimer.stop();
2131 if (d->delayedPressEvent) {
2132 d->replayDelayedPress();
2133 }
2134 }
2135}
2136
2137qreal QQuickFlickable::minYExtent() const
2138{
2139 Q_D(const QQuickFlickable);
2140 return d->vData.startMargin;
2141}
2142
2143qreal QQuickFlickable::minXExtent() const
2144{
2145 Q_D(const QQuickFlickable);
2146 return d->hData.startMargin;
2147}
2148
2149/* returns -ve */
2150qreal QQuickFlickable::maxXExtent() const
2151{
2152 Q_D(const QQuickFlickable);
2153 return qMin<qreal>(minXExtent(), width() - vWidth() - d->hData.endMargin);
2154}
2155/* returns -ve */
2156qreal QQuickFlickable::maxYExtent() const
2157{
2158 Q_D(const QQuickFlickable);
2159 return qMin<qreal>(minYExtent(), height() - vHeight() - d->vData.endMargin);
2160}
2161
2162void QQuickFlickable::componentComplete()
2163{
2164 Q_D(QQuickFlickable);
2165 QQuickItem::componentComplete();
2166 if (!d->hData.explicitValue && d->hData.startMargin != 0.)
2167 setContentX(-minXExtent());
2168 if (!d->vData.explicitValue && d->vData.startMargin != 0.)
2169 setContentY(-minYExtent());
2170 if (lcWheel().isDebugEnabled() || lcVel().isDebugEnabled()) {
2171 d->timeline.setObjectName(QLatin1String("timeline for Flickable ") + objectName());
2172 d->velocityTimeline.setObjectName(QLatin1String("velocity timeline for Flickable ") + objectName());
2173 }
2174}
2175
2176void QQuickFlickable::viewportMoved(Qt::Orientations orient)
2177{
2178 Q_D(QQuickFlickable);
2179 if (orient & Qt::Vertical)
2180 d->viewportAxisMoved(d->vData, minYExtent(), maxYExtent(), d->fixupY_callback);
2181 if (orient & Qt::Horizontal)
2182 d->viewportAxisMoved(d->hData, minXExtent(), maxXExtent(), d->fixupX_callback);
2183 d->updateBeginningEnd();
2184}
2185
2186void QQuickFlickablePrivate::viewportAxisMoved(AxisData &data, qreal minExtent, qreal maxExtent,
2187 QQuickTimeLineCallback::Callback fixupCallback)
2188{
2189 if (!scrollingPhase && (pressed || calcVelocity)) {
2190 int elapsed = data.velocityTime.restart();
2191 if (elapsed > 0) {
2192 qreal velocity = (data.lastPos - data.move.value()) * 1000 / elapsed;
2193 if (qAbs(velocity) > 0) {
2194 velocityTimeline.reset(data.smoothVelocity);
2195 velocityTimeline.set(data.smoothVelocity, velocity);
2196 qCDebug(lcVel) << "touchpad scroll phase: velocity" << velocity;
2197 }
2198 }
2199 } else {
2200 if (timeline.time() > data.vTime) {
2201 velocityTimeline.reset(data.smoothVelocity);
2202 int dt = timeline.time() - data.vTime;
2203 if (dt > 2) {
2204 qreal velocity = (data.lastPos - data.move.value()) * 1000 / dt;
2205 if (!qFuzzyCompare(data.smoothVelocity.value(), velocity))
2206 qCDebug(lcVel) << "velocity" << data.smoothVelocity.value() << "->" << velocity
2207 << "computed as (" << data.lastPos << "-" << data.move.value() << ") * 1000 / ("
2208 << timeline.time() << "-" << data.vTime << ")";
2209 data.smoothVelocity.setValue(velocity);
2210 }
2211 }
2212 }
2213
2214 if (!data.inOvershoot && !data.fixingUp && data.flicking
2215 && (data.move.value() > minExtent || data.move.value() < maxExtent)
2216 && qAbs(data.smoothVelocity.value()) > 10) {
2217 // Increase deceleration if we've passed a bound
2218 qreal overBound = data.move.value() > minExtent
2219 ? data.move.value() - minExtent
2220 : maxExtent - data.move.value();
2221 data.inOvershoot = true;
2222 qreal maxDistance = overShootDistance(qAbs(data.smoothVelocity.value())) - overBound;
2223 resetTimeline(data);
2224 if (maxDistance > 0)
2225 timeline.accel(data.move, -data.smoothVelocity.value(), deceleration*QML_FLICK_OVERSHOOTFRICTION, maxDistance);
2226 timeline.callback(QQuickTimeLineCallback(&data.move, fixupCallback, this));
2227 }
2228
2229 data.lastPos = data.move.value();
2230 data.vTime = timeline.time();
2231}
2232
2233void QQuickFlickable::geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry)
2234{
2235 Q_D(QQuickFlickable);
2236 QQuickItem::geometryChange(newGeometry, oldGeometry);
2237
2238 bool changed = false;
2239 if (newGeometry.width() != oldGeometry.width()) {
2240 changed = true; // we must update visualArea.widthRatio
2241 if (d->hData.viewSize < 0)
2242 d->contentItem->setWidth(width() - d->hData.startMargin - d->hData.endMargin);
2243 // Make sure that we're entirely in view.
2244 if (!d->pressed && !d->hData.moving && !d->vData.moving) {
2245 d->fixupMode = QQuickFlickablePrivate::Immediate;
2246 d->fixupX();
2247 }
2248 }
2249 if (newGeometry.height() != oldGeometry.height()) {
2250 changed = true; // we must update visualArea.heightRatio
2251 if (d->vData.viewSize < 0)
2252 d->contentItem->setHeight(height() - d->vData.startMargin - d->vData.endMargin);
2253 // Make sure that we're entirely in view.
2254 if (!d->pressed && !d->hData.moving && !d->vData.moving) {
2255 d->fixupMode = QQuickFlickablePrivate::Immediate;
2256 d->fixupY();
2257 }
2258 }
2259
2260 if (changed)
2261 d->updateBeginningEnd();
2262}
2263
2264/*!
2265 \qmlmethod void QtQuick::Flickable::flick(qreal xVelocity, qreal yVelocity)
2266
2267 Flicks the content with \a xVelocity horizontally and \a yVelocity vertically in pixels/sec.
2268
2269 Calling this method will update the corresponding moving and flicking properties and signals,
2270 just like a real touchscreen flick.
2271*/
2272
2273void QQuickFlickable::flick(qreal xVelocity, qreal yVelocity)
2274{
2275 Q_D(QQuickFlickable);
2276 d->hData.reset();
2277 d->vData.reset();
2278 d->hData.velocity = xVelocity;
2279 d->vData.velocity = yVelocity;
2280 d->hData.vTime = d->vData.vTime = d->timeline.time();
2281
2282 const bool flickedX = xflick() && !qFuzzyIsNull(xVelocity) && d->flickX(QEvent::TouchUpdate, xVelocity);
2283 const bool flickedY = yflick() && !qFuzzyIsNull(yVelocity) && d->flickY(QEvent::TouchUpdate, yVelocity);
2284
2285 if (flickedX)
2286 d->hMoved = true;
2287 if (flickedY)
2288 d->vMoved = true;
2289 movementStarting();
2290 d->flickingStarted(flickedX, flickedY);
2291}
2292
2293void QQuickFlickablePrivate::flickingStarted(bool flickingH, bool flickingV)
2294{
2295 Q_Q(QQuickFlickable);
2296 if (!flickingH && !flickingV)
2297 return;
2298
2299 bool wasFlicking = hData.flicking || vData.flicking;
2300 if (flickingH && !hData.flicking) {
2301 hData.flicking = true;
2302 emit q->flickingHorizontallyChanged();
2303 }
2304 if (flickingV && !vData.flicking) {
2305 vData.flicking = true;
2306 emit q->flickingVerticallyChanged();
2307 }
2308 if (!wasFlicking && (hData.flicking || vData.flicking)) {
2309 emit q->flickingChanged();
2310 emit q->flickStarted();
2311 }
2312}
2313
2314/*!
2315 \qmlmethod void QtQuick::Flickable::cancelFlick()
2316
2317 Cancels the current flick animation.
2318*/
2319
2320void QQuickFlickable::cancelFlick()
2321{
2322 Q_D(QQuickFlickable);
2323 d->resetTimeline(d->hData);
2324 d->resetTimeline(d->vData);
2325 movementEnding();
2326}
2327
2328/*!
2329 \qmlmethod void QtQuick::Flickable::positionViewAtChild(QQuickItem *child, PositionMode mode, point offset)
2330 \since 6.11
2331
2332 Positions \l {Flickable::}{contentX} and \l {Flickable::}{contentY} such
2333 that \a child item (if it is a child) is at the position specified by \a mode. \a mode
2334 can be an or-ed combination of the following:
2335
2336 \value Flickable.AlignLeft Position the child at the left of the view.
2337 \value Flickable.AlignHCenter Position the child at the horizontal center of the view.
2338 \value Flickable.AlignRight Position the child at the right of the view.
2339 \value Flickable.AlignTop Position the child at the top of the view.
2340 \value Flickable.AlignVCenter Position the child at the vertical center of the view.
2341 \value Flickable.AlignBottom Position the child at the bottom of the view.
2342 \value Flickable.AlignCenter The same as (Flickable.AlignHCenter | Flickable.AlignVCenter)
2343 \value Flickable.Visible If any part of the child is visible then take no action. Otherwise
2344 move the content item so that the entire child becomes visible.
2345 \value Flickable.Contain If the entire child is visible then take no action. Otherwise
2346 move the content item so that the entire child becomes visible. If the child is
2347 bigger than the view, the top-left part of the child will be preferred.
2348
2349 If no vertical alignment is specified, vertical positioning will be ignored.
2350 The same is true for horizontal alignment.
2351
2352 Optionally, you can specify \a offset to move \e contentX and \e contentY an extra number of
2353 pixels beyond the target alignment.
2354
2355 If positioning the flickable at the child item would cause empty space to be displayed at the
2356 beginning or end of the flickable, the flickable will be positioned at the boundary.
2357
2358 \snippet qml/flickablePositionActiveFocusPosition.qml 0
2359*/
2360
2361void QQuickFlickable::positionViewAtChild(QQuickItem *child, PositionMode mode, const QPointF &offset)
2362{
2363 Q_D(QQuickFlickable);
2364 cancelFlick();
2365
2366 if (!d->contentItem->isAncestorOf(child))
2367 return;
2368
2369 const QRectF itemRect =
2370 child->mapRectToItem(d->contentItem, QRectF(0, 0, child->width(), child->height()));
2371
2372 QPointF currentPosition = QPointF(contentX(), contentY());
2373 QPointF newPosition = computePosition(currentPosition, itemRect, mode, offset);
2374
2375 if (newPosition.x() != currentPosition.x()) {
2376 setContentX(newPosition.x());
2377 d->fixupX();
2378 }
2379 if (newPosition.y() != currentPosition.y()) {
2380 setContentY(newPosition.y());
2381 d->fixupY();
2382 }
2383}
2384
2385/*!
2386 \qmlmethod void QtQuick::Flickable::flickToChild(QQuickItem *child, PositionMode mode, point offset)
2387 \since 6.11
2388
2389 Flicks the flickable such that \a child item (if it is a child) is at the position
2390 specified by \a mode. \a mode can be an or-ed combination of the following:
2391
2392 \value Flickable.AlignLeft Flick the child at the left of the view.
2393 \value Flickable.AlignHCenter Flick the child at the horizontal center of the view.
2394 \value Flickable.AlignRight Flick the child at the right of the view.
2395 \value Flickable.AlignTop Flick the child at the top of the view.
2396 \value Flickable.AlignVCenter Flick the child at the vertical center of the view.
2397 \value Flickable.AlignBottom Flick the child at the bottom of the view.
2398 \value Flickable.AlignCenter The same as (Flickable.AlignHCenter | Flickable.AlignVCenter)
2399 \value Flickable.Visible If any part of the child is visible then take no action. Otherwise
2400 move the content item so that the entire child becomes visible.
2401 \value Flickable.Contain If the entire child is visible then take no action. Otherwise
2402 move the content item so that the entire child becomes visible. If the child is
2403 bigger than the view, the top-left part of the child will be preferred.
2404
2405 If no vertical alignment is specified, vertical flicking will be ignored.
2406 The same is true for horizontal alignment.
2407
2408 Optionally, you can specify \a offset to flick an extra number of
2409 pixels beyond the target alignment.
2410
2411 If flicking the flickable at the child item would cause empty space to be displayed at the
2412 beginning or end of the flickable, the flickable will stop flicking at the boundary.
2413
2414 \snippet qml/flickableFlickActiveFocusPosition.qml 0
2415*/
2416
2417void QQuickFlickable::flickToChild(QQuickItem *child, PositionMode mode, const QPointF &offset)
2418{
2419 Q_D(QQuickFlickable);
2420 cancelFlick();
2421
2422 if (!d->contentItem->isAncestorOf(child))
2423 return;
2424
2425 const QRectF itemRect =
2426 child->mapRectToItem(d->contentItem, QRectF(0, 0, child->width(), child->height()));
2427
2428 QPointF currentPosition = QPointF(contentX(), contentY());
2429 QPointF newPosition = computePosition(currentPosition, itemRect, mode, offset);
2430
2431 flickTo(newPosition);
2432}
2433
2434/*!
2435 \qmlmethod void QtQuick::Flickable::flickTo(point position)
2436 \since 6.11
2437
2438 Flicks the flickable to \a position.
2439
2440 If flicking the flickable would cause empty space to be displayed at the
2441 beginning or end of the flickable, the flickable will stop flicking at the boundary.
2442*/
2443
2444void QQuickFlickable::flickTo(const QPointF &newPosition)
2445{
2446 Q_D(QQuickFlickable);
2447
2448 QPointF currentPosition = QPointF(contentX(), contentY());
2449
2450 qreal xVelocity = 0.0;
2451 qreal yVelocity = 0.0;
2452
2453 const qreal deltaX = newPosition.x() - currentPosition.x();
2454 const qreal deltaY = newPosition.y() - currentPosition.y();
2455
2456 // Calculate velocity based on distance to travel
2457 // Formula: v = sqrt(2 * deceleration * distance)
2458
2459 if (xflick() && qAbs(deltaX) > 0.5) {
2460 const qreal decel = flickDeceleration();
2461 qreal velocity = qSqrt(2.0 * decel * qAbs(deltaX));
2462 if (qAbs(velocity) < _q_MinimumFlickVelocity)
2463 velocity = 0;
2464 const qreal maxVel = maximumFlickVelocity();
2465 if (maxVel > 0 && velocity > maxVel)
2466 velocity = maxVel;
2467 xVelocity = deltaX > 0 ? -velocity : velocity;
2468 }
2469
2470 if (yflick() && qAbs(deltaY) > 0.5) {
2471 const qreal decel = flickDeceleration();
2472 qreal velocity = qSqrt(2.0 * decel * qAbs(deltaY));
2473 if (qAbs(velocity) < _q_MinimumFlickVelocity)
2474 velocity = 0;
2475 const qreal maxVel = maximumFlickVelocity();
2476 if (maxVel > 0 && velocity > maxVel)
2477 velocity = maxVel;
2478 yVelocity = deltaY > 0 ? -velocity : velocity;
2479 }
2480
2481 if (qAbs(xVelocity) > 0.0 || qAbs(yVelocity) > 0.0) {
2482 flick(xVelocity, yVelocity);
2483 } else {
2484 if (newPosition.x() != currentPosition.x()) {
2485 setContentX(newPosition.x());
2486 d->fixupX();
2487 }
2488 if (newPosition.y() != currentPosition.y()) {
2489 setContentY(newPosition.y());
2490 d->fixupY();
2491 }
2492 }
2493}
2494
2495void QQuickFlickablePrivate::data_append(QQmlListProperty<QObject> *prop, QObject *o)
2496{
2497 if (!prop || !prop->data)
2498 return;
2499
2500 if (QQuickItem *i = qmlobject_cast<QQuickItem *>(o)) {
2501 i->setParentItem(static_cast<QQuickFlickablePrivate*>(prop->data)->contentItem);
2502 } else if (QQuickPointerHandler *pointerHandler = qmlobject_cast<QQuickPointerHandler *>(o)) {
2503 static_cast<QQuickFlickablePrivate*>(prop->data)->addPointerHandler(pointerHandler);
2504 } else {
2505 o->setParent(prop->object); // XXX todo - do we want this?
2506 }
2507}
2508
2509qsizetype QQuickFlickablePrivate::data_count(QQmlListProperty<QObject> *)
2510{
2511 // XXX todo
2512 return 0;
2513}
2514
2515QObject *QQuickFlickablePrivate::data_at(QQmlListProperty<QObject> *, qsizetype)
2516{
2517 // XXX todo
2518 return nullptr;
2519}
2520
2521void QQuickFlickablePrivate::data_clear(QQmlListProperty<QObject> *)
2522{
2523 // XXX todo
2524}
2525
2526QQmlListProperty<QObject> QQuickFlickable::flickableData()
2527{
2528 Q_D(QQuickFlickable);
2529 return QQmlListProperty<QObject>(this, (void *)d, QQuickFlickablePrivate::data_append,
2530 QQuickFlickablePrivate::data_count,
2531 QQuickFlickablePrivate::data_at,
2532 QQuickFlickablePrivate::data_clear);
2533}
2534
2535QQmlListProperty<QQuickItem> QQuickFlickable::flickableChildren()
2536{
2537 Q_D(QQuickFlickable);
2538 return QQuickItemPrivate::get(d->contentItem)->children();
2539}
2540
2541/*!
2542 \qmlproperty enumeration QtQuick::Flickable::boundsBehavior
2543 This property holds whether the surface may be dragged
2544 beyond the Flickable's boundaries, or overshoot the
2545 Flickable's boundaries when flicked.
2546
2547 When the \l boundsMovement is \c Flickable.FollowBoundsBehavior, a value
2548 other than \c Flickable.StopAtBounds will give a feeling that the edges of
2549 the view are soft, rather than a hard physical boundary.
2550
2551 The \c boundsBehavior can be one of:
2552
2553 \list
2554 \li Flickable.StopAtBounds - the contents can not be dragged beyond the boundary
2555 of the flickable, and flicks will not overshoot.
2556 \li Flickable.DragOverBounds - the contents can be dragged beyond the boundary
2557 of the Flickable, but flicks will not overshoot.
2558 \li Flickable.OvershootBounds - the contents can overshoot the boundary when flicked,
2559 but the content cannot be dragged beyond the boundary of the flickable. (since \c{QtQuick 2.5})
2560 \li Flickable.DragAndOvershootBounds (default) - the contents can be dragged
2561 beyond the boundary of the Flickable, and can overshoot the
2562 boundary when flicked.
2563 \endlist
2564
2565 \sa horizontalOvershoot, verticalOvershoot, boundsMovement
2566*/
2567QQuickFlickable::BoundsBehavior QQuickFlickable::boundsBehavior() const
2568{
2569 Q_D(const QQuickFlickable);
2570 return d->boundsBehavior;
2571}
2572
2573void QQuickFlickable::setBoundsBehavior(BoundsBehavior b)
2574{
2575 Q_D(QQuickFlickable);
2576 if (b == d->boundsBehavior)
2577 return;
2578 d->boundsBehavior = b;
2579 emit boundsBehaviorChanged();
2580}
2581
2582/*!
2583 \qmlproperty Transition QtQuick::Flickable::rebound
2584
2585 This holds the transition to be applied to the content view when
2586 it snaps back to the bounds of the flickable. The transition is
2587 triggered when the view is flicked or dragged past the edge of the
2588 content area, or when returnToBounds() is called.
2589
2590 \qml
2591 import QtQuick 2.0
2592
2593 Flickable {
2594 width: 150; height: 150
2595 contentWidth: 300; contentHeight: 300
2596
2597 rebound: Transition {
2598 NumberAnimation {
2599 properties: "x,y"
2600 duration: 1000
2601 easing.type: Easing.OutBounce
2602 }
2603 }
2604
2605 Rectangle {
2606 width: 300; height: 300
2607 gradient: Gradient {
2608 GradientStop { position: 0.0; color: "lightsteelblue" }
2609 GradientStop { position: 1.0; color: "blue" }
2610 }
2611 }
2612 }
2613 \endqml
2614
2615 When the above view is flicked beyond its bounds, it will return to its
2616 bounds using the transition specified:
2617
2618 \image flickable-rebound.gif {Flickable content bouncing back
2619 after being dragged beyond its bounds}
2620
2621 If this property is not set, a default animation is applied.
2622 */
2623QQuickTransition *QQuickFlickable::rebound() const
2624{
2625 Q_D(const QQuickFlickable);
2626 return d->rebound;
2627}
2628
2629void QQuickFlickable::setRebound(QQuickTransition *transition)
2630{
2631 Q_D(QQuickFlickable);
2632 if (transition) {
2633 if (!d->hData.transitionToBounds)
2634 d->hData.transitionToBounds = new QQuickFlickableReboundTransition(this, QLatin1String("x"));
2635 if (!d->vData.transitionToBounds)
2636 d->vData.transitionToBounds = new QQuickFlickableReboundTransition(this, QLatin1String("y"));
2637 }
2638 if (d->rebound != transition) {
2639 d->rebound = transition;
2640 emit reboundChanged();
2641 }
2642}
2643
2644/*!
2645 \qmlproperty real QtQuick::Flickable::contentWidth
2646 \qmlproperty real QtQuick::Flickable::contentHeight
2647
2648 The dimensions of the content (the surface controlled by Flickable).
2649 This should typically be set to the combined size of the items placed in the
2650 Flickable.
2651
2652 The following snippet shows how these properties are used to display
2653 an image that is larger than the Flickable item itself:
2654
2655 \snippet qml/flickable.qml document
2656
2657 In some cases, the content dimensions can be automatically set
2658 based on the \l {Item::childrenRect.width}{childrenRect.width}
2659 and \l {Item::childrenRect.height}{childrenRect.height} properties
2660 of the \l contentItem. For example, the previous snippet could be rewritten with:
2661
2662 \code
2663 contentWidth: contentItem.childrenRect.width; contentHeight: contentItem.childrenRect.height
2664 \endcode
2665
2666 Though this assumes that the origin of the childrenRect is 0,0.
2667*/
2668qreal QQuickFlickable::contentWidth() const
2669{
2670 Q_D(const QQuickFlickable);
2671 return d->hData.viewSize;
2672}
2673
2674void QQuickFlickable::setContentWidth(qreal w)
2675{
2676 Q_D(QQuickFlickable);
2677 if (d->hData.viewSize == w)
2678 return;
2679 d->hData.viewSize = w;
2680 if (w < 0)
2681 d->contentItem->setWidth(width() - d->hData.startMargin - d->hData.endMargin);
2682 else
2683 d->contentItem->setWidth(w);
2684 d->hData.markExtentsDirty();
2685 // Make sure that we're entirely in view.
2686 if (!d->pressed && !d->hData.moving && !d->vData.moving) {
2687 d->fixupMode = QQuickFlickablePrivate::Immediate;
2688 d->fixupX();
2689 } else if (!d->pressed && d->hData.fixingUp) {
2690 d->fixupMode = QQuickFlickablePrivate::ExtentChanged;
2691 d->fixupX();
2692 }
2693 emit contentWidthChanged();
2694 d->updateBeginningEnd();
2695}
2696
2697qreal QQuickFlickable::contentHeight() const
2698{
2699 Q_D(const QQuickFlickable);
2700 return d->vData.viewSize;
2701}
2702
2703void QQuickFlickable::setContentHeight(qreal h)
2704{
2705 Q_D(QQuickFlickable);
2706 if (d->vData.viewSize == h)
2707 return;
2708 d->vData.viewSize = h;
2709 if (h < 0)
2710 d->contentItem->setHeight(height() - d->vData.startMargin - d->vData.endMargin);
2711 else
2712 d->contentItem->setHeight(h);
2713 d->vData.markExtentsDirty();
2714 // Make sure that we're entirely in view.
2715 if (!d->pressed && !d->hData.moving && !d->vData.moving) {
2716 d->fixupMode = QQuickFlickablePrivate::Immediate;
2717 d->fixupY();
2718 } else if (!d->pressed && d->vData.fixingUp) {
2719 d->fixupMode = QQuickFlickablePrivate::ExtentChanged;
2720 d->fixupY();
2721 }
2722 emit contentHeightChanged();
2723 d->updateBeginningEnd();
2724}
2725
2726/*!
2727 \qmlproperty real QtQuick::Flickable::topMargin
2728 \qmlproperty real QtQuick::Flickable::leftMargin
2729 \qmlproperty real QtQuick::Flickable::bottomMargin
2730 \qmlproperty real QtQuick::Flickable::rightMargin
2731
2732 These properties hold the margins around the content. This space is reserved
2733 in addition to the contentWidth and contentHeight.
2734*/
2735
2736
2737qreal QQuickFlickable::topMargin() const
2738{
2739 Q_D(const QQuickFlickable);
2740 return d->vData.startMargin;
2741}
2742
2743void QQuickFlickable::setTopMargin(qreal m)
2744{
2745 Q_D(QQuickFlickable);
2746 if (d->vData.startMargin == m)
2747 return;
2748 d->vData.startMargin = m;
2749 d->vData.markExtentsDirty();
2750 if (!d->pressed && !d->hData.moving && !d->vData.moving) {
2751 // FIXME: We're not consistently updating the contentY, see QTBUG-131478
2752 d->fixupMode = QQuickFlickablePrivate::Immediate;
2753 d->fixupY();
2754 }
2755 emit topMarginChanged();
2756 d->updateBeginningEnd();
2757}
2758
2759qreal QQuickFlickable::bottomMargin() const
2760{
2761 Q_D(const QQuickFlickable);
2762 return d->vData.endMargin;
2763}
2764
2765void QQuickFlickable::setBottomMargin(qreal m)
2766{
2767 Q_D(QQuickFlickable);
2768 if (d->vData.endMargin == m)
2769 return;
2770 d->vData.endMargin = m;
2771 d->vData.markExtentsDirty();
2772 if (!d->pressed && !d->hData.moving && !d->vData.moving) {
2773 // FIXME: We're not consistently updating the contentY, see QTBUG-131478
2774 d->fixupMode = QQuickFlickablePrivate::Immediate;
2775 d->fixupY();
2776 }
2777 emit bottomMarginChanged();
2778 d->updateBeginningEnd();
2779}
2780
2781qreal QQuickFlickable::leftMargin() const
2782{
2783 Q_D(const QQuickFlickable);
2784 return d->hData.startMargin;
2785}
2786
2787void QQuickFlickable::setLeftMargin(qreal m)
2788{
2789 Q_D(QQuickFlickable);
2790 if (d->hData.startMargin == m)
2791 return;
2792 d->hData.startMargin = m;
2793 d->hData.markExtentsDirty();
2794 if (!d->pressed && !d->hData.moving && !d->vData.moving) {
2795 // FIXME: We're not consistently updating the contentX, see QTBUG-131478
2796 d->fixupMode = QQuickFlickablePrivate::Immediate;
2797 d->fixupX();
2798 }
2799 emit leftMarginChanged();
2800 d->updateBeginningEnd();
2801}
2802
2803qreal QQuickFlickable::rightMargin() const
2804{
2805 Q_D(const QQuickFlickable);
2806 return d->hData.endMargin;
2807}
2808
2809void QQuickFlickable::setRightMargin(qreal m)
2810{
2811 Q_D(QQuickFlickable);
2812 if (d->hData.endMargin == m)
2813 return;
2814 d->hData.endMargin = m;
2815 d->hData.markExtentsDirty();
2816 if (!d->pressed && !d->hData.moving && !d->vData.moving) {
2817 // FIXME: We're not consistently updating the contentX, see QTBUG-131478
2818 d->fixupMode = QQuickFlickablePrivate::Immediate;
2819 d->fixupX();
2820 }
2821 emit rightMarginChanged();
2822 d->updateBeginningEnd();
2823}
2824
2825/*!
2826 \qmlproperty real QtQuick::Flickable::originX
2827 \qmlproperty real QtQuick::Flickable::originY
2828
2829 These properties hold the origin of the content. This value always refers
2830 to the top-left position of the content regardless of layout direction.
2831
2832 This is usually (0,0), however ListView and GridView may have an arbitrary
2833 origin due to delegate size variation, or item insertion/removal outside
2834 the visible region.
2835
2836 \sa contentX, contentY
2837*/
2838
2839qreal QQuickFlickable::originY() const
2840{
2841 Q_D(const QQuickFlickable);
2842 return -minYExtent() + d->vData.startMargin;
2843}
2844
2845qreal QQuickFlickable::originX() const
2846{
2847 Q_D(const QQuickFlickable);
2848 return -minXExtent() + d->hData.startMargin;
2849}
2850
2851
2852/*!
2853 \qmlmethod void QtQuick::Flickable::resizeContent(real width, real height, point center)
2854
2855 Resizes the content to \a width x \a height about \a center.
2856
2857 This does not scale the contents of the Flickable - it only resizes the \l contentWidth
2858 and \l contentHeight.
2859
2860 Resizing the content may result in the content being positioned outside
2861 the bounds of the Flickable. Calling \l returnToBounds() will
2862 move the content back within legal bounds.
2863*/
2864void QQuickFlickable::resizeContent(qreal w, qreal h, QPointF center)
2865{
2866 Q_D(QQuickFlickable);
2867 const qreal oldHSize = d->hData.viewSize;
2868 const qreal oldVSize = d->vData.viewSize;
2869 const bool needToUpdateWidth = w != oldHSize;
2870 const bool needToUpdateHeight = h != oldVSize;
2871 d->hData.viewSize = w;
2872 d->vData.viewSize = h;
2873 d->contentItem->setSize(QSizeF(w, h));
2874 if (needToUpdateWidth)
2875 emit contentWidthChanged();
2876 if (needToUpdateHeight)
2877 emit contentHeightChanged();
2878
2879 if (center.x() != 0) {
2880 qreal pos = center.x() * w / oldHSize;
2881 setContentX(contentX() + pos - center.x());
2882 }
2883 if (center.y() != 0) {
2884 qreal pos = center.y() * h / oldVSize;
2885 setContentY(contentY() + pos - center.y());
2886 }
2887 d->updateBeginningEnd();
2888}
2889
2890/*!
2891 \qmlmethod void QtQuick::Flickable::returnToBounds()
2892
2893 Ensures the content is within legal bounds.
2894
2895 This may be called to ensure that the content is within legal bounds
2896 after manually positioning the content.
2897*/
2898void QQuickFlickable::returnToBounds()
2899{
2900 Q_D(QQuickFlickable);
2901 d->fixupX();
2902 d->fixupY();
2903}
2904
2905qreal QQuickFlickable::vWidth() const
2906{
2907 Q_D(const QQuickFlickable);
2908 if (d->hData.viewSize < 0)
2909 return width();
2910 else
2911 return d->hData.viewSize;
2912}
2913
2914qreal QQuickFlickable::vHeight() const
2915{
2916 Q_D(const QQuickFlickable);
2917 if (d->vData.viewSize < 0)
2918 return height();
2919 else
2920 return d->vData.viewSize;
2921}
2922
2923/*!
2924 \internal
2925
2926 The setFlickableDirection function can be used to set constraints on which axis the contentItem can be flicked along.
2927
2928 \return true if the flickable is allowed to flick in the horizontal direction, otherwise returns false
2929*/
2930bool QQuickFlickable::xflick() const
2931{
2932 Q_D(const QQuickFlickable);
2933 const int contentWidthWithMargins = d->contentItem->width() + d->hData.startMargin + d->hData.endMargin;
2934 if ((d->flickableDirection & QQuickFlickable::AutoFlickIfNeeded) && (contentWidthWithMargins > width()))
2935 return true;
2936 if (d->flickableDirection == QQuickFlickable::AutoFlickDirection)
2937 return std::floor(qAbs(contentWidthWithMargins - width()));
2938 return d->flickableDirection & QQuickFlickable::HorizontalFlick;
2939}
2940
2941/*!
2942 \internal
2943
2944 The setFlickableDirection function can be used to set constraints on which axis the contentItem can be flicked along.
2945
2946 \return true if the flickable is allowed to flick in the vertical direction, otherwise returns false.
2947*/
2948bool QQuickFlickable::yflick() const
2949{
2950 Q_D(const QQuickFlickable);
2951 const int contentHeightWithMargins = d->contentItem->height() + d->vData.startMargin + d->vData.endMargin;
2952 if ((d->flickableDirection & QQuickFlickable::AutoFlickIfNeeded) && (contentHeightWithMargins > height()))
2953 return true;
2954 if (d->flickableDirection == QQuickFlickable::AutoFlickDirection)
2955 return std::floor(qAbs(contentHeightWithMargins - height()));
2956 return d->flickableDirection & QQuickFlickable::VerticalFlick;
2957}
2958
2959QPointF QQuickFlickable::computePosition(QPointF currentPosition, QRectF itemRect, PositionMode mode, const QPointF &offset) const
2960{
2961 QPointF newPosition = currentPosition;
2962
2963 if (xflick()) {
2964 const qreal viewWidth = width();
2965
2966 if (mode & QQuickFlickable::AlignLeft)
2967 newPosition.setX(itemRect.left());
2968 if (mode & QQuickFlickable::AlignHCenter)
2969 newPosition.setX(itemRect.left() - (viewWidth - itemRect.width()) / 2);
2970 if (mode & QQuickFlickable::AlignRight)
2971 newPosition.setX(itemRect.right() - viewWidth);
2972 if (mode & QQuickFlickable::Visible) {
2973 if (itemRect.right() < currentPosition.x())
2974 newPosition.setX(itemRect.left());
2975 else if (itemRect.left() > currentPosition.x() + viewWidth)
2976 newPosition.setX(itemRect.right() - viewWidth);
2977 }
2978 if (mode & QQuickFlickable::Contain) {
2979 if (itemRect.right() > currentPosition.x() + viewWidth)
2980 newPosition.setX(itemRect.right() - viewWidth);
2981 if (itemRect.left() < newPosition.x())
2982 newPosition.setX(itemRect.left());
2983 }
2984
2985 const qreal minX = -minXExtent();
2986 const qreal maxX = -maxXExtent();
2987 newPosition.setX(qMin(newPosition.x(), maxX));
2988 newPosition.setX(qMax(newPosition.x(), minX));
2989 }
2990
2991 if (yflick()) {
2992 const qreal viewHeight = height();
2993
2994 if (mode & QQuickFlickable::AlignTop)
2995 newPosition.setY(itemRect.top());
2996 if (mode & QQuickFlickable::AlignVCenter)
2997 newPosition.setY(itemRect.top() - (viewHeight - itemRect.height()) / 2);
2998 if (mode & QQuickFlickable::AlignBottom)
2999 newPosition.setY(itemRect.bottom() - viewHeight);
3000 if (mode & QQuickFlickable::Visible) {
3001 if (itemRect.bottom() < currentPosition.y())
3002 newPosition.setY(itemRect.top());
3003 else if (itemRect.top() > currentPosition.y() + viewHeight)
3004 newPosition.setY(itemRect.bottom() - viewHeight);
3005 }
3006 if (mode & QQuickFlickable::Contain) {
3007 if (itemRect.bottom() > currentPosition.y() + viewHeight)
3008 newPosition.setY(itemRect.bottom() - viewHeight);
3009 if (itemRect.top() < currentPosition.y())
3010 newPosition.setY(itemRect.top());
3011 }
3012
3013 const qreal minY = -minYExtent();
3014 const qreal maxY = -maxYExtent();
3015 newPosition.setY(qMin(newPosition.y(), maxY));
3016 newPosition.setY(qMax(newPosition.y(), minY));
3017 }
3018
3019 return newPosition + offset;
3020}
3021
3022void QQuickFlickable::mouseUngrabEvent()
3023{
3024 Q_D(QQuickFlickable);
3025 // if our mouse grab has been removed (probably by another Flickable),
3026 // fix our state
3027 if (!d->replayingPressEvent)
3028 d->cancelInteraction();
3029}
3030
3031void QQuickFlickablePrivate::cancelInteraction()
3032{
3033 Q_Q(QQuickFlickable);
3034 if (pressed) {
3035 clearDelayedPress();
3036 pressed = false;
3037 draggingEnding();
3038 stealGrab = false;
3039 q->setKeepMouseGrab(false);
3040 q->setKeepTouchGrab(false);
3041 fixupX();
3042 fixupY();
3043 if (!isViewMoving())
3044 q->movementEnding();
3045 }
3046}
3047
3048void QQuickFlickablePrivate::addPointerHandler(QQuickPointerHandler *h)
3049{
3050 Q_Q(const QQuickFlickable);
3051 qCDebug(lcHandlerParent) << "reparenting handler" << h << "to contentItem of" << q;
3052 h->setParent(contentItem);
3053 QQuickItemPrivate::get(contentItem)->addPointerHandler(h);
3054}
3055
3056/*! \internal
3057 QQuickFlickable::filterPointerEvent filters pointer events intercepted on the way
3058 to the child \a receiver, and potentially steals the exclusive grab.
3059
3060 This is how flickable takes over the handling of events from child items.
3061
3062 Returns true if the event will be stolen and should <em>not</em> be delivered to the \a receiver.
3063*/
3064bool QQuickFlickable::filterPointerEvent(QQuickItem *receiver, QPointerEvent *event)
3065{
3066 Q_D(QQuickFlickable);
3067 const bool isTouch = QQuickDeliveryAgentPrivate::isTouchEvent(event);
3068 const bool isMouse = QQuickDeliveryAgentPrivate::isMouseEvent(event);
3069 if (isMouse || QQuickDeliveryAgentPrivate::isTabletEvent(event)) {
3070 if (!d->buttonsAccepted(static_cast<QSinglePointEvent *>(event)))
3071 return QQuickItem::childMouseEventFilter(receiver, event);
3072 } else if (!isTouch) {
3073 return false; // don't filter hover events or wheel events, for example
3074 }
3075 Q_ASSERT_X(receiver != this, "", "Flickable received a filter event for itself");
3076 // If a touch event contains a new press point, don't steal right away: watch the movements for a while
3077 if (isTouch && static_cast<QTouchEvent *>(event)->touchPointStates().testFlag(QEventPoint::State::Pressed))
3078 d->stealGrab = false;
3079 const auto &firstPoint = event->points().first();
3080
3081 if (event->pointCount() == 1 && event->exclusiveGrabber(firstPoint) == this) {
3082 // We have an exclusive grab (since we're e.g. dragging), but at the same time, we have
3083 // a child with a passive grab (which is why this filter is being called). And because
3084 // of that, we end up getting the same pointer events twice; First in our own event
3085 // handlers (because of the grab), then once more in here, since we filter the child.
3086 // To avoid processing the event twice (e.g. avoid calling handleReleaseEvent once more
3087 // from below), return early. But return false (not true) so that passive-grab handlers
3088 // (TapHandler, DragHandler) inside this Flickable can still receive the event to update
3089 // their state (e.g. setPressed(false) when drag threshold is exceeded).
3090 return false;
3091 }
3092
3093 QPointF localPos = mapFromScene(firstPoint.scenePosition());
3094 bool receiverDisabled = receiver && !receiver->isEnabled();
3095 bool stealThisEvent = d->stealGrab;
3096 bool receiverKeepsGrab = receiver && (receiver->keepMouseGrab() || receiver->keepTouchGrab());
3097 bool receiverRelinquishGrab = false;
3098
3099 // Special case for MouseArea, try to guess what it does with the event
3100 if (auto *mouseArea = qmlobject_cast<QQuickMouseArea *>(receiver)) {
3101 bool preventStealing = mouseArea->preventStealing();
3102#if QT_CONFIG(quick_draganddrop)
3103 if (mouseArea->drag() && mouseArea->drag()->target())
3104 preventStealing = true;
3105#endif
3106 if (!preventStealing && receiverKeepsGrab) {
3107 receiverRelinquishGrab = !receiverDisabled || (isMouse
3108 && firstPoint.state() == QEventPoint::State::Pressed
3109 && (receiver->acceptedMouseButtons() & static_cast<QMouseEvent *>(event)->button()));
3110 if (receiverRelinquishGrab)
3111 receiverKeepsGrab = false;
3112 }
3113 }
3114
3115 if ((stealThisEvent || contains(localPos)) && (!receiver || !receiverKeepsGrab || receiverDisabled)) {
3116 QScopedPointer<QPointerEvent> localizedEvent(QQuickDeliveryAgentPrivate::clonePointerEvent(event, localPos));
3117 localizedEvent->setAccepted(false);
3118 switch (firstPoint.state()) {
3119 case QEventPoint::State::Updated:
3120 d->handleMoveEvent(localizedEvent.data());
3121 break;
3122 case QEventPoint::State::Pressed:
3123 d->handlePressEvent(localizedEvent.data());
3124 d->captureDelayedPress(receiver, event);
3125 // never grab the pointing device on press during filtering: do it later, during a move
3126 d->stealGrab = false;
3127 stealThisEvent = false;
3128 break;
3129 case QEventPoint::State::Released:
3130 d->handleReleaseEvent(localizedEvent.data());
3131 stealThisEvent = d->stealGrab;
3132 break;
3133 case QEventPoint::State::Stationary:
3134 case QEventPoint::State::Unknown:
3135 break;
3136 }
3137 if ((receiver && stealThisEvent && !receiverKeepsGrab && receiver != this) || receiverDisabled) {
3138 d->clearDelayedPress();
3139 event->setExclusiveGrabber(firstPoint, this);
3140 } else if (d->delayedPressEvent) {
3141 event->setExclusiveGrabber(firstPoint, this);
3142 }
3143 /*
3144 Note that d->stealMouse can be false before the call to d->handleMoveEvent(), but true
3145 afterwards. That means we detected a drag. But even so, we deliberately don't filter
3146 the move event that cause this to happen, since the user might actually be dragging on
3147 a child item, such as a Slider, in which case the child should get a chance to detect
3148 the drag instead, and take the grab. Only if we receive another move event after this,
3149 without the child grabbing the mouse in-between, do we initiate a flick.
3150 An exception is if the user is already in a flicking session started from an earlier
3151 drag, meaning that the content item is still moving (isMoving() == true). In that
3152 case, we see any subsequent drags as being a continuation of the flicking.
3153 Then we filter all events straight away, to avoid triggering any taps or drags in a child.
3154 */
3155 if (isMoving() || (!receiverRelinquishGrab && (stealThisEvent || d->delayedPressEvent || receiverDisabled))) {
3156 // Filter the event
3157 event->setAccepted(true);
3158 return true;
3159 }
3160
3161 // Don't filter the event
3162 return false;
3163 } else if (d->lastPosTime != -1) {
3164 d->lastPosTime = -1;
3165 returnToBounds();
3166 }
3167 if (firstPoint.state() == QEventPoint::State::Released || (receiverKeepsGrab && !receiverDisabled)) {
3168 // mouse released, or another item has claimed the grab
3169 d->lastPosTime = -1;
3170 d->clearDelayedPress();
3171 d->stealGrab = false;
3172 d->pressed = false;
3173 }
3174 return false;
3175}
3176
3177/*! \internal
3178 Despite the name, this function filters all pointer events on their way to any child within.
3179 Returns true if the event will be stolen and should <em>not</em> be delivered to the \a receiver.
3180*/
3181bool QQuickFlickable::childMouseEventFilter(QQuickItem *i, QEvent *e)
3182{
3183 Q_D(QQuickFlickable);
3184 QPointerEvent *pointerEvent = e->isPointerEvent() ? static_cast<QPointerEvent *>(e) : nullptr;
3185
3186 auto wantsPointerEvent_helper = [this, d, i, pointerEvent]() {
3187 Q_ASSERT(pointerEvent);
3188 QQuickDeliveryAgentPrivate::localizePointerEvent(pointerEvent, this);
3189 const bool wants = d->wantsPointerEvent(pointerEvent);
3190 // re-localize event back to \a i before returning
3191 QQuickDeliveryAgentPrivate::localizePointerEvent(pointerEvent, i);
3192 return wants;
3193 };
3194
3195 if (!isVisible() || !isEnabled() || !isInteractive() ||
3196 (pointerEvent && !wantsPointerEvent_helper())) {
3197 d->cancelInteraction();
3198 return QQuickItem::childMouseEventFilter(i, e);
3199 }
3200
3201 if (e->type() == QEvent::UngrabMouse) {
3202 Q_ASSERT(e->isSinglePointEvent());
3203 auto spe = static_cast<QSinglePointEvent *>(e);
3204 const QObject *grabber = spe->exclusiveGrabber(spe->points().first());
3205 qCDebug(lcFilter) << "filtering UngrabMouse" << spe->points().first() << "for" << i << "grabber is" << grabber;
3206 if (grabber != this)
3207 mouseUngrabEvent(); // A child has been ungrabbed
3208 } else if (pointerEvent) {
3209 return filterPointerEvent(i, pointerEvent);
3210 }
3211
3212 return QQuickItem::childMouseEventFilter(i, e);
3213}
3214
3215/*!
3216 \qmlproperty real QtQuick::Flickable::maximumFlickVelocity
3217 This property holds the maximum velocity that the user can flick the view in pixels/second.
3218
3219 The default value is platform dependent.
3220*/
3221qreal QQuickFlickable::maximumFlickVelocity() const
3222{
3223 Q_D(const QQuickFlickable);
3224 return d->maxVelocity;
3225}
3226
3227void QQuickFlickable::setMaximumFlickVelocity(qreal v)
3228{
3229 Q_D(QQuickFlickable);
3230 if (v == d->maxVelocity)
3231 return;
3232 d->maxVelocity = v;
3233 emit maximumFlickVelocityChanged();
3234}
3235
3236/*!
3237 \qmlproperty real QtQuick::Flickable::flickDeceleration
3238 This property holds the rate at which a flick will decelerate:
3239 the higher the number, the faster it slows down when the user stops
3240 flicking via touch. For example 0.0001 is nearly
3241 "frictionless", and 10000 feels quite "sticky".
3242
3243 The default value is platform dependent. Values of zero or less are not allowed.
3244*/
3245qreal QQuickFlickable::flickDeceleration() const
3246{
3247 Q_D(const QQuickFlickable);
3248 return d->deceleration;
3249}
3250
3251void QQuickFlickable::setFlickDeceleration(qreal deceleration)
3252{
3253 Q_D(QQuickFlickable);
3254 if (deceleration == d->deceleration)
3255 return;
3256 d->deceleration = qMax(0.001, deceleration);
3257 emit flickDecelerationChanged();
3258}
3259
3260bool QQuickFlickable::isFlicking() const
3261{
3262 Q_D(const QQuickFlickable);
3263 return d->hData.flicking || d->vData.flicking;
3264}
3265
3266/*!
3267 \qmlproperty bool QtQuick::Flickable::flicking
3268 \qmlproperty bool QtQuick::Flickable::flickingHorizontally
3269 \qmlproperty bool QtQuick::Flickable::flickingVertically
3270
3271 These properties describe whether the view is currently moving horizontally,
3272 vertically or in either direction, due to the user flicking the view.
3273*/
3274bool QQuickFlickable::isFlickingHorizontally() const
3275{
3276 Q_D(const QQuickFlickable);
3277 return d->hData.flicking;
3278}
3279
3280bool QQuickFlickable::isFlickingVertically() const
3281{
3282 Q_D(const QQuickFlickable);
3283 return d->vData.flicking;
3284}
3285
3286/*!
3287 \qmlproperty bool QtQuick::Flickable::dragging
3288 \qmlproperty bool QtQuick::Flickable::draggingHorizontally
3289 \qmlproperty bool QtQuick::Flickable::draggingVertically
3290
3291 These properties describe whether the view is currently moving horizontally,
3292 vertically or in either direction, due to the user dragging the view.
3293*/
3294bool QQuickFlickable::isDragging() const
3295{
3296 Q_D(const QQuickFlickable);
3297 return d->hData.dragging || d->vData.dragging;
3298}
3299
3300bool QQuickFlickable::isDraggingHorizontally() const
3301{
3302 Q_D(const QQuickFlickable);
3303 return d->hData.dragging;
3304}
3305
3306bool QQuickFlickable::isDraggingVertically() const
3307{
3308 Q_D(const QQuickFlickable);
3309 return d->vData.dragging;
3310}
3311
3312void QQuickFlickablePrivate::draggingStarting()
3313{
3314 Q_Q(QQuickFlickable);
3315 bool wasDragging = hData.dragging || vData.dragging;
3316 if (hMoved && !hData.dragging) {
3317 hData.dragging = true;
3318 emit q->draggingHorizontallyChanged();
3319 }
3320 if (vMoved && !vData.dragging) {
3321 vData.dragging = true;
3322 emit q->draggingVerticallyChanged();
3323 }
3324 if (!wasDragging && (hData.dragging || vData.dragging)) {
3325 emit q->draggingChanged();
3326 emit q->dragStarted();
3327 }
3328}
3329
3330void QQuickFlickablePrivate::draggingEnding()
3331{
3332 Q_Q(QQuickFlickable);
3333 const bool wasDragging = hData.dragging || vData.dragging;
3334 if (hData.dragging) {
3335 hData.dragging = false;
3336 emit q->draggingHorizontallyChanged();
3337 }
3338 if (vData.dragging) {
3339 vData.dragging = false;
3340 emit q->draggingVerticallyChanged();
3341 }
3342 if (wasDragging) {
3343 if (!hData.dragging && !vData.dragging) {
3344 emit q->draggingChanged();
3345 emit q->dragEnded();
3346 }
3347 hData.inRebound = false;
3348 vData.inRebound = false;
3349 }
3350}
3351
3352bool QQuickFlickablePrivate::isViewMoving() const
3353{
3354 if (timeline.isActive()
3355 || (hData.transitionToBounds && hData.transitionToBounds->isActive())
3356 || (vData.transitionToBounds && vData.transitionToBounds->isActive()) ) {
3357 return true;
3358 }
3359 return false;
3360}
3361
3362/*!
3363 \qmlproperty int QtQuick::Flickable::pressDelay
3364
3365 This property holds the time to delay (ms) delivering a press to
3366 children of the Flickable. This can be useful where reacting
3367 to a press before a flicking action has undesirable effects.
3368
3369 If the flickable is dragged/flicked before the delay times out
3370 the press event will not be delivered. If the button is released
3371 within the timeout, both the press and release will be delivered.
3372
3373 Note that for nested Flickables with pressDelay set, the pressDelay of
3374 outer Flickables is overridden by the innermost Flickable. If the drag
3375 exceeds the platform drag threshold, the press event will be delivered
3376 regardless of this property.
3377
3378 \sa QStyleHints
3379*/
3380int QQuickFlickable::pressDelay() const
3381{
3382 Q_D(const QQuickFlickable);
3383 return d->pressDelay;
3384}
3385
3386void QQuickFlickable::setPressDelay(int delay)
3387{
3388 Q_D(QQuickFlickable);
3389 if (d->pressDelay == delay)
3390 return;
3391 d->pressDelay = delay;
3392 emit pressDelayChanged();
3393}
3394
3395/*!
3396 \qmlproperty bool QtQuick::Flickable::moving
3397 \qmlproperty bool QtQuick::Flickable::movingHorizontally
3398 \qmlproperty bool QtQuick::Flickable::movingVertically
3399
3400 These properties describe whether the view is currently moving horizontally,
3401 vertically or in either direction, due to the user either dragging or
3402 flicking the view.
3403*/
3404
3405bool QQuickFlickable::isMoving() const
3406{
3407 Q_D(const QQuickFlickable);
3408 return d->hData.moving || d->vData.moving;
3409}
3410
3411bool QQuickFlickable::isMovingHorizontally() const
3412{
3413 Q_D(const QQuickFlickable);
3414 return d->hData.moving;
3415}
3416
3417bool QQuickFlickable::isMovingVertically() const
3418{
3419 Q_D(const QQuickFlickable);
3420 return d->vData.moving;
3421}
3422
3423void QQuickFlickable::velocityTimelineCompleted()
3424{
3425 Q_D(QQuickFlickable);
3426 if ( (d->hData.transitionToBounds && d->hData.transitionToBounds->isActive())
3427 || (d->vData.transitionToBounds && d->vData.transitionToBounds->isActive()) ) {
3428 return;
3429 }
3430 // With subclasses such as GridView, velocityTimeline.completed is emitted repeatedly:
3431 // for example setting currentIndex results in a visual "flick" which the user
3432 // didn't initiate directly. We don't want to end movement repeatedly, and in
3433 // that case movementEnding will happen after the sequence of movements ends.
3434 if (d->vData.flicking)
3435 movementEnding();
3436 d->updateBeginningEnd();
3437}
3438
3439void QQuickFlickable::timelineCompleted()
3440{
3441 Q_D(QQuickFlickable);
3442 if ( (d->hData.transitionToBounds && d->hData.transitionToBounds->isActive())
3443 || (d->vData.transitionToBounds && d->vData.transitionToBounds->isActive()) ) {
3444 return;
3445 }
3446 movementEnding();
3447 d->updateBeginningEnd();
3448}
3449
3450void QQuickFlickable::movementStarting()
3451{
3452 Q_D(QQuickFlickable);
3453 bool wasMoving = d->hData.moving || d->vData.moving;
3454 if (d->hMoved && !d->hData.moving) {
3455 d->hData.moving = true;
3456 emit movingHorizontallyChanged();
3457 }
3458 if (d->vMoved && !d->vData.moving) {
3459 d->vData.moving = true;
3460 emit movingVerticallyChanged();
3461 }
3462
3463 if (!wasMoving && (d->hData.moving || d->vData.moving)) {
3464 emit movingChanged();
3465 emit movementStarted();
3466#if QT_CONFIG(accessibility)
3467 if (QAccessible::isActive()) {
3468 QAccessibleEvent ev(this, QAccessible::ScrollingStart);
3469 QAccessible::updateAccessibility(&ev);
3470 }
3471#endif
3472 }
3473}
3474
3475void QQuickFlickable::movementEnding()
3476{
3477 movementEnding(true, true);
3478}
3479
3480void QQuickFlickable::movementEnding(bool hMovementEnding, bool vMovementEnding)
3481{
3482 Q_D(QQuickFlickable);
3483
3484 // emit flicking signals
3485 const bool wasFlicking = d->hData.flicking || d->vData.flicking;
3486 if (hMovementEnding && d->hData.flicking) {
3487 d->hData.flicking = false;
3488 emit flickingHorizontallyChanged();
3489 }
3490 if (vMovementEnding && d->vData.flicking) {
3491 d->vData.flicking = false;
3492 emit flickingVerticallyChanged();
3493 }
3494 if (wasFlicking && (!d->hData.flicking || !d->vData.flicking)) {
3495 emit flickingChanged();
3496 emit flickEnded();
3497 } else if (d->hData.flickingWhenDragBegan || d->vData.flickingWhenDragBegan) {
3498 d->hData.flickingWhenDragBegan = !hMovementEnding;
3499 d->vData.flickingWhenDragBegan = !vMovementEnding;
3500 emit flickEnded();
3501 }
3502
3503 // emit moving signals
3504 bool wasMoving = isMoving();
3505 if (hMovementEnding && d->hData.moving
3506 && (!d->pressed && !d->stealGrab)) {
3507 d->hData.moving = false;
3508 d->hMoved = false;
3509 emit movingHorizontallyChanged();
3510 }
3511 if (vMovementEnding && d->vData.moving
3512 && (!d->pressed && !d->stealGrab)) {
3513 d->vData.moving = false;
3514 d->vMoved = false;
3515 emit movingVerticallyChanged();
3516 }
3517 if (wasMoving && !isMoving()) {
3518 emit movingChanged();
3519 emit movementEnded();
3520#if QT_CONFIG(accessibility)
3521 if (QAccessible::isActive()) {
3522 QAccessibleEvent ev(this, QAccessible::ScrollingEnd);
3523 QAccessible::updateAccessibility(&ev);
3524 }
3525#endif
3526 }
3527
3528 if (hMovementEnding) {
3529 d->hData.fixingUp = false;
3530 d->hData.smoothVelocity.setValue(0);
3531 d->hData.previousDragDelta = 0.0;
3532 }
3533 if (vMovementEnding) {
3534 d->vData.fixingUp = false;
3535 d->vData.smoothVelocity.setValue(0);
3536 d->vData.previousDragDelta = 0.0;
3537 }
3538}
3539
3540void QQuickFlickablePrivate::updateVelocity()
3541{
3542 Q_Q(QQuickFlickable);
3543 emit q->horizontalVelocityChanged();
3544 emit q->verticalVelocityChanged();
3545}
3546
3547/*!
3548 \qmlproperty real QtQuick::Flickable::horizontalOvershoot
3549 \since 5.9
3550
3551 This property holds the horizontal overshoot, that is, the horizontal distance by
3552 which the contents has been dragged or flicked past the bounds of the flickable.
3553 The value is negative when the content is dragged or flicked beyond the beginning,
3554 and positive when beyond the end; \c 0.0 otherwise.
3555
3556 Whether the values are reported for dragging and/or flicking is determined by
3557 \l boundsBehavior. The overshoot distance is reported even when \l boundsMovement
3558 is \c Flickable.StopAtBounds.
3559
3560 \sa verticalOvershoot, boundsBehavior, boundsMovement
3561*/
3562qreal QQuickFlickable::horizontalOvershoot() const
3563{
3564 Q_D(const QQuickFlickable);
3565 return d->hData.overshoot;
3566}
3567
3568/*!
3569 \qmlproperty real QtQuick::Flickable::verticalOvershoot
3570 \since 5.9
3571
3572 This property holds the vertical overshoot, that is, the vertical distance by
3573 which the contents has been dragged or flicked past the bounds of the flickable.
3574 The value is negative when the content is dragged or flicked beyond the beginning,
3575 and positive when beyond the end; \c 0.0 otherwise.
3576
3577 Whether the values are reported for dragging and/or flicking is determined by
3578 \l boundsBehavior. The overshoot distance is reported even when \l boundsMovement
3579 is \c Flickable.StopAtBounds.
3580
3581 \sa horizontalOvershoot, boundsBehavior, boundsMovement
3582*/
3583qreal QQuickFlickable::verticalOvershoot() const
3584{
3585 Q_D(const QQuickFlickable);
3586 return d->vData.overshoot;
3587}
3588
3589/*!
3590 \qmlproperty enumeration QtQuick::Flickable::boundsMovement
3591 \since 5.10
3592
3593 This property holds whether the flickable will give a feeling that the edges of the
3594 view are soft, rather than a hard physical boundary.
3595
3596 The \c boundsMovement can be one of:
3597
3598 \list
3599 \li Flickable.StopAtBounds - this allows implementing custom edge effects where the
3600 contents do not follow drags or flicks beyond the bounds of the flickable. The values
3601 of \l horizontalOvershoot and \l verticalOvershoot can be utilized to implement custom
3602 edge effects.
3603 \li Flickable.FollowBoundsBehavior (default) - whether the contents follow drags or
3604 flicks beyond the bounds of the flickable is determined by \l boundsBehavior.
3605 \endlist
3606
3607 The following example keeps the contents within bounds and instead applies a flip
3608 effect when flicked over horizontal bounds:
3609 \code
3610 Flickable {
3611 id: flickable
3612 boundsMovement: Flickable.StopAtBounds
3613 boundsBehavior: Flickable.DragAndOvershootBounds
3614 transform: Rotation {
3615 axis { x: 0; y: 1; z: 0 }
3616 origin.x: flickable.width / 2
3617 origin.y: flickable.height / 2
3618 angle: Math.min(30, Math.max(-30, flickable.horizontalOvershoot))
3619 }
3620 }
3621 \endcode
3622
3623 The following example keeps the contents within bounds and instead applies an opacity
3624 effect when dragged over vertical bounds:
3625 \code
3626 Flickable {
3627 boundsMovement: Flickable.StopAtBounds
3628 boundsBehavior: Flickable.DragOverBounds
3629 opacity: Math.max(0.5, 1.0 - Math.abs(verticalOvershoot) / height)
3630 }
3631 \endcode
3632
3633 \sa boundsBehavior, verticalOvershoot, horizontalOvershoot
3634*/
3635QQuickFlickable::BoundsMovement QQuickFlickable::boundsMovement() const
3636{
3637 Q_D(const QQuickFlickable);
3638 return d->boundsMovement;
3639}
3640
3641void QQuickFlickable::setBoundsMovement(BoundsMovement movement)
3642{
3643 Q_D(QQuickFlickable);
3644 if (d->boundsMovement == movement)
3645 return;
3646
3647 d->boundsMovement = movement;
3648 emit boundsMovementChanged();
3649}
3650
3651QT_END_NAMESPACE
3652
3653#include "moc_qquickflickable_p_p.cpp"
3654
3655#include "moc_qquickflickable_p.cpp"
bool contains(const QPointF &point) const override
QQuickFlickableContentItem(QQuickItem *parent=nullptr)
bool startTransition(QQuickFlickablePrivate::AxisData *data, qreal toPos)
QQuickFlickableReboundTransition(QQuickFlickable *f, const QString &name)
QT_BEGIN_NAMESPACE Q_STATIC_LOGGING_CATEGORY(lcSynthesizedIterableAccess, "qt.iterable.synthesized", QtWarningMsg)
static bool fuzzyLessThanOrEqualTo(qreal a, qreal b)
static qreal EaseOvershoot(qreal t)
#define QML_FLICK_SAMPLEBUFFER
#define QML_FLICK_OVERSHOOT
#define QML_FLICK_MULTIFLICK_MAXBOOST
#define QML_FLICK_MULTIFLICK_THRESHOLD
#define QML_FLICK_OVERSHOOTFRICTION
#define QML_FLICK_DISCARDSAMPLES
#define QML_FLICK_MULTIFLICK_RATIO