From c093b57c8696079fc3408796e0e17c62a990bce2 Mon Sep 17 00:00:00 2001 From: Thomas Moerschell Date: Mon, 17 Feb 2025 20:58:56 +0100 Subject: [PATCH] QScroller: Remove workaround for timer start The CI is flakey, likely due to missing timer events. Instead of skipping the first event, start the timer only when the new state has been set. Task-number: QTBUG-30133 Pick-to: 6.9 6.8 Change-Id: Ia58e4b091d8791d1b77642ded67312bc3927d0b7 Reviewed-by: Shawn Rutledge Reviewed-by: Axel Spoerl Reviewed-by: Volker Hilsheimer --- src/widgets/util/qscroller.cpp | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/widgets/util/qscroller.cpp b/src/widgets/util/qscroller.cpp index 5329c8681da..9cdbb385fe2 100644 --- a/src/widgets/util/qscroller.cpp +++ b/src/widgets/util/qscroller.cpp @@ -154,9 +154,7 @@ static qreal progressForValue(const QEasingCurve &curve, qreal value) class QScrollTimer : public QAbstractAnimation { public: - QScrollTimer(QScrollerPrivate *_d) - : QAbstractAnimation(_d), d(_d), ignoreUpdate(false), skip(0) - { } + QScrollTimer(QScrollerPrivate *_d) : QAbstractAnimation(_d), d(_d), skip(0) {} int duration() const override { @@ -165,28 +163,21 @@ public: void start() { - // QAbstractAnimation::start() will immediately call - // updateCurrentTime(), but our state is not set correctly yet - ignoreUpdate = true; QAbstractAnimation::start(); - ignoreUpdate = false; skip = 0; } protected: void updateCurrentTime(int /*currentTime*/) override { - if (!ignoreUpdate) { - if (++skip >= d->frameRateSkip()) { - skip = 0; - d->timerTick(); - } + if (++skip >= d->frameRateSkip()) { + skip = 0; + d->timerTick(); } } private: QScrollerPrivate *d; - bool ignoreUpdate; int skip; }; #endif // animation @@ -1655,6 +1646,7 @@ void QScrollerPrivate::setState(QScroller::State newstate) { Q_Q(QScroller); bool sendLastScroll = false; + bool startTimer = false; if (state == newstate) return; @@ -1687,19 +1679,24 @@ void QScrollerPrivate::setState(QScroller::State newstate) dragDistance = QPointF(0, 0); #if QT_CONFIG(animation) if (state == QScroller::Pressed) - scrollTimer->start(); + startTimer = true; #endif break; case QScroller::Scrolling: #if QT_CONFIG(animation) - scrollTimer->start(); + startTimer = true; #endif break; } qSwap(state, newstate); +#if QT_CONFIG(animation) + // Only start the timer after the state has been changed + if (startTimer) + scrollTimer->start(); +#endif if (sendLastScroll) { QScrollEvent se(contentPosition, overshootPosition, QScrollEvent::ScrollFinished); sendEvent(target, &se);