perf: smooth UI animations and reduce repaint overhead

Batch of performance and animation work: shared FadeHelper/MotionPrefs
primitives, hover animators, shadow pixmap caching, smooth scrolling,
seek time bubble, and widespread component repaint reductions.
This commit is contained in:
dela
2026-07-08 11:29:38 +08:00
parent 03bc33518c
commit ab1accc821
85 changed files with 2308 additions and 661 deletions
@@ -0,0 +1,80 @@
#include "seektimebubble.h"
#include <QLabel>
#include <QPainter>
#include <QVBoxLayout>
#include "../utils/fadehelper.h"
SeekTimeBubble::SeekTimeBubble(QWidget *parent)
: QWidget(parent)
{
setAttribute(Qt::WA_TransparentForMouseEvents);
setVisible(false);
auto *layout = new QVBoxLayout(this);
layout->setContentsMargins(10, 4, 10, 4);
layout->setSpacing(4);
m_thumbSlot = new QLabel(this);
m_thumbSlot->setObjectName("seekBubbleThumb");
m_thumbSlot->setVisible(false);
layout->addWidget(m_thumbSlot, 0, Qt::AlignHCenter);
m_timeLabel = new QLabel(this);
m_timeLabel->setObjectName("seekBubbleTime");
m_timeLabel->setAlignment(Qt::AlignCenter);
layout->addWidget(m_timeLabel, 0, Qt::AlignHCenter);
}
void SeekTimeBubble::setTimeText(const QString &text)
{
if (m_timeLabel->text() == text)
{
return;
}
m_timeLabel->setText(text);
adjustSize();
}
void SeekTimeBubble::showAt(const QPoint &anchor)
{
adjustSize();
QPoint topLeft(anchor.x() - width() / 2, anchor.y() - height());
if (parentWidget())
{
const int maxX = parentWidget()->width() - width();
topLeft.setX(qBound(0, topLeft.x(), qMax(0, maxX)));
topLeft.setY(qMax(0, topLeft.y()));
}
move(topLeft);
if (!m_shown)
{
m_shown = true;
raise();
FadeHelper::fadeIn(this, AnimationTokens::DurationMs::kQuick);
}
}
void SeekTimeBubble::hideBubble()
{
if (!m_shown)
{
return;
}
m_shown = false;
FadeHelper::fadeOut(this, AnimationTokens::DurationMs::kMicro,
AnimationTokens::Curve::exit(), [this]() { hide(); });
}
void SeekTimeBubble::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
painter.setPen(QPen(QColor(148, 163, 184, 60), 1));
painter.setBrush(QColor(15, 23, 42, 235));
painter.drawRoundedRect(QRectF(rect()).adjusted(0.5, 0.5, -0.5, -0.5), 6, 6);
}