From 29801e7c0426b1272a725b13e6ad97f155f0a586 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 Change-Id: Ia58e4b091d8791d1b77642ded67312bc3927d0b7 Reviewed-by: Shawn Rutledge Reviewed-by: Axel Spoerl Reviewed-by: Volker Hilsheimer (cherry picked from commit c093b57c8696079fc3408796e0e17c62a990bce2) Reviewed-by: Qt Cherry-pick Bot (cherry picked from commit 69f78f3cbe8776a0c20c972d6624906d95fc2fbc) --- 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 1192a0be603..95c1a22299a 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 @@ -1658,6 +1649,7 @@ void QScrollerPrivate::setState(QScroller::State newstate) { Q_Q(QScroller); bool sendLastScroll = false; + bool startTimer = false; if (state == newstate) return; @@ -1690,19 +1682,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);