Warning, /multimedia/elisa/src/qml/MediaTrackMetadataDelegate.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2016 (c) Matthieu Gallien <matthieu_gallien@yahoo.fr> 0003 SPDX-FileCopyrightText: 2020 (c) Devin Lin <espidev@gmail.com> 0004 0005 SPDX-License-Identifier: LGPL-3.0-or-later 0006 */ 0007 0008 import QtQuick 2.10 0009 import QtQuick.Controls 2.2 0010 import QtQuick.Layouts 1.2 0011 import org.kde.kirigami 2.5 as Kirigami 0012 import org.kde.elisa 1.0 0013 0014 RowLayout { 0015 id: delegateRow 0016 property real maximumWidth: Number.POSITIVE_INFINITY 0017 0018 property string name 0019 property int index 0020 property var type 0021 property var display 0022 property bool isRemovable 0023 property bool readOnly 0024 property string url 0025 0026 spacing: 0 0027 0028 signal edited() 0029 signal deleteField() 0030 0031 Loader { 0032 id: textDisplayLoader 0033 active: readOnly && (type === EditableTrackMetadataModel.TextEntry || type === EditableTrackMetadataModel.IntegerEntry || type === EditableTrackMetadataModel.UrlEntry || type === EditableTrackMetadataModel.DurationEntry) && typeof display !== "undefined" 0034 visible: active 0035 Layout.maximumWidth: Math.min(Kirigami.Units.gridUnit * 20, delegateRow.maximumWidth) 0036 0037 sourceComponent: LabelWithToolTip { 0038 text: display 0039 horizontalAlignment: Text.AlignLeft 0040 elide: Text.ElideRight 0041 wrapMode: Text.WordWrap 0042 } 0043 } 0044 0045 Loader { 0046 id: longTextDisplayLoader 0047 active: readOnly && (type === EditableTrackMetadataModel.LongTextEntry) && typeof display !== "undefined" 0048 visible: active 0049 Layout.maximumWidth: Math.min(Kirigami.Units.gridUnit * 20, delegateRow.maximumWidth) 0050 0051 sourceComponent: Label { 0052 text: display 0053 textFormat: Text.PlainText 0054 horizontalAlignment: Text.AlignLeft 0055 elide: Text.ElideRight 0056 wrapMode: Text.WordWrap 0057 } 0058 } 0059 0060 Loader { 0061 active: readOnly && (type === EditableTrackMetadataModel.DateEntry) && typeof display !== "undefined" 0062 visible: active 0063 Layout.maximumWidth: Math.min(Kirigami.Units.gridUnit * 20, delegateRow.maximumWidth) 0064 0065 sourceComponent: LabelWithToolTip { 0066 text: rawDate.toLocaleDateString(Locale.ShortFormat) 0067 0068 horizontalAlignment: Text.AlignLeft 0069 elide: Text.ElideRight 0070 property date rawDate: new Date(display) 0071 } 0072 } 0073 0074 Loader { 0075 id: editTextDisplayLoader 0076 0077 focus: index === 0 0078 0079 active: !readOnly && (type === EditableTrackMetadataModel.TextEntry || type === EditableTrackMetadataModel.UrlEntry || type === EditableTrackMetadataModel.IntegerEntry) 0080 visible: active 0081 0082 sourceComponent: TextField { 0083 enabled: !delegateRow.readOnly 0084 text: display 0085 0086 focus: index === 0 0087 0088 horizontalAlignment: Text.AlignLeft 0089 0090 onTextEdited: { 0091 if (display !== text) { 0092 display = text 0093 0094 edited() 0095 } 0096 } 0097 } 0098 } 0099 0100 Loader { 0101 focus: index === 0 0102 0103 active: type === EditableTrackMetadataModel.RatingEntry && typeof display !== "undefined" 0104 visible: active 0105 0106 sourceComponent: ElisaApplication.useFavoriteStyleRatings ? favoriteButton : ratingStars 0107 0108 Component { 0109 id: ratingStars 0110 0111 RatingStar { 0112 starRating: delegateRow.display 0113 0114 readOnly: delegateRow.readOnly 0115 0116 anchors.verticalCenter: parent.verticalCenter 0117 0118 onRatingEdited: { 0119 if (display !== starRating) { 0120 display = starRating 0121 ElisaApplication.musicManager.updateSingleFileMetaData(url, DataTypes.RatingRole, starRating) 0122 edited() 0123 } 0124 } 0125 } 0126 } 0127 0128 Component { 0129 id: favoriteButton 0130 0131 FlatButtonWithToolTip { 0132 readonly property bool isFavorite: delegateRow.display === 10 0133 0134 text: isFavorite ? i18nc("@action:button", "Un-mark this song as a favorite") : i18nc("@action:button", "Mark this song as a favorite") 0135 icon.name: isFavorite ? "rating" : "rating-unrated" 0136 0137 onClicked: { 0138 const newRating = isFavorite ? 0 : 10; 0139 // Change icon immediately in case backend is slow 0140 icon.name = isFavorite ? "rating-unrated" : "rating"; 0141 ElisaApplication.musicManager.updateSingleFileMetaData(url, DataTypes.RatingRole, newRating) 0142 edited() 0143 } 0144 } 0145 } 0146 } 0147 0148 Loader { 0149 id: editLongTextDisplayLoader 0150 0151 active: !readOnly && (type === EditableTrackMetadataModel.LongTextEntry) 0152 visible: active 0153 Layout.maximumHeight: Kirigami.Units.gridUnit * 10 0154 Layout.minimumWidth: Kirigami.Units.gridUnit * 8 0155 0156 sourceComponent: ScrollView { 0157 TextArea { 0158 enabled: !delegateRow.readOnly 0159 text: display 0160 0161 focus: index === 0 0162 0163 horizontalAlignment: TextEdit.AlignLeft 0164 0165 selectByMouse: true 0166 0167 wrapMode: TextEdit.Wrap 0168 0169 onEditingFinished: { 0170 if (display !== text) { 0171 display = text 0172 0173 edited() 0174 } 0175 } 0176 } 0177 } 0178 } 0179 0180 FlatButtonWithToolTip { 0181 Layout.preferredHeight: Kirigami.Units.iconSizes.smallMedium 0182 Layout.preferredWidth: Kirigami.Units.iconSizes.smallMedium 0183 0184 icon.name: 'delete' 0185 text: i18nc("@action:button remove a metadata tag", "Remove this tag") 0186 0187 visible: !readOnly && isRemovable 0188 onClicked: deleteField() 0189 } 0190 } 0191