feat: add seek to lyrics

Closes #1524
This commit is contained in:
2 * r + 2 * t 2026-06-08 16:20:12 +10:00
parent 24816fb0d9
commit f21373bcb0
3 changed files with 25 additions and 3 deletions

View file

@ -260,13 +260,14 @@ Item {
id: lyric
required property string modelData
required property int index
property real effectScale: ListView.isCurrentItem ? 1 : 0
anchors.left: ListView.view?.contentItem.left
anchors.right: ListView.view?.contentItem.right
anchors.left: lyrics.contentItem.left
anchors.right: lyrics.contentItem.right
text: modelData || ". . ."
color: ListView.isCurrentItem ? Colours.palette.m3primary : Colours.palette.m3outline
color: ListView.isCurrentItem ? Colours.palette.m3primary : mouse.containsMouse ? Colours.palette.m3onSurface : Colours.palette.m3outline
font: Tokens.font.body.medium
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
@ -284,6 +285,19 @@ Item {
type: Anim.SlowEffects
}
}
MouseArea {
id: mouse
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
hoverEnabled: true
onClicked: {
const p = Players.active;
if (p)
p.position = Lyrics.timeForIndex(lyric.index);
}
}
}
Behavior on opacity {

View file

@ -223,6 +223,13 @@ int Lyrics::indexForTime(qreal time) const {
return static_cast<int>(lo - 1);
}
qreal Lyrics::timeForIndex(int index) const {
if (index < 0 || index >= m_lines.size()) {
return -1.0;
}
return m_lines.at(index).time + m_offset;
}
void Lyrics::setTrack(const QString& artist, const QString& title, const QString& album, qreal duration) {
const QString a = artist.trimmed();
const QString t = title.trimmed();

View file

@ -51,6 +51,7 @@ public:
[[nodiscard]] QString trackTitle() const;
[[nodiscard]] Q_INVOKABLE int indexForTime(qreal time) const;
[[nodiscard]] Q_INVOKABLE qreal timeForIndex(int index) const;
Q_INVOKABLE void setTrack(
const QString& artist, const QString& title, const QString& album = {}, qreal duration = 0.0);
Q_INVOKABLE void clearTrack();