| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/util/qscroller.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||
| 2 | - | |||||||||||||||||||
| 3 | - | |||||||||||||||||||
| 4 | - | |||||||||||||||||||
| 5 | - | |||||||||||||||||||
| 6 | - | |||||||||||||||||||
| 7 | - | |||||||||||||||||||
| 8 | - | |||||||||||||||||||
| 9 | bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event); | - | ||||||||||||||||||
| 10 | QDebug &operator<<(QDebug &dbg, const QScrollerPrivate::ScrollSegment &s) | - | ||||||||||||||||||
| 11 | { | - | ||||||||||||||||||
| 12 | dbg << "\n Time: start:" << s.startTime << " duration:" << s.deltaTime << " stop progress:" << s.stopProgress; | - | ||||||||||||||||||
| 13 | dbg << "\n Pos: start:" << s.startPos << " delta:" << s.deltaPos << " stop:" << s.stopPos; | - | ||||||||||||||||||
| 14 | dbg << "\n Curve: type:" << s.curve.type() << "\n"; | - | ||||||||||||||||||
| 15 | return dbg; | - | ||||||||||||||||||
| 16 | } | - | ||||||||||||||||||
| 17 | - | |||||||||||||||||||
| 18 | - | |||||||||||||||||||
| 19 | - | |||||||||||||||||||
| 20 | - | |||||||||||||||||||
| 21 | - | |||||||||||||||||||
| 22 | - | |||||||||||||||||||
| 23 | - | |||||||||||||||||||
| 24 | inline bool operator<=(const QPointF &p, qreal f) | - | ||||||||||||||||||
| 25 | { | - | ||||||||||||||||||
| 26 | return (qAbs(p.x()) <= f) && (qAbs(p.y()) <= f); | - | ||||||||||||||||||
| 27 | } | - | ||||||||||||||||||
| 28 | - | |||||||||||||||||||
| 29 | - | |||||||||||||||||||
| 30 | inline bool operator<(const QPointF &p, qreal f) | - | ||||||||||||||||||
| 31 | { | - | ||||||||||||||||||
| 32 | return (qAbs(p.x()) < f) && (qAbs(p.y()) < f); | - | ||||||||||||||||||
| 33 | } | - | ||||||||||||||||||
| 34 | - | |||||||||||||||||||
| 35 | - | |||||||||||||||||||
| 36 | inline bool operator>=(const QPointF &p, qreal f) | - | ||||||||||||||||||
| 37 | { | - | ||||||||||||||||||
| 38 | return (qAbs(p.x()) >= f) || (qAbs(p.y()) >= f); | - | ||||||||||||||||||
| 39 | } | - | ||||||||||||||||||
| 40 | - | |||||||||||||||||||
| 41 | - | |||||||||||||||||||
| 42 | inline bool operator>(const QPointF &p, qreal f) | - | ||||||||||||||||||
| 43 | { | - | ||||||||||||||||||
| 44 | return (qAbs(p.x()) > f) || (qAbs(p.y()) > f); | - | ||||||||||||||||||
| 45 | } | - | ||||||||||||||||||
| 46 | - | |||||||||||||||||||
| 47 | - | |||||||||||||||||||
| 48 | inline QPointF qAbs(const QPointF &p) | - | ||||||||||||||||||
| 49 | { | - | ||||||||||||||||||
| 50 | return QPointF(qAbs(p.x()), qAbs(p.y())); | - | ||||||||||||||||||
| 51 | } | - | ||||||||||||||||||
| 52 | - | |||||||||||||||||||
| 53 | - | |||||||||||||||||||
| 54 | inline QPointF operator*(const QPointF &p1, const QPointF &p2) | - | ||||||||||||||||||
| 55 | { | - | ||||||||||||||||||
| 56 | return QPointF(p1.x() * p2.x(), p1.y() * p2.y()); | - | ||||||||||||||||||
| 57 | } | - | ||||||||||||||||||
| 58 | - | |||||||||||||||||||
| 59 | - | |||||||||||||||||||
| 60 | inline QPointF operator/(const QPointF &p1, const QPointF &p2) | - | ||||||||||||||||||
| 61 | { | - | ||||||||||||||||||
| 62 | return QPointF(p1.x() / p2.x(), p1.y() / p2.y()); | - | ||||||||||||||||||
| 63 | } | - | ||||||||||||||||||
| 64 | - | |||||||||||||||||||
| 65 | inline QPointF clampToRect(const QPointF &p, const QRectF &rect) | - | ||||||||||||||||||
| 66 | { | - | ||||||||||||||||||
| 67 | qreal x = qBound(rect.left(), p.x(), rect.right()); | - | ||||||||||||||||||
| 68 | qreal y = qBound(rect.top(), p.y(), rect.bottom()); | - | ||||||||||||||||||
| 69 | return QPointF(x, y); | - | ||||||||||||||||||
| 70 | } | - | ||||||||||||||||||
| 71 | - | |||||||||||||||||||
| 72 | - | |||||||||||||||||||
| 73 | inline int qSign(qreal r) | - | ||||||||||||||||||
| 74 | { | - | ||||||||||||||||||
| 75 | return (r < 0) ? -1 : ((r > 0) ? 1 : 0); | - | ||||||||||||||||||
| 76 | } | - | ||||||||||||||||||
| 77 | - | |||||||||||||||||||
| 78 | - | |||||||||||||||||||
| 79 | - | |||||||||||||||||||
| 80 | - | |||||||||||||||||||
| 81 | static qreal differentialForProgress(const QEasingCurve &curve, qreal pos) | - | ||||||||||||||||||
| 82 | { | - | ||||||||||||||||||
| 83 | const qreal dx = 0.01; | - | ||||||||||||||||||
| 84 | qreal left = (pos < qreal(0.5)) ? pos : pos - qreal(dx); | - | ||||||||||||||||||
| 85 | qreal right = (pos >= qreal(0.5)) ? pos : pos + qreal(dx); | - | ||||||||||||||||||
| 86 | qreal d = (curve.valueForProgress(right) - curve.valueForProgress(left)) / qreal(dx); | - | ||||||||||||||||||
| 87 | - | |||||||||||||||||||
| 88 | - | |||||||||||||||||||
| 89 | - | |||||||||||||||||||
| 90 | return d; | - | ||||||||||||||||||
| 91 | } | - | ||||||||||||||||||
| 92 | - | |||||||||||||||||||
| 93 | - | |||||||||||||||||||
| 94 | - | |||||||||||||||||||
| 95 | - | |||||||||||||||||||
| 96 | static qreal progressForValue(const QEasingCurve &curve, qreal value) | - | ||||||||||||||||||
| 97 | { | - | ||||||||||||||||||
| 98 | if (__builtin_expect(!!(
| 0 | ||||||||||||||||||
| 99 | ) { | - | ||||||||||||||||||
| 100 | QMessageLogger(__FILE__, 164170, __PRETTY_FUNCTION__).warning("progressForValue(): QEasingCurves of type %d do not have an inverse, since they are not injective.", curve.type()); | - | ||||||||||||||||||
| 101 | return never executed: value;return value;never executed: return value; | 0 | ||||||||||||||||||
| 102 | } | - | ||||||||||||||||||
| 103 | if (value < qreal(0)
| 0 | ||||||||||||||||||
| 104 | return never executed: value;return value;never executed: return value; | 0 | ||||||||||||||||||
| 105 | - | |||||||||||||||||||
| 106 | qreal progress = value, left(0), right(1); | - | ||||||||||||||||||
| 107 | for (int iterations = 6; iterations
| 0 | ||||||||||||||||||
| 108 | qreal v = curve.valueForProgress(progress); | - | ||||||||||||||||||
| 109 | if (v < value
| 0 | ||||||||||||||||||
| 110 | left = progress; never executed: left = progress; | 0 | ||||||||||||||||||
| 111 | else if (v > value
| 0 | ||||||||||||||||||
| 112 | right = progress; never executed: right = progress; | 0 | ||||||||||||||||||
| 113 | else | - | ||||||||||||||||||
| 114 | break; never executed: break; | 0 | ||||||||||||||||||
| 115 | progress = (left + right) / qreal(2); | - | ||||||||||||||||||
| 116 | } never executed: end of block | 0 | ||||||||||||||||||
| 117 | return never executed: progress;return progress;never executed: return progress; | 0 | ||||||||||||||||||
| 118 | } | - | ||||||||||||||||||
| 119 | - | |||||||||||||||||||
| 120 | - | |||||||||||||||||||
| 121 | - | |||||||||||||||||||
| 122 | class QScrollTimer : public QAbstractAnimation | - | ||||||||||||||||||
| 123 | { | - | ||||||||||||||||||
| 124 | public: | - | ||||||||||||||||||
| 125 | QScrollTimer(QScrollerPrivate *_d) | - | ||||||||||||||||||
| 126 | : QAbstractAnimation(_d), d(_d), ignoreUpdate(false), skip(0) | - | ||||||||||||||||||
| 127 | { } | - | ||||||||||||||||||
| 128 | - | |||||||||||||||||||
| 129 | int duration() const override | - | ||||||||||||||||||
| 130 | { | - | ||||||||||||||||||
| 131 | return -1; | - | ||||||||||||||||||
| 132 | } | - | ||||||||||||||||||
| 133 | - | |||||||||||||||||||
| 134 | void start() | - | ||||||||||||||||||
| 135 | { | - | ||||||||||||||||||
| 136 | - | |||||||||||||||||||
| 137 | - | |||||||||||||||||||
| 138 | ignoreUpdate = true; | - | ||||||||||||||||||
| 139 | QAbstractAnimation::start(); | - | ||||||||||||||||||
| 140 | ignoreUpdate = false; | - | ||||||||||||||||||
| 141 | skip = 0; | - | ||||||||||||||||||
| 142 | } | - | ||||||||||||||||||
| 143 | - | |||||||||||||||||||
| 144 | protected: | - | ||||||||||||||||||
| 145 | void updateCurrentTime(int ) override | - | ||||||||||||||||||
| 146 | { | - | ||||||||||||||||||
| 147 | if (!ignoreUpdate) { | - | ||||||||||||||||||
| 148 | if (++skip >= d->frameRateSkip()) { | - | ||||||||||||||||||
| 149 | skip = 0; | - | ||||||||||||||||||
| 150 | d->timerTick(); | - | ||||||||||||||||||
| 151 | } | - | ||||||||||||||||||
| 152 | } | - | ||||||||||||||||||
| 153 | } | - | ||||||||||||||||||
| 154 | - | |||||||||||||||||||
| 155 | private: | - | ||||||||||||||||||
| 156 | QScrollerPrivate *d; | - | ||||||||||||||||||
| 157 | bool ignoreUpdate; | - | ||||||||||||||||||
| 158 | int skip; | - | ||||||||||||||||||
| 159 | }; | - | ||||||||||||||||||
| 160 | typedef QMap<QObject *, QScroller *> ScrollerHash; | - | ||||||||||||||||||
| 161 | typedef QSet<QScroller *> ScrollerSet; | - | ||||||||||||||||||
| 162 | - | |||||||||||||||||||
| 163 | namespace { namespace Q_QGS_qt_allScrollers { typedef ScrollerHash Type; QBasicAtomicInt guard = { QtGlobalStatic::Uninitialized }; __attribute__((visibility("hidden"))) inline Type *innerFunction() { struct HolderBase { ~HolderBase() noexcept { if (guard.load() == QtGlobalStatic::Initialized) guard.store(QtGlobalStatic::Destroyed); } }; static struct Holder : public HolderBase { Type value; Holder() noexcept(noexcept(Type ())) : value () { guard.store(QtGlobalStatic::Initialized); } } holder; return &holder.value; } } } static QGlobalStatic<ScrollerHash, Q_QGS_qt_allScrollers::innerFunction, Q_QGS_qt_allScrollers::guard> qt_allScrollers; | - | ||||||||||||||||||
| 164 | namespace { namespace Q_QGS_qt_activeScrollers { typedef ScrollerSet Type; QBasicAtomicInt guard = { QtGlobalStatic::Uninitialized }; __attribute__((visibility("hidden"))) inline Type *innerFunction() { struct HolderBase { ~HolderBase() noexcept { if (guard.load() == QtGlobalStatic::Initialized) guard.store(QtGlobalStatic::Destroyed); } }; static struct Holder : public HolderBase { Type value; Holder() noexcept(noexcept(Type ())) : value () { guard.store(QtGlobalStatic::Initialized); } } holder; return &holder.value; } } } static QGlobalStatic<ScrollerSet, Q_QGS_qt_activeScrollers::innerFunction, Q_QGS_qt_activeScrollers::guard> qt_activeScrollers; | - | ||||||||||||||||||
| 165 | - | |||||||||||||||||||
| 166 | - | |||||||||||||||||||
| 167 | - | |||||||||||||||||||
| 168 | - | |||||||||||||||||||
| 169 | - | |||||||||||||||||||
| 170 | - | |||||||||||||||||||
| 171 | bool QScroller::hasScroller(QObject *target) | - | ||||||||||||||||||
| 172 | { | - | ||||||||||||||||||
| 173 | return (qt_allScrollers()->value(target)); | - | ||||||||||||||||||
| 174 | } | - | ||||||||||||||||||
| 175 | QScroller *QScroller::scroller(QObject *target) | - | ||||||||||||||||||
| 176 | { | - | ||||||||||||||||||
| 177 | if (!target) { | - | ||||||||||||||||||
| 178 | QMessageLogger(__FILE__, 301307, __PRETTY_FUNCTION__).warning("QScroller::scroller() was called with a null target."); | - | ||||||||||||||||||
| 179 | return 0; | - | ||||||||||||||||||
| 180 | } | - | ||||||||||||||||||
| 181 | - | |||||||||||||||||||
| 182 | if (qt_allScrollers()->contains(target)) | - | ||||||||||||||||||
| 183 | return qt_allScrollers()->value(target); | - | ||||||||||||||||||
| 184 | - | |||||||||||||||||||
| 185 | QScroller *s = new QScroller(target); | - | ||||||||||||||||||
| 186 | qt_allScrollers()->insert(target, s); | - | ||||||||||||||||||
| 187 | return s; | - | ||||||||||||||||||
| 188 | } | - | ||||||||||||||||||
| 189 | - | |||||||||||||||||||
| 190 | - | |||||||||||||||||||
| 191 | - | |||||||||||||||||||
| 192 | - | |||||||||||||||||||
| 193 | - | |||||||||||||||||||
| 194 | const QScroller *QScroller::scroller(const QObject *target) | - | ||||||||||||||||||
| 195 | { | - | ||||||||||||||||||
| 196 | return scroller(const_cast<QObject*>(target)); | - | ||||||||||||||||||
| 197 | } | - | ||||||||||||||||||
| 198 | - | |||||||||||||||||||
| 199 | - | |||||||||||||||||||
| 200 | - | |||||||||||||||||||
| 201 | - | |||||||||||||||||||
| 202 | - | |||||||||||||||||||
| 203 | - | |||||||||||||||||||
| 204 | QList<QScroller *> QScroller::activeScrollers() | - | ||||||||||||||||||
| 205 | { | - | ||||||||||||||||||
| 206 | return qt_activeScrollers()->toList(); | - | ||||||||||||||||||
| 207 | } | - | ||||||||||||||||||
| 208 | - | |||||||||||||||||||
| 209 | - | |||||||||||||||||||
| 210 | - | |||||||||||||||||||
| 211 | - | |||||||||||||||||||
| 212 | - | |||||||||||||||||||
| 213 | QObject *QScroller::target() const | - | ||||||||||||||||||
| 214 | { | - | ||||||||||||||||||
| 215 | const QScrollerPrivate * const d = d_func(); | - | ||||||||||||||||||
| 216 | return d->target; | - | ||||||||||||||||||
| 217 | } | - | ||||||||||||||||||
| 218 | QScrollerProperties QScroller::scrollerProperties() const | - | ||||||||||||||||||
| 219 | { | - | ||||||||||||||||||
| 220 | const QScrollerPrivate * const d = d_func(); | - | ||||||||||||||||||
| 221 | return d->properties; | - | ||||||||||||||||||
| 222 | } | - | ||||||||||||||||||
| 223 | - | |||||||||||||||||||
| 224 | void QScroller::setScrollerProperties(const QScrollerProperties &sp) | - | ||||||||||||||||||
| 225 | { | - | ||||||||||||||||||
| 226 | QScrollerPrivate * const d = d_func(); | - | ||||||||||||||||||
| 227 | if (d->properties != sp) { | - | ||||||||||||||||||
| 228 | d->properties = sp; | - | ||||||||||||||||||
| 229 | scrollerPropertiesChanged(sp); | - | ||||||||||||||||||
| 230 | - | |||||||||||||||||||
| 231 | - | |||||||||||||||||||
| 232 | - | |||||||||||||||||||
| 233 | d->recalcScrollingSegments(true); | - | ||||||||||||||||||
| 234 | } | - | ||||||||||||||||||
| 235 | } | - | ||||||||||||||||||
| 236 | Qt::GestureType QScroller::grabGesture(QObject *target, ScrollerGestureType scrollGestureType) | - | ||||||||||||||||||
| 237 | { | - | ||||||||||||||||||
| 238 | - | |||||||||||||||||||
| 239 | QScroller *s = scroller(target); | - | ||||||||||||||||||
| 240 | if (!s) | - | ||||||||||||||||||
| 241 | return Qt::GestureType(0); | - | ||||||||||||||||||
| 242 | - | |||||||||||||||||||
| 243 | QScrollerPrivate *sp = s->d_ptr; | - | ||||||||||||||||||
| 244 | if (sp->recognizer) | - | ||||||||||||||||||
| 245 | ungrabGesture(target); | - | ||||||||||||||||||
| 246 | - | |||||||||||||||||||
| 247 | Qt::MouseButton button; | - | ||||||||||||||||||
| 248 | switch (scrollGestureType) { | - | ||||||||||||||||||
| 249 | case LeftMouseButtonGesture : button = Qt::LeftButton; break; | - | ||||||||||||||||||
| 250 | case RightMouseButtonGesture : button = Qt::RightButton; break; | - | ||||||||||||||||||
| 251 | case MiddleMouseButtonGesture: button = Qt::MiddleButton; break; | - | ||||||||||||||||||
| 252 | default : | - | ||||||||||||||||||
| 253 | case TouchGesture : button = Qt::NoButton; break; | - | ||||||||||||||||||
| 254 | } | - | ||||||||||||||||||
| 255 | - | |||||||||||||||||||
| 256 | sp->recognizer = new QFlickGestureRecognizer(button); | - | ||||||||||||||||||
| 257 | sp->recognizerType = QGestureRecognizer::registerRecognizer(sp->recognizer); | - | ||||||||||||||||||
| 258 | - | |||||||||||||||||||
| 259 | if (target->isWidgetType()) { | - | ||||||||||||||||||
| 260 | QWidget *widget = static_cast<QWidget *>(target); | - | ||||||||||||||||||
| 261 | widget->grabGesture(sp->recognizerType); | - | ||||||||||||||||||
| 262 | if (scrollGestureType == TouchGesture) | - | ||||||||||||||||||
| 263 | widget->setAttribute(Qt::WA_AcceptTouchEvents); | - | ||||||||||||||||||
| 264 | - | |||||||||||||||||||
| 265 | } else if (QGraphicsObject *go = qobject_cast<QGraphicsObject*>(target)) { | - | ||||||||||||||||||
| 266 | if (scrollGestureType == TouchGesture) | - | ||||||||||||||||||
| 267 | go->setAcceptTouchEvents(true); | - | ||||||||||||||||||
| 268 | go->grabGesture(sp->recognizerType); | - | ||||||||||||||||||
| 269 | - | |||||||||||||||||||
| 270 | } | - | ||||||||||||||||||
| 271 | return sp->recognizerType; | - | ||||||||||||||||||
| 272 | } | - | ||||||||||||||||||
| 273 | - | |||||||||||||||||||
| 274 | - | |||||||||||||||||||
| 275 | - | |||||||||||||||||||
| 276 | - | |||||||||||||||||||
| 277 | - | |||||||||||||||||||
| 278 | - | |||||||||||||||||||
| 279 | - | |||||||||||||||||||
| 280 | Qt::GestureType QScroller::grabbedGesture(QObject *target) | - | ||||||||||||||||||
| 281 | { | - | ||||||||||||||||||
| 282 | QScroller *s = scroller(target); | - | ||||||||||||||||||
| 283 | if (s && s->d_ptr) | - | ||||||||||||||||||
| 284 | return s->d_ptr->recognizerType; | - | ||||||||||||||||||
| 285 | else | - | ||||||||||||||||||
| 286 | return Qt::GestureType(0); | - | ||||||||||||||||||
| 287 | } | - | ||||||||||||||||||
| 288 | - | |||||||||||||||||||
| 289 | - | |||||||||||||||||||
| 290 | - | |||||||||||||||||||
| 291 | - | |||||||||||||||||||
| 292 | - | |||||||||||||||||||
| 293 | - | |||||||||||||||||||
| 294 | - | |||||||||||||||||||
| 295 | void QScroller::ungrabGesture(QObject *target) | - | ||||||||||||||||||
| 296 | { | - | ||||||||||||||||||
| 297 | QScroller *s = scroller(target); | - | ||||||||||||||||||
| 298 | if (!s) | - | ||||||||||||||||||
| 299 | return; | - | ||||||||||||||||||
| 300 | - | |||||||||||||||||||
| 301 | QScrollerPrivate *sp = s->d_ptr; | - | ||||||||||||||||||
| 302 | if (!sp->recognizer) | - | ||||||||||||||||||
| 303 | return; | - | ||||||||||||||||||
| 304 | - | |||||||||||||||||||
| 305 | if (target->isWidgetType()) { | - | ||||||||||||||||||
| 306 | QWidget *widget = static_cast<QWidget *>(target); | - | ||||||||||||||||||
| 307 | widget->ungrabGesture(sp->recognizerType); | - | ||||||||||||||||||
| 308 | - | |||||||||||||||||||
| 309 | } else if (QGraphicsObject *go = qobject_cast<QGraphicsObject*>(target)) { | - | ||||||||||||||||||
| 310 | go->ungrabGesture(sp->recognizerType); | - | ||||||||||||||||||
| 311 | - | |||||||||||||||||||
| 312 | } | - | ||||||||||||||||||
| 313 | - | |||||||||||||||||||
| 314 | QGestureRecognizer::unregisterRecognizer(sp->recognizerType); | - | ||||||||||||||||||
| 315 | - | |||||||||||||||||||
| 316 | sp->recognizer = 0; | - | ||||||||||||||||||
| 317 | } | - | ||||||||||||||||||
| 318 | - | |||||||||||||||||||
| 319 | - | |||||||||||||||||||
| 320 | - | |||||||||||||||||||
| 321 | - | |||||||||||||||||||
| 322 | - | |||||||||||||||||||
| 323 | - | |||||||||||||||||||
| 324 | QScroller::QScroller(QObject *target) | - | ||||||||||||||||||
| 325 | : d_ptr(new QScrollerPrivate(this, target)) | - | ||||||||||||||||||
| 326 | { | - | ||||||||||||||||||
| 327 | ((!(target)) ? qt_assert("target",__FILE__,489495) : qt_noop()); | - | ||||||||||||||||||
| 328 | QScrollerPrivate * const d = d_func(); | - | ||||||||||||||||||
| 329 | d->init(); | - | ||||||||||||||||||
| 330 | } | - | ||||||||||||||||||
| 331 | - | |||||||||||||||||||
| 332 | - | |||||||||||||||||||
| 333 | - | |||||||||||||||||||
| 334 | - | |||||||||||||||||||
| 335 | QScroller::~QScroller() | - | ||||||||||||||||||
| 336 | { | - | ||||||||||||||||||
| 337 | QScrollerPrivate * const d = d_func(); | - | ||||||||||||||||||
| 338 | - | |||||||||||||||||||
| 339 | QGestureRecognizer::unregisterRecognizer(d->recognizerType); | - | ||||||||||||||||||
| 340 | - | |||||||||||||||||||
| 341 | d->recognizer = 0; | - | ||||||||||||||||||
| 342 | - | |||||||||||||||||||
| 343 | qt_allScrollers()->remove(d->target); | - | ||||||||||||||||||
| 344 | qt_activeScrollers()->remove(this); | - | ||||||||||||||||||
| 345 | - | |||||||||||||||||||
| 346 | delete d_ptr; | - | ||||||||||||||||||
| 347 | } | - | ||||||||||||||||||
| 348 | QScroller::State QScroller::state() const | - | ||||||||||||||||||
| 349 | { | - | ||||||||||||||||||
| 350 | const QScrollerPrivate * const d = d_func(); | - | ||||||||||||||||||
| 351 | return d->state; | - | ||||||||||||||||||
| 352 | } | - | ||||||||||||||||||
| 353 | - | |||||||||||||||||||
| 354 | - | |||||||||||||||||||
| 355 | - | |||||||||||||||||||
| 356 | - | |||||||||||||||||||
| 357 | void QScroller::stop() | - | ||||||||||||||||||
| 358 | { | - | ||||||||||||||||||
| 359 | QScrollerPrivate * const d = d_func(); | - | ||||||||||||||||||
| 360 | if (d->state != Inactive) { | - | ||||||||||||||||||
| 361 | QPointF here = clampToRect(d->contentPosition, d->contentPosRange); | - | ||||||||||||||||||
| 362 | qreal snapX = d->nextSnapPos(here.x(), 0, Qt::Horizontal); | - | ||||||||||||||||||
| 363 | qreal snapY = d->nextSnapPos(here.y(), 0, Qt::Vertical); | - | ||||||||||||||||||
| 364 | QPointF snap = here; | - | ||||||||||||||||||
| 365 | if (!qIsNaN(snapX)) | - | ||||||||||||||||||
| 366 | snap.setX(snapX); | - | ||||||||||||||||||
| 367 | if (!qIsNaN(snapY)) | - | ||||||||||||||||||
| 368 | snap.setY(snapY); | - | ||||||||||||||||||
| 369 | d->contentPosition = snap; | - | ||||||||||||||||||
| 370 | d->overshootPosition = QPointF(0, 0); | - | ||||||||||||||||||
| 371 | - | |||||||||||||||||||
| 372 | d->setState(Inactive); | - | ||||||||||||||||||
| 373 | } | - | ||||||||||||||||||
| 374 | } | - | ||||||||||||||||||
| 375 | QPointF QScroller::pixelPerMeter() const | - | ||||||||||||||||||
| 376 | { | - | ||||||||||||||||||
| 377 | const QScrollerPrivate * const d = d_func(); | - | ||||||||||||||||||
| 378 | QPointF ppm = d->pixelPerMeter; | - | ||||||||||||||||||
| 379 | - | |||||||||||||||||||
| 380 | - | |||||||||||||||||||
| 381 | if (QGraphicsObject *go = qobject_cast<QGraphicsObject *>(d->target)
| 0 | ||||||||||||||||||
| 382 | QTransform viewtr; | - | ||||||||||||||||||
| 383 | - | |||||||||||||||||||
| 384 | if (go->const
| 0 | ||||||||||||||||||
| 385 | const auto views ().= scene->views(); | - | ||||||||||||||||||
| 386 | if (!views.
| 0 | ||||||||||||||||||
| 387 | viewtr = go->scene()->views()..first()->viewportTransform(); never executed: viewtr = views.first()->viewportTransform(); | 0 | ||||||||||||||||||
| 388 | } never executed: end of block | 0 | ||||||||||||||||||
| 389 | QTransform tr = go->deviceTransform(viewtr); | - | ||||||||||||||||||
| 390 | if (tr.isScaling()
| 0 | ||||||||||||||||||
| 391 | QPointF p0 = tr.map(QPointF(0, 0)); | - | ||||||||||||||||||
| 392 | QPointF px = tr.map(QPointF(1, 0)); | - | ||||||||||||||||||
| 393 | QPointF py = tr.map(QPointF(0, 1)); | - | ||||||||||||||||||
| 394 | ppm.rx() /= QLineF(p0, px).length(); | - | ||||||||||||||||||
| 395 | ppm.ry() /= QLineF(p0, py).length(); | - | ||||||||||||||||||
| 396 | } never executed: end of block | 0 | ||||||||||||||||||
| 397 | } never executed: end of block | 0 | ||||||||||||||||||
| 398 | - | |||||||||||||||||||
| 399 | return never executed: ppm;return ppm;never executed: return ppm; | 0 | ||||||||||||||||||
| 400 | } | - | ||||||||||||||||||
| 401 | QPointF QScroller::velocity() const | - | ||||||||||||||||||
| 402 | { | - | ||||||||||||||||||
| 403 | const QScrollerPrivate * const d = d_func(); | - | ||||||||||||||||||
| 404 | const QScrollerPropertiesPrivate *sp = d->properties.d.data(); | - | ||||||||||||||||||
| 405 | - | |||||||||||||||||||
| 406 | switch (state()) { | - | ||||||||||||||||||
| 407 | case Dragging: | - | ||||||||||||||||||
| 408 | return d->releaseVelocity; | - | ||||||||||||||||||
| 409 | case Scrolling: { | - | ||||||||||||||||||
| 410 | QPointF vel; | - | ||||||||||||||||||
| 411 | qint64 now = d->monotonicTimer.elapsed(); | - | ||||||||||||||||||
| 412 | - | |||||||||||||||||||
| 413 | if (!d->xSegments.isEmpty()) { | - | ||||||||||||||||||
| 414 | const QScrollerPrivate::ScrollSegment &s = d->xSegments.head(); | - | ||||||||||||||||||
| 415 | qreal progress = qreal(now - s.startTime) / qreal(s.deltaTime); | - | ||||||||||||||||||
| 416 | qreal v = qSign(s.deltaPos) * qreal(s.deltaTime) / qreal(1000) * sp->decelerationFactor * qreal(0.5) * differentialForProgress(s.curve, progress); | - | ||||||||||||||||||
| 417 | vel.setX(v); | - | ||||||||||||||||||
| 418 | } | - | ||||||||||||||||||
| 419 | - | |||||||||||||||||||
| 420 | if (!d->ySegments.isEmpty()) { | - | ||||||||||||||||||
| 421 | const QScrollerPrivate::ScrollSegment &s = d->ySegments.head(); | - | ||||||||||||||||||
| 422 | qreal progress = qreal(now - s.startTime) / qreal(s.deltaTime); | - | ||||||||||||||||||
| 423 | qreal v = qSign(s.deltaPos) * qreal(s.deltaTime) / qreal(1000) * sp->decelerationFactor * qreal(0.5) * differentialForProgress(s.curve, progress); | - | ||||||||||||||||||
| 424 | vel.setY(v); | - | ||||||||||||||||||
| 425 | } | - | ||||||||||||||||||
| 426 | return vel; | - | ||||||||||||||||||
| 427 | } | - | ||||||||||||||||||
| 428 | default: | - | ||||||||||||||||||
| 429 | return QPointF(0, 0); | - | ||||||||||||||||||
| 430 | } | - | ||||||||||||||||||
| 431 | } | - | ||||||||||||||||||
| 432 | QPointF QScroller::finalPosition() const | - | ||||||||||||||||||
| 433 | { | - | ||||||||||||||||||
| 434 | const QScrollerPrivate * const d = d_func(); | - | ||||||||||||||||||
| 435 | return QPointF(d->scrollingSegmentsEndPos(Qt::Horizontal), | - | ||||||||||||||||||
| 436 | d->scrollingSegmentsEndPos(Qt::Vertical)); | - | ||||||||||||||||||
| 437 | } | - | ||||||||||||||||||
| 438 | void QScroller::scrollTo(const QPointF &pos) | - | ||||||||||||||||||
| 439 | { | - | ||||||||||||||||||
| 440 | - | |||||||||||||||||||
| 441 | scrollTo(pos, 300); | - | ||||||||||||||||||
| 442 | } | - | ||||||||||||||||||
| 443 | - | |||||||||||||||||||
| 444 | - | |||||||||||||||||||
| 445 | - | |||||||||||||||||||
| 446 | - | |||||||||||||||||||
| 447 | - | |||||||||||||||||||
| 448 | void QScroller::scrollTo(const QPointF &pos, int scrollTime) | - | ||||||||||||||||||
| 449 | { | - | ||||||||||||||||||
| 450 | QScrollerPrivate * const d = d_func(); | - | ||||||||||||||||||
| 451 | - | |||||||||||||||||||
| 452 | if (d->state == Pressed || d->state == Dragging ) | - | ||||||||||||||||||
| 453 | return; | - | ||||||||||||||||||
| 454 | - | |||||||||||||||||||
| 455 | - | |||||||||||||||||||
| 456 | if (d->state == Inactive && !d->prepareScrolling(QPointF())) | - | ||||||||||||||||||
| 457 | return; | - | ||||||||||||||||||
| 458 | - | |||||||||||||||||||
| 459 | QPointF newpos = clampToRect(pos, d->contentPosRange); | - | ||||||||||||||||||
| 460 | qreal snapX = d->nextSnapPos(newpos.x(), 0, Qt::Horizontal); | - | ||||||||||||||||||
| 461 | qreal snapY = d->nextSnapPos(newpos.y(), 0, Qt::Vertical); | - | ||||||||||||||||||
| 462 | if (!qIsNaN(snapX)) | - | ||||||||||||||||||
| 463 | newpos.setX(snapX); | - | ||||||||||||||||||
| 464 | if (!qIsNaN(snapY)) | - | ||||||||||||||||||
| 465 | newpos.setY(snapY); | - | ||||||||||||||||||
| 466 | - | |||||||||||||||||||
| 467 | while (false) QMessageLogger(__FILE__, 686695, __PRETTY_FUNCTION__).debug() << "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])"; | - | ||||||||||||||||||
| 468 | - | |||||||||||||||||||
| 469 | if (newpos == d->contentPosition + d->overshootPosition) | - | ||||||||||||||||||
| 470 | return; | - | ||||||||||||||||||
| 471 | - | |||||||||||||||||||
| 472 | QPointF vel = velocity(); | - | ||||||||||||||||||
| 473 | - | |||||||||||||||||||
| 474 | if (scrollTime < 0) | - | ||||||||||||||||||
| 475 | scrollTime = 0; | - | ||||||||||||||||||
| 476 | qreal time = qreal(scrollTime) / 1000; | - | ||||||||||||||||||
| 477 | - | |||||||||||||||||||
| 478 | d->createScrollToSegments(vel.x(), time, newpos.x(), Qt::Horizontal, QScrollerPrivate::ScrollTypeScrollTo); | - | ||||||||||||||||||
| 479 | d->createScrollToSegments(vel.y(), time, newpos.y(), Qt::Vertical, QScrollerPrivate::ScrollTypeScrollTo); | - | ||||||||||||||||||
| 480 | - | |||||||||||||||||||
| 481 | if (!scrollTime) | - | ||||||||||||||||||
| 482 | d->setContentPositionHelperScrolling(); | - | ||||||||||||||||||
| 483 | d->setState(scrollTime ? Scrolling : Inactive); | - | ||||||||||||||||||
| 484 | } | - | ||||||||||||||||||
| 485 | void QScroller::ensureVisible(const QRectF &rect, qreal xmargin, qreal ymargin) | - | ||||||||||||||||||
| 486 | { | - | ||||||||||||||||||
| 487 | - | |||||||||||||||||||
| 488 | ensureVisible(rect, xmargin, ymargin, 1000); | - | ||||||||||||||||||
| 489 | } | - | ||||||||||||||||||
| 490 | - | |||||||||||||||||||
| 491 | - | |||||||||||||||||||
| 492 | - | |||||||||||||||||||
| 493 | - | |||||||||||||||||||
| 494 | - | |||||||||||||||||||
| 495 | void QScroller::ensureVisible(const QRectF &rect, qreal xmargin, qreal ymargin, int scrollTime) | - | ||||||||||||||||||
| 496 | { | - | ||||||||||||||||||
| 497 | QScrollerPrivate * const d = d_func(); | - | ||||||||||||||||||
| 498 | - | |||||||||||||||||||
| 499 | if (d->state == Pressed || d->state == Dragging ) | - | ||||||||||||||||||
| 500 | return; | - | ||||||||||||||||||
| 501 | - | |||||||||||||||||||
| 502 | if (d->state == Inactive && !d->prepareScrolling(QPointF())) | - | ||||||||||||||||||
| 503 | return; | - | ||||||||||||||||||
| 504 | - | |||||||||||||||||||
| 505 | - | |||||||||||||||||||
| 506 | QPointF startPos(d->scrollingSegmentsEndPos(Qt::Horizontal), | - | ||||||||||||||||||
| 507 | d->scrollingSegmentsEndPos(Qt::Vertical)); | - | ||||||||||||||||||
| 508 | - | |||||||||||||||||||
| 509 | QRectF marginRect(rect.x() - xmargin, rect.y() - ymargin, | - | ||||||||||||||||||
| 510 | rect.width() + 2 * xmargin, rect.height() + 2 * ymargin); | - | ||||||||||||||||||
| 511 | - | |||||||||||||||||||
| 512 | QSizeF visible = d->viewportSize; | - | ||||||||||||||||||
| 513 | QRectF visibleRect(startPos, visible); | - | ||||||||||||||||||
| 514 | - | |||||||||||||||||||
| 515 | while (false) QMessageLogger(__FILE__, 750759, __PRETTY_FUNCTION__).debug() << "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])"; | - | ||||||||||||||||||
| 516 | while (false) QMessageLogger(__FILE__, 751760, __PRETTY_FUNCTION__).debug() << " --> content position:" << d->contentPosition; dead code: QMessageLogger(__FILE__, 760, __PRETTY_FUNCTION__).debug() << " --> content position:" << d->contentPosition; | - | ||||||||||||||||||
| 517 | - | |||||||||||||||||||
| 518 | if (visibleRect.contains(marginRect)) | - | ||||||||||||||||||
| 519 | return; | - | ||||||||||||||||||
| 520 | - | |||||||||||||||||||
| 521 | QPointF newPos = startPos; | - | ||||||||||||||||||
| 522 | - | |||||||||||||||||||
| 523 | if (visibleRect.width() < rect.width()) { | - | ||||||||||||||||||
| 524 | - | |||||||||||||||||||
| 525 | if (rect.left() > visibleRect.left()) | - | ||||||||||||||||||
| 526 | newPos.setX(rect.left()); | - | ||||||||||||||||||
| 527 | else if (rect.right() < visibleRect.right()) | - | ||||||||||||||||||
| 528 | newPos.setX(rect.right() - visible.width()); | - | ||||||||||||||||||
| 529 | - | |||||||||||||||||||
| 530 | } else if (visibleRect.width() < marginRect.width()) { | - | ||||||||||||||||||
| 531 | newPos.setX(rect.center().x() - visibleRect.width() / 2); | - | ||||||||||||||||||
| 532 | } else if (marginRect.left() > visibleRect.left()) { | - | ||||||||||||||||||
| 533 | newPos.setX(marginRect.left()); | - | ||||||||||||||||||
| 534 | } else if (marginRect.right() < visibleRect.right()) { | - | ||||||||||||||||||
| 535 | newPos.setX(marginRect.right() - visible.width()); | - | ||||||||||||||||||
| 536 | } | - | ||||||||||||||||||
| 537 | - | |||||||||||||||||||
| 538 | if (visibleRect.height() < rect.height()) { | - | ||||||||||||||||||
| 539 | - | |||||||||||||||||||
| 540 | if (rect.top() > visibleRect.top()) | - | ||||||||||||||||||
| 541 | newPos.setX(rect.top()); | - | ||||||||||||||||||
| 542 | else if (rect.bottom() < visibleRect.bottom()) | - | ||||||||||||||||||
| 543 | newPos.setX(rect.bottom() - visible.height()); | - | ||||||||||||||||||
| 544 | - | |||||||||||||||||||
| 545 | } else if (visibleRect.height() < marginRect.height()) { | - | ||||||||||||||||||
| 546 | newPos.setY(rect.center().y() - visibleRect.height() / 2); | - | ||||||||||||||||||
| 547 | } else if (marginRect.top() > visibleRect.top()) { | - | ||||||||||||||||||
| 548 | newPos.setY(marginRect.top()); | - | ||||||||||||||||||
| 549 | } else if (marginRect.bottom() < visibleRect.bottom()) { | - | ||||||||||||||||||
| 550 | newPos.setY(marginRect.bottom() - visible.height()); | - | ||||||||||||||||||
| 551 | } | - | ||||||||||||||||||
| 552 | - | |||||||||||||||||||
| 553 | - | |||||||||||||||||||
| 554 | newPos = clampToRect(newPos, d->contentPosRange); | - | ||||||||||||||||||
| 555 | if (newPos == startPos) | - | ||||||||||||||||||
| 556 | return; | - | ||||||||||||||||||
| 557 | - | |||||||||||||||||||
| 558 | scrollTo(newPos, scrollTime); | - | ||||||||||||||||||
| 559 | } | - | ||||||||||||||||||
| 560 | void QScroller::resendPrepareEvent() | - | ||||||||||||||||||
| 561 | { | - | ||||||||||||||||||
| 562 | QScrollerPrivate * const d = d_func(); | - | ||||||||||||||||||
| 563 | d->prepareScrolling(d->pressPosition); | - | ||||||||||||||||||
| 564 | } | - | ||||||||||||||||||
| 565 | - | |||||||||||||||||||
| 566 | - | |||||||||||||||||||
| 567 | - | |||||||||||||||||||
| 568 | - | |||||||||||||||||||
| 569 | - | |||||||||||||||||||
| 570 | - | |||||||||||||||||||
| 571 | void QScroller::setSnapPositionsX(const QList<qreal> &positions) | - | ||||||||||||||||||
| 572 | { | - | ||||||||||||||||||
| 573 | QScrollerPrivate * const d = d_func(); | - | ||||||||||||||||||
| 574 | d->snapPositionsX = positions; | - | ||||||||||||||||||
| 575 | d->snapIntervalX = 0.0; | - | ||||||||||||||||||
| 576 | - | |||||||||||||||||||
| 577 | d->recalcScrollingSegments(); | - | ||||||||||||||||||
| 578 | } | - | ||||||||||||||||||
| 579 | void QScroller::setSnapPositionsX(qreal first, qreal interval) | - | ||||||||||||||||||
| 580 | { | - | ||||||||||||||||||
| 581 | QScrollerPrivate * const d = d_func(); | - | ||||||||||||||||||
| 582 | d->snapFirstX = first; | - | ||||||||||||||||||
| 583 | d->snapIntervalX = interval; | - | ||||||||||||||||||
| 584 | d->snapPositionsX.clear(); | - | ||||||||||||||||||
| 585 | - | |||||||||||||||||||
| 586 | d->recalcScrollingSegments(); | - | ||||||||||||||||||
| 587 | } | - | ||||||||||||||||||
| 588 | - | |||||||||||||||||||
| 589 | - | |||||||||||||||||||
| 590 | - | |||||||||||||||||||
| 591 | - | |||||||||||||||||||
| 592 | - | |||||||||||||||||||
| 593 | - | |||||||||||||||||||
| 594 | void QScroller::setSnapPositionsY(const QList<qreal> &positions) | - | ||||||||||||||||||
| 595 | { | - | ||||||||||||||||||
| 596 | QScrollerPrivate * const d = d_func(); | - | ||||||||||||||||||
| 597 | d->snapPositionsY = positions; | - | ||||||||||||||||||
| 598 | d->snapIntervalY = 0.0; | - | ||||||||||||||||||
| 599 | - | |||||||||||||||||||
| 600 | d->recalcScrollingSegments(); | - | ||||||||||||||||||
| 601 | } | - | ||||||||||||||||||
| 602 | - | |||||||||||||||||||
| 603 | - | |||||||||||||||||||
| 604 | - | |||||||||||||||||||
| 605 | - | |||||||||||||||||||
| 606 | - | |||||||||||||||||||
| 607 | - | |||||||||||||||||||
| 608 | - | |||||||||||||||||||
| 609 | void QScroller::setSnapPositionsY(qreal first, qreal interval) | - | ||||||||||||||||||
| 610 | { | - | ||||||||||||||||||
| 611 | QScrollerPrivate * const d = d_func(); | - | ||||||||||||||||||
| 612 | d->snapFirstY = first; | - | ||||||||||||||||||
| 613 | d->snapIntervalY = interval; | - | ||||||||||||||||||
| 614 | d->snapPositionsY.clear(); | - | ||||||||||||||||||
| 615 | - | |||||||||||||||||||
| 616 | d->recalcScrollingSegments(); | - | ||||||||||||||||||
| 617 | } | - | ||||||||||||||||||
| 618 | - | |||||||||||||||||||
| 619 | - | |||||||||||||||||||
| 620 | - | |||||||||||||||||||
| 621 | - | |||||||||||||||||||
| 622 | - | |||||||||||||||||||
| 623 | QScrollerPrivate::QScrollerPrivate(QScroller *q, QObject *_target) | - | ||||||||||||||||||
| 624 | : target(_target) | - | ||||||||||||||||||
| 625 | - | |||||||||||||||||||
| 626 | , recognizer(0) | - | ||||||||||||||||||
| 627 | , recognizerType(Qt::CustomGesture) | - | ||||||||||||||||||
| 628 | - | |||||||||||||||||||
| 629 | , state(QScroller::Inactive) | - | ||||||||||||||||||
| 630 | , firstScroll(true) | - | ||||||||||||||||||
| 631 | , pressTimestamp(0) | - | ||||||||||||||||||
| 632 | , lastTimestamp(0) | - | ||||||||||||||||||
| 633 | , snapFirstX(-1.0) | - | ||||||||||||||||||
| 634 | , snapIntervalX(0.0) | - | ||||||||||||||||||
| 635 | , snapFirstY(-1.0) | - | ||||||||||||||||||
| 636 | , snapIntervalY(0.0) | - | ||||||||||||||||||
| 637 | - | |||||||||||||||||||
| 638 | , scrollTimer(new QScrollTimer(this)) | - | ||||||||||||||||||
| 639 | - | |||||||||||||||||||
| 640 | , q_ptr(q) | - | ||||||||||||||||||
| 641 | { | - | ||||||||||||||||||
| 642 | connect(target, qFlagLocation("2""destroyed(QObject*)" "\0" __FILE__ ":" "893""902"), this, qFlagLocation("1""targetDestroyed()" "\0" __FILE__ ":" "893""902")); | - | ||||||||||||||||||
| 643 | } | - | ||||||||||||||||||
| 644 | - | |||||||||||||||||||
| 645 | void QScrollerPrivate::init() | - | ||||||||||||||||||
| 646 | { | - | ||||||||||||||||||
| 647 | setDpiFromWidget(0); | - | ||||||||||||||||||
| 648 | monotonicTimer.start(); | - | ||||||||||||||||||
| 649 | } | - | ||||||||||||||||||
| 650 | - | |||||||||||||||||||
| 651 | void QScrollerPrivate::sendEvent(QObject *o, QEvent *e) | - | ||||||||||||||||||
| 652 | { | - | ||||||||||||||||||
| 653 | qt_sendSpontaneousEvent(o, e); | - | ||||||||||||||||||
| 654 | } | - | ||||||||||||||||||
| 655 | - | |||||||||||||||||||
| 656 | const char *QScrollerPrivate::stateName(QScroller::State state) | - | ||||||||||||||||||
| 657 | { | - | ||||||||||||||||||
| 658 | switch (state) { | - | ||||||||||||||||||
| 659 | case QScroller::Inactive: return "inactive"; | - | ||||||||||||||||||
| 660 | case QScroller::Pressed: return "pressed"; | - | ||||||||||||||||||
| 661 | case QScroller::Dragging: return "dragging"; | - | ||||||||||||||||||
| 662 | case QScroller::Scrolling: return "scrolling"; | - | ||||||||||||||||||
| 663 | default: return "(invalid)"; | - | ||||||||||||||||||
| 664 | } | - | ||||||||||||||||||
| 665 | } | - | ||||||||||||||||||
| 666 | - | |||||||||||||||||||
| 667 | const char *QScrollerPrivate::inputName(QScroller::Input input) | - | ||||||||||||||||||
| 668 | { | - | ||||||||||||||||||
| 669 | switch (input) { | - | ||||||||||||||||||
| 670 | case QScroller::InputPress: return "press"; | - | ||||||||||||||||||
| 671 | case QScroller::InputMove: return "move"; | - | ||||||||||||||||||
| 672 | case QScroller::InputRelease: return "release"; | - | ||||||||||||||||||
| 673 | default: return "(invalid)"; | - | ||||||||||||||||||
| 674 | } | - | ||||||||||||||||||
| 675 | } | - | ||||||||||||||||||
| 676 | - | |||||||||||||||||||
| 677 | void QScrollerPrivate::targetDestroyed() | - | ||||||||||||||||||
| 678 | { | - | ||||||||||||||||||
| 679 | - | |||||||||||||||||||
| 680 | scrollTimer->stop(); | - | ||||||||||||||||||
| 681 | - | |||||||||||||||||||
| 682 | delete q_ptr; | - | ||||||||||||||||||
| 683 | } | - | ||||||||||||||||||
| 684 | - | |||||||||||||||||||
| 685 | void QScrollerPrivate::timerTick() | - | ||||||||||||||||||
| 686 | { | - | ||||||||||||||||||
| 687 | struct timerevent { | - | ||||||||||||||||||
| 688 | QScroller::State state; | - | ||||||||||||||||||
| 689 | typedef void (QScrollerPrivate::*timerhandler_t)(); | - | ||||||||||||||||||
| 690 | timerhandler_t handler; | - | ||||||||||||||||||
| 691 | }; | - | ||||||||||||||||||
| 692 | - | |||||||||||||||||||
| 693 | timerevent timerevents[] = { | - | ||||||||||||||||||
| 694 | { QScroller::Dragging, &QScrollerPrivate::timerEventWhileDragging }, | - | ||||||||||||||||||
| 695 | { QScroller::Scrolling, &QScrollerPrivate::timerEventWhileScrolling }, | - | ||||||||||||||||||
| 696 | }; | - | ||||||||||||||||||
| 697 | - | |||||||||||||||||||
| 698 | for (int i = 0; i < int(sizeof(timerevents) / sizeof(*timerevents)); ++i) { | - | ||||||||||||||||||
| 699 | timerevent *te = timerevents + i; | - | ||||||||||||||||||
| 700 | - | |||||||||||||||||||
| 701 | if (state == te->state) { | - | ||||||||||||||||||
| 702 | (this->*te->handler)(); | - | ||||||||||||||||||
| 703 | return; | - | ||||||||||||||||||
| 704 | } | - | ||||||||||||||||||
| 705 | } | - | ||||||||||||||||||
| 706 | - | |||||||||||||||||||
| 707 | - | |||||||||||||||||||
| 708 | scrollTimer->stop(); | - | ||||||||||||||||||
| 709 | - | |||||||||||||||||||
| 710 | } | - | ||||||||||||||||||
| 711 | bool QScroller::handleInput(Input input, const QPointF &position, qint64 timestamp) | - | ||||||||||||||||||
| 712 | { | - | ||||||||||||||||||
| 713 | QScrollerPrivate * const d = d_func(); | - | ||||||||||||||||||
| 714 | - | |||||||||||||||||||
| 715 | while (false) QMessageLogger(__FILE__, 979988, __PRETTY_FUNCTION__).debug() << "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 << ')'; | - | ||||||||||||||||||
| 716 | struct statechange { | - | ||||||||||||||||||
| 717 | State state; | - | ||||||||||||||||||
| 718 | Input input; | - | ||||||||||||||||||
| 719 | typedef bool (QScrollerPrivate::*inputhandler_t)(const QPointF &position, qint64 timestamp); | - | ||||||||||||||||||
| 720 | inputhandler_t handler; | - | ||||||||||||||||||
| 721 | }; | - | ||||||||||||||||||
| 722 | - | |||||||||||||||||||
| 723 | statechange statechanges[] = { | - | ||||||||||||||||||
| 724 | { QScroller::Inactive, InputPress, &QScrollerPrivate::pressWhileInactive }, | - | ||||||||||||||||||
| 725 | { QScroller::Pressed, InputMove, &QScrollerPrivate::moveWhilePressed }, | - | ||||||||||||||||||
| 726 | { QScroller::Pressed, InputRelease, &QScrollerPrivate::releaseWhilePressed }, | - | ||||||||||||||||||
| 727 | { QScroller::Dragging, InputMove, &QScrollerPrivate::moveWhileDragging }, | - | ||||||||||||||||||
| 728 | { QScroller::Dragging, InputRelease, &QScrollerPrivate::releaseWhileDragging }, | - | ||||||||||||||||||
| 729 | { QScroller::Scrolling, InputPress, &QScrollerPrivate::pressWhileScrolling } | - | ||||||||||||||||||
| 730 | }; | - | ||||||||||||||||||
| 731 | - | |||||||||||||||||||
| 732 | for (int i = 0; i < int(sizeof(statechanges) / sizeof(*statechanges)); ++i) { | - | ||||||||||||||||||
| 733 | statechange *sc = statechanges + i; | - | ||||||||||||||||||
| 734 | - | |||||||||||||||||||
| 735 | if (d->state == sc->state && input == sc->input) | - | ||||||||||||||||||
| 736 | return (d->*sc->handler)(position - d->overshootPosition, timestamp); | - | ||||||||||||||||||
| 737 | } | - | ||||||||||||||||||
| 738 | return false; | - | ||||||||||||||||||
| 739 | } | - | ||||||||||||||||||
| 740 | - | |||||||||||||||||||
| 741 | - | |||||||||||||||||||
| 742 | - | |||||||||||||||||||
| 743 | - | |||||||||||||||||||
| 744 | QPointF QScrollerPrivate::realDpi(int screen) const | - | ||||||||||||||||||
| 745 | { | - | ||||||||||||||||||
| 746 | QWidget *w = QApplication::desktop()->screen(screen); | - | ||||||||||||||||||
| 747 | return never executed: QPointF(w->physicalDpiX(), w->physicalDpiY());return QPointF(w->physicalDpiX(), w->physicalDpiY());never executed: return QPointF(w->physicalDpiX(), w->physicalDpiY()); | 0 | ||||||||||||||||||
| 748 | } | - | ||||||||||||||||||
| 749 | - | |||||||||||||||||||
| 750 | - | |||||||||||||||||||
| 751 | - | |||||||||||||||||||
| 752 | - | |||||||||||||||||||
| 753 | - | |||||||||||||||||||
| 754 | - | |||||||||||||||||||
| 755 | - | |||||||||||||||||||
| 756 | QPointF QScrollerPrivate::dpi() const | - | ||||||||||||||||||
| 757 | { | - | ||||||||||||||||||
| 758 | return pixelPerMeter * qreal(0.0254); | - | ||||||||||||||||||
| 759 | } | - | ||||||||||||||||||
| 760 | - | |||||||||||||||||||
| 761 | - | |||||||||||||||||||
| 762 | - | |||||||||||||||||||
| 763 | - | |||||||||||||||||||
| 764 | - | |||||||||||||||||||
| 765 | - | |||||||||||||||||||
| 766 | - | |||||||||||||||||||
| 767 | void QScrollerPrivate::setDpi(const QPointF &dpi) | - | ||||||||||||||||||
| 768 | { | - | ||||||||||||||||||
| 769 | pixelPerMeter = dpi / qreal(0.0254); | - | ||||||||||||||||||
| 770 | } | - | ||||||||||||||||||
| 771 | - | |||||||||||||||||||
| 772 | - | |||||||||||||||||||
| 773 | - | |||||||||||||||||||
| 774 | - | |||||||||||||||||||
| 775 | void QScrollerPrivate::setDpiFromWidget(QWidget *widget) | - | ||||||||||||||||||
| 776 | { | - | ||||||||||||||||||
| 777 | QDesktopWidget *dw = QApplication::desktop(); | - | ||||||||||||||||||
| 778 | setDpi(realDpi(widget ? dw->screenNumber(widget) : dw->primaryScreen())); | - | ||||||||||||||||||
| 779 | } | - | ||||||||||||||||||
| 780 | - | |||||||||||||||||||
| 781 | - | |||||||||||||||||||
| 782 | - | |||||||||||||||||||
| 783 | - | |||||||||||||||||||
| 784 | - | |||||||||||||||||||
| 785 | void QScrollerPrivate::updateVelocity(const QPointF &deltaPixelRaw, qint64 deltaTime) | - | ||||||||||||||||||
| 786 | { | - | ||||||||||||||||||
| 787 | if (deltaTime <= 0) | - | ||||||||||||||||||
| 788 | return; | - | ||||||||||||||||||
| 789 | - | |||||||||||||||||||
| 790 | QScroller * const q = q_func(); | - | ||||||||||||||||||
| 791 | QPointF ppm = q->pixelPerMeter(); | - | ||||||||||||||||||
| 792 | const QScrollerPropertiesPrivate *sp = properties.d.data(); | - | ||||||||||||||||||
| 793 | QPointF deltaPixel = deltaPixelRaw; | - | ||||||||||||||||||
| 794 | - | |||||||||||||||||||
| 795 | while (false) QMessageLogger(__FILE__, 10811090, __PRETTY_FUNCTION__).debug() << "QScroller::updateVelocity(" << deltaPixelRaw << " [delta pix], " << deltaTime << " [delta ms])"; dead code: QMessageLogger(__FILE__, 1090, __PRETTY_FUNCTION__).debug() << "QScroller::updateVelocity(" << deltaPixelRaw << " [delta pix], " << deltaTime << " [delta ms])"; | - | ||||||||||||||||||
| 796 | - | |||||||||||||||||||
| 797 | - | |||||||||||||||||||
| 798 | if (((deltaPixelRaw / qreal(deltaTime)).manhattanLength() / ((ppm.x() + ppm.y()) / 2) * 1000) > qreal(2.5)) | - | ||||||||||||||||||
| 799 | deltaPixel = deltaPixelRaw * qreal(2.5) * ppm / 1000 / (deltaPixelRaw / qreal(deltaTime)).manhattanLength(); | - | ||||||||||||||||||
| 800 | - | |||||||||||||||||||
| 801 | QPointF newv = -deltaPixel / qreal(deltaTime) * qreal(1000) / ppm; | - | ||||||||||||||||||
| 802 | - | |||||||||||||||||||
| 803 | - | |||||||||||||||||||
| 804 | - | |||||||||||||||||||
| 805 | qreal smoothing = sp->dragVelocitySmoothingFactor * qMin(qreal(deltaTime), qreal(50)) / qreal(50); | - | ||||||||||||||||||
| 806 | - | |||||||||||||||||||
| 807 | - | |||||||||||||||||||
| 808 | - | |||||||||||||||||||
| 809 | if ((releaseVelocity != QPointF(0, 0)) && (deltaTime < 100)) { | - | ||||||||||||||||||
| 810 | while (false) QMessageLogger(__FILE__, 10961105, __PRETTY_FUNCTION__).debug() << "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); | - | ||||||||||||||||||
| 811 | - | |||||||||||||||||||
| 812 | - | |||||||||||||||||||
| 813 | if (!newv.x() || (qSign(releaseVelocity.x()) == qSign(newv.x()))) | - | ||||||||||||||||||
| 814 | newv.setX(newv.x() * smoothing + releaseVelocity.x() * (qreal(1) - smoothing)); | - | ||||||||||||||||||
| 815 | if (!newv.y() || (qSign(releaseVelocity.y()) == qSign(newv.y()))) | - | ||||||||||||||||||
| 816 | newv.setY(newv.y() * smoothing + releaseVelocity.y() * (qreal(1) - smoothing)); | - | ||||||||||||||||||
| 817 | } else | - | ||||||||||||||||||
| 818 | while (false) QMessageLogger(__FILE__, 11041113, __PRETTY_FUNCTION__).debug() << "NO SMOOTHING to " << newv; dead code: QMessageLogger(__FILE__, 1113, __PRETTY_FUNCTION__).debug() << "NO SMOOTHING to " << newv; | - | ||||||||||||||||||
| 819 | - | |||||||||||||||||||
| 820 | releaseVelocity.setX(qBound(-sp->maximumVelocity, newv.x(), sp->maximumVelocity)); | - | ||||||||||||||||||
| 821 | releaseVelocity.setY(qBound(-sp->maximumVelocity, newv.y(), sp->maximumVelocity)); | - | ||||||||||||||||||
| 822 | - | |||||||||||||||||||
| 823 | while (false) QMessageLogger(__FILE__, 11091118, __PRETTY_FUNCTION__).debug() << " --> new velocity:" << releaseVelocity; dead code: QMessageLogger(__FILE__, 1118, __PRETTY_FUNCTION__).debug() << " --> new velocity:" << releaseVelocity; | - | ||||||||||||||||||
| 824 | } | - | ||||||||||||||||||
| 825 | - | |||||||||||||||||||
| 826 | void QScrollerPrivate::pushSegment(ScrollType type, qreal deltaTime, qreal stopProgress, qreal startPos, qreal deltaPos, qreal stopPos, QEasingCurve::Type curve, Qt::Orientation orientation) | - | ||||||||||||||||||
| 827 | { | - | ||||||||||||||||||
| 828 | if (startPos == stopPos
| 0 | ||||||||||||||||||
| 829 | return; never executed: return; | 0 | ||||||||||||||||||
| 830 | - | |||||||||||||||||||
| 831 | ScrollSegment s; | - | ||||||||||||||||||
| 832 | if (orientation == Qt::Horizontal
| 0 | ||||||||||||||||||
| 833 | const auto &lastX = xSegments.constLast(); | - | ||||||||||||||||||
| 834 | s.startTime = xSegmentslastX.last().startTime + xSegmentslastX.last().deltaTime * xSegmentslastX.last().stopProgress; | - | ||||||||||||||||||
| 835 | } never executed: else if (orientation == Qt::Verticalend of block
| 0 | ||||||||||||||||||
| 836 | const auto &lastY = ySegments.constLast(); | - | ||||||||||||||||||
| 837 | s.startTime = ySegmentslastY.last().startTime + ySegmentslastY.last().deltaTime * ySegmentslastY.last().stopProgress; | - | ||||||||||||||||||
| 838 | } never executed: else {end of block | 0 | ||||||||||||||||||
| 839 | s.startTime = monotonicTimer.elapsed(); | - | ||||||||||||||||||
| 840 | } never executed: end of block | 0 | ||||||||||||||||||
| 841 | - | |||||||||||||||||||
| 842 | s.startPos = startPos; | - | ||||||||||||||||||
| 843 | s.deltaPos = deltaPos; | - | ||||||||||||||||||
| 844 | s.stopPos = stopPos; | - | ||||||||||||||||||
| 845 | s.deltaTime = deltaTime * 1000; | - | ||||||||||||||||||
| 846 | s.stopProgress = stopProgress; | - | ||||||||||||||||||
| 847 | s.curve.setType(curve); | - | ||||||||||||||||||
| 848 | s.type = type; | - | ||||||||||||||||||
| 849 | - | |||||||||||||||||||
| 850 | if (orientation == Qt::Horizontal
| 0 | ||||||||||||||||||
| 851 | xSegments.enqueue(s); never executed: xSegments.enqueue(s); | 0 | ||||||||||||||||||
| 852 | else | - | ||||||||||||||||||
| 853 | ySegments.enqueue(s); never executed: ySegments.enqueue(s); | 0 | ||||||||||||||||||
| 854 | - | |||||||||||||||||||
| 855 | while (false) QMessageLogger(__FILE__, 11381150, __PRETTY_FUNCTION__).debug() << "+++ Added a new ScrollSegment: " << s; dead code: QMessageLogger(__FILE__, 1150, __PRETTY_FUNCTION__).debug() << "+++ Added a new ScrollSegment: " << s; | - | ||||||||||||||||||
| 856 | } never executed: end of block | 0 | ||||||||||||||||||
| 857 | - | |||||||||||||||||||
| 858 | - | |||||||||||||||||||
| 859 | - | |||||||||||||||||||
| 860 | - | |||||||||||||||||||
| 861 | - | |||||||||||||||||||
| 862 | void QScrollerPrivate::recalcScrollingSegments(bool forceRecalc) | - | ||||||||||||||||||
| 863 | { | - | ||||||||||||||||||
| 864 | QScroller * const q = q_func(); | - | ||||||||||||||||||
| 865 | QPointF ppm = q->pixelPerMeter(); | - | ||||||||||||||||||
| 866 | - | |||||||||||||||||||
| 867 | releaseVelocity = q->velocity(); | - | ||||||||||||||||||
| 868 | - | |||||||||||||||||||
| 869 | if (forceRecalc || | - | ||||||||||||||||||
| 870 | !scrollingSegmentsValid(Qt::Horizontal) || | - | ||||||||||||||||||
| 871 | !scrollingSegmentsValid(Qt::Vertical)) | - | ||||||||||||||||||
| 872 | createScrollingSegments(releaseVelocity, contentPosition + overshootPosition, ppm); | - | ||||||||||||||||||
| 873 | } | - | ||||||||||||||||||
| 874 | - | |||||||||||||||||||
| 875 | - | |||||||||||||||||||
| 876 | - | |||||||||||||||||||
| 877 | - | |||||||||||||||||||
| 878 | qreal QScrollerPrivate::scrollingSegmentsEndPos(Qt::Orientation orientation) const | - | ||||||||||||||||||
| 879 | { | - | ||||||||||||||||||
| 880 | if (orientation == Qt::Horizontal) { | - | ||||||||||||||||||
| 881 | if (xSegments.isEmpty()) | - | ||||||||||||||||||
| 882 | return contentPosition.x() + overshootPosition.x(); | - | ||||||||||||||||||
| 883 | else | - | ||||||||||||||||||
| 884 | return xSegments.last().stopPos; | - | ||||||||||||||||||
| 885 | } else { | - | ||||||||||||||||||
| 886 | if (ySegments.isEmpty()) | - | ||||||||||||||||||
| 887 | return contentPosition.y() + overshootPosition.y(); | - | ||||||||||||||||||
| 888 | else | - | ||||||||||||||||||
| 889 | return ySegments.last().stopPos; | - | ||||||||||||||||||
| 890 | } | - | ||||||||||||||||||
| 891 | } | - | ||||||||||||||||||
| 892 | - | |||||||||||||||||||
| 893 | - | |||||||||||||||||||
| 894 | - | |||||||||||||||||||
| 895 | - | |||||||||||||||||||
| 896 | bool QScrollerPrivate::scrollingSegmentsValid(Qt::Orientation orientation) const | - | ||||||||||||||||||
| 897 | { | - | ||||||||||||||||||
| 898 | const QQueue<ScrollSegment> *segments; | - | ||||||||||||||||||
| 899 | qreal minPos; | - | ||||||||||||||||||
| 900 | qreal maxPos; | - | ||||||||||||||||||
| 901 | - | |||||||||||||||||||
| 902 | if (orientation == Qt::Horizontal
| 0 | ||||||||||||||||||
| 903 | segments = &xSegments; | - | ||||||||||||||||||
| 904 | minPos = contentPosRange.left(); | - | ||||||||||||||||||
| 905 | maxPos = contentPosRange.right(); | - | ||||||||||||||||||
| 906 | } never executed: else {end of block | 0 | ||||||||||||||||||
| 907 | segments = &ySegments; | - | ||||||||||||||||||
| 908 | minPos = contentPosRange.top(); | - | ||||||||||||||||||
| 909 | maxPos = contentPosRange.bottom(); | - | ||||||||||||||||||
| 910 | } never executed: end of block | 0 | ||||||||||||||||||
| 911 | - | |||||||||||||||||||
| 912 | if (segments->isEmpty()
| 0 | ||||||||||||||||||
| 913 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||||||||
| 914 | - | |||||||||||||||||||
| 915 | const ScrollSegment &last = segments->last(); | - | ||||||||||||||||||
| 916 | qreal stopPos = last.stopPos; | - | ||||||||||||||||||
| 917 | - | |||||||||||||||||||
| 918 | if (last.type == ScrollTypeScrollTo
| 0 | ||||||||||||||||||
| 919 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||||||||
| 920 | - | |||||||||||||||||||
| 921 | if (last.type == ScrollTypeOvershoot
| 0 | ||||||||||||||||||
| 922 | (stopPos != minPos
| 0 | ||||||||||||||||||
| 923 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 924 | - | |||||||||||||||||||
| 925 | if (stopPos < minPos
| 0 | ||||||||||||||||||
| 926 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 927 | - | |||||||||||||||||||
| 928 | if (stopPos == minPos
| 0 | ||||||||||||||||||
| 929 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||||||||
| 930 | - | |||||||||||||||||||
| 931 | qreal nextSnap = nextSnapPos(stopPos, 0, orientation); | - | ||||||||||||||||||
| 932 | if (!qIsNaN(nextSnap)
| 0 | ||||||||||||||||||
| 933 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 934 | - | |||||||||||||||||||
| 935 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||||||||
| 936 | } | - | ||||||||||||||||||
| 937 | - | |||||||||||||||||||
| 938 | - | |||||||||||||||||||
| 939 | - | |||||||||||||||||||
| 940 | - | |||||||||||||||||||
| 941 | void QScrollerPrivate::createScrollToSegments(qreal v, qreal deltaTime, qreal endPos, Qt::Orientation orientation, ScrollType type) | - | ||||||||||||||||||
| 942 | { | - | ||||||||||||||||||
| 943 | (void)v;; | - | ||||||||||||||||||
| 944 | - | |||||||||||||||||||
| 945 | if (orientation == Qt::Horizontal) | - | ||||||||||||||||||
| 946 | xSegments.clear(); | - | ||||||||||||||||||
| 947 | else | - | ||||||||||||||||||
| 948 | ySegments.clear(); | - | ||||||||||||||||||
| 949 | - | |||||||||||||||||||
| 950 | while (false) QMessageLogger(__FILE__, 12331245, __PRETTY_FUNCTION__).debug() << "+++ createScrollToSegments: t:" << deltaTime << "ep:" << endPos << "o:" << int(orientation); dead code: QMessageLogger(__FILE__, 1245, __PRETTY_FUNCTION__).debug() << "+++ createScrollToSegments: t:" << deltaTime << "ep:" << endPos << "o:" << int(orientation); | - | ||||||||||||||||||
| 951 | - | |||||||||||||||||||
| 952 | const QScrollerPropertiesPrivate *sp = properties.d.data(); | - | ||||||||||||||||||
| 953 | - | |||||||||||||||||||
| 954 | qreal startPos = (orientation == Qt::Horizontal) ? contentPosition.x() + overshootPosition.x() | - | ||||||||||||||||||
| 955 | : contentPosition.y() + overshootPosition.y(); | - | ||||||||||||||||||
| 956 | qreal deltaPos = (endPos - startPos) / 2; | - | ||||||||||||||||||
| 957 | - | |||||||||||||||||||
| 958 | pushSegment(type, deltaTime * qreal(0.3), qreal(1.0), startPos, deltaPos, startPos + deltaPos, QEasingCurve::InQuad, orientation); | - | ||||||||||||||||||
| 959 | pushSegment(type, deltaTime * qreal(0.7), qreal(1.0), startPos + deltaPos, deltaPos, endPos, sp->scrollingCurve.type(), orientation); | - | ||||||||||||||||||
| 960 | } | - | ||||||||||||||||||
| 961 | - | |||||||||||||||||||
| 962 | - | |||||||||||||||||||
| 963 | - | |||||||||||||||||||
| 964 | void QScrollerPrivate::createScrollingSegments(qreal v, qreal startPos, | - | ||||||||||||||||||
| 965 | qreal deltaTime, qreal deltaPos, | - | ||||||||||||||||||
| 966 | Qt::Orientation orientation) | - | ||||||||||||||||||
| 967 | { | - | ||||||||||||||||||
| 968 | const QScrollerPropertiesPrivate *sp = properties.d.data(); | - | ||||||||||||||||||
| 969 | - | |||||||||||||||||||
| 970 | QScrollerProperties::OvershootPolicy policy; | - | ||||||||||||||||||
| 971 | qreal minPos; | - | ||||||||||||||||||
| 972 | qreal maxPos; | - | ||||||||||||||||||
| 973 | qreal viewSize; | - | ||||||||||||||||||
| 974 | - | |||||||||||||||||||
| 975 | if (orientation == Qt::Horizontal) { | - | ||||||||||||||||||
| 976 | xSegments.clear(); | - | ||||||||||||||||||
| 977 | policy = sp->hOvershootPolicy; | - | ||||||||||||||||||
| 978 | minPos = contentPosRange.left(); | - | ||||||||||||||||||
| 979 | maxPos = contentPosRange.right(); | - | ||||||||||||||||||
| 980 | viewSize = viewportSize.width(); | - | ||||||||||||||||||
| 981 | } else { | - | ||||||||||||||||||
| 982 | ySegments.clear(); | - | ||||||||||||||||||
| 983 | policy = sp->vOvershootPolicy; | - | ||||||||||||||||||
| 984 | minPos = contentPosRange.top(); | - | ||||||||||||||||||
| 985 | maxPos = contentPosRange.bottom(); | - | ||||||||||||||||||
| 986 | viewSize = viewportSize.height(); | - | ||||||||||||||||||
| 987 | } | - | ||||||||||||||||||
| 988 | - | |||||||||||||||||||
| 989 | bool alwaysOvershoot = (policy == QScrollerProperties::OvershootAlwaysOn); | - | ||||||||||||||||||
| 990 | bool noOvershoot = (policy == QScrollerProperties::OvershootAlwaysOff) || !sp->overshootScrollDistanceFactor; | - | ||||||||||||||||||
| 991 | bool canOvershoot = !noOvershoot && (alwaysOvershoot || maxPos); | - | ||||||||||||||||||
| 992 | - | |||||||||||||||||||
| 993 | while (false) QMessageLogger(__FILE__, 12761288, __PRETTY_FUNCTION__).debug() << "+++ createScrollingSegments: s:" << startPos << "maxPos:" << maxPos << "o:" << int(orientation); dead code: QMessageLogger(__FILE__, 1288, __PRETTY_FUNCTION__).debug() << "+++ createScrollingSegments: s:" << startPos << "maxPos:" << maxPos << "o:" << int(orientation); | - | ||||||||||||||||||
| 994 | - | |||||||||||||||||||
| 995 | while (false) QMessageLogger(__FILE__, 12781290, __PRETTY_FUNCTION__).debug() << "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(); | - | ||||||||||||||||||
| 996 | - | |||||||||||||||||||
| 997 | qreal endPos = startPos + deltaPos; | - | ||||||||||||||||||
| 998 | - | |||||||||||||||||||
| 999 | while (false) QMessageLogger(__FILE__, 12821294, __PRETTY_FUNCTION__).debug() << " Real Delta:" << deltaPos; dead code: QMessageLogger(__FILE__, 1294, __PRETTY_FUNCTION__).debug() << " Real Delta:" << deltaPos; | - | ||||||||||||||||||
| 1000 | - | |||||||||||||||||||
| 1001 | - | |||||||||||||||||||
| 1002 | if ((startPos < minPos && endPos < minPos) || | - | ||||||||||||||||||
| 1003 | (startPos > maxPos && endPos > maxPos)) { | - | ||||||||||||||||||
| 1004 | qreal stopPos = endPos < minPos ? minPos : maxPos; | - | ||||||||||||||||||
| 1005 | qreal oDeltaTime = sp->overshootScrollTime; | - | ||||||||||||||||||
| 1006 | - | |||||||||||||||||||
| 1007 | pushSegment(ScrollTypeOvershoot, oDeltaTime * qreal(0.7), qreal(1.0), startPos, stopPos - startPos, stopPos, sp->scrollingCurve.type(), orientation); | - | ||||||||||||||||||
| 1008 | return; | - | ||||||||||||||||||
| 1009 | } | - | ||||||||||||||||||
| 1010 | - | |||||||||||||||||||
| 1011 | - | |||||||||||||||||||
| 1012 | qreal nextSnap = nextSnapPos(endPos, 0, orientation); | - | ||||||||||||||||||
| 1013 | qreal lowerSnapPos = nextSnapPos(startPos, -1, orientation); | - | ||||||||||||||||||
| 1014 | qreal higherSnapPos = nextSnapPos(startPos, 1, orientation); | - | ||||||||||||||||||
| 1015 | - | |||||||||||||||||||
| 1016 | while (false) QMessageLogger(__FILE__, 12991311, __PRETTY_FUNCTION__).debug() << " Real Delta:" << lowerSnapPos << '-' << nextSnap << '-' <<higherSnapPos; dead code: QMessageLogger(__FILE__, 1311, __PRETTY_FUNCTION__).debug() << " Real Delta:" << lowerSnapPos << '-' << nextSnap << '-' <<higherSnapPos; | - | ||||||||||||||||||
| 1017 | - | |||||||||||||||||||
| 1018 | - | |||||||||||||||||||
| 1019 | if (nextSnap > higherSnapPos || qIsNaN(higherSnapPos)) | - | ||||||||||||||||||
| 1020 | higherSnapPos = nextSnap; | - | ||||||||||||||||||
| 1021 | if (nextSnap < lowerSnapPos || qIsNaN(lowerSnapPos)) | - | ||||||||||||||||||
| 1022 | lowerSnapPos = nextSnap; | - | ||||||||||||||||||
| 1023 | - | |||||||||||||||||||
| 1024 | if (qAbs(v) < sp->minimumVelocity) { | - | ||||||||||||||||||
| 1025 | - | |||||||||||||||||||
| 1026 | while (false) QMessageLogger(__FILE__, 13091321, __PRETTY_FUNCTION__).debug() << "### below minimum Vel" << orientation; dead code: QMessageLogger(__FILE__, 1321, __PRETTY_FUNCTION__).debug() << "### below minimum Vel" << orientation; | - | ||||||||||||||||||
| 1027 | - | |||||||||||||||||||
| 1028 | - | |||||||||||||||||||
| 1029 | if (qIsNaN(nextSnap) || nextSnap == startPos) | - | ||||||||||||||||||
| 1030 | return; | - | ||||||||||||||||||
| 1031 | - | |||||||||||||||||||
| 1032 | - | |||||||||||||||||||
| 1033 | - | |||||||||||||||||||
| 1034 | qreal snapDistance = higherSnapPos - lowerSnapPos; | - | ||||||||||||||||||
| 1035 | - | |||||||||||||||||||
| 1036 | qreal pressDistance = (orientation == Qt::Horizontal) ? | - | ||||||||||||||||||
| 1037 | lastPosition.x() - pressPosition.x() : | - | ||||||||||||||||||
| 1038 | lastPosition.y() - pressPosition.y(); | - | ||||||||||||||||||
| 1039 | - | |||||||||||||||||||
| 1040 | - | |||||||||||||||||||
| 1041 | if (sp->snapPositionRatio == 0.0 || qAbs(pressDistance / sp->snapPositionRatio) > snapDistance) | - | ||||||||||||||||||
| 1042 | endPos = nextSnap; | - | ||||||||||||||||||
| 1043 | else if (pressDistance < 0.0) | - | ||||||||||||||||||
| 1044 | endPos = lowerSnapPos; | - | ||||||||||||||||||
| 1045 | else | - | ||||||||||||||||||
| 1046 | endPos = higherSnapPos; | - | ||||||||||||||||||
| 1047 | - | |||||||||||||||||||
| 1048 | deltaPos = endPos - startPos; | - | ||||||||||||||||||
| 1049 | qreal midPos = startPos + deltaPos * qreal(0.3); | - | ||||||||||||||||||
| 1050 | pushSegment(ScrollTypeFlick, sp->snapTime * qreal(0.3), qreal(1.0), startPos, midPos - startPos, midPos, QEasingCurve::InQuad, orientation); | - | ||||||||||||||||||
| 1051 | pushSegment(ScrollTypeFlick, sp->snapTime * qreal(0.7), qreal(1.0), midPos, endPos - midPos, endPos, sp->scrollingCurve.type(), orientation); | - | ||||||||||||||||||
| 1052 | return; | - | ||||||||||||||||||
| 1053 | } | - | ||||||||||||||||||
| 1054 | - | |||||||||||||||||||
| 1055 | - | |||||||||||||||||||
| 1056 | if (v > 0 && !qIsNaN(higherSnapPos)) { | - | ||||||||||||||||||
| 1057 | - | |||||||||||||||||||
| 1058 | if (endPos - startPos) | - | ||||||||||||||||||
| 1059 | deltaTime *= qAbs((higherSnapPos - startPos) / (endPos - startPos)); | - | ||||||||||||||||||
| 1060 | if (deltaTime > sp->snapTime) | - | ||||||||||||||||||
| 1061 | deltaTime = sp->snapTime; | - | ||||||||||||||||||
| 1062 | endPos = higherSnapPos; | - | ||||||||||||||||||
| 1063 | - | |||||||||||||||||||
| 1064 | } else if (v < 0 && !qIsNaN(lowerSnapPos)) { | - | ||||||||||||||||||
| 1065 | - | |||||||||||||||||||
| 1066 | if (endPos - startPos) | - | ||||||||||||||||||
| 1067 | deltaTime *= qAbs((lowerSnapPos - startPos) / (endPos - startPos)); | - | ||||||||||||||||||
| 1068 | if (deltaTime > sp->snapTime) | - | ||||||||||||||||||
| 1069 | deltaTime = sp->snapTime; | - | ||||||||||||||||||
| 1070 | endPos = lowerSnapPos; | - | ||||||||||||||||||
| 1071 | - | |||||||||||||||||||
| 1072 | - | |||||||||||||||||||
| 1073 | } else if (endPos < minPos || endPos > maxPos) { | - | ||||||||||||||||||
| 1074 | qreal stopPos = endPos < minPos ? minPos : maxPos; | - | ||||||||||||||||||
| 1075 | - | |||||||||||||||||||
| 1076 | while (false) QMessageLogger(__FILE__, 13591371, __PRETTY_FUNCTION__).debug() << "Overshoot: delta:" << (stopPos - startPos); dead code: QMessageLogger(__FILE__, 1371, __PRETTY_FUNCTION__).debug() << "Overshoot: delta:" << (stopPos - startPos); | - | ||||||||||||||||||
| 1077 | - | |||||||||||||||||||
| 1078 | qreal stopProgress = progressForValue(sp->scrollingCurve, qAbs((stopPos - startPos) / deltaPos)); | - | ||||||||||||||||||
| 1079 | - | |||||||||||||||||||
| 1080 | if (!canOvershoot) { | - | ||||||||||||||||||
| 1081 | while (false) QMessageLogger(__FILE__, 13641376, __PRETTY_FUNCTION__).debug() << "Overshoot stopp:" << stopProgress; dead code: QMessageLogger(__FILE__, 1376, __PRETTY_FUNCTION__).debug() << "Overshoot stopp:" << stopProgress; | - | ||||||||||||||||||
| 1082 | - | |||||||||||||||||||
| 1083 | pushSegment(ScrollTypeFlick, deltaTime, stopProgress, startPos, endPos, stopPos, sp->scrollingCurve.type(), orientation); | - | ||||||||||||||||||
| 1084 | } else { | - | ||||||||||||||||||
| 1085 | qreal oDeltaTime = sp->overshootScrollTime; | - | ||||||||||||||||||
| 1086 | qreal oStopProgress = qMin(stopProgress + oDeltaTime * qreal(0.3) / deltaTime, qreal(1)); | - | ||||||||||||||||||
| 1087 | qreal oDistance = startPos + deltaPos * sp->scrollingCurve.valueForProgress(oStopProgress) - stopPos; | - | ||||||||||||||||||
| 1088 | qreal oMaxDistance = qSign(oDistance) * (viewSize * sp->overshootScrollDistanceFactor); | - | ||||||||||||||||||
| 1089 | - | |||||||||||||||||||
| 1090 | while (false) QMessageLogger(__FILE__, 13731385, __PRETTY_FUNCTION__).debug() << "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; | - | ||||||||||||||||||
| 1091 | - | |||||||||||||||||||
| 1092 | if (qAbs(oDistance) > qAbs(oMaxDistance)) { | - | ||||||||||||||||||
| 1093 | oStopProgress = progressForValue(sp->scrollingCurve, qAbs((stopPos + oMaxDistance - startPos) / deltaPos)); | - | ||||||||||||||||||
| 1094 | oDistance = oMaxDistance; | - | ||||||||||||||||||
| 1095 | while (false) QMessageLogger(__FILE__, 13781390, __PRETTY_FUNCTION__).debug() << "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; | - | ||||||||||||||||||
| 1096 | } | - | ||||||||||||||||||
| 1097 | - | |||||||||||||||||||
| 1098 | pushSegment(ScrollTypeFlick, deltaTime, oStopProgress, startPos, deltaPos, stopPos + oDistance, sp->scrollingCurve.type(), orientation); | - | ||||||||||||||||||
| 1099 | pushSegment(ScrollTypeOvershoot, oDeltaTime * qreal(0.7), qreal(1.0), stopPos + oDistance, -oDistance, stopPos, sp->scrollingCurve.type(), orientation); | - | ||||||||||||||||||
| 1100 | } | - | ||||||||||||||||||
| 1101 | return; | - | ||||||||||||||||||
| 1102 | } | - | ||||||||||||||||||
| 1103 | - | |||||||||||||||||||
| 1104 | pushSegment(ScrollTypeFlick, deltaTime, qreal(1.0), startPos, deltaPos, endPos, sp->scrollingCurve.type(), orientation); | - | ||||||||||||||||||
| 1105 | } | - | ||||||||||||||||||
| 1106 | - | |||||||||||||||||||
| 1107 | - | |||||||||||||||||||
| 1108 | void QScrollerPrivate::createScrollingSegments(const QPointF &v, | - | ||||||||||||||||||
| 1109 | const QPointF &startPos, | - | ||||||||||||||||||
| 1110 | const QPointF &ppm) | - | ||||||||||||||||||
| 1111 | { | - | ||||||||||||||||||
| 1112 | const QScrollerPropertiesPrivate *sp = properties.d.data(); | - | ||||||||||||||||||
| 1113 | QVector2D vel(v); | - | ||||||||||||||||||
| 1114 | qreal deltaTime = (qreal(2) * vel.length()) / (sp->decelerationFactor * differentialForProgress(sp->scrollingCurve, 0)); | - | ||||||||||||||||||
| 1115 | QPointF deltaPos = (vel.normalized() * QVector2D(ppm)).toPointF() * deltaTime * deltaTime * qreal(0.5) * sp->decelerationFactor; | - | ||||||||||||||||||
| 1116 | - | |||||||||||||||||||
| 1117 | createScrollingSegments(v.x(), startPos.x(), deltaTime, deltaPos.x(), | - | ||||||||||||||||||
| 1118 | Qt::Horizontal); | - | ||||||||||||||||||
| 1119 | createScrollingSegments(v.y(), startPos.y(), deltaTime, deltaPos.y(), | - | ||||||||||||||||||
| 1120 | Qt::Vertical); | - | ||||||||||||||||||
| 1121 | } | - | ||||||||||||||||||
| 1122 | - | |||||||||||||||||||
| 1123 | - | |||||||||||||||||||
| 1124 | - | |||||||||||||||||||
| 1125 | - | |||||||||||||||||||
| 1126 | - | |||||||||||||||||||
| 1127 | bool QScrollerPrivate::prepareScrolling(const QPointF &position) | - | ||||||||||||||||||
| 1128 | { | - | ||||||||||||||||||
| 1129 | QScrollPrepareEvent spe(position); | - | ||||||||||||||||||
| 1130 | spe.ignore(); | - | ||||||||||||||||||
| 1131 | sendEvent(target, &spe); | - | ||||||||||||||||||
| 1132 | - | |||||||||||||||||||
| 1133 | while (false) QMessageLogger(__FILE__, 14311443, __PRETTY_FUNCTION__).debug() << "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(); | - | ||||||||||||||||||
| 1134 | if (spe.isAccepted()
| 0 | ||||||||||||||||||
| 1135 | QPointF oldContentPos = contentPosition + overshootPosition; | - | ||||||||||||||||||
| 1136 | QPointF contentDelta = spe.contentPos() - oldContentPos; | - | ||||||||||||||||||
| 1137 | - | |||||||||||||||||||
| 1138 | viewportSize = spe.viewportSize(); | - | ||||||||||||||||||
| 1139 | contentPosRange = spe.contentPosRange(); | - | ||||||||||||||||||
| 1140 | if (contentPosRange.width() < 0
| 0 | ||||||||||||||||||
| 1141 | contentPosRange.setWidth(0); never executed: contentPosRange.setWidth(0); | 0 | ||||||||||||||||||
| 1142 | if (contentPosRange.height() < 0
| 0 | ||||||||||||||||||
| 1143 | contentPosRange.setHeight(0); never executed: contentPosRange.setHeight(0); | 0 | ||||||||||||||||||
| 1144 | contentPosition = clampToRect(spe.contentPos(), contentPosRange); | - | ||||||||||||||||||
| 1145 | overshootPosition = spe.contentPos() - contentPosition; | - | ||||||||||||||||||
| 1146 | - | |||||||||||||||||||
| 1147 | - | |||||||||||||||||||
| 1148 | if (contentDelta != QPointF(0, 0)
| 0 | ||||||||||||||||||
| 1149 | - | |||||||||||||||||||
| 1150 | for (int i = 0; i < xSegments.count()
| 0 | ||||||||||||||||||
| 1151 | xSegments[i].startPos -= contentDelta.x(); never executed: xSegments[i].startPos -= contentDelta.x(); | 0 | ||||||||||||||||||
| 1152 | - | |||||||||||||||||||
| 1153 | for (int i = 0; i < ySegments.count()
| 0 | ||||||||||||||||||
| 1154 | ySegments[i].startPos -= contentDelta.y(); never executed: ySegments[i].startPos -= contentDelta.y(); | 0 | ||||||||||||||||||
| 1155 | } never executed: end of block | 0 | ||||||||||||||||||
| 1156 | - | |||||||||||||||||||
| 1157 | if (QWidget *w = qobject_cast<QWidget *>(target)
| 0 | ||||||||||||||||||
| 1158 | setDpiFromWidget(w); never executed: setDpiFromWidget(w); | 0 | ||||||||||||||||||
| 1159 | - | |||||||||||||||||||
| 1160 | if (QGraphicsObject *go = qobject_cast<QGraphicsObject *>(target)
| 0 | ||||||||||||||||||
| 1161 | - | |||||||||||||||||||
| 1162 | if (go->const
| 0 | ||||||||||||||||||
| 1163 | const auto views ().= scene->views(); | - | ||||||||||||||||||
| 1164 | if (!views.
| 0 | ||||||||||||||||||
| 1165 | setDpiFromWidget(go->scene()->views()..first()); never executed: setDpiFromWidget(views.first()); | 0 | ||||||||||||||||||
| 1166 | } never executed: end of block | 0 | ||||||||||||||||||
| 1167 | } never executed: end of block | 0 | ||||||||||||||||||
| 1168 | - | |||||||||||||||||||
| 1169 | - | |||||||||||||||||||
| 1170 | if (state == QScroller::Scrolling
| 0 | ||||||||||||||||||
| 1171 | recalcScrollingSegments(); | - | ||||||||||||||||||
| 1172 | } never executed: end of block | 0 | ||||||||||||||||||
| 1173 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||||||||
| 1174 | } | - | ||||||||||||||||||
| 1175 | - | |||||||||||||||||||
| 1176 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 1177 | } | - | ||||||||||||||||||
| 1178 | - | |||||||||||||||||||
| 1179 | void QScrollerPrivate::handleDrag(const QPointF &position, qint64 timestamp) | - | ||||||||||||||||||
| 1180 | { | - | ||||||||||||||||||
| 1181 | const QScrollerPropertiesPrivate *sp = properties.d.data(); | - | ||||||||||||||||||
| 1182 | - | |||||||||||||||||||
| 1183 | QPointF deltaPixel = position - lastPosition; | - | ||||||||||||||||||
| 1184 | qint64 deltaTime = timestamp - lastTimestamp; | - | ||||||||||||||||||
| 1185 | - | |||||||||||||||||||
| 1186 | if (sp->axisLockThreshold) { | - | ||||||||||||||||||
| 1187 | int dx = qAbs(deltaPixel.x()); | - | ||||||||||||||||||
| 1188 | int dy = qAbs(deltaPixel.y()); | - | ||||||||||||||||||
| 1189 | if (dx || dy) { | - | ||||||||||||||||||
| 1190 | bool vertical = (dy > dx); | - | ||||||||||||||||||
| 1191 | qreal alpha = qreal(vertical ? dx : dy) / qreal(vertical ? dy : dx); | - | ||||||||||||||||||
| 1192 | - | |||||||||||||||||||
| 1193 | if (alpha <= sp->axisLockThreshold) { | - | ||||||||||||||||||
| 1194 | if (vertical) | - | ||||||||||||||||||
| 1195 | deltaPixel.setX(0); | - | ||||||||||||||||||
| 1196 | else | - | ||||||||||||||||||
| 1197 | deltaPixel.setY(0); | - | ||||||||||||||||||
| 1198 | } | - | ||||||||||||||||||
| 1199 | } | - | ||||||||||||||||||
| 1200 | } | - | ||||||||||||||||||
| 1201 | - | |||||||||||||||||||
| 1202 | - | |||||||||||||||||||
| 1203 | updateVelocity(deltaPixel, deltaTime); | - | ||||||||||||||||||
| 1204 | - | |||||||||||||||||||
| 1205 | - | |||||||||||||||||||
| 1206 | QRectF max = contentPosRange; | - | ||||||||||||||||||
| 1207 | bool canScrollX = (max.width() > 0) || (sp->hOvershootPolicy == QScrollerProperties::OvershootAlwaysOn); | - | ||||||||||||||||||
| 1208 | bool canScrollY = (max.height() > 0) || (sp->vOvershootPolicy == QScrollerProperties::OvershootAlwaysOn); | - | ||||||||||||||||||
| 1209 | - | |||||||||||||||||||
| 1210 | if (!canScrollX) { | - | ||||||||||||||||||
| 1211 | deltaPixel.setX(0); | - | ||||||||||||||||||
| 1212 | releaseVelocity.setX(0); | - | ||||||||||||||||||
| 1213 | } | - | ||||||||||||||||||
| 1214 | if (!canScrollY) { | - | ||||||||||||||||||
| 1215 | deltaPixel.setY(0); | - | ||||||||||||||||||
| 1216 | releaseVelocity.setY(0); | - | ||||||||||||||||||
| 1217 | } | - | ||||||||||||||||||
| 1218 | - | |||||||||||||||||||
| 1219 | - | |||||||||||||||||||
| 1220 | - | |||||||||||||||||||
| 1221 | - | |||||||||||||||||||
| 1222 | - | |||||||||||||||||||
| 1223 | - | |||||||||||||||||||
| 1224 | dragDistance += deltaPixel; | - | ||||||||||||||||||
| 1225 | - | |||||||||||||||||||
| 1226 | - | |||||||||||||||||||
| 1227 | - | |||||||||||||||||||
| 1228 | lastPosition = position; | - | ||||||||||||||||||
| 1229 | lastTimestamp = timestamp; | - | ||||||||||||||||||
| 1230 | } | - | ||||||||||||||||||
| 1231 | - | |||||||||||||||||||
| 1232 | bool QScrollerPrivate::pressWhileInactive(const QPointF &position, qint64 timestamp) | - | ||||||||||||||||||
| 1233 | { | - | ||||||||||||||||||
| 1234 | if (prepareScrolling(position)) { | - | ||||||||||||||||||
| 1235 | const QScrollerPropertiesPrivate *sp = properties.d.data(); | - | ||||||||||||||||||
| 1236 | - | |||||||||||||||||||
| 1237 | if (!contentPosRange.isNull() || | - | ||||||||||||||||||
| 1238 | (sp->hOvershootPolicy == QScrollerProperties::OvershootAlwaysOn) || | - | ||||||||||||||||||
| 1239 | (sp->vOvershootPolicy == QScrollerProperties::OvershootAlwaysOn)) { | - | ||||||||||||||||||
| 1240 | - | |||||||||||||||||||
| 1241 | lastPosition = pressPosition = position; | - | ||||||||||||||||||
| 1242 | lastTimestamp = pressTimestamp = timestamp; | - | ||||||||||||||||||
| 1243 | setState(QScroller::Pressed); | - | ||||||||||||||||||
| 1244 | } | - | ||||||||||||||||||
| 1245 | } | - | ||||||||||||||||||
| 1246 | return false; | - | ||||||||||||||||||
| 1247 | } | - | ||||||||||||||||||
| 1248 | - | |||||||||||||||||||
| 1249 | bool QScrollerPrivate::releaseWhilePressed(const QPointF &, qint64) | - | ||||||||||||||||||
| 1250 | { | - | ||||||||||||||||||
| 1251 | if (overshootPosition != QPointF(0.0, 0.0)) { | - | ||||||||||||||||||
| 1252 | setState(QScroller::Scrolling); | - | ||||||||||||||||||
| 1253 | return true; | - | ||||||||||||||||||
| 1254 | } else { | - | ||||||||||||||||||
| 1255 | setState(QScroller::Inactive); | - | ||||||||||||||||||
| 1256 | return false; | - | ||||||||||||||||||
| 1257 | } | - | ||||||||||||||||||
| 1258 | } | - | ||||||||||||||||||
| 1259 | - | |||||||||||||||||||
| 1260 | bool QScrollerPrivate::moveWhilePressed(const QPointF &position, qint64 timestamp) | - | ||||||||||||||||||
| 1261 | { | - | ||||||||||||||||||
| 1262 | QScroller * const q = q_func(); | - | ||||||||||||||||||
| 1263 | const QScrollerPropertiesPrivate *sp = properties.d.data(); | - | ||||||||||||||||||
| 1264 | QPointF ppm = q->pixelPerMeter(); | - | ||||||||||||||||||
| 1265 | - | |||||||||||||||||||
| 1266 | QPointF deltaPixel = position - pressPosition; | - | ||||||||||||||||||
| 1267 | - | |||||||||||||||||||
| 1268 | bool moveAborted = false; | - | ||||||||||||||||||
| 1269 | bool moveStarted = (((deltaPixel / ppm).manhattanLength()) > sp->dragStartDistance); | - | ||||||||||||||||||
| 1270 | - | |||||||||||||||||||
| 1271 | - | |||||||||||||||||||
| 1272 | if (moveStarted) { | - | ||||||||||||||||||
| 1273 | QRectF max = contentPosRange; | - | ||||||||||||||||||
| 1274 | bool canScrollX = (max.width() > 0); | - | ||||||||||||||||||
| 1275 | bool canScrollY = (max.height() > 0); | - | ||||||||||||||||||
| 1276 | - | |||||||||||||||||||
| 1277 | if (sp->hOvershootPolicy == QScrollerProperties::OvershootAlwaysOn) | - | ||||||||||||||||||
| 1278 | canScrollX = true; | - | ||||||||||||||||||
| 1279 | if (sp->vOvershootPolicy == QScrollerProperties::OvershootAlwaysOn) | - | ||||||||||||||||||
| 1280 | canScrollY = true; | - | ||||||||||||||||||
| 1281 | - | |||||||||||||||||||
| 1282 | if (qAbs(deltaPixel.x() / ppm.x()) < qAbs(deltaPixel.y() / ppm.y())) { | - | ||||||||||||||||||
| 1283 | if (!canScrollY) | - | ||||||||||||||||||
| 1284 | moveAborted = true; | - | ||||||||||||||||||
| 1285 | } else { | - | ||||||||||||||||||
| 1286 | if (!canScrollX) | - | ||||||||||||||||||
| 1287 | moveAborted = true; | - | ||||||||||||||||||
| 1288 | } | - | ||||||||||||||||||
| 1289 | } | - | ||||||||||||||||||
| 1290 | - | |||||||||||||||||||
| 1291 | if (moveAborted) { | - | ||||||||||||||||||
| 1292 | setState(QScroller::Inactive); | - | ||||||||||||||||||
| 1293 | moveStarted = false; | - | ||||||||||||||||||
| 1294 | - | |||||||||||||||||||
| 1295 | } else if (moveStarted) { | - | ||||||||||||||||||
| 1296 | setState(QScroller::Dragging); | - | ||||||||||||||||||
| 1297 | - | |||||||||||||||||||
| 1298 | - | |||||||||||||||||||
| 1299 | deltaPixel = deltaPixel - deltaPixel * (sp->dragStartDistance / deltaPixel.manhattanLength()); | - | ||||||||||||||||||
| 1300 | - | |||||||||||||||||||
| 1301 | if (deltaPixel != QPointF(0, 0)) { | - | ||||||||||||||||||
| 1302 | - | |||||||||||||||||||
| 1303 | handleDrag(pressPosition + deltaPixel, timestamp); | - | ||||||||||||||||||
| 1304 | } | - | ||||||||||||||||||
| 1305 | } | - | ||||||||||||||||||
| 1306 | return moveStarted; | - | ||||||||||||||||||
| 1307 | } | - | ||||||||||||||||||
| 1308 | - | |||||||||||||||||||
| 1309 | bool QScrollerPrivate::moveWhileDragging(const QPointF &position, qint64 timestamp) | - | ||||||||||||||||||
| 1310 | { | - | ||||||||||||||||||
| 1311 | - | |||||||||||||||||||
| 1312 | handleDrag(position, timestamp); | - | ||||||||||||||||||
| 1313 | return true; | - | ||||||||||||||||||
| 1314 | } | - | ||||||||||||||||||
| 1315 | - | |||||||||||||||||||
| 1316 | void QScrollerPrivate::timerEventWhileDragging() | - | ||||||||||||||||||
| 1317 | { | - | ||||||||||||||||||
| 1318 | if (dragDistance != QPointF(0, 0)) { | - | ||||||||||||||||||
| 1319 | while (false) QMessageLogger(__FILE__, 16141629, __PRETTY_FUNCTION__).debug() << "QScroller::timerEventWhileDragging() -- dragDistance:" << dragDistance; dead code: QMessageLogger(__FILE__, 1629, __PRETTY_FUNCTION__).debug() << "QScroller::timerEventWhileDragging() -- dragDistance:" << dragDistance; | - | ||||||||||||||||||
| 1320 | - | |||||||||||||||||||
| 1321 | setContentPositionHelperDragging(-dragDistance); | - | ||||||||||||||||||
| 1322 | dragDistance = QPointF(0, 0); | - | ||||||||||||||||||
| 1323 | } | - | ||||||||||||||||||
| 1324 | } | - | ||||||||||||||||||
| 1325 | - | |||||||||||||||||||
| 1326 | bool QScrollerPrivate::releaseWhileDragging(const QPointF &position, qint64 timestamp) | - | ||||||||||||||||||
| 1327 | { | - | ||||||||||||||||||
| 1328 | QScroller * const q = q_func(); | - | ||||||||||||||||||
| 1329 | const QScrollerPropertiesPrivate *sp = properties.d.data(); | - | ||||||||||||||||||
| 1330 | - | |||||||||||||||||||
| 1331 | - | |||||||||||||||||||
| 1332 | handleDrag(position, timestamp); | - | ||||||||||||||||||
| 1333 | - | |||||||||||||||||||
| 1334 | - | |||||||||||||||||||
| 1335 | - | |||||||||||||||||||
| 1336 | QPointF deltaPixel = position - pressPosition; | - | ||||||||||||||||||
| 1337 | if (((deltaPixel / q->pixelPerMeter()).manhattanLength()) > sp->dragStartDistance) { | - | ||||||||||||||||||
| 1338 | - | |||||||||||||||||||
| 1339 | - | |||||||||||||||||||
| 1340 | if ((oldVelocity != QPointF(0, 0)) && sp->acceleratingFlickMaximumTime && | - | ||||||||||||||||||
| 1341 | ((timestamp - pressTimestamp) < qint64(sp->acceleratingFlickMaximumTime * 1000))) { | - | ||||||||||||||||||
| 1342 | - | |||||||||||||||||||
| 1343 | - | |||||||||||||||||||
| 1344 | int signX = 0, signY = 0; | - | ||||||||||||||||||
| 1345 | if (releaseVelocity.x()) | - | ||||||||||||||||||
| 1346 | signX = (releaseVelocity.x() > 0) == (oldVelocity.x() > 0) ? 1 : -1; | - | ||||||||||||||||||
| 1347 | if (releaseVelocity.y()) | - | ||||||||||||||||||
| 1348 | signY = (releaseVelocity.y() > 0) == (oldVelocity.y() > 0) ? 1 : -1; | - | ||||||||||||||||||
| 1349 | - | |||||||||||||||||||
| 1350 | if (signX > 0) | - | ||||||||||||||||||
| 1351 | releaseVelocity.setX(qBound(-sp->maximumVelocity, | - | ||||||||||||||||||
| 1352 | oldVelocity.x() * sp->acceleratingFlickSpeedupFactor, | - | ||||||||||||||||||
| 1353 | sp->maximumVelocity)); | - | ||||||||||||||||||
| 1354 | if (signY > 0) | - | ||||||||||||||||||
| 1355 | releaseVelocity.setY(qBound(-sp->maximumVelocity, | - | ||||||||||||||||||
| 1356 | oldVelocity.y() * sp->acceleratingFlickSpeedupFactor, | - | ||||||||||||||||||
| 1357 | sp->maximumVelocity)); | - | ||||||||||||||||||
| 1358 | } | - | ||||||||||||||||||
| 1359 | } | - | ||||||||||||||||||
| 1360 | - | |||||||||||||||||||
| 1361 | QPointF ppm = q->pixelPerMeter(); | - | ||||||||||||||||||
| 1362 | createScrollingSegments(releaseVelocity, contentPosition + overshootPosition, ppm); | - | ||||||||||||||||||
| 1363 | - | |||||||||||||||||||
| 1364 | while (false) QMessageLogger(__FILE__, 16591674, __PRETTY_FUNCTION__).debug() << "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; | - | ||||||||||||||||||
| 1365 | - | |||||||||||||||||||
| 1366 | if (xSegments.isEmpty() && ySegments.isEmpty()) | - | ||||||||||||||||||
| 1367 | setState(QScroller::Inactive); | - | ||||||||||||||||||
| 1368 | else | - | ||||||||||||||||||
| 1369 | setState(QScroller::Scrolling); | - | ||||||||||||||||||
| 1370 | - | |||||||||||||||||||
| 1371 | return true; | - | ||||||||||||||||||
| 1372 | } | - | ||||||||||||||||||
| 1373 | - | |||||||||||||||||||
| 1374 | void QScrollerPrivate::timerEventWhileScrolling() | - | ||||||||||||||||||
| 1375 | { | - | ||||||||||||||||||
| 1376 | while (false) QMessageLogger(__FILE__, 16711686, __PRETTY_FUNCTION__).debug("QScroller::timerEventWhileScrolling()"); dead code: QMessageLogger(__FILE__, 1686, __PRETTY_FUNCTION__).debug("QScroller::timerEventWhileScrolling()"); | - | ||||||||||||||||||
| 1377 | - | |||||||||||||||||||
| 1378 | setContentPositionHelperScrolling(); | - | ||||||||||||||||||
| 1379 | if (xSegments.isEmpty() && ySegments.isEmpty()) | - | ||||||||||||||||||
| 1380 | setState(QScroller::Inactive); | - | ||||||||||||||||||
| 1381 | } | - | ||||||||||||||||||
| 1382 | - | |||||||||||||||||||
| 1383 | bool QScrollerPrivate::pressWhileScrolling(const QPointF &position, qint64 timestamp) | - | ||||||||||||||||||
| 1384 | { | - | ||||||||||||||||||
| 1385 | QScroller * const q = q_func(); | - | ||||||||||||||||||
| 1386 | - | |||||||||||||||||||
| 1387 | if ((q->velocity() <= properties.d->maximumClickThroughVelocity) && | - | ||||||||||||||||||
| 1388 | (overshootPosition == QPointF(0.0, 0.0))) { | - | ||||||||||||||||||
| 1389 | setState(QScroller::Inactive); | - | ||||||||||||||||||
| 1390 | return false; | - | ||||||||||||||||||
| 1391 | } else { | - | ||||||||||||||||||
| 1392 | lastPosition = pressPosition = position; | - | ||||||||||||||||||
| 1393 | lastTimestamp = pressTimestamp = timestamp; | - | ||||||||||||||||||
| 1394 | setState(QScroller::Pressed); | - | ||||||||||||||||||
| 1395 | setState(QScroller::Dragging); | - | ||||||||||||||||||
| 1396 | return true; | - | ||||||||||||||||||
| 1397 | } | - | ||||||||||||||||||
| 1398 | } | - | ||||||||||||||||||
| 1399 | - | |||||||||||||||||||
| 1400 | - | |||||||||||||||||||
| 1401 | - | |||||||||||||||||||
| 1402 | - | |||||||||||||||||||
| 1403 | void QScrollerPrivate::setState(QScroller::State newstate) | - | ||||||||||||||||||
| 1404 | { | - | ||||||||||||||||||
| 1405 | QScroller * const q = q_func(); | - | ||||||||||||||||||
| 1406 | bool sendLastScroll = false; | - | ||||||||||||||||||
| 1407 | - | |||||||||||||||||||
| 1408 | if (state == newstate) | - | ||||||||||||||||||
| 1409 | return; | - | ||||||||||||||||||
| 1410 | - | |||||||||||||||||||
| 1411 | while (false) QMessageLogger(__FILE__, 17061721, __PRETTY_FUNCTION__).debug() << q << "QScroller::setState(" << stateName(newstate) << ')'; dead code: QMessageLogger(__FILE__, 1721, __PRETTY_FUNCTION__).debug() << q << "QScroller::setState(" << stateName(newstate) << ')'; | - | ||||||||||||||||||
| 1412 | - | |||||||||||||||||||
| 1413 | switch (newstate) { | - | ||||||||||||||||||
| 1414 | case QScroller::Inactive: | - | ||||||||||||||||||
| 1415 | - | |||||||||||||||||||
| 1416 | scrollTimer->stop(); | - | ||||||||||||||||||
| 1417 | - | |||||||||||||||||||
| 1418 | - | |||||||||||||||||||
| 1419 | - | |||||||||||||||||||
| 1420 | if (!firstScroll) | - | ||||||||||||||||||
| 1421 | sendLastScroll = true; | - | ||||||||||||||||||
| 1422 | - | |||||||||||||||||||
| 1423 | releaseVelocity = QPointF(0, 0); | - | ||||||||||||||||||
| 1424 | break; | - | ||||||||||||||||||
| 1425 | - | |||||||||||||||||||
| 1426 | case QScroller::Pressed: | - | ||||||||||||||||||
| 1427 | - | |||||||||||||||||||
| 1428 | scrollTimer->stop(); | - | ||||||||||||||||||
| 1429 | - | |||||||||||||||||||
| 1430 | - | |||||||||||||||||||
| 1431 | oldVelocity = releaseVelocity; | - | ||||||||||||||||||
| 1432 | releaseVelocity = QPointF(0, 0); | - | ||||||||||||||||||
| 1433 | break; | - | ||||||||||||||||||
| 1434 | - | |||||||||||||||||||
| 1435 | case QScroller::Dragging: | - | ||||||||||||||||||
| 1436 | dragDistance = QPointF(0, 0); | - | ||||||||||||||||||
| 1437 | - | |||||||||||||||||||
| 1438 | if (state == QScroller::Pressed) | - | ||||||||||||||||||
| 1439 | scrollTimer->start(); | - | ||||||||||||||||||
| 1440 | - | |||||||||||||||||||
| 1441 | break; | - | ||||||||||||||||||
| 1442 | - | |||||||||||||||||||
| 1443 | case QScroller::Scrolling: | - | ||||||||||||||||||
| 1444 | - | |||||||||||||||||||
| 1445 | scrollTimer->start(); | - | ||||||||||||||||||
| 1446 | - | |||||||||||||||||||
| 1447 | break; | - | ||||||||||||||||||
| 1448 | } | - | ||||||||||||||||||
| 1449 | - | |||||||||||||||||||
| 1450 | qSwap(state, newstate); | - | ||||||||||||||||||
| 1451 | - | |||||||||||||||||||
| 1452 | if (sendLastScroll) { | - | ||||||||||||||||||
| 1453 | QScrollEvent se(contentPosition, overshootPosition, QScrollEvent::ScrollFinished); | - | ||||||||||||||||||
| 1454 | sendEvent(target, &se); | - | ||||||||||||||||||
| 1455 | firstScroll = true; | - | ||||||||||||||||||
| 1456 | } | - | ||||||||||||||||||
| 1457 | if (state == QScroller::Dragging || state == QScroller::Scrolling) | - | ||||||||||||||||||
| 1458 | qt_activeScrollers()->insert(q); | - | ||||||||||||||||||
| 1459 | else | - | ||||||||||||||||||
| 1460 | qt_activeScrollers()->remove(q); | - | ||||||||||||||||||
| 1461 | q->stateChanged(state); | - | ||||||||||||||||||
| 1462 | } | - | ||||||||||||||||||
| 1463 | void QScrollerPrivate::setContentPositionHelperDragging(const QPointF &deltaPos) | - | ||||||||||||||||||
| 1464 | { | - | ||||||||||||||||||
| 1465 | const QScrollerPropertiesPrivate *sp = properties.d.data(); | - | ||||||||||||||||||
| 1466 | - | |||||||||||||||||||
| 1467 | if (sp->overshootDragResistanceFactor) | - | ||||||||||||||||||
| 1468 | overshootPosition /= sp->overshootDragResistanceFactor; | - | ||||||||||||||||||
| 1469 | - | |||||||||||||||||||
| 1470 | QPointF oldPos = contentPosition + overshootPosition; | - | ||||||||||||||||||
| 1471 | QPointF newPos = oldPos + deltaPos; | - | ||||||||||||||||||
| 1472 | - | |||||||||||||||||||
| 1473 | while (false) QMessageLogger(__FILE__, 17821797, __PRETTY_FUNCTION__).debug() << "QScroller::setContentPositionHelperDragging(" << deltaPos << " [pix])"; dead code: QMessageLogger(__FILE__, 1797, __PRETTY_FUNCTION__).debug() << "QScroller::setContentPositionHelperDragging(" << deltaPos << " [pix])"; | - | ||||||||||||||||||
| 1474 | while (false) QMessageLogger(__FILE__, 17831798, __PRETTY_FUNCTION__).debug() << " --> overshoot:" << overshootPosition << "- old pos:" << oldPos << "- new pos:" << newPos; dead code: QMessageLogger(__FILE__, 1798, __PRETTY_FUNCTION__).debug() << " --> overshoot:" << overshootPosition << "- old pos:" << oldPos << "- new pos:" << newPos; | - | ||||||||||||||||||
| 1475 | - | |||||||||||||||||||
| 1476 | QPointF oldClampedPos = clampToRect(oldPos, contentPosRange); | - | ||||||||||||||||||
| 1477 | QPointF newClampedPos = clampToRect(newPos, contentPosRange); | - | ||||||||||||||||||
| 1478 | - | |||||||||||||||||||
| 1479 | - | |||||||||||||||||||
| 1480 | bool alwaysOvershootX = (sp->hOvershootPolicy == QScrollerProperties::OvershootAlwaysOn); | - | ||||||||||||||||||
| 1481 | bool alwaysOvershootY = (sp->vOvershootPolicy == QScrollerProperties::OvershootAlwaysOn); | - | ||||||||||||||||||
| 1482 | bool noOvershootX = (sp->hOvershootPolicy == QScrollerProperties::OvershootAlwaysOff) || | - | ||||||||||||||||||
| 1483 | ((state == QScroller::Dragging) && !sp->overshootDragResistanceFactor) || | - | ||||||||||||||||||
| 1484 | !sp->overshootDragDistanceFactor; | - | ||||||||||||||||||
| 1485 | bool noOvershootY = (sp->vOvershootPolicy == QScrollerProperties::OvershootAlwaysOff) || | - | ||||||||||||||||||
| 1486 | ((state == QScroller::Dragging) && !sp->overshootDragResistanceFactor) || | - | ||||||||||||||||||
| 1487 | !sp->overshootDragDistanceFactor; | - | ||||||||||||||||||
| 1488 | bool canOvershootX = !noOvershootX && (alwaysOvershootX || contentPosRange.width()); | - | ||||||||||||||||||
| 1489 | bool canOvershootY = !noOvershootY && (alwaysOvershootY || contentPosRange.height()); | - | ||||||||||||||||||
| 1490 | - | |||||||||||||||||||
| 1491 | qreal oldOvershootX = (canOvershootX) ? oldPos.x() - oldClampedPos.x() : 0; | - | ||||||||||||||||||
| 1492 | qreal oldOvershootY = (canOvershootY) ? oldPos.y() - oldClampedPos.y() : 0; | - | ||||||||||||||||||
| 1493 | - | |||||||||||||||||||
| 1494 | qreal newOvershootX = (canOvershootX) ? newPos.x() - newClampedPos.x() : 0; | - | ||||||||||||||||||
| 1495 | qreal newOvershootY = (canOvershootY) ? newPos.y() - newClampedPos.y() : 0; | - | ||||||||||||||||||
| 1496 | - | |||||||||||||||||||
| 1497 | qreal maxOvershootX = viewportSize.width() * sp->overshootDragDistanceFactor; | - | ||||||||||||||||||
| 1498 | qreal maxOvershootY = viewportSize.height() * sp->overshootDragDistanceFactor; | - | ||||||||||||||||||
| 1499 | - | |||||||||||||||||||
| 1500 | while (false) QMessageLogger(__FILE__, 18091824, __PRETTY_FUNCTION__).debug() << " --> 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; | - | ||||||||||||||||||
| 1501 | while (false) QMessageLogger(__FILE__, 18101825, __PRETTY_FUNCTION__).debug() << " --> canOS:" << canOvershootX << "newOS:" << newOvershootX << "maxOS:" << maxOvershootX; dead code: QMessageLogger(__FILE__, 1825, __PRETTY_FUNCTION__).debug() << " --> canOS:" << canOvershootX << "newOS:" << newOvershootX << "maxOS:" << maxOvershootX; | - | ||||||||||||||||||
| 1502 | - | |||||||||||||||||||
| 1503 | if (sp->overshootDragResistanceFactor) { | - | ||||||||||||||||||
| 1504 | oldOvershootX *= sp->overshootDragResistanceFactor; | - | ||||||||||||||||||
| 1505 | oldOvershootY *= sp->overshootDragResistanceFactor; | - | ||||||||||||||||||
| 1506 | newOvershootX *= sp->overshootDragResistanceFactor; | - | ||||||||||||||||||
| 1507 | newOvershootY *= sp->overshootDragResistanceFactor; | - | ||||||||||||||||||
| 1508 | } | - | ||||||||||||||||||
| 1509 | - | |||||||||||||||||||
| 1510 | - | |||||||||||||||||||
| 1511 | - | |||||||||||||||||||
| 1512 | newOvershootX = qBound(-maxOvershootX, newOvershootX, maxOvershootX); | - | ||||||||||||||||||
| 1513 | newOvershootY = qBound(-maxOvershootY, newOvershootY, maxOvershootY); | - | ||||||||||||||||||
| 1514 | - | |||||||||||||||||||
| 1515 | overshootPosition.setX(newOvershootX); | - | ||||||||||||||||||
| 1516 | overshootPosition.setY(newOvershootY); | - | ||||||||||||||||||
| 1517 | contentPosition = newClampedPos; | - | ||||||||||||||||||
| 1518 | - | |||||||||||||||||||
| 1519 | QScrollEvent se(contentPosition, overshootPosition, firstScroll ? QScrollEvent::ScrollStarted : QScrollEvent::ScrollUpdated); | - | ||||||||||||||||||
| 1520 | sendEvent(target, &se); | - | ||||||||||||||||||
| 1521 | firstScroll = false; | - | ||||||||||||||||||
| 1522 | - | |||||||||||||||||||
| 1523 | while (false) QMessageLogger(__FILE__, 18321847, __PRETTY_FUNCTION__).debug() << " --> new position:" << newClampedPos << "- new overshoot:" << overshootPosition << dead code: QMessageLogger(__FILE__, 1847, __PRETTY_FUNCTION__).debug() << " --> new position:" << newClampedPos << "- new overshoot:" << overshootPosition << "- overshoot x/y?:" << overshootPosition; | - | ||||||||||||||||||
| 1524 | "- overshoot x/y?:" << overshootPosition; dead code: QMessageLogger(__FILE__, 1847, __PRETTY_FUNCTION__).debug() << " --> new position:" << newClampedPos << "- new overshoot:" << overshootPosition << "- overshoot x/y?:" << overshootPosition; | - | ||||||||||||||||||
| 1525 | } | - | ||||||||||||||||||
| 1526 | - | |||||||||||||||||||
| 1527 | - | |||||||||||||||||||
| 1528 | qreal QScrollerPrivate::nextSegmentPosition(QQueue<ScrollSegment> &segments, qint64 now, qreal oldPos) | - | ||||||||||||||||||
| 1529 | { | - | ||||||||||||||||||
| 1530 | qreal pos = oldPos; | - | ||||||||||||||||||
| 1531 | - | |||||||||||||||||||
| 1532 | - | |||||||||||||||||||
| 1533 | while (!segments.isEmpty()) { | - | ||||||||||||||||||
| 1534 | const ScrollSegment s = segments.head(); | - | ||||||||||||||||||
| 1535 | - | |||||||||||||||||||
| 1536 | if ((s.startTime + s.deltaTime * s.stopProgress) <= now) { | - | ||||||||||||||||||
| 1537 | segments.dequeue(); | - | ||||||||||||||||||
| 1538 | pos = s.stopPos; | - | ||||||||||||||||||
| 1539 | } else if (s.startTime <= now) { | - | ||||||||||||||||||
| 1540 | qreal progress = qreal(now - s.startTime) / qreal(s.deltaTime); | - | ||||||||||||||||||
| 1541 | pos = s.startPos + s.deltaPos * s.curve.valueForProgress(progress); | - | ||||||||||||||||||
| 1542 | if (s.deltaPos > 0 ? pos > s.stopPos : pos < s.stopPos) { | - | ||||||||||||||||||
| 1543 | segments.dequeue(); | - | ||||||||||||||||||
| 1544 | pos = s.stopPos; | - | ||||||||||||||||||
| 1545 | } else { | - | ||||||||||||||||||
| 1546 | break; | - | ||||||||||||||||||
| 1547 | } | - | ||||||||||||||||||
| 1548 | } else { | - | ||||||||||||||||||
| 1549 | break; | - | ||||||||||||||||||
| 1550 | } | - | ||||||||||||||||||
| 1551 | } | - | ||||||||||||||||||
| 1552 | return pos; | - | ||||||||||||||||||
| 1553 | } | - | ||||||||||||||||||
| 1554 | - | |||||||||||||||||||
| 1555 | void QScrollerPrivate::setContentPositionHelperScrolling() | - | ||||||||||||||||||
| 1556 | { | - | ||||||||||||||||||
| 1557 | qint64 now = monotonicTimer.elapsed(); | - | ||||||||||||||||||
| 1558 | QPointF newPos = contentPosition + overshootPosition; | - | ||||||||||||||||||
| 1559 | - | |||||||||||||||||||
| 1560 | newPos.setX(nextSegmentPosition(xSegments, now, newPos.x())); | - | ||||||||||||||||||
| 1561 | newPos.setY(nextSegmentPosition(ySegments, now, newPos.y())); | - | ||||||||||||||||||
| 1562 | - | |||||||||||||||||||
| 1563 | - | |||||||||||||||||||
| 1564 | while (false) QMessageLogger(__FILE__, 18731888, __PRETTY_FUNCTION__).debug() << "QScroller::setContentPositionHelperScrolling()\n" dead code: QMessageLogger(__FILE__, 1888, __PRETTY_FUNCTION__).debug() << "QScroller::setContentPositionHelperScrolling()\n" " --> overshoot:" << overshootPosition << "- new pos:" << newPos; | - | ||||||||||||||||||
| 1565 | " --> overshoot:" << overshootPosition << "- new pos:" << newPos; dead code: QMessageLogger(__FILE__, 1888, __PRETTY_FUNCTION__).debug() << "QScroller::setContentPositionHelperScrolling()\n" " --> overshoot:" << overshootPosition << "- new pos:" << newPos; | - | ||||||||||||||||||
| 1566 | - | |||||||||||||||||||
| 1567 | QPointF newClampedPos = clampToRect(newPos, contentPosRange); | - | ||||||||||||||||||
| 1568 | - | |||||||||||||||||||
| 1569 | overshootPosition = newPos - newClampedPos; | - | ||||||||||||||||||
| 1570 | contentPosition = newClampedPos; | - | ||||||||||||||||||
| 1571 | - | |||||||||||||||||||
| 1572 | QScrollEvent se(contentPosition, overshootPosition, firstScroll ? QScrollEvent::ScrollStarted : QScrollEvent::ScrollUpdated); | - | ||||||||||||||||||
| 1573 | sendEvent(target, &se); | - | ||||||||||||||||||
| 1574 | firstScroll = false; | - | ||||||||||||||||||
| 1575 | - | |||||||||||||||||||
| 1576 | while (false) QMessageLogger(__FILE__, 18851900, __PRETTY_FUNCTION__).debug() << " --> new position:" << newClampedPos << "- new overshoot:" << overshootPosition; dead code: QMessageLogger(__FILE__, 1900, __PRETTY_FUNCTION__).debug() << " --> new position:" << newClampedPos << "- new overshoot:" << overshootPosition; | - | ||||||||||||||||||
| 1577 | } | - | ||||||||||||||||||
| 1578 | qreal QScrollerPrivate::nextSnapPos(qreal p, int dir, Qt::Orientation orientation) const | - | ||||||||||||||||||
| 1579 | { | - | ||||||||||||||||||
| 1580 | qreal bestSnapPos = (::qQNaN()); | - | ||||||||||||||||||
| 1581 | qreal bestSnapPosDist = (::qInf()); | - | ||||||||||||||||||
| 1582 | - | |||||||||||||||||||
| 1583 | qreal minPos; | - | ||||||||||||||||||
| 1584 | qreal maxPos; | - | ||||||||||||||||||
| 1585 | - | |||||||||||||||||||
| 1586 | if (orientation == Qt::Horizontal
| 0 | ||||||||||||||||||
| 1587 | minPos = contentPosRange.left(); | - | ||||||||||||||||||
| 1588 | maxPos = contentPosRange.right(); | - | ||||||||||||||||||
| 1589 | } never executed: else {end of block | 0 | ||||||||||||||||||
| 1590 | minPos = contentPosRange.top(); | - | ||||||||||||||||||
| 1591 | maxPos = contentPosRange.bottom(); | - | ||||||||||||||||||
| 1592 | } never executed: end of block | 0 | ||||||||||||||||||
| 1593 | - | |||||||||||||||||||
| 1594 | if (orientation == Qt::Horizontal
| 0 | ||||||||||||||||||
| 1595 | - | |||||||||||||||||||
| 1596 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(snapPositionsX)>::type> _container_((snapPositionsX)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (qreal snapPos = *_container_.i; _container_.control; _container_.control = 0) { | - | ||||||||||||||||||
| 1597 | qreal snapPosDist = snapPos - p; | - | ||||||||||||||||||
| 1598 | if ((dir > 0
| 0 | ||||||||||||||||||
| 1599 | (dir < 0
| 0 | ||||||||||||||||||
| 1600 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 1601 | if (snapPos < minPos
| 0 | ||||||||||||||||||
| 1602 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 1603 | - | |||||||||||||||||||
| 1604 | if (qIsNaN(bestSnapPos)
| 0 | ||||||||||||||||||
| 1605 | qAbs(snapPosDist) < bestSnapPosDist
| 0 | ||||||||||||||||||
| 1606 | bestSnapPos = snapPos; | - | ||||||||||||||||||
| 1607 | bestSnapPosDist = qAbs(snapPosDist); | - | ||||||||||||||||||
| 1608 | } never executed: end of block | 0 | ||||||||||||||||||
| 1609 | } never executed: end of block | 0 | ||||||||||||||||||
| 1610 | - | |||||||||||||||||||
| 1611 | - | |||||||||||||||||||
| 1612 | if (snapIntervalX > 0.0
| 0 | ||||||||||||||||||
| 1613 | qreal first = minPos + snapFirstX; | - | ||||||||||||||||||
| 1614 | qreal snapPos; | - | ||||||||||||||||||
| 1615 | if (dir > 0
| 0 | ||||||||||||||||||
| 1616 | snapPos = qCeil((p - first) / snapIntervalX) * snapIntervalX + first; never executed: snapPos = qCeil((p - first) / snapIntervalX) * snapIntervalX + first; | 0 | ||||||||||||||||||
| 1617 | else if (dir < 0
| 0 | ||||||||||||||||||
| 1618 | snapPos = qFloor((p - first) / snapIntervalX) * snapIntervalX + first; never executed: snapPos = qFloor((p - first) / snapIntervalX) * snapIntervalX + first; | 0 | ||||||||||||||||||
| 1619 | else if (p <= first
| 0 | ||||||||||||||||||
| 1620 | snapPos = first; never executed: snapPos = first; | 0 | ||||||||||||||||||
| 1621 | else | - | ||||||||||||||||||
| 1622 | { | - | ||||||||||||||||||
| 1623 | qreal last = qFloor((maxPos - first) / snapIntervalX) * snapIntervalX + first; | - | ||||||||||||||||||
| 1624 | if (p >= last
| 0 | ||||||||||||||||||
| 1625 | snapPos = last; never executed: snapPos = last; | 0 | ||||||||||||||||||
| 1626 | else | - | ||||||||||||||||||
| 1627 | snapPos = qRound((p - first) / snapIntervalX) * snapIntervalX + first; never executed: snapPos = qRound((p - first) / snapIntervalX) * snapIntervalX + first; | 0 | ||||||||||||||||||
| 1628 | } | - | ||||||||||||||||||
| 1629 | - | |||||||||||||||||||
| 1630 | if (snapPos >= first
| 0 | ||||||||||||||||||
| 1631 | qreal snapPosDist = snapPos - p; | - | ||||||||||||||||||
| 1632 | - | |||||||||||||||||||
| 1633 | if (qIsNaN(bestSnapPos)
| 0 | ||||||||||||||||||
| 1634 | qAbs(snapPosDist) < bestSnapPosDist
| 0 | ||||||||||||||||||
| 1635 | bestSnapPos = snapPos; | - | ||||||||||||||||||
| 1636 | bestSnapPosDist = qAbs(snapPosDist); | - | ||||||||||||||||||
| 1637 | } never executed: end of block | 0 | ||||||||||||||||||
| 1638 | } never executed: end of block | 0 | ||||||||||||||||||
| 1639 | } never executed: end of block | 0 | ||||||||||||||||||
| 1640 | - | |||||||||||||||||||
| 1641 | } never executed: else {end of block | 0 | ||||||||||||||||||
| 1642 | - | |||||||||||||||||||
| 1643 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(snapPositionsY)>::type> _container_((snapPositionsY)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (qreal snapPos = *_container_.i; _container_.control; _container_.control = 0) { | - | ||||||||||||||||||
| 1644 | qreal snapPosDist = snapPos - p; | - | ||||||||||||||||||
| 1645 | if ((dir > 0
| 0 | ||||||||||||||||||
| 1646 | (dir < 0
| 0 | ||||||||||||||||||
| 1647 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 1648 | if (snapPos < minPos
| 0 | ||||||||||||||||||
| 1649 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 1650 | - | |||||||||||||||||||
| 1651 | if (qIsNaN(bestSnapPos)
| 0 | ||||||||||||||||||
| 1652 | qAbs(snapPosDist) < bestSnapPosDist
| 0 | ||||||||||||||||||
| 1653 | bestSnapPos = snapPos; | - | ||||||||||||||||||
| 1654 | bestSnapPosDist = qAbs(snapPosDist); | - | ||||||||||||||||||
| 1655 | } never executed: end of block | 0 | ||||||||||||||||||
| 1656 | } never executed: end of block | 0 | ||||||||||||||||||
| 1657 | - | |||||||||||||||||||
| 1658 | - | |||||||||||||||||||
| 1659 | if (snapIntervalY > 0.0
| 0 | ||||||||||||||||||
| 1660 | qreal first = minPos + snapFirstY; | - | ||||||||||||||||||
| 1661 | qreal snapPos; | - | ||||||||||||||||||
| 1662 | if (dir > 0
| 0 | ||||||||||||||||||
| 1663 | snapPos = qCeil((p - first) / snapIntervalY) * snapIntervalY + first; never executed: snapPos = qCeil((p - first) / snapIntervalY) * snapIntervalY + first; | 0 | ||||||||||||||||||
| 1664 | else if (dir < 0
| 0 | ||||||||||||||||||
| 1665 | snapPos = qFloor((p - first) / snapIntervalY) * snapIntervalY + first; never executed: snapPos = qFloor((p - first) / snapIntervalY) * snapIntervalY + first; | 0 | ||||||||||||||||||
| 1666 | else if (p <= first
| 0 | ||||||||||||||||||
| 1667 | snapPos = first; never executed: snapPos = first; | 0 | ||||||||||||||||||
| 1668 | else | - | ||||||||||||||||||
| 1669 | { | - | ||||||||||||||||||
| 1670 | qreal last = qFloor((maxPos - first) / snapIntervalY) * snapIntervalY + first; | - | ||||||||||||||||||
| 1671 | if (p >= last
| 0 | ||||||||||||||||||
| 1672 | snapPos = last; never executed: snapPos = last; | 0 | ||||||||||||||||||
| 1673 | else | - | ||||||||||||||||||
| 1674 | snapPos = qRound((p - first) / snapIntervalY) * snapIntervalY + first; never executed: snapPos = qRound((p - first) / snapIntervalY) * snapIntervalY + first; | 0 | ||||||||||||||||||
| 1675 | } | - | ||||||||||||||||||
| 1676 | - | |||||||||||||||||||
| 1677 | if (snapPos >= first
| 0 | ||||||||||||||||||
| 1678 | qreal snapPosDist = snapPos - p; | - | ||||||||||||||||||
| 1679 | - | |||||||||||||||||||
| 1680 | if (qIsNaN(bestSnapPos)
| 0 | ||||||||||||||||||
| 1681 | qAbs(snapPosDist) < bestSnapPosDist
| 0 | ||||||||||||||||||
| 1682 | bestSnapPos = snapPos; | - | ||||||||||||||||||
| 1683 | bestSnapPosDist = qAbs(snapPosDist); | - | ||||||||||||||||||
| 1684 | } never executed: end of block | 0 | ||||||||||||||||||
| 1685 | } never executed: end of block | 0 | ||||||||||||||||||
| 1686 | } never executed: end of block | 0 | ||||||||||||||||||
| 1687 | } never executed: end of block | 0 | ||||||||||||||||||
| 1688 | - | |||||||||||||||||||
| 1689 | return never executed: bestSnapPos;return bestSnapPos;never executed: return bestSnapPos; | 0 | ||||||||||||||||||
| 1690 | } | - | ||||||||||||||||||
| 1691 | - | |||||||||||||||||||
| 1692 | - | |||||||||||||||||||
| Switch to Source code | Preprocessed file |