2 * Copyright (C) 2014,2015 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 import Ubuntu.Components 1.3
21 /*! \brief Preview widget for audio tracks.
23 This widget shows tracks contained in widgetData["tracks"], each of which should be of the form:
27 "source" "uri://to/file",
29 "subtitle": "Subtitle", // optional
30 "length": 125 // in seconds
37 implicitHeight: childrenRect.height
40 anchors { left: parent.left; right: parent.right }
41 visible: trackRepeater.count > 0
45 objectName: "trackRepeater"
46 model: root.widgetData["tracks"]
50 objectName: "trackItem" + index
52 readonly property url sourceUrl: modelData["source"]
53 readonly property bool isPlayingItem: AudioUrlComparer.compare(sourceUrl, DashAudioPlayer.currentSource)
55 anchors { left: parent.left; right: parent.right }
61 readonly property int column1Width: units.gu(2)
62 readonly property int column2Width: width - (2 * spacing) - column1Width - column3Width
63 readonly property int column3Width: units.gu(4)
65 anchors.verticalCenter: parent.verticalCenter
70 objectName: "playButton"
71 width: trackRow.column1Width
73 activeFocusOnPress: false
76 if (trackItem.isPlayingItem) {
77 if (DashAudioPlayer.playing) {
78 DashAudioPlayer.pause();
79 } else if (DashAudioPlayer.paused) {
80 DashAudioPlayer.play();
84 for (var i = 0; i < trackRepeater.count; ++i) {
85 playlist.push(trackRepeater.itemAt(i).sourceUrl);
87 DashAudioPlayer.playSource(sourceUrl, playlist);
93 source: DashAudioPlayer.playing && trackItem.isPlayingItem ? "image://theme/media-preview-pause" : "image://theme/media-preview-start"
98 anchors.verticalCenter: parent.verticalCenter
99 width: parent.column2Width
100 height: trackSubtitleLabel.visible ? trackTitleLabel.height + trackSubtitleLabel.height : trackTitleLabel.height
104 objectName: "trackTitleLabel"
105 anchors { top: parent.top; left: parent.left; right: parent.right }
107 color: scopeStyle ? scopeStyle.foreground : theme.palette.normal.baseText
109 font.weight: Font.Light
110 horizontalAlignment: Text.AlignLeft
111 text: modelData["title"]
112 elide: Text.ElideRight
116 id: trackSubtitleLabel
117 objectName: "trackSubtitleLabel"
118 anchors { top: trackTitleLabel.bottom; left: parent.left; right: parent.right }
121 color: scopeStyle ? scopeStyle.foreground : theme.palette.normal.baseText
122 font.weight: Font.Light
124 horizontalAlignment: Text.AlignLeft
125 text: modelData["subtitle"] || ""
126 elide: Text.ElideRight
130 anchors { left: parent.left; top: parent.bottom; right: parent.right }
131 visible: !DashAudioPlayer.stopped && trackItem.isPlayingItem && modelData["length"] > 0
138 objectName: "timeLabel"
139 anchors.verticalCenter: parent.verticalCenter
140 width: parent.column3Width
142 color: scopeStyle ? scopeStyle.foreground : theme.palette.normal.baseText
144 font.weight: Font.Light
145 horizontalAlignment: Text.AlignRight
146 text: DashAudioPlayer.lengthToString(modelData["length"])