Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/items/qquickflickable.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||||||||
2 | ** | - | ||||||||||||||||||||||||
3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||||||||||||||
4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||||||||||||||
5 | ** | - | ||||||||||||||||||||||||
6 | ** This file is part of the QtQuick module of the Qt Toolkit. | - | ||||||||||||||||||||||||
7 | ** | - | ||||||||||||||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||||||||||||||
9 | ** Commercial License Usage | - | ||||||||||||||||||||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||||||||
14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||||||||
15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||||||||||||||
16 | ** | - | ||||||||||||||||||||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||||||||
19 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||||||||||||||
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||||||||||||||
21 | ** packaging of this file. Please review the following information to | - | ||||||||||||||||||||||||
22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||||||||||||||
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||||||||||||||
24 | ** | - | ||||||||||||||||||||||||
25 | ** GNU General Public License Usage | - | ||||||||||||||||||||||||
26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||||||||||||||
27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||||||||||||||
28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||||||||||||||
29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||||||||||||||
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||||||||||||||
31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||||||||||||||
32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||||||||||||||
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||||||||||||||
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||||||||||||||
35 | ** | - | ||||||||||||||||||||||||
36 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||||||||
37 | ** | - | ||||||||||||||||||||||||
38 | ****************************************************************************/ | - | ||||||||||||||||||||||||
39 | - | |||||||||||||||||||||||||
40 | #include "qquickflickable_p.h" | - | ||||||||||||||||||||||||
41 | #include "qquickflickable_p_p.h" | - | ||||||||||||||||||||||||
42 | #include "qquickflickablebehavior_p.h" | - | ||||||||||||||||||||||||
43 | #include "qquickwindow.h" | - | ||||||||||||||||||||||||
44 | #include "qquickwindow_p.h" | - | ||||||||||||||||||||||||
45 | #include "qquickevents_p_p.h" | - | ||||||||||||||||||||||||
46 | - | |||||||||||||||||||||||||
47 | #include <QtQuick/private/qquickpointerhandler_p.h> | - | ||||||||||||||||||||||||
48 | #include <QtQuick/private/qquicktransition_p.h> | - | ||||||||||||||||||||||||
49 | #include <private/qqmlglobal_p.h> | - | ||||||||||||||||||||||||
50 | - | |||||||||||||||||||||||||
51 | #include <QtQml/qqmlinfo.h> | - | ||||||||||||||||||||||||
52 | #include <QtGui/qevent.h> | - | ||||||||||||||||||||||||
53 | #include <QtGui/qguiapplication.h> | - | ||||||||||||||||||||||||
54 | #include <QtGui/private/qguiapplication_p.h> | - | ||||||||||||||||||||||||
55 | #include <QtGui/qstylehints.h> | - | ||||||||||||||||||||||||
56 | #include <QtCore/qmath.h> | - | ||||||||||||||||||||||||
57 | #include "qplatformdefs.h" | - | ||||||||||||||||||||||||
58 | - | |||||||||||||||||||||||||
59 | #include <math.h> | - | ||||||||||||||||||||||||
60 | #include <cmath> | - | ||||||||||||||||||||||||
61 | - | |||||||||||||||||||||||||
62 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||
63 | - | |||||||||||||||||||||||||
64 | // FlickThreshold determines how far the "mouse" must have moved | - | ||||||||||||||||||||||||
65 | // before we perform a flick. | - | ||||||||||||||||||||||||
66 | static const int FlickThreshold = 15; | - | ||||||||||||||||||||||||
67 | - | |||||||||||||||||||||||||
68 | // RetainGrabVelocity is the maxmimum instantaneous velocity that | - | ||||||||||||||||||||||||
69 | // will ensure the Flickable retains the grab on consecutive flicks. | - | ||||||||||||||||||||||||
70 | static const int RetainGrabVelocity = 100; | - | ||||||||||||||||||||||||
71 | - | |||||||||||||||||||||||||
72 | #ifdef Q_OS_OSX | - | ||||||||||||||||||||||||
73 | static const int MovementEndingTimerInterval = 100; | - | ||||||||||||||||||||||||
74 | #endif | - | ||||||||||||||||||||||||
75 | - | |||||||||||||||||||||||||
76 | // Currently std::round can't be used on Android when using ndk g++, so | - | ||||||||||||||||||||||||
77 | // use C version instead. We could just define two versions of Round, one | - | ||||||||||||||||||||||||
78 | // for float and one for double, but then only one of them would be used | - | ||||||||||||||||||||||||
79 | // and compiler would trigger a warning about unused function. | - | ||||||||||||||||||||||||
80 | // | - | ||||||||||||||||||||||||
81 | // See https://code.google.com/p/android/issues/detail?id=54418 | - | ||||||||||||||||||||||||
82 | template<typename T> | - | ||||||||||||||||||||||||
83 | static T Round(T t) { | - | ||||||||||||||||||||||||
84 | return round(t); executed 3734 times by 9 tests: return round(t); Executed by:
| 3734 | ||||||||||||||||||||||||
85 | } | - | ||||||||||||||||||||||||
86 | template<> | - | ||||||||||||||||||||||||
87 | Q_DECL_UNUSED float Round<float>(float f) { | - | ||||||||||||||||||||||||
88 | return roundf(f); never executed: return roundf(f); | 0 | ||||||||||||||||||||||||
89 | } | - | ||||||||||||||||||||||||
90 | - | |||||||||||||||||||||||||
91 | static qreal EaseOvershoot(qreal t) { | - | ||||||||||||||||||||||||
92 | return qAtan(t); never executed: return qAtan(t); | 0 | ||||||||||||||||||||||||
93 | } | - | ||||||||||||||||||||||||
94 | - | |||||||||||||||||||||||||
95 | QQuickFlickableVisibleArea::QQuickFlickableVisibleArea(QQuickFlickable *parent) | - | ||||||||||||||||||||||||
96 | : QObject(parent), flickable(parent), m_xPosition(0.), m_widthRatio(0.) | - | ||||||||||||||||||||||||
97 | , m_yPosition(0.), m_heightRatio(0.) | - | ||||||||||||||||||||||||
98 | { | - | ||||||||||||||||||||||||
99 | } executed 566 times by 3 tests: end of block Executed by:
| 566 | ||||||||||||||||||||||||
100 | - | |||||||||||||||||||||||||
101 | qreal QQuickFlickableVisibleArea::widthRatio() const | - | ||||||||||||||||||||||||
102 | { | - | ||||||||||||||||||||||||
103 | return m_widthRatio; executed 18 times by 2 tests: return m_widthRatio; Executed by:
| 18 | ||||||||||||||||||||||||
104 | } | - | ||||||||||||||||||||||||
105 | - | |||||||||||||||||||||||||
106 | qreal QQuickFlickableVisibleArea::xPosition() const | - | ||||||||||||||||||||||||
107 | { | - | ||||||||||||||||||||||||
108 | return m_xPosition; executed 8 times by 1 test: return m_xPosition; Executed by:
| 8 | ||||||||||||||||||||||||
109 | } | - | ||||||||||||||||||||||||
110 | - | |||||||||||||||||||||||||
111 | qreal QQuickFlickableVisibleArea::heightRatio() const | - | ||||||||||||||||||||||||
112 | { | - | ||||||||||||||||||||||||
113 | return m_heightRatio; executed 2324 times by 3 tests: return m_heightRatio; Executed by:
| 2324 | ||||||||||||||||||||||||
114 | } | - | ||||||||||||||||||||||||
115 | - | |||||||||||||||||||||||||
116 | qreal QQuickFlickableVisibleArea::yPosition() const | - | ||||||||||||||||||||||||
117 | { | - | ||||||||||||||||||||||||
118 | return m_yPosition; executed 18 times by 1 test: return m_yPosition; Executed by:
| 18 | ||||||||||||||||||||||||
119 | } | - | ||||||||||||||||||||||||
120 | - | |||||||||||||||||||||||||
121 | void QQuickFlickableVisibleArea::updateVisible() | - | ||||||||||||||||||||||||
122 | { | - | ||||||||||||||||||||||||
123 | QQuickFlickablePrivate *p = QQuickFlickablePrivate::get(flickable); | - | ||||||||||||||||||||||||
124 | - | |||||||||||||||||||||||||
125 | bool changeX = false; | - | ||||||||||||||||||||||||
126 | bool changeY = false; | - | ||||||||||||||||||||||||
127 | bool changeWidth = false; | - | ||||||||||||||||||||||||
128 | bool changeHeight = false; | - | ||||||||||||||||||||||||
129 | - | |||||||||||||||||||||||||
130 | // Vertical | - | ||||||||||||||||||||||||
131 | const qreal viewheight = flickable->height(); | - | ||||||||||||||||||||||||
132 | const qreal maxyextent = -flickable->maxYExtent() + flickable->minYExtent(); | - | ||||||||||||||||||||||||
133 | qreal pagePos = (-p->vData.move.value() + flickable->minYExtent()) / (maxyextent + viewheight); | - | ||||||||||||||||||||||||
134 | qreal pageSize = viewheight / (maxyextent + viewheight); | - | ||||||||||||||||||||||||
135 | - | |||||||||||||||||||||||||
136 | if (pageSize != m_heightRatio) {
| 2318-2483 | ||||||||||||||||||||||||
137 | m_heightRatio = pageSize; | - | ||||||||||||||||||||||||
138 | changeHeight = true; | - | ||||||||||||||||||||||||
139 | } executed 2318 times by 3 tests: end of block Executed by:
| 2318 | ||||||||||||||||||||||||
140 | if (pagePos != m_yPosition) {
| 946-3855 | ||||||||||||||||||||||||
141 | m_yPosition = pagePos; | - | ||||||||||||||||||||||||
142 | changeY = true; | - | ||||||||||||||||||||||||
143 | } executed 946 times by 3 tests: end of block Executed by:
| 946 | ||||||||||||||||||||||||
144 | - | |||||||||||||||||||||||||
145 | // Horizontal | - | ||||||||||||||||||||||||
146 | const qreal viewwidth = flickable->width(); | - | ||||||||||||||||||||||||
147 | const qreal maxxextent = -flickable->maxXExtent() + flickable->minXExtent(); | - | ||||||||||||||||||||||||
148 | pagePos = (-p->hData.move.value() + flickable->minXExtent()) / (maxxextent + viewwidth); | - | ||||||||||||||||||||||||
149 | pageSize = viewwidth / (maxxextent + viewwidth); | - | ||||||||||||||||||||||||
150 | - | |||||||||||||||||||||||||
151 | if (pageSize != m_widthRatio) {
| 584-4217 | ||||||||||||||||||||||||
152 | m_widthRatio = pageSize; | - | ||||||||||||||||||||||||
153 | changeWidth = true; | - | ||||||||||||||||||||||||
154 | } executed 584 times by 3 tests: end of block Executed by:
| 584 | ||||||||||||||||||||||||
155 | if (pagePos != m_xPosition) {
| 14-4787 | ||||||||||||||||||||||||
156 | m_xPosition = pagePos; | - | ||||||||||||||||||||||||
157 | changeX = true; | - | ||||||||||||||||||||||||
158 | } executed 4787 times by 3 tests: end of block Executed by:
| 4787 | ||||||||||||||||||||||||
159 | - | |||||||||||||||||||||||||
160 | if (changeX)
| 14-4787 | ||||||||||||||||||||||||
161 | emit xPositionChanged(m_xPosition); executed 4787 times by 3 tests: xPositionChanged(m_xPosition); Executed by:
| 4787 | ||||||||||||||||||||||||
162 | if (changeY)
| 946-3855 | ||||||||||||||||||||||||
163 | emit yPositionChanged(m_yPosition); executed 946 times by 3 tests: yPositionChanged(m_yPosition); Executed by:
| 946 | ||||||||||||||||||||||||
164 | if (changeWidth)
| 584-4217 | ||||||||||||||||||||||||
165 | emit widthRatioChanged(m_widthRatio); executed 584 times by 3 tests: widthRatioChanged(m_widthRatio); Executed by:
| 584 | ||||||||||||||||||||||||
166 | if (changeHeight)
| 2318-2483 | ||||||||||||||||||||||||
167 | emit heightRatioChanged(m_heightRatio); executed 2318 times by 3 tests: heightRatioChanged(m_heightRatio); Executed by:
| 2318 | ||||||||||||||||||||||||
168 | } executed 4801 times by 3 tests: end of block Executed by:
| 4801 | ||||||||||||||||||||||||
169 | - | |||||||||||||||||||||||||
170 | - | |||||||||||||||||||||||||
171 | class QQuickFlickableReboundTransition : public QQuickTransitionManager | - | ||||||||||||||||||||||||
172 | { | - | ||||||||||||||||||||||||
173 | public: | - | ||||||||||||||||||||||||
174 | QQuickFlickableReboundTransition(QQuickFlickable *f, const QString &name) | - | ||||||||||||||||||||||||
175 | : flickable(f), axisData(nullptr), propName(name), active(false) | - | ||||||||||||||||||||||||
176 | { | - | ||||||||||||||||||||||||
177 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||||||||||||||
178 | - | |||||||||||||||||||||||||
179 | ~QQuickFlickableReboundTransition() | - | ||||||||||||||||||||||||
180 | { | - | ||||||||||||||||||||||||
181 | flickable = nullptr; | - | ||||||||||||||||||||||||
182 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||||||||||||||
183 | - | |||||||||||||||||||||||||
184 | bool startTransition(QQuickFlickablePrivate::AxisData *data, qreal toPos) { | - | ||||||||||||||||||||||||
185 | QQuickFlickablePrivate *fp = QQuickFlickablePrivate::get(flickable); | - | ||||||||||||||||||||||||
186 | if (!fp->rebound || !fp->rebound->enabled())
| 0 | ||||||||||||||||||||||||
187 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
188 | active = true; | - | ||||||||||||||||||||||||
189 | axisData = data; | - | ||||||||||||||||||||||||
190 | axisData->transitionTo = toPos; | - | ||||||||||||||||||||||||
191 | axisData->transitionToSet = true; | - | ||||||||||||||||||||||||
192 | - | |||||||||||||||||||||||||
193 | actions.clear(); | - | ||||||||||||||||||||||||
194 | actions << QQuickStateAction(fp->contentItem, propName, toPos); | - | ||||||||||||||||||||||||
195 | QQuickTransitionManager::transition(actions, fp->rebound, fp->contentItem); | - | ||||||||||||||||||||||||
196 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
197 | } | - | ||||||||||||||||||||||||
198 | - | |||||||||||||||||||||||||
199 | bool isActive() const { | - | ||||||||||||||||||||||||
200 | return active; never executed: return active; | 0 | ||||||||||||||||||||||||
201 | } | - | ||||||||||||||||||||||||
202 | - | |||||||||||||||||||||||||
203 | void stopTransition() { | - | ||||||||||||||||||||||||
204 | if (!flickable || !isRunning())
| 0-4 | ||||||||||||||||||||||||
205 | return; executed 4 times by 1 test: return; Executed by:
| 4 | ||||||||||||||||||||||||
206 | QQuickFlickablePrivate *fp = QQuickFlickablePrivate::get(flickable); | - | ||||||||||||||||||||||||
207 | if (axisData == &fp->hData)
| 0 | ||||||||||||||||||||||||
208 | axisData->move.setValue(-flickable->contentX()); never executed: axisData->move.setValue(-flickable->contentX()); | 0 | ||||||||||||||||||||||||
209 | else | - | ||||||||||||||||||||||||
210 | axisData->move.setValue(-flickable->contentY()); never executed: axisData->move.setValue(-flickable->contentY()); | 0 | ||||||||||||||||||||||||
211 | cancel(); | - | ||||||||||||||||||||||||
212 | active = false; | - | ||||||||||||||||||||||||
213 | } never executed: end of block | 0 | ||||||||||||||||||||||||
214 | - | |||||||||||||||||||||||||
215 | protected: | - | ||||||||||||||||||||||||
216 | void finished() override { | - | ||||||||||||||||||||||||
217 | if (!flickable)
| 0 | ||||||||||||||||||||||||
218 | return; never executed: return; | 0 | ||||||||||||||||||||||||
219 | axisData->move.setValue(axisData->transitionTo); | - | ||||||||||||||||||||||||
220 | QQuickFlickablePrivate *fp = QQuickFlickablePrivate::get(flickable); | - | ||||||||||||||||||||||||
221 | active = false; | - | ||||||||||||||||||||||||
222 | - | |||||||||||||||||||||||||
223 | if (!fp->hData.transitionToBounds->isActive()
| 0 | ||||||||||||||||||||||||
224 | && !fp->vData.transitionToBounds->isActive()) {
| 0 | ||||||||||||||||||||||||
225 | flickable->movementEnding(); | - | ||||||||||||||||||||||||
226 | } never executed: end of block | 0 | ||||||||||||||||||||||||
227 | } never executed: end of block | 0 | ||||||||||||||||||||||||
228 | - | |||||||||||||||||||||||||
229 | private: | - | ||||||||||||||||||||||||
230 | QQuickStateOperation::ActionList actions; | - | ||||||||||||||||||||||||
231 | QQuickFlickable *flickable; | - | ||||||||||||||||||||||||
232 | QQuickFlickablePrivate::AxisData *axisData; | - | ||||||||||||||||||||||||
233 | QString propName; | - | ||||||||||||||||||||||||
234 | bool active; | - | ||||||||||||||||||||||||
235 | }; | - | ||||||||||||||||||||||||
236 | - | |||||||||||||||||||||||||
237 | QQuickFlickablePrivate::AxisData::~AxisData() | - | ||||||||||||||||||||||||
238 | { | - | ||||||||||||||||||||||||
239 | delete transitionToBounds; | - | ||||||||||||||||||||||||
240 | } executed 8184 times by 16 tests: end of block Executed by:
| 8184 | ||||||||||||||||||||||||
241 | - | |||||||||||||||||||||||||
242 | - | |||||||||||||||||||||||||
243 | QQuickFlickablePrivate::QQuickFlickablePrivate() | - | ||||||||||||||||||||||||
244 | : contentItem(new QQuickItem) | - | ||||||||||||||||||||||||
245 | , hData(this, &QQuickFlickablePrivate::setViewportX) | - | ||||||||||||||||||||||||
246 | , vData(this, &QQuickFlickablePrivate::setViewportY) | - | ||||||||||||||||||||||||
247 | , hMoved(false), vMoved(false) | - | ||||||||||||||||||||||||
248 | , stealMouse(false), pressed(false) | - | ||||||||||||||||||||||||
249 | , scrollingPhase(false), interactive(true), calcVelocity(false) | - | ||||||||||||||||||||||||
250 | , pixelAligned(false) | - | ||||||||||||||||||||||||
251 | , lastPosTime(-1) | - | ||||||||||||||||||||||||
252 | , lastPressTime(0) | - | ||||||||||||||||||||||||
253 | , deceleration(QML_FLICK_DEFAULTDECELERATION) | - | ||||||||||||||||||||||||
254 | , maxVelocity(QML_FLICK_DEFAULTMAXVELOCITY), reportedVelocitySmoothing(100) | - | ||||||||||||||||||||||||
255 | , delayedPressEvent(nullptr), pressDelay(0), fixupDuration(400) | - | ||||||||||||||||||||||||
256 | , flickBoost(1.0), fixupMode(Normal), vTime(0), visibleArea(nullptr) | - | ||||||||||||||||||||||||
257 | , flickableDirection(QQuickFlickable::AutoFlickDirection) | - | ||||||||||||||||||||||||
258 | , boundsBehavior(QQuickFlickable::DragAndOvershootBounds) | - | ||||||||||||||||||||||||
259 | , boundsMovement(QQuickFlickable::FollowBoundsBehavior) | - | ||||||||||||||||||||||||
260 | , rebound(nullptr) | - | ||||||||||||||||||||||||
261 | { | - | ||||||||||||||||||||||||
262 | } executed 4100 times by 18 tests: end of block Executed by:
| 4100 | ||||||||||||||||||||||||
263 | - | |||||||||||||||||||||||||
264 | void QQuickFlickablePrivate::init() | - | ||||||||||||||||||||||||
265 | { | - | ||||||||||||||||||||||||
266 | Q_Q(QQuickFlickable); | - | ||||||||||||||||||||||||
267 | QQml_setParent_noEvent(contentItem, q); | - | ||||||||||||||||||||||||
268 | contentItem->setParentItem(q); | - | ||||||||||||||||||||||||
269 | qmlobject_connect(&timeline, QQuickTimeLine, SIGNAL(completed()), executed 36 times by 18 tests: end of block Executed by:
executed 36 times by 18 tests: methodIdx = QQuickFlickable::staticMetaObject.indexOfSlot(method+1); Executed by:
never executed: methodIdx = QQuickFlickable::staticMetaObject.indexOfSignal(method+1);
| 0-4064 | ||||||||||||||||||||||||
270 | q, QQuickFlickable, SLOT(timelineCompleted())) | - | ||||||||||||||||||||||||
271 | qmlobject_connect(&velocityTimeline, QQuickTimeLine, SIGNAL(completed()), executed 36 times by 18 tests: end of block Executed by:
executed 36 times by 18 tests: methodIdx = QQuickFlickable::staticMetaObject.indexOfSlot(method+1); Executed by:
never executed: methodIdx = QQuickFlickable::staticMetaObject.indexOfSignal(method+1);
| 0-4064 | ||||||||||||||||||||||||
272 | q, QQuickFlickable, SLOT(velocityTimelineCompleted())) | - | ||||||||||||||||||||||||
273 | q->setAcceptedMouseButtons(Qt::LeftButton); | - | ||||||||||||||||||||||||
274 | q->setAcceptTouchEvents(false); // rely on mouse events synthesized from touch | - | ||||||||||||||||||||||||
275 | q->setFiltersChildMouseEvents(true); | - | ||||||||||||||||||||||||
276 | QQuickItemPrivate *viewportPrivate = QQuickItemPrivate::get(contentItem); | - | ||||||||||||||||||||||||
277 | viewportPrivate->addItemChangeListener(this, QQuickItemPrivate::Geometry); | - | ||||||||||||||||||||||||
278 | } executed 4100 times by 18 tests: end of block Executed by:
| 4100 | ||||||||||||||||||||||||
279 | - | |||||||||||||||||||||||||
280 | /* | - | ||||||||||||||||||||||||
281 | Returns the amount to overshoot by given a velocity. | - | ||||||||||||||||||||||||
282 | Will be roughly in range 0 - size/4 | - | ||||||||||||||||||||||||
283 | */ | - | ||||||||||||||||||||||||
284 | qreal QQuickFlickablePrivate::overShootDistance(qreal size) const | - | ||||||||||||||||||||||||
285 | { | - | ||||||||||||||||||||||||
286 | if (maxVelocity <= 0)
| 0-346 | ||||||||||||||||||||||||
287 | return 0.0; never executed: return 0.0; | 0 | ||||||||||||||||||||||||
288 | - | |||||||||||||||||||||||||
289 | return qMin(qreal(QML_FLICK_OVERSHOOT), size/3); executed 346 times by 7 tests: return qMin(qreal(150), size/3); Executed by:
| 346 | ||||||||||||||||||||||||
290 | } | - | ||||||||||||||||||||||||
291 | - | |||||||||||||||||||||||||
292 | void QQuickFlickablePrivate::AxisData::addVelocitySample(qreal v, qreal maxVelocity) | - | ||||||||||||||||||||||||
293 | { | - | ||||||||||||||||||||||||
294 | if (v > maxVelocity)
| 501-4869 | ||||||||||||||||||||||||
295 | v = maxVelocity; executed 501 times by 6 tests: v = maxVelocity; Executed by:
| 501 | ||||||||||||||||||||||||
296 | else if (v < -maxVelocity)
| 518-4351 | ||||||||||||||||||||||||
297 | v = -maxVelocity; executed 518 times by 3 tests: v = -maxVelocity; Executed by:
| 518 | ||||||||||||||||||||||||
298 | velocityBuffer.append(v); | - | ||||||||||||||||||||||||
299 | if (velocityBuffer.count() > QML_FLICK_SAMPLEBUFFER)
| 2504-2866 | ||||||||||||||||||||||||
300 | velocityBuffer.remove(0); executed 2866 times by 7 tests: velocityBuffer.remove(0); Executed by:
| 2866 | ||||||||||||||||||||||||
301 | } executed 5370 times by 7 tests: end of block Executed by:
| 5370 | ||||||||||||||||||||||||
302 | - | |||||||||||||||||||||||||
303 | void QQuickFlickablePrivate::AxisData::updateVelocity() | - | ||||||||||||||||||||||||
304 | { | - | ||||||||||||||||||||||||
305 | velocity = 0; | - | ||||||||||||||||||||||||
306 | if (velocityBuffer.count() > QML_FLICK_DISCARDSAMPLES) {
| 700-840 | ||||||||||||||||||||||||
307 | int count = velocityBuffer.count()-QML_FLICK_DISCARDSAMPLES; | - | ||||||||||||||||||||||||
308 | for (int i = 0; i < count; ++i) {
| 840-2326 | ||||||||||||||||||||||||
309 | qreal v = velocityBuffer.at(i); | - | ||||||||||||||||||||||||
310 | velocity += v; | - | ||||||||||||||||||||||||
311 | } executed 2326 times by 7 tests: end of block Executed by:
| 2326 | ||||||||||||||||||||||||
312 | velocity /= count; | - | ||||||||||||||||||||||||
313 | } executed 840 times by 7 tests: end of block Executed by:
| 840 | ||||||||||||||||||||||||
314 | } executed 1540 times by 7 tests: end of block Executed by:
| 1540 | ||||||||||||||||||||||||
315 | - | |||||||||||||||||||||||||
316 | void QQuickFlickablePrivate::itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change, const QRectF &) | - | ||||||||||||||||||||||||
317 | { | - | ||||||||||||||||||||||||
318 | Q_Q(QQuickFlickable); | - | ||||||||||||||||||||||||
319 | if (item == contentItem) {
| 39814-155234 | ||||||||||||||||||||||||
320 | Qt::Orientations orient = nullptr; | - | ||||||||||||||||||||||||
321 | if (change.xChange())
| 10388-29426 | ||||||||||||||||||||||||
322 | orient |= Qt::Horizontal; executed 10388 times by 7 tests: orient |= Qt::Horizontal; Executed by:
| 10388 | ||||||||||||||||||||||||
323 | if (change.yChange())
| 12988-26826 | ||||||||||||||||||||||||
324 | orient |= Qt::Vertical; executed 12988 times by 7 tests: orient |= Qt::Vertical; Executed by:
| 12988 | ||||||||||||||||||||||||
325 | if (orient)
| 16438-23376 | ||||||||||||||||||||||||
326 | q->viewportMoved(orient); executed 23376 times by 9 tests: q->viewportMoved(orient); Executed by:
| 23376 | ||||||||||||||||||||||||
327 | if (orient & Qt::Horizontal)
| 10388-29426 | ||||||||||||||||||||||||
328 | emit q->contentXChanged(); executed 10388 times by 7 tests: q->contentXChanged(); Executed by:
| 10388 | ||||||||||||||||||||||||
329 | if (orient & Qt::Vertical)
| 12988-26826 | ||||||||||||||||||||||||
330 | emit q->contentYChanged(); executed 12988 times by 7 tests: q->contentYChanged(); Executed by:
| 12988 | ||||||||||||||||||||||||
331 | } executed 39814 times by 17 tests: end of block Executed by:
| 39814 | ||||||||||||||||||||||||
332 | } executed 195048 times by 17 tests: end of block Executed by:
| 195048 | ||||||||||||||||||||||||
333 | - | |||||||||||||||||||||||||
334 | bool QQuickFlickablePrivate::flickX(qreal velocity) | - | ||||||||||||||||||||||||
335 | { | - | ||||||||||||||||||||||||
336 | Q_Q(QQuickFlickable); | - | ||||||||||||||||||||||||
337 | return flick(hData, q->minXExtent(), q->maxXExtent(), q->width(), fixupX_callback, velocity); executed 1271 times by 6 tests: return flick(hData, q->minXExtent(), q->maxXExtent(), q->width(), fixupX_callback, velocity); Executed by:
| 1271 | ||||||||||||||||||||||||
338 | } | - | ||||||||||||||||||||||||
339 | - | |||||||||||||||||||||||||
340 | bool QQuickFlickablePrivate::flickY(qreal velocity) | - | ||||||||||||||||||||||||
341 | { | - | ||||||||||||||||||||||||
342 | Q_Q(QQuickFlickable); | - | ||||||||||||||||||||||||
343 | return flick(vData, q->minYExtent(), q->maxYExtent(), q->height(), fixupY_callback, velocity); executed 1278 times by 5 tests: return flick(vData, q->minYExtent(), q->maxYExtent(), q->height(), fixupY_callback, velocity); Executed by:
| 1278 | ||||||||||||||||||||||||
344 | } | - | ||||||||||||||||||||||||
345 | - | |||||||||||||||||||||||||
346 | bool QQuickFlickablePrivate::flick(AxisData &data, qreal minExtent, qreal maxExtent, qreal, | - | ||||||||||||||||||||||||
347 | QQuickTimeLineCallback::Callback fixupCallback, qreal velocity) | - | ||||||||||||||||||||||||
348 | { | - | ||||||||||||||||||||||||
349 | Q_Q(QQuickFlickable); | - | ||||||||||||||||||||||||
350 | qreal maxDistance = -1; | - | ||||||||||||||||||||||||
351 | data.fixingUp = false; | - | ||||||||||||||||||||||||
352 | // -ve velocity means list is moving up | - | ||||||||||||||||||||||||
353 | if (velocity > 0) {
| 164-169 | ||||||||||||||||||||||||
354 | maxDistance = qAbs(minExtent - data.move.value()); | - | ||||||||||||||||||||||||
355 | data.flickTarget = minExtent; | - | ||||||||||||||||||||||||
356 | } else { executed 164 times by 7 tests: end of block Executed by:
| 164 | ||||||||||||||||||||||||
357 | maxDistance = qAbs(maxExtent - data.move.value()); | - | ||||||||||||||||||||||||
358 | data.flickTarget = maxExtent; | - | ||||||||||||||||||||||||
359 | } executed 169 times by 4 tests: end of block Executed by:
| 169 | ||||||||||||||||||||||||
360 | if (maxDistance > 0 || boundsBehavior & QQuickFlickable::OvershootBounds) {
| 48-285 | ||||||||||||||||||||||||
361 | qreal v = velocity; | - | ||||||||||||||||||||||||
362 | if (maxVelocity != -1 && maxVelocity < qAbs(v)) {
| 0-317 | ||||||||||||||||||||||||
363 | if (v < 0)
| 0 | ||||||||||||||||||||||||
364 | v = -maxVelocity; never executed: v = -maxVelocity; | 0 | ||||||||||||||||||||||||
365 | else | - | ||||||||||||||||||||||||
366 | v = maxVelocity; never executed: v = maxVelocity; | 0 | ||||||||||||||||||||||||
367 | } | - | ||||||||||||||||||||||||
368 | - | |||||||||||||||||||||||||
369 | // adjust accel so that we hit a full pixel | - | ||||||||||||||||||||||||
370 | qreal accel = deceleration; | - | ||||||||||||||||||||||||
371 | qreal v2 = v * v; | - | ||||||||||||||||||||||||
372 | qreal dist = v2 / (accel * 2.0); | - | ||||||||||||||||||||||||
373 | if (v > 0)
| 156-161 | ||||||||||||||||||||||||
374 | dist = -dist; executed 156 times by 7 tests: dist = -dist; Executed by:
| 156 | ||||||||||||||||||||||||
375 | qreal target = -Round(-(data.move.value() - dist)); | - | ||||||||||||||||||||||||
376 | dist = -target + data.move.value(); | - | ||||||||||||||||||||||||
377 | accel = v2 / (2.0f * qAbs(dist)); | - | ||||||||||||||||||||||||
378 | - | |||||||||||||||||||||||||
379 | resetTimeline(data); | - | ||||||||||||||||||||||||
380 | if (!data.inOvershoot) {
| 0-317 | ||||||||||||||||||||||||
381 | if (boundsBehavior & QQuickFlickable::OvershootBounds)
| 84-233 | ||||||||||||||||||||||||
382 | timeline.accel(data.move, v, accel); executed 233 times by 7 tests: timeline.accel(data.move, v, accel); Executed by:
| 233 | ||||||||||||||||||||||||
383 | else | - | ||||||||||||||||||||||||
384 | timeline.accel(data.move, v, accel, maxDistance); executed 84 times by 1 test: timeline.accel(data.move, v, accel, maxDistance); Executed by:
| 84 | ||||||||||||||||||||||||
385 | } | - | ||||||||||||||||||||||||
386 | timeline.callback(QQuickTimeLineCallback(&data.move, fixupCallback, this)); | - | ||||||||||||||||||||||||
387 | - | |||||||||||||||||||||||||
388 | if (&data == &hData)
| 140-177 | ||||||||||||||||||||||||
389 | return !hData.flicking && q->xflick(); executed 140 times by 5 tests: return !hData.flicking && q->xflick(); Executed by:
| 140 | ||||||||||||||||||||||||
390 | else if (&data == &vData)
| 0-177 | ||||||||||||||||||||||||
391 | return !vData.flicking && q->yflick(); executed 177 times by 5 tests: return !vData.flicking && q->yflick(); Executed by:
| 177 | ||||||||||||||||||||||||
392 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
393 | } else { | - | ||||||||||||||||||||||||
394 | resetTimeline(data); | - | ||||||||||||||||||||||||
395 | fixup(data, minExtent, maxExtent); | - | ||||||||||||||||||||||||
396 | return false; executed 16 times by 1 test: return false; Executed by:
| 16 | ||||||||||||||||||||||||
397 | } | - | ||||||||||||||||||||||||
398 | } | - | ||||||||||||||||||||||||
399 | - | |||||||||||||||||||||||||
400 | void QQuickFlickablePrivate::fixupY_callback(void *data) | - | ||||||||||||||||||||||||
401 | { | - | ||||||||||||||||||||||||
402 | ((QQuickFlickablePrivate *)data)->fixupY(); | - | ||||||||||||||||||||||||
403 | } executed 289 times by 5 tests: end of block Executed by:
| 289 | ||||||||||||||||||||||||
404 | - | |||||||||||||||||||||||||
405 | void QQuickFlickablePrivate::fixupX_callback(void *data) | - | ||||||||||||||||||||||||
406 | { | - | ||||||||||||||||||||||||
407 | ((QQuickFlickablePrivate *)data)->fixupX(); | - | ||||||||||||||||||||||||
408 | } executed 320 times by 5 tests: end of block Executed by:
| 320 | ||||||||||||||||||||||||
409 | - | |||||||||||||||||||||||||
410 | void QQuickFlickablePrivate::fixupX() | - | ||||||||||||||||||||||||
411 | { | - | ||||||||||||||||||||||||
412 | Q_Q(QQuickFlickable); | - | ||||||||||||||||||||||||
413 | if (!q->isComponentComplete())
| 4010-5728 | ||||||||||||||||||||||||
414 | return; //Do not fixup from initialization values executed 4010 times by 14 tests: return; Executed by:
| 4010 | ||||||||||||||||||||||||
415 | fixup(hData, q->minXExtent(), q->maxXExtent()); | - | ||||||||||||||||||||||||
416 | } executed 5728 times by 12 tests: end of block Executed by:
| 5728 | ||||||||||||||||||||||||
417 | - | |||||||||||||||||||||||||
418 | void QQuickFlickablePrivate::fixupY() | - | ||||||||||||||||||||||||
419 | { | - | ||||||||||||||||||||||||
420 | Q_Q(QQuickFlickable); | - | ||||||||||||||||||||||||
421 | if (!q->isComponentComplete())
| 6382-17873 | ||||||||||||||||||||||||
422 | return; //Do not fixup from initialization values executed 6382 times by 14 tests: return; Executed by:
| 6382 | ||||||||||||||||||||||||
423 | fixup(vData, q->minYExtent(), q->maxYExtent()); | - | ||||||||||||||||||||||||
424 | } executed 17873 times by 17 tests: end of block Executed by:
| 17873 | ||||||||||||||||||||||||
425 | - | |||||||||||||||||||||||||
426 | void QQuickFlickablePrivate::adjustContentPos(AxisData &data, qreal toPos) | - | ||||||||||||||||||||||||
427 | { | - | ||||||||||||||||||||||||
428 | Q_Q(QQuickFlickable); | - | ||||||||||||||||||||||||
429 | switch (fixupMode) { | - | ||||||||||||||||||||||||
430 | case Immediate: executed 3528 times by 5 tests: case Immediate: Executed by:
| 3528 | ||||||||||||||||||||||||
431 | timeline.set(data.move, toPos); | - | ||||||||||||||||||||||||
432 | break; executed 3528 times by 5 tests: break; Executed by:
| 3528 | ||||||||||||||||||||||||
433 | case ExtentChanged: executed 51 times by 1 test: case ExtentChanged: Executed by:
| 51 | ||||||||||||||||||||||||
434 | // The target has changed. Don't start from the beginning; just complete the | - | ||||||||||||||||||||||||
435 | // second half of the animation using the new extent. | - | ||||||||||||||||||||||||
436 | timeline.move(data.move, toPos, QEasingCurve(QEasingCurve::OutExpo), 3*fixupDuration/4); | - | ||||||||||||||||||||||||
437 | data.fixingUp = true; | - | ||||||||||||||||||||||||
438 | break; executed 51 times by 1 test: break; Executed by:
| 51 | ||||||||||||||||||||||||
439 | default: { executed 325 times by 7 tests: default: Executed by:
| 325 | ||||||||||||||||||||||||
440 | if (data.transitionToBounds && data.transitionToBounds->startTransition(&data, toPos)) {
| 0-325 | ||||||||||||||||||||||||
441 | q->movementStarting(); | - | ||||||||||||||||||||||||
442 | data.fixingUp = true; | - | ||||||||||||||||||||||||
443 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
444 | qreal dist = toPos - data.move; | - | ||||||||||||||||||||||||
445 | timeline.move(data.move, toPos - dist/2, QEasingCurve(QEasingCurve::InQuad), fixupDuration/4); | - | ||||||||||||||||||||||||
446 | timeline.move(data.move, toPos, QEasingCurve(QEasingCurve::OutExpo), 3*fixupDuration/4); | - | ||||||||||||||||||||||||
447 | data.fixingUp = true; | - | ||||||||||||||||||||||||
448 | } executed 325 times by 7 tests: end of block Executed by:
| 325 | ||||||||||||||||||||||||
449 | } | - | ||||||||||||||||||||||||
450 | } | - | ||||||||||||||||||||||||
451 | } | - | ||||||||||||||||||||||||
452 | - | |||||||||||||||||||||||||
453 | void QQuickFlickablePrivate::resetTimeline(AxisData &data) | - | ||||||||||||||||||||||||
454 | { | - | ||||||||||||||||||||||||
455 | timeline.reset(data.move); | - | ||||||||||||||||||||||||
456 | if (data.transitionToBounds)
| 4-44190 | ||||||||||||||||||||||||
457 | data.transitionToBounds->stopTransition(); executed 4 times by 1 test: data.transitionToBounds->stopTransition(); Executed by:
| 4 | ||||||||||||||||||||||||
458 | } executed 44194 times by 17 tests: end of block Executed by:
| 44194 | ||||||||||||||||||||||||
459 | - | |||||||||||||||||||||||||
460 | void QQuickFlickablePrivate::clearTimeline() | - | ||||||||||||||||||||||||
461 | { | - | ||||||||||||||||||||||||
462 | timeline.clear(); | - | ||||||||||||||||||||||||
463 | if (hData.transitionToBounds)
| 0-2832 | ||||||||||||||||||||||||
464 | hData.transitionToBounds->stopTransition(); never executed: hData.transitionToBounds->stopTransition(); | 0 | ||||||||||||||||||||||||
465 | if (vData.transitionToBounds)
| 0-2832 | ||||||||||||||||||||||||
466 | vData.transitionToBounds->stopTransition(); never executed: vData.transitionToBounds->stopTransition(); | 0 | ||||||||||||||||||||||||
467 | } executed 2832 times by 7 tests: end of block Executed by:
| 2832 | ||||||||||||||||||||||||
468 | - | |||||||||||||||||||||||||
469 | void QQuickFlickablePrivate::fixup(AxisData &data, qreal minExtent, qreal maxExtent) | - | ||||||||||||||||||||||||
470 | { | - | ||||||||||||||||||||||||
471 | if (data.move.value() >= minExtent || maxExtent > minExtent) {
| 0-15399 | ||||||||||||||||||||||||
472 | resetTimeline(data); | - | ||||||||||||||||||||||||
473 | if (data.move.value() != minExtent) {
| 320-15079 | ||||||||||||||||||||||||
474 | adjustContentPos(data, minExtent); | - | ||||||||||||||||||||||||
475 | } executed 320 times by 7 tests: end of block Executed by:
| 320 | ||||||||||||||||||||||||
476 | } else if (data.move.value() <= maxExtent) { executed 15399 times by 17 tests: end of block Executed by:
| 2904-15399 | ||||||||||||||||||||||||
477 | resetTimeline(data); | - | ||||||||||||||||||||||||
478 | adjustContentPos(data, maxExtent); | - | ||||||||||||||||||||||||
479 | } else if (-Round(-data.move.value()) != data.move.value()) { executed 3584 times by 6 tests: end of block Executed by:
| 70-3584 | ||||||||||||||||||||||||
480 | // We could animate, but since it is less than 0.5 pixel it's probably not worthwhile. | - | ||||||||||||||||||||||||
481 | resetTimeline(data); | - | ||||||||||||||||||||||||
482 | qreal val = data.move.value(); | - | ||||||||||||||||||||||||
483 | if (std::abs(-Round(-val) - val) < 0.25) // round small differences
| 11-59 | ||||||||||||||||||||||||
484 | val = -Round(-val); executed 59 times by 3 tests: val = -Round(-val); Executed by:
| 59 | ||||||||||||||||||||||||
485 | else if (data.smoothVelocity.value() > 0) // continue direction of motion for larger
| 5-6 | ||||||||||||||||||||||||
486 | val = -std::floor(-val); executed 5 times by 1 test: val = -std::floor(-val); Executed by:
| 5 | ||||||||||||||||||||||||
487 | else if (data.smoothVelocity.value() < 0)
| 0-6 | ||||||||||||||||||||||||
488 | val = -std::ceil(-val); never executed: val = -std::ceil(-val); | 0 | ||||||||||||||||||||||||
489 | else // otherwise round | - | ||||||||||||||||||||||||
490 | val = -Round(-val); executed 6 times by 2 tests: val = -Round(-val); Executed by:
| 6 | ||||||||||||||||||||||||
491 | timeline.set(data.move, val); | - | ||||||||||||||||||||||||
492 | } executed 70 times by 3 tests: end of block Executed by:
| 70 | ||||||||||||||||||||||||
493 | data.inOvershoot = false; | - | ||||||||||||||||||||||||
494 | fixupMode = Normal; | - | ||||||||||||||||||||||||
495 | data.vTime = timeline.time(); | - | ||||||||||||||||||||||||
496 | } executed 21887 times by 17 tests: end of block Executed by:
| 21887 | ||||||||||||||||||||||||
497 | - | |||||||||||||||||||||||||
498 | static bool fuzzyLessThanOrEqualTo(qreal a, qreal b) | - | ||||||||||||||||||||||||
499 | { | - | ||||||||||||||||||||||||
500 | if (a == 0.0 || b == 0.0) {
| 66305-143646 | ||||||||||||||||||||||||
501 | // qFuzzyCompare is broken | - | ||||||||||||||||||||||||
502 | a += 1.0; | - | ||||||||||||||||||||||||
503 | b += 1.0; | - | ||||||||||||||||||||||||
504 | } executed 175763 times by 18 tests: end of block Executed by:
| 175763 | ||||||||||||||||||||||||
505 | return a <= b || qFuzzyCompare(a, b); executed 242068 times by 18 tests: return a <= b || qFuzzyCompare(a, b); Executed by:
| 242068 | ||||||||||||||||||||||||
506 | } | - | ||||||||||||||||||||||||
507 | - | |||||||||||||||||||||||||
508 | void QQuickFlickablePrivate::updateBeginningEnd() | - | ||||||||||||||||||||||||
509 | { | - | ||||||||||||||||||||||||
510 | Q_Q(QQuickFlickable); | - | ||||||||||||||||||||||||
511 | bool atBoundaryChange = false; | - | ||||||||||||||||||||||||
512 | - | |||||||||||||||||||||||||
513 | // Vertical | - | ||||||||||||||||||||||||
514 | const qreal maxyextent = -q->maxYExtent(); | - | ||||||||||||||||||||||||
515 | const qreal minyextent = -q->minYExtent(); | - | ||||||||||||||||||||||||
516 | const qreal ypos = -vData.move.value(); | - | ||||||||||||||||||||||||
517 | bool atBeginning = fuzzyLessThanOrEqualTo(ypos, minyextent); | - | ||||||||||||||||||||||||
518 | bool atEnd = fuzzyLessThanOrEqualTo(maxyextent, ypos); | - | ||||||||||||||||||||||||
519 | - | |||||||||||||||||||||||||
520 | if (atBeginning != vData.atBeginning) {
| 2230-57676 | ||||||||||||||||||||||||
521 | vData.atBeginning = atBeginning; | - | ||||||||||||||||||||||||
522 | atBoundaryChange = true; | - | ||||||||||||||||||||||||
523 | } executed 2230 times by 6 tests: end of block Executed by:
| 2230 | ||||||||||||||||||||||||
524 | if (atEnd != vData.atEnd) {
| 8187-51719 | ||||||||||||||||||||||||
525 | vData.atEnd = atEnd; | - | ||||||||||||||||||||||||
526 | atBoundaryChange = true; | - | ||||||||||||||||||||||||
527 | } executed 8187 times by 17 tests: end of block Executed by:
| 8187 | ||||||||||||||||||||||||
528 | - | |||||||||||||||||||||||||
529 | // Horizontal | - | ||||||||||||||||||||||||
530 | const qreal maxxextent = -q->maxXExtent(); | - | ||||||||||||||||||||||||
531 | const qreal minxextent = -q->minXExtent(); | - | ||||||||||||||||||||||||
532 | const qreal xpos = -hData.move.value(); | - | ||||||||||||||||||||||||
533 | atBeginning = fuzzyLessThanOrEqualTo(xpos, minxextent); | - | ||||||||||||||||||||||||
534 | atEnd = fuzzyLessThanOrEqualTo(maxxextent, xpos); | - | ||||||||||||||||||||||||
535 | - | |||||||||||||||||||||||||
536 | if (atBeginning != hData.atBeginning) {
| 1294-58612 | ||||||||||||||||||||||||
537 | hData.atBeginning = atBeginning; | - | ||||||||||||||||||||||||
538 | atBoundaryChange = true; | - | ||||||||||||||||||||||||
539 | } executed 1294 times by 6 tests: end of block Executed by:
| 1294 | ||||||||||||||||||||||||
540 | if (atEnd != hData.atEnd) {
| 5502-54404 | ||||||||||||||||||||||||
541 | hData.atEnd = atEnd; | - | ||||||||||||||||||||||||
542 | atBoundaryChange = true; | - | ||||||||||||||||||||||||
543 | } executed 5502 times by 17 tests: end of block Executed by:
| 5502 | ||||||||||||||||||||||||
544 | - | |||||||||||||||||||||||||
545 | if (vData.extentsChanged) {
| 27283-32623 | ||||||||||||||||||||||||
546 | vData.extentsChanged = false; | - | ||||||||||||||||||||||||
547 | qreal originY = q->originY(); | - | ||||||||||||||||||||||||
548 | if (vData.origin != originY) {
| 1533-25750 | ||||||||||||||||||||||||
549 | vData.origin = originY; | - | ||||||||||||||||||||||||
550 | emit q->originYChanged(); | - | ||||||||||||||||||||||||
551 | } executed 1533 times by 3 tests: end of block Executed by:
| 1533 | ||||||||||||||||||||||||
552 | } executed 27283 times by 17 tests: end of block Executed by:
| 27283 | ||||||||||||||||||||||||
553 | - | |||||||||||||||||||||||||
554 | if (hData.extentsChanged) {
| 6267-53639 | ||||||||||||||||||||||||
555 | hData.extentsChanged = false; | - | ||||||||||||||||||||||||
556 | qreal originX = q->originX(); | - | ||||||||||||||||||||||||
557 | if (hData.origin != originX) {
| 1076-5191 | ||||||||||||||||||||||||
558 | hData.origin = originX; | - | ||||||||||||||||||||||||
559 | emit q->originXChanged(); | - | ||||||||||||||||||||||||
560 | } executed 1076 times by 3 tests: end of block Executed by:
| 1076 | ||||||||||||||||||||||||
561 | } executed 6267 times by 9 tests: end of block Executed by:
| 6267 | ||||||||||||||||||||||||
562 | - | |||||||||||||||||||||||||
563 | if (atBoundaryChange)
| 12573-47333 | ||||||||||||||||||||||||
564 | emit q->isAtBoundaryChanged(); executed 12573 times by 18 tests: q->isAtBoundaryChanged(); Executed by:
| 12573 | ||||||||||||||||||||||||
565 | - | |||||||||||||||||||||||||
566 | if (visibleArea)
| 4235-55671 | ||||||||||||||||||||||||
567 | visibleArea->updateVisible(); executed 4235 times by 3 tests: visibleArea->updateVisible(); Executed by:
| 4235 | ||||||||||||||||||||||||
568 | } executed 59906 times by 18 tests: end of block Executed by:
| 59906 | ||||||||||||||||||||||||
569 | - | |||||||||||||||||||||||||
570 | /*! | - | ||||||||||||||||||||||||
571 | \qmlsignal QtQuick::Flickable::dragStarted() | - | ||||||||||||||||||||||||
572 | - | |||||||||||||||||||||||||
573 | This signal is emitted when the view starts to be dragged due to user | - | ||||||||||||||||||||||||
574 | interaction. | - | ||||||||||||||||||||||||
575 | - | |||||||||||||||||||||||||
576 | The corresponding handler is \c onDragStarted. | - | ||||||||||||||||||||||||
577 | */ | - | ||||||||||||||||||||||||
578 | - | |||||||||||||||||||||||||
579 | /*! | - | ||||||||||||||||||||||||
580 | \qmlsignal QtQuick::Flickable::dragEnded() | - | ||||||||||||||||||||||||
581 | - | |||||||||||||||||||||||||
582 | This signal is emitted when the user stops dragging the view. | - | ||||||||||||||||||||||||
583 | - | |||||||||||||||||||||||||
584 | If the velocity of the drag is sufficient at the time the | - | ||||||||||||||||||||||||
585 | touch/mouse button is released then a flick will start. | - | ||||||||||||||||||||||||
586 | - | |||||||||||||||||||||||||
587 | The corresponding handler is \c onDragEnded. | - | ||||||||||||||||||||||||
588 | */ | - | ||||||||||||||||||||||||
589 | - | |||||||||||||||||||||||||
590 | /*! | - | ||||||||||||||||||||||||
591 | \qmltype Flickable | - | ||||||||||||||||||||||||
592 | \instantiates QQuickFlickable | - | ||||||||||||||||||||||||
593 | \inqmlmodule QtQuick | - | ||||||||||||||||||||||||
594 | \ingroup qtquick-input | - | ||||||||||||||||||||||||
595 | \ingroup qtquick-containers | - | ||||||||||||||||||||||||
596 | - | |||||||||||||||||||||||||
597 | \brief Provides a surface that can be "flicked". | - | ||||||||||||||||||||||||
598 | \inherits Item | - | ||||||||||||||||||||||||
599 | - | |||||||||||||||||||||||||
600 | The Flickable item places its children on a surface that can be dragged | - | ||||||||||||||||||||||||
601 | and flicked, causing the view onto the child items to scroll. This | - | ||||||||||||||||||||||||
602 | behavior forms the basis of Items that are designed to show large numbers | - | ||||||||||||||||||||||||
603 | of child items, such as \l ListView and \l GridView. | - | ||||||||||||||||||||||||
604 | - | |||||||||||||||||||||||||
605 | In traditional user interfaces, views can be scrolled using standard | - | ||||||||||||||||||||||||
606 | controls, such as scroll bars and arrow buttons. In some situations, it | - | ||||||||||||||||||||||||
607 | is also possible to drag the view directly by pressing and holding a | - | ||||||||||||||||||||||||
608 | mouse button while moving the cursor. In touch-based user interfaces, | - | ||||||||||||||||||||||||
609 | this dragging action is often complemented with a flicking action, where | - | ||||||||||||||||||||||||
610 | scrolling continues after the user has stopped touching the view. | - | ||||||||||||||||||||||||
611 | - | |||||||||||||||||||||||||
612 | Flickable does not automatically clip its contents. If it is not used as | - | ||||||||||||||||||||||||
613 | a full-screen item, you should consider setting the \l{Item::}{clip} property | - | ||||||||||||||||||||||||
614 | to true. | - | ||||||||||||||||||||||||
615 | - | |||||||||||||||||||||||||
616 | \section1 Example Usage | - | ||||||||||||||||||||||||
617 | - | |||||||||||||||||||||||||
618 | \div {class="float-right"} | - | ||||||||||||||||||||||||
619 | \inlineimage flickable.gif | - | ||||||||||||||||||||||||
620 | \enddiv | - | ||||||||||||||||||||||||
621 | - | |||||||||||||||||||||||||
622 | The following example shows a small view onto a large image in which the | - | ||||||||||||||||||||||||
623 | user can drag or flick the image in order to view different parts of it. | - | ||||||||||||||||||||||||
624 | - | |||||||||||||||||||||||||
625 | \snippet qml/flickable.qml document | - | ||||||||||||||||||||||||
626 | - | |||||||||||||||||||||||||
627 | \clearfloat | - | ||||||||||||||||||||||||
628 | - | |||||||||||||||||||||||||
629 | Items declared as children of a Flickable are automatically parented to the | - | ||||||||||||||||||||||||
630 | Flickable's \l contentItem. This should be taken into account when | - | ||||||||||||||||||||||||
631 | operating on the children of the Flickable; it is usually the children of | - | ||||||||||||||||||||||||
632 | \c contentItem that are relevant. For example, the bound of Items added | - | ||||||||||||||||||||||||
633 | to the Flickable will be available by \c contentItem.childrenRect | - | ||||||||||||||||||||||||
634 | - | |||||||||||||||||||||||||
635 | \section1 Limitations | - | ||||||||||||||||||||||||
636 | - | |||||||||||||||||||||||||
637 | \note Due to an implementation detail, items placed inside a Flickable | - | ||||||||||||||||||||||||
638 | cannot anchor to the Flickable. Instead, use \l {Item::}{parent}, which | - | ||||||||||||||||||||||||
639 | refers to the Flickable's \l contentItem. The size of the content item is | - | ||||||||||||||||||||||||
640 | determined by \l contentWidth and \l contentHeight. | - | ||||||||||||||||||||||||
641 | */ | - | ||||||||||||||||||||||||
642 | - | |||||||||||||||||||||||||
643 | /*! | - | ||||||||||||||||||||||||
644 | \qmlsignal QtQuick::Flickable::movementStarted() | - | ||||||||||||||||||||||||
645 | - | |||||||||||||||||||||||||
646 | This signal is emitted when the view begins moving due to user | - | ||||||||||||||||||||||||
647 | interaction or a generated flick(). | - | ||||||||||||||||||||||||
648 | - | |||||||||||||||||||||||||
649 | The corresponding handler is \c onMovementStarted. | - | ||||||||||||||||||||||||
650 | */ | - | ||||||||||||||||||||||||
651 | - | |||||||||||||||||||||||||
652 | /*! | - | ||||||||||||||||||||||||
653 | \qmlsignal QtQuick::Flickable::movementEnded() | - | ||||||||||||||||||||||||
654 | - | |||||||||||||||||||||||||
655 | This signal is emitted when the view stops moving due to user | - | ||||||||||||||||||||||||
656 | interaction or a generated flick(). If a flick was active, this signal will | - | ||||||||||||||||||||||||
657 | be emitted once the flick stops. If a flick was not | - | ||||||||||||||||||||||||
658 | active, this signal will be emitted when the | - | ||||||||||||||||||||||||
659 | user stops dragging - i.e. a mouse or touch release. | - | ||||||||||||||||||||||||
660 | - | |||||||||||||||||||||||||
661 | The corresponding handler is \c onMovementEnded. | - | ||||||||||||||||||||||||
662 | */ | - | ||||||||||||||||||||||||
663 | - | |||||||||||||||||||||||||
664 | /*! | - | ||||||||||||||||||||||||
665 | \qmlsignal QtQuick::Flickable::flickStarted() | - | ||||||||||||||||||||||||
666 | - | |||||||||||||||||||||||||
667 | This signal is emitted when the view is flicked. A flick | - | ||||||||||||||||||||||||
668 | starts from the point that the mouse or touch is released, | - | ||||||||||||||||||||||||
669 | while still in motion. | - | ||||||||||||||||||||||||
670 | - | |||||||||||||||||||||||||
671 | The corresponding handler is \c onFlickStarted. | - | ||||||||||||||||||||||||
672 | */ | - | ||||||||||||||||||||||||
673 | - | |||||||||||||||||||||||||
674 | /*! | - | ||||||||||||||||||||||||
675 | \qmlsignal QtQuick::Flickable::flickEnded() | - | ||||||||||||||||||||||||
676 | - | |||||||||||||||||||||||||
677 | This signal is emitted when the view stops moving due to a flick. | - | ||||||||||||||||||||||||
678 | - | |||||||||||||||||||||||||
679 | The corresponding handler is \c onFlickEnded. | - | ||||||||||||||||||||||||
680 | */ | - | ||||||||||||||||||||||||
681 | - | |||||||||||||||||||||||||
682 | /*! | - | ||||||||||||||||||||||||
683 | \qmlpropertygroup QtQuick::Flickable::visibleArea | - | ||||||||||||||||||||||||
684 | \qmlproperty real QtQuick::Flickable::visibleArea.xPosition | - | ||||||||||||||||||||||||
685 | \qmlproperty real QtQuick::Flickable::visibleArea.widthRatio | - | ||||||||||||||||||||||||
686 | \qmlproperty real QtQuick::Flickable::visibleArea.yPosition | - | ||||||||||||||||||||||||
687 | \qmlproperty real QtQuick::Flickable::visibleArea.heightRatio | - | ||||||||||||||||||||||||
688 | - | |||||||||||||||||||||||||
689 | These properties describe the position and size of the currently viewed area. | - | ||||||||||||||||||||||||
690 | The size is defined as the percentage of the full view currently visible, | - | ||||||||||||||||||||||||
691 | scaled to 0.0 - 1.0. The page position is usually in the range 0.0 (beginning) to | - | ||||||||||||||||||||||||
692 | 1.0 minus size ratio (end), i.e. \c yPosition is in the range 0.0 to 1.0-\c heightRatio. | - | ||||||||||||||||||||||||
693 | However, it is possible for the contents to be dragged outside of the normal | - | ||||||||||||||||||||||||
694 | range, resulting in the page positions also being outside the normal range. | - | ||||||||||||||||||||||||
695 | - | |||||||||||||||||||||||||
696 | These properties are typically used to draw a scrollbar. For example: | - | ||||||||||||||||||||||||
697 | - | |||||||||||||||||||||||||
698 | \snippet qml/flickableScrollbar.qml 0 | - | ||||||||||||||||||||||||
699 | \dots 8 | - | ||||||||||||||||||||||||
700 | \snippet qml/flickableScrollbar.qml 1 | - | ||||||||||||||||||||||||
701 | - | |||||||||||||||||||||||||
702 | \sa {customitems/scrollbar}{UI Components: Scrollbar Example} | - | ||||||||||||||||||||||||
703 | */ | - | ||||||||||||||||||||||||
704 | QQuickFlickable::QQuickFlickable(QQuickItem *parent) | - | ||||||||||||||||||||||||
705 | : QQuickItem(*(new QQuickFlickablePrivate), parent) | - | ||||||||||||||||||||||||
706 | { | - | ||||||||||||||||||||||||
707 | Q_D(QQuickFlickable); | - | ||||||||||||||||||||||||
708 | d->init(); | - | ||||||||||||||||||||||||
709 | } executed 296 times by 7 tests: end of block Executed by:
| 296 | ||||||||||||||||||||||||
710 | - | |||||||||||||||||||||||||
711 | QQuickFlickable::QQuickFlickable(QQuickFlickablePrivate &dd, QQuickItem *parent) | - | ||||||||||||||||||||||||
712 | : QQuickItem(dd, parent) | - | ||||||||||||||||||||||||
713 | { | - | ||||||||||||||||||||||||
714 | Q_D(QQuickFlickable); | - | ||||||||||||||||||||||||
715 | d->init(); | - | ||||||||||||||||||||||||
716 | } executed 3804 times by 13 tests: end of block Executed by:
| 3804 | ||||||||||||||||||||||||
717 | - | |||||||||||||||||||||||||
718 | QQuickFlickable::~QQuickFlickable() | - | ||||||||||||||||||||||||
719 | { | - | ||||||||||||||||||||||||
720 | } | - | ||||||||||||||||||||||||
721 | - | |||||||||||||||||||||||||
722 | /*! | - | ||||||||||||||||||||||||
723 | \qmlproperty real QtQuick::Flickable::contentX | - | ||||||||||||||||||||||||
724 | \qmlproperty real QtQuick::Flickable::contentY | - | ||||||||||||||||||||||||
725 | - | |||||||||||||||||||||||||
726 | These properties hold the surface coordinate currently at the top-left | - | ||||||||||||||||||||||||
727 | corner of the Flickable. For example, if you flick an image up 100 pixels, | - | ||||||||||||||||||||||||
728 | \c contentY will increase by 100. | - | ||||||||||||||||||||||||
729 | - | |||||||||||||||||||||||||
730 | \note If you flick back to the origin (the top-left corner), after the | - | ||||||||||||||||||||||||
731 | rebound animation, \c contentX will settle to the same value as \c originX, | - | ||||||||||||||||||||||||
732 | and \c contentY to \c originY. These are usually (0,0), however ListView | - | ||||||||||||||||||||||||
733 | and GridView may have an arbitrary origin due to delegate size variation, | - | ||||||||||||||||||||||||
734 | or item insertion/removal outside the visible region. So if you want to | - | ||||||||||||||||||||||||
735 | implement something like a vertical scrollbar, one way is to use | - | ||||||||||||||||||||||||
736 | \c {y: (contentY - originY) * (height / contentHeight)} | - | ||||||||||||||||||||||||
737 | for the position; another way is to use the normalized values in | - | ||||||||||||||||||||||||
738 | \l {QtQuick::Flickable::visibleArea}{visibleArea}. | - | ||||||||||||||||||||||||
739 | - | |||||||||||||||||||||||||
740 | \sa originX, originY | - | ||||||||||||||||||||||||
741 | */ | - | ||||||||||||||||||||||||
742 | qreal QQuickFlickable::contentX() const | - | ||||||||||||||||||||||||
743 | { | - | ||||||||||||||||||||||||
744 | Q_D(const QQuickFlickable); | - | ||||||||||||||||||||||||
745 | return -d->contentItem->x(); executed 65931 times by 10 tests: return -d->contentItem->x(); Executed by:
| 65931 | ||||||||||||||||||||||||
746 | } | - | ||||||||||||||||||||||||
747 | - | |||||||||||||||||||||||||
748 | void QQuickFlickable::setContentX(qreal pos) | - | ||||||||||||||||||||||||
749 | { | - | ||||||||||||||||||||||||
750 | Q_D(QQuickFlickable); | - | ||||||||||||||||||||||||
751 | d->hData.explicitValue = true; | - | ||||||||||||||||||||||||
752 | d->resetTimeline(d->hData); | - | ||||||||||||||||||||||||
753 | d->hData.vTime = d->timeline.time(); | - | ||||||||||||||||||||||||
754 | if (isMoving() || isFlicking())
| 0-8592 | ||||||||||||||||||||||||
755 | movementEnding(true, false); executed 24 times by 2 tests: movementEnding(true, false); Executed by:
| 24 | ||||||||||||||||||||||||
756 | if (-pos != d->hData.move.value())
| 1647-6969 | ||||||||||||||||||||||||
757 | d->hData.move.setValue(-pos); executed 1647 times by 6 tests: d->hData.move.setValue(-pos); Executed by:
| 1647 | ||||||||||||||||||||||||
758 | } executed 8616 times by 8 tests: end of block Executed by:
| 8616 | ||||||||||||||||||||||||
759 | - | |||||||||||||||||||||||||
760 | qreal QQuickFlickable::contentY() const | - | ||||||||||||||||||||||||
761 | { | - | ||||||||||||||||||||||||
762 | Q_D(const QQuickFlickable); | - | ||||||||||||||||||||||||
763 | return -d->contentItem->y(); executed 136739 times by 15 tests: return -d->contentItem->y(); Executed by:
| 136739 | ||||||||||||||||||||||||
764 | } | - | ||||||||||||||||||||||||
765 | - | |||||||||||||||||||||||||
766 | void QQuickFlickable::setContentY(qreal pos) | - | ||||||||||||||||||||||||
767 | { | - | ||||||||||||||||||||||||
768 | Q_D(QQuickFlickable); | - | ||||||||||||||||||||||||
769 | d->vData.explicitValue = true; | - | ||||||||||||||||||||||||
770 | d->resetTimeline(d->vData); | - | ||||||||||||||||||||||||
771 | d->vData.vTime = d->timeline.time(); | - | ||||||||||||||||||||||||
772 | if (isMoving() || isFlicking())
| 0-13909 | ||||||||||||||||||||||||
773 | movementEnding(false, true); executed 24 times by 2 tests: movementEnding(false, true); Executed by:
| 24 | ||||||||||||||||||||||||
774 | if (-pos != d->vData.move.value())
| 3501-10432 | ||||||||||||||||||||||||
775 | d->vData.move.setValue(-pos); executed 3501 times by 6 tests: d->vData.move.setValue(-pos); Executed by:
| 3501 | ||||||||||||||||||||||||
776 | } executed 13933 times by 13 tests: end of block Executed by:
| 13933 | ||||||||||||||||||||||||
777 | - | |||||||||||||||||||||||||
778 | /*! | - | ||||||||||||||||||||||||
779 | \qmlproperty bool QtQuick::Flickable::interactive | - | ||||||||||||||||||||||||
780 | - | |||||||||||||||||||||||||
781 | This property describes whether the user can interact with the Flickable. | - | ||||||||||||||||||||||||
782 | A user cannot drag or flick a Flickable that is not interactive. | - | ||||||||||||||||||||||||
783 | - | |||||||||||||||||||||||||
784 | By default, this property is true. | - | ||||||||||||||||||||||||
785 | - | |||||||||||||||||||||||||
786 | This property is useful for temporarily disabling flicking. This allows | - | ||||||||||||||||||||||||
787 | special interaction with Flickable's children; for example, you might want | - | ||||||||||||||||||||||||
788 | to freeze a flickable map while scrolling through a pop-up dialog that | - | ||||||||||||||||||||||||
789 | is a child of the Flickable. | - | ||||||||||||||||||||||||
790 | */ | - | ||||||||||||||||||||||||
791 | bool QQuickFlickable::isInteractive() const | - | ||||||||||||||||||||||||
792 | { | - | ||||||||||||||||||||||||
793 | Q_D(const QQuickFlickable); | - | ||||||||||||||||||||||||
794 | return d->interactive; executed 2189 times by 7 tests: return d->interactive; Executed by:
| 2189 | ||||||||||||||||||||||||
795 | } | - | ||||||||||||||||||||||||
796 | - | |||||||||||||||||||||||||
797 | void QQuickFlickable::setInteractive(bool interactive) | - | ||||||||||||||||||||||||
798 | { | - | ||||||||||||||||||||||||
799 | Q_D(QQuickFlickable); | - | ||||||||||||||||||||||||
800 | if (interactive != d->interactive) {
| 4-24 | ||||||||||||||||||||||||
801 | d->interactive = interactive; | - | ||||||||||||||||||||||||
802 | if (!interactive) {
| 8-16 | ||||||||||||||||||||||||
803 | d->cancelInteraction(); | - | ||||||||||||||||||||||||
804 | } executed 16 times by 4 tests: end of block Executed by:
| 16 | ||||||||||||||||||||||||
805 | emit interactiveChanged(); | - | ||||||||||||||||||||||||
806 | } executed 24 times by 4 tests: end of block Executed by:
| 24 | ||||||||||||||||||||||||
807 | } executed 28 times by 4 tests: end of block Executed by:
| 28 | ||||||||||||||||||||||||
808 | - | |||||||||||||||||||||||||
809 | /*! | - | ||||||||||||||||||||||||
810 | \qmlproperty real QtQuick::Flickable::horizontalVelocity | - | ||||||||||||||||||||||||
811 | \qmlproperty real QtQuick::Flickable::verticalVelocity | - | ||||||||||||||||||||||||
812 | - | |||||||||||||||||||||||||
813 | The instantaneous velocity of movement along the x and y axes, in pixels/sec. | - | ||||||||||||||||||||||||
814 | - | |||||||||||||||||||||||||
815 | The reported velocity is smoothed to avoid erratic output. | - | ||||||||||||||||||||||||
816 | - | |||||||||||||||||||||||||
817 | Note that for views with a large content size (more than 10 times the view size), | - | ||||||||||||||||||||||||
818 | the velocity of the flick may exceed the velocity of the touch in the case | - | ||||||||||||||||||||||||
819 | of multiple quick consecutive flicks. This allows the user to flick faster | - | ||||||||||||||||||||||||
820 | through large content. | - | ||||||||||||||||||||||||
821 | */ | - | ||||||||||||||||||||||||
822 | qreal QQuickFlickable::horizontalVelocity() const | - | ||||||||||||||||||||||||
823 | { | - | ||||||||||||||||||||||||
824 | Q_D(const QQuickFlickable); | - | ||||||||||||||||||||||||
825 | return d->hData.smoothVelocity.value(); executed 15 times by 3 tests: return d->hData.smoothVelocity.value(); Executed by:
| 15 | ||||||||||||||||||||||||
826 | } | - | ||||||||||||||||||||||||
827 | - | |||||||||||||||||||||||||
828 | qreal QQuickFlickable::verticalVelocity() const | - | ||||||||||||||||||||||||
829 | { | - | ||||||||||||||||||||||||
830 | Q_D(const QQuickFlickable); | - | ||||||||||||||||||||||||
831 | return d->vData.smoothVelocity.value(); executed 62 times by 3 tests: return d->vData.smoothVelocity.value(); Executed by:
| 62 | ||||||||||||||||||||||||
832 | } | - | ||||||||||||||||||||||||
833 | - | |||||||||||||||||||||||||
834 | /*! | - | ||||||||||||||||||||||||
835 | \qmlproperty bool QtQuick::Flickable::atXBeginning | - | ||||||||||||||||||||||||
836 | \qmlproperty bool QtQuick::Flickable::atXEnd | - | ||||||||||||||||||||||||
837 | \qmlproperty bool QtQuick::Flickable::atYBeginning | - | ||||||||||||||||||||||||
838 | \qmlproperty bool QtQuick::Flickable::atYEnd | - | ||||||||||||||||||||||||
839 | - | |||||||||||||||||||||||||
840 | These properties are true if the flickable view is positioned at the beginning, | - | ||||||||||||||||||||||||
841 | or end respectively. | - | ||||||||||||||||||||||||
842 | */ | - | ||||||||||||||||||||||||
843 | bool QQuickFlickable::isAtXEnd() const | - | ||||||||||||||||||||||||
844 | { | - | ||||||||||||||||||||||||
845 | Q_D(const QQuickFlickable); | - | ||||||||||||||||||||||||
846 | return d->hData.atEnd; executed 168 times by 3 tests: return d->hData.atEnd; Executed by:
| 168 | ||||||||||||||||||||||||
847 | } | - | ||||||||||||||||||||||||
848 | - | |||||||||||||||||||||||||
849 | bool QQuickFlickable::isAtXBeginning() const | - | ||||||||||||||||||||||||
850 | { | - | ||||||||||||||||||||||||
851 | Q_D(const QQuickFlickable); | - | ||||||||||||||||||||||||
852 | return d->hData.atBeginning; executed 158 times by 3 tests: return d->hData.atBeginning; Executed by:
| 158 | ||||||||||||||||||||||||
853 | } | - | ||||||||||||||||||||||||
854 | - | |||||||||||||||||||||||||
855 | bool QQuickFlickable::isAtYEnd() const | - | ||||||||||||||||||||||||
856 | { | - | ||||||||||||||||||||||||
857 | Q_D(const QQuickFlickable); | - | ||||||||||||||||||||||||
858 | return d->vData.atEnd; executed 193 times by 5 tests: return d->vData.atEnd; Executed by:
| 193 | ||||||||||||||||||||||||
859 | } | - | ||||||||||||||||||||||||
860 | - | |||||||||||||||||||||||||
861 | bool QQuickFlickable::isAtYBeginning() const | - | ||||||||||||||||||||||||
862 | { | - | ||||||||||||||||||||||||
863 | Q_D(const QQuickFlickable); | - | ||||||||||||||||||||||||
864 | return d->vData.atBeginning; executed 190 times by 5 tests: return d->vData.atBeginning; Executed by:
| 190 | ||||||||||||||||||||||||
865 | } | - | ||||||||||||||||||||||||
866 | - | |||||||||||||||||||||||||
867 | /*! | - | ||||||||||||||||||||||||
868 | \qmlproperty Item QtQuick::Flickable::contentItem | - | ||||||||||||||||||||||||
869 | - | |||||||||||||||||||||||||
870 | The internal item that contains the Items to be moved in the Flickable. | - | ||||||||||||||||||||||||
871 | - | |||||||||||||||||||||||||
872 | Items declared as children of a Flickable are automatically parented to the Flickable's contentItem. | - | ||||||||||||||||||||||||
873 | - | |||||||||||||||||||||||||
874 | Items created dynamically need to be explicitly parented to the \e contentItem: | - | ||||||||||||||||||||||||
875 | \code | - | ||||||||||||||||||||||||
876 | Flickable { | - | ||||||||||||||||||||||||
877 | id: myFlickable | - | ||||||||||||||||||||||||
878 | function addItem(file) { | - | ||||||||||||||||||||||||
879 | var component = Qt.createComponent(file) | - | ||||||||||||||||||||||||
880 | component.createObject(myFlickable.contentItem); | - | ||||||||||||||||||||||||
881 | } | - | ||||||||||||||||||||||||
882 | } | - | ||||||||||||||||||||||||
883 | \endcode | - | ||||||||||||||||||||||||
884 | */ | - | ||||||||||||||||||||||||
885 | QQuickItem *QQuickFlickable::contentItem() const | - | ||||||||||||||||||||||||
886 | { | - | ||||||||||||||||||||||||
887 | Q_D(const QQuickFlickable); | - | ||||||||||||||||||||||||
888 | return d->contentItem; executed 172139 times by 12 tests: return d->contentItem; Executed by:
| 172139 | ||||||||||||||||||||||||
889 | } | - | ||||||||||||||||||||||||
890 | - | |||||||||||||||||||||||||
891 | QQuickFlickableVisibleArea *QQuickFlickable::visibleArea() | - | ||||||||||||||||||||||||
892 | { | - | ||||||||||||||||||||||||
893 | Q_D(QQuickFlickable); | - | ||||||||||||||||||||||||
894 | if (!d->visibleArea) {
| 566-1802 | ||||||||||||||||||||||||
895 | d->visibleArea = new QQuickFlickableVisibleArea(this); | - | ||||||||||||||||||||||||
896 | d->visibleArea->updateVisible(); // calculate initial ratios | - | ||||||||||||||||||||||||
897 | } executed 566 times by 3 tests: end of block Executed by:
| 566 | ||||||||||||||||||||||||
898 | return d->visibleArea; executed 2368 times by 3 tests: return d->visibleArea; Executed by:
| 2368 | ||||||||||||||||||||||||
899 | } | - | ||||||||||||||||||||||||
900 | - | |||||||||||||||||||||||||
901 | /*! | - | ||||||||||||||||||||||||
902 | \qmlproperty enumeration QtQuick::Flickable::flickableDirection | - | ||||||||||||||||||||||||
903 | - | |||||||||||||||||||||||||
904 | This property determines which directions the view can be flicked. | - | ||||||||||||||||||||||||
905 | - | |||||||||||||||||||||||||
906 | \list | - | ||||||||||||||||||||||||
907 | \li Flickable.AutoFlickDirection (default) - allows flicking vertically if the | - | ||||||||||||||||||||||||
908 | \e contentHeight is not equal to the \e height of the Flickable. | - | ||||||||||||||||||||||||
909 | Allows flicking horizontally if the \e contentWidth is not equal | - | ||||||||||||||||||||||||
910 | to the \e width of the Flickable. | - | ||||||||||||||||||||||||
911 | \li Flickable.AutoFlickIfNeeded - allows flicking vertically if the | - | ||||||||||||||||||||||||
912 | \e contentHeight is greater than the \e height of the Flickable. | - | ||||||||||||||||||||||||
913 | Allows flicking horizontally if the \e contentWidth is greater than | - | ||||||||||||||||||||||||
914 | to the \e width of the Flickable. (since \c{QtQuick 2.7}) | - | ||||||||||||||||||||||||
915 | \li Flickable.HorizontalFlick - allows flicking horizontally. | - | ||||||||||||||||||||||||
916 | \li Flickable.VerticalFlick - allows flicking vertically. | - | ||||||||||||||||||||||||
917 | \li Flickable.HorizontalAndVerticalFlick - allows flicking in both directions. | - | ||||||||||||||||||||||||
918 | \endlist | - | ||||||||||||||||||||||||
919 | */ | - | ||||||||||||||||||||||||
920 | QQuickFlickable::FlickableDirection QQuickFlickable::flickableDirection() const | - | ||||||||||||||||||||||||
921 | { | - | ||||||||||||||||||||||||
922 | Q_D(const QQuickFlickable); | - | ||||||||||||||||||||||||
923 | return d->flickableDirection; executed 66 times by 1 test: return d->flickableDirection; Executed by:
| 66 | ||||||||||||||||||||||||
924 | } | - | ||||||||||||||||||||||||
925 | - | |||||||||||||||||||||||||
926 | void QQuickFlickable::setFlickableDirection(FlickableDirection direction) | - | ||||||||||||||||||||||||
927 | { | - | ||||||||||||||||||||||||
928 | Q_D(QQuickFlickable); | - | ||||||||||||||||||||||||
929 | if (direction != d->flickableDirection) {
| 56-4658 | ||||||||||||||||||||||||
930 | d->flickableDirection = direction; | - | ||||||||||||||||||||||||
931 | emit flickableDirectionChanged(); | - | ||||||||||||||||||||||||
932 | } executed 4658 times by 15 tests: end of block Executed by:
| 4658 | ||||||||||||||||||||||||
933 | } executed 4714 times by 15 tests: end of block Executed by:
| 4714 | ||||||||||||||||||||||||
934 | - | |||||||||||||||||||||||||
935 | /*! | - | ||||||||||||||||||||||||
936 | \qmlproperty bool QtQuick::Flickable::pixelAligned | - | ||||||||||||||||||||||||
937 | - | |||||||||||||||||||||||||
938 | This property sets the alignment of \l contentX and \l contentY to | - | ||||||||||||||||||||||||
939 | pixels (\c true) or subpixels (\c false). | - | ||||||||||||||||||||||||
940 | - | |||||||||||||||||||||||||
941 | Enable pixelAligned to optimize for still content or moving content with | - | ||||||||||||||||||||||||
942 | high constrast edges, such as one-pixel-wide lines, text or vector graphics. | - | ||||||||||||||||||||||||
943 | Disable pixelAligned when optimizing for animation quality. | - | ||||||||||||||||||||||||
944 | - | |||||||||||||||||||||||||
945 | The default is \c false. | - | ||||||||||||||||||||||||
946 | */ | - | ||||||||||||||||||||||||
947 | bool QQuickFlickable::pixelAligned() const | - | ||||||||||||||||||||||||
948 | { | - | ||||||||||||||||||||||||
949 | Q_D(const QQuickFlickable); | - | ||||||||||||||||||||||||
950 | return d->pixelAligned; never executed: return d->pixelAligned; | 0 | ||||||||||||||||||||||||
951 | } | - | ||||||||||||||||||||||||
952 | - | |||||||||||||||||||||||||
953 | void QQuickFlickable::setPixelAligned(bool align) | - | ||||||||||||||||||||||||
954 | { | - | ||||||||||||||||||||||||
955 | Q_D(QQuickFlickable); | - | ||||||||||||||||||||||||
956 | if (align != d->pixelAligned) {
| 10-42 | ||||||||||||||||||||||||
957 | d->pixelAligned = align; | - | ||||||||||||||||||||||||
958 | emit pixelAlignedChanged(); | - | ||||||||||||||||||||||||
959 | } executed 42 times by 2 tests: end of block Executed by:
| 42 | ||||||||||||||||||||||||
960 | } executed 52 times by 2 tests: end of block Executed by:
| 52 | ||||||||||||||||||||||||
961 | - | |||||||||||||||||||||||||
962 | qint64 QQuickFlickablePrivate::computeCurrentTime(QInputEvent *event) const | - | ||||||||||||||||||||||||
963 | { | - | ||||||||||||||||||||||||
964 | if (0 != event->timestamp())
| 0-6406 | ||||||||||||||||||||||||
965 | return event->timestamp(); executed 6406 times by 7 tests: return event->timestamp(); Executed by:
| 6406 | ||||||||||||||||||||||||
966 | if (!timer.isValid())
| 0 | ||||||||||||||||||||||||
967 | return 0LL; never executed: return 0LL; | 0 | ||||||||||||||||||||||||
968 | return timer.elapsed(); never executed: return timer.elapsed(); | 0 | ||||||||||||||||||||||||
969 | } | - | ||||||||||||||||||||||||
970 | - | |||||||||||||||||||||||||
971 | qreal QQuickFlickablePrivate::devicePixelRatio() const | - | ||||||||||||||||||||||||
972 | { | - | ||||||||||||||||||||||||
973 | return (window ? window->effectiveDevicePixelRatio() : qApp->devicePixelRatio()); never executed: return (window ? window->effectiveDevicePixelRatio() : (static_cast<QGuiApplication *>(QCoreApplication::instance()))->devicePixelRatio()); | 0 | ||||||||||||||||||||||||
974 | } | - | ||||||||||||||||||||||||
975 | - | |||||||||||||||||||||||||
976 | void QQuickFlickablePrivate::handleMousePressEvent(QMouseEvent *event) | - | ||||||||||||||||||||||||
977 | { | - | ||||||||||||||||||||||||
978 | Q_Q(QQuickFlickable); | - | ||||||||||||||||||||||||
979 | timer.start(); | - | ||||||||||||||||||||||||
980 | if (interactive && timeline.isActive()
| 0-1012 | ||||||||||||||||||||||||
981 | && ((qAbs(hData.smoothVelocity.value()) > RetainGrabVelocity && !hData.fixingUp && !hData.inOvershoot)
| 0-25 | ||||||||||||||||||||||||
982 | || (qAbs(vData.smoothVelocity.value()) > RetainGrabVelocity && !vData.fixingUp && !vData.inOvershoot))) {
| 0-23 | ||||||||||||||||||||||||
983 | stealMouse = true; // If we've been flicked then steal the click. | - | ||||||||||||||||||||||||
984 | int flickTime = timeline.time(); | - | ||||||||||||||||||||||||
985 | if (flickTime > 600) {
| 0-20 | ||||||||||||||||||||||||
986 | // too long between flicks - cancel boost | - | ||||||||||||||||||||||||
987 | hData.continuousFlickVelocity = 0; | - | ||||||||||||||||||||||||
988 | vData.continuousFlickVelocity = 0; | - | ||||||||||||||||||||||||
989 | flickBoost = 1.0; | - | ||||||||||||||||||||||||
990 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
991 | hData.continuousFlickVelocity = -hData.smoothVelocity.value(); | - | ||||||||||||||||||||||||
992 | vData.continuousFlickVelocity = -vData.smoothVelocity.value(); | - | ||||||||||||||||||||||||
993 | if (flickTime > 300) // slower flicking - reduce boost
| 0-20 | ||||||||||||||||||||||||
994 | flickBoost = qMax(1.0, flickBoost - 0.5); never executed: flickBoost = qMax(1.0, flickBoost - 0.5); | 0 | ||||||||||||||||||||||||
995 | } executed 20 times by 2 tests: end of block Executed by:
| 20 | ||||||||||||||||||||||||
996 | } else { | - | ||||||||||||||||||||||||
997 | stealMouse = false; | - | ||||||||||||||||||||||||
998 | hData.continuousFlickVelocity = 0; | - | ||||||||||||||||||||||||
999 | vData.continuousFlickVelocity = 0; | - | ||||||||||||||||||||||||
1000 | flickBoost = 1.0; | - | ||||||||||||||||||||||||
1001 | } executed 992 times by 7 tests: end of block Executed by:
| 992 | ||||||||||||||||||||||||
1002 | q->setKeepMouseGrab(stealMouse); | - | ||||||||||||||||||||||||
1003 | - | |||||||||||||||||||||||||
1004 | maybeBeginDrag(computeCurrentTime(event), event->localPos()); | - | ||||||||||||||||||||||||
1005 | } executed 1012 times by 7 tests: end of block Executed by:
| 1012 | ||||||||||||||||||||||||
1006 | - | |||||||||||||||||||||||||
1007 | void QQuickFlickablePrivate::maybeBeginDrag(qint64 currentTimestamp, const QPointF &pressPosn) | - | ||||||||||||||||||||||||
1008 | { | - | ||||||||||||||||||||||||
1009 | Q_Q(QQuickFlickable); | - | ||||||||||||||||||||||||
1010 | clearDelayedPress(); | - | ||||||||||||||||||||||||
1011 | pressed = true; | - | ||||||||||||||||||||||||
1012 | - | |||||||||||||||||||||||||
1013 | if (hData.transitionToBounds)
| 0-1012 | ||||||||||||||||||||||||
1014 | hData.transitionToBounds->stopTransition(); never executed: hData.transitionToBounds->stopTransition(); | 0 | ||||||||||||||||||||||||
1015 | if (vData.transitionToBounds)
| 0-1012 | ||||||||||||||||||||||||
1016 | vData.transitionToBounds->stopTransition(); never executed: vData.transitionToBounds->stopTransition(); | 0 | ||||||||||||||||||||||||
1017 | if (!hData.fixingUp)
| 6-1006 | ||||||||||||||||||||||||
1018 | resetTimeline(hData); executed 1006 times by 7 tests: resetTimeline(hData); Executed by:
| 1006 | ||||||||||||||||||||||||
1019 | if (!vData.fixingUp)
| 19-993 | ||||||||||||||||||||||||
1020 | resetTimeline(vData); executed 993 times by 7 tests: resetTimeline(vData); Executed by:
| 993 | ||||||||||||||||||||||||
1021 | - | |||||||||||||||||||||||||
1022 | hData.reset(); | - | ||||||||||||||||||||||||
1023 | vData.reset(); | - | ||||||||||||||||||||||||
1024 | hData.dragMinBound = q->minXExtent() - hData.startMargin; | - | ||||||||||||||||||||||||
1025 | vData.dragMinBound = q->minYExtent() - vData.startMargin; | - | ||||||||||||||||||||||||
1026 | hData.dragMaxBound = q->maxXExtent() + hData.endMargin; | - | ||||||||||||||||||||||||
1027 | vData.dragMaxBound = q->maxYExtent() + vData.endMargin; | - | ||||||||||||||||||||||||
1028 | fixupMode = Normal; | - | ||||||||||||||||||||||||
1029 | lastPos = QPointF(); | - | ||||||||||||||||||||||||
1030 | pressPos = pressPosn; | - | ||||||||||||||||||||||||
1031 | hData.pressPos = hData.move.value(); | - | ||||||||||||||||||||||||
1032 | vData.pressPos = vData.move.value(); | - | ||||||||||||||||||||||||
1033 | bool wasFlicking = hData.flicking || vData.flicking;
| 8-1004 | ||||||||||||||||||||||||
1034 | if (hData.flicking) {
| 8-1004 | ||||||||||||||||||||||||
1035 | hData.flicking = false; | - | ||||||||||||||||||||||||
1036 | emit q->flickingHorizontallyChanged(); | - | ||||||||||||||||||||||||
1037 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||||||||||||||
1038 | if (vData.flicking) {
| 23-989 | ||||||||||||||||||||||||
1039 | vData.flicking = false; | - | ||||||||||||||||||||||||
1040 | emit q->flickingVerticallyChanged(); | - | ||||||||||||||||||||||||
1041 | } executed 23 times by 2 tests: end of block Executed by:
| 23 | ||||||||||||||||||||||||
1042 | if (wasFlicking)
| 31-981 | ||||||||||||||||||||||||
1043 | emit q->flickingChanged(); executed 31 times by 2 tests: q->flickingChanged(); Executed by:
| 31 | ||||||||||||||||||||||||
1044 | lastPosTime = lastPressTime = currentTimestamp; | - | ||||||||||||||||||||||||
1045 | vData.velocityTime.start(); | - | ||||||||||||||||||||||||
1046 | hData.velocityTime.start(); | - | ||||||||||||||||||||||||
1047 | } executed 1012 times by 7 tests: end of block Executed by:
| 1012 | ||||||||||||||||||||||||
1048 | - | |||||||||||||||||||||||||
1049 | void QQuickFlickablePrivate::drag(qint64 currentTimestamp, QEvent::Type eventType, const QPointF &localPos, | - | ||||||||||||||||||||||||
1050 | const QVector2D &deltas, bool overThreshold, bool momentum, | - | ||||||||||||||||||||||||
1051 | bool velocitySensitiveOverBounds, const QVector2D &velocity) | - | ||||||||||||||||||||||||
1052 | { | - | ||||||||||||||||||||||||
1053 | Q_Q(QQuickFlickable); | - | ||||||||||||||||||||||||
1054 | bool rejectY = false; | - | ||||||||||||||||||||||||
1055 | bool rejectX = false; | - | ||||||||||||||||||||||||
1056 | - | |||||||||||||||||||||||||
1057 | bool keepY = q->yflick(); | - | ||||||||||||||||||||||||
1058 | bool keepX = q->xflick(); | - | ||||||||||||||||||||||||
1059 | - | |||||||||||||||||||||||||
1060 | bool stealY = false; | - | ||||||||||||||||||||||||
1061 | bool stealX = false; | - | ||||||||||||||||||||||||
1062 | if (eventType == QEvent::MouseMove) {
| 0-4540 | ||||||||||||||||||||||||
1063 | stealX = stealY = stealMouse; | - | ||||||||||||||||||||||||
1064 | } else if (eventType == QEvent::Wheel) { executed 4540 times by 7 tests: end of block Executed by:
| 0-4540 | ||||||||||||||||||||||||
1065 | stealX = stealY = scrollingPhase; | - | ||||||||||||||||||||||||
1066 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1067 | - | |||||||||||||||||||||||||
1068 | bool prevHMoved = hMoved; | - | ||||||||||||||||||||||||
1069 | bool prevVMoved = vMoved; | - | ||||||||||||||||||||||||
1070 | - | |||||||||||||||||||||||||
1071 | qint64 elapsedSincePress = currentTimestamp - lastPressTime; | - | ||||||||||||||||||||||||
1072 | - | |||||||||||||||||||||||||
1073 | if (q->yflick()) {
| 1516-3024 | ||||||||||||||||||||||||
1074 | qreal dy = deltas.y(); | - | ||||||||||||||||||||||||
1075 | if (overThreshold || elapsedSincePress > 200) {
| 8-2662 | ||||||||||||||||||||||||
1076 | if (!vMoved)
| 1174-1496 | ||||||||||||||||||||||||
1077 | vData.dragStartOffset = dy; executed 1174 times by 6 tests: vData.dragStartOffset = dy; Executed by:
| 1174 | ||||||||||||||||||||||||
1078 | qreal newY = dy + vData.pressPos - vData.dragStartOffset; | - | ||||||||||||||||||||||||
1079 | // Recalculate bounds in case margins have changed, but use the content | - | ||||||||||||||||||||||||
1080 | // size estimate taken at the start of the drag in case the drag causes | - | ||||||||||||||||||||||||
1081 | // the estimate to be altered | - | ||||||||||||||||||||||||
1082 | const qreal minY = vData.dragMinBound + vData.startMargin; | - | ||||||||||||||||||||||||
1083 | const qreal maxY = vData.dragMaxBound - vData.endMargin; | - | ||||||||||||||||||||||||
1084 | if (!(boundsBehavior & QQuickFlickable::DragOverBounds)) {
| 600-2070 | ||||||||||||||||||||||||
1085 | if (fuzzyLessThanOrEqualTo(newY, maxY)) {
| 110-490 | ||||||||||||||||||||||||
1086 | newY = maxY; | - | ||||||||||||||||||||||||
1087 | rejectY = vData.pressPos == maxY && vData.move.value() == maxY && dy < 0;
| 4-102 | ||||||||||||||||||||||||
1088 | } executed 110 times by 1 test: end of block Executed by:
| 110 | ||||||||||||||||||||||||
1089 | if (fuzzyLessThanOrEqualTo(minY, newY)) {
| 110-490 | ||||||||||||||||||||||||
1090 | newY = minY; | - | ||||||||||||||||||||||||
1091 | rejectY |= vData.pressPos == minY && vData.move.value() == minY && dy > 0;
| 4-102 | ||||||||||||||||||||||||
1092 | } executed 110 times by 1 test: end of block Executed by:
| 110 | ||||||||||||||||||||||||
1093 | } else { executed 600 times by 1 test: end of block Executed by:
| 600 | ||||||||||||||||||||||||
1094 | qreal vel = velocity.y() / QML_FLICK_OVERSHOOTFRICTION; | - | ||||||||||||||||||||||||
1095 | if (vel > 0. && vel > vData.velocity)
| 108-1178 | ||||||||||||||||||||||||
1096 | vData.velocity = qMin(velocity.y() / QML_FLICK_OVERSHOOTFRICTION, float(QML_FLICK_DEFAULTMAXVELOCITY)); executed 108 times by 6 tests: vData.velocity = qMin(velocity.y() / 8, float(2500)); Executed by:
| 108 | ||||||||||||||||||||||||
1097 | else if (vel < 0. && vel < vData.velocity)
| 125-1142 | ||||||||||||||||||||||||
1098 | vData.velocity = qMax(velocity.y() / QML_FLICK_OVERSHOOTFRICTION, -float(QML_FLICK_DEFAULTMAXVELOCITY)); executed 125 times by 5 tests: vData.velocity = qMax(velocity.y() / 8, -float(2500)); Executed by:
| 125 | ||||||||||||||||||||||||
1099 | if (newY > minY) {
| 274-1796 | ||||||||||||||||||||||||
1100 | // Overshoot beyond the top. But don't wait for momentum phase to end before returning to bounds. | - | ||||||||||||||||||||||||
1101 | if (momentum && vData.atBeginning) {
| 0-274 | ||||||||||||||||||||||||
1102 | if (!vData.inRebound) {
| 0 | ||||||||||||||||||||||||
1103 | vData.inRebound = true; | - | ||||||||||||||||||||||||
1104 | q->returnToBounds(); | - | ||||||||||||||||||||||||
1105 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1106 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1107 | } | - | ||||||||||||||||||||||||
1108 | if (velocitySensitiveOverBounds) {
| 0-274 | ||||||||||||||||||||||||
1109 | qreal overshoot = (newY - minY) * vData.velocity / QML_FLICK_DEFAULTMAXVELOCITY / QML_FLICK_OVERSHOOTFRICTION; | - | ||||||||||||||||||||||||
1110 | overshoot = QML_FLICK_OVERSHOOT * devicePixelRatio() * EaseOvershoot(overshoot / QML_FLICK_OVERSHOOT / devicePixelRatio()); | - | ||||||||||||||||||||||||
1111 | newY = minY + overshoot; | - | ||||||||||||||||||||||||
1112 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
1113 | newY = minY + (newY - minY) / 2; | - | ||||||||||||||||||||||||
1114 | } executed 274 times by 5 tests: end of block Executed by:
| 274 | ||||||||||||||||||||||||
1115 | } else if (newY < maxY && maxY - minY <= 0) {
| 0-1707 | ||||||||||||||||||||||||
1116 | // Overshoot beyond the bottom. But don't wait for momentum phase to end before returning to bounds. | - | ||||||||||||||||||||||||
1117 | if (momentum && vData.atEnd) {
| 0-89 | ||||||||||||||||||||||||
1118 | if (!vData.inRebound) {
| 0 | ||||||||||||||||||||||||
1119 | vData.inRebound = true; | - | ||||||||||||||||||||||||
1120 | q->returnToBounds(); | - | ||||||||||||||||||||||||
1121 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1122 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1123 | } | - | ||||||||||||||||||||||||
1124 | if (velocitySensitiveOverBounds) {
| 0-89 | ||||||||||||||||||||||||
1125 | qreal overshoot = (newY - maxY) * vData.velocity / QML_FLICK_DEFAULTMAXVELOCITY / QML_FLICK_OVERSHOOTFRICTION; | - | ||||||||||||||||||||||||
1126 | overshoot = QML_FLICK_OVERSHOOT * devicePixelRatio() * EaseOvershoot(overshoot / QML_FLICK_OVERSHOOT / devicePixelRatio()); | - | ||||||||||||||||||||||||
1127 | newY = maxY - overshoot; | - | ||||||||||||||||||||||||
1128 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
1129 | newY = maxY + (newY - maxY) / 2; | - | ||||||||||||||||||||||||
1130 | } executed 89 times by 4 tests: end of block Executed by:
| 89 | ||||||||||||||||||||||||
1131 | } | - | ||||||||||||||||||||||||
1132 | } executed 2070 times by 6 tests: end of block Executed by:
| 2070 | ||||||||||||||||||||||||
1133 | if (!rejectY && stealMouse && dy != 0.0 && dy != vData.previousDragDelta) {
| 140-2530 | ||||||||||||||||||||||||
1134 | clearTimeline(); | - | ||||||||||||||||||||||||
1135 | vData.move.setValue(newY); | - | ||||||||||||||||||||||||
1136 | vMoved = true; | - | ||||||||||||||||||||||||
1137 | } executed 1554 times by 5 tests: end of block Executed by:
| 1554 | ||||||||||||||||||||||||
1138 | if (!rejectY && overThreshold)
| 8-2530 | ||||||||||||||||||||||||
1139 | stealY = true; executed 2522 times by 6 tests: stealY = true; Executed by:
| 2522 | ||||||||||||||||||||||||
1140 | - | |||||||||||||||||||||||||
1141 | if ((newY >= minY && vData.pressPos == minY && vData.move.value() == minY && dy > 0)
| 66-1992 | ||||||||||||||||||||||||
1142 | || (newY <= maxY && vData.pressPos == maxY && vData.move.value() == maxY && dy < 0)) {
| 40-2187 | ||||||||||||||||||||||||
1143 | keepY = false; | - | ||||||||||||||||||||||||
1144 | } executed 298 times by 5 tests: end of block Executed by:
| 298 | ||||||||||||||||||||||||
1145 | } executed 2670 times by 6 tests: end of block Executed by:
| 2670 | ||||||||||||||||||||||||
1146 | vData.previousDragDelta = dy; | - | ||||||||||||||||||||||||
1147 | } executed 3024 times by 6 tests: end of block Executed by:
| 3024 | ||||||||||||||||||||||||
1148 | - | |||||||||||||||||||||||||
1149 | if (q->xflick()) {
| 1900-2640 | ||||||||||||||||||||||||
1150 | qreal dx = deltas.x(); | - | ||||||||||||||||||||||||
1151 | if (overThreshold || elapsedSincePress > 200) {
| 0-2292 | ||||||||||||||||||||||||
1152 | if (!hMoved)
| 1116-1176 | ||||||||||||||||||||||||
1153 | hData.dragStartOffset = dx; executed 1116 times by 6 tests: hData.dragStartOffset = dx; Executed by:
| 1116 | ||||||||||||||||||||||||
1154 | qreal newX = dx + hData.pressPos - hData.dragStartOffset; | - | ||||||||||||||||||||||||
1155 | const qreal minX = hData.dragMinBound + hData.startMargin; | - | ||||||||||||||||||||||||
1156 | const qreal maxX = hData.dragMaxBound - hData.endMargin; | - | ||||||||||||||||||||||||
1157 | if (!(boundsBehavior & QQuickFlickable::DragOverBounds)) {
| 622-1670 | ||||||||||||||||||||||||
1158 | if (fuzzyLessThanOrEqualTo(newX, maxX)) {
| 132-490 | ||||||||||||||||||||||||
1159 | newX = maxX; | - | ||||||||||||||||||||||||
1160 | rejectX = hData.pressPos == maxX && hData.move.value() == maxX && dx < 0;
| 4-124 | ||||||||||||||||||||||||
1161 | } executed 132 times by 1 test: end of block Executed by:
| 132 | ||||||||||||||||||||||||
1162 | if (fuzzyLessThanOrEqualTo(minX, newX)) {
| 118-504 | ||||||||||||||||||||||||
1163 | newX = minX; | - | ||||||||||||||||||||||||
1164 | rejectX |= hData.pressPos == minX && hData.move.value() == minX && dx > 0;
| 4-110 | ||||||||||||||||||||||||
1165 | } executed 118 times by 1 test: end of block Executed by:
| 118 | ||||||||||||||||||||||||
1166 | } else { executed 622 times by 1 test: end of block Executed by:
| 622 | ||||||||||||||||||||||||
1167 | qreal vel = velocity.x() / QML_FLICK_OVERSHOOTFRICTION; | - | ||||||||||||||||||||||||
1168 | if (vel > 0. && vel > hData.velocity)
| 110-912 | ||||||||||||||||||||||||
1169 | hData.velocity = qMin(velocity.x() / QML_FLICK_OVERSHOOTFRICTION, float(QML_FLICK_DEFAULTMAXVELOCITY)); executed 110 times by 5 tests: hData.velocity = qMin(velocity.x() / 8, float(2500)); Executed by:
| 110 | ||||||||||||||||||||||||
1170 | else if (vel < 0. && vel < hData.velocity)
| 77-882 | ||||||||||||||||||||||||
1171 | hData.velocity = qMax(velocity.x() / QML_FLICK_OVERSHOOTFRICTION, -float(QML_FLICK_DEFAULTMAXVELOCITY)); executed 77 times by 4 tests: hData.velocity = qMax(velocity.x() / 8, -float(2500)); Executed by:
| 77 | ||||||||||||||||||||||||
1172 | if (newX > minX) {
| 86-1584 | ||||||||||||||||||||||||
1173 | // Overshoot beyond the left. But don't wait for momentum phase to end before returning to bounds. | - | ||||||||||||||||||||||||
1174 | if (momentum && hData.atBeginning) {
| 0-86 | ||||||||||||||||||||||||
1175 | if (!hData.inRebound) {
| 0 | ||||||||||||||||||||||||
1176 | hData.inRebound = true; | - | ||||||||||||||||||||||||
1177 | q->returnToBounds(); | - | ||||||||||||||||||||||||
1178 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1179 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1180 | } | - | ||||||||||||||||||||||||
1181 | if (velocitySensitiveOverBounds) {
| 0-86 | ||||||||||||||||||||||||
1182 | qreal overshoot = (newX - minX) * hData.velocity / QML_FLICK_DEFAULTMAXVELOCITY / QML_FLICK_OVERSHOOTFRICTION; | - | ||||||||||||||||||||||||
1183 | overshoot = QML_FLICK_OVERSHOOT * devicePixelRatio() * EaseOvershoot(overshoot / QML_FLICK_OVERSHOOT / devicePixelRatio()); | - | ||||||||||||||||||||||||
1184 | newX = minX + overshoot; | - | ||||||||||||||||||||||||
1185 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
1186 | newX = minX + (newX - minX) / 2; | - | ||||||||||||||||||||||||
1187 | } executed 86 times by 4 tests: end of block Executed by:
| 86 | ||||||||||||||||||||||||
1188 | } else if (newX < maxX && maxX - minX <= 0) {
| 0-1528 | ||||||||||||||||||||||||
1189 | // Overshoot beyond the right. But don't wait for momentum phase to end before returning to bounds. | - | ||||||||||||||||||||||||
1190 | if (momentum && hData.atEnd) {
| 0-56 | ||||||||||||||||||||||||
1191 | if (!hData.inRebound) {
| 0 | ||||||||||||||||||||||||
1192 | hData.inRebound = true; | - | ||||||||||||||||||||||||
1193 | q->returnToBounds(); | - | ||||||||||||||||||||||||
1194 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1195 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1196 | } | - | ||||||||||||||||||||||||
1197 | if (velocitySensitiveOverBounds) {
| 0-56 | ||||||||||||||||||||||||
1198 | qreal overshoot = (newX - maxX) * hData.velocity / QML_FLICK_DEFAULTMAXVELOCITY / QML_FLICK_OVERSHOOTFRICTION; | - | ||||||||||||||||||||||||
1199 | overshoot = QML_FLICK_OVERSHOOT * devicePixelRatio() * EaseOvershoot(overshoot / QML_FLICK_OVERSHOOT / devicePixelRatio()); | - | ||||||||||||||||||||||||
1200 | newX = maxX - overshoot; | - | ||||||||||||||||||||||||
1201 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
1202 | newX = maxX + (newX - maxX) / 2; | - | ||||||||||||||||||||||||
1203 | } executed 56 times by 3 tests: end of block Executed by:
| 56 | ||||||||||||||||||||||||
1204 | } | - | ||||||||||||||||||||||||
1205 | } executed 1670 times by 6 tests: end of block Executed by:
| 1670 | ||||||||||||||||||||||||
1206 | - | |||||||||||||||||||||||||
1207 | if (!rejectX && stealMouse && dx != 0.0 && dx != hData.previousDragDelta) {
| 154-2138 | ||||||||||||||||||||||||
1208 | clearTimeline(); | - | ||||||||||||||||||||||||
1209 | hData.move.setValue(newX); | - | ||||||||||||||||||||||||
1210 | hMoved = true; | - | ||||||||||||||||||||||||
1211 | } executed 1278 times by 6 tests: end of block Executed by:
| 1278 | ||||||||||||||||||||||||
1212 | - | |||||||||||||||||||||||||
1213 | if (!rejectX && overThreshold)
| 0-2138 | ||||||||||||||||||||||||
1214 | stealX = true; executed 2138 times by 6 tests: stealX = true; Executed by:
| 2138 | ||||||||||||||||||||||||
1215 | - | |||||||||||||||||||||||||
1216 | if ((newX >= minX && vData.pressPos == minX && vData.move.value() == minX && dx > 0)
| 8-1908 | ||||||||||||||||||||||||
1217 | || (newX <= maxX && vData.pressPos == maxX && vData.move.value() == maxX && dx < 0)) {
| 8-1844 | ||||||||||||||||||||||||
1218 | keepX = false; | - | ||||||||||||||||||||||||
1219 | } executed 224 times by 4 tests: end of block Executed by:
| 224 | ||||||||||||||||||||||||
1220 | } executed 2292 times by 6 tests: end of block Executed by:
| 2292 | ||||||||||||||||||||||||
1221 | hData.previousDragDelta = dx; | - | ||||||||||||||||||||||||
1222 | } executed 2640 times by 6 tests: end of block Executed by:
| 2640 | ||||||||||||||||||||||||
1223 | - | |||||||||||||||||||||||||
1224 | stealMouse = stealX || stealY;
| 342-3838 | ||||||||||||||||||||||||
1225 | if (stealMouse) {
| 360-4180 | ||||||||||||||||||||||||
1226 | if ((stealX && keepX) || (stealY && keepY))
| 12-3838 | ||||||||||||||||||||||||
1227 | q->setKeepMouseGrab(true); executed 4008 times by 7 tests: q->setKeepMouseGrab(true); Executed by:
| 4008 | ||||||||||||||||||||||||
1228 | clearDelayedPress(); | - | ||||||||||||||||||||||||
1229 | } executed 4180 times by 7 tests: end of block Executed by:
| 4180 | ||||||||||||||||||||||||
1230 | - | |||||||||||||||||||||||||
1231 | if (rejectY) {
| 140-4400 | ||||||||||||||||||||||||
1232 | vData.velocityBuffer.clear(); | - | ||||||||||||||||||||||||
1233 | vData.velocity = 0; | - | ||||||||||||||||||||||||
1234 | } executed 140 times by 1 test: end of block Executed by:
| 140 | ||||||||||||||||||||||||
1235 | if (rejectX) {
| 154-4386 | ||||||||||||||||||||||||
1236 | hData.velocityBuffer.clear(); | - | ||||||||||||||||||||||||
1237 | hData.velocity = 0; | - | ||||||||||||||||||||||||
1238 | } executed 154 times by 1 test: end of block Executed by:
| 154 | ||||||||||||||||||||||||
1239 | - | |||||||||||||||||||||||||
1240 | if (momentum && !hData.flicking && !vData.flicking)
| 0-4540 | ||||||||||||||||||||||||
1241 | flickingStarted(hData.velocity != 0, vData.velocity != 0); never executed: flickingStarted(hData.velocity != 0, vData.velocity != 0); | 0 | ||||||||||||||||||||||||
1242 | draggingStarting(); | - | ||||||||||||||||||||||||
1243 | - | |||||||||||||||||||||||||
1244 | if ((hMoved && !prevHMoved) || (vMoved && !prevVMoved))
| 305-2980 | ||||||||||||||||||||||||
1245 | q->movementStarting(); executed 681 times by 7 tests: q->movementStarting(); Executed by:
| 681 | ||||||||||||||||||||||||
1246 | - | |||||||||||||||||||||||||
1247 | lastPosTime = currentTimestamp; | - | ||||||||||||||||||||||||
1248 | if (q->yflick() && !rejectY)
| 140-3024 | ||||||||||||||||||||||||
1249 | vData.addVelocitySample(velocity.y(), maxVelocity); executed 2884 times by 6 tests: vData.addVelocitySample(velocity.y(), maxVelocity); Executed by:
| 2884 | ||||||||||||||||||||||||
1250 | if (q->xflick() && !rejectX)
| 154-2640 | ||||||||||||||||||||||||
1251 | hData.addVelocitySample(velocity.x(), maxVelocity); executed 2486 times by 6 tests: hData.addVelocitySample(velocity.x(), maxVelocity); Executed by:
| 2486 | ||||||||||||||||||||||||
1252 | lastPos = localPos; | - | ||||||||||||||||||||||||
1253 | } executed 4540 times by 7 tests: end of block Executed by:
| 4540 | ||||||||||||||||||||||||
1254 | - | |||||||||||||||||||||||||
1255 | void QQuickFlickablePrivate::handleMouseMoveEvent(QMouseEvent *event) | - | ||||||||||||||||||||||||
1256 | { | - | ||||||||||||||||||||||||
1257 | Q_Q(QQuickFlickable); | - | ||||||||||||||||||||||||
1258 | if (!interactive || lastPosTime == -1)
| 0-4624 | ||||||||||||||||||||||||
1259 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1260 | - | |||||||||||||||||||||||||
1261 | qint64 currentTimestamp = computeCurrentTime(event); | - | ||||||||||||||||||||||||
1262 | QVector2D deltas = QVector2D(event->localPos() - pressPos); | - | ||||||||||||||||||||||||
1263 | bool overThreshold = false; | - | ||||||||||||||||||||||||
1264 | QVector2D velocity = QGuiApplicationPrivate::mouseEventVelocity(event); | - | ||||||||||||||||||||||||
1265 | // TODO guarantee that events always have velocity so that it never needs to be computed here | - | ||||||||||||||||||||||||
1266 | if (!(QGuiApplicationPrivate::mouseEventCaps(event) & QTouchDevice::Velocity)) {
| 0-4624 | ||||||||||||||||||||||||
1267 | qint64 lastTimestamp = (lastPos.isNull() ? lastPressTime : lastPosTime);
| 864-3760 | ||||||||||||||||||||||||
1268 | if (currentTimestamp == lastTimestamp)
| 84-4540 | ||||||||||||||||||||||||
1269 | return; // events are too close together: velocity would be infinite executed 84 times by 1 test: return; Executed by:
| 84 | ||||||||||||||||||||||||
1270 | qreal elapsed = qreal(currentTimestamp - lastTimestamp) / 1000.; | - | ||||||||||||||||||||||||
1271 | velocity = QVector2D(event->localPos() - (lastPos.isNull() ? pressPos : lastPos)) / elapsed; | - | ||||||||||||||||||||||||
1272 | } executed 4540 times by 7 tests: end of block Executed by:
| 4540 | ||||||||||||||||||||||||
1273 | - | |||||||||||||||||||||||||
1274 | if (q->yflick())
| 1516-3024 | ||||||||||||||||||||||||
1275 | overThreshold |= QQuickWindowPrivate::dragOverThreshold(deltas.y(), Qt::YAxis, event); executed 3024 times by 6 tests: overThreshold |= QQuickWindowPrivate::dragOverThreshold(deltas.y(), Qt::YAxis, event); Executed by:
| 3024 | ||||||||||||||||||||||||
1276 | if (q->xflick())
| 1900-2640 | ||||||||||||||||||||||||
1277 | overThreshold |= QQuickWindowPrivate::dragOverThreshold(deltas.x(), Qt::XAxis, event); executed 2640 times by 6 tests: overThreshold |= QQuickWindowPrivate::dragOverThreshold(deltas.x(), Qt::XAxis, event); Executed by:
| 2640 | ||||||||||||||||||||||||
1278 | - | |||||||||||||||||||||||||
1279 | drag(currentTimestamp, event->type(), event->localPos(), deltas, overThreshold, false, false, velocity); | - | ||||||||||||||||||||||||
1280 | } executed 4540 times by 7 tests: end of block Executed by:
| 4540 | ||||||||||||||||||||||||
1281 | - | |||||||||||||||||||||||||
1282 | void QQuickFlickablePrivate::handleMouseReleaseEvent(QMouseEvent *event) | - | ||||||||||||||||||||||||
1283 | { | - | ||||||||||||||||||||||||
1284 | Q_Q(QQuickFlickable); | - | ||||||||||||||||||||||||
1285 | stealMouse = false; | - | ||||||||||||||||||||||||
1286 | q->setKeepMouseGrab(false); | - | ||||||||||||||||||||||||
1287 | pressed = false; | - | ||||||||||||||||||||||||
1288 | - | |||||||||||||||||||||||||
1289 | // if we drag then pause before release we should not cause a flick. | - | ||||||||||||||||||||||||
1290 | qint64 elapsed = computeCurrentTime(event) - lastPosTime; | - | ||||||||||||||||||||||||
1291 | - | |||||||||||||||||||||||||
1292 | vData.updateVelocity(); | - | ||||||||||||||||||||||||
1293 | hData.updateVelocity(); | - | ||||||||||||||||||||||||
1294 | - | |||||||||||||||||||||||||
1295 | draggingEnding(); | - | ||||||||||||||||||||||||
1296 | - | |||||||||||||||||||||||||
1297 | if (lastPosTime == -1)
| 10-760 | ||||||||||||||||||||||||
1298 | return; executed 10 times by 3 tests: return; Executed by:
| 10 | ||||||||||||||||||||||||
1299 | - | |||||||||||||||||||||||||
1300 | hData.vTime = vData.vTime = timeline.time(); | - | ||||||||||||||||||||||||
1301 | - | |||||||||||||||||||||||||
1302 | bool canBoost = false; | - | ||||||||||||||||||||||||
1303 | - | |||||||||||||||||||||||||
1304 | qreal vVelocity = 0; | - | ||||||||||||||||||||||||
1305 | if (elapsed < 100 && vData.velocity != 0.) {
| 0-760 | ||||||||||||||||||||||||
1306 | vVelocity = (QGuiApplicationPrivate::mouseEventCaps(event) & QTouchDevice::Velocity)
| 0-384 | ||||||||||||||||||||||||
1307 | ? QGuiApplicationPrivate::mouseEventVelocity(event).y() : vData.velocity; | - | ||||||||||||||||||||||||
1308 | } executed 384 times by 5 tests: end of block Executed by:
| 384 | ||||||||||||||||||||||||
1309 | if ((vData.atBeginning && vVelocity > 0.) || (vData.atEnd && vVelocity < 0.)) {
| 48-412 | ||||||||||||||||||||||||
1310 | vVelocity /= 2; | - | ||||||||||||||||||||||||
1311 | } else if (vData.continuousFlickVelocity != 0.0 executed 96 times by 5 tests: end of block Executed by:
| 8-656 | ||||||||||||||||||||||||
1312 | && vData.viewSize/q->height() > QML_FLICK_MULTIFLICK_RATIO
| 0-8 | ||||||||||||||||||||||||
1313 | && ((vVelocity > 0) == (vData.continuousFlickVelocity > 0))
| 0 | ||||||||||||||||||||||||
1314 | && qAbs(vVelocity) > QML_FLICK_MULTIFLICK_THRESHOLD) {
| 0 | ||||||||||||||||||||||||
1315 | // accelerate flick for large view flicked quickly | - | ||||||||||||||||||||||||
1316 | canBoost = true; | - | ||||||||||||||||||||||||
1317 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1318 | - | |||||||||||||||||||||||||
1319 | qreal hVelocity = 0; | - | ||||||||||||||||||||||||
1320 | if (elapsed < 100 && hData.velocity != 0.) {
| 0-760 | ||||||||||||||||||||||||
1321 | hVelocity = (QGuiApplicationPrivate::mouseEventCaps(event) & QTouchDevice::Velocity)
| 0-386 | ||||||||||||||||||||||||
1322 | ? QGuiApplicationPrivate::mouseEventVelocity(event).x() : hData.velocity; | - | ||||||||||||||||||||||||
1323 | } executed 386 times by 6 tests: end of block Executed by:
| 386 | ||||||||||||||||||||||||
1324 | if ((hData.atBeginning && hVelocity > 0.) || (hData.atEnd && hVelocity < 0.)) {
| 32-388 | ||||||||||||||||||||||||
1325 | hVelocity /= 2; | - | ||||||||||||||||||||||||
1326 | } else if (hData.continuousFlickVelocity != 0.0 executed 106 times by 4 tests: end of block Executed by:
| 8-646 | ||||||||||||||||||||||||
1327 | && hData.viewSize/q->width() > QML_FLICK_MULTIFLICK_RATIO
| 0-8 | ||||||||||||||||||||||||
1328 | && ((hVelocity > 0) == (hData.continuousFlickVelocity > 0))
| 0 | ||||||||||||||||||||||||
1329 | && qAbs(hVelocity) > QML_FLICK_MULTIFLICK_THRESHOLD) {
| 0 | ||||||||||||||||||||||||
1330 | // accelerate flick for large view flicked quickly | - | ||||||||||||||||||||||||
1331 | canBoost = true; | - | ||||||||||||||||||||||||
1332 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1333 | - | |||||||||||||||||||||||||
1334 | flickBoost = canBoost ? qBound(1.0, flickBoost+0.25, QML_FLICK_MULTIFLICK_MAXBOOST) : 1.0;
| 0-760 | ||||||||||||||||||||||||
1335 | - | |||||||||||||||||||||||||
1336 | bool flickedVertically = false; | - | ||||||||||||||||||||||||
1337 | vVelocity *= flickBoost; | - | ||||||||||||||||||||||||
1338 | bool isVerticalFlickAllowed = q->yflick() && qAbs(vVelocity) > MinimumFlickVelocity && qAbs(event->localPos().y() - pressPos.y()) > FlickThreshold;
| 0-472 | ||||||||||||||||||||||||
1339 | if (isVerticalFlickAllowed) {
| 336-424 | ||||||||||||||||||||||||
1340 | velocityTimeline.reset(vData.smoothVelocity); | - | ||||||||||||||||||||||||
1341 | vData.smoothVelocity.setValue(-vVelocity); | - | ||||||||||||||||||||||||
1342 | flickedVertically = flickY(vVelocity); | - | ||||||||||||||||||||||||
1343 | } executed 336 times by 5 tests: end of block Executed by:
| 336 | ||||||||||||||||||||||||
1344 | - | |||||||||||||||||||||||||
1345 | bool flickedHorizontally = false; | - | ||||||||||||||||||||||||
1346 | hVelocity *= flickBoost; | - | ||||||||||||||||||||||||
1347 | bool isHorizontalFlickAllowed = q->xflick() && qAbs(hVelocity) > MinimumFlickVelocity && qAbs(event->localPos().x() - pressPos.x()) > FlickThreshold;
| 32-434 | ||||||||||||||||||||||||
1348 | if (isHorizontalFlickAllowed) {
| 354-406 | ||||||||||||||||||||||||
1349 | velocityTimeline.reset(hData.smoothVelocity); | - | ||||||||||||||||||||||||
1350 | hData.smoothVelocity.setValue(-hVelocity); | - | ||||||||||||||||||||||||
1351 | flickedHorizontally = flickX(hVelocity); | - | ||||||||||||||||||||||||
1352 | } executed 354 times by 6 tests: end of block Executed by:
| 354 | ||||||||||||||||||||||||
1353 | - | |||||||||||||||||||||||||
1354 | if (!isVerticalFlickAllowed)
| 336-424 | ||||||||||||||||||||||||
1355 | fixupY(); executed 424 times by 6 tests: fixupY(); Executed by:
| 424 | ||||||||||||||||||||||||
1356 | - | |||||||||||||||||||||||||
1357 | if (!isHorizontalFlickAllowed)
| 354-406 | ||||||||||||||||||||||||
1358 | fixupX(); executed 406 times by 6 tests: fixupX(); Executed by:
| 406 | ||||||||||||||||||||||||
1359 | - | |||||||||||||||||||||||||
1360 | flickingStarted(flickedHorizontally, flickedVertically); | - | ||||||||||||||||||||||||
1361 | if (!isViewMoving())
| 60-700 | ||||||||||||||||||||||||
1362 | q->movementEnding(); executed 60 times by 3 tests: q->movementEnding(); Executed by:
| 60 | ||||||||||||||||||||||||
1363 | } executed 760 times by 7 tests: end of block Executed by:
| 760 | ||||||||||||||||||||||||
1364 | - | |||||||||||||||||||||||||
1365 | void QQuickFlickable::mousePressEvent(QMouseEvent *event) | - | ||||||||||||||||||||||||
1366 | { | - | ||||||||||||||||||||||||
1367 | Q_D(QQuickFlickable); | - | ||||||||||||||||||||||||
1368 | if (d->interactive) {
| 8-667 | ||||||||||||||||||||||||
1369 | if (!d->pressed)
| 310-357 | ||||||||||||||||||||||||
1370 | d->handleMousePressEvent(event); executed 357 times by 4 tests: d->handleMousePressEvent(event); Executed by:
| 357 | ||||||||||||||||||||||||
1371 | event->accept(); | - | ||||||||||||||||||||||||
1372 | } else { executed 667 times by 5 tests: end of block Executed by:
| 667 | ||||||||||||||||||||||||
1373 | QQuickItem::mousePressEvent(event); | - | ||||||||||||||||||||||||
1374 | } executed 8 times by 2 tests: end of block Executed by:
| 8 | ||||||||||||||||||||||||
1375 | } | - | ||||||||||||||||||||||||
1376 | - | |||||||||||||||||||||||||
1377 | void QQuickFlickable::mouseMoveEvent(QMouseEvent *event) | - | ||||||||||||||||||||||||
1378 | { | - | ||||||||||||||||||||||||
1379 | Q_D(QQuickFlickable); | - | ||||||||||||||||||||||||
1380 | if (d->interactive) {
| 0-4070 | ||||||||||||||||||||||||
1381 | d->handleMouseMoveEvent(event); | - | ||||||||||||||||||||||||
1382 | event->accept(); | - | ||||||||||||||||||||||||
1383 | } else { executed 4070 times by 6 tests: end of block Executed by:
| 4070 | ||||||||||||||||||||||||
1384 | QQuickItem::mouseMoveEvent(event); | - | ||||||||||||||||||||||||
1385 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1386 | } | - | ||||||||||||||||||||||||
1387 | - | |||||||||||||||||||||||||
1388 | void QQuickFlickable::mouseReleaseEvent(QMouseEvent *event) | - | ||||||||||||||||||||||||
1389 | { | - | ||||||||||||||||||||||||
1390 | Q_D(QQuickFlickable); | - | ||||||||||||||||||||||||
1391 | if (d->interactive) {
| 0-724 | ||||||||||||||||||||||||
1392 | if (d->delayedPressEvent) {
| 0-724 | ||||||||||||||||||||||||
1393 | d->replayDelayedPress(); | - | ||||||||||||||||||||||||
1394 | - | |||||||||||||||||||||||||
1395 | // Now send the release | - | ||||||||||||||||||||||||
1396 | if (window() && window()->mouseGrabberItem()) {
| 0 | ||||||||||||||||||||||||
1397 | QPointF localPos = window()->mouseGrabberItem()->mapFromScene(event->windowPos()); | - | ||||||||||||||||||||||||
1398 | QScopedPointer<QMouseEvent> mouseEvent(QQuickWindowPrivate::cloneMouseEvent(event, &localPos)); | - | ||||||||||||||||||||||||
1399 | QCoreApplication::sendEvent(window(), mouseEvent.data()); | - | ||||||||||||||||||||||||
1400 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1401 | - | |||||||||||||||||||||||||
1402 | // And the event has been consumed | - | ||||||||||||||||||||||||
1403 | d->stealMouse = false; | - | ||||||||||||||||||||||||
1404 | d->pressed = false; | - | ||||||||||||||||||||||||
1405 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1406 | } | - | ||||||||||||||||||||||||
1407 | - | |||||||||||||||||||||||||
1408 | d->handleMouseReleaseEvent(event); | - | ||||||||||||||||||||||||
1409 | event->accept(); | - | ||||||||||||||||||||||||
1410 | } else { executed 724 times by 7 tests: end of block Executed by:
| 724 | ||||||||||||||||||||||||
1411 | QQuickItem::mouseReleaseEvent(event); | - | ||||||||||||||||||||||||
1412 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1413 | } | - | ||||||||||||||||||||||||
1414 | - | |||||||||||||||||||||||||
1415 | #if QT_CONFIG(wheelevent) | - | ||||||||||||||||||||||||
1416 | void QQuickFlickable::wheelEvent(QWheelEvent *event) | - | ||||||||||||||||||||||||
1417 | { | - | ||||||||||||||||||||||||
1418 | Q_D(QQuickFlickable); | - | ||||||||||||||||||||||||
1419 | if (!d->interactive) {
| 0 | ||||||||||||||||||||||||
1420 | QQuickItem::wheelEvent(event); | - | ||||||||||||||||||||||||
1421 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1422 | } | - | ||||||||||||||||||||||||
1423 | event->setAccepted(false); | - | ||||||||||||||||||||||||
1424 | qint64 currentTimestamp = d->computeCurrentTime(event); | - | ||||||||||||||||||||||||
1425 | switch (event->phase()) { | - | ||||||||||||||||||||||||
1426 | case Qt::ScrollBegin: never executed: case Qt::ScrollBegin: | 0 | ||||||||||||||||||||||||
1427 | d->scrollingPhase = true; | - | ||||||||||||||||||||||||
1428 | d->accumulatedWheelPixelDelta = QVector2D(); | - | ||||||||||||||||||||||||
1429 | d->vData.velocity = 0; | - | ||||||||||||||||||||||||
1430 | d->hData.velocity = 0; | - | ||||||||||||||||||||||||
1431 | d->timer.start(); | - | ||||||||||||||||||||||||
1432 | d->maybeBeginDrag(currentTimestamp, event->posF()); | - | ||||||||||||||||||||||||
1433 | break; never executed: break; | 0 | ||||||||||||||||||||||||
1434 | case Qt::NoScrollPhase: // default phase with an ordinary wheel mouse never executed: case Qt::NoScrollPhase: | 0 | ||||||||||||||||||||||||
1435 | case Qt::ScrollUpdate: never executed: case Qt::ScrollUpdate: | 0 | ||||||||||||||||||||||||
1436 | if (d->scrollingPhase)
| 0 | ||||||||||||||||||||||||
1437 | d->pressed = true; never executed: d->pressed = true; | 0 | ||||||||||||||||||||||||
1438 | #ifdef Q_OS_MACOS | - | ||||||||||||||||||||||||
1439 | // TODO eliminate this timer when ScrollMomentum has been added | - | ||||||||||||||||||||||||
1440 | d->movementEndingTimer.start(MovementEndingTimerInterval, this); | - | ||||||||||||||||||||||||
1441 | #endif | - | ||||||||||||||||||||||||
1442 | break; never executed: break; | 0 | ||||||||||||||||||||||||
1443 | case Qt::ScrollEnd: never executed: case Qt::ScrollEnd: | 0 | ||||||||||||||||||||||||
1444 | // TODO most of this should be done at transition to ScrollMomentum phase, | - | ||||||||||||||||||||||||
1445 | // then do what the movementEndingTimer triggers at transition to ScrollEnd phase | - | ||||||||||||||||||||||||
1446 | d->pressed = false; | - | ||||||||||||||||||||||||
1447 | d->scrollingPhase = false; | - | ||||||||||||||||||||||||
1448 | d->draggingEnding(); | - | ||||||||||||||||||||||||
1449 | event->accept(); | - | ||||||||||||||||||||||||
1450 | returnToBounds(); | - | ||||||||||||||||||||||||
1451 | d->lastPosTime = -1; | - | ||||||||||||||||||||||||
1452 | #ifdef Q_OS_MACOS | - | ||||||||||||||||||||||||
1453 | d->movementEndingTimer.start(MovementEndingTimerInterval, this); | - | ||||||||||||||||||||||||
1454 | #endif | - | ||||||||||||||||||||||||
1455 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1456 | } | - | ||||||||||||||||||||||||
1457 | - | |||||||||||||||||||||||||
1458 | if (event->source() == Qt::MouseEventNotSynthesized || event->pixelDelta().isNull()) {
| 0 | ||||||||||||||||||||||||
1459 | // physical mouse wheel, so use angleDelta | - | ||||||||||||||||||||||||
1460 | int xDelta = event->angleDelta().x(); | - | ||||||||||||||||||||||||
1461 | int yDelta = event->angleDelta().y(); | - | ||||||||||||||||||||||||
1462 | if (yflick() && yDelta != 0) {
| 0 | ||||||||||||||||||||||||
1463 | bool valid = false; | - | ||||||||||||||||||||||||
1464 | if (yDelta > 0 && contentY() > -minYExtent()) {
| 0 | ||||||||||||||||||||||||
1465 | d->vData.velocity = qMax(yDelta*2 - d->vData.smoothVelocity.value(), qreal(d->maxVelocity/4)); | - | ||||||||||||||||||||||||
1466 | valid = true; | - | ||||||||||||||||||||||||
1467 | } else if (yDelta < 0 && contentY() < -maxYExtent()) { never executed: end of block
| 0 | ||||||||||||||||||||||||
1468 | d->vData.velocity = qMin(yDelta*2 - d->vData.smoothVelocity.value(), qreal(-d->maxVelocity/4)); | - | ||||||||||||||||||||||||
1469 | valid = true; | - | ||||||||||||||||||||||||
1470 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1471 | if (valid) {
| 0 | ||||||||||||||||||||||||
1472 | d->flickY(d->vData.velocity); | - | ||||||||||||||||||||||||
1473 | d->flickingStarted(false, true); | - | ||||||||||||||||||||||||
1474 | if (d->vData.flicking) {
| 0 | ||||||||||||||||||||||||
1475 | d->vMoved = true; | - | ||||||||||||||||||||||||
1476 | movementStarting(); | - | ||||||||||||||||||||||||
1477 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1478 | event->accept(); | - | ||||||||||||||||||||||||
1479 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1480 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1481 | if (xflick() && xDelta != 0) {
|