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:
@@ -1,12 +1,23 @@
|
||||
#include "collectioncard.h"
|
||||
#include "collectiongrid.h"
|
||||
#include "../managers/thememanager.h"
|
||||
#include "../utils/hoveranimator.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
#include <QPainterPath>
|
||||
|
||||
namespace {
|
||||
QColor lerpColor(const QColor& from, const QColor& to, qreal t)
|
||||
{
|
||||
return QColor(qRound(from.red() + (to.red() - from.red()) * t),
|
||||
qRound(from.green() + (to.green() - from.green()) * t),
|
||||
qRound(from.blue() + (to.blue() - from.blue()) * t),
|
||||
qRound(from.alpha() + (to.alpha() - from.alpha()) * t));
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -40,6 +51,9 @@ CollectionCard::CollectionCard(const QString& itemId,
|
||||
m_btnRename->setToolTip(tr("Rename"));
|
||||
m_btnDelete->setToolTip(tr("Delete"));
|
||||
|
||||
m_hover = new HoverAnimator(this);
|
||||
m_hover->setCallback([this](qreal) { update(); });
|
||||
|
||||
updateButtonLayout();
|
||||
|
||||
connect(m_btnRename, &QPushButton::clicked, this,
|
||||
@@ -115,6 +129,14 @@ void CollectionCard::paintEvent(QPaintEvent* event)
|
||||
QColor typeFg = isDark ? QColor("#94A3B8") : QColor("#64748B");
|
||||
const QColor accent("#3B82F6");
|
||||
|
||||
const qreal hp = m_hover->progress();
|
||||
if (hp > 0.0 && !m_selected && !m_dragging) {
|
||||
const QColor hoverBorder = isDark ? QColor(96, 165, 250, 190) : QColor(59, 130, 246, 190);
|
||||
const QColor hoverBg = isDark ? QColor(51, 65, 85, 190) : QColor(255, 255, 255, 255);
|
||||
border = lerpColor(border, hoverBorder, hp);
|
||||
cardBg = lerpColor(cardBg, hoverBg, hp);
|
||||
}
|
||||
|
||||
if (m_selected) {
|
||||
cardBg = isDark ? QColor(30, 41, 59, 220) : QColor(239, 246, 255, 245);
|
||||
border = isDark ? QColor(96, 165, 250, 220) : QColor(59, 130, 246, 220);
|
||||
@@ -298,6 +320,18 @@ void CollectionCard::resizeEvent(QResizeEvent* event)
|
||||
updateButtonLayout();
|
||||
}
|
||||
|
||||
void CollectionCard::enterEvent(QEnterEvent* event)
|
||||
{
|
||||
QFrame::enterEvent(event);
|
||||
m_hover->setHovered(true);
|
||||
}
|
||||
|
||||
void CollectionCard::leaveEvent(QEvent* event)
|
||||
{
|
||||
QFrame::leaveEvent(event);
|
||||
m_hover->setHovered(false);
|
||||
}
|
||||
|
||||
void CollectionCard::toggleSelected()
|
||||
{
|
||||
m_selected = !m_selected;
|
||||
|
||||
Reference in New Issue
Block a user