Fusion style: misc speedup drawing indeterminate progress bar

When drawing an indeterminate progress bar, QPainter::drawLine() is
called very often. Avoid it by first calculating all lines and then call
QPainter::drawLines() once with all lines to draw.

Change-Id: I51ce23236b945b30da649fd06aad60676321e403
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit 0eedffa01daed077aba4781b240068929cf768be)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Christian Ehrlicher 2024-11-22 21:35:42 +01:00 committed by Qt Cherry-pick Bot
parent 6f353bb066
commit 0188953c6d

View File

@ -1300,14 +1300,21 @@ void QFusionStyle::drawControl(ControlElement element, const QStyleOption *optio
painter->setPen(QPen(highlightedGradientStartColor, 9.0));
painter->setClipRect(progressBar.adjusted(1, 1, -1, -1));
#if QT_CONFIG(animation)
if (QProgressStyleAnimation *animation = qobject_cast<QProgressStyleAnimation*>(d->animation(option->styleObject)))
step = animation->animationStep() % 22;
else
(const_cast<QFusionStylePrivate*>(d))->startAnimation(new QProgressStyleAnimation(d->animationFps, option->styleObject));
if (QProgressStyleAnimation *animation =
qobject_cast<QProgressStyleAnimation*>(d->animation(option->styleObject))) {
step = animation->animationStep() % 22;
} else {
(const_cast<QFusionStylePrivate*>(d))->startAnimation(
new QProgressStyleAnimation(d->animationFps, option->styleObject)
);
}
#endif
for (int x = progressBar.left() - rect.height(); x < rect.right() ; x += 22)
painter->drawLine(x + step, progressBar.bottom() + 1,
x + rect.height() + step, progressBar.top() - 2);
QVarLengthArray<QLine, 40> lines;
for (int x = progressBar.left() - rect.height(); x < rect.right() ; x += 22) {
lines.emplace_back(x + step, progressBar.bottom() + 1,
x + rect.height() + step, progressBar.top() - 2);
}
painter->drawLines(lines.data(), lines.count());
}
}
if (!indeterminate && !complete) {