1
0
Fork 0
mirror of https://github.com/HenkKalkwater/harbour-sailfin.git synced 2024-11-25 10:25:17 +00:00
harbour-sailfin/sailfish/qml/components/music/SongDelegate.qml

152 lines
4.5 KiB
QML
Raw Permalink Normal View History

2020-10-27 01:35:50 +00:00
/*
Sailfin: a Jellyfin client written using Qt
Copyright (C) 2020 Chris Josten
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
import QtQuick 2.6
import Sailfish.Silica 1.0
import "../.."
ListItem {
id: songDelegateRoot
property var artists: []
property real duration
property string name
property int indexNumber
2021-08-21 20:01:13 +00:00
property bool playing
2020-10-27 01:35:50 +00:00
contentHeight: songName.height + songArtists.height + 2 * Theme.paddingMedium
width: parent.width
menu: contextMenu
2020-10-27 01:35:50 +00:00
TextMetrics {
id: indexMetrics
text: "99"
font.pixelSize: Theme.fontSizeLarge
}
Label {
id: songIndex
anchors {
top: parent.top
topMargin: Theme.paddingMedium
left: parent.left
leftMargin: Theme.horizontalPageMargin
}
text: indexNumber
horizontalAlignment: Text.AlignRight
font.pixelSize: Theme.fontSizeExtraLarge
width: indexMetrics.width
2021-08-21 20:01:13 +00:00
highlighted: playing
2020-10-27 01:35:50 +00:00
}
Label {
id: songName
anchors {
left: songIndex.right
leftMargin: Theme.paddingLarge
top: parent.top
topMargin: Theme.paddingMedium
right: duration.left
rightMargin: Theme.paddingLarge
}
text: name
font.pixelSize: Theme.fontSizeMedium
truncationMode: TruncationMode.Fade
2021-08-21 20:01:13 +00:00
highlighted: down || playing
2020-10-27 01:35:50 +00:00
}
Label {
id: songArtists
anchors {
top: songName.bottom
left: songIndex.right
leftMargin: Theme.paddingLarge
right: parent.right
rightMargin: Theme.horizontalPageMargin
}
text: {
var names = []
for (var i = 0; i < artists.length; i++) {
names.push(artists[i].name)
}
return names.join(", ")
}
2020-10-27 01:35:50 +00:00
font.pixelSize: Theme.fontSizeSmall
truncationMode: TruncationMode.Fade
color: highlighted ? Theme.secondaryHighlightColor : Theme.secondaryColor
2021-08-21 20:01:13 +00:00
highlighted: down || playing
2020-10-27 01:35:50 +00:00
}
Label {
id: duration
anchors {
right: parent.right
rightMargin: Theme.horizontalPageMargin
baseline: songName.baseline
}
width: contentWidth
text: Utils.ticksToText(songDelegateRoot.duration)
font.pixelSize: Theme.fontSizeSmall
color: highlighted ? Theme.secondaryHighlightColor : Theme.secondaryColor
2021-08-21 20:01:13 +00:00
highlighted: down || playing
2020-10-27 01:35:50 +00:00
}
function goToArtist(id) {
appWindow.navigateToItem(id, "audio", "MusicArtist", true)
}
Component {
id: contextMenu
ContextMenu {
MenuItem {
text: {
if(artists.length === 1) {
//: Context menu item for navigating to the artist of the selected track
return qsTr("Go to %1").arg(artists[0].name)
} else {
//: Context menu item for navigating to one of the artists of the selected track (opens submenu)
return qsTr("Go to artists")
}
}
onDelayedClick: {
if (artists.length > 1) {
songDelegateRoot.menu = artistMenu
songDelegateRoot.openMenu()
} else {
goToArtist(artists[0].jellyfinId)
}
}
}
}
}
Component {
id: artistMenu
ContextMenu {
Repeater {
model: artists
MenuItem {
text: modelData.name
onDelayedClick: goToArtist(modelData.jellyfinId)
}
}
onClosed: songDelegateRoot.menu = contextMenu
}
}
2020-10-27 01:35:50 +00:00
}