Warning, /multimedia/elisa/src/qml/mobile/MobilePlayListDelegate.qml is written in an unsupported language. File is not indexed.

0001 /*
0002    SPDX-FileCopyrightText: 2020 (c) Devin Lin <espidev@gmail.com>
0003 
0004    SPDX-License-Identifier: LGPL-3.0-or-later
0005  */
0006 
0007 import QtQuick 2.7
0008 import QtQuick.Layouts 1.2
0009 import QtQuick.Controls 2.3
0010 import QtQuick.Window 2.2
0011 import org.kde.kirigami 2.19 as Kirigami
0012 import org.kde.elisa 1.0
0013 
0014 import ".."
0015 import "../shared"
0016 
0017 BasePlayListDelegate {
0018     id: playListEntry
0019 
0020     Accessible.role: Accessible.ListItem
0021     Accessible.name: title + ' ' + album + ' ' + artist
0022 
0023     Kirigami.Theme.useAlternateBackgroundColor: true
0024     padding: 0
0025 
0026     Keys.onReturnPressed: {
0027         playListEntry.switchToTrack(playListEntry.index)
0028         playListEntry.startPlayback()
0029     }
0030 
0031     function openContextMenu() {
0032         mainWindow.contextDrawer.close();
0033         contextMenuLoader.active = true;
0034         contextMenuLoader.item.open();
0035     }
0036 
0037     contentItem: Item {
0038         implicitWidth: playListEntry.width
0039         implicitHeight: 4 * Kirigami.Units.smallSpacing + Kirigami.Units.gridUnit * 2
0040 
0041         Loader {
0042             id: metadataLoader
0043             active: false
0044             onLoaded: mainWindow.pageStack.layers.push(item)
0045 
0046             sourceComponent: MobileMediaTrackMetadataView {
0047                 fileName: playListEntry.fileName
0048                 showImage: entryType !== ElisaUtils.Radio
0049                 modelType: entryType
0050                 showTrackFileName: entryType !== ElisaUtils.Radio
0051                 showDeleteButton: entryType === ElisaUtils.Radio
0052                 editableMetadata: playListEntry.metadataModifiableRole
0053                 canAddMoreMetadata: entryType !== ElisaUtils.Radio
0054             }
0055         }
0056 
0057         Loader {
0058             active: isPlaying === MediaPlayList.IsPlaying || isPlaying === MediaPlayList.IsPaused
0059             sourceComponent: Rectangle {
0060                 width: background.width * (ElisaApplication.audioPlayer.position / ElisaApplication.audioPlayer.duration)
0061                 height: background.height
0062                 color: myPalette.mid
0063             }
0064         }
0065 
0066         // row contents
0067         RowLayout {
0068             id: trackRow
0069 
0070             anchors.fill: parent
0071             spacing: Math.round(Kirigami.Units.smallSpacing / 2)
0072 
0073             // drag handle (for list reordering)
0074             Kirigami.ListItemDragHandle {
0075                 visible: playListEntry.showDragHandle
0076                 listItem: playListEntry
0077                 listView: playListEntry.listView
0078                 onMoveRequested: (oldIndex, newIndex) => {
0079                     ElisaApplication.mediaPlayListProxyModel.moveRow(oldIndex, newIndex);
0080                 }
0081             }
0082 
0083             ColumnLayout {
0084                 Layout.fillWidth: true
0085                 Layout.fillHeight: true
0086                 Layout.leftMargin: Kirigami.Units.largeSpacing
0087 
0088                 spacing: Kirigami.Units.smallSpacing / 2
0089 
0090                 Label {
0091                     id: mainLabelDetailed
0092 
0093                     text: title
0094                     textFormat: Text.PlainText
0095                     color: myPalette.text
0096                     elide: Text.ElideRight
0097 
0098                     Layout.fillWidth: true
0099                 }
0100 
0101                 Label {
0102                     id: artistLabel
0103 
0104                     text: {
0105                         var labelText = ""
0106                         if (artist) {
0107                             labelText += artist
0108                         }
0109                         if (album !== '') {
0110                             labelText += ' - ' + album
0111                             if (!hideDiscNumber && discNumber !== -1) {
0112                                 labelText += ' - CD ' + discNumber
0113                             }
0114                         }
0115                         return labelText;
0116                     }
0117                     textFormat: Text.PlainText
0118 
0119                     visible: text.length > 0
0120                     opacity: 0.6
0121                     color: myPalette.text
0122 
0123                     Layout.fillWidth: true
0124                     elide: Text.ElideRight
0125                     font: Kirigami.Theme.smallFont
0126                 }
0127             }
0128 
0129             LabelWithToolTip {
0130                 id: durationLabel
0131 
0132                 text: duration
0133 
0134                 font.weight: Font.Light
0135                 color: myPalette.text
0136 
0137                 Layout.rightMargin: !LayoutMirroring.enabled ? Kirigami.Units.largeSpacing : 0
0138                 Layout.leftMargin: LayoutMirroring.enabled ? Kirigami.Units.largeSpacing : 0
0139             }
0140 
0141             // context menu
0142             FlatButtonWithToolTip {
0143                 id: contextMenuButton
0144                 scale: LayoutMirroring.enabled ? -1 : 1
0145                 text: entryType === ElisaUtils.Track ? i18nc("@action:button", "Track Options") : i18nc("@action:button", "Radio Options")
0146                 icon.name: "view-more-symbolic"
0147                 onClicked: openContextMenu()
0148                 activeFocusOnTab: playListEntry.isSelected
0149             }
0150         }
0151 
0152         Loader {
0153             id: contextMenuLoader
0154             active: false
0155 
0156             // context menu sheet
0157             sourceComponent: Kirigami.MenuDialog {
0158                 id: contextMenu
0159                 title: playListEntry.title
0160 
0161                 preferredWidth: Kirigami.Units.gridUnit * 20
0162 
0163                 actions: [
0164                     Kirigami.Action {
0165                         visible: playListEntry.fileName.toString().substring(0, 7) === 'file://'
0166                         icon.name: "document-open-folder"
0167                         text: i18nc("@action:button Show the file for this song in the file manager", "Show in folder")
0168                         onTriggered: ElisaApplication.showInFolder(playListEntry.fileName)
0169                     },
0170                     Kirigami.Action {
0171                         visible: isValid
0172                         icon.name: "documentinfo"
0173                         text: i18nc("@action:button Show track metadata", "View details")
0174                         onTriggered: {
0175                             if (metadataLoader.active === false) {
0176                                 metadataLoader.active = true
0177                             } else {
0178                                 metadataLoader.item.close();
0179                                 metadataLoader.active = false
0180                             }
0181                         }
0182                     },
0183                     Kirigami.Action {
0184                         visible: isValid
0185                         icon.name: "error"
0186                         text: i18nc("@action:button", "Remove from queue")
0187                         onTriggered: playListEntry.removeFromPlaylist(playListEntry.index)
0188                     }
0189                 ]
0190             }
0191         }
0192     }
0193 }