on xenial help sign in
Merge
commit6fea34b9a004e6cc1c6403732b70bc87480457d3 authorAlbert Astals Cid <albert.astals@canonical.com> dateTue 16 Feb 2016, 16:17 (11 years ago) parent40eeb37dba5275
27 files changed+1589−58
plugins/Dash/CardCreator.js+5−5 plugins/Dash/CardCreatorCache.qml+3−3 qml/Dash/CardTool.qml+2−2 tests/plugins/Dash/cardcreator/1.res+1−2 tests/plugins/Dash/cardcreator/1.res.cardcreator+121 tests/plugins/Dash/cardcreator/10.res+1−2 tests/plugins/Dash/cardcreator/10.res.cardcreator+140 tests/plugins/Dash/cardcreator/11.res+1−2 tests/plugins/Dash/cardcreator/11.res.cardcreator+213 tests/plugins/Dash/cardcreator/2.res+1−2 tests/plugins/Dash/cardcreator/2.res.cardcreator+139 tests/plugins/Dash/cardcreator/3.res+1−2 tests/plugins/Dash/cardcreator/3.res.cardcreator+139 tests/plugins/Dash/cardcreator/4.res+1−2 tests/plugins/Dash/cardcreator/4.res.cardcreator+112 tests/plugins/Dash/cardcreator/5.res+1−2 tests/plugins/Dash/cardcreator/5.res.cardcreator+158 tests/plugins/Dash/cardcreator/6.res+1−2 tests/plugins/Dash/cardcreator/6.res.cardcreator+128 tests/plugins/Dash/cardcreator/7.res+1−2 tests/plugins/Dash/cardcreator/7.res.cardcreator+152 tests/plugins/Dash/cardcreator/8.res+1−2 tests/plugins/Dash/cardcreator/8.res.cardcreator+110 tests/plugins/Dash/cardcreator/9.res+1−2 tests/plugins/Dash/cardcreator/9.res.cardcreator+120 tests/plugins/Dash/cardcreatortest.cpp+32−22 tests/plugins/Dash/cardcreatortest.qml+4−4
plugins/Dash/CardCreator.js+5−5
@@ -399,7 +399,7 @@ function sanitizeColor(colorString) {
399399 return colorString;
400400}
401401
402−function cardString(template, components) {
402+function cardString(template, components, isCardTool) {
403403 var code;
404404
405405 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 = '""';
@@ -869,13 +869,13 @@ function cardString(template, components) {
869869 return code;
870870}
871871
872−function createCardComponent(parent, template, components, identifier) {
872+function createCardComponent(parent, template, components, isCardTool, identifier) {
873873 var imports = 'import QtQuick 2.4; \n\
874874 import Ubuntu.Components 1.3; \n\
875875 import Ubuntu.Settings.Components 0.1; \n\
876876 import Dash 0.1;\n\
877877 import Utils 0.1;\n';
878− var card = cardString(template, components);
878+ var card = cardString(template, components, isCardTool);
879879 var code = imports + 'Component {\n' + card + '}\n';
880880
881881 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.
@@ -193,7 +193,7 @@ Item {
193193 "summary": "—\n—\n—\n—\n—",
194194 "attributes": attributesModel.model
195195 }
196− sourceComponent: cardTool.cardComponent
196+ sourceComponent: CardCreatorCache.getCardComponent(cardTool.template, cardTool.components, true);
197197 onLoaded: {
198198 item.objectName = "cardToolCard";
199199 item.asynchronous = false;
tests/plugins/Dash/cardcreator/1.res+1−2
@@ -5,7 +5,6 @@ AbstractButton {
55 property string backgroundShapeStyle: "inset";
66 property real fontScale: 1.0;
77 property var scopeStyle: null;
8− property int titleAlignment: Text.AlignLeft;
98 property int fixedHeaderHeight: -1;
109 property size fixedArtShapeSize: Qt.size(-1, -1);
1110 readonly property string title: cardData && cardData["title"] || "";
@@ -108,7 +107,7 @@ Label {
108107 width: undefined;
109108 text: root.title;
110109 font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal;
111− horizontalAlignment: root.titleAlignment;
110+ horizontalAlignment: Text.AlignHCenter;
112111 }
113112UbuntuShape {
114113 id: touchdown;
tests/plugins/Dash/cardcreator/1.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 fixedHeaderHeight: -1;
9+ property size fixedArtShapeSize: Qt.size(-1, -1);
10+ readonly property string title: cardData && cardData["title"] || "";
11+ property bool asynchronous: true;
12+ property bool showHeader: true;
13+ implicitWidth: childrenRect.width;
14+ enabled: true;
15+
16+readonly property size artShapeSize: artShapeLoader.item ? Qt.size(artShapeLoader.item.width, artShapeLoader.item.height) : Qt.size(-1, -1);
17+Item {
18+ id: artShapeHolder;
19+ height: root.fixedArtShapeSize.height > 0 ? root.fixedArtShapeSize.height : artShapeLoader.height;
20+ width: root.fixedArtShapeSize.width > 0 ? root.fixedArtShapeSize.width : artShapeLoader.width;
21+ anchors { horizontalCenter: parent.horizontalCenter; }
22+ Loader {
23+ id: artShapeLoader;
24+ objectName: "artShapeLoader";
25+ readonly property string cardArt: cardData && cardData["art"] || "";
26+ active: cardArt != "";
27+ asynchronous: root.asynchronous;
28+ visible: status == Loader.Ready;
29+ sourceComponent: Item {
30+ id: artShape;
31+ objectName: "artShape";
32+ visible: image.status == Image.Ready;
33+ readonly property alias image: artImage;
34+ ShaderEffectSource {
35+ id: artShapeSource;
36+ sourceItem: artImage;
37+ anchors.centerIn: parent;
38+ width: 1;
39+ height: 1;
40+ hideSource: true;
41+ }
42+ Loader {
43+ anchors.fill: parent;
44+ visible: true;
45+ sourceComponent: root.artShapeStyle === "icon" ? artShapeIconComponent : artShapeShapeComponent;
46+ Component {
47+ id: artShapeShapeComponent;
48+ UbuntuShape {
49+ source: artShapeSource;
50+ sourceFillMode: UbuntuShape.PreserveAspectCrop;
51+ radius: "medium";
52+ aspect: {
53+ switch (root.artShapeStyle) {
54+ case "inset": return UbuntuShape.Inset;
55+ case "shadow": return UbuntuShape.DropShadow;
56+ default:
57+ case "flat": return UbuntuShape.Flat;
58+ }
59+ }
60+ }
61+ }
62+ Component {
63+ id: artShapeIconComponent;
64+ ProportionalShape { source: artShapeSource; aspect: UbuntuShape.DropShadow; }
65+ }
66+ }
67+ readonly property real fixedArtShapeSizeAspect: (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) ? root.fixedArtShapeSize.width / root.fixedArtShapeSize.height : -1;
68+ readonly property real aspect: fixedArtShapeSizeAspect > 0 ? fixedArtShapeSizeAspect : 1.6;
69+ Component.onCompleted: { updateWidthHeightBindings(); }
70+ Connections { target: root; onFixedArtShapeSizeChanged: updateWidthHeightBindings(); }
71+ function updateWidthHeightBindings() {
72+ if (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) {
73+ width = root.fixedArtShapeSize.width;
74+ height = root.fixedArtShapeSize.height;
75+ } else {
76+ width = Qt.binding(function() { return image.status !== Image.Ready ? 0 : image.width });
77+ height = Qt.binding(function() { return image.status !== Image.Ready ? 0 : image.height });
78+ }
79+ }
80+ CroppedImageMinimumSourceSize {
81+ id: artImage;
82+ objectName: "artImage";
83+ source: artShapeLoader.cardArt;
84+ asynchronous: root.asynchronous;
85+ width: root.width;
86+ height: width / artShape.aspect;
87+ }
88+ }
89+ }
90+ }
91+readonly property int headerHeight: titleLabel.height;
92+Label {
93+ id: titleLabel;
94+ objectName: "titleLabel";
95+ anchors { right: parent.right;
96+ left: parent.left;
97+ top: artShapeHolder.bottom;
98+ topMargin: units.gu(1);
99+ }
100+ elide: Text.ElideRight;
101+ fontSize: "small";
102+ wrapMode: Text.Wrap;
103+ maximumLineCount: 2;
104+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
105+ color: root.scopeStyle ? root.scopeStyle.foreground : theme.palette.normal.baseText;
106+ visible: showHeader ;
107+ width: undefined;
108+ text: root.title;
109+ font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal;
110+ horizontalAlignment: Text.AlignHCenter;
111+ }
112+UbuntuShape {
113+ id: touchdown;
114+ objectName: "touchdown";
115+ anchors { fill: artShapeHolder }
116+ visible: root.artShapeStyle != "shadow" && root.artShapeStyle != "icon" && root.pressed;
117+ radius: "medium";
118+ borderSource: "radius_pressed.sci"
119+}
120+implicitHeight: titleLabel.y + titleLabel.height + units.gu(1);
121+}
tests/plugins/Dash/cardcreator/10.res+1−2
@@ -5,7 +5,6 @@ AbstractButton {
55 property string backgroundShapeStyle: "inset";
66 property real fontScale: 1.0;
77 property var scopeStyle: null;
8− property int titleAlignment: Text.AlignLeft;
98 property int fixedHeaderHeight: -1;
109 property size fixedArtShapeSize: Qt.size(-1, -1);
1110 readonly property string title: cardData && cardData["title"] || "";
@@ -103,7 +102,7 @@ left: parent.left;
103102 width: undefined;
104103 text: root.title;
105104 font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal;
106− horizontalAlignment: root.titleAlignment;
105+ horizontalAlignment: Text.AlignLeft;
107106 }
108107,Label {
109108 id: subtitleLabel;
tests/plugins/Dash/cardcreator/10.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 fixedHeaderHeight: -1;
9+ property size fixedArtShapeSize: Qt.size(-1, -1);
10+ readonly property string title: cardData && cardData["title"] || "";
11+ property bool asynchronous: true;
12+ property bool showHeader: true;
13+ implicitWidth: childrenRect.width;
14+ enabled: true;
15+
16+Loader {
17+ id: backgroundLoader;
18+ objectName: "backgroundLoader";
19+ anchors.fill: parent;
20+ asynchronous: root.asynchronous;
21+ visible: status == Loader.Ready;
22+ sourceComponent: UbuntuShape {
23+ objectName: "background";
24+ radius: "medium";
25+ aspect: {
26+ switch (root.backgroundShapeStyle) {
27+ case "inset": return UbuntuShape.Inset;
28+ case "shadow": return UbuntuShape.DropShadow;
29+ default:
30+ case "flat": return UbuntuShape.Flat;
31+ }
32+ }
33+ backgroundColor: getColor(0) || "white";
34+ secondaryBackgroundColor: getColor(1) || backgroundColor;
35+ backgroundMode: UbuntuShape.VerticalGradient;
36+ anchors.fill: parent;
37+ source: backgroundImage.source ? backgroundImage : null;
38+ property real luminance: Style.luminance(backgroundColor);
39+ property Image backgroundImage: Image {
40+ objectName: "backgroundImage";
41+ source: {
42+ if (cardData && typeof cardData["background"] === "string") return cardData["background"];
43+ else return "";
44+ }
45+ }
46+ function getColor(index) {
47+ if (cardData && typeof cardData["background"] === "object"
48+ && (cardData["background"]["type"] === "color" || cardData["background"]["type"] === "gradient")) {
49+ return cardData["background"]["elements"][index];
50+ } else return index === 0 ? "" : "";
51+ }
52+ }
53+ }
54+readonly property size artShapeSize: Qt.size(-1, -1);
55+readonly property int headerHeight: row.height;
56+Row {
57+ id: row;
58+ objectName: "outerRow";
59+ property real margins: units.gu(1);
60+ spacing: margins;
61+ height: root.fixedHeaderHeight != -1 ? root.fixedHeaderHeight : implicitHeight;
62+ anchors { top: parent.top;
63+ topMargin: units.gu(1);
64+left: parent.left;
65+ }
66+ anchors.right: parent.right;
67+ anchors.margins: margins;
68+ anchors.rightMargin: 0;
69+ data: [
70+ CroppedImageMinimumSourceSize {
71+ id: mascotImage;
72+ objectName: "mascotImage";
73+ anchors { verticalCenter: parent.verticalCenter; }
74+ source: cardData && cardData["mascot"] || "";
75+ width: units.gu(6);
76+ height: units.gu(5.625);
77+ horizontalAlignment: Image.AlignHCenter;
78+ verticalAlignment: Image.AlignVCenter;
79+ visible: showHeader;
80+
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: Text.AlignLeft;
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/11.res+1−2
@@ -5,7 +5,6 @@ AbstractButton {
55 property string backgroundShapeStyle: "inset";
66 property real fontScale: 1.0;
77 property var scopeStyle: null;
8− property int titleAlignment: Text.AlignLeft;
98 property int fixedHeaderHeight: -1;
109 property size fixedArtShapeSize: Qt.size(-1, -1);
1110 readonly property string title: cardData && cardData["title"] || "";
@@ -178,7 +177,7 @@ left: parent.left;
178177 width: undefined;
179178 text: root.title;
180179 font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal;
181− horizontalAlignment: root.titleAlignment;
180+ horizontalAlignment: Text.AlignLeft;
182181 }
183182,Label {
184183 id: subtitleLabel;
tests/plugins/Dash/cardcreator/11.res.cardcreatornew file+213
@@ -0,0 +1,213 @@
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 fixedHeaderHeight: -1;
9+ property size fixedArtShapeSize: Qt.size(-1, -1);
10+ readonly property string title: cardData && cardData["title"] || "";
11+ property bool asynchronous: true;
12+ property bool showHeader: true;
13+ implicitWidth: childrenRect.width;
14+ enabled: true;
15+
16+Loader {
17+ id: backgroundLoader;
18+ objectName: "backgroundLoader";
19+ anchors.fill: parent;
20+ asynchronous: root.asynchronous;
21+ visible: status == Loader.Ready;
22+ sourceComponent: UbuntuShape {
23+ objectName: "background";
24+ radius: "medium";
25+ aspect: {
26+ switch (root.backgroundShapeStyle) {
27+ case "inset": return UbuntuShape.Inset;
28+ case "shadow": return UbuntuShape.DropShadow;
29+ default:
30+ case "flat": return UbuntuShape.Flat;
31+ }
32+ }
33+ backgroundColor: getColor(0) || "white";
34+ secondaryBackgroundColor: getColor(1) || backgroundColor;
35+ backgroundMode: UbuntuShape.VerticalGradient;
36+ anchors.fill: parent;
37+ source: backgroundImage.source ? backgroundImage : null;
38+ property real luminance: Style.luminance(backgroundColor);
39+ property Image backgroundImage: Image {
40+ objectName: "backgroundImage";
41+ source: {
42+ if (cardData && typeof cardData["background"] === "string") return cardData["background"];
43+ else return "";
44+ }
45+ }
46+ function getColor(index) {
47+ if (cardData && typeof cardData["background"] === "object"
48+ && (cardData["background"]["type"] === "color" || cardData["background"]["type"] === "gradient")) {
49+ return cardData["background"]["elements"][index];
50+ } else return index === 0 ? "#E9E9E9" : undefined;
51+ }
52+ }
53+ }
54+readonly property size artShapeSize: artShapeLoader.item ? Qt.size(artShapeLoader.item.width, artShapeLoader.item.height) : Qt.size(-1, -1);
55+Item {
56+ id: artShapeHolder;
57+ height: root.fixedArtShapeSize.height > 0 ? root.fixedArtShapeSize.height : artShapeLoader.height;
58+ width: root.fixedArtShapeSize.width > 0 ? root.fixedArtShapeSize.width : artShapeLoader.width;
59+ anchors { horizontalCenter: parent.horizontalCenter; }
60+ Loader {
61+ id: artShapeLoader;
62+ objectName: "artShapeLoader";
63+ readonly property string cardArt: cardData && cardData["art"] || "";
64+ active: cardArt != "";
65+ asynchronous: root.asynchronous;
66+ visible: status == Loader.Ready;
67+ sourceComponent: Item {
68+ id: artShape;
69+ objectName: "artShape";
70+ visible: image.status == Image.Ready;
71+ readonly property alias image: artImage;
72+ ShaderEffectSource {
73+ id: artShapeSource;
74+ sourceItem: artImage;
75+ anchors.centerIn: parent;
76+ width: 1;
77+ height: 1;
78+ hideSource: true;
79+ }
80+ Loader {
81+ anchors.fill: parent;
82+ visible: true;
83+ sourceComponent: root.artShapeStyle === "icon" ? artShapeIconComponent : artShapeShapeComponent;
84+ Component {
85+ id: artShapeShapeComponent;
86+ UbuntuShape {
87+ source: artShapeSource;
88+ sourceFillMode: UbuntuShape.PreserveAspectCrop;
89+ radius: "medium";
90+ aspect: {
91+ switch (root.artShapeStyle) {
92+ case "inset": return UbuntuShape.Inset;
93+ case "shadow": return UbuntuShape.DropShadow;
94+ default:
95+ case "flat": return UbuntuShape.Flat;
96+ }
97+ }
98+ }
99+ }
100+ Component {
101+ id: artShapeIconComponent;
102+ ProportionalShape { source: artShapeSource; aspect: UbuntuShape.DropShadow; }
103+ }
104+ }
105+ readonly property real fixedArtShapeSizeAspect: (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) ? root.fixedArtShapeSize.width / root.fixedArtShapeSize.height : -1;
106+ readonly property real aspect: fixedArtShapeSizeAspect > 0 ? fixedArtShapeSizeAspect : 1;
107+ Component.onCompleted: { updateWidthHeightBindings(); }
108+ Connections { target: root; onFixedArtShapeSizeChanged: updateWidthHeightBindings(); }
109+ function updateWidthHeightBindings() {
110+ if (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) {
111+ width = root.fixedArtShapeSize.width;
112+ height = root.fixedArtShapeSize.height;
113+ } else {
114+ width = Qt.binding(function() { return image.status !== Image.Ready ? 0 : image.width });
115+ height = Qt.binding(function() { return image.status !== Image.Ready ? 0 : image.height });
116+ }
117+ }
118+ CroppedImageMinimumSourceSize {
119+ id: artImage;
120+ objectName: "artImage";
121+ source: artShapeLoader.cardArt;
122+ asynchronous: root.asynchronous;
123+ width: root.width;
124+ height: width / artShape.aspect;
125+ }
126+ }
127+ }
128+ }
129+readonly property int headerHeight: row.height;
130+Row {
131+ id: row;
132+ objectName: "outerRow";
133+ property real margins: units.gu(1);
134+ spacing: margins;
135+ height: root.fixedHeaderHeight != -1 ? root.fixedHeaderHeight : implicitHeight;
136+ anchors { top: artShapeHolder.bottom;
137+ topMargin: units.gu(1);
138+left: parent.left;
139+ }
140+ anchors.right: parent.right;
141+ anchors.margins: margins;
142+ anchors.rightMargin: 0;
143+ data: [
144+ CroppedImageMinimumSourceSize {
145+ id: mascotImage;
146+ objectName: "mascotImage";
147+ anchors { verticalCenter: parent.verticalCenter; }
148+ source: cardData && cardData["mascot"] || "";
149+ width: units.gu(6);
150+ height: units.gu(5.625);
151+ horizontalAlignment: Image.AlignHCenter;
152+ verticalAlignment: Image.AlignVCenter;
153+ visible: showHeader;
154+ }
155+,Item {
156+ id: headerTitleContainer;
157+ anchors { verticalCenter: parent.verticalCenter; }
158+ width: parent.width - x;
159+ implicitHeight: titleLabel.height + subtitleLabel.height;
160+ data: [
161+ Label {
162+ id: titleLabel;
163+ objectName: "titleLabel";
164+ anchors { right: parent.right;
165+rightMargin: units.gu(1);
166+left: parent.left;
167+ top: parent.top; }
168+ elide: Text.ElideRight;
169+ fontSize: "small";
170+ wrapMode: Text.Wrap;
171+ maximumLineCount: 2;
172+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
173+ 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");
174+ visible: showHeader ;
175+ width: undefined;
176+ text: root.title;
177+ font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal;
178+ horizontalAlignment: Text.AlignLeft;
179+ }
180+,Label {
181+ id: subtitleLabel;
182+ objectName: "subtitleLabel";
183+ anchors { right: parent.right;
184+ left: parent.left;
185+rightMargin: units.gu(1);
186+top: titleLabel.bottom;
187+ }
188+ anchors.topMargin: units.dp(2);
189+ elide: Text.ElideRight;
190+ maximumLineCount: 1;
191+ fontSize: "x-small";
192+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
193+ 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");
194+ visible: titleLabel.visible && titleLabel.text;
195+ text: cardData && cardData["subtitle"] || "";
196+ font.weight: Font.Light;
197+ }
198+
199+ ]
200+ }
201+
202+ ]
203+ }
204+UbuntuShape {
205+ id: touchdown;
206+ objectName: "touchdown";
207+ anchors { fill: backgroundLoader }
208+ visible: root.artShapeStyle != "shadow" && root.artShapeStyle != "icon" && root.pressed;
209+ radius: "medium";
210+ borderSource: "radius_pressed.sci"
211+ }
212+implicitHeight: row.y + row.height + units.gu(1);
213+}
tests/plugins/Dash/cardcreator/2.res+1−2
@@ -5,7 +5,6 @@ AbstractButton {
55 property string backgroundShapeStyle: "inset";
66 property real fontScale: 1.0;
77 property var scopeStyle: null;
8− property int titleAlignment: Text.AlignLeft;
98 property int fixedHeaderHeight: -1;
109 property size fixedArtShapeSize: Qt.size(-1, -1);
1110 readonly property string title: cardData && cardData["title"] || "";
@@ -102,7 +101,7 @@ CroppedImageMinimumSourceSize {
102101 width: undefined;
103102 text: root.title;
104103 font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal;
105− horizontalAlignment: root.titleAlignment;
104+ horizontalAlignment: Text.AlignLeft;
106105 }
107106 ,Label {
108107 id: subtitleLabel;
tests/plugins/Dash/cardcreator/2.res.cardcreatornew file+139
@@ -0,0 +1,139 @@
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 fixedHeaderHeight: -1;
9+ property size fixedArtShapeSize: Qt.size(-1, -1);
10+ readonly property string title: cardData && cardData["title"] || "";
11+ property bool asynchronous: true;
12+ property bool showHeader: true;
13+ implicitWidth: childrenRect.width;
14+ enabled: true;
15+
16+Loader {
17+ id: backgroundLoader;
18+ objectName: "backgroundLoader";
19+ anchors.fill: parent;
20+ asynchronous: root.asynchronous;
21+ visible: status == Loader.Ready;
22+ sourceComponent: UbuntuShape {
23+ objectName: "background";
24+ radius: "medium";
25+ aspect: {
26+ switch (root.backgroundShapeStyle) {
27+ case "inset": return UbuntuShape.Inset;
28+ case "shadow": return UbuntuShape.DropShadow;
29+ default:
30+ case "flat": return UbuntuShape.Flat;
31+ }
32+ }
33+ backgroundColor: getColor(0) || "white";
34+ secondaryBackgroundColor: getColor(1) || backgroundColor;
35+ backgroundMode: UbuntuShape.VerticalGradient;
36+ anchors.fill: parent;
37+ source: backgroundImage.source ? backgroundImage : null;
38+ property real luminance: Style.luminance(backgroundColor);
39+ property Image backgroundImage: Image {
40+ objectName: "backgroundImage";
41+ source: {
42+ if (cardData && typeof cardData["background"] === "string") return cardData["background"];
43+ else return "";
44+ }
45+ }
46+ function getColor(index) {
47+ if (cardData && typeof cardData["background"] === "object"
48+ && (cardData["background"]["type"] === "color" || cardData["background"]["type"] === "gradient")) {
49+ return cardData["background"]["elements"][index];
50+ } else return index === 0 ? "#E9E9E9" : undefined;
51+ }
52+ }
53+ }
54+readonly property size artShapeSize: Qt.size(-1, -1);
55+readonly property int headerHeight: row.height;
56+Row {
57+ id: row;
58+ objectName: "outerRow";
59+ property real margins: units.gu(1);
60+ spacing: margins;
61+ height: root.fixedHeaderHeight != -1 ? root.fixedHeaderHeight : implicitHeight;
62+ anchors { top: parent.top;
63+ topMargin: units.gu(1);
64+ left: parent.left;
65+ }
66+ anchors.right: parent.right;
67+ anchors.margins: margins;
68+ anchors.rightMargin: 0;
69+ data: [
70+CroppedImageMinimumSourceSize {
71+ id: mascotImage;
72+ objectName: "mascotImage";
73+ anchors { verticalCenter: parent.verticalCenter; }
74+ source: cardData && cardData["mascot"] || "";
75+ width: units.gu(6);
76+ height: units.gu(5.625);
77+ horizontalAlignment: Image.AlignHCenter;
78+ verticalAlignment: Image.AlignVCenter;
79+ visible: showHeader;
80+ }
81+,Item {
82+ id: headerTitleContainer;
83+ anchors { verticalCenter: parent.verticalCenter; }
84+ width: parent.width - x;
85+ implicitHeight: titleLabel.height + subtitleLabel.height;
86+ data: [
87+ Label {
88+ id: titleLabel;
89+ objectName: "titleLabel";
90+ anchors { right: parent.right;
91+ rightMargin: units.gu(1);
92+ left: parent.left;
93+ top: parent.top; }
94+ elide: Text.ElideRight;
95+ fontSize: "small";
96+ wrapMode: Text.Wrap;
97+ maximumLineCount: 2;
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: showHeader ;
101+ width: undefined;
102+ text: root.title;
103+ font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal;
104+ horizontalAlignment: Text.AlignLeft;
105+ }
106+ ,Label {
107+ id: subtitleLabel;
108+ objectName: "subtitleLabel";
109+ anchors { right: parent.right;
110+ left: parent.left;
111+ rightMargin: units.gu(1);
112+ top: titleLabel.bottom;
113+ }
114+ anchors.topMargin: units.dp(2);
115+ elide: Text.ElideRight;
116+ maximumLineCount: 1;
117+ fontSize: "x-small";
118+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
119+ 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");
120+ visible: titleLabel.visible && titleLabel.text;
121+ text: cardData && cardData["subtitle"] || "";
122+ font.weight: Font.Light;
123+ }
124+
125+ ]
126+ }
127+
128+ ]
129+ }
130+UbuntuShape {
131+ id: touchdown;
132+ objectName: "touchdown";
133+ anchors { fill: backgroundLoader }
134+ visible: root.artShapeStyle != "shadow" && root.artShapeStyle != "icon" && root.pressed;
135+ radius: "medium";
136+ borderSource: "radius_pressed.sci"
137+}
138+implicitHeight: row.y + row.height + units.gu(1);
139+}
tests/plugins/Dash/cardcreator/3.res+1−2
@@ -5,7 +5,6 @@ AbstractButton {
55 property string backgroundShapeStyle: "inset";
66 property real fontScale: 1.0;
77 property var scopeStyle: null;
8− property int titleAlignment: Text.AlignLeft;
98 property int fixedHeaderHeight: -1;
109 property size fixedArtShapeSize: Qt.size(-1, -1);
1110 readonly property string title: cardData && cardData["title"] || "";
@@ -109,7 +108,7 @@ Label {
109108 width: undefined;
110109 text: root.title;
111110 font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal;
112− horizontalAlignment: root.titleAlignment;
111+ horizontalAlignment: Text.AlignLeft;
113112 }
114113Label {
115114 id: subtitleLabel;
tests/plugins/Dash/cardcreator/3.res.cardcreatornew file+139
@@ -0,0 +1,139 @@
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 fixedHeaderHeight: -1;
9+ property size fixedArtShapeSize: Qt.size(-1, -1);
10+ readonly property string title: cardData && cardData["title"] || "";
11+ property bool asynchronous: true;
12+ property bool showHeader: true;
13+ implicitWidth: childrenRect.width;
14+ enabled: true;
15+
16+readonly property size artShapeSize: artShapeLoader.item ? Qt.size(artShapeLoader.item.width, artShapeLoader.item.height) : Qt.size(-1, -1);
17+Item {
18+ id: artShapeHolder;
19+ height: root.fixedArtShapeSize.height > 0 ? root.fixedArtShapeSize.height : artShapeLoader.height;
20+ width: root.fixedArtShapeSize.width > 0 ? root.fixedArtShapeSize.width : artShapeLoader.width;
21+ anchors { horizontalCenter: parent.horizontalCenter; }
22+ Loader {
23+ id: artShapeLoader;
24+ objectName: "artShapeLoader";
25+ readonly property string cardArt: cardData && cardData["art"] || "";
26+ active: cardArt != "";
27+ asynchronous: root.asynchronous;
28+ visible: status == Loader.Ready;
29+ sourceComponent: Item {
30+ id: artShape;
31+ objectName: "artShape";
32+ visible: image.status == Image.Ready;
33+ readonly property alias image: artImage;
34+ ShaderEffectSource {
35+ id: artShapeSource;
36+ sourceItem: artImage;
37+ anchors.centerIn: parent;
38+ width: 1;
39+ height: 1;
40+ hideSource: true;
41+ }
42+ Loader {
43+ anchors.fill: parent;
44+ visible: true;
45+ sourceComponent: root.artShapeStyle === "icon" ? artShapeIconComponent : artShapeShapeComponent;
46+ Component {
47+ id: artShapeShapeComponent;
48+ UbuntuShape {
49+ source: artShapeSource;
50+ sourceFillMode: UbuntuShape.PreserveAspectCrop;
51+ radius: "medium";
52+ aspect: {
53+ switch (root.artShapeStyle) {
54+ case "inset": return UbuntuShape.Inset;
55+ case "shadow": return UbuntuShape.DropShadow;
56+ default:
57+ case "flat": return UbuntuShape.Flat;
58+ }
59+ }
60+ }
61+ }
62+ Component {
63+ id: artShapeIconComponent;
64+ ProportionalShape { source: artShapeSource; aspect: UbuntuShape.DropShadow; }
65+ }
66+ }
67+ readonly property real fixedArtShapeSizeAspect: (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) ? root.fixedArtShapeSize.width / root.fixedArtShapeSize.height : -1;
68+ readonly property real aspect: fixedArtShapeSizeAspect > 0 ? fixedArtShapeSizeAspect : 0.75;
69+ Component.onCompleted: { updateWidthHeightBindings(); }
70+ Connections { target: root; onFixedArtShapeSizeChanged: updateWidthHeightBindings(); }
71+ function updateWidthHeightBindings() {
72+ if (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) {
73+ width = root.fixedArtShapeSize.width;
74+ height = root.fixedArtShapeSize.height;
75+ } else {
76+ width = Qt.binding(function() { return image.status !== Image.Ready ? 0 : image.width });
77+ height = Qt.binding(function() { return image.status !== Image.Ready ? 0 : image.height });
78+ }
79+ }
80+ CroppedImageMinimumSourceSize {
81+ id: artImage;
82+ objectName: "artImage";
83+ source: artShapeLoader.cardArt;
84+ asynchronous: root.asynchronous;
85+ width: root.width;
86+ height: width / artShape.aspect;
87+ }
88+ }
89+ }
90+ }
91+readonly property int headerHeight: titleLabel.height + subtitleLabel.height + subtitleLabel.anchors.topMargin;
92+Label {
93+ id: titleLabel;
94+ objectName: "titleLabel";
95+ anchors { right: parent.right;
96+ left: parent.left;
97+ top: artShapeHolder.bottom;
98+ topMargin: units.gu(1);
99+ }
100+ elide: Text.ElideRight;
101+ fontSize: "small";
102+ wrapMode: Text.Wrap;
103+ maximumLineCount: 2;
104+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
105+ color: root.scopeStyle ? root.scopeStyle.foreground : theme.palette.normal.baseText;
106+ visible: showHeader ;
107+ width: undefined;
108+ text: root.title;
109+ font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal;
110+ horizontalAlignment: Text.AlignLeft;
111+ }
112+Label {
113+ id: subtitleLabel;
114+ objectName: "subtitleLabel";
115+ anchors { left: titleLabel.left;
116+ leftMargin: titleLabel.leftMargin;
117+ right: titleLabel.right;
118+ top: titleLabel.bottom;
119+ }
120+ anchors.topMargin: units.dp(2);
121+ elide: Text.ElideRight;
122+ maximumLineCount: 1;
123+ fontSize: "x-small";
124+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
125+ color: root.scopeStyle ? root.scopeStyle.foreground : theme.palette.normal.baseText;
126+ visible: titleLabel.visible && titleLabel.text;
127+ text: cardData && cardData["subtitle"] || "";
128+ font.weight: Font.Light;
129+ }
130+UbuntuShape {
131+ id: touchdown;
132+ objectName: "touchdown";
133+ anchors { fill: artShapeHolder }
134+ visible: root.artShapeStyle != "shadow" && root.artShapeStyle != "icon" && root.pressed;
135+ radius: "medium";
136+ borderSource: "radius_pressed.sci"
137+}
138+implicitHeight: subtitleLabel.y + subtitleLabel.height + units.gu(1);
139+}
tests/plugins/Dash/cardcreator/4.res+1−2
@@ -5,7 +5,6 @@ AbstractButton {
55 property string backgroundShapeStyle: "inset";
66 property real fontScale: 1.0;
77 property var scopeStyle: null;
8− property int titleAlignment: Text.AlignLeft;
98 property int fixedHeaderHeight: -1;
109 property size fixedArtShapeSize: Qt.size(-1, -1);
1110 readonly property string title: cardData && cardData["title"] || "";
@@ -77,7 +76,7 @@ Label {
7776 width: undefined;
7877 text: root.title;
7978 font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal;
80− horizontalAlignment: root.titleAlignment;
79+ horizontalAlignment: Text.AlignLeft;
8180 }
8281,Label {
8382 id: subtitleLabel;
tests/plugins/Dash/cardcreator/4.res.cardcreatornew file+112
@@ -0,0 +1,112 @@
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 fixedHeaderHeight: -1;
9+ property size fixedArtShapeSize: Qt.size(-1, -1);
10+ readonly property string title: cardData && cardData["title"] || "";
11+ property bool asynchronous: true;
12+ property bool showHeader: true;
13+ implicitWidth: childrenRect.width;
14+ enabled: true;
15+
16+readonly property size artShapeSize: Qt.size(-1, -1);
17+readonly property int headerHeight: row.height;
18+Row {
19+ id: row;
20+ objectName: "outerRow";
21+ property real margins: units.gu(1);
22+ spacing: margins;
23+ height: root.fixedHeaderHeight != -1 ? root.fixedHeaderHeight : implicitHeight;
24+ anchors { top: parent.top;
25+ topMargin: units.gu(1);
26+ left: parent.left;
27+}
28+ anchors.right: parent.right;
29+ anchors.margins: margins;
30+ anchors.rightMargin: 0;
31+data: [
32+Loader {
33+ id: mascotShapeLoader;
34+ objectName: "mascotShapeLoader";
35+ asynchronous: root.asynchronous;
36+ active: mascotImage.status === Image.Ready;
37+ visible: showHeader && active && status == Loader.Ready;
38+ width: units.gu(6);
39+ height: units.gu(5.625);
40+ sourceComponent: UbuntuShape { image: mascotImage }
41+ anchors { verticalCenter: parent.verticalCenter; }
42+ }
43+
44+,CroppedImageMinimumSourceSize {
45+ id: mascotImage;
46+ objectName: "mascotImage";
47+ anchors { verticalCenter: parent.verticalCenter; }
48+ source: cardData && cardData["mascot"] || "";
49+ width: units.gu(6);
50+ height: units.gu(5.625);
51+ horizontalAlignment: Image.AlignHCenter;
52+ verticalAlignment: Image.AlignVCenter;
53+ visible: false;
54+ }
55+
56+,Item {
57+ id: headerTitleContainer;
58+ anchors { verticalCenter: parent.verticalCenter; }
59+ width: parent.width - x;
60+ implicitHeight: titleLabel.height + subtitleLabel.height;
61+ data: [
62+Label {
63+ id: titleLabel;
64+ objectName: "titleLabel";
65+ anchors { right: parent.right;
66+ rightMargin: units.gu(1);
67+ left: parent.left;
68+ top: parent.top; }
69+ elide: Text.ElideRight;
70+ fontSize: "small";
71+ wrapMode: Text.Wrap;
72+ maximumLineCount: 2;
73+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
74+ color: root.scopeStyle ? root.scopeStyle.foreground : theme.palette.normal.baseText;
75+ visible: showHeader ;
76+ width: undefined;
77+ text: root.title;
78+ font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal;
79+ horizontalAlignment: Text.AlignLeft;
80+ }
81+,Label {
82+ id: subtitleLabel;
83+ objectName: "subtitleLabel";
84+ anchors { right: parent.right;
85+ left: parent.left;
86+ rightMargin: units.gu(1);
87+ top: titleLabel.bottom;
88+ }
89+ anchors.topMargin: units.dp(2);
90+ elide: Text.ElideRight;
91+ maximumLineCount: 1;
92+ fontSize: "x-small";
93+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
94+ color: root.scopeStyle ? root.scopeStyle.foreground : theme.palette.normal.baseText;
95+ visible: titleLabel.visible && titleLabel.text;
96+ text: cardData && cardData["subtitle"] || "";
97+ font.weight: Font.Light;
98+ }
99+]
100+}
101+]
102+}
103+UbuntuShape {
104+ id: touchdown;
105+ objectName: "touchdown";
106+ anchors { fill: root }
107+ visible: root.artShapeStyle != "shadow" && root.artShapeStyle != "icon" && root.pressed;
108+ radius: "medium";
109+ borderSource: "radius_pressed.sci"
110+}
111+implicitHeight: row.y + row.height + units.gu(1);
112+}
tests/plugins/Dash/cardcreator/5.res+1−2
@@ -5,7 +5,6 @@ AbstractButton {
55 property string backgroundShapeStyle: "inset";
66 property real fontScale: 1.0;
77 property var scopeStyle: null;
8− property int titleAlignment: Text.AlignLeft;
98 property int fixedHeaderHeight: -1;
109 property size fixedArtShapeSize: Qt.size(-1, -1);
1110 readonly property string title: cardData && cardData["title"] || "";
@@ -126,7 +125,7 @@ Label {
126125 width: undefined;
127126 text: root.title;
128127 font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal;
129− horizontalAlignment: root.titleAlignment;
128+ horizontalAlignment: Text.AlignLeft;
130129 }
131130Label {
132131 id: subtitleLabel;
tests/plugins/Dash/cardcreator/5.res.cardcreatornew file+158
@@ -0,0 +1,158 @@
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 fixedHeaderHeight: -1;
9+ property size fixedArtShapeSize: Qt.size(-1, -1);
10+ readonly property string title: cardData && cardData["title"] || "";
11+ property bool asynchronous: true;
12+ property bool showHeader: true;
13+ implicitWidth: childrenRect.width;
14+ enabled: false;
15+
16+readonly property size artShapeSize: artShapeLoader.item ? Qt.size(artShapeLoader.item.width, artShapeLoader.item.height) : Qt.size(-1, -1);
17+Item {
18+ id: artShapeHolder;
19+ height: root.fixedArtShapeSize.height > 0 ? root.fixedArtShapeSize.height : artShapeLoader.height;
20+ width: root.fixedArtShapeSize.width > 0 ? root.fixedArtShapeSize.width : artShapeLoader.width;
21+ anchors { horizontalCenter: parent.horizontalCenter; }
22+ Loader {
23+ id: artShapeLoader;
24+ objectName: "artShapeLoader";
25+ readonly property string cardArt: cardData && cardData["art"] || "";
26+ active: cardArt != "";
27+ asynchronous: root.asynchronous;
28+ visible: status == Loader.Ready;
29+ sourceComponent: Item {
30+ id: artShape;
31+ objectName: "artShape";
32+ visible: image.status == Image.Ready;
33+ readonly property alias image: artImage;
34+ ShaderEffectSource {
35+ id: artShapeSource;
36+ sourceItem: artImage;
37+ anchors.centerIn: parent;
38+ width: 1;
39+ height: 1;
40+ hideSource: false;
41+ }
42+ Loader {
43+ anchors.fill: parent;
44+ visible: false;
45+ sourceComponent: root.artShapeStyle === "icon" ? artShapeIconComponent : artShapeShapeComponent;
46+ Component {
47+ id: artShapeShapeComponent;
48+ UbuntuShape {
49+ source: artShapeSource;
50+ sourceFillMode: UbuntuShape.PreserveAspectCrop;
51+ radius: "medium";
52+ aspect: {
53+ switch (root.artShapeStyle) {
54+ case "inset": return UbuntuShape.Inset;
55+ case "shadow": return UbuntuShape.DropShadow;
56+ default:
57+ case "flat": return UbuntuShape.Flat;
58+ }
59+ }
60+ }
61+ }
62+ Component {
63+ id: artShapeIconComponent;
64+ ProportionalShape { source: artShapeSource; aspect: UbuntuShape.DropShadow; }
65+ }
66+ }
67+ readonly property real fixedArtShapeSizeAspect: (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) ? root.fixedArtShapeSize.width / root.fixedArtShapeSize.height : -1;
68+ readonly property real aspect: fixedArtShapeSizeAspect > 0 ? fixedArtShapeSizeAspect : 1;
69+ Component.onCompleted: { updateWidthHeightBindings(); }
70+ Connections { target: root; onFixedArtShapeSizeChanged: updateWidthHeightBindings(); }
71+ function updateWidthHeightBindings() {
72+ if (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) {
73+ width = root.fixedArtShapeSize.width;
74+ height = root.fixedArtShapeSize.height;
75+ } else {
76+ width = Qt.binding(function() { return image.status !== Image.Ready ? 0 : image.width });
77+ height = Qt.binding(function() { return image.status !== Image.Ready ? 0 : image.height });
78+ }
79+ }
80+ CroppedImageMinimumSourceSize {
81+ id: artImage;
82+ objectName: "artImage";
83+ source: artShapeLoader.cardArt;
84+ asynchronous: root.asynchronous;
85+ width: root.width;
86+ height: width / artShape.aspect;
87+ }
88+ }
89+ }
90+ }
91+Loader {
92+ id: overlayLoader;
93+ readonly property real overlayHeight: (fixedHeaderHeight > 0 ? fixedHeaderHeight : headerHeight) + units.gu(2);
94+ anchors.fill: artShapeHolder;
95+ active: artShapeLoader.active && artShapeLoader.item && artShapeLoader.item.image.status === Image.Ready || false;
96+ asynchronous: root.asynchronous;
97+ visible: showHeader && status == Loader.Ready;
98+ sourceComponent: UbuntuShapeOverlay {
99+ id: overlay;
100+ property real luminance: Style.luminance(overlayColor);
101+ aspect: UbuntuShape.Flat;
102+ radius: "medium";
103+ overlayColor: cardData && cardData["overlayColor"] || "#99000000";
104+ overlayRect: Qt.rect(0, 1 - overlayLoader.overlayHeight / height, 1, 1);
105+ }
106+ }
107+readonly property int headerHeight: titleLabel.height + subtitleLabel.height + subtitleLabel.anchors.topMargin;
108+Label {
109+ id: titleLabel;
110+ objectName: "titleLabel";
111+ anchors { right: parent.right;
112+ rightMargin: units.gu(1);
113+ left: parent.left;
114+ leftMargin: units.gu(1);
115+ top: overlayLoader.top;
116+ topMargin: units.gu(1) + overlayLoader.height - overlayLoader.overlayHeight;
117+ }
118+ elide: Text.ElideRight;
119+ fontSize: "small";
120+ wrapMode: Text.Wrap;
121+ maximumLineCount: 2;
122+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
123+ color: root.scopeStyle && overlayLoader.item ? root.scopeStyle.getTextColor(overlayLoader.item.luminance) : (overlayLoader.item && overlayLoader.item.luminance > 0.7 ? theme.palette.normal.baseText : "white");
124+ visible: showHeader && overlayLoader.active;
125+ width: undefined;
126+ text: root.title;
127+ font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal;
128+ horizontalAlignment: Text.AlignLeft;
129+ }
130+Label {
131+ id: subtitleLabel;
132+ objectName: "subtitleLabel";
133+ anchors { left: titleLabel.left;
134+ leftMargin: titleLabel.leftMargin;
135+ rightMargin: units.gu(1);
136+ right: titleLabel.right;
137+ top: titleLabel.bottom;
138+ }
139+ anchors.topMargin: units.dp(2);
140+ elide: Text.ElideRight;
141+ maximumLineCount: 1;
142+ fontSize: "x-small";
143+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
144+ color: root.scopeStyle && overlayLoader.item ? root.scopeStyle.getTextColor(overlayLoader.item.luminance) : (overlayLoader.item && overlayLoader.item.luminance > 0.7 ? theme.palette.normal.baseText : "white");
145+ visible: titleLabel.visible && titleLabel.text;
146+ text: cardData && cardData["subtitle"] || "";
147+ font.weight: Font.Light;
148+ }
149+UbuntuShape {
150+ id: touchdown;
151+ objectName: "touchdown";
152+ anchors { fill: artShapeHolder }
153+ visible: root.artShapeStyle != "shadow" && root.artShapeStyle != "icon" && root.pressed;
154+ radius: "medium";
155+ borderSource: "radius_pressed.sci"
156+}
157+implicitHeight: artShapeHolder.height;
158+}
tests/plugins/Dash/cardcreator/6.res+1−2
@@ -5,7 +5,6 @@ AbstractButton {
55 property string backgroundShapeStyle: "inset";
66 property real fontScale: 1.0;
77 property var scopeStyle: null;
8− property int titleAlignment: Text.AlignLeft;
98 property int fixedHeaderHeight: -1;
109 property size fixedArtShapeSize: Qt.size(-1, -1);
1110 readonly property string title: cardData && cardData["title"] || "";
@@ -81,7 +80,7 @@ Item {
8180 width: undefined;
8281 text: root.title;
8382 font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal;
84− horizontalAlignment: root.titleAlignment;
83+ horizontalAlignment: Text.AlignLeft;
8584 }
8685,Label {
8786 id: subtitleLabel;
tests/plugins/Dash/cardcreator/6.res.cardcreatornew file+128
@@ -0,0 +1,128 @@
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 fixedHeaderHeight: -1;
9+ property size fixedArtShapeSize: Qt.size(-1, -1);
10+ readonly property string title: cardData && cardData["title"] || "";
11+ property bool asynchronous: true;
12+ property bool showHeader: true;
13+ implicitWidth: childrenRect.width;
14+ enabled: true;
15+
16+Loader {
17+ id: backgroundLoader;
18+ objectName: "backgroundLoader";
19+ anchors.fill: parent;
20+ asynchronous: root.asynchronous;
21+ visible: status == Loader.Ready;
22+ sourceComponent: UbuntuShape {
23+ objectName: "background";
24+ radius: "medium";
25+ aspect: {
26+ switch (root.backgroundShapeStyle) {
27+ case "inset": return UbuntuShape.Inset;
28+ case "shadow": return UbuntuShape.DropShadow;
29+ default:
30+ case "flat": return UbuntuShape.Flat;
31+ }
32+ }
33+ backgroundColor: getColor(0) || "white";
34+ secondaryBackgroundColor: getColor(1) || backgroundColor;
35+ backgroundMode: UbuntuShape.VerticalGradient;
36+ anchors.fill: parent;
37+ source: backgroundImage.source ? backgroundImage : null;
38+ property real luminance: Style.luminance(backgroundColor);
39+ property Image backgroundImage: Image {
40+ objectName: "backgroundImage";
41+ source: {
42+ if (cardData && typeof cardData["background"] === "string") return cardData["background"];
43+ else return decodeURI("http://assets.ubuntu.com/sites/ubuntu/latest/u/img/logos/logo-ubuntu-grey.png");
44+ }
45+ }
46+ function getColor(index) {
47+ if (cardData && typeof cardData["background"] === "object"
48+ && (cardData["background"]["type"] === "color" || cardData["background"]["type"] === "gradient")) {
49+ return cardData["background"]["elements"][index];
50+ } else return index === 0 ? undefined : undefined;
51+ }
52+ }
53+ }
54+readonly property size artShapeSize: Qt.size(-1, -1);
55+readonly property int headerHeight: titleLabel.height + subtitleLabel.height + subtitleLabel.anchors.topMargin;
56+Item {
57+ id: headerTitleContainer;
58+ anchors { right: parent.right; left: parent.left;
59+ top: parent.top;
60+ topMargin: units.gu(1);
61+ leftMargin: units.gu(1);
62+ }
63+ width: parent.width - x;
64+ implicitHeight: titleLabel.height + subtitleLabel.height;
65+ data: [
66+ Label {
67+ id: titleLabel;
68+ objectName: "titleLabel";
69+ anchors { right: emblemIcon.left;
70+ rightMargin: emblemIcon.width > 0 ? units.gu(0.5) : 0;
71+ left: parent.left;
72+ top: parent.top; }
73+ elide: Text.ElideRight;
74+ fontSize: "small";
75+ wrapMode: Text.Wrap;
76+ maximumLineCount: 2;
77+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
78+ 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");
79+ visible: showHeader ;
80+ width: undefined;
81+ text: root.title;
82+ font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal;
83+ horizontalAlignment: Text.AlignLeft;
84+ }
85+,Label {
86+ id: subtitleLabel;
87+ objectName: "subtitleLabel";
88+ anchors { right: parent.right;
89+ left: parent.left;
90+ rightMargin: units.gu(1);
91+ top: titleLabel.bottom;
92+ }
93+ anchors.topMargin: units.dp(2);
94+ elide: Text.ElideRight;
95+ maximumLineCount: 1;
96+ fontSize: "x-small";
97+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
98+ 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");
99+ visible: titleLabel.visible && titleLabel.text;
100+ text: cardData && cardData["subtitle"] || "";
101+ font.weight: Font.Light;
102+ }
103+,Icon {
104+ id: emblemIcon;
105+ objectName: "emblemIcon";
106+ anchors {
107+ bottom: titleLabel.baseline;
108+ right: parent.right;
109+ rightMargin: units.gu(1);
110+ }
111+ source: cardData && cardData["emblem"] || "";
112+ 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");
113+ height: source != "" ? titleLabel.font.pixelSize : 0;
114+ width: implicitWidth > 0 && implicitHeight > 0 ? (implicitWidth / implicitHeight * height) : implicitWidth;
115+ }
116+
117+ ]
118+ }
119+UbuntuShape {
120+ id: touchdown;
121+ objectName: "touchdown";
122+ anchors { fill: backgroundLoader }
123+ visible: root.artShapeStyle != "shadow" && root.artShapeStyle != "icon" && root.pressed;
124+ radius: "medium";
125+ borderSource: "radius_pressed.sci"
126+}
127+implicitHeight: headerTitleContainer.y + headerTitleContainer.height + units.gu(1);
128+}
tests/plugins/Dash/cardcreator/7.res+1−2
@@ -5,7 +5,6 @@ AbstractButton {
55 property string backgroundShapeStyle: "inset";
66 property real fontScale: 1.0;
77 property var scopeStyle: null;
8− property int titleAlignment: Text.AlignLeft;
98 property int fixedHeaderHeight: -1;
109 property size fixedArtShapeSize: Qt.size(-1, -1);
1110 readonly property string title: cardData && cardData["title"] || "";
@@ -103,7 +102,7 @@ CroppedImageMinimumSourceSize {
103102 width: undefined;
104103 text: root.title;
105104 font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal;
106− horizontalAlignment: root.titleAlignment;
105+ horizontalAlignment: Text.AlignLeft;
107106 }
108107,Label {
109108 id: subtitleLabel;
tests/plugins/Dash/cardcreator/7.res.cardcreatornew file+152
@@ -0,0 +1,152 @@
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 fixedHeaderHeight: -1;
9+ property size fixedArtShapeSize: Qt.size(-1, -1);
10+ readonly property string title: cardData && cardData["title"] || "";
11+ property bool asynchronous: true;
12+ property bool showHeader: true;
13+ implicitWidth: childrenRect.width;
14+ enabled: true;
15+
16+Loader {
17+ id: backgroundLoader;
18+ objectName: "backgroundLoader";
19+ anchors.fill: parent;
20+ asynchronous: root.asynchronous;
21+ visible: status == Loader.Ready;
22+ sourceComponent: UbuntuShape {
23+ objectName: "background";
24+ radius: "medium";
25+ aspect: {
26+ switch (root.backgroundShapeStyle) {
27+ case "inset": return UbuntuShape.Inset;
28+ case "shadow": return UbuntuShape.DropShadow;
29+ default:
30+ case "flat": return UbuntuShape.Flat;
31+ }
32+ }
33+ backgroundColor: getColor(0) || "white";
34+ secondaryBackgroundColor: getColor(1) || backgroundColor;
35+ backgroundMode: UbuntuShape.VerticalGradient;
36+ anchors.fill: parent;
37+ source: backgroundImage.source ? backgroundImage : null;
38+ property real luminance: Style.luminance(backgroundColor);
39+ property Image backgroundImage: Image {
40+ objectName: "backgroundImage";
41+ source: {
42+ if (cardData && typeof cardData["background"] === "string") return cardData["background"];
43+ else return "";
44+ }
45+ }
46+ function getColor(index) {
47+ if (cardData && typeof cardData["background"] === "object"
48+ && (cardData["background"]["type"] === "color" || cardData["background"]["type"] === "gradient")) {
49+ return cardData["background"]["elements"][index];
50+ } else return index === 0 ? "#E9E9E9" : "#E9AAE9";
51+ }
52+ }
53+ }
54+readonly property size artShapeSize: Qt.size(-1, -1);
55+readonly property int headerHeight: row.height;
56+Row {
57+ id: row;
58+ objectName: "outerRow";
59+ property real margins: units.gu(1);
60+ spacing: margins;
61+ height: root.fixedHeaderHeight != -1 ? root.fixedHeaderHeight : implicitHeight;
62+ anchors { top: parent.top;
63+ topMargin: units.gu(1);
64+ left: parent.left;
65+ }
66+ anchors.right: parent.right;
67+ anchors.margins: margins;
68+ anchors.rightMargin: 0;
69+ data: [
70+CroppedImageMinimumSourceSize {
71+ id: mascotImage;
72+ objectName: "mascotImage";
73+ anchors { verticalCenter: parent.verticalCenter; }
74+ source: cardData && cardData["mascot"] || "";
75+ width: units.gu(6);
76+ height: units.gu(5.625);
77+ horizontalAlignment: Image.AlignHCenter;
78+ verticalAlignment: Image.AlignVCenter;
79+ visible: showHeader;
80+ }
81+
82+,Item {
83+ id: headerTitleContainer;
84+ anchors { verticalCenter: parent.verticalCenter; }
85+ width: parent.width - x;
86+ implicitHeight: titleLabel.height + subtitleLabel.height + attributesRow.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: Text.AlignLeft;
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+,CardAttributes {
126+ id: attributesRow;
127+ objectName: "attributesRow";
128+ anchors { right: parent.right;
129+ left: parent.left;
130+ rightMargin: units.gu(1);
131+ top: subtitleLabel.bottom;
132+ }
133+ 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");
134+ fontScale: root.fontScale;
135+ model: cardData && cardData["attributes"];
136+ }
137+
138+ ]
139+ }
140+
141+ ]
142+ }
143+UbuntuShape {
144+ id: touchdown;
145+ objectName: "touchdown";
146+ anchors { fill: backgroundLoader }
147+ visible: root.artShapeStyle != "shadow" && root.artShapeStyle != "icon" && root.pressed;
148+ radius: "medium";
149+ borderSource: "radius_pressed.sci"
150+}
151+implicitHeight: row.y + row.height + units.gu(1);
152+}
tests/plugins/Dash/cardcreator/8.res+1−2
@@ -5,7 +5,6 @@ AbstractButton {
55 property string backgroundShapeStyle: "inset";
66 property real fontScale: 1.0;
77 property var scopeStyle: null;
8− property int titleAlignment: Text.AlignLeft;
98 property int fixedHeaderHeight: -1;
109 property size fixedArtShapeSize: Qt.size(-1, -1);
1110 readonly property string title: cardData && cardData["title"] || "";
@@ -94,7 +93,7 @@ left: parent.left;
9493 width: parent.width - x;
9594 text: root.title;
9695 font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal;
97− horizontalAlignment: root.titleAlignment;
96+ horizontalAlignment: Text.AlignLeft;
9897 }
9998
10099 ]
tests/plugins/Dash/cardcreator/8.res.cardcreatornew file+110
@@ -0,0 +1,110 @@
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 fixedHeaderHeight: -1;
9+ property size fixedArtShapeSize: Qt.size(-1, -1);
10+ readonly property string title: cardData && cardData["title"] || "";
11+ property bool asynchronous: true;
12+ property bool showHeader: true;
13+ implicitWidth: childrenRect.width;
14+ enabled: true;
15+
16+Loader {
17+ id: backgroundLoader;
18+ objectName: "backgroundLoader";
19+ anchors.fill: parent;
20+ asynchronous: root.asynchronous;
21+ visible: status == Loader.Ready;
22+ sourceComponent: UbuntuShape {
23+ objectName: "background";
24+ radius: "medium";
25+ aspect: {
26+ switch (root.backgroundShapeStyle) {
27+ case "inset": return UbuntuShape.Inset;
28+ case "shadow": return UbuntuShape.DropShadow;
29+ default:
30+ case "flat": return UbuntuShape.Flat;
31+ }
32+ }
33+ backgroundColor: getColor(0) || "white";
34+ secondaryBackgroundColor: getColor(1) || backgroundColor;
35+ backgroundMode: UbuntuShape.VerticalGradient;
36+ anchors.fill: parent;
37+ source: backgroundImage.source ? backgroundImage : null;
38+ property real luminance: Style.luminance(backgroundColor);
39+ property Image backgroundImage: Image {
40+ objectName: "backgroundImage";
41+ source: {
42+ if (cardData && typeof cardData["background"] === "string") return cardData["background"];
43+ else return "";
44+ }
45+ }
46+ function getColor(index) {
47+ if (cardData && typeof cardData["background"] === "object"
48+ && (cardData["background"]["type"] === "color" || cardData["background"]["type"] === "gradient")) {
49+ return cardData["background"]["elements"][index];
50+ } else return index === 0 ? "#E9E9E9" : "#E9AAE9";
51+ }
52+ }
53+ }
54+readonly property size artShapeSize: Qt.size(-1, -1);
55+readonly property int headerHeight: row.height;
56+Row {
57+ id: row;
58+ objectName: "outerRow";
59+ property real margins: units.gu(1);
60+ spacing: margins;
61+ height: root.fixedHeaderHeight != -1 ? root.fixedHeaderHeight : implicitHeight;
62+ anchors { top: parent.top;
63+ topMargin: units.gu(1);
64+left: parent.left;
65+ }
66+ anchors.right: parent.right;
67+ anchors.margins: margins;
68+ anchors.rightMargin: 0;
69+ data: [
70+ CroppedImageMinimumSourceSize {
71+ id: mascotImage;
72+ objectName: "mascotImage";
73+ anchors { verticalCenter: parent.verticalCenter; }
74+ source: cardData && cardData["mascot"] || "";
75+ width: units.gu(6);
76+ height: units.gu(5.625);
77+ horizontalAlignment: Image.AlignHCenter;
78+ verticalAlignment: Image.AlignVCenter;
79+ visible: showHeader;
80+ }
81+,Label {
82+ id: titleLabel;
83+ objectName: "titleLabel";
84+ anchors { verticalCenter: parent.verticalCenter;
85+ }
86+ elide: Text.ElideRight;
87+ fontSize: "small";
88+ wrapMode: Text.Wrap;
89+ maximumLineCount: 2;
90+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
91+ 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");
92+ visible: showHeader ;
93+ width: parent.width - x;
94+ text: root.title;
95+ font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal;
96+ horizontalAlignment: Text.AlignLeft;
97+ }
98+
99+ ]
100+ }
101+UbuntuShape {
102+ id: touchdown;
103+ objectName: "touchdown";
104+ anchors { fill: backgroundLoader }
105+ visible: root.artShapeStyle != "shadow" && root.artShapeStyle != "icon" && root.pressed;
106+ radius: "medium";
107+ borderSource: "radius_pressed.sci"
108+}
109+implicitHeight: row.y + row.height + units.gu(1);
110+}
tests/plugins/Dash/cardcreator/9.res+1−2
@@ -5,7 +5,6 @@ AbstractButton {
55 property string backgroundShapeStyle: "inset";
66 property real fontScale: 1.0;
77 property var scopeStyle: null;
8− property int titleAlignment: Text.AlignLeft;
98 property int fixedHeaderHeight: -1;
109 property size fixedArtShapeSize: Qt.size(-1, -1);
1110 readonly property string title: cardData && cardData["title"] || "";
@@ -36,7 +35,7 @@ top: parent.top;
3635 width: undefined;
3736 text: root.title;
3837 font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal;
39− horizontalAlignment: root.titleAlignment;
38+ horizontalAlignment: Text.AlignLeft;
4039 }
4140Label {
4241 id: subtitleLabel;
tests/plugins/Dash/cardcreator/9.res.cardcreatornew file+120
@@ -0,0 +1,120 @@
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 fixedHeaderHeight: -1;
9+ property size fixedArtShapeSize: Qt.size(-1, -1);
10+ readonly property string title: cardData && cardData["title"] || "";
11+ property bool asynchronous: true;
12+ property bool showHeader: true;
13+ implicitWidth: childrenRect.width;
14+ enabled: true;
15+
16+readonly property size artShapeSize: Qt.size(-1, -1);
17+readonly property int headerHeight: titleLabel.height + subtitleLabel.height + subtitleLabel.anchors.topMargin + audioProgressBar.height + audioProgressBar.anchors.topMargin;
18+Label {
19+ id: titleLabel;
20+ objectName: "titleLabel";
21+ anchors { right: parent.right;
22+rightMargin: units.gu(1);
23+left: audioButton.right;
24+ leftMargin: units.gu(1);
25+top: parent.top;
26+ topMargin: units.gu(1);
27+ }
28+ elide: Text.ElideRight;
29+ fontSize: "small";
30+ wrapMode: Text.Wrap;
31+ maximumLineCount: 2;
32+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
33+ color: root.scopeStyle ? root.scopeStyle.foreground : theme.palette.normal.baseText;
34+ visible: showHeader ;
35+ width: undefined;
36+ text: root.title;
37+ font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal;
38+ horizontalAlignment: Text.AlignLeft;
39+ }
40+Label {
41+ id: subtitleLabel;
42+ objectName: "subtitleLabel";
43+ anchors { left: titleLabel.left;
44+ leftMargin: titleLabel.leftMargin;
45+rightMargin: units.gu(1);
46+right: titleLabel.right;
47+top: titleLabel.bottom;
48+ }
49+ anchors.topMargin: units.dp(2);
50+ elide: Text.ElideRight;
51+ maximumLineCount: 1;
52+ fontSize: "x-small";
53+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
54+ color: root.scopeStyle ? root.scopeStyle.foreground : theme.palette.normal.baseText;
55+ visible: titleLabel.visible && titleLabel.text;
56+ text: cardData && cardData["subtitle"] || "";
57+ font.weight: Font.Light;
58+ }
59+CardAudioProgress {
60+ id: audioProgressBar;
61+ duration: (cardData["quickPreviewData"] && cardData["quickPreviewData"]["duration"]) || 0;
62+ source: (cardData["quickPreviewData"] && cardData["quickPreviewData"]["uri"]) || "";
63+ anchors {
64+ bottom: audioButton.bottom;
65+ left: audioButton.right;
66+ right: parent.right;
67+ margins: units.gu(1);
68+ }
69+ color: root.scopeStyle ? root.scopeStyle.foreground : theme.palette.normal.baseText;
70+ }AbstractButton {
71+ id: audioButton;
72+ anchors.fill: undefined;
73+ width: height;
74+ height: (root.fixedHeaderHeight > 0 ? root.fixedHeaderHeight : headerHeight) + 2 * units.gu(1);
75+ readonly property url source: (cardData["quickPreviewData"] && cardData["quickPreviewData"]["uri"]) || "";
76+ UbuntuShape {
77+ anchors.fill: parent;
78+ visible: parent.pressed;
79+ radius: "medium";
80+ }
81+ Rectangle {
82+ color: Qt.rgba(0, 0, 0, 0.5);
83+ anchors.centerIn: parent;
84+ width: parent.width * 0.5;
85+ height: width;
86+ radius: width / 2;
87+ }
88+ Icon {
89+ anchors.centerIn: parent;
90+ width: parent.width * 0.3;
91+ height: width;
92+ opacity: 0.9;
93+ name: DashAudioPlayer.playing && AudioUrlComparer.compare(parent.source, DashAudioPlayer.currentSource) ? "media-playback-pause" : "media-playback-start";
94+ color: "white";
95+ }
96+ onClicked: {
97+ if (AudioUrlComparer.compare(source, DashAudioPlayer.currentSource)) {
98+ if (DashAudioPlayer.playing) {
99+ DashAudioPlayer.pause();
100+ } else {
101+ DashAudioPlayer.play();
102+ }
103+ } else {
104+ var playlist = (cardData["quickPreviewData"] && cardData["quickPreviewData"]["playlist"]) || null;
105+ DashAudioPlayer.playSource(source, playlist);
106+ }
107+ }
108+ onPressAndHold: {
109+ root.pressAndHold();
110+ }
111+ }UbuntuShape {
112+ id: touchdown;
113+ objectName: "touchdown";
114+ anchors { fill: root }
115+ visible: root.artShapeStyle != "shadow" && root.artShapeStyle != "icon" && root.pressed;
116+ radius: "medium";
117+ borderSource: "radius_pressed.sci"
118+ }
119+implicitHeight: audioButton.height;
120+}
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}