Repository navigation
Expand file tree
/
Copy pathLibrary.qml
More file actions
281 lines (243 loc) · 8.67 KB
/
Copy pathLibrary.qml
File metadata and controls
281 lines (243 loc) · 8.67 KB
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import qs.Commons
import qs.Ui
// The library, browsed straight off the Subsonic server with the token cliamp already
// published. Choosing an album replaces the queue in place, so the daemon never stops
// and the terminal player is never needed to change what is playing.
Column {
id: root
property var service: null
property color foreground: Color.foreground
property string fontFamily: Style.font.family
property bool expanded: false
property int cursorIndex: -1
signal toggleRequested()
signal moveRequested(int delta)
signal activateRequested()
// PanelKeyCatcher runs at Keys.BeforeItem, so the panel must stand down while this
// field has the keyboard or every letter typed also fires a panel action.
readonly property bool searchFocused: search.activeFocus
onExpandedChanged: expanded ? search.forceActiveFocus() : root.forceActiveFocus()
readonly property color dim: Qt.darker(foreground, 1.45)
readonly property var results: service ? service.results : []
readonly property bool cliampRunning: !!(service && service.running)
// A search can return a hundred rows, which is taller than the whole panel. Capping
// the list keeps the hero and transport on screen while browsing.
readonly property int listMaxHeight: Style.space(240)
// Keeps the cursor row on screen without ListView owning the cursor.
onCursorIndexChanged: if (cursorIndex >= 0) albumList.positionViewAtIndex(cursorIndex, ListView.Contain)
spacing: Style.space(8)
PanelSeparator {
width: parent.width
foreground: root.foreground
}
Item {
width: parent.width
implicitHeight: Math.max(libraryHeader.implicitHeight, countLabel.implicitHeight)
PanelSectionHeader {
id: libraryHeader
text: "LIBRARY"
foreground: root.foreground
fontFamily: root.fontFamily
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
}
Text {
id: countLabel
textFormat: Text.PlainText
text: root.results.length > 0
? root.results.length + (root.results.length === 1 ? " RESULT" : " RESULTS")
: ""
color: Qt.darker(root.foreground, 1.4)
font.family: root.fontFamily
font.pixelSize: Style.font.caption
font.bold: true
font.letterSpacing: 1.2
anchors.right: parent.right
anchors.rightMargin: Style.space(6)
anchors.verticalCenter: parent.verticalCenter
}
}
CursorSurface {
width: parent.width
foreground: root.foreground
implicitHeight: summaryLabel.implicitHeight + Style.spacing.rowPaddingX
MouseArea {
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: root.toggleRequested()
}
RowLayout {
anchors.left: parent.left
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
anchors.leftMargin: Style.space(10)
anchors.rightMargin: Style.space(10)
spacing: Style.space(8)
Text {
id: summaryLabel
textFormat: Text.PlainText
Layout.fillWidth: true
text: root.expanded ? "Browse" : "Browse the library"
color: root.foreground
font.family: root.fontFamily
font.pixelSize: Style.font.body
elide: Text.ElideRight
}
Text {
textFormat: Text.PlainText
text: "/"
color: root.dim
font.family: root.fontFamily
font.pixelSize: Style.font.caption
}
Text {
textFormat: Text.PlainText
text: root.expanded ? "⌄" : "›"
color: root.dim
font.family: root.fontFamily
font.pixelSize: Style.font.body
}
}
}
Column {
width: parent.width
spacing: Style.space(8)
visible: root.expanded
// search3 matches album, artist and song names, and saved playlists are matched
// locally, so one field reaches everything that can be played.
TextField {
id: search
width: parent.width
placeholderText: "Search songs, albums and playlists"
foreground: root.foreground
font.family: root.fontFamily
// The catcher is standing down, so these are the panel keys worth keeping here.
Keys.onEscapePressed: root.focus = true
Keys.onUpPressed: root.moveRequested(-1)
Keys.onDownPressed: root.moveRequested(1)
Keys.onReturnPressed: root.activateRequested()
Keys.onEnterPressed: root.activateRequested()
onTextChanged: searchDebounce.restart()
}
Timer {
id: searchDebounce
interval: 260
repeat: false
onTriggered: if (root.service) root.service.search(search.text)
}
// The list scrolls inside its own bounds, so the wheel over it moves rows rather
// than the whole panel. ListView is used over a Repeater for positionViewAtIndex,
// which is what keeps the j/k cursor on screen in a list this long.
ListView {
id: albumList
width: parent.width
height: Math.min(contentHeight, root.listMaxHeight)
clip: true
spacing: Style.space(2)
model: root.results
keyNavigationEnabled: false
boundsBehavior: Flickable.StopAtBounds
interactive: contentHeight > height
ScrollBar.vertical: ScrollBar { policy: ScrollBar.AsNeeded }
// currentIndex is deliberately not bound to the panel's cursor. ListView writes
// that property itself on every model swap, which breaks a QML binding for good
// and would strand the highlight on row 0 while the panel still held its cursor.
onCountChanged: if (root.cursorIndex >= 0) positionViewAtIndex(root.cursorIndex, ListView.Contain)
delegate: CursorSurface {
required property var modelData
required property int index
width: albumList.width
foreground: root.foreground
hasCursor: index === root.cursorIndex
implicitHeight: albumLabel.implicitHeight + Style.spacing.rowPaddingX
MouseArea {
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: root.service.playResult(modelData)
}
RowLayout {
anchors.left: parent.left
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
anchors.leftMargin: Style.space(10)
anchors.rightMargin: Style.space(10)
spacing: Style.space(8)
Text {
id: albumLabel
textFormat: Text.PlainText
Layout.fillWidth: true
text: (modelData.artist ? modelData.artist + " · " : "") + modelData.name
color: root.foreground
font.family: root.fontFamily
font.pixelSize: Style.font.body
elide: Text.ElideRight
}
// The kind is the load-bearing detail once one list mixes three of them.
Text {
textFormat: Text.PlainText
text: String(modelData.kind || "").toUpperCase()
color: root.dim
font.family: root.fontFamily
font.pixelSize: Style.font.caption
font.letterSpacing: 1.2
}
}
}
}
Text {
textFormat: Text.PlainText
width: parent.width
text: "Nothing matched"
color: root.dim
font.family: root.fontFamily
font.pixelSize: Style.font.bodySmall
horizontalAlignment: Text.AlignHCenter
visible: root.results.length === 0
}
}
// Only offered when nothing holds the socket. cliamp allows one instance per user, so
// launching it while the daemon runs would start a second, IPC-less copy that this
// panel cannot see. Browsing above removes the reason to open it at all.
CursorSurface {
width: parent.width
foreground: root.foreground
visible: !root.cliampRunning
implicitHeight: startLabel.implicitHeight + Style.spacing.rowPaddingX
MouseArea {
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: root.service.openPlayer()
}
RowLayout {
anchors.left: parent.left
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
anchors.leftMargin: Style.space(10)
anchors.rightMargin: Style.space(10)
spacing: Style.space(8)
Text {
id: startLabel
textFormat: Text.PlainText
Layout.fillWidth: true
text: "Start cliamp"
color: root.foreground
font.family: root.fontFamily
font.pixelSize: Style.font.body
elide: Text.ElideRight
}
Text {
textFormat: Text.PlainText
text: "f ›"
color: root.dim
font.family: root.fontFamily
font.pixelSize: Style.font.caption
}
}
}
}