OpenCoverage

qscroller.cpp

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

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9