on xenial help sign in
Do not create fallback code for the card tool fake card

Causes issues with layouting Fixes: #1545865 Approved by: Andrea Cimitan, Unity8 CI Bot

commita26f1c6e4d31d3bf4d42c61b81d62a7b6a780c50 authorAlbert Astals Cid <albert.astals@canonical.com> dateThu 10 Mar 2016, 22:38 (11 years ago) parent0163213e9cd011
16 files changed+1589−36
plugins/Dash/CardCreator.js+5−5 plugins/Dash/CardCreatorCache.qml+3−3 qml/Dash/CardTool.qml+2−2 tests/plugins/Dash/cardcreator/1.res.cardcreator+122 tests/plugins/Dash/cardcreator/10.res.cardcreator+141 tests/plugins/Dash/cardcreator/11.res.cardcreator+214 tests/plugins/Dash/cardcreator/2.res.cardcreator+140 tests/plugins/Dash/cardcreator/3.res.cardcreator+140 tests/plugins/Dash/cardcreator/4.res.cardcreator+113 tests/plugins/Dash/cardcreator/5.res.cardcreator+159 tests/plugins/Dash/cardcreator/6.res.cardcreator+129 tests/plugins/Dash/cardcreator/7.res.cardcreator+153 tests/plugins/Dash/cardcreator/8.res.cardcreator+111 tests/plugins/Dash/cardcreator/9.res.cardcreator+121 tests/plugins/Dash/cardcreatortest.cpp+32−22 tests/plugins/Dash/cardcreatortest.qml+4−4
plugins/Dash/CardCreator.js+5−5
@@ -398,7 +398,7 @@ function sanitizeColor(colorString) {
398398 return colorString;
399399}
400400
401−function cardString(template, components) {
401+function cardString(template, components, isCardTool) {
402402 var code;
403403
404404 var templateInteractive = (template == null ? true : (template["non-interactive"] !== undefined ? !template["non-interactive"] : true)) ? "true" : "false";
@@ -497,7 +497,7 @@ function cardString(template, components) {
497497 if (isNaN(aspectRatio)) {
498498 aspectRatio = 1;
499499 }
500− var fallback = components["art"] && components["art"]["fallback"] || "";
500+ var fallback = !isCardTool && components["art"] && components["art"]["fallback"] || "";
501501 fallback = encodeURI(fallback);
502502 var fallbackStatusCode = "";
503503 var fallbackURICode = '""';
@@ -599,7 +599,7 @@ function cardString(template, components) {
599599 }
600600
601601 var mascotImageVisible = useMascotShape ? 'false' : 'showHeader';
602− var fallback = components["mascot"] && components["mascot"]["fallback"] || "";
602+ var fallback = !isCardTool && components["mascot"] && components["mascot"]["fallback"] || "";
603603 fallback = encodeURI(fallback);
604604 var fallbackStatusCode = "";
605605 var fallbackURICode = '""';
@@ -854,13 +854,13 @@ function cardString(template, components) {
854854 return code;
855855}
856856
857−function createCardComponent(parent, template, components, identifier) {
857+function createCardComponent(parent, template, components, isCardTool, identifier) {
858858 var imports = 'import QtQuick 2.4; \n\
859859 import Ubuntu.Components 1.3; \n\
860860 import Ubuntu.Settings.Components 0.1; \n\
861861 import Dash 0.1;\n\
862862 import Utils 0.1;\n';
863− var card = cardString(template, components);
863+ var card = cardString(template, components, isCardTool);
864864 var code = imports + 'Component {\n' + card + '}\n';
865865
866866 try {
plugins/Dash/CardCreatorCache.qml+3−3
@@ -23,16 +23,16 @@ QtObject {
2323
2424 property var cache: new Object();
2525
26− function getCardComponent(template, components) {
26+ function getCardComponent(template, components, isCardTool) {
2727 if (template === undefined || components === undefined)
2828 return undefined;
2929
3030 var tString = JSON.stringify(template);
3131 var cString = JSON.stringify(components);
32− var allString = tString + cString;
32+ var allString = tString + cString + isCardTool;
3333 var component = cache[allString];
3434 if (component === undefined) {
35− component = CardCreator.createCardComponent(root, template, components, allString);
35+ component = CardCreator.createCardComponent(root, template, components, isCardTool, allString);
3636 cache[allString] = component;
3737 }
3838 return component;
qml/Dash/CardTool.qml+2−2
@@ -66,7 +66,7 @@ Item {
6666 return layout;
6767 }
6868
69− property var cardComponent: CardCreatorCache.getCardComponent(cardTool.template, cardTool.components);
69+ property var cardComponent: CardCreatorCache.getCardComponent(cardTool.template, cardTool.components, false);
7070
7171 // FIXME: Saviq
7272 // Only way for the card below to actually be laid out completely.
@@ -216,7 +216,7 @@ Item {
216216 "summary": "—\n—\n—\n—\n—",
217217 "attributes": attributesModel.model
218218 }
219− sourceComponent: cardTool.cardComponent
219+ sourceComponent: CardCreatorCache.getCardComponent(cardTool.template, cardTool.components, true);
220220 onLoaded: {
221221 item.objectName = "cardToolCard";
222222 item.asynchronous = false;
tests/plugins/Dash/cardcreator/1.res.cardcreatornew file+122
@@ -0,0 +1,122 @@
1+AbstractButton {
2+ id: root;
3+ property var cardData;
4+ property string artShapeStyle: "inset";
5+ property string backgroundShapeStyle: "inset";
6+ property real fontScale: 1.0;
7+ property var scopeStyle: null;
8+ property int titleAlignment: Text.AlignLeft;
9+ property int fixedHeaderHeight: -1;
10+ property size fixedArtShapeSize: Qt.size(-1, -1);
11+ readonly property string title: cardData && cardData["title"] || "";
12+ property bool asynchronous: true;
13+ property bool showHeader: true;
14+ implicitWidth: childrenRect.width;
15+ enabled: true;
16+
17+readonly property size artShapeSize: artShapeLoader.item ? Qt.size(artShapeLoader.item.width, artShapeLoader.item.height) : Qt.size(-1, -1);
18+Item {
19+ id: artShapeHolder;
20+ height: root.fixedArtShapeSize.height > 0 ? root.fixedArtShapeSize.height : artShapeLoader.height;
21+ width: root.fixedArtShapeSize.width > 0 ? root.fixedArtShapeSize.width : artShapeLoader.width;
22+ anchors { horizontalCenter: parent.horizontalCenter; }
23+ Loader {
24+ id: artShapeLoader;
25+ objectName: "artShapeLoader";
26+ readonly property string cardArt: cardData && cardData["art"] || "";
27+ active: cardArt != "";
28+ asynchronous: root.asynchronous;
29+ visible: status == Loader.Ready;
30+ sourceComponent: Item {
31+ id: artShape;
32+ objectName: "artShape";
33+ visible: image.status == Image.Ready;
34+ readonly property alias image: artImage;
35+ ShaderEffectSource {
36+ id: artShapeSource;
37+ sourceItem: artImage;
38+ anchors.centerIn: parent;
39+ width: 1;
40+ height: 1;
41+ hideSource: true;
42+ }
43+ Loader {
44+ anchors.fill: parent;
45+ visible: true;
46+ sourceComponent: root.artShapeStyle === "icon" ? artShapeIconComponent : artShapeShapeComponent;
47+ Component {
48+ id: artShapeShapeComponent;
49+ UbuntuShape {
50+ source: artShapeSource;
51+ sourceFillMode: UbuntuShape.PreserveAspectCrop;
52+ radius: "medium";
53+ aspect: {
54+ switch (root.artShapeStyle) {
55+ case "inset": return UbuntuShape.Inset;
56+ case "shadow": return UbuntuShape.DropShadow;
57+ default:
58+ case "flat": return UbuntuShape.Flat;
59+ }
60+ }
61+ }
62+ }
63+ Component {
64+ id: artShapeIconComponent;
65+ ProportionalShape { source: artShapeSource; aspect: UbuntuShape.DropShadow; }
66+ }
67+ }
68+ readonly property real fixedArtShapeSizeAspect: (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) ? root.fixedArtShapeSize.width / root.fixedArtShapeSize.height : -1;
69+ readonly property real aspect: fixedArtShapeSizeAspect > 0 ? fixedArtShapeSizeAspect : 1.6;
70+ Component.onCompleted: { updateWidthHeightBindings(); }
71+ Connections { target: root; onFixedArtShapeSizeChanged: updateWidthHeightBindings(); }
72+ function updateWidthHeightBindings() {
73+ if (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) {
74+ width = root.fixedArtShapeSize.width;
75+ height = root.fixedArtShapeSize.height;
76+ } else {
77+ width = Qt.binding(function() { return image.status !== Image.Ready ? 0 : image.width });
78+ height = Qt.binding(function() { return image.status !== Image.Ready ? 0 : image.height });
79+ }
80+ }
81+ CroppedImageMinimumSourceSize {
82+ id: artImage;
83+ objectName: "artImage";
84+ source: artShapeLoader.cardArt;
85+ asynchronous: root.asynchronous;
86+ width: root.width;
87+ height: width / artShape.aspect;
88+ }
89+ }
90+ }
91+ }
92+readonly property int headerHeight: titleLabel.height;
93+Label {
94+ id: titleLabel;
95+ objectName: "titleLabel";
96+ anchors { right: parent.right;
97+ left: parent.left;
98+ top: artShapeHolder.bottom;
99+ topMargin: units.gu(1);
100+ }
101+ elide: Text.ElideRight;
102+ fontSize: "small";
103+ wrapMode: Text.Wrap;
104+ maximumLineCount: 2;
105+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
106+ color: root.scopeStyle ? root.scopeStyle.foreground : theme.palette.normal.baseText;
107+ visible: showHeader ;
108+ width: undefined;
109+ text: root.title;
110+ font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal;
111+ horizontalAlignment: root.titleAlignment;
112+ }
113+UbuntuShape {
114+ id: touchdown;
115+ objectName: "touchdown";
116+ anchors { fill: artShapeHolder }
117+ visible: root.artShapeStyle != "shadow" && root.artShapeStyle != "icon" && root.pressed;
118+ radius: "medium";
119+ borderSource: "radius_pressed.sci"
120+}
121+implicitHeight: titleLabel.y + titleLabel.height + units.gu(1);
122+}
tests/plugins/Dash/cardcreator/10.res.cardcreatornew file+141
@@ -0,0 +1,141 @@
1+AbstractButton {
2+ id: root;
3+ property var cardData;
4+ property string artShapeStyle: "inset";
5+ property string backgroundShapeStyle: "inset";
6+ property real fontScale: 1.0;
7+ property var scopeStyle: null;
8+ property int titleAlignment: Text.AlignLeft;
9+ property int fixedHeaderHeight: -1;
10+ property size fixedArtShapeSize: Qt.size(-1, -1);
11+ readonly property string title: cardData && cardData["title"] || "";
12+ property bool asynchronous: true;
13+ property bool showHeader: true;
14+ implicitWidth: childrenRect.width;
15+ enabled: true;
16+
17+Loader {
18+ id: backgroundLoader;
19+ objectName: "backgroundLoader";
20+ anchors.fill: parent;
21+ asynchronous: root.asynchronous;
22+ visible: status == Loader.Ready;
23+ sourceComponent: UbuntuShape {
24+ objectName: "background";
25+ radius: "medium";
26+ aspect: {
27+ switch (root.backgroundShapeStyle) {
28+ case "inset": return UbuntuShape.Inset;
29+ case "shadow": return UbuntuShape.DropShadow;
30+ default:
31+ case "flat": return UbuntuShape.Flat;
32+ }
33+ }
34+ backgroundColor: getColor(0) || "white";
35+ secondaryBackgroundColor: getColor(1) || backgroundColor;
36+ backgroundMode: UbuntuShape.VerticalGradient;
37+ anchors.fill: parent;
38+ source: backgroundImage.source ? backgroundImage : null;
39+ property real luminance: Style.luminance(backgroundColor);
40+ property Image backgroundImage: Image {
41+ objectName: "backgroundImage";
42+ source: {
43+ if (cardData && typeof cardData["background"] === "string") return cardData["background"];
44+ else return "";
45+ }
46+ }
47+ function getColor(index) {
48+ if (cardData && typeof cardData["background"] === "object"
49+ && (cardData["background"]["type"] === "color" || cardData["background"]["type"] === "gradient")) {
50+ return cardData["background"]["elements"][index];
51+ } else return index === 0 ? "" : "";
52+ }
53+ }
54+ }
55+readonly property size artShapeSize: Qt.size(-1, -1);
56+readonly property int headerHeight: row.height;
57+Row {
58+ id: row;
59+ objectName: "outerRow";
60+ property real margins: units.gu(1);
61+ spacing: margins;
62+ height: root.fixedHeaderHeight != -1 ? root.fixedHeaderHeight : implicitHeight;
63+ anchors { top: parent.top;
64+ topMargin: units.gu(1);
65+left: parent.left;
66+ }
67+ anchors.right: parent.right;
68+ anchors.margins: margins;
69+ anchors.rightMargin: 0;
70+ data: [
71+ CroppedImageMinimumSourceSize {
72+ id: mascotImage;
73+ objectName: "mascotImage";
74+ anchors { verticalCenter: parent.verticalCenter; }
75+ source: cardData && cardData["mascot"] || "";
76+ width: units.gu(6);
77+ height: units.gu(5.625);
78+ horizontalAlignment: Image.AlignHCenter;
79+ verticalAlignment: Image.AlignVCenter;
80+ visible: showHeader;
81+
82+ }
83+,Item {
84+ id: headerTitleContainer;
85+ anchors { verticalCenter: parent.verticalCenter; }
86+ width: parent.width - x;
87+ implicitHeight: titleLabel.height + subtitleLabel.height;
88+ data: [
89+ Label {
90+ id: titleLabel;
91+ objectName: "titleLabel";
92+ anchors { right: parent.right;
93+rightMargin: units.gu(1);
94+left: parent.left;
95+ top: parent.top; }
96+ elide: Text.ElideRight;
97+ fontSize: "small";
98+ wrapMode: Text.Wrap;
99+ maximumLineCount: 2;
100+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
101+ color: backgroundLoader.active && backgroundLoader.item && root.scopeStyle ? root.scopeStyle.getTextColor(backgroundLoader.item.luminance) : (backgroundLoader.item && backgroundLoader.item.luminance > 0.7 ? theme.palette.normal.baseText : "white");
102+ visible: showHeader ;
103+ width: undefined;
104+ text: root.title;
105+ font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal;
106+ horizontalAlignment: root.titleAlignment;
107+ }
108+,Label {
109+ id: subtitleLabel;
110+ objectName: "subtitleLabel";
111+ anchors { right: parent.right;
112+ left: parent.left;
113+rightMargin: units.gu(1);
114+top: titleLabel.bottom;
115+ }
116+ anchors.topMargin: units.dp(2);
117+ elide: Text.ElideRight;
118+ maximumLineCount: 1;
119+ fontSize: "x-small";
120+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
121+ color: backgroundLoader.active && backgroundLoader.item && root.scopeStyle ? root.scopeStyle.getTextColor(backgroundLoader.item.luminance) : (backgroundLoader.item && backgroundLoader.item.luminance > 0.7 ? theme.palette.normal.baseText : "white");
122+ visible: titleLabel.visible && titleLabel.text;
123+ text: cardData && cardData["subtitle"] || "";
124+ font.weight: Font.Light;
125+ }
126+
127+ ]
128+ }
129+
130+ ]
131+ }
132+UbuntuShape {
133+ id: touchdown;
134+ objectName: "touchdown";
135+ anchors { fill: backgroundLoader }
136+ visible: root.artShapeStyle != "shadow" && root.artShapeStyle != "icon" && root.pressed;
137+ radius: "medium";
138+ borderSource: "radius_pressed.sci"
139+ }
140+implicitHeight: row.y + row.height + units.gu(1);
141+}
tests/plugins/Dash/cardcreator/11.res.cardcreatornew file+214
@@ -0,0 +1,214 @@
1+AbstractButton {
2+ id: root;
3+ property var cardData;
4+ property string artShapeStyle: "inset";
5+ property string backgroundShapeStyle: "inset";
6+ property real fontScale: 1.0;
7+ property var scopeStyle: null;
8+ property int titleAlignment: Text.AlignLeft;
9+ property int fixedHeaderHeight: -1;
10+ property size fixedArtShapeSize: Qt.size(-1, -1);
11+ readonly property string title: cardData && cardData["title"] || "";
12+ property bool asynchronous: true;
13+ property bool showHeader: true;
14+ implicitWidth: childrenRect.width;
15+ enabled: true;
16+
17+Loader {
18+ id: backgroundLoader;
19+ objectName: "backgroundLoader";
20+ anchors.fill: parent;
21+ asynchronous: root.asynchronous;
22+ visible: status == Loader.Ready;
23+ sourceComponent: UbuntuShape {
24+ objectName: "background";
25+ radius: "medium";
26+ aspect: {
27+ switch (root.backgroundShapeStyle) {
28+ case "inset": return UbuntuShape.Inset;
29+ case "shadow": return UbuntuShape.DropShadow;
30+ default:
31+ case "flat": return UbuntuShape.Flat;
32+ }
33+ }
34+ backgroundColor: getColor(0) || "white";
35+ secondaryBackgroundColor: getColor(1) || backgroundColor;
36+ backgroundMode: UbuntuShape.VerticalGradient;
37+ anchors.fill: parent;
38+ source: backgroundImage.source ? backgroundImage : null;
39+ property real luminance: Style.luminance(backgroundColor);
40+ property Image backgroundImage: Image {
41+ objectName: "backgroundImage";
42+ source: {
43+ if (cardData && typeof cardData["background"] === "string") return cardData["background"];
44+ else return "";
45+ }
46+ }
47+ function getColor(index) {
48+ if (cardData && typeof cardData["background"] === "object"
49+ && (cardData["background"]["type"] === "color" || cardData["background"]["type"] === "gradient")) {
50+ return cardData["background"]["elements"][index];
51+ } else return index === 0 ? "#E9E9E9" : undefined;
52+ }
53+ }
54+ }
55+readonly property size artShapeSize: artShapeLoader.item ? Qt.size(artShapeLoader.item.width, artShapeLoader.item.height) : Qt.size(-1, -1);
56+Item {
57+ id: artShapeHolder;
58+ height: root.fixedArtShapeSize.height > 0 ? root.fixedArtShapeSize.height : artShapeLoader.height;
59+ width: root.fixedArtShapeSize.width > 0 ? root.fixedArtShapeSize.width : artShapeLoader.width;
60+ anchors { horizontalCenter: parent.horizontalCenter; }
61+ Loader {
62+ id: artShapeLoader;
63+ objectName: "artShapeLoader";
64+ readonly property string cardArt: cardData && cardData["art"] || "";
65+ active: cardArt != "";
66+ asynchronous: root.asynchronous;
67+ visible: status == Loader.Ready;
68+ sourceComponent: Item {
69+ id: artShape;
70+ objectName: "artShape";
71+ visible: image.status == Image.Ready;
72+ readonly property alias image: artImage;
73+ ShaderEffectSource {
74+ id: artShapeSource;
75+ sourceItem: artImage;
76+ anchors.centerIn: parent;
77+ width: 1;
78+ height: 1;
79+ hideSource: true;
80+ }
81+ Loader {
82+ anchors.fill: parent;
83+ visible: true;
84+ sourceComponent: root.artShapeStyle === "icon" ? artShapeIconComponent : artShapeShapeComponent;
85+ Component {
86+ id: artShapeShapeComponent;
87+ UbuntuShape {
88+ source: artShapeSource;
89+ sourceFillMode: UbuntuShape.PreserveAspectCrop;
90+ radius: "medium";
91+ aspect: {
92+ switch (root.artShapeStyle) {
93+ case "inset": return UbuntuShape.Inset;
94+ case "shadow": return UbuntuShape.DropShadow;
95+ default:
96+ case "flat": return UbuntuShape.Flat;
97+ }
98+ }
99+ }
100+ }
101+ Component {
102+ id: artShapeIconComponent;
103+ ProportionalShape { source: artShapeSource; aspect: UbuntuShape.DropShadow; }
104+ }
105+ }
106+ readonly property real fixedArtShapeSizeAspect: (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) ? root.fixedArtShapeSize.width / root.fixedArtShapeSize.height : -1;
107+ readonly property real aspect: fixedArtShapeSizeAspect > 0 ? fixedArtShapeSizeAspect : 1;
108+ Component.onCompleted: { updateWidthHeightBindings(); }
109+ Connections { target: root; onFixedArtShapeSizeChanged: updateWidthHeightBindings(); }
110+ function updateWidthHeightBindings() {
111+ if (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) {
112+ width = root.fixedArtShapeSize.width;
113+ height = root.fixedArtShapeSize.height;
114+ } else {
115+ width = Qt.binding(function() { return image.status !== Image.Ready ? 0 : image.width });
116+ height = Qt.binding(function() { return image.status !== Image.Ready ? 0 : image.height });
117+ }
118+ }
119+ CroppedImageMinimumSourceSize {
120+ id: artImage;
121+ objectName: "artImage";
122+ source: artShapeLoader.cardArt;
123+ asynchronous: root.asynchronous;
124+ width: root.width;
125+ height: width / artShape.aspect;
126+ }
127+ }
128+ }
129+ }
130+readonly property int headerHeight: row.height;
131+Row {
132+ id: row;
133+ objectName: "outerRow";
134+ property real margins: units.gu(1);
135+ spacing: margins;
136+ height: root.fixedHeaderHeight != -1 ? root.fixedHeaderHeight : implicitHeight;
137+ anchors { top: artShapeHolder.bottom;
138+ topMargin: units.gu(1);
139+left: parent.left;
140+ }
141+ anchors.right: parent.right;
142+ anchors.margins: margins;
143+ anchors.rightMargin: 0;
144+ data: [
145+ CroppedImageMinimumSourceSize {
146+ id: mascotImage;
147+ objectName: "mascotImage";
148+ anchors { verticalCenter: parent.verticalCenter; }
149+ source: cardData && cardData["mascot"] || "";
150+ width: units.gu(6);
151+ height: units.gu(5.625);
152+ horizontalAlignment: Image.AlignHCenter;
153+ verticalAlignment: Image.AlignVCenter;
154+ visible: showHeader;
155+ }
156+,Item {
157+ id: headerTitleContainer;
158+ anchors { verticalCenter: parent.verticalCenter; }
159+ width: parent.width - x;
160+ implicitHeight: titleLabel.height + subtitleLabel.height;
161+ data: [
162+ Label {
163+ id: titleLabel;
164+ objectName: "titleLabel";
165+ anchors { right: parent.right;
166+rightMargin: units.gu(1);
167+left: parent.left;
168+ top: parent.top; }
169+ elide: Text.ElideRight;
170+ fontSize: "small";
171+ wrapMode: Text.Wrap;
172+ maximumLineCount: 2;
173+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
174+ color: backgroundLoader.active && backgroundLoader.item && root.scopeStyle ? root.scopeStyle.getTextColor(backgroundLoader.item.luminance) : (backgroundLoader.item && backgroundLoader.item.luminance > 0.7 ? theme.palette.normal.baseText : "white");
175+ visible: showHeader ;
176+ width: undefined;
177+ text: root.title;
178+ font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal;
179+ horizontalAlignment: root.titleAlignment;
180+ }
181+,Label {
182+ id: subtitleLabel;
183+ objectName: "subtitleLabel";
184+ anchors { right: parent.right;
185+ left: parent.left;
186+rightMargin: units.gu(1);
187+top: titleLabel.bottom;
188+ }
189+ anchors.topMargin: units.dp(2);
190+ elide: Text.ElideRight;
191+ maximumLineCount: 1;
192+ fontSize: "x-small";
193+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
194+ color: backgroundLoader.active && backgroundLoader.item && root.scopeStyle ? root.scopeStyle.getTextColor(backgroundLoader.item.luminance) : (backgroundLoader.item && backgroundLoader.item.luminance > 0.7 ? theme.palette.normal.baseText : "white");
195+ visible: titleLabel.visible && titleLabel.text;
196+ text: cardData && cardData["subtitle"] || "";
197+ font.weight: Font.Light;
198+ }
199+
200+ ]
201+ }
202+
203+ ]
204+ }
205+UbuntuShape {
206+ id: touchdown;
207+ objectName: "touchdown";
208+ anchors { fill: backgroundLoader }
209+ visible: root.artShapeStyle != "shadow" && root.artShapeStyle != "icon" && root.pressed;
210+ radius: "medium";
211+ borderSource: "radius_pressed.sci"
212+ }
213+implicitHeight: row.y + row.height + units.gu(1);
214+}
tests/plugins/Dash/cardcreator/2.res.cardcreatornew file+140
@@ -0,0 +1,140 @@
1+AbstractButton {
2+ id: root;
3+ property var cardData;
4+ property string artShapeStyle: "inset";
5+ property string backgroundShapeStyle: "inset";
6+ property real fontScale: 1.0;
7+ property var scopeStyle: null;
8+ property int titleAlignment: Text.AlignLeft;
9+ property int fixedHeaderHeight: -1;
10+ property size fixedArtShapeSize: Qt.size(-1, -1);
11+ readonly property string title: cardData && cardData["title"] || "";
12+ property bool asynchronous: true;
13+ property bool showHeader: true;
14+ implicitWidth: childrenRect.width;
15+ enabled: true;
16+
17+Loader {
18+ id: backgroundLoader;
19+ objectName: "backgroundLoader";
20+ anchors.fill: parent;
21+ asynchronous: root.asynchronous;
22+ visible: status == Loader.Ready;
23+ sourceComponent: UbuntuShape {
24+ objectName: "background";
25+ radius: "medium";
26+ aspect: {
27+ switch (root.backgroundShapeStyle) {
28+ case "inset": return UbuntuShape.Inset;
29+ case "shadow": return UbuntuShape.DropShadow;
30+ default:
31+ case "flat": return UbuntuShape.Flat;
32+ }
33+ }
34+ backgroundColor: getColor(0) || "white";
35+ secondaryBackgroundColor: getColor(1) || backgroundColor;
36+ backgroundMode: UbuntuShape.VerticalGradient;
37+ anchors.fill: parent;
38+ source: backgroundImage.source ? backgroundImage : null;
39+ property real luminance: Style.luminance(backgroundColor);
40+ property Image backgroundImage: Image {
41+ objectName: "backgroundImage";
42+ source: {
43+ if (cardData && typeof cardData["background"] === "string") return cardData["background"];
44+ else return "";
45+ }
46+ }
47+ function getColor(index) {
48+ if (cardData && typeof cardData["background"] === "object"
49+ && (cardData["background"]["type"] === "color" || cardData["background"]["type"] === "gradient")) {
50+ return cardData["background"]["elements"][index];
51+ } else return index === 0 ? "#E9E9E9" : undefined;
52+ }
53+ }
54+ }
55+readonly property size artShapeSize: Qt.size(-1, -1);
56+readonly property int headerHeight: row.height;
57+Row {
58+ id: row;
59+ objectName: "outerRow";
60+ property real margins: units.gu(1);
61+ spacing: margins;
62+ height: root.fixedHeaderHeight != -1 ? root.fixedHeaderHeight : implicitHeight;
63+ anchors { top: parent.top;
64+ topMargin: units.gu(1);
65+ left: parent.left;
66+ }
67+ anchors.right: parent.right;
68+ anchors.margins: margins;
69+ anchors.rightMargin: 0;
70+ data: [
71+CroppedImageMinimumSourceSize {
72+ id: mascotImage;
73+ objectName: "mascotImage";
74+ anchors { verticalCenter: parent.verticalCenter; }
75+ source: cardData && cardData["mascot"] || "";
76+ width: units.gu(6);
77+ height: units.gu(5.625);
78+ horizontalAlignment: Image.AlignHCenter;
79+ verticalAlignment: Image.AlignVCenter;
80+ visible: showHeader;
81+ }
82+,Item {
83+ id: headerTitleContainer;
84+ anchors { verticalCenter: parent.verticalCenter; }
85+ width: parent.width - x;
86+ implicitHeight: titleLabel.height + subtitleLabel.height;
87+ data: [
88+ Label {
89+ id: titleLabel;
90+ objectName: "titleLabel";
91+ anchors { right: parent.right;
92+ rightMargin: units.gu(1);
93+ left: parent.left;
94+ top: parent.top; }
95+ elide: Text.ElideRight;
96+ fontSize: "small";
97+ wrapMode: Text.Wrap;
98+ maximumLineCount: 2;
99+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
100+ color: backgroundLoader.active && backgroundLoader.item && root.scopeStyle ? root.scopeStyle.getTextColor(backgroundLoader.item.luminance) : (backgroundLoader.item && backgroundLoader.item.luminance > 0.7 ? theme.palette.normal.baseText : "white");
101+ visible: showHeader ;
102+ width: undefined;
103+ text: root.title;
104+ font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal;
105+ horizontalAlignment: root.titleAlignment;
106+ }
107+ ,Label {
108+ id: subtitleLabel;
109+ objectName: "subtitleLabel";
110+ anchors { right: parent.right;
111+ left: parent.left;
112+ rightMargin: units.gu(1);
113+ top: titleLabel.bottom;
114+ }
115+ anchors.topMargin: units.dp(2);
116+ elide: Text.ElideRight;
117+ maximumLineCount: 1;
118+ fontSize: "x-small";
119+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
120+ color: backgroundLoader.active && backgroundLoader.item && root.scopeStyle ? root.scopeStyle.getTextColor(backgroundLoader.item.luminance) : (backgroundLoader.item && backgroundLoader.item.luminance > 0.7 ? theme.palette.normal.baseText : "white");
121+ visible: titleLabel.visible && titleLabel.text;
122+ text: cardData && cardData["subtitle"] || "";
123+ font.weight: Font.Light;
124+ }
125+
126+ ]
127+ }
128+
129+ ]
130+ }
131+UbuntuShape {
132+ id: touchdown;
133+ objectName: "touchdown";
134+ anchors { fill: backgroundLoader }
135+ visible: root.artShapeStyle != "shadow" && root.artShapeStyle != "icon" && root.pressed;
136+ radius: "medium";
137+ borderSource: "radius_pressed.sci"
138+}
139+implicitHeight: row.y + row.height + units.gu(1);
140+}
tests/plugins/Dash/cardcreator/3.res.cardcreatornew file+140
@@ -0,0 +1,140 @@
1+AbstractButton {
2+ id: root;
3+ property var cardData;
4+ property string artShapeStyle: "inset";
5+ property string backgroundShapeStyle: "inset";
6+ property real fontScale: 1.0;
7+ property var scopeStyle: null;
8+ property int titleAlignment: Text.AlignLeft;
9+ property int fixedHeaderHeight: -1;
10+ property size fixedArtShapeSize: Qt.size(-1, -1);
11+ readonly property string title: cardData && cardData["title"] || "";
12+ property bool asynchronous: true;
13+ property bool showHeader: true;
14+ implicitWidth: childrenRect.width;
15+ enabled: true;
16+
17+readonly property size artShapeSize: artShapeLoader.item ? Qt.size(artShapeLoader.item.width, artShapeLoader.item.height) : Qt.size(-1, -1);
18+Item {
19+ id: artShapeHolder;
20+ height: root.fixedArtShapeSize.height > 0 ? root.fixedArtShapeSize.height : artShapeLoader.height;
21+ width: root.fixedArtShapeSize.width > 0 ? root.fixedArtShapeSize.width : artShapeLoader.width;
22+ anchors { horizontalCenter: parent.horizontalCenter; }
23+ Loader {
24+ id: artShapeLoader;
25+ objectName: "artShapeLoader";
26+ readonly property string cardArt: cardData && cardData["art"] || "";
27+ active: cardArt != "";
28+ asynchronous: root.asynchronous;
29+ visible: status == Loader.Ready;
30+ sourceComponent: Item {
31+ id: artShape;
32+ objectName: "artShape";
33+ visible: image.status == Image.Ready;
34+ readonly property alias image: artImage;
35+ ShaderEffectSource {
36+ id: artShapeSource;
37+ sourceItem: artImage;
38+ anchors.centerIn: parent;
39+ width: 1;
40+ height: 1;
41+ hideSource: true;
42+ }
43+ Loader {
44+ anchors.fill: parent;
45+ visible: true;
46+ sourceComponent: root.artShapeStyle === "icon" ? artShapeIconComponent : artShapeShapeComponent;
47+ Component {
48+ id: artShapeShapeComponent;
49+ UbuntuShape {
50+ source: artShapeSource;
51+ sourceFillMode: UbuntuShape.PreserveAspectCrop;
52+ radius: "medium";
53+ aspect: {
54+ switch (root.artShapeStyle) {
55+ case "inset": return UbuntuShape.Inset;
56+ case "shadow": return UbuntuShape.DropShadow;
57+ default:
58+ case "flat": return UbuntuShape.Flat;
59+ }
60+ }
61+ }
62+ }
63+ Component {
64+ id: artShapeIconComponent;
65+ ProportionalShape { source: artShapeSource; aspect: UbuntuShape.DropShadow; }
66+ }
67+ }
68+ readonly property real fixedArtShapeSizeAspect: (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) ? root.fixedArtShapeSize.width / root.fixedArtShapeSize.height : -1;
69+ readonly property real aspect: fixedArtShapeSizeAspect > 0 ? fixedArtShapeSizeAspect : 0.75;
70+ Component.onCompleted: { updateWidthHeightBindings(); }
71+ Connections { target: root; onFixedArtShapeSizeChanged: updateWidthHeightBindings(); }
72+ function updateWidthHeightBindings() {
73+ if (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) {
74+ width = root.fixedArtShapeSize.width;
75+ height = root.fixedArtShapeSize.height;
76+ } else {
77+ width = Qt.binding(function() { return image.status !== Image.Ready ? 0 : image.width });
78+ height = Qt.binding(function() { return image.status !== Image.Ready ? 0 : image.height });
79+ }
80+ }
81+ CroppedImageMinimumSourceSize {
82+ id: artImage;
83+ objectName: "artImage";
84+ source: artShapeLoader.cardArt;
85+ asynchronous: root.asynchronous;
86+ width: root.width;
87+ height: width / artShape.aspect;
88+ }
89+ }
90+ }
91+ }
92+readonly property int headerHeight: titleLabel.height + subtitleLabel.height + subtitleLabel.anchors.topMargin;
93+Label {
94+ id: titleLabel;
95+ objectName: "titleLabel";
96+ anchors { right: parent.right;
97+ left: parent.left;
98+ top: artShapeHolder.bottom;
99+ topMargin: units.gu(1);
100+ }
101+ elide: Text.ElideRight;
102+ fontSize: "small";
103+ wrapMode: Text.Wrap;
104+ maximumLineCount: 2;
105+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
106+ color: root.scopeStyle ? root.scopeStyle.foreground : theme.palette.normal.baseText;
107+ visible: showHeader ;
108+ width: undefined;
109+ text: root.title;
110+ font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal;
111+ horizontalAlignment: root.titleAlignment;
112+ }
113+Label {
114+ id: subtitleLabel;
115+ objectName: "subtitleLabel";
116+ anchors { left: titleLabel.left;
117+ leftMargin: titleLabel.leftMargin;
118+ right: titleLabel.right;
119+ top: titleLabel.bottom;
120+ }
121+ anchors.topMargin: units.dp(2);
122+ elide: Text.ElideRight;
123+ maximumLineCount: 1;
124+ fontSize: "x-small";
125+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
126+ color: root.scopeStyle ? root.scopeStyle.foreground : theme.palette.normal.baseText;
127+ visible: titleLabel.visible && titleLabel.text;
128+ text: cardData && cardData["subtitle"] || "";
129+ font.weight: Font.Light;
130+ }
131+UbuntuShape {
132+ id: touchdown;
133+ objectName: "touchdown";
134+ anchors { fill: artShapeHolder }
135+ visible: root.artShapeStyle != "shadow" && root.artShapeStyle != "icon" && root.pressed;
136+ radius: "medium";
137+ borderSource: "radius_pressed.sci"
138+}
139+implicitHeight: subtitleLabel.y + subtitleLabel.height + units.gu(1);
140+}
tests/plugins/Dash/cardcreator/4.res.cardcreatornew file+113
@@ -0,0 +1,113 @@
1+AbstractButton {
2+ id: root;
3+ property var cardData;
4+ property string artShapeStyle: "inset";
5+ property string backgroundShapeStyle: "inset";
6+ property real fontScale: 1.0;
7+ property var scopeStyle: null;
8+ property int titleAlignment: Text.AlignLeft;
9+ property int fixedHeaderHeight: -1;
10+ property size fixedArtShapeSize: Qt.size(-1, -1);
11+ readonly property string title: cardData && cardData["title"] || "";
12+ property bool asynchronous: true;
13+ property bool showHeader: true;
14+ implicitWidth: childrenRect.width;
15+ enabled: true;
16+
17+readonly property size artShapeSize: Qt.size(-1, -1);
18+readonly property int headerHeight: row.height;
19+Row {
20+ id: row;
21+ objectName: "outerRow";
22+ property real margins: units.gu(1);
23+ spacing: margins;
24+ height: root.fixedHeaderHeight != -1 ? root.fixedHeaderHeight : implicitHeight;
25+ anchors { top: parent.top;
26+ topMargin: units.gu(1);
27+ left: parent.left;
28+}
29+ anchors.right: parent.right;
30+ anchors.margins: margins;
31+ anchors.rightMargin: 0;
32+data: [
33+Loader {
34+ id: mascotShapeLoader;
35+ objectName: "mascotShapeLoader";
36+ asynchronous: root.asynchronous;
37+ active: mascotImage.status === Image.Ready;
38+ visible: showHeader && active && status == Loader.Ready;
39+ width: units.gu(6);
40+ height: units.gu(5.625);
41+ sourceComponent: UbuntuShape { image: mascotImage }
42+ anchors { verticalCenter: parent.verticalCenter; }
43+ }
44+
45+,CroppedImageMinimumSourceSize {
46+ id: mascotImage;
47+ objectName: "mascotImage";
48+ anchors { verticalCenter: parent.verticalCenter; }
49+ source: cardData && cardData["mascot"] || "";
50+ width: units.gu(6);
51+ height: units.gu(5.625);
52+ horizontalAlignment: Image.AlignHCenter;
53+ verticalAlignment: Image.AlignVCenter;
54+ visible: false;
55+ }
56+
57+,Item {
58+ id: headerTitleContainer;
59+ anchors { verticalCenter: parent.verticalCenter; }
60+ width: parent.width - x;
61+ implicitHeight: titleLabel.height + subtitleLabel.height;
62+ data: [
63+Label {
64+ id: titleLabel;
65+ objectName: "titleLabel";
66+ anchors { right: parent.right;
67+ rightMargin: units.gu(1);
68+ left: parent.left;
69+ top: parent.top; }
70+ elide: Text.ElideRight;
71+ fontSize: "small";
72+ wrapMode: Text.Wrap;
73+ maximumLineCount: 2;
74+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
75+ color: root.scopeStyle ? root.scopeStyle.foreground : theme.palette.normal.baseText;
76+ visible: showHeader ;
77+ width: undefined;
78+ text: root.title;
79+ font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal;
80+ horizontalAlignment: root.titleAlignment;
81+ }
82+,Label {
83+ id: subtitleLabel;
84+ objectName: "subtitleLabel";
85+ anchors { right: parent.right;
86+ left: parent.left;
87+ rightMargin: units.gu(1);
88+ top: titleLabel.bottom;
89+ }
90+ anchors.topMargin: units.dp(2);
91+ elide: Text.ElideRight;
92+ maximumLineCount: 1;
93+ fontSize: "x-small";
94+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
95+ color: root.scopeStyle ? root.scopeStyle.foreground : theme.palette.normal.baseText;
96+ visible: titleLabel.visible && titleLabel.text;
97+ text: cardData && cardData["subtitle"] || "";
98+ font.weight: Font.Light;
99+ }
100+]
101+}
102+]
103+}
104+UbuntuShape {
105+ id: touchdown;
106+ objectName: "touchdown";
107+ anchors { fill: root }
108+ visible: root.artShapeStyle != "shadow" && root.artShapeStyle != "icon" && root.pressed;
109+ radius: "medium";
110+ borderSource: "radius_pressed.sci"
111+}
112+implicitHeight: row.y + row.height + units.gu(1);
113+}
tests/plugins/Dash/cardcreator/5.res.cardcreatornew file+159
@@ -0,0 +1,159 @@
1+AbstractButton {
2+ id: root;
3+ property var cardData;
4+ property string artShapeStyle: "inset";
5+ property string backgroundShapeStyle: "inset";
6+ property real fontScale: 1.0;
7+ property var scopeStyle: null;
8+ property int titleAlignment: Text.AlignLeft;
9+ property int fixedHeaderHeight: -1;
10+ property size fixedArtShapeSize: Qt.size(-1, -1);
11+ readonly property string title: cardData && cardData["title"] || "";
12+ property bool asynchronous: true;
13+ property bool showHeader: true;
14+ implicitWidth: childrenRect.width;
15+ enabled: false;
16+
17+readonly property size artShapeSize: artShapeLoader.item ? Qt.size(artShapeLoader.item.width, artShapeLoader.item.height) : Qt.size(-1, -1);
18+Item {
19+ id: artShapeHolder;
20+ height: root.fixedArtShapeSize.height > 0 ? root.fixedArtShapeSize.height : artShapeLoader.height;
21+ width: root.fixedArtShapeSize.width > 0 ? root.fixedArtShapeSize.width : artShapeLoader.width;
22+ anchors { horizontalCenter: parent.horizontalCenter; }
23+ Loader {
24+ id: artShapeLoader;
25+ objectName: "artShapeLoader";
26+ readonly property string cardArt: cardData && cardData["art"] || "";
27+ active: cardArt != "";
28+ asynchronous: root.asynchronous;
29+ visible: status == Loader.Ready;
30+ sourceComponent: Item {
31+ id: artShape;
32+ objectName: "artShape";
33+ visible: image.status == Image.Ready;
34+ readonly property alias image: artImage;
35+ ShaderEffectSource {
36+ id: artShapeSource;
37+ sourceItem: artImage;
38+ anchors.centerIn: parent;
39+ width: 1;
40+ height: 1;
41+ hideSource: false;
42+ }
43+ Loader {
44+ anchors.fill: parent;
45+ visible: false;
46+ sourceComponent: root.artShapeStyle === "icon" ? artShapeIconComponent : artShapeShapeComponent;
47+ Component {
48+ id: artShapeShapeComponent;
49+ UbuntuShape {
50+ source: artShapeSource;
51+ sourceFillMode: UbuntuShape.PreserveAspectCrop;
52+ radius: "medium";
53+ aspect: {
54+ switch (root.artShapeStyle) {
55+ case "inset": return UbuntuShape.Inset;
56+ case "shadow": return UbuntuShape.DropShadow;
57+ default:
58+ case "flat": return UbuntuShape.Flat;
59+ }
60+ }
61+ }
62+ }
63+ Component {
64+ id: artShapeIconComponent;
65+ ProportionalShape { source: artShapeSource; aspect: UbuntuShape.DropShadow; }
66+ }
67+ }
68+ readonly property real fixedArtShapeSizeAspect: (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) ? root.fixedArtShapeSize.width / root.fixedArtShapeSize.height : -1;
69+ readonly property real aspect: fixedArtShapeSizeAspect > 0 ? fixedArtShapeSizeAspect : 1;
70+ Component.onCompleted: { updateWidthHeightBindings(); }
71+ Connections { target: root; onFixedArtShapeSizeChanged: updateWidthHeightBindings(); }
72+ function updateWidthHeightBindings() {
73+ if (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) {
74+ width = root.fixedArtShapeSize.width;
75+ height = root.fixedArtShapeSize.height;
76+ } else {
77+ width = Qt.binding(function() { return image.status !== Image.Ready ? 0 : image.width });
78+ height = Qt.binding(function() { return image.status !== Image.Ready ? 0 : image.height });
79+ }
80+ }
81+ CroppedImageMinimumSourceSize {
82+ id: artImage;
83+ objectName: "artImage";
84+ source: artShapeLoader.cardArt;
85+ asynchronous: root.asynchronous;
86+ width: root.width;
87+ height: width / artShape.aspect;
88+ }
89+ }
90+ }
91+ }
92+Loader {
93+ id: overlayLoader;
94+ readonly property real overlayHeight: (fixedHeaderHeight > 0 ? fixedHeaderHeight : headerHeight) + units.gu(2);
95+ anchors.fill: artShapeHolder;
96+ active: artShapeLoader.active && artShapeLoader.item && artShapeLoader.item.image.status === Image.Ready || false;
97+ asynchronous: root.asynchronous;
98+ visible: showHeader && status == Loader.Ready;
99+ sourceComponent: UbuntuShapeOverlay {
100+ id: overlay;
101+ property real luminance: Style.luminance(overlayColor);
102+ aspect: UbuntuShape.Flat;
103+ radius: "medium";
104+ overlayColor: cardData && cardData["overlayColor"] || "#99000000";
105+ overlayRect: Qt.rect(0, 1 - overlayLoader.overlayHeight / height, 1, 1);
106+ }
107+ }
108+readonly property int headerHeight: titleLabel.height + subtitleLabel.height + subtitleLabel.anchors.topMargin;
109+Label {
110+ id: titleLabel;
111+ objectName: "titleLabel";
112+ anchors { right: parent.right;
113+ rightMargin: units.gu(1);
114+ left: parent.left;
115+ leftMargin: units.gu(1);
116+ top: overlayLoader.top;
117+ topMargin: units.gu(1) + overlayLoader.height - overlayLoader.overlayHeight;
118+ }
119+ elide: Text.ElideRight;
120+ fontSize: "small";
121+ wrapMode: Text.Wrap;
122+ maximumLineCount: 2;
123+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
124+ color: root.scopeStyle && overlayLoader.item ? root.scopeStyle.getTextColor(overlayLoader.item.luminance) : (overlayLoader.item && overlayLoader.item.luminance > 0.7 ? theme.palette.normal.baseText : "white");
125+ visible: showHeader && overlayLoader.active;
126+ width: undefined;
127+ text: root.title;
128+ font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal;
129+ horizontalAlignment: root.titleAlignment;
130+ }
131+Label {
132+ id: subtitleLabel;
133+ objectName: "subtitleLabel";
134+ anchors { left: titleLabel.left;
135+ leftMargin: titleLabel.leftMargin;
136+ rightMargin: units.gu(1);
137+ right: titleLabel.right;
138+ top: titleLabel.bottom;
139+ }
140+ anchors.topMargin: units.dp(2);
141+ elide: Text.ElideRight;
142+ maximumLineCount: 1;
143+ fontSize: "x-small";
144+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
145+ color: root.scopeStyle && overlayLoader.item ? root.scopeStyle.getTextColor(overlayLoader.item.luminance) : (overlayLoader.item && overlayLoader.item.luminance > 0.7 ? theme.palette.normal.baseText : "white");
146+ visible: titleLabel.visible && titleLabel.text;
147+ text: cardData && cardData["subtitle"] || "";
148+ font.weight: Font.Light;
149+ }
150+UbuntuShape {
151+ id: touchdown;
152+ objectName: "touchdown";
153+ anchors { fill: artShapeHolder }
154+ visible: root.artShapeStyle != "shadow" && root.artShapeStyle != "icon" && root.pressed;
155+ radius: "medium";
156+ borderSource: "radius_pressed.sci"
157+}
158+implicitHeight: artShapeHolder.height;
159+}
tests/plugins/Dash/cardcreator/6.res.cardcreatornew file+129
@@ -0,0 +1,129 @@
1+AbstractButton {
2+ id: root;
3+ property var cardData;
4+ property string artShapeStyle: "inset";
5+ property string backgroundShapeStyle: "inset";
6+ property real fontScale: 1.0;
7+ property var scopeStyle: null;
8+ property int titleAlignment: Text.AlignLeft;
9+ property int fixedHeaderHeight: -1;
10+ property size fixedArtShapeSize: Qt.size(-1, -1);
11+ readonly property string title: cardData && cardData["title"] || "";
12+ property bool asynchronous: true;
13+ property bool showHeader: true;
14+ implicitWidth: childrenRect.width;
15+ enabled: true;
16+
17+Loader {
18+ id: backgroundLoader;
19+ objectName: "backgroundLoader";
20+ anchors.fill: parent;
21+ asynchronous: root.asynchronous;
22+ visible: status == Loader.Ready;
23+ sourceComponent: UbuntuShape {
24+ objectName: "background";
25+ radius: "medium";
26+ aspect: {
27+ switch (root.backgroundShapeStyle) {
28+ case "inset": return UbuntuShape.Inset;
29+ case "shadow": return UbuntuShape.DropShadow;
30+ default:
31+ case "flat": return UbuntuShape.Flat;
32+ }
33+ }
34+ backgroundColor: getColor(0) || "white";
35+ secondaryBackgroundColor: getColor(1) || backgroundColor;
36+ backgroundMode: UbuntuShape.VerticalGradient;
37+ anchors.fill: parent;
38+ source: backgroundImage.source ? backgroundImage : null;
39+ property real luminance: Style.luminance(backgroundColor);
40+ property Image backgroundImage: Image {
41+ objectName: "backgroundImage";
42+ source: {
43+ if (cardData && typeof cardData["background"] === "string") return cardData["background"];
44+ else return decodeURI("http://assets.ubuntu.com/sites/ubuntu/latest/u/img/logos/logo-ubuntu-grey.png");
45+ }
46+ }
47+ function getColor(index) {
48+ if (cardData && typeof cardData["background"] === "object"
49+ && (cardData["background"]["type"] === "color" || cardData["background"]["type"] === "gradient")) {
50+ return cardData["background"]["elements"][index];
51+ } else return index === 0 ? undefined : undefined;
52+ }
53+ }
54+ }
55+readonly property size artShapeSize: Qt.size(-1, -1);
56+readonly property int headerHeight: titleLabel.height + subtitleLabel.height + subtitleLabel.anchors.topMargin;
57+Item {
58+ id: headerTitleContainer;
59+ anchors { right: parent.right; left: parent.left;
60+ top: parent.top;
61+ topMargin: units.gu(1);
62+ leftMargin: units.gu(1);
63+ }
64+ width: parent.width - x;
65+ implicitHeight: titleLabel.height + subtitleLabel.height;
66+ data: [
67+ Label {
68+ id: titleLabel;
69+ objectName: "titleLabel";
70+ anchors { right: emblemIcon.left;
71+ rightMargin: emblemIcon.width > 0 ? units.gu(0.5) : 0;
72+ left: parent.left;
73+ top: parent.top; }
74+ elide: Text.ElideRight;
75+ fontSize: "small";
76+ wrapMode: Text.Wrap;
77+ maximumLineCount: 2;
78+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
79+ color: backgroundLoader.active && backgroundLoader.item && root.scopeStyle ? root.scopeStyle.getTextColor(backgroundLoader.item.luminance) : (backgroundLoader.item && backgroundLoader.item.luminance > 0.7 ? theme.palette.normal.baseText : "white");
80+ visible: showHeader ;
81+ width: undefined;
82+ text: root.title;
83+ font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal;
84+ horizontalAlignment: root.titleAlignment;
85+ }
86+,Label {
87+ id: subtitleLabel;
88+ objectName: "subtitleLabel";
89+ anchors { right: parent.right;
90+ left: parent.left;
91+ rightMargin: units.gu(1);
92+ top: titleLabel.bottom;
93+ }
94+ anchors.topMargin: units.dp(2);
95+ elide: Text.ElideRight;
96+ maximumLineCount: 1;
97+ fontSize: "x-small";
98+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
99+ color: backgroundLoader.active && backgroundLoader.item && root.scopeStyle ? root.scopeStyle.getTextColor(backgroundLoader.item.luminance) : (backgroundLoader.item && backgroundLoader.item.luminance > 0.7 ? theme.palette.normal.baseText : "white");
100+ visible: titleLabel.visible && titleLabel.text;
101+ text: cardData && cardData["subtitle"] || "";
102+ font.weight: Font.Light;
103+ }
104+,Icon {
105+ id: emblemIcon;
106+ objectName: "emblemIcon";
107+ anchors {
108+ bottom: titleLabel.baseline;
109+ right: parent.right;
110+ rightMargin: units.gu(1);
111+ }
112+ source: cardData && cardData["emblem"] || "";
113+ color: backgroundLoader.active && backgroundLoader.item && root.scopeStyle ? root.scopeStyle.getTextColor(backgroundLoader.item.luminance) : (backgroundLoader.item && backgroundLoader.item.luminance > 0.7 ? theme.palette.normal.baseText : "white");
114+ height: source != "" ? titleLabel.font.pixelSize : 0;
115+ width: implicitWidth > 0 && implicitHeight > 0 ? (implicitWidth / implicitHeight * height) : implicitWidth;
116+ }
117+
118+ ]
119+ }
120+UbuntuShape {
121+ id: touchdown;
122+ objectName: "touchdown";
123+ anchors { fill: backgroundLoader }
124+ visible: root.artShapeStyle != "shadow" && root.artShapeStyle != "icon" && root.pressed;
125+ radius: "medium";
126+ borderSource: "radius_pressed.sci"
127+}
128+implicitHeight: headerTitleContainer.y + headerTitleContainer.height + units.gu(1);
129+}
tests/plugins/Dash/cardcreator/7.res.cardcreatornew file+153
@@ -0,0 +1,153 @@
1+AbstractButton {
2+ id: root;
3+ property var cardData;
4+ property string artShapeStyle: "inset";
5+ property string backgroundShapeStyle: "inset";
6+ property real fontScale: 1.0;
7+ property var scopeStyle: null;
8+ property int titleAlignment: Text.AlignLeft;
9+ property int fixedHeaderHeight: -1;
10+ property size fixedArtShapeSize: Qt.size(-1, -1);
11+ readonly property string title: cardData && cardData["title"] || "";
12+ property bool asynchronous: true;
13+ property bool showHeader: true;
14+ implicitWidth: childrenRect.width;
15+ enabled: true;
16+
17+Loader {
18+ id: backgroundLoader;
19+ objectName: "backgroundLoader";
20+ anchors.fill: parent;
21+ asynchronous: root.asynchronous;
22+ visible: status == Loader.Ready;
23+ sourceComponent: UbuntuShape {
24+ objectName: "background";
25+ radius: "medium";
26+ aspect: {
27+ switch (root.backgroundShapeStyle) {
28+ case "inset": return UbuntuShape.Inset;
29+ case "shadow": return UbuntuShape.DropShadow;
30+ default:
31+ case "flat": return UbuntuShape.Flat;
32+ }
33+ }
34+ backgroundColor: getColor(0) || "white";
35+ secondaryBackgroundColor: getColor(1) || backgroundColor;
36+ backgroundMode: UbuntuShape.VerticalGradient;
37+ anchors.fill: parent;
38+ source: backgroundImage.source ? backgroundImage : null;
39+ property real luminance: Style.luminance(backgroundColor);
40+ property Image backgroundImage: Image {
41+ objectName: "backgroundImage";
42+ source: {
43+ if (cardData && typeof cardData["background"] === "string") return cardData["background"];
44+ else return "";
45+ }
46+ }
47+ function getColor(index) {
48+ if (cardData && typeof cardData["background"] === "object"
49+ && (cardData["background"]["type"] === "color" || cardData["background"]["type"] === "gradient")) {
50+ return cardData["background"]["elements"][index];
51+ } else return index === 0 ? "#E9E9E9" : "#E9AAE9";
52+ }
53+ }
54+ }
55+readonly property size artShapeSize: Qt.size(-1, -1);
56+readonly property int headerHeight: row.height;
57+Row {
58+ id: row;
59+ objectName: "outerRow";
60+ property real margins: units.gu(1);
61+ spacing: margins;
62+ height: root.fixedHeaderHeight != -1 ? root.fixedHeaderHeight : implicitHeight;
63+ anchors { top: parent.top;
64+ topMargin: units.gu(1);
65+ left: parent.left;
66+ }
67+ anchors.right: parent.right;
68+ anchors.margins: margins;
69+ anchors.rightMargin: 0;
70+ data: [
71+CroppedImageMinimumSourceSize {
72+ id: mascotImage;
73+ objectName: "mascotImage";
74+ anchors { verticalCenter: parent.verticalCenter; }
75+ source: cardData && cardData["mascot"] || "";
76+ width: units.gu(6);
77+ height: units.gu(5.625);
78+ horizontalAlignment: Image.AlignHCenter;
79+ verticalAlignment: Image.AlignVCenter;
80+ visible: showHeader;
81+ }
82+
83+,Item {
84+ id: headerTitleContainer;
85+ anchors { verticalCenter: parent.verticalCenter; }
86+ width: parent.width - x;
87+ implicitHeight: titleLabel.height + subtitleLabel.height + attributesRow.height;
88+ data: [
89+ Label {
90+ id: titleLabel;
91+ objectName: "titleLabel";
92+ anchors { right: parent.right;
93+ rightMargin: units.gu(1);
94+ left: parent.left;
95+ top: parent.top; }
96+ elide: Text.ElideRight;
97+ fontSize: "small";
98+ wrapMode: Text.Wrap;
99+ maximumLineCount: 2;
100+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
101+ color: backgroundLoader.active && backgroundLoader.item && root.scopeStyle ? root.scopeStyle.getTextColor(backgroundLoader.item.luminance) : (backgroundLoader.item && backgroundLoader.item.luminance > 0.7 ? theme.palette.normal.baseText : "white");
102+ visible: showHeader ;
103+ width: undefined;
104+ text: root.title;
105+ font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal;
106+ horizontalAlignment: root.titleAlignment;
107+ }
108+,Label {
109+ id: subtitleLabel;
110+ objectName: "subtitleLabel";
111+ anchors { right: parent.right;
112+ left: parent.left;
113+ rightMargin: units.gu(1);
114+ top: titleLabel.bottom;
115+ }
116+ anchors.topMargin: units.dp(2);
117+ elide: Text.ElideRight;
118+ maximumLineCount: 1;
119+ fontSize: "x-small";
120+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
121+ color: backgroundLoader.active && backgroundLoader.item && root.scopeStyle ? root.scopeStyle.getTextColor(backgroundLoader.item.luminance) : (backgroundLoader.item && backgroundLoader.item.luminance > 0.7 ? theme.palette.normal.baseText : "white");
122+ visible: titleLabel.visible && titleLabel.text;
123+ text: cardData && cardData["subtitle"] || "";
124+ font.weight: Font.Light;
125+ }
126+,CardAttributes {
127+ id: attributesRow;
128+ objectName: "attributesRow";
129+ anchors { right: parent.right;
130+ left: parent.left;
131+ rightMargin: units.gu(1);
132+ top: subtitleLabel.bottom;
133+ }
134+ color: backgroundLoader.active && backgroundLoader.item && root.scopeStyle ? root.scopeStyle.getTextColor(backgroundLoader.item.luminance) : (backgroundLoader.item && backgroundLoader.item.luminance > 0.7 ? theme.palette.normal.baseText : "white");
135+ fontScale: root.fontScale;
136+ model: cardData && cardData["attributes"];
137+ }
138+
139+ ]
140+ }
141+
142+ ]
143+ }
144+UbuntuShape {
145+ id: touchdown;
146+ objectName: "touchdown";
147+ anchors { fill: backgroundLoader }
148+ visible: root.artShapeStyle != "shadow" && root.artShapeStyle != "icon" && root.pressed;
149+ radius: "medium";
150+ borderSource: "radius_pressed.sci"
151+}
152+implicitHeight: row.y + row.height + units.gu(1);
153+}
tests/plugins/Dash/cardcreator/8.res.cardcreatornew file+111
@@ -0,0 +1,111 @@
1+AbstractButton {
2+ id: root;
3+ property var cardData;
4+ property string artShapeStyle: "inset";
5+ property string backgroundShapeStyle: "inset";
6+ property real fontScale: 1.0;
7+ property var scopeStyle: null;
8+ property int titleAlignment: Text.AlignLeft;
9+ property int fixedHeaderHeight: -1;
10+ property size fixedArtShapeSize: Qt.size(-1, -1);
11+ readonly property string title: cardData && cardData["title"] || "";
12+ property bool asynchronous: true;
13+ property bool showHeader: true;
14+ implicitWidth: childrenRect.width;
15+ enabled: true;
16+
17+Loader {
18+ id: backgroundLoader;
19+ objectName: "backgroundLoader";
20+ anchors.fill: parent;
21+ asynchronous: root.asynchronous;
22+ visible: status == Loader.Ready;
23+ sourceComponent: UbuntuShape {
24+ objectName: "background";
25+ radius: "medium";
26+ aspect: {
27+ switch (root.backgroundShapeStyle) {
28+ case "inset": return UbuntuShape.Inset;
29+ case "shadow": return UbuntuShape.DropShadow;
30+ default:
31+ case "flat": return UbuntuShape.Flat;
32+ }
33+ }
34+ backgroundColor: getColor(0) || "white";
35+ secondaryBackgroundColor: getColor(1) || backgroundColor;
36+ backgroundMode: UbuntuShape.VerticalGradient;
37+ anchors.fill: parent;
38+ source: backgroundImage.source ? backgroundImage : null;
39+ property real luminance: Style.luminance(backgroundColor);
40+ property Image backgroundImage: Image {
41+ objectName: "backgroundImage";
42+ source: {
43+ if (cardData && typeof cardData["background"] === "string") return cardData["background"];
44+ else return "";
45+ }
46+ }
47+ function getColor(index) {
48+ if (cardData && typeof cardData["background"] === "object"
49+ && (cardData["background"]["type"] === "color" || cardData["background"]["type"] === "gradient")) {
50+ return cardData["background"]["elements"][index];
51+ } else return index === 0 ? "#E9E9E9" : "#E9AAE9";
52+ }
53+ }
54+ }
55+readonly property size artShapeSize: Qt.size(-1, -1);
56+readonly property int headerHeight: row.height;
57+Row {
58+ id: row;
59+ objectName: "outerRow";
60+ property real margins: units.gu(1);
61+ spacing: margins;
62+ height: root.fixedHeaderHeight != -1 ? root.fixedHeaderHeight : implicitHeight;
63+ anchors { top: parent.top;
64+ topMargin: units.gu(1);
65+left: parent.left;
66+ }
67+ anchors.right: parent.right;
68+ anchors.margins: margins;
69+ anchors.rightMargin: 0;
70+ data: [
71+ CroppedImageMinimumSourceSize {
72+ id: mascotImage;
73+ objectName: "mascotImage";
74+ anchors { verticalCenter: parent.verticalCenter; }
75+ source: cardData && cardData["mascot"] || "";
76+ width: units.gu(6);
77+ height: units.gu(5.625);
78+ horizontalAlignment: Image.AlignHCenter;
79+ verticalAlignment: Image.AlignVCenter;
80+ visible: showHeader;
81+ }
82+,Label {
83+ id: titleLabel;
84+ objectName: "titleLabel";
85+ anchors { verticalCenter: parent.verticalCenter;
86+ }
87+ elide: Text.ElideRight;
88+ fontSize: "small";
89+ wrapMode: Text.Wrap;
90+ maximumLineCount: 2;
91+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
92+ color: backgroundLoader.active && backgroundLoader.item && root.scopeStyle ? root.scopeStyle.getTextColor(backgroundLoader.item.luminance) : (backgroundLoader.item && backgroundLoader.item.luminance > 0.7 ? theme.palette.normal.baseText : "white");
93+ visible: showHeader ;
94+ width: parent.width - x;
95+ text: root.title;
96+ font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal;
97+ horizontalAlignment: root.titleAlignment;
98+ }
99+
100+ ]
101+ }
102+UbuntuShape {
103+ id: touchdown;
104+ objectName: "touchdown";
105+ anchors { fill: backgroundLoader }
106+ visible: root.artShapeStyle != "shadow" && root.artShapeStyle != "icon" && root.pressed;
107+ radius: "medium";
108+ borderSource: "radius_pressed.sci"
109+}
110+implicitHeight: row.y + row.height + units.gu(1);
111+}
tests/plugins/Dash/cardcreator/9.res.cardcreatornew file+121
@@ -0,0 +1,121 @@
1+AbstractButton {
2+ id: root;
3+ property var cardData;
4+ property string artShapeStyle: "inset";
5+ property string backgroundShapeStyle: "inset";
6+ property real fontScale: 1.0;
7+ property var scopeStyle: null;
8+ property int titleAlignment: Text.AlignLeft;
9+ property int fixedHeaderHeight: -1;
10+ property size fixedArtShapeSize: Qt.size(-1, -1);
11+ readonly property string title: cardData && cardData["title"] || "";
12+ property bool asynchronous: true;
13+ property bool showHeader: true;
14+ implicitWidth: childrenRect.width;
15+ enabled: true;
16+
17+readonly property size artShapeSize: Qt.size(-1, -1);
18+readonly property int headerHeight: titleLabel.height + subtitleLabel.height + subtitleLabel.anchors.topMargin + audioProgressBar.height + audioProgressBar.anchors.topMargin;
19+Label {
20+ id: titleLabel;
21+ objectName: "titleLabel";
22+ anchors { right: parent.right;
23+rightMargin: units.gu(1);
24+left: audioButton.right;
25+ leftMargin: units.gu(1);
26+top: parent.top;
27+ topMargin: units.gu(1);
28+ }
29+ elide: Text.ElideRight;
30+ fontSize: "small";
31+ wrapMode: Text.Wrap;
32+ maximumLineCount: 2;
33+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
34+ color: root.scopeStyle ? root.scopeStyle.foreground : theme.palette.normal.baseText;
35+ visible: showHeader ;
36+ width: undefined;
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+ }
82+ Rectangle {
83+ color: Qt.rgba(0, 0, 0, 0.5);
84+ anchors.centerIn: parent;
85+ width: parent.width * 0.5;
86+ height: width;
87+ radius: width / 2;
88+ }
89+ Icon {
90+ anchors.centerIn: parent;
91+ width: parent.width * 0.3;
92+ height: width;
93+ opacity: 0.9;
94+ name: DashAudioPlayer.playing && AudioUrlComparer.compare(parent.source, DashAudioPlayer.currentSource) ? "media-playback-pause" : "media-playback-start";
95+ color: "white";
96+ }
97+ onClicked: {
98+ if (AudioUrlComparer.compare(source, DashAudioPlayer.currentSource)) {
99+ if (DashAudioPlayer.playing) {
100+ DashAudioPlayer.pause();
101+ } else {
102+ DashAudioPlayer.play();
103+ }
104+ } else {
105+ var playlist = (cardData["quickPreviewData"] && cardData["quickPreviewData"]["playlist"]) || null;
106+ DashAudioPlayer.playSource(source, playlist);
107+ }
108+ }
109+ onPressAndHold: {
110+ root.pressAndHold();
111+ }
112+ }UbuntuShape {
113+ id: touchdown;
114+ objectName: "touchdown";
115+ anchors { fill: root }
116+ visible: root.artShapeStyle != "shadow" && root.artShapeStyle != "icon" && root.pressed;
117+ radius: "medium";
118+ borderSource: "radius_pressed.sci"
119+ }
120+implicitHeight: audioButton.height;
121+}
tests/plugins/Dash/cardcreatortest.cpp+32−22
@@ -45,6 +45,30 @@ private Q_SLOTS:
4545 delete view;
4646 }
4747
48+ void compareFileContents(const QString &filePath, const QString cardStringResult)
49+ {
50+ QFile testResultFile(filePath);
51+ QVERIFY(testResultFile.open(QIODevice::ReadOnly));
52+ QTextStream ts2(&testResultFile);
53+
54+ // Record failed results to /tmp
55+ const QString executedResult = cardStringResult;
56+ QTemporaryFile tmpFile(QDir::tempPath() + QDir::separator() + "testCardCreatorFailedResultXXXXXX");
57+ tmpFile.open();
58+ tmpFile.setAutoRemove(false);
59+ tmpFile.write(executedResult.toUtf8().constData());
60+
61+ // Line by line comparison
62+ const QStringList expectedLines = ts2.readAll().trimmed().replace(QRegExp("\n\\s*\n"),"\n").split("\n");
63+ const QStringList cardStringResultLines = cardStringResult.trimmed().replace(QRegExp("\n\\s*\n"),"\n").split("\n");
64+ for (int i = 0; i < expectedLines.size(); ++i) {
65+ QCOMPARE(cardStringResultLines[i].simplified(), expectedLines[i].simplified());
66+ }
67+
68+ // Remove the result if it passed
69+ tmpFile.setAutoRemove(true);
70+ }
71+
4872 void testKnownCases()
4973 {
5074 const QString templateString("template: ");
@@ -68,33 +92,19 @@ private Q_SLOTS:
6892 const QString templateJSON = lines[0].mid(templateString.length());
6993 const QString componentsJSON = lines[1].mid(componentsString.length());
7094 const QString resultFileName = lines[2].mid(resultString.length());
71−
7295 QVariant cardStringResult;
73− QMetaObject::invokeMethod(view->rootObject(), "cardString", Q_RETURN_ARG(QVariant, cardStringResult), Q_ARG(QVariant, templateJSON), Q_ARG(QVariant, componentsJSON));
74−
75− QFile testResultFile(testDirPath + resultFileName);
76− QVERIFY(testResultFile.open(QIODevice::ReadOnly));
77− QTextStream ts2(&testResultFile);
96+ QVariant createCardComponentResult;
7897
79− // Record failed results to /tmp
80− const QString executedResult = cardStringResult.toString();
81− QTemporaryFile tmpFile(QDir::tempPath() + QDir::separator() + "testCardCreatorFailedResultXXXXXX");
82− tmpFile.open();
83− tmpFile.setAutoRemove(false);
84− tmpFile.write(executedResult.toUtf8().constData());
98+ QMetaObject::invokeMethod(view->rootObject(), "cardString", Q_RETURN_ARG(QVariant, cardStringResult), Q_ARG(QVariant, templateJSON), Q_ARG(QVariant, componentsJSON), Q_ARG(QVariant, false));
99+ compareFileContents(testDirPath + resultFileName, cardStringResult.toString());
85100
86− // Line by line comparison
87− const QStringList expectedLines = ts2.readAll().trimmed().replace(QRegExp("\n\\s*\n"),"\n").split("\n");
88− const QStringList cardStringResultLines = cardStringResult.toString().trimmed().replace(QRegExp("\n\\s*\n"),"\n").split("\n");
89− for (int i = 0; i < expectedLines.size(); ++i) {
90− QCOMPARE(cardStringResultLines[i].simplified(), expectedLines[i].simplified());
91− }
101+ QMetaObject::invokeMethod(view->rootObject(), "cardString", Q_RETURN_ARG(QVariant, cardStringResult), Q_ARG(QVariant, templateJSON), Q_ARG(QVariant, componentsJSON), Q_ARG(QVariant, true));
102+ compareFileContents(testDirPath + resultFileName + ".cardcreator", cardStringResult.toString());
92103
93− // Remove the result if it passed
94− tmpFile.setAutoRemove(true);
104+ QMetaObject::invokeMethod(view->rootObject(), "createCardComponent", Q_RETURN_ARG(QVariant, createCardComponentResult), Q_ARG(QVariant, templateJSON), Q_ARG(QVariant, componentsJSON), Q_ARG(QVariant, false));
105+ QVERIFY(createCardComponentResult.toBool());
95106
96− QVariant createCardComponentResult;
97− QMetaObject::invokeMethod(view->rootObject(), "createCardComponent", Q_RETURN_ARG(QVariant, createCardComponentResult), Q_ARG(QVariant, templateJSON), Q_ARG(QVariant, componentsJSON));
107+ QMetaObject::invokeMethod(view->rootObject(), "createCardComponent", Q_RETURN_ARG(QVariant, createCardComponentResult), Q_ARG(QVariant, templateJSON), Q_ARG(QVariant, componentsJSON), Q_ARG(QVariant, true));
98108 QVERIFY(createCardComponentResult.toBool());
99109 }
100110 }
tests/plugins/Dash/cardcreatortest.qml+4−4
@@ -19,11 +19,11 @@ import "../../../plugins/Dash/CardCreator.js" as CardCreator
1919
2020Item {
2121 id: root
22− function cardString(template, components) {
23− return CardCreator.cardString(JSON.parse(template), JSON.parse(components));
22+ function cardString(template, components, isCardCreator) {
23+ return CardCreator.cardString(JSON.parse(template), JSON.parse(components), isCardCreator);
2424 }
2525
26− function createCardComponent(template, components) {
27− return CardCreator.createCardComponent(root, JSON.parse(template), JSON.parse(components)) !== null;
26+ function createCardComponent(template, components, isCardCreator) {
27+ return CardCreator.createCardComponent(root, JSON.parse(template), JSON.parse(components), isCardCreator) !== null;
2828 }
2929}