on xenial help sign in
Fixed things in review, added test for NAN
commit658f97b6bd767f3596196f0f5762b5a5002a766c authorAndrea Cimitan <andrea.cimitan@gmail.com> dateWed 5 Feb 2014, 11:11 (13 years ago) parentc1564f7
3 files changed+25−24
qml/Dash/Previews/PreviewAudioPlayback.qml+22−22 qml/Dash/Previews/PreviewWidget.qml+2−2 tests/qmltests/Dash/Previews/tst_PreviewAudioPlayback.qml+1
qml/Dash/Previews/PreviewAudioPlayback.qml+22−22
@@ -34,7 +34,7 @@ import Ubuntu.Components 0.1
3434
3535PreviewWidget {
3636 id: root
37− implicitHeight: childrenRect.height
37+ height: childrenRect.height
3838
3939 onIsCurrentPreviewChanged: if (!isCurrentPreview) audio.stop()
4040
@@ -46,24 +46,24 @@ PreviewWidget {
4646 property Item playingItem
4747
4848 Component.onDestruction: {
49− // destructing the component doesn't automatically send stop to the media service, probably a bug in QtMultimedia
49+ // destroying the component doesn't automatically send stop to the media service, probably a bug in QtMultimedia
5050 audio.stop();
5151 }
5252
5353 onErrorStringChanged: console.warn("Audio player error:", errorString)
5454
5555 function lengthToString(s) {
56− if (s <= 0 || s === undefined) return ""
56+ if (s <= 0 || typeof(s) !== "number") return "";
5757
58− var sec = "" + s % 60
59− if (sec.length == 1) sec = "0" + sec
60− var hour = Math.floor(s / 3600)
58+ var sec = "" + s % 60;
59+ if (sec.length == 1) sec = "0" + sec;
60+ var hour = Math.floor(s / 3600);
6161 if (hour < 1) {
62− return Math.floor(s / 60) + ":" + sec
62+ return Math.floor(s / 60) + ":" + sec;
6363 } else {
64− var min = "" + Math.floor(s / 60) % 60
65− if (min.length == 1) min = "0" + min
66− return hour + ":" + min + ":" + sec
64+ var min = "" + Math.floor(s / 60) % 60;
65+ if (min.length == 1) min = "0" + min;
66+ return hour + ":" + min + ":" + sec;
6767 }
6868 }
6969 }
@@ -77,6 +77,15 @@ PreviewWidget {
7777 objectName: "trackRepeater"
7878 model: root.widgetData["tracks"]
7979
80+ function play(item, source) {
81+ audio.stop();
82+ // Make sure we change the source, even if two items point to the same uri location
83+ audio.source = "";
84+ audio.source = source;
85+ audio.playingItem = item;
86+ audio.play();
87+ }
88+
8089 delegate: Item {
8190 id: trackItem
8291 objectName: "trackItem" + index
@@ -86,15 +95,6 @@ PreviewWidget {
8695 anchors { left: parent.left; right: parent.right }
8796 height: units.gu(5)
8897
89− function play() {
90− audio.stop();
91− // Make sure we change the source, even if two items point to the same uri location
92− audio.source = "";
93− audio.source = modelData["source"];
94− audio.playingItem = trackItem;
95− audio.play();
96− }
97−
9898 Row {
9999 id: trackRow
100100
@@ -120,11 +120,11 @@ PreviewWidget {
120120 if (trackItem.isPlayingItem) {
121121 if (audio.playbackState == Audio.PlayingState) {
122122 audio.pause();
123− } else if (audio.playbackState == Audio.PausedState){
123+ } else if (audio.playbackState == Audio.PausedState) {
124124 audio.play();
125125 }
126126 } else {
127− trackItem.play();
127+ trackRepeater.play(trackItem, modelData["source"]);
128128 }
129129 }
130130 }
@@ -155,7 +155,7 @@ PreviewWidget {
155155 color: Theme.palette.selected.backgroundText
156156 fontSize: "small"
157157 horizontalAlignment: Text.AlignLeft
158− text: modelData["subtitle"] !== undefined ? modelData["subtitle"] : ""
158+ text: (modelData["subtitle"] && modelData["subtitle"] !== undefined) ? modelData["subtitle"] : ""
159159 elide: Text.ElideRight
160160 }
161161
qml/Dash/Previews/PreviewWidget.qml+2−2
@@ -19,9 +19,9 @@ import QtQuick 2.0
1919/*! Interface for preview widgets. */
2020
2121Item {
22− /// type:bool Specifies the preview widget being currently used or not
22+ //! Specifies the preview widget being currently used or not
2323 property bool isCurrentPreview: true
2424
25− /// Variable used to contain widget's data
25+ //! Variable used to contain widget's data
2626 property var widgetData
2727}
tests/qmltests/Dash/Previews/tst_PreviewAudioPlayback.qml+1
@@ -57,6 +57,7 @@ Rectangle {
5757
5858 function test_time_formatter_data() {
5959 return [
60+ { tag: "NaN", value: "not a number", result: "" },
6061 { tag: "0", value: 0, result: "" },
6162 { tag: "-1", value: -1, result: "" },
6263 { tag: "30", value: 30, result: "0:30" },