mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-10-20 02:04:01 -04:00
feat(lyrics): add seek-to-line on clicking lyrics line (#3823)
This commit is contained in:
@@ -340,6 +340,18 @@ FocusScope {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
StateLayer {
|
||||
anchors.fill: parent
|
||||
enabled: root.controller.canSeekLines
|
||||
stateColor: Theme.onSurfaceVariant
|
||||
cornerRadius: Theme.cornerRadius
|
||||
onClicked: {
|
||||
root.following = true;
|
||||
root.forceActiveFocus(Qt.MouseFocusReason);
|
||||
root.controller.seekToLine(lyric.index);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -90,6 +90,7 @@ Item {
|
||||
}
|
||||
|
||||
Item {
|
||||
y: (root.implicitHeight - height) / 2
|
||||
width: parent.width
|
||||
height: Math.ceil(line.implicitHeight * root.textScale)
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ QtObject {
|
||||
property bool enabled: false
|
||||
|
||||
readonly property bool available: DMSService.capabilities.includes("lyrics")
|
||||
readonly property bool canSeekLines: synced && (player?.canSeek ?? false) && duration > 0
|
||||
readonly property string fileUrl: url.startsWith("file://") ? url : ""
|
||||
readonly property string trackKey: track ? JSON.stringify([track.key, track.title, track.artist, track.album, fileUrl, MediaOptions.enabledLyricsProviders]) : ""
|
||||
readonly property int duration: Math.round(track?.length ?? 0)
|
||||
@@ -371,6 +372,16 @@ QtObject {
|
||||
state = "ready";
|
||||
}
|
||||
|
||||
function seekToLine(index) {
|
||||
if (!synced || duration <= 0 || !player?.canSeek)
|
||||
return false;
|
||||
const line = lines[index];
|
||||
if (!line || !Number.isFinite(line.t))
|
||||
return false;
|
||||
player.position = Math.max(0.1, Math.min(line.t, duration * 0.99));
|
||||
return true;
|
||||
}
|
||||
|
||||
function currentTime() {
|
||||
if (!anchorPlaying)
|
||||
return anchorPosition;
|
||||
|
||||
Reference in New Issue
Block a user