on xenial help sign in
Add a card creator test for the audio card
02bf6c5Albert Astals Cid
plugins/Dash/CardCreator.js+1−1
@@ -395,7 +395,7 @@ function cardString(template, components) {
395 var headerAsOverlay = hasArt && template && template["overlay"] === true && (hasTitle || hasMascot);
395 var headerAsOverlay = hasArt && template && template["overlay"] === true && (hasTitle || hasMascot);
396 var hasSubtitle = hasTitle && components["subtitle"] || false;
396 var hasSubtitle = hasTitle && components["subtitle"] || false;
397 var hasHeaderRow = hasMascot && hasTitle;
397 var hasHeaderRow = hasMascot && hasTitle;
398− var hasAttributes = hasTitle && components["attributes"]["field"] || false;
398+ var hasAttributes = hasTitle && components["attributes"] && components["attributes"]["field"] || false;
399 var isAudio = template["quickPreviewType"] === "audio";
399 var isAudio = template["quickPreviewType"] === "audio";
400
400
401 if (isAudio) {
401 if (isAudio) {
plugins/Dash/qmldir+1
@@ -7,3 +7,4 @@ ScopeStyle 0.1 ScopeStyle.qml
7CardAttributes 0.1 CardAttributes.qml
7CardAttributes 0.1 CardAttributes.qml
8CroppedImageMinimumSourceSize 0.1 CroppedImageMinimumSourceSize.qml
8CroppedImageMinimumSourceSize 0.1 CroppedImageMinimumSourceSize.qml
9AudioProgressBar 0.1 AudioProgressBar.qml
9AudioProgressBar 0.1 AudioProgressBar.qml
10+CardAudioProgress 0.1 CardAudioProgress.qml
tests/plugins/Dash/cardcreator/8.resnew file+109
@@ -0,0 +1,109 @@
1+AbstractButton {
2+ id: root;
3+ property var template;
4+ property var components;
5+ property var cardData;
6+ property var artShapeBorderSource: undefined;
7+ property real fontScale: 1.0;
8+ property var scopeStyle: null;
9+ property int titleAlignment: Text.AlignLeft;
10+ property int fixedHeaderHeight: -1;
11+ property size fixedArtShapeSize: Qt.size(-1, -1);
12+ readonly property string title: cardData && cardData["title"] || "";
13+ property bool asynchronous: true;
14+ property bool showHeader: true;
15+ implicitWidth: childrenRect.width;
16+ enabled: root.template == null ? true : (root.template["non-interactive"] !== undefined ? !root.template["non-interactive"] : true);
17+
18+readonly property size artShapeSize: Qt.size(-1, -1);
19+readonly property int headerHeight: titleLabel.height + subtitleLabel.height + subtitleLabel.anchors.topMargin + audioProgressBar.height + audioProgressBar.anchors.topMargin;
20+Label {
21+ id: titleLabel;
22+ objectName: "titleLabel";
23+ anchors { right: parent.right;
24+rightMargin: units.gu(1);
25+left: audioButton.right;
26+ leftMargin: units.gu(1);
27+top: parent.top;
28+ topMargin: units.gu(1);
29+ }
30+ elide: Text.ElideRight;
31+ fontSize: "small";
32+ wrapMode: Text.Wrap;
33+ maximumLineCount: 2;
34+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
35+ color: root.scopeStyle ? root.scopeStyle.foreground : Theme.palette.normal.baseText;
36+ visible: showHeader ;
37+ text: root.title;
38+ font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal;
39+ horizontalAlignment: root.titleAlignment;
40+ }
41+Label {
42+ id: subtitleLabel;
43+ objectName: "subtitleLabel";
44+ anchors { left: titleLabel.left;
45+ leftMargin: titleLabel.leftMargin;
46+rightMargin: units.gu(1);
47+right: titleLabel.right;
48+top: titleLabel.bottom;
49+ }
50+ anchors.topMargin: units.dp(2);
51+ elide: Text.ElideRight;
52+ maximumLineCount: 1;
53+ fontSize: "x-small";
54+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
55+ color: root.scopeStyle ? root.scopeStyle.foreground : Theme.palette.normal.baseText;
56+ visible: titleLabel.visible && titleLabel.text;
57+ text: cardData && cardData["subtitle"] || "";
58+ font.weight: Font.Light;
59+ }
60+CardAudioProgress {
61+ id: audioProgressBar;
62+ duration: (cardData["quickPreviewData"] && cardData["quickPreviewData"]["duration"]) || 0;
63+ source: (cardData["quickPreviewData"] && cardData["quickPreviewData"]["uri"]) || "";
64+ anchors {
65+ bottom: audioButton.bottom;
66+ left: audioButton.right;
67+ right: parent.right;
68+ margins: units.gu(1);
69+ }
70+ color: root.scopeStyle ? root.scopeStyle.foreground : Theme.palette.normal.baseText;
71+ }AbstractButton {
72+ id: audioButton;
73+ anchors.fill: undefined;
74+ width: height;
75+ height: (root.fixedHeaderHeight > 0 ? root.fixedHeaderHeight : headerHeight) + 2 * units.gu(1);
76+ readonly property url source: (cardData["quickPreviewData"] && cardData["quickPreviewData"]["uri"]) || "";
77+ UbuntuShape {
78+ anchors.fill: parent;
79+ visible: parent.pressed;
80+ radius: "medium";
81+ borderSource: "radius_pressed.sci"
82+ }
83+ Icon {
84+ anchors.fill: parent;
85+ anchors.margins: parent.height > units.gu(5) ? units.gu(2) : units.gu(0);
86+ opacity: 0.9;
87+ name: DashAudioPlayer.isCurrentSource(parent.source) && DashAudioPlayer.playing ? "media-playback-pause" : "media-playback-start";
88+ }
89+ onClicked: {
90+ if (DashAudioPlayer.isCurrentSource(source)) {
91+ if (DashAudioPlayer.playing) {
92+ DashAudioPlayer.pause();
93+ } else {
94+ DashAudioPlayer.play();
95+ }
96+ } else {
97+ DashAudioPlayer.playSource(source);
98+ }
99+ }
100+ }UbuntuShape {
101+ id: touchdown;
102+ objectName: "touchdown";
103+ anchors { fill: root }
104+ visible: root.pressed;
105+ radius: "medium";
106+ borderSource: "radius_pressed.sci"
107+ }
108+implicitHeight: audioButton.height;
109+}
tests/plugins/Dash/cardcreator/8.tstnew file+3
@@ -0,0 +1,3 @@
1+template: {"card-layout":"horizontal","card-size":"medium","category-layout":"grid","collapsed-rows":2,"quickPreviewType": "audio"}
2+components: {"art":{"aspect-ratio":1},"subtitle":{"field":"author"},"title":{"field":"title"}, "quickPreviewData": "quickPreviewData"}
3+result: 8.res