-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathQCDesktopLyric.qml
172 lines (149 loc) · 5.34 KB
/
QCDesktopLyric.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
pragma Singleton
import QtQuick
import qc.window
Window {
id: root
property var mediaPlayer: null
property ListModel lyricData: ListModel {}
property string family: "黑体"
property string lyric: "播放歌词"
property string textColor: "#00ACC1"
property double fontSize: 15
property double lastX: 700.
property double lastY: 500.
property int current: -1
property bool isHoverd: false
width: lyricContent.width
height: lyricContent.height
minimumWidth: width
minimumHeight: height
title: lyric
flags: Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint
color: "#00000000"
onCurrentChanged: {
lyricText.text = lyricData.get(current).lyric
tlrcText.text = lyricData.get(current).tlrc
console.log("当前播放歌词: " + lyricText.text + " 翻译: " +lyricData.get(current).tlrc)
setCenterPoint()
}
function setCenterPoint() {
let lx = (root.x + lyricColumn.width)
let ly = (root.y + lyricColumn.height)
let offsetx = 0
let offsety = 0
if(lastX - lx > 0) {
root.x += lastX - lx
} else {
root.x -= lx - lastX
}
lx = (root.x + lyricColumn.width)
console.log("中心点: " + lastX +" y" + lastY)
console.log("初始位置:" + lx +" " + ly)
}
Connections {
enabled: visible && mediaPlayer != null
target: mediaPlayer
function onPositionChanged(pos) {
let tim = 0
let index = 0
for(let i = 0; i < lyricData.count;i++) {
if(pos >= lyricData.get(i).tim) {
if(i === lyricData.count-1) {
index = i
break
} else if(pos < lyricData.get(i+1).tim) {
index = i
break
}
}
}
current = index
}
}
Rectangle {
id: lyricContent
width: lyricColumn.width
height: lyricColumn.height
anchors.centerIn: parent
color: if(isHoverd) return "#3F000000"
else return "#00000000"
Item {
width: lyricColumn.width
height: lyricColumn.height
anchors.centerIn: parent
Column {
id: lyricColumn
property double maxChildWidth: lyricText.contentWidth
width: maxChildWidth
height: lyricText.height + tlrcText.height + spacing
anchors.centerIn: parent
spacing: 5
Text {
id: lyricText
anchors.horizontalCenter: parent.horizontalCenter
height: text === "" ? 0 : contentHeight
font.pointSize: fontSize
font.family: family
font.bold: true
text: lyric
color: textColor
onContentWidthChanged: function (contentWidth) {
if(contentWidth > lyricContent.maxChildWidth) {
lyricContent.maxChildWidth = contentWidth
}
}
}
Text {
id: tlrcText
anchors.horizontalCenter: parent.horizontalCenter
height: text === "" ? 0 : contentHeight
font.pointSize: fontSize
font.family: family
font.bold: true
text: ""
color: textColor
onContentWidthChanged: function (contentWidth) {
if(contentWidth > lyricContent.maxChildWidth) {
lyricContent.maxChildWidth = contentWidth
}
}
}
}
MouseArea {
property var click_pos: Qt.point(0,0)
anchors.fill: parent
propagateComposedEvents: true
hoverEnabled: true
cursorShape: Qt.OpenHandCursor
onPositionChanged: function (mouse) {
if(!root.startSystemMove()) { // 启用系统自带的拖拽功能
var offset = Qt.point(mouseX - click_pos.x,mouseY - click_pos.y)
root.x += offset.x
root.y += offset.y
} else {
}
}
onPressedChanged: function (mouse) {
click_pos = Qt.point(mouseX,mouseY)
console.log("winX: " + root.x + " winY: " + root.y + " x: " + parent.x + " y: " + parent.y)
}
onReleased: {
}
onEntered: {
isHoverd = true
}
onExited: {
lastX = (root.x + lyricColumn.width)
lastY = (root.y + lyricColumn.height)
}
}
}
}
Timer {
id: hoverdTimeOut
interval: 3000
onTriggered: {
isHoverd = false
}
}
}