Changeset View
Changeset View
Standalone View
Standalone View
src/MediaTracksDelegate.qml
- This file was deleted.
1 | /* | | |||
---|---|---|---|---|---|
2 | * Copyright 2016-2017 Matthieu Gallien <matthieu_gallien@yahoo.fr> | | |||
3 | * | | |||
4 | * This library is free software; you can redistribute it and/or | | |||
5 | * modify it under the terms of the GNU Library General Public | | |||
6 | * License as published by the Free Software Foundation; either | | |||
7 | * version 3 of the License, or (at your option) any later version. | | |||
8 | * | | |||
9 | * This library is distributed in the hope that it will be useful, | | |||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | | |||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | | |||
12 | * Library General Public License for more details. | | |||
13 | * | | |||
14 | * You should have received a copy of the GNU Library General Public License | | |||
15 | * along with this library; see the file COPYING.LIB. If not, write to | | |||
16 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | | |||
17 | * Boston, MA 02110-1301, USA. | | |||
18 | */ | | |||
19 | | ||||
20 | import QtQuick 2.4 | | |||
21 | import QtQuick.Layouts 1.2 | | |||
22 | import QtQuick.Controls 1.2 | | |||
23 | import QtQuick.Window 2.2 | | |||
24 | import QtGraphicalEffects 1.0 | | |||
25 | import org.kde.elisa 1.0 | | |||
26 | | ||||
27 | FocusScope { | | |||
28 | id: viewTrackDelegate | | |||
29 | | ||||
30 | property string title | | |||
31 | property var coverImage | | |||
32 | property string artist | | |||
33 | property string albumName | | |||
34 | property alias duration: durationLabel.text | | |||
35 | property int trackNumber | | |||
36 | property int discNumber | | |||
37 | property alias rating: ratingWidget.starRating | | |||
38 | property var databaseId | | |||
39 | property var playList | | |||
40 | property var playerControl | | |||
41 | property bool isAlternateColor | | |||
42 | property var trackData | | |||
43 | | ||||
44 | signal clicked() | | |||
45 | | ||||
46 | Action { | | |||
47 | id: clearAndEnqueue | | |||
48 | text: i18nc("Clear play list and enqueue current track", "Play Now and Replace Play List") | | |||
49 | iconName: "media-playback-start" | | |||
50 | onTriggered: { | | |||
51 | playList.clearAndEnqueue(trackData) | | |||
52 | playerControl.ensurePlay() | | |||
53 | } | | |||
54 | } | | |||
55 | | ||||
56 | Action { | | |||
57 | id: enqueue | | |||
58 | text: i18nc("Enqueue current track", "Enqueue") | | |||
59 | iconName: "media-track-add-amarok" | | |||
60 | onTriggered: { | | |||
61 | playList.enqueue(trackData) | | |||
62 | } | | |||
63 | } | | |||
64 | | ||||
65 | Rectangle { | | |||
66 | id: highlightMarker | | |||
67 | | ||||
68 | anchors.fill: parent | | |||
69 | | ||||
70 | color: (isAlternateColor ? myPalette.alternateBase : myPalette.base) | | |||
71 | | ||||
72 | MouseArea { | | |||
73 | id: hoverArea | | |||
74 | | ||||
75 | anchors.fill: parent | | |||
76 | | ||||
77 | hoverEnabled: true | | |||
78 | | ||||
79 | acceptedButtons: Qt.LeftButton | | |||
80 | | ||||
81 | onClicked: { | | |||
82 | hoverArea.forceActiveFocus() | | |||
83 | viewTrackDelegate.clicked() | | |||
84 | } | | |||
85 | | ||||
86 | onDoubleClicked: playList.enqueue(trackData) | | |||
87 | | ||||
88 | RowLayout { | | |||
89 | anchors.fill: parent | | |||
90 | spacing: 0 | | |||
91 | | ||||
92 | Item { | | |||
93 | Layout.preferredHeight: viewTrackDelegate.height * 0.9 | | |||
94 | Layout.preferredWidth: viewTrackDelegate.height * 0.9 | | |||
95 | | ||||
96 | Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter | | |||
97 | | ||||
98 | Image { | | |||
99 | id: coverImageElement | | |||
100 | | ||||
101 | anchors.fill: parent | | |||
102 | | ||||
103 | sourceSize.width: viewTrackDelegate.height * 0.9 | | |||
104 | sourceSize.height: viewTrackDelegate.height * 0.9 | | |||
105 | fillMode: Image.PreserveAspectFit | | |||
106 | smooth: true | | |||
107 | | ||||
108 | source: (coverImage ? coverImage : Qt.resolvedUrl(elisaTheme.albumCover)) | | |||
109 | | ||||
110 | asynchronous: true | | |||
111 | | ||||
112 | layer.enabled: image == undefined ? false : true | | |||
113 | layer.effect: DropShadow { | | |||
114 | horizontalOffset: viewTrackDelegate.height * 0.02 | | |||
115 | verticalOffset: viewTrackDelegate.height * 0.02 | | |||
116 | | ||||
117 | source: coverImageElement | | |||
118 | | ||||
119 | radius: 5.0 | | |||
120 | samples: 11 | | |||
121 | | ||||
122 | color: myPalette.shadow | | |||
123 | } | | |||
124 | } | | |||
125 | } | | |||
126 | | ||||
127 | ColumnLayout { | | |||
128 | Layout.fillWidth: true | | |||
129 | Layout.fillHeight: true | | |||
130 | Layout.alignment: Qt.AlignLeft | | |||
131 | | ||||
132 | spacing: 0 | | |||
133 | | ||||
134 | LabelWithToolTip { | | |||
135 | id: mainLabel | | |||
136 | | ||||
137 | text: trackNumber + ' - ' + title | | |||
138 | horizontalAlignment: Text.AlignLeft | | |||
139 | | ||||
140 | font.weight: Font.Bold | | |||
141 | color: myPalette.text | | |||
142 | | ||||
143 | Layout.alignment: Qt.AlignLeft | Qt.AlignTop | | |||
144 | Layout.leftMargin: !LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0 | | |||
145 | Layout.rightMargin: LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0 | | |||
146 | Layout.fillWidth: true | | |||
147 | Layout.topMargin: elisaTheme.layoutVerticalMargin / 2 | | |||
148 | | ||||
149 | elide: "ElideRight" | | |||
150 | } | | |||
151 | | ||||
152 | Item { | | |||
153 | Layout.fillHeight: true | | |||
154 | } | | |||
155 | | ||||
156 | LabelWithToolTip { | | |||
157 | id: artistLabel | | |||
158 | | ||||
159 | text: artist + ' - ' + albumName | | |||
160 | horizontalAlignment: Text.AlignLeft | | |||
161 | | ||||
162 | font.weight: Font.Light | | |||
163 | font.italic: true | | |||
164 | color: myPalette.text | | |||
165 | | ||||
166 | Layout.alignment: Qt.AlignLeft | Qt.AlignBottom | | |||
167 | Layout.leftMargin: !LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0 | | |||
168 | Layout.rightMargin: LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0 | | |||
169 | Layout.fillWidth: true | | |||
170 | Layout.bottomMargin: elisaTheme.layoutVerticalMargin / 2 | | |||
171 | | ||||
172 | elide: "ElideRight" | | |||
173 | } | | |||
174 | } | | |||
175 | | ||||
176 | ToolButton { | | |||
177 | id: enqueueButton | | |||
178 | | ||||
179 | Layout.preferredHeight: elisaTheme.trackDelegateHeight * 0.75 | | |||
180 | Layout.preferredWidth: elisaTheme.trackDelegateHeight * 0.75 | | |||
181 | | ||||
182 | opacity: 0 | | |||
183 | visible: opacity > 0.1 | | |||
184 | action: enqueue | | |||
185 | Layout.alignment: Qt.AlignVCenter | Qt.AlignRight | | |||
186 | } | | |||
187 | | ||||
188 | ToolButton { | | |||
189 | id: clearAndEnqueueButton | | |||
190 | | ||||
191 | Layout.preferredHeight: elisaTheme.trackDelegateHeight * 0.75 | | |||
192 | Layout.preferredWidth: elisaTheme.trackDelegateHeight * 0.75 | | |||
193 | | ||||
194 | opacity: 0 | | |||
195 | visible: opacity > 0.1 | | |||
196 | action: clearAndEnqueue | | |||
197 | | ||||
198 | Layout.alignment: Qt.AlignVCenter | Qt.AlignRight | | |||
199 | Layout.rightMargin: !LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0 | | |||
200 | Layout.leftMargin: LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0 | | |||
201 | } | | |||
202 | | ||||
203 | RatingStar { | | |||
204 | id: ratingWidget | | |||
205 | | ||||
206 | starSize: elisaTheme.ratingStarSize | | |||
207 | | ||||
208 | Layout.alignment: Qt.AlignVCenter | Qt.AlignRight | | |||
209 | Layout.leftMargin: elisaTheme.layoutHorizontalMargin | | |||
210 | Layout.rightMargin: elisaTheme.layoutHorizontalMargin | | |||
211 | } | | |||
212 | | ||||
213 | LabelWithToolTip { | | |||
214 | id: durationLabel | | |||
215 | | ||||
216 | text: duration | | |||
217 | | ||||
218 | font.weight: Font.Light | | |||
219 | color: myPalette.text | | |||
220 | | ||||
221 | elide: "ElideRight" | | |||
222 | | ||||
223 | Layout.alignment: Qt.AlignVCenter | Qt.AlignRight | | |||
224 | Layout.rightMargin: !LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0 | | |||
225 | Layout.leftMargin: LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0 | | |||
226 | } | | |||
227 | } | | |||
228 | } | | |||
229 | } | | |||
230 | | ||||
231 | states: [ | | |||
232 | State { | | |||
233 | name: 'notSelected' | | |||
234 | when: !hoverArea.containsMouse && !viewTrackDelegate.activeFocus | | |||
235 | PropertyChanges { | | |||
236 | target: clearAndEnqueueButton | | |||
237 | opacity: 0 | | |||
238 | } | | |||
239 | PropertyChanges { | | |||
240 | target: enqueueButton | | |||
241 | opacity: 0 | | |||
242 | } | | |||
243 | PropertyChanges { | | |||
244 | target: highlightMarker | | |||
245 | color: (isAlternateColor ? myPalette.alternateBase : myPalette.base) | | |||
246 | } | | |||
247 | }, | | |||
248 | State { | | |||
249 | name: 'hoveredAndNotSelected' | | |||
250 | when: hoverArea.containsMouse || viewTrackDelegate.activeFocus | | |||
251 | PropertyChanges { | | |||
252 | target: clearAndEnqueueButton | | |||
253 | opacity: 1 | | |||
254 | } | | |||
255 | PropertyChanges { | | |||
256 | target: enqueueButton | | |||
257 | opacity: 1 | | |||
258 | } | | |||
259 | PropertyChanges { | | |||
260 | target: highlightMarker | | |||
261 | color: myPalette.mid | | |||
262 | } | | |||
263 | } | | |||
264 | | ||||
265 | ] | | |||
266 | transitions: Transition { | | |||
267 | ParallelAnimation { | | |||
268 | NumberAnimation { | | |||
269 | properties: "height, opacity" | | |||
270 | easing.type: Easing.InOutQuad | | |||
271 | duration: 50 | | |||
272 | } | | |||
273 | ColorAnimation { | | |||
274 | properties: "color" | | |||
275 | duration: 200 | | |||
276 | } | | |||
277 | } | | |||
278 | } | | |||
279 | } | |