-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLyricsView.qml
72 lines (62 loc) · 1.87 KB
/
LyricsView.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import QtQuick
import QtQml
import QtMultimedia
import kienyew.github
ListView {
property alias lrcSource: model.lyricSource;
property int lineHeight: 70
id: root
clip: true
model: model
snapMode: ListView.SnapToItem
highlightRangeMode: ListView.ApplyRange
preferredHighlightBegin: height / 2 - lineHeight / 2
preferredHighlightEnd: height / 2 + lineHeight / 2
highlightFollowsCurrentItem: true
highlightMoveDuration: 500
interactive: true
reuseItems: true
LyricsModel {
id: model
lyricSource: config.recentLrcFile;
}
delegate: Rectangle {
id: lyricLine
required property int index
required property int timestamp
required property string sentence
color: "transparent"
width: root.width
height: lineHeight
Text {
anchors.fill: parent
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
font.pixelSize: (index === root.currentIndex) ? 22 : 18
text: sentence
color: "#121212"
opacity: (index === root.currentIndex) ? 1.0 : 0.8
wrapMode: Text.WordWrap
Behavior on font.pixelSize {
NumberAnimation {
duration: 50
}
}
}
}
// scoll to the appropriate lyric line at `time` in milliseconds
function scrollToTime(time) {
for (let i = 1 ; i < root.count; ++i) {
let line = model.getLyricLine(i);
if (line !== null && line.timestamp > time) {
if (root.currentIndex != i - 1) {
root.currentIndex = i - 1;
}
return;
}
}
if (root.currentIndex != root.count - 1) {
root.currentIndex = root.count - 1;
}
}
}