Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/util/qscroller.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||
2 | ** | - | ||||||||||||||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||
5 | ** | - | ||||||||||||||||||
6 | ** This file is part of the QtWidgets module of the Qt Toolkit. | - | ||||||||||||||||||
7 | ** | - | ||||||||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||
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 http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
15 | ** information use the contact form at http://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 2.1 or version 3 as published by the Free | - | ||||||||||||||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||
25 | ** | - | ||||||||||||||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||
29 | ** | - | ||||||||||||||||||
30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
31 | ** | - | ||||||||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||||||||
33 | - | |||||||||||||||||||
34 | #include "qevent.h" | - | ||||||||||||||||||
35 | #include "qwidget.h" | - | ||||||||||||||||||
36 | #include "qscroller.h" | - | ||||||||||||||||||
37 | #include "private/qflickgesture_p.h" | - | ||||||||||||||||||
38 | #include "private/qscroller_p.h" | - | ||||||||||||||||||
39 | #include "qscrollerproperties.h" | - | ||||||||||||||||||
40 | #include "private/qscrollerproperties_p.h" | - | ||||||||||||||||||
41 | #include "qnumeric.h" | - | ||||||||||||||||||
42 | #include "math.h" | - | ||||||||||||||||||
43 | - | |||||||||||||||||||
44 | #include <QTime> | - | ||||||||||||||||||
45 | #include <QElapsedTimer> | - | ||||||||||||||||||
46 | #include <QMap> | - | ||||||||||||||||||
47 | #include <QApplication> | - | ||||||||||||||||||
48 | #include <QAbstractScrollArea> | - | ||||||||||||||||||
49 | #include <QGraphicsObject> | - | ||||||||||||||||||
50 | #include <QGraphicsScene> | - | ||||||||||||||||||
51 | #include <QGraphicsView> | - | ||||||||||||||||||
52 | #include <QDesktopWidget> | - | ||||||||||||||||||
53 | #include <QVector2D> | - | ||||||||||||||||||
54 | #include <QtCore/qmath.h> | - | ||||||||||||||||||
55 | #include <QtGui/qevent.h> | - | ||||||||||||||||||
56 | #include <qnumeric.h> | - | ||||||||||||||||||
57 | - | |||||||||||||||||||
58 | #include <QtDebug> | - | ||||||||||||||||||
59 | - | |||||||||||||||||||
60 | - | |||||||||||||||||||
61 | - | |||||||||||||||||||
62 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
63 | - | |||||||||||||||||||
64 | bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event); | - | ||||||||||||||||||
65 | - | |||||||||||||||||||
66 | //#define QSCROLLER_DEBUG | - | ||||||||||||||||||
67 | - | |||||||||||||||||||
68 | #ifdef QSCROLLER_DEBUG | - | ||||||||||||||||||
69 | # define qScrollerDebug qDebug | - | ||||||||||||||||||
70 | #else | - | ||||||||||||||||||
71 | # define qScrollerDebug while (false) qDebug | - | ||||||||||||||||||
72 | #endif | - | ||||||||||||||||||
73 | - | |||||||||||||||||||
74 | QDebug &operator<<(QDebug &dbg, const QScrollerPrivate::ScrollSegment &s) | - | ||||||||||||||||||
75 | { | - | ||||||||||||||||||
76 | dbg << "\n Time: start:" << s.startTime << " duration:" << s.deltaTime << " stop progress:" << s.stopProgress; | - | ||||||||||||||||||
77 | dbg << "\n Pos: start:" << s.startPos << " delta:" << s.deltaPos << " stop:" << s.stopPos; | - | ||||||||||||||||||
78 | dbg << "\n Curve: type:" << s.curve.type() << "\n"; | - | ||||||||||||||||||
79 | return dbg; never executed: return dbg; | 0 | ||||||||||||||||||
80 | } | - | ||||||||||||||||||
81 | - | |||||||||||||||||||
82 | - | |||||||||||||||||||
83 | // a few helper operators to make the code below a lot more readable: | - | ||||||||||||||||||
84 | // otherwise a lot of ifs would have to be multi-line to check both the x | - | ||||||||||||||||||
85 | // and y coordinate separately. | - | ||||||||||||||||||
86 | - | |||||||||||||||||||
87 | // returns true only if the abs. value of BOTH x and y are <= f | - | ||||||||||||||||||
88 | inline bool operator<=(const QPointF &p, qreal f) | - | ||||||||||||||||||
89 | { | - | ||||||||||||||||||
90 | return (qAbs(p.x()) <= f) && (qAbs(p.y()) <= f); never executed: return (qAbs(p.x()) <= f) && (qAbs(p.y()) <= f);
| 0 | ||||||||||||||||||
91 | } | - | ||||||||||||||||||
92 | - | |||||||||||||||||||
93 | // returns true only if the abs. value of BOTH x and y are < f | - | ||||||||||||||||||
94 | inline bool operator<(const QPointF &p, qreal f) | - | ||||||||||||||||||
95 | { | - | ||||||||||||||||||
96 | return (qAbs(p.x()) < f) && (qAbs(p.y()) < f); never executed: return (qAbs(p.x()) < f) && (qAbs(p.y()) < f);
| 0 | ||||||||||||||||||
97 | } | - | ||||||||||||||||||
98 | - | |||||||||||||||||||
99 | // returns true if the abs. value of EITHER x or y are >= f | - | ||||||||||||||||||
100 | inline bool operator>=(const QPointF &p, qreal f) | - | ||||||||||||||||||
101 | { | - | ||||||||||||||||||
102 | return (qAbs(p.x()) >= f) || (qAbs(p.y()) >= f); never executed: return (qAbs(p.x()) >= f) || (qAbs(p.y()) >= f);
| 0 | ||||||||||||||||||
103 | } | - | ||||||||||||||||||
104 | - | |||||||||||||||||||
105 | // returns true if the abs. value of EITHER x or y are > f | - | ||||||||||||||||||
106 | inline bool operator>(const QPointF &p, qreal f) | - | ||||||||||||||||||
107 | { | - | ||||||||||||||||||
108 | return (qAbs(p.x()) > f) || (qAbs(p.y()) > f); never executed: return (qAbs(p.x()) > f) || (qAbs(p.y()) > f);
| 0 | ||||||||||||||||||
109 | } | - | ||||||||||||||||||
110 | - | |||||||||||||||||||
111 | // returns a new point with both coordinates having the abs. value of the original one | - | ||||||||||||||||||
112 | inline QPointF qAbs(const QPointF &p) | - | ||||||||||||||||||
113 | { | - | ||||||||||||||||||
114 | return QPointF(qAbs(p.x()), qAbs(p.y())); never executed: return QPointF(qAbs(p.x()), qAbs(p.y())); | 0 | ||||||||||||||||||
115 | } | - | ||||||||||||||||||
116 | - | |||||||||||||||||||
117 | // returns a new point with all components of p1 multiplied by the corresponding components of p2 | - | ||||||||||||||||||
118 | inline QPointF operator*(const QPointF &p1, const QPointF &p2) | - | ||||||||||||||||||
119 | { | - | ||||||||||||||||||
120 | return QPointF(p1.x() * p2.x(), p1.y() * p2.y()); never executed: return QPointF(p1.x() * p2.x(), p1.y() * p2.y()); | 0 | ||||||||||||||||||
121 | } | - | ||||||||||||||||||
122 | - | |||||||||||||||||||
123 | // returns a new point with all components of p1 divided by the corresponding components of p2 | - | ||||||||||||||||||
124 | inline QPointF operator/(const QPointF &p1, const QPointF &p2) | - | ||||||||||||||||||
125 | { | - | ||||||||||||||||||
126 | return QPointF(p1.x() / p2.x(), p1.y() / p2.y()); never executed: return QPointF(p1.x() / p2.x(), p1.y() / p2.y()); | 0 | ||||||||||||||||||
127 | } | - | ||||||||||||||||||
128 | - | |||||||||||||||||||
129 | inline QPointF clampToRect(const QPointF &p, const QRectF &rect) | - | ||||||||||||||||||
130 | { | - | ||||||||||||||||||
131 | qreal x = qBound(rect.left(), p.x(), rect.right()); | - | ||||||||||||||||||
132 | qreal y = qBound(rect.top(), p.y(), rect.bottom()); | - | ||||||||||||||||||
133 | return QPointF(x, y); never executed: return QPointF(x, y); | 0 | ||||||||||||||||||
134 | } | - | ||||||||||||||||||
135 | - | |||||||||||||||||||
136 | // returns -1, 0 or +1 according to r being <0, ==0 or >0 | - | ||||||||||||||||||
137 | inline int qSign(qreal r) | - | ||||||||||||||||||
138 | { | - | ||||||||||||||||||
139 | return (r < 0) ? -1 : ((r > 0) ? 1 : 0); never executed: return (r < 0) ? -1 : ((r > 0) ? 1 : 0);
| 0 | ||||||||||||||||||
140 | } | - | ||||||||||||||||||
141 | - | |||||||||||||||||||
142 | // this version is not mathematically exact, but it just works for every | - | ||||||||||||||||||
143 | // easing curve type (even custom ones) | - | ||||||||||||||||||
144 | - | |||||||||||||||||||
145 | static qreal differentialForProgress(const QEasingCurve &curve, qreal pos) | - | ||||||||||||||||||
146 | { | - | ||||||||||||||||||
147 | const qreal dx = 0.01; | - | ||||||||||||||||||
148 | qreal left = (pos < qreal(0.5)) ? pos : pos - qreal(dx);
| 0 | ||||||||||||||||||
149 | qreal right = (pos >= qreal(0.5)) ? pos : pos + qreal(dx);
| 0 | ||||||||||||||||||
150 | qreal d = (curve.valueForProgress(right) - curve.valueForProgress(left)) / qreal(dx); | - | ||||||||||||||||||
151 | - | |||||||||||||||||||
152 | //qScrollerDebug() << "differentialForProgress(type: " << curve.type() << ", pos: " << pos << ") = " << d; | - | ||||||||||||||||||
153 | - | |||||||||||||||||||
154 | return d; never executed: return d; | 0 | ||||||||||||||||||
155 | } | - | ||||||||||||||||||
156 | - | |||||||||||||||||||
157 | // this version is not mathematically exact, but it just works for every | - | ||||||||||||||||||
158 | // easing curve type (even custom ones) | - | ||||||||||||||||||
159 | - | |||||||||||||||||||
160 | static qreal progressForValue(const QEasingCurve &curve, qreal value) | - | ||||||||||||||||||
161 | { | - | ||||||||||||||||||
162 | if (curve.type() >= QEasingCurve::InElastic &&
| 0 | ||||||||||||||||||
163 | curve.type() < QEasingCurve::Custom) {
| 0 | ||||||||||||||||||
164 | qWarning("progressForValue(): QEasingCurves of type %d do not have an inverse, since they are not injective.", curve.type()); | - | ||||||||||||||||||
165 | return value; never executed: return value; | 0 | ||||||||||||||||||
166 | } | - | ||||||||||||||||||
167 | if (value < qreal(0) || value > qreal(1))
| 0 | ||||||||||||||||||
168 | return value; never executed: return value; | 0 | ||||||||||||||||||
169 | - | |||||||||||||||||||
170 | qreal progress = value, left(0), right(1); | - | ||||||||||||||||||
171 | for (int iterations = 6; iterations; --iterations) {
| 0 | ||||||||||||||||||
172 | qreal v = curve.valueForProgress(progress); | - | ||||||||||||||||||
173 | if (v < value)
| 0 | ||||||||||||||||||
174 | left = progress; never executed: left = progress; | 0 | ||||||||||||||||||
175 | else if (v > value)
| 0 | ||||||||||||||||||
176 | right = progress; never executed: right = progress; | 0 | ||||||||||||||||||
177 | else | - | ||||||||||||||||||
178 | break; never executed: break; | 0 | ||||||||||||||||||
179 | progress = (left + right) / qreal(2); | - | ||||||||||||||||||
180 | } never executed: end of block | 0 | ||||||||||||||||||
181 | return progress; never executed: return progress; | 0 | ||||||||||||||||||
182 | } | - | ||||||||||||||||||
183 | - | |||||||||||||||||||
184 | - | |||||||||||||||||||
185 | #ifndef QT_NO_ANIMATION | - | ||||||||||||||||||
186 | class QScrollTimer : public QAbstractAnimation | - | ||||||||||||||||||
187 | { | - | ||||||||||||||||||
188 | public: | - | ||||||||||||||||||
189 | QScrollTimer(QScrollerPrivate *_d) | - | ||||||||||||||||||
190 | : QAbstractAnimation(_d), d(_d), ignoreUpdate(false), skip(0) | - | ||||||||||||||||||
191 | { } never executed: end of block | 0 | ||||||||||||||||||
192 | - | |||||||||||||||||||
193 | int duration() const Q_DECL_OVERRIDE | - | ||||||||||||||||||
194 | { | - | ||||||||||||||||||
195 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
196 | } | - | ||||||||||||||||||
197 | - | |||||||||||||||||||
198 | void start() | - | ||||||||||||||||||
199 | { | - | ||||||||||||||||||
200 | // QAbstractAnimation::start() will immediately call | - | ||||||||||||||||||
201 | // updateCurrentTime(), but our state is not set correctly yet | - | ||||||||||||||||||
202 | ignoreUpdate = true; | - | ||||||||||||||||||
203 | QAbstractAnimation::start(); | - | ||||||||||||||||||
204 | ignoreUpdate = false; | - | ||||||||||||||||||
205 | skip = 0; | - | ||||||||||||||||||
206 | } never executed: end of block | 0 | ||||||||||||||||||
207 | - | |||||||||||||||||||
208 | protected: | - | ||||||||||||||||||
209 | void updateCurrentTime(int /*currentTime*/) Q_DECL_OVERRIDE | - | ||||||||||||||||||
210 | { | - | ||||||||||||||||||
211 | if (!ignoreUpdate) {
| 0 | ||||||||||||||||||
212 | if (++skip >= d->frameRateSkip()) {
| 0 | ||||||||||||||||||
213 | skip = 0; | - | ||||||||||||||||||
214 | d->timerTick(); | - | ||||||||||||||||||
215 | } never executed: end of block | 0 | ||||||||||||||||||
216 | } never executed: end of block | 0 | ||||||||||||||||||
217 | } never executed: end of block | 0 | ||||||||||||||||||
218 | - | |||||||||||||||||||
219 | private: | - | ||||||||||||||||||
220 | QScrollerPrivate *d; | - | ||||||||||||||||||
221 | bool ignoreUpdate; | - | ||||||||||||||||||
222 | int skip; | - | ||||||||||||||||||
223 | }; | - | ||||||||||||||||||
224 | #endif // QT_NO_ANIMATION | - | ||||||||||||||||||
225 | - | |||||||||||||||||||
226 | /*! | - | ||||||||||||||||||
227 | \class QScroller | - | ||||||||||||||||||
228 | \brief The QScroller class enables kinetic scrolling for any scrolling widget or graphics item. | - | ||||||||||||||||||
229 | \since 5.0 | - | ||||||||||||||||||
230 | - | |||||||||||||||||||
231 | \inmodule QtWidgets | - | ||||||||||||||||||
232 | - | |||||||||||||||||||
233 | With kinetic scrolling, the user can push the widget in a given | - | ||||||||||||||||||
234 | direction and it will continue to scroll in this direction until it is | - | ||||||||||||||||||
235 | stopped either by the user or by friction. Aspects of inertia, friction | - | ||||||||||||||||||
236 | and other physical concepts can be changed in order to fine-tune an | - | ||||||||||||||||||
237 | intuitive user experience. | - | ||||||||||||||||||
238 | - | |||||||||||||||||||
239 | The QScroller object is the object that stores the current position and | - | ||||||||||||||||||
240 | scrolling speed and takes care of updates. | - | ||||||||||||||||||
241 | QScroller can be triggered by a flick gesture | - | ||||||||||||||||||
242 | - | |||||||||||||||||||
243 | \code | - | ||||||||||||||||||
244 | QWidget *w = ...; | - | ||||||||||||||||||
245 | QScroller::grabGesture(w, QScroller::LeftMouseButtonGesture); | - | ||||||||||||||||||
246 | \endcode | - | ||||||||||||||||||
247 | - | |||||||||||||||||||
248 | or directly like this: | - | ||||||||||||||||||
249 | - | |||||||||||||||||||
250 | \code | - | ||||||||||||||||||
251 | QWidget *w = ...; | - | ||||||||||||||||||
252 | QScroller *scroller = QScroller::scroller(w); | - | ||||||||||||||||||
253 | scroller->scrollTo(QPointF(100, 100)); | - | ||||||||||||||||||
254 | \endcode | - | ||||||||||||||||||
255 | - | |||||||||||||||||||
256 | The scrolled QObjects receive a QScrollPrepareEvent whenever the scroller needs to | - | ||||||||||||||||||
257 | update its geometry information and a QScrollEvent whenever the content of the object should | - | ||||||||||||||||||
258 | actually be scrolled. | - | ||||||||||||||||||
259 | - | |||||||||||||||||||
260 | The scroller uses the global QAbstractAnimation timer to generate its QScrollEvents. This | - | ||||||||||||||||||
261 | can be changed with QScrollerProperties::FrameRate on a per-QScroller basis. | - | ||||||||||||||||||
262 | - | |||||||||||||||||||
263 | Several examples in the \c scroller examples directory show how QScroller, | - | ||||||||||||||||||
264 | QScrollEvent and the scroller gesture can be used. | - | ||||||||||||||||||
265 | - | |||||||||||||||||||
266 | Even though this kinetic scroller has a large number of settings available via | - | ||||||||||||||||||
267 | QScrollerProperties, we recommend that you leave them all at their default, platform optimized | - | ||||||||||||||||||
268 | values. Before changing them you can experiment with the \c plot example in | - | ||||||||||||||||||
269 | the \c scroller examples directory. | - | ||||||||||||||||||
270 | - | |||||||||||||||||||
271 | \sa QScrollEvent, QScrollPrepareEvent, QScrollerProperties | - | ||||||||||||||||||
272 | */ | - | ||||||||||||||||||
273 | - | |||||||||||||||||||
274 | typedef QMap<QObject *, QScroller *> ScrollerHash; | - | ||||||||||||||||||
275 | typedef QSet<QScroller *> ScrollerSet; | - | ||||||||||||||||||
276 | - | |||||||||||||||||||
277 | Q_GLOBAL_STATIC(ScrollerHash, qt_allScrollers) never executed: end of block never executed: guard.store(QtGlobalStatic::Destroyed); never executed: return &holder.value;
| 0 | ||||||||||||||||||
278 | Q_GLOBAL_STATIC(ScrollerSet, qt_activeScrollers) never executed: end of block never executed: guard.store(QtGlobalStatic::Destroyed); never executed: return &holder.value;
| 0 | ||||||||||||||||||
279 | - | |||||||||||||||||||
280 | /*! | - | ||||||||||||||||||
281 | Returns \c true if a QScroller object was already created for \a target; \c false otherwise. | - | ||||||||||||||||||
282 | - | |||||||||||||||||||
283 | \sa scroller() | - | ||||||||||||||||||
284 | */ | - | ||||||||||||||||||
285 | bool QScroller::hasScroller(QObject *target) | - | ||||||||||||||||||
286 | { | - | ||||||||||||||||||
287 | return (qt_allScrollers()->value(target)); never executed: return (qt_allScrollers()->value(target)); | 0 | ||||||||||||||||||
288 | } | - | ||||||||||||||||||
289 | - | |||||||||||||||||||
290 | /*! | - | ||||||||||||||||||
291 | Returns the scroller for the given \a target. | - | ||||||||||||||||||
292 | As long as the object exists this function will always return the same QScroller instance. | - | ||||||||||||||||||
293 | If no QScroller exists for the \a target, one will implicitly be created. | - | ||||||||||||||||||
294 | At no point more than one QScroller will be active on an object. | - | ||||||||||||||||||
295 | - | |||||||||||||||||||
296 | \sa hasScroller(), target() | - | ||||||||||||||||||
297 | */ | - | ||||||||||||||||||
298 | QScroller *QScroller::scroller(QObject *target) | - | ||||||||||||||||||
299 | { | - | ||||||||||||||||||
300 | if (!target) {
| 0 | ||||||||||||||||||
301 | qWarning("QScroller::scroller() was called with a null target."); | - | ||||||||||||||||||
302 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
303 | } | - | ||||||||||||||||||
304 | - | |||||||||||||||||||
305 | if (qt_allScrollers()->contains(target))
| 0 | ||||||||||||||||||
306 | return qt_allScrollers()->value(target); never executed: return qt_allScrollers()->value(target); | 0 | ||||||||||||||||||
307 | - | |||||||||||||||||||
308 | QScroller *s = new QScroller(target); | - | ||||||||||||||||||
309 | qt_allScrollers()->insert(target, s); | - | ||||||||||||||||||
310 | return s; never executed: return s; | 0 | ||||||||||||||||||
311 | } | - | ||||||||||||||||||
312 | - | |||||||||||||||||||
313 | /*! | - | ||||||||||||||||||
314 | \overload | - | ||||||||||||||||||
315 | This is the const version of scroller(). | - | ||||||||||||||||||
316 | */ | - | ||||||||||||||||||
317 | const QScroller *QScroller::scroller(const QObject *target) | - | ||||||||||||||||||
318 | { | - | ||||||||||||||||||
319 | return scroller(const_cast<QObject*>(target)); never executed: return scroller(const_cast<QObject*>(target)); | 0 | ||||||||||||||||||
320 | } | - | ||||||||||||||||||
321 | - | |||||||||||||||||||
322 | /*! | - | ||||||||||||||||||
323 | Returns an application wide list of currently active QScroller objects. | - | ||||||||||||||||||
324 | Active QScroller objects are in a state() that is not QScroller::Inactive. | - | ||||||||||||||||||
325 | This function is useful when writing your own gesture recognizer. | - | ||||||||||||||||||
326 | */ | - | ||||||||||||||||||
327 | QList<QScroller *> QScroller::activeScrollers() | - | ||||||||||||||||||
328 | { | - | ||||||||||||||||||
329 | return qt_activeScrollers()->toList(); never executed: return qt_activeScrollers()->toList(); | 0 | ||||||||||||||||||
330 | } | - | ||||||||||||||||||
331 | - | |||||||||||||||||||
332 | /*! | - | ||||||||||||||||||
333 | Returns the target object of this scroller. | - | ||||||||||||||||||
334 | \sa hasScroller(), scroller() | - | ||||||||||||||||||
335 | */ | - | ||||||||||||||||||
336 | QObject *QScroller::target() const | - | ||||||||||||||||||
337 | { | - | ||||||||||||||||||
338 | Q_D(const QScroller); | - | ||||||||||||||||||
339 | return d->target; never executed: return d->target; | 0 | ||||||||||||||||||
340 | } | - | ||||||||||||||||||
341 | - | |||||||||||||||||||
342 | /*! | - | ||||||||||||||||||
343 | \fn QScroller::scrollerPropertiesChanged(const QScrollerProperties &newProperties); | - | ||||||||||||||||||
344 | - | |||||||||||||||||||
345 | QScroller emits this signal whenever its scroller properties change. | - | ||||||||||||||||||
346 | \a newProperties are the new scroller properties. | - | ||||||||||||||||||
347 | - | |||||||||||||||||||
348 | \sa scrollerProperties | - | ||||||||||||||||||
349 | */ | - | ||||||||||||||||||
350 | - | |||||||||||||||||||
351 | - | |||||||||||||||||||
352 | /*! \property QScroller::scrollerProperties | - | ||||||||||||||||||
353 | \brief The scroller properties of this scroller. | - | ||||||||||||||||||
354 | The properties are used by the QScroller to determine its scrolling behavior. | - | ||||||||||||||||||
355 | */ | - | ||||||||||||||||||
356 | QScrollerProperties QScroller::scrollerProperties() const | - | ||||||||||||||||||
357 | { | - | ||||||||||||||||||
358 | Q_D(const QScroller); | - | ||||||||||||||||||
359 | return d->properties; never executed: return d->properties; | 0 | ||||||||||||||||||
360 | } | - | ||||||||||||||||||
361 | - | |||||||||||||||||||
362 | void QScroller::setScrollerProperties(const QScrollerProperties &sp) | - | ||||||||||||||||||
363 | { | - | ||||||||||||||||||
364 | Q_D(QScroller); | - | ||||||||||||||||||
365 | if (d->properties != sp) {
| 0 | ||||||||||||||||||
366 | d->properties = sp; | - | ||||||||||||||||||
367 | emit scrollerPropertiesChanged(sp); | - | ||||||||||||||||||
368 | - | |||||||||||||||||||
369 | // we need to force the recalculation here, since the overshootPolicy may have changed and | - | ||||||||||||||||||
370 | // existing segments may include an overshoot animation. | - | ||||||||||||||||||
371 | d->recalcScrollingSegments(true); | - | ||||||||||||||||||
372 | } never executed: end of block | 0 | ||||||||||||||||||
373 | } never executed: end of block | 0 | ||||||||||||||||||
374 | - | |||||||||||||||||||
375 | #ifndef QT_NO_GESTURES | - | ||||||||||||||||||
376 | - | |||||||||||||||||||
377 | /*! | - | ||||||||||||||||||
378 | Registers a custom scroll gesture recognizer, grabs it for the \a | - | ||||||||||||||||||
379 | target and returns the resulting gesture type. If \a scrollGestureType is | - | ||||||||||||||||||
380 | set to TouchGesture the gesture triggers on touch events. If it is set to | - | ||||||||||||||||||
381 | one of LeftMouseButtonGesture, RightMouseButtonGesture or | - | ||||||||||||||||||
382 | MiddleMouseButtonGesture it triggers on mouse events of the | - | ||||||||||||||||||
383 | corresponding button. | - | ||||||||||||||||||
384 | - | |||||||||||||||||||
385 | Only one scroll gesture can be active on a single object at the same | - | ||||||||||||||||||
386 | time. If you call this function twice on the same object, it will | - | ||||||||||||||||||
387 | ungrab the existing gesture before grabbing the new one. | - | ||||||||||||||||||
388 | - | |||||||||||||||||||
389 | \note To avoid unwanted side-effects, mouse events are consumed while | - | ||||||||||||||||||
390 | the gesture is triggered. Since the initial mouse press event is | - | ||||||||||||||||||
391 | not consumed, the gesture sends a fake mouse release event | - | ||||||||||||||||||
392 | at the global position \c{(INT_MIN, INT_MIN)}. This ensures that | - | ||||||||||||||||||
393 | internal states of the widget that received the original mouse press | - | ||||||||||||||||||
394 | are consistent. | - | ||||||||||||||||||
395 | - | |||||||||||||||||||
396 | \sa ungrabGesture(), grabbedGesture() | - | ||||||||||||||||||
397 | */ | - | ||||||||||||||||||
398 | Qt::GestureType QScroller::grabGesture(QObject *target, ScrollerGestureType scrollGestureType) | - | ||||||||||||||||||
399 | { | - | ||||||||||||||||||
400 | // ensure that a scroller for target is created | - | ||||||||||||||||||
401 | QScroller *s = scroller(target); | - | ||||||||||||||||||
402 | if (!s)
| 0 | ||||||||||||||||||
403 | return Qt::GestureType(0); never executed: return Qt::GestureType(0); | 0 | ||||||||||||||||||
404 | - | |||||||||||||||||||
405 | QScrollerPrivate *sp = s->d_ptr; | - | ||||||||||||||||||
406 | if (sp->recognizer)
| 0 | ||||||||||||||||||
407 | ungrabGesture(target); // ungrab the old gesture never executed: ungrabGesture(target); | 0 | ||||||||||||||||||
408 | - | |||||||||||||||||||
409 | Qt::MouseButton button; | - | ||||||||||||||||||
410 | switch (scrollGestureType) { | - | ||||||||||||||||||
411 | case LeftMouseButtonGesture : button = Qt::LeftButton; break; never executed: break; never executed: case LeftMouseButtonGesture : | 0 | ||||||||||||||||||
412 | case RightMouseButtonGesture : button = Qt::RightButton; break; never executed: break; never executed: case RightMouseButtonGesture : | 0 | ||||||||||||||||||
413 | case MiddleMouseButtonGesture: button = Qt::MiddleButton; break; never executed: break; never executed: case MiddleMouseButtonGesture: | 0 | ||||||||||||||||||
414 | default : never executed: default : | 0 | ||||||||||||||||||
415 | case TouchGesture : button = Qt::NoButton; break; // NoButton == Touch never executed: break; never executed: case TouchGesture : | 0 | ||||||||||||||||||
416 | } | - | ||||||||||||||||||
417 | - | |||||||||||||||||||
418 | sp->recognizer = new QFlickGestureRecognizer(button); | - | ||||||||||||||||||
419 | sp->recognizerType = QGestureRecognizer::registerRecognizer(sp->recognizer); | - | ||||||||||||||||||
420 | - | |||||||||||||||||||
421 | if (target->isWidgetType()) {
| 0 | ||||||||||||||||||
422 | QWidget *widget = static_cast<QWidget *>(target); | - | ||||||||||||||||||
423 | widget->grabGesture(sp->recognizerType); | - | ||||||||||||||||||
424 | if (scrollGestureType == TouchGesture)
| 0 | ||||||||||||||||||
425 | widget->setAttribute(Qt::WA_AcceptTouchEvents); never executed: widget->setAttribute(Qt::WA_AcceptTouchEvents); | 0 | ||||||||||||||||||
426 | #ifndef QT_NO_GRAPHICSVIEW | - | ||||||||||||||||||
427 | } else if (QGraphicsObject *go = qobject_cast<QGraphicsObject*>(target)) { never executed: end of block
| 0 | ||||||||||||||||||
428 | if (scrollGestureType == TouchGesture)
| 0 | ||||||||||||||||||
429 | go->setAcceptTouchEvents(true); never executed: go->setAcceptTouchEvents(true); | 0 | ||||||||||||||||||
430 | go->grabGesture(sp->recognizerType); | - | ||||||||||||||||||
431 | #endif // QT_NO_GRAPHICSVIEW | - | ||||||||||||||||||
432 | } never executed: end of block | 0 | ||||||||||||||||||
433 | return sp->recognizerType; never executed: return sp->recognizerType; | 0 | ||||||||||||||||||
434 | } | - | ||||||||||||||||||
435 | - | |||||||||||||||||||
436 | /*! | - | ||||||||||||||||||
437 | Returns the gesture type currently grabbed for the \a target or 0 if no | - | ||||||||||||||||||
438 | gesture is grabbed. | - | ||||||||||||||||||
439 | - | |||||||||||||||||||
440 | \sa grabGesture(), ungrabGesture() | - | ||||||||||||||||||
441 | */ | - | ||||||||||||||||||
442 | Qt::GestureType QScroller::grabbedGesture(QObject *target) | - | ||||||||||||||||||
443 | { | - | ||||||||||||||||||
444 | QScroller *s = scroller(target); | - | ||||||||||||||||||
445 | if (s && s->d_ptr)
| 0 | ||||||||||||||||||
446 | return s->d_ptr->recognizerType; never executed: return s->d_ptr->recognizerType; | 0 | ||||||||||||||||||
447 | else | - | ||||||||||||||||||
448 | return Qt::GestureType(0); never executed: return Qt::GestureType(0); | 0 | ||||||||||||||||||
449 | } | - | ||||||||||||||||||
450 | - | |||||||||||||||||||
451 | /*! | - | ||||||||||||||||||
452 | Ungrabs the gesture for the \a target. | - | ||||||||||||||||||
453 | Does nothing if no gesture is grabbed. | - | ||||||||||||||||||
454 | - | |||||||||||||||||||
455 | \sa grabGesture(), grabbedGesture() | - | ||||||||||||||||||
456 | */ | - | ||||||||||||||||||
457 | void QScroller::ungrabGesture(QObject *target) | - | ||||||||||||||||||
458 | { | - | ||||||||||||||||||
459 | QScroller *s = scroller(target); | - | ||||||||||||||||||
460 | if (!s)
| 0 | ||||||||||||||||||
461 | return; never executed: return; | 0 | ||||||||||||||||||
462 | - | |||||||||||||||||||
463 | QScrollerPrivate *sp = s->d_ptr; | - | ||||||||||||||||||
464 | if (!sp->recognizer)
| 0 | ||||||||||||||||||
465 | return; // nothing to do never executed: return; | 0 | ||||||||||||||||||
466 | - | |||||||||||||||||||
467 | if (target->isWidgetType()) {
| 0 | ||||||||||||||||||
468 | QWidget *widget = static_cast<QWidget *>(target); | - | ||||||||||||||||||
469 | widget->ungrabGesture(sp->recognizerType); | - | ||||||||||||||||||
470 | #ifndef QT_NO_GRAPHICSVIEW | - | ||||||||||||||||||
471 | } else if (QGraphicsObject *go = qobject_cast<QGraphicsObject*>(target)) { never executed: end of block
| 0 | ||||||||||||||||||
472 | go->ungrabGesture(sp->recognizerType); | - | ||||||||||||||||||
473 | #endif | - | ||||||||||||||||||
474 | } never executed: end of block | 0 | ||||||||||||||||||
475 | - | |||||||||||||||||||
476 | QGestureRecognizer::unregisterRecognizer(sp->recognizerType); | - | ||||||||||||||||||
477 | // do not delete the recognizer. The QGestureManager is doing this. | - | ||||||||||||||||||
478 | sp->recognizer = 0; | - | ||||||||||||||||||
479 | } never executed: end of block | 0 | ||||||||||||||||||
480 | - | |||||||||||||||||||
481 | #endif // QT_NO_GESTURES | - | ||||||||||||||||||
482 | - | |||||||||||||||||||
483 | /*! | - | ||||||||||||||||||
484 | \internal | - | ||||||||||||||||||
485 | */ | - | ||||||||||||||||||
486 | QScroller::QScroller(QObject *target) | - | ||||||||||||||||||
487 | : d_ptr(new QScrollerPrivate(this, target)) | - | ||||||||||||||||||
488 | { | - | ||||||||||||||||||
489 | Q_ASSERT(target); // you can't create a scroller without a target in any normal way | - | ||||||||||||||||||
490 | Q_D(QScroller); | - | ||||||||||||||||||
491 | d->init(); | - | ||||||||||||||||||
492 | } never executed: end of block | 0 | ||||||||||||||||||
493 | - | |||||||||||||||||||
494 | /*! | - | ||||||||||||||||||
495 | \internal | - | ||||||||||||||||||
496 | */ | - | ||||||||||||||||||
497 | QScroller::~QScroller() | - | ||||||||||||||||||
498 | { | - | ||||||||||||||||||
499 | Q_D(QScroller); | - | ||||||||||||||||||
500 | #ifndef QT_NO_GESTURES | - | ||||||||||||||||||
501 | QGestureRecognizer::unregisterRecognizer(d->recognizerType); | - | ||||||||||||||||||
502 | // do not delete the recognizer. The QGestureManager is doing this. | - | ||||||||||||||||||
503 | d->recognizer = 0; | - | ||||||||||||||||||
504 | #endif | - | ||||||||||||||||||
505 | qt_allScrollers()->remove(d->target); | - | ||||||||||||||||||
506 | qt_activeScrollers()->remove(this); | - | ||||||||||||||||||
507 | - | |||||||||||||||||||
508 | delete d_ptr; | - | ||||||||||||||||||
509 | } never executed: end of block | 0 | ||||||||||||||||||
510 | - | |||||||||||||||||||
511 | - | |||||||||||||||||||
512 | /*! | - | ||||||||||||||||||
513 | \fn QScroller::stateChanged(QScroller::State newState); | - | ||||||||||||||||||
514 | - | |||||||||||||||||||
515 | QScroller emits this signal whenever the state changes. \a newState is the new State. | - | ||||||||||||||||||
516 | - | |||||||||||||||||||
517 | \sa state | - | ||||||||||||||||||
518 | */ | - | ||||||||||||||||||
519 | - | |||||||||||||||||||
520 | /*! | - | ||||||||||||||||||
521 | \property QScroller::state | - | ||||||||||||||||||
522 | \brief the state of the scroller | - | ||||||||||||||||||
523 | - | |||||||||||||||||||
524 | \sa QScroller::State | - | ||||||||||||||||||
525 | */ | - | ||||||||||||||||||
526 | QScroller::State QScroller::state() const | - | ||||||||||||||||||
527 | { | - | ||||||||||||||||||
528 | Q_D(const QScroller); | - | ||||||||||||||||||
529 | return d->state; never executed: return d->state; | 0 | ||||||||||||||||||
530 | } | - | ||||||||||||||||||
531 | - | |||||||||||||||||||
532 | /*! | - | ||||||||||||||||||
533 | Stops the scroller and resets its state back to Inactive. | - | ||||||||||||||||||
534 | */ | - | ||||||||||||||||||
535 | void QScroller::stop() | - | ||||||||||||||||||
536 | { | - | ||||||||||||||||||
537 | Q_D(QScroller); | - | ||||||||||||||||||
538 | if (d->state != Inactive) {
| 0 | ||||||||||||||||||
539 | QPointF here = clampToRect(d->contentPosition, d->contentPosRange); | - | ||||||||||||||||||
540 | qreal snapX = d->nextSnapPos(here.x(), 0, Qt::Horizontal); | - | ||||||||||||||||||
541 | qreal snapY = d->nextSnapPos(here.y(), 0, Qt::Vertical); | - | ||||||||||||||||||
542 | QPointF snap = here; | - | ||||||||||||||||||
543 | if (!qIsNaN(snapX))
| 0 | ||||||||||||||||||
544 | snap.setX(snapX); never executed: snap.setX(snapX); | 0 | ||||||||||||||||||
545 | if (!qIsNaN(snapY))
| 0 | ||||||||||||||||||
546 | snap.setY(snapY); never executed: snap.setY(snapY); | 0 | ||||||||||||||||||
547 | d->contentPosition = snap; | - | ||||||||||||||||||
548 | d->overshootPosition = QPointF(0, 0); | - | ||||||||||||||||||
549 | - | |||||||||||||||||||
550 | d->setState(Inactive); | - | ||||||||||||||||||
551 | } never executed: end of block | 0 | ||||||||||||||||||
552 | } never executed: end of block | 0 | ||||||||||||||||||
553 | - | |||||||||||||||||||
554 | /*! | - | ||||||||||||||||||
555 | Returns the pixel per meter metric for the scrolled widget. | - | ||||||||||||||||||
556 | - | |||||||||||||||||||
557 | The value is reported for both the x and y axis separately by using a QPointF. | - | ||||||||||||||||||
558 | - | |||||||||||||||||||
559 | \note Please note that this value should be physically correct. The actual DPI settings | - | ||||||||||||||||||
560 | that Qt returns for the display may be reported wrongly on purpose by the underlying | - | ||||||||||||||||||
561 | windowing system, for example on \macos. | - | ||||||||||||||||||
562 | */ | - | ||||||||||||||||||
563 | QPointF QScroller::pixelPerMeter() const | - | ||||||||||||||||||
564 | { | - | ||||||||||||||||||
565 | Q_D(const QScroller); | - | ||||||||||||||||||
566 | QPointF ppm = d->pixelPerMeter; | - | ||||||||||||||||||
567 | - | |||||||||||||||||||
568 | #ifndef QT_NO_GRAPHICSVIEW | - | ||||||||||||||||||
569 | if (QGraphicsObject *go = qobject_cast<QGraphicsObject *>(d->target)) {
| 0 | ||||||||||||||||||
570 | QTransform viewtr; | - | ||||||||||||||||||
571 | //TODO: the first view isn't really correct - maybe use an additional field in the prepare event? | - | ||||||||||||||||||
572 | if (go->scene() && !go->scene()->views().isEmpty())
| 0 | ||||||||||||||||||
573 | viewtr = go->scene()->views().first()->viewportTransform(); never executed: viewtr = go->scene()->views().first()->viewportTransform(); | 0 | ||||||||||||||||||
574 | QTransform tr = go->deviceTransform(viewtr); | - | ||||||||||||||||||
575 | if (tr.isScaling()) {
| 0 | ||||||||||||||||||
576 | QPointF p0 = tr.map(QPointF(0, 0)); | - | ||||||||||||||||||
577 | QPointF px = tr.map(QPointF(1, 0)); | - | ||||||||||||||||||
578 | QPointF py = tr.map(QPointF(0, 1)); | - | ||||||||||||||||||
579 | ppm.rx() /= QLineF(p0, px).length(); | - | ||||||||||||||||||
580 | ppm.ry() /= QLineF(p0, py).length(); | - | ||||||||||||||||||
581 | } never executed: end of block | 0 | ||||||||||||||||||
582 | } never executed: end of block | 0 | ||||||||||||||||||
583 | #endif // QT_NO_GRAPHICSVIEW | - | ||||||||||||||||||
584 | return ppm; never executed: return ppm; | 0 | ||||||||||||||||||
585 | } | - | ||||||||||||||||||
586 | - | |||||||||||||||||||
587 | /*! | - | ||||||||||||||||||
588 | Returns the current scrolling velocity in meter per second when the state is Scrolling or Dragging. | - | ||||||||||||||||||
589 | Returns a zero velocity otherwise. | - | ||||||||||||||||||
590 | - | |||||||||||||||||||
591 | The velocity is reported for both the x and y axis separately by using a QPointF. | - | ||||||||||||||||||
592 | - | |||||||||||||||||||
593 | \sa pixelPerMeter() | - | ||||||||||||||||||
594 | */ | - | ||||||||||||||||||
595 | QPointF QScroller::velocity() const | - | ||||||||||||||||||
596 | { | - | ||||||||||||||||||
597 | Q_D(const QScroller); | - | ||||||||||||||||||
598 | const QScrollerPropertiesPrivate *sp = d->properties.d.data(); | - | ||||||||||||||||||
599 | - | |||||||||||||||||||
600 | switch (state()) { | - | ||||||||||||||||||
601 | case Dragging: never executed: case Dragging: | 0 | ||||||||||||||||||
602 | return d->releaseVelocity; never executed: return d->releaseVelocity; | 0 | ||||||||||||||||||
603 | case Scrolling: { never executed: case Scrolling: | 0 | ||||||||||||||||||
604 | QPointF vel; | - | ||||||||||||||||||
605 | qint64 now = d->monotonicTimer.elapsed(); | - | ||||||||||||||||||
606 | - | |||||||||||||||||||
607 | if (!d->xSegments.isEmpty()) {
| 0 | ||||||||||||||||||
608 | const QScrollerPrivate::ScrollSegment &s = d->xSegments.head(); | - | ||||||||||||||||||
609 | qreal progress = qreal(now - s.startTime) / qreal(s.deltaTime); | - | ||||||||||||||||||
610 | qreal v = qSign(s.deltaPos) * qreal(s.deltaTime) / qreal(1000) * sp->decelerationFactor * qreal(0.5) * differentialForProgress(s.curve, progress); | - | ||||||||||||||||||
611 | vel.setX(v); | - | ||||||||||||||||||
612 | } never executed: end of block | 0 | ||||||||||||||||||
613 | - | |||||||||||||||||||
614 | if (!d->ySegments.isEmpty()) {
| 0 | ||||||||||||||||||
615 | const QScrollerPrivate::ScrollSegment &s = d->ySegments.head(); | - | ||||||||||||||||||
616 | qreal progress = qreal(now - s.startTime) / qreal(s.deltaTime); | - | ||||||||||||||||||
617 | qreal v = qSign(s.deltaPos) * qreal(s.deltaTime) / qreal(1000) * sp->decelerationFactor * qreal(0.5) * differentialForProgress(s.curve, progress); | - | ||||||||||||||||||
618 | vel.setY(v); | - | ||||||||||||||||||
619 | } never executed: end of block | 0 | ||||||||||||||||||
620 | return vel; never executed: return vel; | 0 | ||||||||||||||||||
621 | } | - | ||||||||||||||||||
622 | default: never executed: default: | 0 | ||||||||||||||||||
623 | return QPointF(0, 0); never executed: return QPointF(0, 0); | 0 | ||||||||||||||||||
624 | } | - | ||||||||||||||||||
625 | } | - | ||||||||||||||||||
626 | - | |||||||||||||||||||
627 | /*! | - | ||||||||||||||||||
628 | Returns the estimated final position for the current scroll movement. | - | ||||||||||||||||||
629 | Returns the current position if the scroller state is not Scrolling. | - | ||||||||||||||||||
630 | The result is undefined when the scroller state is Inactive. | - | ||||||||||||||||||
631 | - | |||||||||||||||||||
632 | The target position is in pixel. | - | ||||||||||||||||||
633 | - | |||||||||||||||||||
634 | \sa pixelPerMeter(), scrollTo() | - | ||||||||||||||||||
635 | */ | - | ||||||||||||||||||
636 | QPointF QScroller::finalPosition() const | - | ||||||||||||||||||
637 | { | - | ||||||||||||||||||
638 | Q_D(const QScroller); | - | ||||||||||||||||||
639 | return QPointF(d->scrollingSegmentsEndPos(Qt::Horizontal), never executed: return QPointF(d->scrollingSegmentsEndPos(Qt::Horizontal), d->scrollingSegmentsEndPos(Qt::Vertical)); | 0 | ||||||||||||||||||
640 | d->scrollingSegmentsEndPos(Qt::Vertical)); never executed: return QPointF(d->scrollingSegmentsEndPos(Qt::Horizontal), d->scrollingSegmentsEndPos(Qt::Vertical)); | 0 | ||||||||||||||||||
641 | } | - | ||||||||||||||||||
642 | - | |||||||||||||||||||
643 | /*! | - | ||||||||||||||||||
644 | Starts scrolling the widget so that point \a pos is at the top-left position in | - | ||||||||||||||||||
645 | the viewport. | - | ||||||||||||||||||
646 | - | |||||||||||||||||||
647 | The behaviour when scrolling outside the valid scroll area is undefined. | - | ||||||||||||||||||
648 | In this case the scroller might or might not overshoot. | - | ||||||||||||||||||
649 | - | |||||||||||||||||||
650 | The scrolling speed will be calculated so that the given position will | - | ||||||||||||||||||
651 | be reached after a platform-defined time span. | - | ||||||||||||||||||
652 | - | |||||||||||||||||||
653 | \a pos is given in viewport coordinates. | - | ||||||||||||||||||
654 | - | |||||||||||||||||||
655 | \sa ensureVisible() | - | ||||||||||||||||||
656 | */ | - | ||||||||||||||||||
657 | void QScroller::scrollTo(const QPointF &pos) | - | ||||||||||||||||||
658 | { | - | ||||||||||||||||||
659 | // we could make this adjustable via QScrollerProperties | - | ||||||||||||||||||
660 | scrollTo(pos, 300); | - | ||||||||||||||||||
661 | } never executed: end of block | 0 | ||||||||||||||||||
662 | - | |||||||||||||||||||
663 | /*! \overload | - | ||||||||||||||||||
664 | - | |||||||||||||||||||
665 | This version will reach its destination position in \a scrollTime milliseconds. | - | ||||||||||||||||||
666 | */ | - | ||||||||||||||||||
667 | void QScroller::scrollTo(const QPointF &pos, int scrollTime) | - | ||||||||||||||||||
668 | { | - | ||||||||||||||||||
669 | Q_D(QScroller); | - | ||||||||||||||||||
670 | - | |||||||||||||||||||
671 | if (d->state == Pressed || d->state == Dragging )
| 0 | ||||||||||||||||||
672 | return; never executed: return; | 0 | ||||||||||||||||||
673 | - | |||||||||||||||||||
674 | // no need to resend a prepare event if we are already scrolling | - | ||||||||||||||||||
675 | if (d->state == Inactive && !d->prepareScrolling(QPointF()))
| 0 | ||||||||||||||||||
676 | return; never executed: return; | 0 | ||||||||||||||||||
677 | - | |||||||||||||||||||
678 | QPointF newpos = clampToRect(pos, d->contentPosRange); | - | ||||||||||||||||||
679 | qreal snapX = d->nextSnapPos(newpos.x(), 0, Qt::Horizontal); | - | ||||||||||||||||||
680 | qreal snapY = d->nextSnapPos(newpos.y(), 0, Qt::Vertical); | - | ||||||||||||||||||
681 | if (!qIsNaN(snapX))
| 0 | ||||||||||||||||||
682 | newpos.setX(snapX); never executed: newpos.setX(snapX); | 0 | ||||||||||||||||||
683 | if (!qIsNaN(snapY))
| 0 | ||||||||||||||||||
684 | newpos.setY(snapY); never executed: newpos.setY(snapY); | 0 | ||||||||||||||||||
685 | - | |||||||||||||||||||
686 | qScrollerDebug() << "QScroller::scrollTo(req:" << pos << " [pix] / snap:" << newpos << ", " << scrollTime << " [ms])"; dead code: QMessageLogger(__FILE__, 686, __PRETTY_FUNCTION__).debug() << "QScroller::scrollTo(req:" << pos << " [pix] / snap:" << newpos << ", " << scrollTime << " [ms])"; | - | ||||||||||||||||||
687 | - | |||||||||||||||||||
688 | if (newpos == d->contentPosition + d->overshootPosition)
| 0 | ||||||||||||||||||
689 | return; never executed: return; | 0 | ||||||||||||||||||
690 | - | |||||||||||||||||||
691 | QPointF vel = velocity(); | - | ||||||||||||||||||
692 | - | |||||||||||||||||||
693 | if (scrollTime < 0)
| 0 | ||||||||||||||||||
694 | scrollTime = 0; never executed: scrollTime = 0; | 0 | ||||||||||||||||||
695 | qreal time = qreal(scrollTime) / 1000; | - | ||||||||||||||||||
696 | - | |||||||||||||||||||
697 | d->createScrollToSegments(vel.x(), time, newpos.x(), Qt::Horizontal, QScrollerPrivate::ScrollTypeScrollTo); | - | ||||||||||||||||||
698 | d->createScrollToSegments(vel.y(), time, newpos.y(), Qt::Vertical, QScrollerPrivate::ScrollTypeScrollTo); | - | ||||||||||||||||||
699 | - | |||||||||||||||||||
700 | if (!scrollTime)
| 0 | ||||||||||||||||||
701 | d->setContentPositionHelperScrolling(); never executed: d->setContentPositionHelperScrolling(); | 0 | ||||||||||||||||||
702 | d->setState(scrollTime ? Scrolling : Inactive); | - | ||||||||||||||||||
703 | } never executed: end of block | 0 | ||||||||||||||||||
704 | - | |||||||||||||||||||
705 | /*! | - | ||||||||||||||||||
706 | Starts scrolling so that the rectangle \a rect is visible inside the | - | ||||||||||||||||||
707 | viewport with additional margins specified in pixels by \a xmargin and \a ymargin around | - | ||||||||||||||||||
708 | the rect. | - | ||||||||||||||||||
709 | - | |||||||||||||||||||
710 | In cases where it is not possible to fit the rect plus margins inside the viewport the contents | - | ||||||||||||||||||
711 | are scrolled so that as much as possible is visible from \a rect. | - | ||||||||||||||||||
712 | - | |||||||||||||||||||
713 | The scrolling speed is calculated so that the given position is reached after a platform-defined | - | ||||||||||||||||||
714 | time span. | - | ||||||||||||||||||
715 | - | |||||||||||||||||||
716 | This function performs the actual scrolling by calling scrollTo(). | - | ||||||||||||||||||
717 | - | |||||||||||||||||||
718 | \sa scrollTo() | - | ||||||||||||||||||
719 | */ | - | ||||||||||||||||||
720 | void QScroller::ensureVisible(const QRectF &rect, qreal xmargin, qreal ymargin) | - | ||||||||||||||||||
721 | { | - | ||||||||||||||||||
722 | // we could make this adjustable via QScrollerProperties | - | ||||||||||||||||||
723 | ensureVisible(rect, xmargin, ymargin, 1000); | - | ||||||||||||||||||
724 | } never executed: end of block | 0 | ||||||||||||||||||
725 | - | |||||||||||||||||||
726 | /*! \overload | - | ||||||||||||||||||
727 | - | |||||||||||||||||||
728 | This version will reach its destination position in \a scrollTime milliseconds. | - | ||||||||||||||||||
729 | */ | - | ||||||||||||||||||
730 | void QScroller::ensureVisible(const QRectF &rect, qreal xmargin, qreal ymargin, int scrollTime) | - | ||||||||||||||||||
731 | { | - | ||||||||||||||||||
732 | Q_D(QScroller); | - | ||||||||||||||||||
733 | - | |||||||||||||||||||
734 | if (d->state == Pressed || d->state == Dragging )
| 0 | ||||||||||||||||||
735 | return; never executed: return; | 0 | ||||||||||||||||||
736 | - | |||||||||||||||||||
737 | if (d->state == Inactive && !d->prepareScrolling(QPointF()))
| 0 | ||||||||||||||||||
738 | return; never executed: return; | 0 | ||||||||||||||||||
739 | - | |||||||||||||||||||
740 | // -- calculate the current pos (or the position after the current scroll) | - | ||||||||||||||||||
741 | QPointF startPos(d->scrollingSegmentsEndPos(Qt::Horizontal), | - | ||||||||||||||||||
742 | d->scrollingSegmentsEndPos(Qt::Vertical)); | - | ||||||||||||||||||
743 | - | |||||||||||||||||||
744 | QRectF marginRect(rect.x() - xmargin, rect.y() - ymargin, | - | ||||||||||||||||||
745 | rect.width() + 2 * xmargin, rect.height() + 2 * ymargin); | - | ||||||||||||||||||
746 | - | |||||||||||||||||||
747 | QSizeF visible = d->viewportSize; | - | ||||||||||||||||||
748 | QRectF visibleRect(startPos, visible); | - | ||||||||||||||||||
749 | - | |||||||||||||||||||
750 | qScrollerDebug() << "QScroller::ensureVisible(" << rect << " [pix], " << xmargin << " [pix], " << ymargin << " [pix], " << scrollTime << "[ms])"; dead code: QMessageLogger(__FILE__, 750, __PRETTY_FUNCTION__).debug() << "QScroller::ensureVisible(" << rect << " [pix], " << xmargin << " [pix], " << ymargin << " [pix], " << scrollTime << "[ms])"; | - | ||||||||||||||||||
751 | qScrollerDebug() << " --> content position:" << d->contentPosition; dead code: QMessageLogger(__FILE__, 751, __PRETTY_FUNCTION__).debug() << " --> content position:" << d->contentPosition; | - | ||||||||||||||||||
752 | - | |||||||||||||||||||
753 | if (visibleRect.contains(marginRect))
| 0 | ||||||||||||||||||
754 | return; never executed: return; | 0 | ||||||||||||||||||
755 | - | |||||||||||||||||||
756 | QPointF newPos = startPos; | - | ||||||||||||||||||
757 | - | |||||||||||||||||||
758 | if (visibleRect.width() < rect.width()) {
| 0 | ||||||||||||||||||
759 | // at least try to move the rect into view | - | ||||||||||||||||||
760 | if (rect.left() > visibleRect.left())
| 0 | ||||||||||||||||||
761 | newPos.setX(rect.left()); never executed: newPos.setX(rect.left()); | 0 | ||||||||||||||||||
762 | else if (rect.right() < visibleRect.right())
| 0 | ||||||||||||||||||
763 | newPos.setX(rect.right() - visible.width()); never executed: newPos.setX(rect.right() - visible.width()); | 0 | ||||||||||||||||||
764 | - | |||||||||||||||||||
765 | } else if (visibleRect.width() < marginRect.width()) { never executed: end of block
| 0 | ||||||||||||||||||
766 | newPos.setX(rect.center().x() - visibleRect.width() / 2); | - | ||||||||||||||||||
767 | } else if (marginRect.left() > visibleRect.left()) { never executed: end of block
| 0 | ||||||||||||||||||
768 | newPos.setX(marginRect.left()); | - | ||||||||||||||||||
769 | } else if (marginRect.right() < visibleRect.right()) { never executed: end of block
| 0 | ||||||||||||||||||
770 | newPos.setX(marginRect.right() - visible.width()); | - | ||||||||||||||||||
771 | } never executed: end of block | 0 | ||||||||||||||||||
772 | - | |||||||||||||||||||
773 | if (visibleRect.height() < rect.height()) {
| 0 | ||||||||||||||||||
774 | // at least try to move the rect into view | - | ||||||||||||||||||
775 | if (rect.top() > visibleRect.top())
| 0 | ||||||||||||||||||
776 | newPos.setX(rect.top()); never executed: newPos.setX(rect.top()); | 0 | ||||||||||||||||||
777 | else if (rect.bottom() < visibleRect.bottom())
| 0 | ||||||||||||||||||
778 | newPos.setX(rect.bottom() - visible.height()); never executed: newPos.setX(rect.bottom() - visible.height()); | 0 | ||||||||||||||||||
779 | - | |||||||||||||||||||
780 | } else if (visibleRect.height() < marginRect.height()) { never executed: end of block
| 0 | ||||||||||||||||||
781 | newPos.setY(rect.center().y() - visibleRect.height() / 2); | - | ||||||||||||||||||
782 | } else if (marginRect.top() > visibleRect.top()) { never executed: end of block
| 0 | ||||||||||||||||||
783 | newPos.setY(marginRect.top()); | - | ||||||||||||||||||
784 | } else if (marginRect.bottom() < visibleRect.bottom()) { never executed: end of block
| 0 | ||||||||||||||||||
785 | newPos.setY(marginRect.bottom() - visible.height()); | - | ||||||||||||||||||
786 | } never executed: end of block | 0 | ||||||||||||||||||
787 | - | |||||||||||||||||||
788 | // clamp to maximum content position | - | ||||||||||||||||||
789 | newPos = clampToRect(newPos, d->contentPosRange); | - | ||||||||||||||||||
790 | if (newPos == startPos)
| 0 | ||||||||||||||||||
791 | return; never executed: return; | 0 | ||||||||||||||||||
792 | - | |||||||||||||||||||
793 | scrollTo(newPos, scrollTime); | - | ||||||||||||||||||
794 | } never executed: end of block | 0 | ||||||||||||||||||
795 | - | |||||||||||||||||||
796 | /*! This function resends the QScrollPrepareEvent. | - | ||||||||||||||||||
797 | Calling resendPrepareEvent triggers a QScrollPrepareEvent from the scroller. | - | ||||||||||||||||||
798 | This allows the receiver to re-set content position and content size while | - | ||||||||||||||||||
799 | scrolling. | - | ||||||||||||||||||
800 | Calling this function while in the Inactive state is useless as the prepare event | - | ||||||||||||||||||
801 | is sent again before scrolling starts. | - | ||||||||||||||||||
802 | */ | - | ||||||||||||||||||
803 | void QScroller::resendPrepareEvent() | - | ||||||||||||||||||
804 | { | - | ||||||||||||||||||
805 | Q_D(QScroller); | - | ||||||||||||||||||
806 | d->prepareScrolling(d->pressPosition); | - | ||||||||||||||||||
807 | } never executed: end of block | 0 | ||||||||||||||||||
808 | - | |||||||||||||||||||
809 | /*! Set the snap positions for the horizontal axis to a list of \a positions. | - | ||||||||||||||||||
810 | This overwrites all previously set snap positions and also a previously | - | ||||||||||||||||||
811 | set snapping interval. | - | ||||||||||||||||||
812 | Snapping can be deactivated by setting an empty list of positions. | - | ||||||||||||||||||
813 | */ | - | ||||||||||||||||||
814 | void QScroller::setSnapPositionsX(const QList<qreal> &positions) | - | ||||||||||||||||||
815 | { | - | ||||||||||||||||||
816 | Q_D(QScroller); | - | ||||||||||||||||||
817 | d->snapPositionsX = positions; | - | ||||||||||||||||||
818 | d->snapIntervalX = 0.0; | - | ||||||||||||||||||
819 | - | |||||||||||||||||||
820 | d->recalcScrollingSegments(); | - | ||||||||||||||||||
821 | } never executed: end of block | 0 | ||||||||||||||||||
822 | - | |||||||||||||||||||
823 | /*! Set the snap positions for the horizontal axis to regular spaced intervals. | - | ||||||||||||||||||
824 | The first snap position is at \a first. The next at \a first + \a interval. | - | ||||||||||||||||||
825 | This can be used to implement a list header. | - | ||||||||||||||||||
826 | This overwrites all previously set snap positions and also a previously | - | ||||||||||||||||||
827 | set snapping interval. | - | ||||||||||||||||||
828 | Snapping can be deactivated by setting an interval of 0.0 | - | ||||||||||||||||||
829 | */ | - | ||||||||||||||||||
830 | void QScroller::setSnapPositionsX(qreal first, qreal interval) | - | ||||||||||||||||||
831 | { | - | ||||||||||||||||||
832 | Q_D(QScroller); | - | ||||||||||||||||||
833 | d->snapFirstX = first; | - | ||||||||||||||||||
834 | d->snapIntervalX = interval; | - | ||||||||||||||||||
835 | d->snapPositionsX.clear(); | - | ||||||||||||||||||
836 | - | |||||||||||||||||||
837 | d->recalcScrollingSegments(); | - | ||||||||||||||||||
838 | } never executed: end of block | 0 | ||||||||||||||||||
839 | - | |||||||||||||||||||
840 | /*! Set the snap positions for the vertical axis to a list of \a positions. | - | ||||||||||||||||||
841 | This overwrites all previously set snap positions and also a previously | - | ||||||||||||||||||
842 | set snapping interval. | - | ||||||||||||||||||
843 | Snapping can be deactivated by setting an empty list of positions. | - | ||||||||||||||||||
844 | */ | - | ||||||||||||||||||
845 | void QScroller::setSnapPositionsY(const QList<qreal> &positions) | - | ||||||||||||||||||
846 | { | - | ||||||||||||||||||
847 | Q_D(QScroller); | - | ||||||||||||||||||
848 | d->snapPositionsY = positions; | - | ||||||||||||||||||
849 | d->snapIntervalY = 0.0; | - | ||||||||||||||||||
850 | - | |||||||||||||||||||
851 | d->recalcScrollingSegments(); | - | ||||||||||||||||||
852 | } never executed: end of block | 0 | ||||||||||||||||||
853 | - | |||||||||||||||||||
854 | /*! Set the snap positions for the vertical axis to regular spaced intervals. | - | ||||||||||||||||||
855 | The first snap position is at \a first. The next at \a first + \a interval. | - | ||||||||||||||||||
856 | This overwrites all previously set snap positions and also a previously | - | ||||||||||||||||||
857 | set snapping interval. | - | ||||||||||||||||||
858 | Snapping can be deactivated by setting an interval of 0.0 | - | ||||||||||||||||||
859 | */ | - | ||||||||||||||||||
860 | void QScroller::setSnapPositionsY(qreal first, qreal interval) | - | ||||||||||||||||||
861 | { | - | ||||||||||||||||||
862 | Q_D(QScroller); | - | ||||||||||||||||||
863 | d->snapFirstY = first; | - | ||||||||||||||||||
864 | d->snapIntervalY = interval; | - | ||||||||||||||||||
865 | d->snapPositionsY.clear(); | - | ||||||||||||||||||
866 | - | |||||||||||||||||||
867 | d->recalcScrollingSegments(); | - | ||||||||||||||||||
868 | } never executed: end of block | 0 | ||||||||||||||||||
869 | - | |||||||||||||||||||
870 | - | |||||||||||||||||||
871 | - | |||||||||||||||||||
872 | // -------------- private ------------ | - | ||||||||||||||||||
873 | - | |||||||||||||||||||
874 | QScrollerPrivate::QScrollerPrivate(QScroller *q, QObject *_target) | - | ||||||||||||||||||
875 | : target(_target) | - | ||||||||||||||||||
876 | #ifndef QT_NO_GESTURES | - | ||||||||||||||||||
877 | , recognizer(0) | - | ||||||||||||||||||
878 | , recognizerType(Qt::CustomGesture) | - | ||||||||||||||||||
879 | #endif | - | ||||||||||||||||||
880 | , state(QScroller::Inactive) | - | ||||||||||||||||||
881 | , firstScroll(true) | - | ||||||||||||||||||
882 | , pressTimestamp(0) | - | ||||||||||||||||||
883 | , lastTimestamp(0) | - | ||||||||||||||||||
884 | , snapFirstX(-1.0) | - | ||||||||||||||||||
885 | , snapIntervalX(0.0) | - | ||||||||||||||||||
886 | , snapFirstY(-1.0) | - | ||||||||||||||||||
887 | , snapIntervalY(0.0) | - | ||||||||||||||||||
888 | #ifndef QT_NO_ANIMATION | - | ||||||||||||||||||
889 | , scrollTimer(new QScrollTimer(this)) | - | ||||||||||||||||||
890 | #endif | - | ||||||||||||||||||
891 | , q_ptr(q) | - | ||||||||||||||||||
892 | { | - | ||||||||||||||||||
893 | connect(target, SIGNAL(destroyed(QObject*)), this, SLOT(targetDestroyed())); | - | ||||||||||||||||||
894 | } never executed: end of block | 0 | ||||||||||||||||||
895 | - | |||||||||||||||||||
896 | void QScrollerPrivate::init() | - | ||||||||||||||||||
897 | { | - | ||||||||||||||||||
898 | setDpiFromWidget(0); | - | ||||||||||||||||||
899 | monotonicTimer.start(); | - | ||||||||||||||||||
900 | } never executed: end of block | 0 | ||||||||||||||||||
901 | - | |||||||||||||||||||
902 | void QScrollerPrivate::sendEvent(QObject *o, QEvent *e) | - | ||||||||||||||||||
903 | { | - | ||||||||||||||||||
904 | qt_sendSpontaneousEvent(o, e); | - | ||||||||||||||||||
905 | } never executed: end of block | 0 | ||||||||||||||||||
906 | - | |||||||||||||||||||
907 | const char *QScrollerPrivate::stateName(QScroller::State state) | - | ||||||||||||||||||
908 | { | - | ||||||||||||||||||
909 | switch (state) { | - | ||||||||||||||||||
910 | case QScroller::Inactive: return "inactive"; never executed: return "inactive"; never executed: case QScroller::Inactive: | 0 | ||||||||||||||||||
911 | case QScroller::Pressed: return "pressed"; never executed: return "pressed"; never executed: case QScroller::Pressed: | 0 | ||||||||||||||||||
912 | case QScroller::Dragging: return "dragging"; never executed: return "dragging"; never executed: case QScroller::Dragging: | 0 | ||||||||||||||||||
913 | case QScroller::Scrolling: return "scrolling"; never executed: return "scrolling"; never executed: case QScroller::Scrolling: | 0 | ||||||||||||||||||
914 | default: return "(invalid)"; never executed: return "(invalid)"; never executed: default: | 0 | ||||||||||||||||||
915 | } | - | ||||||||||||||||||
916 | } | - | ||||||||||||||||||
917 | - | |||||||||||||||||||
918 | const char *QScrollerPrivate::inputName(QScroller::Input input) | - | ||||||||||||||||||
919 | { | - | ||||||||||||||||||
920 | switch (input) { | - | ||||||||||||||||||
921 | case QScroller::InputPress: return "press"; never executed: return "press"; never executed: case QScroller::InputPress: | 0 | ||||||||||||||||||
922 | case QScroller::InputMove: return "move"; never executed: return "move"; never executed: case QScroller::InputMove: | 0 | ||||||||||||||||||
923 | case QScroller::InputRelease: return "release"; never executed: return "release"; never executed: case QScroller::InputRelease: | 0 | ||||||||||||||||||
924 | default: return "(invalid)"; never executed: return "(invalid)"; never executed: default: | 0 | ||||||||||||||||||
925 | } | - | ||||||||||||||||||
926 | } | - | ||||||||||||||||||
927 | - | |||||||||||||||||||
928 | void QScrollerPrivate::targetDestroyed() | - | ||||||||||||||||||
929 | { | - | ||||||||||||||||||
930 | #ifndef QT_NO_ANIMATION | - | ||||||||||||||||||
931 | scrollTimer->stop(); | - | ||||||||||||||||||
932 | #endif | - | ||||||||||||||||||
933 | delete q_ptr; | - | ||||||||||||||||||
934 | } never executed: end of block | 0 | ||||||||||||||||||
935 | - | |||||||||||||||||||
936 | void QScrollerPrivate::timerTick() | - | ||||||||||||||||||
937 | { | - | ||||||||||||||||||
938 | struct timerevent { | - | ||||||||||||||||||
939 | QScroller::State state; | - | ||||||||||||||||||
940 | typedef void (QScrollerPrivate::*timerhandler_t)(); | - | ||||||||||||||||||
941 | timerhandler_t handler; | - | ||||||||||||||||||
942 | }; | - | ||||||||||||||||||
943 | - | |||||||||||||||||||
944 | timerevent timerevents[] = { | - | ||||||||||||||||||
945 | { QScroller::Dragging, &QScrollerPrivate::timerEventWhileDragging }, | - | ||||||||||||||||||
946 | { QScroller::Scrolling, &QScrollerPrivate::timerEventWhileScrolling }, | - | ||||||||||||||||||
947 | }; | - | ||||||||||||||||||
948 | - | |||||||||||||||||||
949 | for (int i = 0; i < int(sizeof(timerevents) / sizeof(*timerevents)); ++i) {
| 0 | ||||||||||||||||||
950 | timerevent *te = timerevents + i; | - | ||||||||||||||||||
951 | - | |||||||||||||||||||
952 | if (state == te->state) {
| 0 | ||||||||||||||||||
953 | (this->*te->handler)(); | - | ||||||||||||||||||
954 | return; never executed: return; | 0 | ||||||||||||||||||
955 | } | - | ||||||||||||||||||
956 | } never executed: end of block | 0 | ||||||||||||||||||
957 | - | |||||||||||||||||||
958 | #ifndef QT_NO_ANIMATION | - | ||||||||||||||||||
959 | scrollTimer->stop(); | - | ||||||||||||||||||
960 | #endif | - | ||||||||||||||||||
961 | } never executed: end of block | 0 | ||||||||||||||||||
962 | - | |||||||||||||||||||
963 | /*! | - | ||||||||||||||||||
964 | This function is used by gesture recognizers to inform the scroller about a new input event. | - | ||||||||||||||||||
965 | The scroller changes its internal state() according to the input event and its attached | - | ||||||||||||||||||
966 | scroller properties. The scroller doesn't distinguish between the kind of input device the | - | ||||||||||||||||||
967 | event came from. Therefore the event needs to be split into the \a input type, a \a position and a | - | ||||||||||||||||||
968 | milli-second \a timestamp. The \a position needs to be in the target's coordinate system. | - | ||||||||||||||||||
969 | - | |||||||||||||||||||
970 | The return value is \c true if the event should be consumed by the calling filter or \c false | - | ||||||||||||||||||
971 | if the event should be forwarded to the control. | - | ||||||||||||||||||
972 | - | |||||||||||||||||||
973 | \note Using grabGesture() should be sufficient for most use cases. | - | ||||||||||||||||||
974 | */ | - | ||||||||||||||||||
975 | bool QScroller::handleInput(Input input, const QPointF &position, qint64 timestamp) | - | ||||||||||||||||||
976 | { | - | ||||||||||||||||||
977 | Q_D(QScroller); | - | ||||||||||||||||||
978 | - | |||||||||||||||||||
979 | qScrollerDebug() << "QScroller::handleInput(" << input << ", " << d->stateName(d->state) << ", " << position << ", " << timestamp << ')'; dead code: QMessageLogger(__FILE__, 979, __PRETTY_FUNCTION__).debug() << "QScroller::handleInput(" << input << ", " << d->stateName(d->state) << ", " << position << ", " << timestamp << ')'; | - | ||||||||||||||||||
980 | struct statechange { | - | ||||||||||||||||||
981 | State state; | - | ||||||||||||||||||
982 | Input input; | - | ||||||||||||||||||
983 | typedef bool (QScrollerPrivate::*inputhandler_t)(const QPointF &position, qint64 timestamp); | - | ||||||||||||||||||
984 | inputhandler_t handler; | - | ||||||||||||||||||
985 | }; | - | ||||||||||||||||||
986 | - | |||||||||||||||||||
987 | statechange statechanges[] = { | - | ||||||||||||||||||
988 | { QScroller::Inactive, InputPress, &QScrollerPrivate::pressWhileInactive }, | - | ||||||||||||||||||
989 | { QScroller::Pressed, InputMove, &QScrollerPrivate::moveWhilePressed }, | - | ||||||||||||||||||
990 | { QScroller::Pressed, InputRelease, &QScrollerPrivate::releaseWhilePressed }, | - | ||||||||||||||||||
991 | { QScroller::Dragging, InputMove, &QScrollerPrivate::moveWhileDragging }, | - | ||||||||||||||||||
992 | { QScroller::Dragging, InputRelease, &QScrollerPrivate::releaseWhileDragging }, | - | ||||||||||||||||||
993 | { QScroller::Scrolling, InputPress, &QScrollerPrivate::pressWhileScrolling } | - | ||||||||||||||||||
994 | }; | - | ||||||||||||||||||
995 | - | |||||||||||||||||||
996 | for (int i = 0; i < int(sizeof(statechanges) / sizeof(*statechanges)); ++i) {
| 0 | ||||||||||||||||||
997 | statechange *sc = statechanges + i; | - | ||||||||||||||||||
998 | - | |||||||||||||||||||
999 | if (d->state == sc->state && input == sc->input)
| 0 | ||||||||||||||||||
1000 | return (d->*sc->handler)(position - d->overshootPosition, timestamp); never executed: return (d->*sc->handler)(position - d->overshootPosition, timestamp); | 0 | ||||||||||||||||||
1001 | } never executed: end of block | 0 | ||||||||||||||||||
1002 | return false; never executed: return false; | 0 | ||||||||||||||||||
1003 | } | - | ||||||||||||||||||
1004 | - | |||||||||||||||||||
1005 | #if !defined(Q_DEAD_CODE_FROM_QT4_MAC) | - | ||||||||||||||||||
1006 | // the Mac version is implemented in qscroller_mac.mm | - | ||||||||||||||||||
1007 | - | |||||||||||||||||||
1008 | QPointF QScrollerPrivate::realDpi(int screen) | - | ||||||||||||||||||
1009 | { | - | ||||||||||||||||||
1010 | # if defined(Q_DEAD_CODE_FROM_QT4_X11) && !defined(QT_NO_XRANDR) | - | ||||||||||||||||||
1011 | if (X11 && X11->use_xrandr && X11->ptrXRRSizes && X11->ptrXRRRootToScreen) { | - | ||||||||||||||||||
1012 | int nsizes = 0; | - | ||||||||||||||||||
1013 | // QDesktopWidget is based on Xinerama screens, which do not always | - | ||||||||||||||||||
1014 | // correspond to RandR screens: NVidia's TwinView e.g. will show up | - | ||||||||||||||||||
1015 | // as 2 screens in QDesktopWidget, but libXRandR will only see 1 screen. | - | ||||||||||||||||||
1016 | // (although with the combined size of the Xinerama screens). | - | ||||||||||||||||||
1017 | // Additionally, libXrandr will simply crash when calling XRRSizes | - | ||||||||||||||||||
1018 | // for (the non-existent) screen 1 in this scenario. | - | ||||||||||||||||||
1019 | Window root = RootWindow(X11->display, screen == -1 ? X11->defaultScreen : screen); | - | ||||||||||||||||||
1020 | int randrscreen = (root != XNone) ? X11->ptrXRRRootToScreen(X11->display, root) : -1; | - | ||||||||||||||||||
1021 | - | |||||||||||||||||||
1022 | XRRScreenSize *sizes = X11->ptrXRRSizes(X11->display, randrscreen == -1 ? 0 : randrscreen, &nsizes); | - | ||||||||||||||||||
1023 | if (nsizes > 0 && sizes && sizes->width && sizes->height && sizes->mwidth && sizes->mheight) { | - | ||||||||||||||||||
1024 | qScrollerDebug() << "XRandR DPI:" << QPointF(qreal(25.4) * qreal(sizes->width) / qreal(sizes->mwidth), | - | ||||||||||||||||||
1025 | qreal(25.4) * qreal(sizes->height) / qreal(sizes->mheight)); | - | ||||||||||||||||||
1026 | return QPointF(qreal(25.4) * qreal(sizes->width) / qreal(sizes->mwidth), | - | ||||||||||||||||||
1027 | qreal(25.4) * qreal(sizes->height) / qreal(sizes->mheight)); | - | ||||||||||||||||||
1028 | } | - | ||||||||||||||||||
1029 | } | - | ||||||||||||||||||
1030 | # endif | - | ||||||||||||||||||
1031 | - | |||||||||||||||||||
1032 | QWidget *w = QApplication::desktop()->screen(screen); | - | ||||||||||||||||||
1033 | return QPointF(w->physicalDpiX(), w->physicalDpiY()); never executed: return QPointF(w->physicalDpiX(), w->physicalDpiY()); | 0 | ||||||||||||||||||
1034 | } | - | ||||||||||||||||||
1035 | - | |||||||||||||||||||
1036 | #endif // !Q_DEAD_CODE_FROM_QT4_MAC | - | ||||||||||||||||||
1037 | - | |||||||||||||||||||
1038 | - | |||||||||||||||||||
1039 | /*! \internal | - | ||||||||||||||||||
1040 | Returns the resolution of the used screen. | - | ||||||||||||||||||
1041 | */ | - | ||||||||||||||||||
1042 | QPointF QScrollerPrivate::dpi() const | - | ||||||||||||||||||
1043 | { | - | ||||||||||||||||||
1044 | return pixelPerMeter * qreal(0.0254); never executed: return pixelPerMeter * qreal(0.0254); | 0 | ||||||||||||||||||
1045 | } | - | ||||||||||||||||||
1046 | - | |||||||||||||||||||
1047 | /*! \internal | - | ||||||||||||||||||
1048 | Sets the resolution used for scrolling. | - | ||||||||||||||||||
1049 | This resolution is only used by the kinetic scroller. If you change this | - | ||||||||||||||||||
1050 | then the scroller will behave quite different as a lot of the values are | - | ||||||||||||||||||
1051 | given in physical distances (millimeter). | - | ||||||||||||||||||
1052 | */ | - | ||||||||||||||||||
1053 | void QScrollerPrivate::setDpi(const QPointF &dpi) | - | ||||||||||||||||||
1054 | { | - | ||||||||||||||||||
1055 | pixelPerMeter = dpi / qreal(0.0254); | - | ||||||||||||||||||
1056 | } never executed: end of block | 0 | ||||||||||||||||||
1057 | - | |||||||||||||||||||
1058 | /*! \internal | - | ||||||||||||||||||
1059 | Sets the dpi used for scrolling to the value of the widget. | - | ||||||||||||||||||
1060 | */ | - | ||||||||||||||||||
1061 | void QScrollerPrivate::setDpiFromWidget(QWidget *widget) | - | ||||||||||||||||||
1062 | { | - | ||||||||||||||||||
1063 | QDesktopWidget *dw = QApplication::desktop(); | - | ||||||||||||||||||
1064 | setDpi(realDpi(widget ? dw->screenNumber(widget) : dw->primaryScreen())); | - | ||||||||||||||||||
1065 | } never executed: end of block | 0 | ||||||||||||||||||
1066 | - | |||||||||||||||||||
1067 | /*! \internal | - | ||||||||||||||||||
1068 | Updates the velocity during dragging. | - | ||||||||||||||||||
1069 | Sets releaseVelocity. | - | ||||||||||||||||||
1070 | */ | - | ||||||||||||||||||
1071 | void QScrollerPrivate::updateVelocity(const QPointF &deltaPixelRaw, qint64 deltaTime) | - | ||||||||||||||||||
1072 | { | - | ||||||||||||||||||
1073 | if (deltaTime <= 0)
| 0 | ||||||||||||||||||
1074 | return; never executed: return; | 0 | ||||||||||||||||||
1075 | - | |||||||||||||||||||
1076 | Q_Q(QScroller); | - | ||||||||||||||||||
1077 | QPointF ppm = q->pixelPerMeter(); | - | ||||||||||||||||||
1078 | const QScrollerPropertiesPrivate *sp = properties.d.data(); | - | ||||||||||||||||||
1079 | QPointF deltaPixel = deltaPixelRaw; | - | ||||||||||||||||||
1080 | - | |||||||||||||||||||
1081 | qScrollerDebug() << "QScroller::updateVelocity(" << deltaPixelRaw << " [delta pix], " << deltaTime << " [delta ms])"; dead code: QMessageLogger(__FILE__, 1081, __PRETTY_FUNCTION__).debug() << "QScroller::updateVelocity(" << deltaPixelRaw << " [delta pix], " << deltaTime << " [delta ms])"; | - | ||||||||||||||||||
1082 | - | |||||||||||||||||||
1083 | // faster than 2.5mm/ms seems bogus (that would be a screen height in ~20 ms) | - | ||||||||||||||||||
1084 | if (((deltaPixelRaw / qreal(deltaTime)).manhattanLength() / ((ppm.x() + ppm.y()) / 2) * 1000) > qreal(2.5))
| 0 | ||||||||||||||||||
1085 | deltaPixel = deltaPixelRaw * qreal(2.5) * ppm / 1000 / (deltaPixelRaw / qreal(deltaTime)).manhattanLength(); never executed: deltaPixel = deltaPixelRaw * qreal(2.5) * ppm / 1000 / (deltaPixelRaw / qreal(deltaTime)).manhattanLength(); | 0 | ||||||||||||||||||
1086 | - | |||||||||||||||||||
1087 | QPointF newv = -deltaPixel / qreal(deltaTime) * qreal(1000) / ppm; | - | ||||||||||||||||||
1088 | // around 95% of all updates are in the [1..50] ms range, so make sure | - | ||||||||||||||||||
1089 | // to scale the smoothing factor over that range: this way a 50ms update | - | ||||||||||||||||||
1090 | // will have full impact, while 5ms update will only have a 10% impact. | - | ||||||||||||||||||
1091 | qreal smoothing = sp->dragVelocitySmoothingFactor * qMin(qreal(deltaTime), qreal(50)) / qreal(50); | - | ||||||||||||||||||
1092 | - | |||||||||||||||||||
1093 | // only smooth if we already have a release velocity and only if the | - | ||||||||||||||||||
1094 | // user hasn't stopped to move his finger for more than 100ms | - | ||||||||||||||||||
1095 | if ((releaseVelocity != QPointF(0, 0)) && (deltaTime < 100)) {
| 0 | ||||||||||||||||||
1096 | qScrollerDebug() << "SMOOTHED from " << newv << " to " << newv * smoothing + releaseVelocity * (qreal(1) - smoothing); dead code: QMessageLogger(__FILE__, 1096, __PRETTY_FUNCTION__).debug() << "SMOOTHED from " << newv << " to " << newv * smoothing + releaseVelocity * (qreal(1) - smoothing); | - | ||||||||||||||||||
1097 | // smooth x or y only if the new velocity is either 0 or at least in | - | ||||||||||||||||||
1098 | // the same direction of the release velocity | - | ||||||||||||||||||
1099 | if (!newv.x() || (qSign(releaseVelocity.x()) == qSign(newv.x())))
| 0 | ||||||||||||||||||
1100 | newv.setX(newv.x() * smoothing + releaseVelocity.x() * (qreal(1) - smoothing)); never executed: newv.setX(newv.x() * smoothing + releaseVelocity.x() * (qreal(1) - smoothing)); | 0 | ||||||||||||||||||
1101 | if (!newv.y() || (qSign(releaseVelocity.y()) == qSign(newv.y())))
| 0 | ||||||||||||||||||
1102 | newv.setY(newv.y() * smoothing + releaseVelocity.y() * (qreal(1) - smoothing)); never executed: newv.setY(newv.y() * smoothing + releaseVelocity.y() * (qreal(1) - smoothing)); | 0 | ||||||||||||||||||
1103 | } else never executed: end of block | 0 | ||||||||||||||||||
1104 | qScrollerDebug() << "NO SMOOTHING to " << newv; dead code: QMessageLogger(__FILE__, 1104, __PRETTY_FUNCTION__).debug() << "NO SMOOTHING to " << newv; | - | ||||||||||||||||||
1105 | - | |||||||||||||||||||
1106 | releaseVelocity.setX(qBound(-sp->maximumVelocity, newv.x(), sp->maximumVelocity)); | - | ||||||||||||||||||
1107 | releaseVelocity.setY(qBound(-sp->maximumVelocity, newv.y(), sp->maximumVelocity)); | - | ||||||||||||||||||
1108 | - | |||||||||||||||||||
1109 | qScrollerDebug() << " --> new velocity:" << releaseVelocity; dead code: QMessageLogger(__FILE__, 1109, __PRETTY_FUNCTION__).debug() << " --> new velocity:" << releaseVelocity; | - | ||||||||||||||||||
1110 | } never executed: end of block | 0 | ||||||||||||||||||
1111 | - | |||||||||||||||||||
1112 | void QScrollerPrivate::pushSegment(ScrollType type, qreal deltaTime, qreal stopProgress, qreal startPos, qreal deltaPos, qreal stopPos, QEasingCurve::Type curve, Qt::Orientation orientation) | - | ||||||||||||||||||
1113 | { | - | ||||||||||||||||||
1114 | if (startPos == stopPos || deltaPos == 0)
| 0 | ||||||||||||||||||
1115 | return; never executed: return; | 0 | ||||||||||||||||||
1116 | - | |||||||||||||||||||
1117 | ScrollSegment s; | - | ||||||||||||||||||
1118 | if (orientation == Qt::Horizontal && !xSegments.isEmpty())
| 0 | ||||||||||||||||||
1119 | s.startTime = xSegments.last().startTime + xSegments.last().deltaTime * xSegments.last().stopProgress; never executed: s.startTime = xSegments.last().startTime + xSegments.last().deltaTime * xSegments.last().stopProgress; | 0 | ||||||||||||||||||
1120 | else if (orientation == Qt::Vertical && !ySegments.isEmpty())
| 0 | ||||||||||||||||||
1121 | s.startTime = ySegments.last().startTime + ySegments.last().deltaTime * ySegments.last().stopProgress; never executed: s.startTime = ySegments.last().startTime + ySegments.last().deltaTime * ySegments.last().stopProgress; | 0 | ||||||||||||||||||
1122 | else | - | ||||||||||||||||||
1123 | s.startTime = monotonicTimer.elapsed(); never executed: s.startTime = monotonicTimer.elapsed(); | 0 | ||||||||||||||||||
1124 | - | |||||||||||||||||||
1125 | s.startPos = startPos; | - | ||||||||||||||||||
1126 | s.deltaPos = deltaPos; | - | ||||||||||||||||||
1127 | s.stopPos = stopPos; | - | ||||||||||||||||||
1128 | s.deltaTime = deltaTime * 1000; | - | ||||||||||||||||||
1129 | s.stopProgress = stopProgress; | - | ||||||||||||||||||
1130 | s.curve.setType(curve); | - | ||||||||||||||||||
1131 | s.type = type; | - | ||||||||||||||||||
1132 | - | |||||||||||||||||||
1133 | if (orientation == Qt::Horizontal)
| 0 | ||||||||||||||||||
1134 | xSegments.enqueue(s); never executed: xSegments.enqueue(s); | 0 | ||||||||||||||||||
1135 | else | - | ||||||||||||||||||
1136 | ySegments.enqueue(s); never executed: ySegments.enqueue(s); | 0 | ||||||||||||||||||
1137 | - | |||||||||||||||||||
1138 | qScrollerDebug() << "+++ Added a new ScrollSegment: " << s; dead code: QMessageLogger(__FILE__, 1138, __PRETTY_FUNCTION__).debug() << "+++ Added a new ScrollSegment: " << s; | - | ||||||||||||||||||
1139 | } never executed: end of block | 0 | ||||||||||||||||||
1140 | - | |||||||||||||||||||
1141 | - | |||||||||||||||||||
1142 | /*! \internal | - | ||||||||||||||||||
1143 | Clears the old segments and recalculates them if the current segments are not longer valid | - | ||||||||||||||||||
1144 | */ | - | ||||||||||||||||||
1145 | void QScrollerPrivate::recalcScrollingSegments(bool forceRecalc) | - | ||||||||||||||||||
1146 | { | - | ||||||||||||||||||
1147 | Q_Q(QScroller); | - | ||||||||||||||||||
1148 | QPointF ppm = q->pixelPerMeter(); | - | ||||||||||||||||||
1149 | - | |||||||||||||||||||
1150 | releaseVelocity = q->velocity(); | - | ||||||||||||||||||
1151 | - | |||||||||||||||||||
1152 | if (forceRecalc ||
| 0 | ||||||||||||||||||
1153 | !scrollingSegmentsValid(Qt::Horizontal) ||
| 0 | ||||||||||||||||||
1154 | !scrollingSegmentsValid(Qt::Vertical))
| 0 | ||||||||||||||||||
1155 | createScrollingSegments(releaseVelocity, contentPosition + overshootPosition, ppm); never executed: createScrollingSegments(releaseVelocity, contentPosition + overshootPosition, ppm); | 0 | ||||||||||||||||||
1156 | } never executed: end of block | 0 | ||||||||||||||||||
1157 | - | |||||||||||||||||||
1158 | /*! \internal | - | ||||||||||||||||||
1159 | Returns the end position after the current scroll has finished. | - | ||||||||||||||||||
1160 | */ | - | ||||||||||||||||||
1161 | qreal QScrollerPrivate::scrollingSegmentsEndPos(Qt::Orientation orientation) const | - | ||||||||||||||||||
1162 | { | - | ||||||||||||||||||
1163 | if (orientation == Qt::Horizontal) {
| 0 | ||||||||||||||||||
1164 | if (xSegments.isEmpty())
| 0 | ||||||||||||||||||
1165 | return contentPosition.x() + overshootPosition.x(); never executed: return contentPosition.x() + overshootPosition.x(); | 0 | ||||||||||||||||||
1166 | else | - | ||||||||||||||||||
1167 | return xSegments.last().stopPos; never executed: return xSegments.last().stopPos; | 0 | ||||||||||||||||||
1168 | } else { | - | ||||||||||||||||||
1169 | if (ySegments.isEmpty())
| 0 | ||||||||||||||||||
1170 | return contentPosition.y() + overshootPosition.y(); never executed: return contentPosition.y() + overshootPosition.y(); | 0 | ||||||||||||||||||
1171 | else | - | ||||||||||||||||||
1172 | return ySegments.last().stopPos; never executed: return ySegments.last().stopPos; | 0 | ||||||||||||||||||
1173 | } | - | ||||||||||||||||||
1174 | } | - | ||||||||||||||||||
1175 | - | |||||||||||||||||||
1176 | /*! \internal | - | ||||||||||||||||||
1177 | Checks if the scroller segment end in a valid position. | - | ||||||||||||||||||
1178 | */ | - | ||||||||||||||||||
1179 | bool QScrollerPrivate::scrollingSegmentsValid(Qt::Orientation orientation) | - | ||||||||||||||||||
1180 | { | - | ||||||||||||||||||
1181 | QQueue<ScrollSegment> *segments; | - | ||||||||||||||||||
1182 | qreal minPos; | - | ||||||||||||||||||
1183 | qreal maxPos; | - | ||||||||||||||||||
1184 | - | |||||||||||||||||||
1185 | if (orientation == Qt::Horizontal) {
| 0 | ||||||||||||||||||
1186 | segments = &xSegments; | - | ||||||||||||||||||
1187 | minPos = contentPosRange.left(); | - | ||||||||||||||||||
1188 | maxPos = contentPosRange.right(); | - | ||||||||||||||||||
1189 | } else { never executed: end of block | 0 | ||||||||||||||||||
1190 | segments = &ySegments; | - | ||||||||||||||||||
1191 | minPos = contentPosRange.top(); | - | ||||||||||||||||||
1192 | maxPos = contentPosRange.bottom(); | - | ||||||||||||||||||
1193 | } never executed: end of block | 0 | ||||||||||||||||||
1194 | - | |||||||||||||||||||
1195 | if (segments->isEmpty())
| 0 | ||||||||||||||||||
1196 | return true; never executed: return true; | 0 | ||||||||||||||||||
1197 | - | |||||||||||||||||||
1198 | const ScrollSegment &last = segments->last(); | - | ||||||||||||||||||
1199 | qreal stopPos = last.stopPos; | - | ||||||||||||||||||
1200 | - | |||||||||||||||||||
1201 | if (last.type == ScrollTypeScrollTo)
| 0 | ||||||||||||||||||
1202 | return true; // scrollTo is always valid never executed: return true; | 0 | ||||||||||||||||||
1203 | - | |||||||||||||||||||
1204 | if (last.type == ScrollTypeOvershoot &&
| 0 | ||||||||||||||||||
1205 | (stopPos != minPos && stopPos != maxPos))
| 0 | ||||||||||||||||||
1206 | return false; never executed: return false; | 0 | ||||||||||||||||||
1207 | - | |||||||||||||||||||
1208 | if (stopPos < minPos || stopPos > maxPos)
| 0 | ||||||||||||||||||
1209 | return false; never executed: return false; | 0 | ||||||||||||||||||
1210 | - | |||||||||||||||||||
1211 | if (stopPos == minPos || stopPos == maxPos) // the begin and the end of the list are always ok
| 0 | ||||||||||||||||||
1212 | return true; never executed: return true; | 0 | ||||||||||||||||||
1213 | - | |||||||||||||||||||
1214 | qreal nextSnap = nextSnapPos(stopPos, 0, orientation); | - | ||||||||||||||||||
1215 | if (!qIsNaN(nextSnap) && stopPos != nextSnap)
| 0 | ||||||||||||||||||
1216 | return false; never executed: return false; | 0 | ||||||||||||||||||
1217 | - | |||||||||||||||||||
1218 | return true; never executed: return true; | 0 | ||||||||||||||||||
1219 | } | - | ||||||||||||||||||
1220 | - | |||||||||||||||||||
1221 | /*! \internal | - | ||||||||||||||||||
1222 | Creates the sections needed to scroll to the specific \a endPos to the segments queue. | - | ||||||||||||||||||
1223 | */ | - | ||||||||||||||||||
1224 | void QScrollerPrivate::createScrollToSegments(qreal v, qreal deltaTime, qreal endPos, Qt::Orientation orientation, ScrollType type) | - | ||||||||||||||||||
1225 | { | - | ||||||||||||||||||
1226 | Q_UNUSED(v); | - | ||||||||||||||||||
1227 | - | |||||||||||||||||||
1228 | if (orientation == Qt::Horizontal)
| 0 | ||||||||||||||||||
1229 | xSegments.clear(); never executed: xSegments.clear(); | 0 | ||||||||||||||||||
1230 | else | - | ||||||||||||||||||
1231 | ySegments.clear(); never executed: ySegments.clear(); | 0 | ||||||||||||||||||
1232 | - | |||||||||||||||||||
1233 | qScrollerDebug() << "+++ createScrollToSegments: t:" << deltaTime << "ep:" << endPos << "o:" << int(orientation); dead code: QMessageLogger(__FILE__, 1233, __PRETTY_FUNCTION__).debug() << "+++ createScrollToSegments: t:" << deltaTime << "ep:" << endPos << "o:" << int(orientation); | - | ||||||||||||||||||
1234 | - | |||||||||||||||||||
1235 | const QScrollerPropertiesPrivate *sp = properties.d.data(); | - | ||||||||||||||||||
1236 | - | |||||||||||||||||||
1237 | qreal startPos = (orientation == Qt::Horizontal) ? contentPosition.x() + overshootPosition.x()
| 0 | ||||||||||||||||||
1238 | : contentPosition.y() + overshootPosition.y(); | - | ||||||||||||||||||
1239 | qreal deltaPos = (endPos - startPos) / 2; | - | ||||||||||||||||||
1240 | - | |||||||||||||||||||
1241 | pushSegment(type, deltaTime * qreal(0.3), qreal(1.0), startPos, deltaPos, startPos + deltaPos, QEasingCurve::InQuad, orientation); | - | ||||||||||||||||||
1242 | pushSegment(type, deltaTime * qreal(0.7), qreal(1.0), startPos + deltaPos, deltaPos, endPos, sp->scrollingCurve.type(), orientation); | - | ||||||||||||||||||
1243 | } never executed: end of block | 0 | ||||||||||||||||||
1244 | - | |||||||||||||||||||
1245 | /*! \internal | - | ||||||||||||||||||
1246 | */ | - | ||||||||||||||||||
1247 | void QScrollerPrivate::createScrollingSegments(qreal v, qreal startPos, | - | ||||||||||||||||||
1248 | qreal deltaTime, qreal deltaPos, | - | ||||||||||||||||||
1249 | Qt::Orientation orientation) | - | ||||||||||||||||||
1250 | { | - | ||||||||||||||||||
1251 | const QScrollerPropertiesPrivate *sp = properties.d.data(); | - | ||||||||||||||||||
1252 | - | |||||||||||||||||||
1253 | QScrollerProperties::OvershootPolicy policy; | - | ||||||||||||||||||
1254 | qreal minPos; | - | ||||||||||||||||||
1255 | qreal maxPos; | - | ||||||||||||||||||
1256 | qreal viewSize; | - | ||||||||||||||||||
1257 | - | |||||||||||||||||||
1258 | if (orientation == Qt::Horizontal) {
| 0 | ||||||||||||||||||
1259 | xSegments.clear(); | - | ||||||||||||||||||
1260 | policy = sp->hOvershootPolicy; | - | ||||||||||||||||||
1261 | minPos = contentPosRange.left(); | - | ||||||||||||||||||
1262 | maxPos = contentPosRange.right(); | - | ||||||||||||||||||
1263 | viewSize = viewportSize.width(); | - | ||||||||||||||||||
1264 | } else { never executed: end of block | 0 | ||||||||||||||||||
1265 | ySegments.clear(); | - | ||||||||||||||||||
1266 | policy = sp->vOvershootPolicy; | - | ||||||||||||||||||
1267 | minPos = contentPosRange.top(); | - | ||||||||||||||||||
1268 | maxPos = contentPosRange.bottom(); | - | ||||||||||||||||||
1269 | viewSize = viewportSize.height(); | - | ||||||||||||||||||
1270 | } never executed: end of block | 0 | ||||||||||||||||||
1271 | - | |||||||||||||||||||
1272 | bool alwaysOvershoot = (policy == QScrollerProperties::OvershootAlwaysOn); | - | ||||||||||||||||||
1273 | bool noOvershoot = (policy == QScrollerProperties::OvershootAlwaysOff) || !sp->overshootScrollDistanceFactor;
| 0 | ||||||||||||||||||
1274 | bool canOvershoot = !noOvershoot && (alwaysOvershoot || maxPos);
| 0 | ||||||||||||||||||
1275 | - | |||||||||||||||||||
1276 | qScrollerDebug() << "+++ createScrollingSegments: s:" << startPos << "maxPos:" << maxPos << "o:" << int(orientation); dead code: QMessageLogger(__FILE__, 1276, __PRETTY_FUNCTION__).debug() << "+++ createScrollingSegments: s:" << startPos << "maxPos:" << maxPos << "o:" << int(orientation); | - | ||||||||||||||||||
1277 | - | |||||||||||||||||||
1278 | qScrollerDebug() << "v = " << v << ", decelerationFactor = " << sp->decelerationFactor << ", curveType = " << sp->scrollingCurve.type(); dead code: QMessageLogger(__FILE__, 1278, __PRETTY_FUNCTION__).debug() << "v = " << v << ", decelerationFactor = " << sp->decelerationFactor << ", curveType = " << sp->scrollingCurve.type(); | - | ||||||||||||||||||
1279 | - | |||||||||||||||||||
1280 | qreal endPos = startPos + deltaPos; | - | ||||||||||||||||||
1281 | - | |||||||||||||||||||
1282 | qScrollerDebug() << " Real Delta:" << deltaPos; dead code: QMessageLogger(__FILE__, 1282, __PRETTY_FUNCTION__).debug() << " Real Delta:" << deltaPos; | - | ||||||||||||||||||
1283 | - | |||||||||||||||||||
1284 | // -- check if are in overshoot and end in overshoot | - | ||||||||||||||||||
1285 | if ((startPos < minPos && endPos < minPos) ||
| 0 | ||||||||||||||||||
1286 | (startPos > maxPos && endPos > maxPos)) {
| 0 | ||||||||||||||||||
1287 | qreal stopPos = endPos < minPos ? minPos : maxPos;
| 0 | ||||||||||||||||||
1288 | qreal oDeltaTime = sp->overshootScrollTime; | - | ||||||||||||||||||
1289 | - | |||||||||||||||||||
1290 | pushSegment(ScrollTypeOvershoot, oDeltaTime * qreal(0.7), qreal(1.0), startPos, stopPos - startPos, stopPos, sp->scrollingCurve.type(), orientation); | - | ||||||||||||||||||
1291 | return; never executed: return; | 0 | ||||||||||||||||||
1292 | } | - | ||||||||||||||||||
1293 | - | |||||||||||||||||||
1294 | // -- determine snap points | - | ||||||||||||||||||
1295 | qreal nextSnap = nextSnapPos(endPos, 0, orientation); | - | ||||||||||||||||||
1296 | qreal lowerSnapPos = nextSnapPos(startPos, -1, orientation); | - | ||||||||||||||||||
1297 | qreal higherSnapPos = nextSnapPos(startPos, 1, orientation); | - | ||||||||||||||||||
1298 | - | |||||||||||||||||||
1299 | qScrollerDebug() << " Real Delta:" << lowerSnapPos << '-' << nextSnap << '-' <<higherSnapPos; dead code: QMessageLogger(__FILE__, 1299, __PRETTY_FUNCTION__).debug() << " Real Delta:" << lowerSnapPos << '-' << nextSnap << '-' <<higherSnapPos; | - | ||||||||||||||||||
1300 | - | |||||||||||||||||||
1301 | // - check if we can reach another snap point | - | ||||||||||||||||||
1302 | if (nextSnap > higherSnapPos || qIsNaN(higherSnapPos))
| 0 | ||||||||||||||||||
1303 | higherSnapPos = nextSnap; never executed: higherSnapPos = nextSnap; | 0 | ||||||||||||||||||
1304 | if (nextSnap < lowerSnapPos || qIsNaN(lowerSnapPos))
| 0 | ||||||||||||||||||
1305 | lowerSnapPos = nextSnap; never executed: lowerSnapPos = nextSnap; | 0 | ||||||||||||||||||
1306 | - | |||||||||||||||||||
1307 | if (qAbs(v) < sp->minimumVelocity) {
| 0 | ||||||||||||||||||
1308 | - | |||||||||||||||||||
1309 | qScrollerDebug() << "### below minimum Vel" << orientation; dead code: QMessageLogger(__FILE__, 1309, __PRETTY_FUNCTION__).debug() << "### below minimum Vel" << orientation; | - | ||||||||||||||||||
1310 | - | |||||||||||||||||||
1311 | // - no snap points or already at one | - | ||||||||||||||||||
1312 | if (qIsNaN(nextSnap) || nextSnap == startPos)
| 0 | ||||||||||||||||||
1313 | return; // nothing to do, no scrolling needed. never executed: return; | 0 | ||||||||||||||||||
1314 | - | |||||||||||||||||||
1315 | // - decide which point to use | - | ||||||||||||||||||
1316 | - | |||||||||||||||||||
1317 | qreal snapDistance = higherSnapPos - lowerSnapPos; | - | ||||||||||||||||||
1318 | - | |||||||||||||||||||
1319 | qreal pressDistance = (orientation == Qt::Horizontal) ?
| 0 | ||||||||||||||||||
1320 | lastPosition.x() - pressPosition.x() : | - | ||||||||||||||||||
1321 | lastPosition.y() - pressPosition.y(); | - | ||||||||||||||||||
1322 | - | |||||||||||||||||||
1323 | // if not dragged far enough, pick the next snap point. | - | ||||||||||||||||||
1324 | if (sp->snapPositionRatio == 0.0 || qAbs(pressDistance / sp->snapPositionRatio) > snapDistance)
| 0 | ||||||||||||||||||
1325 | endPos = nextSnap; never executed: endPos = nextSnap; | 0 | ||||||||||||||||||
1326 | else if (pressDistance < 0.0)
| 0 | ||||||||||||||||||
1327 | endPos = lowerSnapPos; never executed: endPos = lowerSnapPos; | 0 | ||||||||||||||||||
1328 | else | - | ||||||||||||||||||
1329 | endPos = higherSnapPos; never executed: endPos = higherSnapPos; | 0 | ||||||||||||||||||
1330 | - | |||||||||||||||||||
1331 | deltaPos = endPos - startPos; | - | ||||||||||||||||||
1332 | qreal midPos = startPos + deltaPos * qreal(0.3); | - | ||||||||||||||||||
1333 | pushSegment(ScrollTypeFlick, sp->snapTime * qreal(0.3), qreal(1.0), startPos, midPos - startPos, midPos, QEasingCurve::InQuad, orientation); | - | ||||||||||||||||||
1334 | pushSegment(ScrollTypeFlick, sp->snapTime * qreal(0.7), qreal(1.0), midPos, endPos - midPos, endPos, sp->scrollingCurve.type(), orientation); | - | ||||||||||||||||||
1335 | return; never executed: return; | 0 | ||||||||||||||||||
1336 | } | - | ||||||||||||||||||
1337 | - | |||||||||||||||||||
1338 | // - go to the next snappoint if there is one | - | ||||||||||||||||||
1339 | if (v > 0 && !qIsNaN(higherSnapPos)) {
| 0 | ||||||||||||||||||
1340 | // change the time in relation to the changed end position | - | ||||||||||||||||||
1341 | if (endPos - startPos)
| 0 | ||||||||||||||||||
1342 | deltaTime *= qAbs((higherSnapPos - startPos) / (endPos - startPos)); never executed: deltaTime *= qAbs((higherSnapPos - startPos) / (endPos - startPos)); | 0 | ||||||||||||||||||
1343 | if (deltaTime > sp->snapTime)
| 0 | ||||||||||||||||||
1344 | deltaTime = sp->snapTime; never executed: deltaTime = sp->snapTime; | 0 | ||||||||||||||||||
1345 | endPos = higherSnapPos; | - | ||||||||||||||||||
1346 | - | |||||||||||||||||||
1347 | } else if (v < 0 && !qIsNaN(lowerSnapPos)) { never executed: end of block
| 0 | ||||||||||||||||||
1348 | // change the time in relation to the changed end position | - | ||||||||||||||||||
1349 | if (endPos - startPos)
| 0 | ||||||||||||||||||
1350 | deltaTime *= qAbs((lowerSnapPos - startPos) / (endPos - startPos)); never executed: deltaTime *= qAbs((lowerSnapPos - startPos) / (endPos - startPos)); | 0 | ||||||||||||||||||
1351 | if (deltaTime > sp->snapTime)
| 0 | ||||||||||||||||||
1352 | deltaTime = sp->snapTime; never executed: deltaTime = sp->snapTime; | 0 | ||||||||||||||||||
1353 | endPos = lowerSnapPos; | - | ||||||||||||||||||
1354 | - | |||||||||||||||||||
1355 | // -- check if we are overshooting | - | ||||||||||||||||||
1356 | } else if (endPos < minPos || endPos > maxPos) { never executed: end of block
| 0 | ||||||||||||||||||
1357 | qreal stopPos = endPos < minPos ? minPos : maxPos;
| 0 | ||||||||||||||||||
1358 | - | |||||||||||||||||||
1359 | qScrollerDebug() << "Overshoot: delta:" << (stopPos - startPos); dead code: QMessageLogger(__FILE__, 1359, __PRETTY_FUNCTION__).debug() << "Overshoot: delta:" << (stopPos - startPos); | - | ||||||||||||||||||
1360 | - | |||||||||||||||||||
1361 | qreal stopProgress = progressForValue(sp->scrollingCurve, qAbs((stopPos - startPos) / deltaPos)); | - | ||||||||||||||||||
1362 | - | |||||||||||||||||||
1363 | if (!canOvershoot) {
| 0 | ||||||||||||||||||
1364 | qScrollerDebug() << "Overshoot stopp:" << stopProgress; dead code: QMessageLogger(__FILE__, 1364, __PRETTY_FUNCTION__).debug() << "Overshoot stopp:" << stopProgress; | - | ||||||||||||||||||
1365 | - | |||||||||||||||||||
1366 | pushSegment(ScrollTypeFlick, deltaTime, stopProgress, startPos, endPos, stopPos, sp->scrollingCurve.type(), orientation); | - | ||||||||||||||||||
1367 | } else { never executed: end of block | 0 | ||||||||||||||||||
1368 | qreal oDeltaTime = sp->overshootScrollTime; | - | ||||||||||||||||||
1369 | qreal oStopProgress = qMin(stopProgress + oDeltaTime * qreal(0.3) / deltaTime, qreal(1)); | - | ||||||||||||||||||
1370 | qreal oDistance = startPos + deltaPos * sp->scrollingCurve.valueForProgress(oStopProgress) - stopPos; | - | ||||||||||||||||||
1371 | qreal oMaxDistance = qSign(oDistance) * (viewSize * sp->overshootScrollDistanceFactor); | - | ||||||||||||||||||
1372 | - | |||||||||||||||||||
1373 | qScrollerDebug() << "1 oDistance:" << oDistance << "Max:" << oMaxDistance << "stopP/oStopP" << stopProgress << oStopProgress; dead code: QMessageLogger(__FILE__, 1373, __PRETTY_FUNCTION__).debug() << "1 oDistance:" << oDistance << "Max:" << oMaxDistance << "stopP/oStopP" << stopProgress << oStopProgress; | - | ||||||||||||||||||
1374 | - | |||||||||||||||||||
1375 | if (qAbs(oDistance) > qAbs(oMaxDistance)) {
| 0 | ||||||||||||||||||
1376 | oStopProgress = progressForValue(sp->scrollingCurve, qAbs((stopPos + oMaxDistance - startPos) / deltaPos)); | - | ||||||||||||||||||
1377 | oDistance = oMaxDistance; | - | ||||||||||||||||||
1378 | qScrollerDebug() << "2 oDistance:" << oDistance << "Max:" << oMaxDistance << "stopP/oStopP" << stopProgress << oStopProgress; dead code: QMessageLogger(__FILE__, 1378, __PRETTY_FUNCTION__).debug() << "2 oDistance:" << oDistance << "Max:" << oMaxDistance << "stopP/oStopP" << stopProgress << oStopProgress; | - | ||||||||||||||||||
1379 | } never executed: end of block | 0 | ||||||||||||||||||
1380 | - | |||||||||||||||||||
1381 | pushSegment(ScrollTypeFlick, deltaTime, oStopProgress, startPos, deltaPos, stopPos + oDistance, sp->scrollingCurve.type(), orientation); | - | ||||||||||||||||||
1382 | pushSegment(ScrollTypeOvershoot, oDeltaTime * qreal(0.7), qreal(1.0), stopPos + oDistance, -oDistance, stopPos, sp->scrollingCurve.type(), orientation); | - | ||||||||||||||||||
1383 | } never executed: end of block | 0 | ||||||||||||||||||
1384 | return; never executed: return; | 0 | ||||||||||||||||||
1385 | } | - | ||||||||||||||||||
1386 | - | |||||||||||||||||||
1387 | pushSegment(ScrollTypeFlick, deltaTime, qreal(1.0), startPos, deltaPos, endPos, sp->scrollingCurve.type(), orientation); | - | ||||||||||||||||||
1388 | } never executed: end of block | 0 | ||||||||||||||||||
1389 | - | |||||||||||||||||||
1390 | - | |||||||||||||||||||
1391 | void QScrollerPrivate::createScrollingSegments(const QPointF &v, | - | ||||||||||||||||||
1392 | const QPointF &startPos, | - | ||||||||||||||||||
1393 | const QPointF &ppm) | - | ||||||||||||||||||
1394 | { | - | ||||||||||||||||||
1395 | const QScrollerPropertiesPrivate *sp = properties.d.data(); | - | ||||||||||||||||||
1396 | - | |||||||||||||||||||
1397 | // This is only correct for QEasingCurve::OutQuad (linear velocity, | - | ||||||||||||||||||
1398 | // constant deceleration), but the results look and feel ok for OutExpo | - | ||||||||||||||||||
1399 | // and OutSine as well | - | ||||||||||||||||||
1400 | - | |||||||||||||||||||
1401 | // v(t) = deltaTime * a * 0.5 * differentialForProgress(t / deltaTime) | - | ||||||||||||||||||
1402 | // v(0) = vrelease | - | ||||||||||||||||||
1403 | // v(deltaTime) = 0 | - | ||||||||||||||||||
1404 | // deltaTime = (2 * vrelease) / (a * differntial(0)) | - | ||||||||||||||||||
1405 | - | |||||||||||||||||||
1406 | // pos(t) = integrate(v(t)dt) | - | ||||||||||||||||||
1407 | // pos(t) = vrelease * t - 0.5 * a * t * t | - | ||||||||||||||||||
1408 | // pos(t) = deltaTime * a * 0.5 * progress(t / deltaTime) * deltaTime | - | ||||||||||||||||||
1409 | // deltaPos = pos(deltaTime) | - | ||||||||||||||||||
1410 | - | |||||||||||||||||||
1411 | QVector2D vel(v); | - | ||||||||||||||||||
1412 | qreal deltaTime = (qreal(2) * vel.length()) / (sp->decelerationFactor * differentialForProgress(sp->scrollingCurve, 0)); | - | ||||||||||||||||||
1413 | QPointF deltaPos = (vel.normalized() * QVector2D(ppm)).toPointF() * deltaTime * deltaTime * qreal(0.5) * sp->decelerationFactor; | - | ||||||||||||||||||
1414 | - | |||||||||||||||||||
1415 | createScrollingSegments(v.x(), startPos.x(), deltaTime, deltaPos.x(), | - | ||||||||||||||||||
1416 | Qt::Horizontal); | - | ||||||||||||||||||
1417 | createScrollingSegments(v.y(), startPos.y(), deltaTime, deltaPos.y(), | - | ||||||||||||||||||
1418 | Qt::Vertical); | - | ||||||||||||||||||
1419 | } never executed: end of block | 0 | ||||||||||||||||||
1420 | - | |||||||||||||||||||
1421 | /*! \internal | - | ||||||||||||||||||
1422 | Prepares scrolling by sending a QScrollPrepareEvent to the receiver widget. | - | ||||||||||||||||||
1423 | Returns \c true if the scrolling was accepted and a target was returned. | - | ||||||||||||||||||
1424 | */ | - | ||||||||||||||||||
1425 | bool QScrollerPrivate::prepareScrolling(const QPointF &position) | - | ||||||||||||||||||
1426 | { | - | ||||||||||||||||||
1427 | QScrollPrepareEvent spe(position); | - | ||||||||||||||||||
1428 | spe.ignore(); | - | ||||||||||||||||||
1429 | sendEvent(target, &spe); | - | ||||||||||||||||||
1430 | - | |||||||||||||||||||
1431 | qScrollerDebug() << "QScrollPrepareEvent returned from" << target << "with" << spe.isAccepted() << "mcp:" << spe.contentPosRange() << "cp:" << spe.contentPos(); dead code: QMessageLogger(__FILE__, 1431, __PRETTY_FUNCTION__).debug() << "QScrollPrepareEvent returned from" << target << "with" << spe.isAccepted() << "mcp:" << spe.contentPosRange() << "cp:" << spe.contentPos(); | - | ||||||||||||||||||
1432 | if (spe.isAccepted()) {
| 0 | ||||||||||||||||||
1433 | QPointF oldContentPos = contentPosition + overshootPosition; | - | ||||||||||||||||||
1434 | QPointF contentDelta = spe.contentPos() - oldContentPos; | - | ||||||||||||||||||
1435 | - | |||||||||||||||||||
1436 | viewportSize = spe.viewportSize(); | - | ||||||||||||||||||
1437 | contentPosRange = spe.contentPosRange(); | - | ||||||||||||||||||
1438 | if (contentPosRange.width() < 0)
| 0 | ||||||||||||||||||
1439 | contentPosRange.setWidth(0); never executed: contentPosRange.setWidth(0); | 0 | ||||||||||||||||||
1440 | if (contentPosRange.height() < 0)
| 0 | ||||||||||||||||||
1441 | contentPosRange.setHeight(0); never executed: contentPosRange.setHeight(0); | 0 | ||||||||||||||||||
1442 | contentPosition = clampToRect(spe.contentPos(), contentPosRange); | - | ||||||||||||||||||
1443 | overshootPosition = spe.contentPos() - contentPosition; | - | ||||||||||||||||||
1444 | - | |||||||||||||||||||
1445 | // - check if the content position was moved | - | ||||||||||||||||||
1446 | if (contentDelta != QPointF(0, 0)) {
| 0 | ||||||||||||||||||
1447 | // need to correct all segments | - | ||||||||||||||||||
1448 | for (int i = 0; i < xSegments.count(); i++)
| 0 | ||||||||||||||||||
1449 | xSegments[i].startPos -= contentDelta.x(); never executed: xSegments[i].startPos -= contentDelta.x(); | 0 | ||||||||||||||||||
1450 | - | |||||||||||||||||||
1451 | for (int i = 0; i < ySegments.count(); i++)
| 0 | ||||||||||||||||||
1452 | ySegments[i].startPos -= contentDelta.y(); never executed: ySegments[i].startPos -= contentDelta.y(); | 0 | ||||||||||||||||||
1453 | } never executed: end of block | 0 | ||||||||||||||||||
1454 | - | |||||||||||||||||||
1455 | if (QWidget *w = qobject_cast<QWidget *>(target))
| 0 | ||||||||||||||||||
1456 | setDpiFromWidget(w); never executed: setDpiFromWidget(w); | 0 | ||||||||||||||||||
1457 | #ifndef QT_NO_GRAPHICSVIEW | - | ||||||||||||||||||
1458 | if (QGraphicsObject *go = qobject_cast<QGraphicsObject *>(target)) {
| 0 | ||||||||||||||||||
1459 | //TODO: the first view isn't really correct - maybe use an additional field in the prepare event? | - | ||||||||||||||||||
1460 | if (go->scene() && !go->scene()->views().isEmpty())
| 0 | ||||||||||||||||||
1461 | setDpiFromWidget(go->scene()->views().first()); never executed: setDpiFromWidget(go->scene()->views().first()); | 0 | ||||||||||||||||||
1462 | } never executed: end of block | 0 | ||||||||||||||||||
1463 | #endif | - | ||||||||||||||||||
1464 | - | |||||||||||||||||||
1465 | if (state == QScroller::Scrolling) {
| 0 | ||||||||||||||||||
1466 | recalcScrollingSegments(); | - | ||||||||||||||||||
1467 | } never executed: end of block | 0 | ||||||||||||||||||
1468 | return true; never executed: return true; | 0 | ||||||||||||||||||
1469 | } | - | ||||||||||||||||||
1470 | - | |||||||||||||||||||
1471 | return false; never executed: return false; | 0 | ||||||||||||||||||
1472 | } | - | ||||||||||||||||||
1473 | - | |||||||||||||||||||
1474 | void QScrollerPrivate::handleDrag(const QPointF &position, qint64 timestamp) | - | ||||||||||||||||||
1475 | { | - | ||||||||||||||||||
1476 | const QScrollerPropertiesPrivate *sp = properties.d.data(); | - | ||||||||||||||||||
1477 | - | |||||||||||||||||||
1478 | QPointF deltaPixel = position - lastPosition; | - | ||||||||||||||||||
1479 | qint64 deltaTime = timestamp - lastTimestamp; | - | ||||||||||||||||||
1480 | - | |||||||||||||||||||
1481 | if (sp->axisLockThreshold) {
| 0 | ||||||||||||||||||
1482 | int dx = qAbs(deltaPixel.x()); | - | ||||||||||||||||||
1483 | int dy = qAbs(deltaPixel.y()); | - | ||||||||||||||||||
1484 | if (dx || dy) {
| 0 | ||||||||||||||||||
1485 | bool vertical = (dy > dx); | - | ||||||||||||||||||
1486 | qreal alpha = qreal(vertical ? dx : dy) / qreal(vertical ? dy : dx); | - | ||||||||||||||||||
1487 | //qScrollerDebug() << "QScroller::handleDrag() -- axis lock:" << alpha << " / " << axisLockThreshold << "- isvertical:" << vertical << "- dx:" << dx << "- dy:" << dy; | - | ||||||||||||||||||
1488 | if (alpha <= sp->axisLockThreshold) {
| 0 | ||||||||||||||||||
1489 | if (vertical)
| 0 | ||||||||||||||||||
1490 | deltaPixel.setX(0); never executed: deltaPixel.setX(0); | 0 | ||||||||||||||||||
1491 | else | - | ||||||||||||||||||
1492 | deltaPixel.setY(0); never executed: deltaPixel.setY(0); | 0 | ||||||||||||||||||
1493 | } | - | ||||||||||||||||||
1494 | } never executed: end of block | 0 | ||||||||||||||||||
1495 | } never executed: end of block | 0 | ||||||||||||||||||
1496 | - | |||||||||||||||||||
1497 | // calculate velocity (if the user would release the mouse NOW) | - | ||||||||||||||||||
1498 | updateVelocity(deltaPixel, deltaTime); | - | ||||||||||||||||||
1499 | - | |||||||||||||||||||
1500 | // restrict velocity, if content is not scrollable | - | ||||||||||||||||||
1501 | QRectF max = contentPosRange; | - | ||||||||||||||||||
1502 | bool canScrollX = (max.width() > 0) || (sp->hOvershootPolicy == QScrollerProperties::OvershootAlwaysOn);
| 0 | ||||||||||||||||||
1503 | bool canScrollY = (max.height() > 0) || (sp->vOvershootPolicy == QScrollerProperties::OvershootAlwaysOn);
| 0 | ||||||||||||||||||
1504 | - | |||||||||||||||||||
1505 | if (!canScrollX) {
| 0 | ||||||||||||||||||
1506 | deltaPixel.setX(0); | - | ||||||||||||||||||
1507 | releaseVelocity.setX(0); | - | ||||||||||||||||||
1508 | } never executed: end of block | 0 | ||||||||||||||||||
1509 | if (!canScrollY) {
| 0 | ||||||||||||||||||
1510 | deltaPixel.setY(0); | - | ||||||||||||||||||
1511 | releaseVelocity.setY(0); | - | ||||||||||||||||||
1512 | } never executed: end of block | 0 | ||||||||||||||||||
1513 | - | |||||||||||||||||||
1514 | // if (firstDrag) { | - | ||||||||||||||||||
1515 | // // Do not delay the first drag | - | ||||||||||||||||||
1516 | // setContentPositionHelper(q->contentPosition() - overshootDistance - deltaPixel); | - | ||||||||||||||||||
1517 | // dragDistance = QPointF(0, 0); | - | ||||||||||||||||||
1518 | // } else { | - | ||||||||||||||||||
1519 | dragDistance += deltaPixel; | - | ||||||||||||||||||
1520 | // } | - | ||||||||||||||||||
1521 | //qScrollerDebug() << "######################" << deltaPixel << position.y() << lastPosition.y(); | - | ||||||||||||||||||
1522 | - | |||||||||||||||||||
1523 | lastPosition = position; | - | ||||||||||||||||||
1524 | lastTimestamp = timestamp; | - | ||||||||||||||||||
1525 | } never executed: end of block | 0 | ||||||||||||||||||
1526 | - | |||||||||||||||||||
1527 | bool QScrollerPrivate::pressWhileInactive(const QPointF &position, qint64 timestamp) | - | ||||||||||||||||||
1528 | { | - | ||||||||||||||||||
1529 | if (prepareScrolling(position)) {
| 0 | ||||||||||||||||||
1530 | const QScrollerPropertiesPrivate *sp = properties.d.data(); | - | ||||||||||||||||||
1531 | - | |||||||||||||||||||
1532 | if (!contentPosRange.isNull() ||
| 0 | ||||||||||||||||||
1533 | (sp->hOvershootPolicy == QScrollerProperties::OvershootAlwaysOn) ||
| 0 | ||||||||||||||||||
1534 | (sp->vOvershootPolicy == QScrollerProperties::OvershootAlwaysOn)) {
| 0 | ||||||||||||||||||
1535 | - | |||||||||||||||||||
1536 | lastPosition = pressPosition = position; | - | ||||||||||||||||||
1537 | lastTimestamp = pressTimestamp = timestamp; | - | ||||||||||||||||||
1538 | setState(QScroller::Pressed); | - | ||||||||||||||||||
1539 | } never executed: end of block | 0 | ||||||||||||||||||
1540 | } never executed: end of block | 0 | ||||||||||||||||||
1541 | return false; never executed: return false; | 0 | ||||||||||||||||||
1542 | } | - | ||||||||||||||||||
1543 | - | |||||||||||||||||||
1544 | bool QScrollerPrivate::releaseWhilePressed(const QPointF &, qint64) | - | ||||||||||||||||||
1545 | { | - | ||||||||||||||||||
1546 | if (overshootPosition != QPointF(0.0, 0.0)) {
| 0 | ||||||||||||||||||
1547 | setState(QScroller::Scrolling); | - | ||||||||||||||||||
1548 | return true; never executed: return true; | 0 | ||||||||||||||||||
1549 | } else { | - | ||||||||||||||||||
1550 | setState(QScroller::Inactive); | - | ||||||||||||||||||
1551 | return false; never executed: return false; | 0 | ||||||||||||||||||
1552 | } | - | ||||||||||||||||||
1553 | } | - | ||||||||||||||||||
1554 | - | |||||||||||||||||||
1555 | bool QScrollerPrivate::moveWhilePressed(const QPointF &position, qint64 timestamp) | - | ||||||||||||||||||
1556 | { | - | ||||||||||||||||||
1557 | Q_Q(QScroller); | - | ||||||||||||||||||
1558 | const QScrollerPropertiesPrivate *sp = properties.d.data(); | - | ||||||||||||||||||
1559 | QPointF ppm = q->pixelPerMeter(); | - | ||||||||||||||||||
1560 | - | |||||||||||||||||||
1561 | QPointF deltaPixel = position - pressPosition; | - | ||||||||||||||||||
1562 | - | |||||||||||||||||||
1563 | bool moveAborted = false; | - | ||||||||||||||||||
1564 | bool moveStarted = (((deltaPixel / ppm).manhattanLength()) > sp->dragStartDistance); | - | ||||||||||||||||||
1565 | - | |||||||||||||||||||
1566 | // check the direction of the mouse drag and abort if it's too much in the wrong direction. | - | ||||||||||||||||||
1567 | if (moveStarted) {
| 0 | ||||||||||||||||||
1568 | QRectF max = contentPosRange; | - | ||||||||||||||||||
1569 | bool canScrollX = (max.width() > 0); | - | ||||||||||||||||||
1570 | bool canScrollY = (max.height() > 0); | - | ||||||||||||||||||
1571 | - | |||||||||||||||||||
1572 | if (sp->hOvershootPolicy == QScrollerProperties::OvershootAlwaysOn)
| 0 | ||||||||||||||||||
1573 | canScrollX = true; never executed: canScrollX = true; | 0 | ||||||||||||||||||
1574 | if (sp->vOvershootPolicy == QScrollerProperties::OvershootAlwaysOn)
| 0 | ||||||||||||||||||
1575 | canScrollY = true; never executed: canScrollY = true; | 0 | ||||||||||||||||||
1576 | - | |||||||||||||||||||
1577 | if (qAbs(deltaPixel.x() / ppm.x()) < qAbs(deltaPixel.y() / ppm.y())) {
| 0 | ||||||||||||||||||
1578 | if (!canScrollY)
| 0 | ||||||||||||||||||
1579 | moveAborted = true; never executed: moveAborted = true; | 0 | ||||||||||||||||||
1580 | } else { never executed: end of block | 0 | ||||||||||||||||||
1581 | if (!canScrollX)
| 0 | ||||||||||||||||||
1582 | moveAborted = true; never executed: moveAborted = true; | 0 | ||||||||||||||||||
1583 | } never executed: end of block | 0 | ||||||||||||||||||
1584 | } | - | ||||||||||||||||||
1585 | - | |||||||||||||||||||
1586 | if (moveAborted) {
| 0 | ||||||||||||||||||
1587 | setState(QScroller::Inactive); | - | ||||||||||||||||||
1588 | moveStarted = false; | - | ||||||||||||||||||
1589 | - | |||||||||||||||||||
1590 | } else if (moveStarted) { never executed: end of block
| 0 | ||||||||||||||||||
1591 | setState(QScroller::Dragging); | - | ||||||||||||||||||
1592 | - | |||||||||||||||||||
1593 | // subtract the dragStartDistance | - | ||||||||||||||||||
1594 | deltaPixel = deltaPixel - deltaPixel * (sp->dragStartDistance / deltaPixel.manhattanLength()); | - | ||||||||||||||||||
1595 | - | |||||||||||||||||||
1596 | if (deltaPixel != QPointF(0, 0)) {
| 0 | ||||||||||||||||||
1597 | // handleDrag updates lastPosition, lastTimestamp and velocity | - | ||||||||||||||||||
1598 | handleDrag(pressPosition + deltaPixel, timestamp); | - | ||||||||||||||||||
1599 | } never executed: end of block | 0 | ||||||||||||||||||
1600 | } never executed: end of block | 0 | ||||||||||||||||||
1601 | return moveStarted; never executed: return moveStarted; | 0 | ||||||||||||||||||
1602 | } | - | ||||||||||||||||||
1603 | - | |||||||||||||||||||
1604 | bool QScrollerPrivate::moveWhileDragging(const QPointF &position, qint64 timestamp) | - | ||||||||||||||||||
1605 | { | - | ||||||||||||||||||
1606 | // handleDrag updates lastPosition, lastTimestamp and velocity | - | ||||||||||||||||||
1607 | handleDrag(position, timestamp); | - | ||||||||||||||||||
1608 | return true; never executed: return true; | 0 | ||||||||||||||||||
1609 | } | - | ||||||||||||||||||
1610 | - | |||||||||||||||||||
1611 | void QScrollerPrivate::timerEventWhileDragging() | - | ||||||||||||||||||
1612 | { | - | ||||||||||||||||||
1613 | if (dragDistance != QPointF(0, 0)) {
| 0 | ||||||||||||||||||
1614 | qScrollerDebug() << "QScroller::timerEventWhileDragging() -- dragDistance:" << dragDistance; dead code: QMessageLogger(__FILE__, 1614, __PRETTY_FUNCTION__).debug() << "QScroller::timerEventWhileDragging() -- dragDistance:" << dragDistance; | - | ||||||||||||||||||
1615 | - | |||||||||||||||||||
1616 | setContentPositionHelperDragging(-dragDistance); | - | ||||||||||||||||||
1617 | dragDistance = QPointF(0, 0); | - | ||||||||||||||||||
1618 | } never executed: end of block | 0 | ||||||||||||||||||
1619 | } never executed: end of block | 0 | ||||||||||||||||||
1620 | - | |||||||||||||||||||
1621 | bool QScrollerPrivate::releaseWhileDragging(const QPointF &position, qint64 timestamp) | - | ||||||||||||||||||
1622 | { | - | ||||||||||||||||||
1623 | Q_Q(QScroller); | - | ||||||||||||||||||
1624 | const QScrollerPropertiesPrivate *sp = properties.d.data(); | - | ||||||||||||||||||
1625 | - | |||||||||||||||||||
1626 | // handleDrag updates lastPosition, lastTimestamp and velocity | - | ||||||||||||||||||
1627 | handleDrag(position, timestamp); | - | ||||||||||||||||||
1628 | - | |||||||||||||||||||
1629 | // check if we moved at all - this can happen if you stop a running | - | ||||||||||||||||||
1630 | // scroller with a press and release shortly afterwards | - | ||||||||||||||||||
1631 | QPointF deltaPixel = position - pressPosition; | - | ||||||||||||||||||
1632 | if (((deltaPixel / q->pixelPerMeter()).manhattanLength()) > sp->dragStartDistance) {
| 0 | ||||||||||||||||||
1633 | - | |||||||||||||||||||
1634 | // handle accelerating flicks | - | ||||||||||||||||||
1635 | if ((oldVelocity != QPointF(0, 0)) && sp->acceleratingFlickMaximumTime &&
| 0 | ||||||||||||||||||
1636 | ((timestamp - pressTimestamp) < qint64(sp->acceleratingFlickMaximumTime * 1000))) {
| 0 | ||||||||||||||||||
1637 | - | |||||||||||||||||||
1638 | // - determine if the direction was changed | - | ||||||||||||||||||
1639 | int signX = 0, signY = 0; | - | ||||||||||||||||||
1640 | if (releaseVelocity.x())
| 0 | ||||||||||||||||||
1641 | signX = (releaseVelocity.x() > 0) == (oldVelocity.x() > 0) ? 1 : -1; never executed: signX = (releaseVelocity.x() > 0) == (oldVelocity.x() > 0) ? 1 : -1;
| 0 | ||||||||||||||||||
1642 | if (releaseVelocity.y())
| 0 | ||||||||||||||||||
1643 | signY = (releaseVelocity.y() > 0) == (oldVelocity.y() > 0) ? 1 : -1; never executed: signY = (releaseVelocity.y() > 0) == (oldVelocity.y() > 0) ? 1 : -1;
| 0 | ||||||||||||||||||
1644 | - | |||||||||||||||||||
1645 | if (signX > 0)
| 0 | ||||||||||||||||||
1646 | releaseVelocity.setX(qBound(-sp->maximumVelocity, never executed: releaseVelocity.setX(qBound(-sp->maximumVelocity, oldVelocity.x() * sp->acceleratingFlickSpeedupFactor, sp->maximumVelocity)); | 0 | ||||||||||||||||||
1647 | oldVelocity.x() * sp->acceleratingFlickSpeedupFactor, never executed: releaseVelocity.setX(qBound(-sp->maximumVelocity, oldVelocity.x() * sp->acceleratingFlickSpeedupFactor, sp->maximumVelocity)); | 0 | ||||||||||||||||||
1648 | sp->maximumVelocity)); never executed: releaseVelocity.setX(qBound(-sp->maximumVelocity, oldVelocity.x() * sp->acceleratingFlickSpeedupFactor, sp->maximumVelocity)); | 0 | ||||||||||||||||||
1649 | if (signY > 0)
| 0 | ||||||||||||||||||
1650 | releaseVelocity.setY(qBound(-sp->maximumVelocity, never executed: releaseVelocity.setY(qBound(-sp->maximumVelocity, oldVelocity.y() * sp->acceleratingFlickSpeedupFactor, sp->maximumVelocity)); | 0 | ||||||||||||||||||
1651 | oldVelocity.y() * sp->acceleratingFlickSpeedupFactor, never executed: releaseVelocity.setY(qBound(-sp->maximumVelocity, oldVelocity.y() * sp->acceleratingFlickSpeedupFactor, sp->maximumVelocity)); | 0 | ||||||||||||||||||
1652 | sp->maximumVelocity)); never executed: releaseVelocity.setY(qBound(-sp->maximumVelocity, oldVelocity.y() * sp->acceleratingFlickSpeedupFactor, sp->maximumVelocity)); | 0 | ||||||||||||||||||
1653 | } never executed: end of block | 0 | ||||||||||||||||||
1654 | } never executed: end of block | 0 | ||||||||||||||||||
1655 | - | |||||||||||||||||||
1656 | QPointF ppm = q->pixelPerMeter(); | - | ||||||||||||||||||
1657 | createScrollingSegments(releaseVelocity, contentPosition + overshootPosition, ppm); | - | ||||||||||||||||||
1658 | - | |||||||||||||||||||
1659 | qScrollerDebug() << "QScroller::releaseWhileDragging() -- velocity:" << releaseVelocity << "-- minimum velocity:" << sp->minimumVelocity << "overshoot" << overshootPosition; dead code: QMessageLogger(__FILE__, 1659, __PRETTY_FUNCTION__).debug() << "QScroller::releaseWhileDragging() -- velocity:" << releaseVelocity << "-- minimum velocity:" << sp->minimumVelocity << "overshoot" << overshootPosition; | - | ||||||||||||||||||
1660 | - | |||||||||||||||||||
1661 | if (xSegments.isEmpty() && ySegments.isEmpty())
| 0 | ||||||||||||||||||
1662 | setState(QScroller::Inactive); never executed: setState(QScroller::Inactive); | 0 | ||||||||||||||||||
1663 | else | - | ||||||||||||||||||
1664 | setState(QScroller::Scrolling); never executed: setState(QScroller::Scrolling); | 0 | ||||||||||||||||||
1665 | - | |||||||||||||||||||
1666 | return true; never executed: return true; | 0 | ||||||||||||||||||
1667 | } | - | ||||||||||||||||||
1668 | - | |||||||||||||||||||
1669 | void QScrollerPrivate::timerEventWhileScrolling() | - | ||||||||||||||||||
1670 | { | - | ||||||||||||||||||
1671 | qScrollerDebug("QScroller::timerEventWhileScrolling()"); dead code: QMessageLogger(__FILE__, 1671, __PRETTY_FUNCTION__).debug("QScroller::timerEventWhileScrolling()"); | - | ||||||||||||||||||
1672 | - | |||||||||||||||||||
1673 | setContentPositionHelperScrolling(); | - | ||||||||||||||||||
1674 | if (xSegments.isEmpty() && ySegments.isEmpty())
| 0 | ||||||||||||||||||
1675 | setState(QScroller::Inactive); never executed: setState(QScroller::Inactive); | 0 | ||||||||||||||||||
1676 | } never executed: end of block | 0 | ||||||||||||||||||
1677 | - | |||||||||||||||||||
1678 | bool QScrollerPrivate::pressWhileScrolling(const QPointF &position, qint64 timestamp) | - | ||||||||||||||||||
1679 | { | - | ||||||||||||||||||
1680 | Q_Q(QScroller); | - | ||||||||||||||||||
1681 | - | |||||||||||||||||||
1682 | if ((q->velocity() <= properties.d->maximumClickThroughVelocity) &&
| 0 | ||||||||||||||||||
1683 | (overshootPosition == QPointF(0.0, 0.0))) {
| 0 | ||||||||||||||||||
1684 | setState(QScroller::Inactive); | - | ||||||||||||||||||
1685 | return false; never executed: return false; | 0 | ||||||||||||||||||
1686 | } else { | - | ||||||||||||||||||
1687 | lastPosition = pressPosition = position; | - | ||||||||||||||||||
1688 | lastTimestamp = pressTimestamp = timestamp; | - | ||||||||||||||||||
1689 | setState(QScroller::Pressed); | - | ||||||||||||||||||
1690 | setState(QScroller::Dragging); | - | ||||||||||||||||||
1691 | return true; never executed: return true; | 0 | ||||||||||||||||||
1692 | } | - | ||||||||||||||||||
1693 | } | - | ||||||||||||||||||
1694 | - | |||||||||||||||||||
1695 | /*! \internal | - | ||||||||||||||||||
1696 | This function handles all state changes of the scroller. | - | ||||||||||||||||||
1697 | */ | - | ||||||||||||||||||
1698 | void QScrollerPrivate::setState(QScroller::State newstate) | - | ||||||||||||||||||
1699 | { | - | ||||||||||||||||||
1700 | Q_Q(QScroller); | - | ||||||||||||||||||
1701 | bool sendLastScroll = false; | - | ||||||||||||||||||
1702 | - | |||||||||||||||||||
1703 | if (state == newstate)
| 0 | ||||||||||||||||||
1704 | return; never executed: return; | 0 | ||||||||||||||||||
1705 | - | |||||||||||||||||||
1706 | qScrollerDebug() << q << "QScroller::setState(" << stateName(newstate) << ')'; dead code: QMessageLogger(__FILE__, 1706, __PRETTY_FUNCTION__).debug() << q << "QScroller::setState(" << stateName(newstate) << ')'; | - | ||||||||||||||||||
1707 | - | |||||||||||||||||||
1708 | switch (newstate) { | - | ||||||||||||||||||
1709 | case QScroller::Inactive: never executed: case QScroller::Inactive: | 0 | ||||||||||||||||||
1710 | #ifndef QT_NO_ANIMATION | - | ||||||||||||||||||
1711 | scrollTimer->stop(); | - | ||||||||||||||||||
1712 | #endif | - | ||||||||||||||||||
1713 | - | |||||||||||||||||||
1714 | // send the last scroll event (but only after the current state change was finished) | - | ||||||||||||||||||
1715 | if (!firstScroll)
| 0 | ||||||||||||||||||
1716 | sendLastScroll = true; never executed: sendLastScroll = true; | 0 | ||||||||||||||||||
1717 | - | |||||||||||||||||||
1718 | releaseVelocity = QPointF(0, 0); | - | ||||||||||||||||||
1719 | break; never executed: break; | 0 | ||||||||||||||||||
1720 | - | |||||||||||||||||||
1721 | case QScroller::Pressed: never executed: case QScroller::Pressed: | 0 | ||||||||||||||||||
1722 | #ifndef QT_NO_ANIMATION | - | ||||||||||||||||||
1723 | scrollTimer->stop(); | - | ||||||||||||||||||
1724 | #endif | - | ||||||||||||||||||
1725 | - | |||||||||||||||||||
1726 | oldVelocity = releaseVelocity; | - | ||||||||||||||||||
1727 | releaseVelocity = QPointF(0, 0); | - | ||||||||||||||||||
1728 | break; never executed: break; | 0 | ||||||||||||||||||
1729 | - | |||||||||||||||||||
1730 | case QScroller::Dragging: never executed: case QScroller::Dragging: | 0 | ||||||||||||||||||
1731 | dragDistance = QPointF(0, 0); | - | ||||||||||||||||||
1732 | #ifndef QT_NO_ANIMATION | - | ||||||||||||||||||
1733 | if (state == QScroller::Pressed)
| 0 | ||||||||||||||||||
1734 | scrollTimer->start(); never executed: scrollTimer->start(); | 0 | ||||||||||||||||||
1735 | #endif | - | ||||||||||||||||||
1736 | break; never executed: break; | 0 | ||||||||||||||||||
1737 | - | |||||||||||||||||||
1738 | case QScroller::Scrolling: never executed: case QScroller::Scrolling: | 0 | ||||||||||||||||||
1739 | #ifndef QT_NO_ANIMATION | - | ||||||||||||||||||
1740 | scrollTimer->start(); | - | ||||||||||||||||||
1741 | #endif | - | ||||||||||||||||||
1742 | break; never executed: break; | 0 | ||||||||||||||||||
1743 | } | - | ||||||||||||||||||
1744 | - | |||||||||||||||||||
1745 | qSwap(state, newstate); | - | ||||||||||||||||||
1746 | - | |||||||||||||||||||
1747 | if (sendLastScroll) {
| 0 | ||||||||||||||||||
1748 | QScrollEvent se(contentPosition, overshootPosition, QScrollEvent::ScrollFinished); | - | ||||||||||||||||||
1749 | sendEvent(target, &se); | - | ||||||||||||||||||
1750 | firstScroll = true; | - | ||||||||||||||||||
1751 | } never executed: end of block | 0 | ||||||||||||||||||
1752 | if (state == QScroller::Dragging || state == QScroller::Scrolling)
| 0 | ||||||||||||||||||
1753 | qt_activeScrollers()->insert(q); never executed: qt_activeScrollers()->insert(q); | 0 | ||||||||||||||||||
1754 | else | - | ||||||||||||||||||
1755 | qt_activeScrollers()->remove(q); never executed: qt_activeScrollers()->remove(q); | 0 | ||||||||||||||||||
1756 | emit q->stateChanged(state); | - | ||||||||||||||||||
1757 | } never executed: end of block | 0 | ||||||||||||||||||
1758 | - | |||||||||||||||||||
1759 | - | |||||||||||||||||||
1760 | /*! \internal | - | ||||||||||||||||||
1761 | Helps when setting the content position. | - | ||||||||||||||||||
1762 | It will try to move the content by the requested delta but stop in case | - | ||||||||||||||||||
1763 | when we are coming back from an overshoot or a scrollTo. | - | ||||||||||||||||||
1764 | It will also indicate a new overshooting condition by the overshootX and oversthootY flags. | - | ||||||||||||||||||
1765 | - | |||||||||||||||||||
1766 | In this cases it will reset the velocity variables and other flags. | - | ||||||||||||||||||
1767 | - | |||||||||||||||||||
1768 | Also keeps track of the current over-shooting value in overshootPosition. | - | ||||||||||||||||||
1769 | - | |||||||||||||||||||
1770 | \a deltaPos is the amount of pixels the current content position should be moved | - | ||||||||||||||||||
1771 | */ | - | ||||||||||||||||||
1772 | void QScrollerPrivate::setContentPositionHelperDragging(const QPointF &deltaPos) | - | ||||||||||||||||||
1773 | { | - | ||||||||||||||||||
1774 | const QScrollerPropertiesPrivate *sp = properties.d.data(); | - | ||||||||||||||||||
1775 | - | |||||||||||||||||||
1776 | if (sp->overshootDragResistanceFactor)
| 0 | ||||||||||||||||||
1777 | overshootPosition /= sp->overshootDragResistanceFactor; never executed: overshootPosition /= sp->overshootDragResistanceFactor; | 0 | ||||||||||||||||||
1778 | - | |||||||||||||||||||
1779 | QPointF oldPos = contentPosition + overshootPosition; | - | ||||||||||||||||||
1780 | QPointF newPos = oldPos + deltaPos; | - | ||||||||||||||||||
1781 | - | |||||||||||||||||||
1782 | qScrollerDebug() << "QScroller::setContentPositionHelperDragging(" << deltaPos << " [pix])"; dead code: QMessageLogger(__FILE__, 1782, __PRETTY_FUNCTION__).debug() << "QScroller::setContentPositionHelperDragging(" << deltaPos << " [pix])"; | - | ||||||||||||||||||
1783 | qScrollerDebug() << " --> overshoot:" << overshootPosition << "- old pos:" << oldPos << "- new pos:" << newPos; dead code: QMessageLogger(__FILE__, 1783, __PRETTY_FUNCTION__).debug() << " --> overshoot:" << overshootPosition << "- old pos:" << oldPos << "- new pos:" << newPos; | - | ||||||||||||||||||
1784 | - | |||||||||||||||||||
1785 | QPointF oldClampedPos = clampToRect(oldPos, contentPosRange); | - | ||||||||||||||||||
1786 | QPointF newClampedPos = clampToRect(newPos, contentPosRange); | - | ||||||||||||||||||
1787 | - | |||||||||||||||||||
1788 | // --- handle overshooting and stop if the coordinate is going back inside the normal area | - | ||||||||||||||||||
1789 | bool alwaysOvershootX = (sp->hOvershootPolicy == QScrollerProperties::OvershootAlwaysOn); | - | ||||||||||||||||||
1790 | bool alwaysOvershootY = (sp->vOvershootPolicy == QScrollerProperties::OvershootAlwaysOn); | - | ||||||||||||||||||
1791 | bool noOvershootX = (sp->hOvershootPolicy == QScrollerProperties::OvershootAlwaysOff) ||
| 0 | ||||||||||||||||||
1792 | ((state == QScroller::Dragging) && !sp->overshootDragResistanceFactor) ||
| 0 | ||||||||||||||||||
1793 | !sp->overshootDragDistanceFactor;
| 0 | ||||||||||||||||||
1794 | bool noOvershootY = (sp->vOvershootPolicy == QScrollerProperties::OvershootAlwaysOff) ||
| 0 | ||||||||||||||||||
1795 | ((state == QScroller::Dragging) && !sp->overshootDragResistanceFactor) ||
| 0 | ||||||||||||||||||
1796 | !sp->overshootDragDistanceFactor;
| 0 | ||||||||||||||||||
1797 | bool canOvershootX = !noOvershootX && (alwaysOvershootX || contentPosRange.width());
| 0 | ||||||||||||||||||
1798 | bool canOvershootY = !noOvershootY && (alwaysOvershootY || contentPosRange.height());
| 0 | ||||||||||||||||||
1799 | - | |||||||||||||||||||
1800 | qreal oldOvershootX = (canOvershootX) ? oldPos.x() - oldClampedPos.x() : 0;
| 0 | ||||||||||||||||||
1801 | qreal oldOvershootY = (canOvershootY) ? oldPos.y() - oldClampedPos.y() : 0;
| 0 | ||||||||||||||||||
1802 | - | |||||||||||||||||||
1803 | qreal newOvershootX = (canOvershootX) ? newPos.x() - newClampedPos.x() : 0;
| 0 | ||||||||||||||||||
1804 | qreal newOvershootY = (canOvershootY) ? newPos.y() - newClampedPos.y() : 0;
| 0 | ||||||||||||||||||
1805 | - | |||||||||||||||||||
1806 | qreal maxOvershootX = viewportSize.width() * sp->overshootDragDistanceFactor; | - | ||||||||||||||||||
1807 | qreal maxOvershootY = viewportSize.height() * sp->overshootDragDistanceFactor; | - | ||||||||||||||||||
1808 | - | |||||||||||||||||||
1809 | qScrollerDebug() << " --> noOs:" << noOvershootX << "drf:" << sp->overshootDragResistanceFactor << "mdf:" << sp->overshootScrollDistanceFactor << "ossP:"<<sp->hOvershootPolicy; dead code: QMessageLogger(__FILE__, 1809, __PRETTY_FUNCTION__).debug() << " --> noOs:" << noOvershootX << "drf:" << sp->overshootDragResistanceFactor << "mdf:" << sp->overshootScrollDistanceFactor << "ossP:"<<sp->hOvershootPolicy; | - | ||||||||||||||||||
1810 | qScrollerDebug() << " --> canOS:" << canOvershootX << "newOS:" << newOvershootX << "maxOS:" << maxOvershootX; dead code: QMessageLogger(__FILE__, 1810, __PRETTY_FUNCTION__).debug() << " --> canOS:" << canOvershootX << "newOS:" << newOvershootX << "maxOS:" << maxOvershootX; | - | ||||||||||||||||||
1811 | - | |||||||||||||||||||
1812 | if (sp->overshootDragResistanceFactor) {
| 0 | ||||||||||||||||||
1813 | oldOvershootX *= sp->overshootDragResistanceFactor; | - | ||||||||||||||||||
1814 | oldOvershootY *= sp->overshootDragResistanceFactor; | - | ||||||||||||||||||
1815 | newOvershootX *= sp->overshootDragResistanceFactor; | - | ||||||||||||||||||
1816 | newOvershootY *= sp->overshootDragResistanceFactor; | - | ||||||||||||||||||
1817 | } never executed: end of block | 0 | ||||||||||||||||||
1818 | - | |||||||||||||||||||
1819 | // -- stop at the maximum overshoot distance | - | ||||||||||||||||||
1820 | - | |||||||||||||||||||
1821 | newOvershootX = qBound(-maxOvershootX, newOvershootX, maxOvershootX); | - | ||||||||||||||||||
1822 | newOvershootY = qBound(-maxOvershootY, newOvershootY, maxOvershootY); | - | ||||||||||||||||||
1823 | - | |||||||||||||||||||
1824 | overshootPosition.setX(newOvershootX); | - | ||||||||||||||||||
1825 | overshootPosition.setY(newOvershootY); | - | ||||||||||||||||||
1826 | contentPosition = newClampedPos; | - | ||||||||||||||||||
1827 | - | |||||||||||||||||||
1828 | QScrollEvent se(contentPosition, overshootPosition, firstScroll ? QScrollEvent::ScrollStarted : QScrollEvent::ScrollUpdated); | - | ||||||||||||||||||
1829 | sendEvent(target, &se); | - | ||||||||||||||||||
1830 | firstScroll = false; | - | ||||||||||||||||||
1831 | - | |||||||||||||||||||
1832 | qScrollerDebug() << " --> new position:" << newClampedPos << "- new overshoot:" << overshootPosition << dead code: QMessageLogger(__FILE__, 1832, __PRETTY_FUNCTION__).debug() << " --> new position:" << newClampedPos << "- new overshoot:" << overshootPosition << "- overshoot x/y?:" << overshootPosition; | - | ||||||||||||||||||
1833 | "- overshoot x/y?:" << overshootPosition; dead code: QMessageLogger(__FILE__, 1832, __PRETTY_FUNCTION__).debug() << " --> new position:" << newClampedPos << "- new overshoot:" << overshootPosition << "- overshoot x/y?:" << overshootPosition; | - | ||||||||||||||||||
1834 | } never executed: end of block | 0 | ||||||||||||||||||
1835 | - | |||||||||||||||||||
1836 | - | |||||||||||||||||||
1837 | qreal QScrollerPrivate::nextSegmentPosition(QQueue<ScrollSegment> &segments, qint64 now, qreal oldPos) | - | ||||||||||||||||||
1838 | { | - | ||||||||||||||||||
1839 | qreal pos = oldPos; | - | ||||||||||||||||||
1840 | - | |||||||||||||||||||
1841 | // check the X segments for new positions | - | ||||||||||||||||||
1842 | while (!segments.isEmpty()) {
| 0 | ||||||||||||||||||
1843 | const ScrollSegment s = segments.head(); | - | ||||||||||||||||||
1844 | - | |||||||||||||||||||
1845 | if ((s.startTime + s.deltaTime * s.stopProgress) <= now) {
| 0 | ||||||||||||||||||
1846 | segments.dequeue(); | - | ||||||||||||||||||
1847 | pos = s.stopPos; | - | ||||||||||||||||||
1848 | } else if (s.startTime <= now) { never executed: end of block
| 0 | ||||||||||||||||||
1849 | qreal progress = qreal(now - s.startTime) / qreal(s.deltaTime); | - | ||||||||||||||||||
1850 | pos = s.startPos + s.deltaPos * s.curve.valueForProgress(progress); | - | ||||||||||||||||||
1851 | if (s.deltaPos > 0 ? pos > s.stopPos : pos < s.stopPos) {
| 0 | ||||||||||||||||||
1852 | segments.dequeue(); | - | ||||||||||||||||||
1853 | pos = s.stopPos; | - | ||||||||||||||||||
1854 | } else { never executed: end of block | 0 | ||||||||||||||||||
1855 | break; never executed: break; | 0 | ||||||||||||||||||
1856 | } | - | ||||||||||||||||||
1857 | } else { | - | ||||||||||||||||||
1858 | break; never executed: break; | 0 | ||||||||||||||||||
1859 | } | - | ||||||||||||||||||
1860 | } | - | ||||||||||||||||||
1861 | return pos; never executed: return pos; | 0 | ||||||||||||||||||
1862 | } | - | ||||||||||||||||||
1863 | - | |||||||||||||||||||
1864 | void QScrollerPrivate::setContentPositionHelperScrolling() | - | ||||||||||||||||||
1865 | { | - | ||||||||||||||||||
1866 | qint64 now = monotonicTimer.elapsed(); | - | ||||||||||||||||||
1867 | QPointF newPos = contentPosition + overshootPosition; | - | ||||||||||||||||||
1868 | - | |||||||||||||||||||
1869 | newPos.setX(nextSegmentPosition(xSegments, now, newPos.x())); | - | ||||||||||||||||||
1870 | newPos.setY(nextSegmentPosition(ySegments, now, newPos.y())); | - | ||||||||||||||||||
1871 | - | |||||||||||||||||||
1872 | // -- set the position and handle overshoot | - | ||||||||||||||||||
1873 | qScrollerDebug() << "QScroller::setContentPositionHelperScrolling()\n" dead code: QMessageLogger(__FILE__, 1873, __PRETTY_FUNCTION__).debug() << "QScroller::setContentPositionHelperScrolling()\n" " --> overshoot:" << overshootPosition << "- new pos:" << newPos; | - | ||||||||||||||||||
1874 | " --> overshoot:" << overshootPosition << "- new pos:" << newPos; dead code: QMessageLogger(__FILE__, 1873, __PRETTY_FUNCTION__).debug() << "QScroller::setContentPositionHelperScrolling()\n" " --> overshoot:" << overshootPosition << "- new pos:" << newPos; | - | ||||||||||||||||||
1875 | - | |||||||||||||||||||
1876 | QPointF newClampedPos = clampToRect(newPos, contentPosRange); | - | ||||||||||||||||||
1877 | - | |||||||||||||||||||
1878 | overshootPosition = newPos - newClampedPos; | - | ||||||||||||||||||
1879 | contentPosition = newClampedPos; | - | ||||||||||||||||||
1880 | - | |||||||||||||||||||
1881 | QScrollEvent se(contentPosition, overshootPosition, firstScroll ? QScrollEvent::ScrollStarted : QScrollEvent::ScrollUpdated); | - | ||||||||||||||||||
1882 | sendEvent(target, &se); | - | ||||||||||||||||||
1883 | firstScroll = false; | - | ||||||||||||||||||
1884 | - | |||||||||||||||||||
1885 | qScrollerDebug() << " --> new position:" << newClampedPos << "- new overshoot:" << overshootPosition; dead code: QMessageLogger(__FILE__, 1885, __PRETTY_FUNCTION__).debug() << " --> new position:" << newClampedPos << "- new overshoot:" << overshootPosition; | - | ||||||||||||||||||
1886 | } never executed: end of block | 0 | ||||||||||||||||||
1887 | - | |||||||||||||||||||
1888 | /*! \internal | - | ||||||||||||||||||
1889 | Returns the next snap point in direction. | - | ||||||||||||||||||
1890 | If \a direction >0 it will return the next snap point that is larger than the current position. | - | ||||||||||||||||||
1891 | If \a direction <0 it will return the next snap point that is smaller than the current position. | - | ||||||||||||||||||
1892 | If \a direction ==0 it will return the nearest snap point (or the current position if we are already | - | ||||||||||||||||||
1893 | on a snap point. | - | ||||||||||||||||||
1894 | Returns the nearest snap position or NaN if no such point could be found. | - | ||||||||||||||||||
1895 | */ | - | ||||||||||||||||||
1896 | qreal QScrollerPrivate::nextSnapPos(qreal p, int dir, Qt::Orientation orientation) | - | ||||||||||||||||||
1897 | { | - | ||||||||||||||||||
1898 | qreal bestSnapPos = Q_QNAN; | - | ||||||||||||||||||
1899 | qreal bestSnapPosDist = Q_INFINITY; | - | ||||||||||||||||||
1900 | - | |||||||||||||||||||
1901 | qreal minPos; | - | ||||||||||||||||||
1902 | qreal maxPos; | - | ||||||||||||||||||
1903 | - | |||||||||||||||||||
1904 | if (orientation == Qt::Horizontal) {
| 0 | ||||||||||||||||||
1905 | minPos = contentPosRange.left(); | - | ||||||||||||||||||
1906 | maxPos = contentPosRange.right(); | - | ||||||||||||||||||
1907 | } else { never executed: end of block | 0 | ||||||||||||||||||
1908 | minPos = contentPosRange.top(); | - | ||||||||||||||||||
1909 | maxPos = contentPosRange.bottom(); | - | ||||||||||||||||||
1910 | } never executed: end of block | 0 | ||||||||||||||||||
1911 | - | |||||||||||||||||||
1912 | if (orientation == Qt::Horizontal) {
| 0 | ||||||||||||||||||
1913 | // the snap points in the list | - | ||||||||||||||||||
1914 | foreach (qreal snapPos, snapPositionsX) { | - | ||||||||||||||||||
1915 | qreal snapPosDist = snapPos - p; | - | ||||||||||||||||||
1916 | if ((dir > 0 && snapPosDist < 0) ||
| 0 | ||||||||||||||||||
1917 | (dir < 0 && snapPosDist > 0))
| 0 | ||||||||||||||||||
1918 | continue; // wrong direction never executed: continue; | 0 | ||||||||||||||||||
1919 | if (snapPos < minPos || snapPos > maxPos )
| 0 | ||||||||||||||||||
1920 | continue; // invalid never executed: continue; | 0 | ||||||||||||||||||
1921 | - | |||||||||||||||||||
1922 | if (qIsNaN(bestSnapPos) ||
| 0 | ||||||||||||||||||
1923 | qAbs(snapPosDist) < bestSnapPosDist ) {
| 0 | ||||||||||||||||||
1924 | bestSnapPos = snapPos; | - | ||||||||||||||||||
1925 | bestSnapPosDist = qAbs(snapPosDist); | - | ||||||||||||||||||
1926 | } never executed: end of block | 0 | ||||||||||||||||||
1927 | } never executed: end of block | 0 | ||||||||||||||||||
1928 | - | |||||||||||||||||||
1929 | // the snap point interval | - | ||||||||||||||||||
1930 | if (snapIntervalX > 0.0) {
| 0 | ||||||||||||||||||
1931 | qreal first = minPos + snapFirstX; | - | ||||||||||||||||||
1932 | qreal snapPos; | - | ||||||||||||||||||
1933 | if (dir > 0)
| 0 | ||||||||||||||||||
1934 | snapPos = qCeil((p - first) / snapIntervalX) * snapIntervalX + first; never executed: snapPos = qCeil((p - first) / snapIntervalX) * snapIntervalX + first; | 0 | ||||||||||||||||||
1935 | else if (dir < 0)
| 0 | ||||||||||||||||||
1936 | snapPos = qFloor((p - first) / snapIntervalX) * snapIntervalX + first; never executed: snapPos = qFloor((p - first) / snapIntervalX) * snapIntervalX + first; | 0 | ||||||||||||||||||
1937 | else if (p <= first)
| 0 | ||||||||||||||||||
1938 | snapPos = first; never executed: snapPos = first; | 0 | ||||||||||||||||||
1939 | else | - | ||||||||||||||||||
1940 | { | - | ||||||||||||||||||
1941 | qreal last = qFloor((maxPos - first) / snapIntervalX) * snapIntervalX + first; | - | ||||||||||||||||||
1942 | if (p >= last)
| 0 | ||||||||||||||||||
1943 | snapPos = last; never executed: snapPos = last; | 0 | ||||||||||||||||||
1944 | else | - | ||||||||||||||||||
1945 | snapPos = qRound((p - first) / snapIntervalX) * snapIntervalX + first; never executed: snapPos = qRound((p - first) / snapIntervalX) * snapIntervalX + first; | 0 | ||||||||||||||||||
1946 | } | - | ||||||||||||||||||
1947 | - | |||||||||||||||||||
1948 | if (snapPos >= first && snapPos <= maxPos ) {
| 0 | ||||||||||||||||||
1949 | qreal snapPosDist = snapPos - p; | - | ||||||||||||||||||
1950 | - | |||||||||||||||||||
1951 | if (qIsNaN(bestSnapPos) ||
| 0 | ||||||||||||||||||
1952 | qAbs(snapPosDist) < bestSnapPosDist ) {
| 0 | ||||||||||||||||||
1953 | bestSnapPos = snapPos; | - | ||||||||||||||||||
1954 | bestSnapPosDist = qAbs(snapPosDist); | - | ||||||||||||||||||
1955 | } never executed: end of block | 0 | ||||||||||||||||||
1956 | } never executed: end of block | 0 | ||||||||||||||||||
1957 | } never executed: end of block | 0 | ||||||||||||||||||
1958 | - | |||||||||||||||||||
1959 | } else { // (orientation == Qt::Vertical) never executed: end of block | 0 | ||||||||||||||||||
1960 | // the snap points in the list | - | ||||||||||||||||||
1961 | foreach (qreal snapPos, snapPositionsY) { | - | ||||||||||||||||||
1962 | qreal snapPosDist = snapPos - p; | - | ||||||||||||||||||
1963 | if ((dir > 0 && snapPosDist < 0) ||
| 0 | ||||||||||||||||||
1964 | (dir < 0 && snapPosDist > 0))
| 0 | ||||||||||||||||||
1965 | continue; // wrong direction never executed: continue; | 0 | ||||||||||||||||||
1966 | if (snapPos < minPos || snapPos > maxPos )
| 0 | ||||||||||||||||||
1967 | continue; // invalid never executed: continue; | 0 | ||||||||||||||||||
1968 | - | |||||||||||||||||||
1969 | if (qIsNaN(bestSnapPos) ||
| 0 | ||||||||||||||||||
1970 | qAbs(snapPosDist) < bestSnapPosDist) {
| 0 | ||||||||||||||||||
1971 | bestSnapPos = snapPos; | - | ||||||||||||||||||
1972 | bestSnapPosDist = qAbs(snapPosDist); | - | ||||||||||||||||||
1973 | } never executed: end of block | 0 | ||||||||||||||||||
1974 | } never executed: end of block | 0 | ||||||||||||||||||
1975 | - | |||||||||||||||||||
1976 | // the snap point interval | - | ||||||||||||||||||
1977 | if (snapIntervalY > 0.0) {
| 0 | ||||||||||||||||||
1978 | qreal first = minPos + snapFirstY; | - | ||||||||||||||||||
1979 | qreal snapPos; | - | ||||||||||||||||||
1980 | if (dir > 0)
| 0 | ||||||||||||||||||
1981 | snapPos = qCeil((p - first) / snapIntervalY) * snapIntervalY + first; never executed: snapPos = qCeil((p - first) / snapIntervalY) * snapIntervalY + first; | 0 | ||||||||||||||||||
1982 | else if (dir < 0)
| 0 | ||||||||||||||||||
1983 | snapPos = qFloor((p - first) / snapIntervalY) * snapIntervalY + first; never executed: snapPos = qFloor((p - first) / snapIntervalY) * snapIntervalY + first; | 0 | ||||||||||||||||||
1984 | else if (p <= first)
| 0 | ||||||||||||||||||
1985 | snapPos = first; never executed: snapPos = first; | 0 | ||||||||||||||||||
1986 | else | - | ||||||||||||||||||
1987 | { | - | ||||||||||||||||||
1988 | qreal last = qFloor((maxPos - first) / snapIntervalY) * snapIntervalY + first; | - | ||||||||||||||||||
1989 | if (p >= last)
| 0 | ||||||||||||||||||
1990 | snapPos = last; never executed: snapPos = last; | 0 | ||||||||||||||||||
1991 | else | - | ||||||||||||||||||
1992 | snapPos = qRound((p - first) / snapIntervalY) * snapIntervalY + first; never executed: snapPos = qRound((p - first) / snapIntervalY) * snapIntervalY + first; | 0 | ||||||||||||||||||
1993 | } | - | ||||||||||||||||||
1994 | - | |||||||||||||||||||
1995 | if (snapPos >= first && snapPos <= maxPos ) {
| 0 | ||||||||||||||||||
1996 | qreal snapPosDist = snapPos - p; | - | ||||||||||||||||||
1997 | - | |||||||||||||||||||
1998 | if (qIsNaN(bestSnapPos) ||
| 0 | ||||||||||||||||||
1999 | qAbs(snapPosDist) < bestSnapPosDist) {
| 0 | ||||||||||||||||||
2000 | bestSnapPos = snapPos; | - | ||||||||||||||||||
2001 | bestSnapPosDist = qAbs(snapPosDist); | - | ||||||||||||||||||
2002 | } never executed: end of block | 0 | ||||||||||||||||||
2003 | } never executed: end of block | 0 | ||||||||||||||||||
2004 | } never executed: end of block | 0 | ||||||||||||||||||
2005 | } never executed: end of block | 0 | ||||||||||||||||||
2006 | - | |||||||||||||||||||
2007 | return bestSnapPos; never executed: return bestSnapPos; | 0 | ||||||||||||||||||
2008 | } | - | ||||||||||||||||||
2009 | - | |||||||||||||||||||
2010 | /*! | - | ||||||||||||||||||
2011 | \enum QScroller::State | - | ||||||||||||||||||
2012 | - | |||||||||||||||||||
2013 | This enum contains the different QScroller states. | - | ||||||||||||||||||
2014 | - | |||||||||||||||||||
2015 | \value Inactive The scroller is not scrolling and nothing is pressed. | - | ||||||||||||||||||
2016 | \value Pressed A touch event was received or the mouse button was pressed but the scroll area is currently not dragged. | - | ||||||||||||||||||
2017 | \value Dragging The scroll area is currently following the touch point or mouse. | - | ||||||||||||||||||
2018 | \value Scrolling The scroll area is moving on it's own. | - | ||||||||||||||||||
2019 | */ | - | ||||||||||||||||||
2020 | - | |||||||||||||||||||
2021 | /*! | - | ||||||||||||||||||
2022 | \enum QScroller::ScrollerGestureType | - | ||||||||||||||||||
2023 | - | |||||||||||||||||||
2024 | This enum contains the different gesture types that are supported by the QScroller gesture recognizer. | - | ||||||||||||||||||
2025 | - | |||||||||||||||||||
2026 | \value TouchGesture The gesture recognizer will only trigger on touch | - | ||||||||||||||||||
2027 | events. Specifically it will react on single touch points when using a | - | ||||||||||||||||||
2028 | touch screen and dual touch points when using a touchpad. | - | ||||||||||||||||||
2029 | \value LeftMouseButtonGesture The gesture recognizer will only trigger on left mouse button events. | - | ||||||||||||||||||
2030 | \value MiddleMouseButtonGesture The gesture recognizer will only trigger on middle mouse button events. | - | ||||||||||||||||||
2031 | \value RightMouseButtonGesture The gesture recognizer will only trigger on right mouse button events. | - | ||||||||||||||||||
2032 | */ | - | ||||||||||||||||||
2033 | - | |||||||||||||||||||
2034 | /*! | - | ||||||||||||||||||
2035 | \enum QScroller::Input | - | ||||||||||||||||||
2036 | - | |||||||||||||||||||
2037 | This enum contains an input device agnostic view of input events that are relevant for QScroller. | - | ||||||||||||||||||
2038 | - | |||||||||||||||||||
2039 | \value InputPress The user pressed the input device (e.g. QEvent::MouseButtonPress, | - | ||||||||||||||||||
2040 | QEvent::GraphicsSceneMousePress, QEvent::TouchBegin) | - | ||||||||||||||||||
2041 | - | |||||||||||||||||||
2042 | \value InputMove The user moved the input device (e.g. QEvent::MouseMove, | - | ||||||||||||||||||
2043 | QEvent::GraphicsSceneMouseMove, QEvent::TouchUpdate) | - | ||||||||||||||||||
2044 | - | |||||||||||||||||||
2045 | \value InputRelease The user released the input device (e.g. QEvent::MouseButtonRelease, | - | ||||||||||||||||||
2046 | QEvent::GraphicsSceneMouseRelease, QEvent::TouchEnd) | - | ||||||||||||||||||
2047 | - | |||||||||||||||||||
2048 | */ | - | ||||||||||||||||||
2049 | - | |||||||||||||||||||
2050 | QT_END_NAMESPACE | - | ||||||||||||||||||
2051 | - | |||||||||||||||||||
2052 | #include "moc_qscroller.cpp" | - | ||||||||||||||||||
2053 | #include "moc_qscroller_p.cpp" | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |