on 62fce76 help sign in
unity8/plugins/Dash/CardCreator.js
602 lines 31 kB history raw
1/*
2 * Copyright (C) 2014 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17.pragma library
19var kBackgroundLoaderCode = 'Loader {\n\
20 id: backgroundLoader; \n\
21 objectName: "backgroundLoader"; \n\
22 anchors.fill: parent; \n\
23 asynchronous: root.asynchronous; \n\
24 visible: status == Loader.Ready; \n\
25 sourceComponent: UbuntuShape { \n\
26 objectName: "background"; \n\
27 radius: "medium"; \n\
28 color: getColor(0) || "white"; \n\
29 gradientColor: getColor(1) || color; \n\
30 anchors.fill: parent; \n\
31 image: backgroundImage.source ? backgroundImage : null; \n\
32 property real luminance: 0.2126 * color.r + 0.7152 * color.g + 0.0722 * color.b; \n\
33 property Image backgroundImage: Image { \n\
34 objectName: "backgroundImage"; \n\
35 source: { \n\
36 if (cardData && typeof cardData["background"] === "string") return cardData["background"]; \n\
37 else if (template && typeof template["card-background"] === "string") return template["card-background"]; \n\
38 else return ""; \n\
39 } \n\
40 } \n\
41 function getColor(index) { \n\
42 if (cardData && typeof cardData["background"] === "object" \n\
43 && (cardData["background"]["type"] === "color" || cardData["background"]["type"] === "gradient")) { \n\
44 return cardData["background"]["elements"][index]; \n\
45 } else if (template && typeof template["card-background"] === "object" \n\
46 && (template["card-background"]["type"] === "color" || template["card-background"]["type"] === "gradient")) { \n\
47 return template["card-background"]["elements"][index]; \n\
48 } else return undefined; \n\
49 } \n\
50 } \n\
51 }\n';
53// %1 is used as anchors of artShapeHolder
54// %2 is used as image width
55// %3 is used as image height
56var kArtShapeHolderCode = 'Item { \n\
57 id: artShapeHolder; \n\
58 height: root.fixedArtShapeSize.height > 0 ? root.fixedArtShapeSize.height : artShapeLoader.height; \n\
59 width: root.fixedArtShapeSize.width > 0 ? root.fixedArtShapeSize.width : artShapeLoader.width; \n\
60 anchors { %1 } \n\
61 Loader { \n\
62 id: artShapeLoader; \n\
63 objectName: "artShapeLoader"; \n\
64 active: cardData && cardData["art"] || false; \n\
65 asynchronous: root.asynchronous; \n\
66 visible: status == Loader.Ready; \n\
67 sourceComponent: UbuntuShape { \n\
68 id: artShape; \n\
69 objectName: "artShape"; \n\
70 radius: "medium"; \n\
71 visible: image.status == Image.Ready; \n\
72 readonly property real fixedArtShapeSizeAspect: (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) ? root.fixedArtShapeSize.width / root.fixedArtShapeSize.height : -1; \n\
73 readonly property real aspect: fixedArtShapeSizeAspect > 0 ? fixedArtShapeSizeAspect : components !== undefined ? components["art"]["aspect-ratio"] : 1; \n\
74 readonly property bool aspectSmallerThanImageAspect: aspect < image.aspect; \n\
75 Component.onCompleted: { updateWidthHeightBindings(); if (artShapeBorderSource !== undefined) borderSource = artShapeBorderSource; } \n\
76 onAspectSmallerThanImageAspectChanged: updateWidthHeightBindings(); \n\
77 Connections { target: root; onFixedArtShapeSizeChanged: updateWidthHeightBindings(); } \n\
78 function updateWidthHeightBindings() { \n\
79 if (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) { \n\
80 width = root.fixedArtShapeSize.width; \n\
81 height = root.fixedArtShapeSize.height; \n\
82 } else if (aspectSmallerThanImageAspect) { \n\
83 width = Qt.binding(function() { return !visible ? 0 : image.width }); \n\
84 height = Qt.binding(function() { return !visible ? 0 : image.fillMode === Image.PreserveAspectCrop ? image.height : width / image.aspect }); \n\
85 } else { \n\
86 width = Qt.binding(function() { return !visible ? 0 : image.fillMode === Image.PreserveAspectCrop ? image.width : height * image.aspect }); \n\
87 height = Qt.binding(function() { return !visible ? 0 : image.height }); \n\
88 } \n\
89 } \n\
90 image: Image { \n\
91 objectName: "artImage"; \n\
92 source: cardData && cardData["art"] || ""; \n\
93 cache: true; \n\
94 asynchronous: root.asynchronous; \n\
95 fillMode: components && components["art"]["fill-mode"] === "fit" ? Image.PreserveAspectFit: Image.PreserveAspectCrop; \n\
96 readonly property real aspect: implicitWidth / implicitHeight; \n\
97 width: %2; \n\
98 height: %3; \n\
99 } \n\
100 } \n\
101 } \n\
102 }\n';
104var kOverlayLoaderCode = 'Loader { \n\
105 id: overlayLoader; \n\
106 anchors { \n\
107 left: artShapeHolder.left; \n\
108 right: artShapeHolder.right; \n\
109 bottom: artShapeHolder.bottom; \n\
110 } \n\
111 active: artShapeLoader.active && artShapeLoader.item && artShapeLoader.item.image.status === Image.Ready || false; \n\
112 asynchronous: root.asynchronous; \n\
113 visible: showHeader && status == Loader.Ready; \n\
114 sourceComponent: ShaderEffect { \n\
115 id: overlay; \n\
116 height: (fixedHeaderHeight > 0 ? fixedHeaderHeight : headerHeight) + units.gu(2); \n\
117 opacity: 0.6; \n\
118 property var source: ShaderEffectSource { \n\
119 id: shaderSource; \n\
120 sourceItem: artShapeLoader.item; \n\
121 onVisibleChanged: if (visible) scheduleUpdate(); \n\
122 live: false; \n\
123 sourceRect: Qt.rect(0, artShapeLoader.height - overlay.height, artShapeLoader.width, overlay.height); \n\
124 } \n\
125 vertexShader: " \n\
126 uniform highp mat4 qt_Matrix; \n\
127 attribute highp vec4 qt_Vertex; \n\
128 attribute highp vec2 qt_MultiTexCoord0; \n\
129 varying highp vec2 coord; \n\
130 void main() { \n\
131 coord = qt_MultiTexCoord0; \n\
132 gl_Position = qt_Matrix * qt_Vertex; \n\
133 }"; \n\
134 fragmentShader: " \n\
135 varying highp vec2 coord; \n\
136 uniform sampler2D source; \n\
137 uniform lowp float qt_Opacity; \n\
138 void main() { \n\
139 lowp vec4 tex = texture2D(source, coord); \n\
140 gl_FragColor = vec4(0, 0, 0, tex.a) * qt_Opacity; \n\
141 }"; \n\
142 } \n\
143 }\n';
145// %1 is used as anchors of row
146// %2 is used as first child of the row
147// %3 is used as second child of the row
148var kHeaderRow2Code = 'Row { \n\
149 id: row; \n\
150 objectName: "outerRow"; \n\
151 property real margins: units.gu(1); \n\
152 spacing: margins; \n\
153 height: root.fixedHeaderHeight != -1 ? root.fixedHeaderHeight : implicitHeight; \n\
154 anchors { %1 } \n\
155 anchors.right: parent.right; \n\
156 anchors.margins: margins;\n\
157 data: [ %2\n\
158 ,\n\
159 %3 \n\
160 ] \n\
161 }\n';
163// %1 is used as anchors of row
164// %2 is used as first child of the row
165// %3 is used as second child of the row
166// %4 is used as third child of the row
167var kHeaderRow3Code = 'Row { \n\
168 id: row; \n\
169 objectName: "outerRow"; \n\
170 property real margins: units.gu(1); \n\
171 spacing: margins; \n\
172 height: root.fixedHeaderHeight != -1 ? root.fixedHeaderHeight : implicitHeight; \n\
173 anchors { %1 } \n\
174 anchors.right: parent.right; \n\
175 anchors.margins: margins;\n\
176 data: [ %2\n\
177 ,\n\
178 %3 \n\
179 ,\n\
180 %4 \n\
181 ] \n\
182 }\n';
184// %1 is used as first child of the column
185// %2 is used as second child of the column
186var kHeaderColumnCode = 'Column { \n\
187 anchors.verticalCenter: parent.verticalCenter; \n\
188 spacing: units.dp(2); \n\
189 width: parent.width - x;\n\
190 data: [ %1\n\
191 ,\n\
192 %2 \n\
193 ] \n\
194 }\n';
196// multiple column version of kHeaderColumnCode.
197function kHeaderColumnCodeGenerator() {
198 var headerColumnCodeTemplate = 'Column { \n\
199 anchors.verticalCenter: parent.verticalCenter; \n\
200 spacing: units.dp(2); \n\
201 width: parent.width - x;\n\
202 data: [ \n\
203 %1 \n\
204 ]\n\
205 }\n';
206 var args = Array.prototype.slice.call(arguments);
207 var code = headerColumnCodeTemplate.arg(args.join(',\n'));
208 return code;
211// %1 is used as anchors of mascotShapeLoader
212var kMascotShapeLoaderCode = 'Loader { \n\
213 id: mascotShapeLoader; \n\
214 objectName: "mascotShapeLoader"; \n\
215 asynchronous: root.asynchronous; \n\
216 active: mascotImage.status === Image.Ready; \n\
217 visible: showHeader && active && status == Loader.Ready; \n\
218 width: units.gu(6); \n\
219 height: units.gu(5.625); \n\
220 sourceComponent: UbuntuShape { image: mascotImage } \n\
221 anchors { %1 } \n\
222 }\n';
224// %1 is used as anchors of mascotImage
225// %2 is used as visible of mascotImage
226var kMascotImageCode = 'Image { \n\
227 id: mascotImage; \n\
228 objectName: "mascotImage"; \n\
229 anchors { %1 } \n\
230 readonly property int maxSize: Math.max(width, height) * 4; \n\
231 source: cardData && cardData["mascot"]; \n\
232 width: units.gu(6); \n\
233 height: units.gu(5.625); \n\
234 sourceSize { width: maxSize; height: maxSize } \n\
235 fillMode: Image.PreserveAspectCrop; \n\
236 horizontalAlignment: Image.AlignHCenter; \n\
237 verticalAlignment: Image.AlignVCenter; \n\
238 visible: %2; \n\
239 }\n';
241// %1 is used as anchors of titleLabel
242// %2 is used as color of titleLabel
243// %3 is used as extra condition for visible of titleLabel
244var kTitleLabelCode = 'Label { \n\
245 id: titleLabel; \n\
246 objectName: "titleLabel"; \n\
247 anchors { %1 } \n\
248 elide: Text.ElideRight; \n\
249 fontSize: "small"; \n\
250 wrapMode: Text.Wrap; \n\
251 maximumLineCount: 2; \n\
252 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale); \n\
253 color: %2; \n\
254 visible: showHeader %3; \n\
255 text: root.title; \n\
256 font.weight: components && components["subtitle"] ? Font.DemiBold : Font.Normal; \n\
257 horizontalAlignment: root.headerAlignment; \n\
258 }\n';
260// %1 is used as anchors of subtitleLabel
261// %2 is used as color of subtitleLabel
262var kSubtitleLabelCode = 'Label { \n\
263 id: subtitleLabel; \n\
264 objectName: "subtitleLabel"; \n\
265 anchors { %1 } \n\
266 elide: Text.ElideRight; \n\
267 fontSize: "small"; \n\
268 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale); \n\
269 color: %2; \n\
270 visible: titleLabel.visible && titleLabel.text; \n\
271 text: cardData && cardData["subtitle"] || ""; \n\
272 font.weight: Font.Light; \n\
273 horizontalAlignment: root.headerAlignment; \n\
274 }\n';
276// %1 is used as anchors of attributesRow
277var kAttributesRowCode = 'CardAttributes { \n\
278 id: attributesRow; \n\
279 objectName: "attributesRow"; \n\
280 anchors { %1 } \n\
281 color: %2; \n\
282 model: cardData && cardData["attributes"] || undefined; \n\
283 }\n';
285// %1 is used as top anchor of summary
286// %2 is used as topMargin anchor of summary
287// %3 is used as color of summary
288var kSummaryLabelCode = 'Label { \n\
289 id: summary; \n\
290 objectName: "summaryLabel"; \n\
291 anchors { \n\
292 top: %1; \n\
293 left: parent.left; \n\
294 right: parent.right; \n\
295 margins: units.gu(1); \n\
296 topMargin: %2; \n\
297 } \n\
298 wrapMode: Text.Wrap; \n\
299 maximumLineCount: 5; \n\
300 elide: Text.ElideRight; \n\
301 text: cardData && cardData["summary"] || ""; \n\
302 height: text ? implicitHeight : 0; \n\
303 fontSize: "small"; \n\
304 color: %3; \n\
305 }\n';
307function cardString(template, components) {
308 var code;
309 code = 'AbstractButton { \n\
310 id: root; \n\
311 property var template; \n\
312 property var components; \n\
313 property var cardData; \n\
314 property var artShapeBorderSource: undefined; \n\
315 property real fontScale: 1.0; \n\
316 property var scopeStyle: null; \n\
317 property int headerAlignment: Text.AlignLeft; \n\
318 property int fixedHeaderHeight: -1; \n\
319 property size fixedArtShapeSize: Qt.size(-1, -1); \n\
320 readonly property string title: cardData && cardData["title"] || ""; \n\
321 property bool asynchronous: true; \n\
322 property bool showHeader: true; \n\
323 implicitWidth: childrenRect.width; \n';
325 var hasArt = components["art"] && components["art"]["field"] || false;
326 var hasSummary = components["summary"] || false;
327 var artAndSummary = hasArt && hasSummary;
328 var isHorizontal = template["card-layout"] === "horizontal";
329 var hasBackground = !isHorizontal && (template["card-background"] || components["background"] || artAndSummary);
330 var hasTitle = components["title"] || false;
331 var hasMascot = components["mascot"] || false;
332 var headerAsOverlay = hasArt && template && template["overlay"] === true && (hasTitle || hasMascot);
333 var hasSubtitle = hasTitle && components["subtitle"] || false;
334 var hasHeaderRow = hasMascot && hasTitle;
335 var hasAttributes = hasTitle && components["attributes"] || false;
337 if (hasBackground) {
338 code += kBackgroundLoaderCode;
339 }
341 if (hasArt) {
342 code += 'onArtShapeBorderSourceChanged: { if (artShapeBorderSource !== undefined && artShapeLoader.item) artShapeLoader.item.borderSource = artShapeBorderSource; } \n';
343 code += 'readonly property size artShapeSize: artShapeLoader.item ? Qt.size(artShapeLoader.item.width, artShapeLoader.item.height) : Qt.size(-1, -1);\n';
345 var widthCode, heightCode;
346 var anchors;
347 if (isHorizontal) {
348 anchors = 'left: parent.left';
349 if (hasMascot || hasTitle) {
350 widthCode = 'height * artShape.aspect'
351 heightCode = 'headerHeight + 2 * units.gu(1)';
352 } else {
353 // This side of the else is a bit silly, who wants an horizontal layout without mascot and title?
354 // So we define a "random" height of the image height + 2 gu for the margins
355 widthCode = 'height * artShape.aspect'
356 heightCode = 'units.gu(7.625)';
357 }
358 } else {
359 anchors = 'horizontalCenter: parent.horizontalCenter;';
360 widthCode = 'root.width'
361 heightCode = 'width / artShape.aspect';
362 }
364 code += kArtShapeHolderCode.arg(anchors).arg(widthCode).arg(heightCode);
365 } else {
366 code += 'readonly property size artShapeSize: Qt.size(-1, -1);\n'
367 }
369 if (headerAsOverlay) {
370 code += kOverlayLoaderCode;
371 }
373 var headerVerticalAnchors;
374 if (headerAsOverlay) {
375 headerVerticalAnchors = 'bottom: artShapeHolder.bottom; \n\
376 bottomMargin: units.gu(1);\n';
377 } else {
378 if (hasArt) {
379 if (isHorizontal) {
380 headerVerticalAnchors = 'top: artShapeHolder.top; \n\
381 topMargin: units.gu(1);\n';
382 } else {
383 headerVerticalAnchors = 'top: artShapeHolder.bottom; \n\
384 topMargin: units.gu(1);\n';
385 }
386 } else {
387 headerVerticalAnchors = 'top: parent.top; \n\
388 topMargin: units.gu(1);\n';
389 }
390 }
391 var headerLeftAnchor;
392 var headerLeftAnchorHasMargin = false;
393 if (isHorizontal && hasArt) {
394 headerLeftAnchor = 'left: artShapeHolder.right; \n\
395 leftMargin: units.gu(1);\n';
396 headerLeftAnchorHasMargin = true;
397 } else {
398 headerLeftAnchor = 'left: parent.left;\n';
399 }
401 if (hasHeaderRow) {
402 code += 'readonly property int headerHeight: row.height;\n'
403 } else if (hasMascot) {
404 code += 'readonly property int headerHeight: mascotImage.height;\n'
405 } else if (hasAttributes) {
406 if (hasTitle && hasSubtitle) {
407 code += 'readonly property int headerHeight: titleLabel.height + subtitleLabel.height + subtitleLabel.anchors.topMargin + attributesRow.height + attributesRow.anchors.topMargin;\n'
408 } else if (hasTitle) {
409 code += 'readonly property int headerHeight: titleLabel.height + attributesRow.height + attributesRow.anchors.topMargin;\n'
410 } else {
411 code += 'readonly property int headerHeight: attributesRow.height;\n'
412 }
413 } else if (hasSubtitle) {
414 code += 'readonly property int headerHeight: titleLabel.height + subtitleLabel.height + subtitleLabel.anchors.topMargin;\n'
415 } else if (hasTitle) {
416 code += 'readonly property int headerHeight: titleLabel.height;\n'
417 } else {
418 code += 'readonly property int headerHeight: 0;\n'
419 }
421 var mascotShapeCode = "";
422 var mascotCode = "";
423 if (hasMascot) {
424 var useMascotShape = !hasBackground && !headerAsOverlay;
425 var anchors = "";
426 if (!hasHeaderRow) {
427 anchors += headerLeftAnchor;
428 anchors += headerVerticalAnchors;
429 if (!headerLeftAnchorHasMargin) {
430 anchors += 'leftMargin: units.gu(1);\n'
431 }
432 } else {
433 anchors = "verticalCenter: parent.verticalCenter;"
434 }
436 if (useMascotShape) {
437 mascotShapeCode = kMascotShapeLoaderCode.arg(anchors);
438 }
440 var mascotImageVisible = useMascotShape ? 'false' : 'showHeader';
441 mascotCode = kMascotImageCode.arg(anchors).arg(mascotImageVisible);
442 }
444 var summaryColorWithBackground = 'backgroundLoader.active && backgroundLoader.item && backgroundLoader.item.luminance < 0.7 ? "white" : (root.scopeStyle ? root.scopeStyle.foreground : "grey")';
446 var titleSubtitleCode = "";
447 if (hasTitle) {
448 var color;
449 if (headerAsOverlay) {
450 color = '"white"';
451 } else if (hasSummary) {
452 color = 'summary.color';
453 } else if (hasBackground) {
454 color = summaryColorWithBackground;
455 } else {
456 color = 'root.scopeStyle ? root.scopeStyle.foreground : "grey"';
457 }
459 var titleAnchors;
460 var subtitleAnchors;
461 var attributesAnchors;
462 if (hasMascot && (hasSubtitle || hasAttributes)) {
463 // Using row + column
464 titleAnchors = 'left: parent.left; right: parent.right';
465 subtitleAnchors = titleAnchors;
466 attributesAnchors = subtitleAnchors;
467 } else if (hasMascot) {
468 // Using row + label
469 titleAnchors = 'verticalCenter: parent.verticalCenter;\n'
470 } else {
471 if (headerAsOverlay) {
472 // Using anchors to the overlay
473 titleAnchors = 'left: parent.left; \n\
474 leftMargin: units.gu(1); \n\
475 right: parent.right; \n\
476 rightMargin: units.gu(1); \n\
477 top: overlayLoader.top; \n\
478 topMargin: units.gu(1);\n';
479 } else {
480 // Using anchors to the mascot/parent
481 titleAnchors = "right: parent.right;\n";
482 titleAnchors += "rightMargin: units.gu(1);\n";
483 titleAnchors += headerLeftAnchor;
484 titleAnchors += headerVerticalAnchors;
485 if (!headerLeftAnchorHasMargin) {
486 titleAnchors += 'leftMargin: units.gu(1);\n'
487 }
488 }
489 subtitleAnchors = 'left: titleLabel.left; \n\
490 leftMargin: titleLabel.leftMargin; \n\
491 right: titleLabel.right; \n\
492 rightMargin: titleLabel.rightMargin; \n\
493 top: titleLabel.bottom; \n\
494 topMargin: units.dp(2);\n';
495 if (hasSubtitle) {
496 attributesAnchors = 'left: subtitleLabel.left; \n\
497 leftMargin: subtitleLabel.leftMargin; \n\
498 right: subtitleLabel.right; \n\
499 rightMargin: subtitleLabel.rightMargin; \n\
500 top: subtitleLabel.bottom; \n\
501 topMargin: units.dp(2);\n';
502 } else {
503 attributesAnchors = subtitleAnchors;
504 }
505 }
507 var titleLabelVisibleExtra = (headerAsOverlay ? '&& overlayLoader.active': '');
508 var titleCode = kTitleLabelCode.arg(titleAnchors).arg(color).arg(titleLabelVisibleExtra);
509 var subtitleCode = "";
510 if (hasSubtitle) {
511 subtitleCode += kSubtitleLabelCode.arg(subtitleAnchors).arg(color);
512 }
514 if (hasMascot && (hasSubtitle || hasAttributes)) {
515 // If using row + column wrap the code in the column
516 titleSubtitleCode = kHeaderColumnCode.arg(titleCode).arg(subtitleCode);
517 if (hasSubtitle && hasAttributes) {
518 var attributesCode = kAttributesRowCode.arg(attributesAnchors).arg(color);
519 titleSubtitleCode = kHeaderColumnCodeGenerator(titleCode, subtitleCode, attributesCode);
520 } else if (hasSubtitle) {
521 titleSubtitleCode = kHeaderColumnCode.arg(titleCode).arg(subtitleCode);
522 } else if (hasAttributes) {
523 var attributesCode = kAttributesRowCode.arg(attributesAnchors).arg(color);
524 titleSubtitleCode = kHeaderColumnCode.arg(titleCode).arg(attributesCode);
525 }
526 } else {
527 titleSubtitleCode = titleCode;
528 if (hasSubtitle) {
529 titleSubtitleCode = titleSubtitleCode + subtitleCode;
530 }
531 if (hasAttributes) {
532 var attributesCode = kAttributesRowCode.arg(attributesAnchors).arg(color);
533 titleSubtitleCode = titleSubtitleCode + attributesCode;
534 }
535 }
536 }
538 if (hasHeaderRow) {
539 if (mascotShapeCode != "") {
540 code += kHeaderRow3Code.arg(headerVerticalAnchors + headerLeftAnchor).arg(mascotShapeCode).arg(mascotCode).arg(titleSubtitleCode);
541 } else {
542 code += kHeaderRow2Code.arg(headerVerticalAnchors + headerLeftAnchor).arg(mascotCode).arg(titleSubtitleCode);
543 }
544 } else {
545 code += mascotShapeCode + mascotCode + titleSubtitleCode;
546 }
548 if (hasSummary) {
549 var summaryTopAnchor;
550 if (isHorizontal && hasArt) summaryTopAnchor = "artShapeHolder.bottom";
551 else if (headerAsOverlay && hasArt) summaryTopAnchor = "artShapeHolder.bottom";
552 else if (hasHeaderRow) summaryTopAnchor = "row.bottom";
553 else if (hasMascot) summaryTopAnchor = "mascotImage.bottom";
554 else if (hasAttributes) summaryTopAnchor = "attributesRow.bottom";
555 else if (hasSubtitle) summaryTopAnchor = "subtitleLabel.bottom";
556 else if (hasTitle) summaryTopAnchor = "titleLabel.bottom";
557 else if (hasArt) summaryTopAnchor = "artShapeHolder.bottom";
558 else summaryTopAnchor = "parent.top";
560 var color;
561 if (hasBackground) {
562 color = summaryColorWithBackground;
563 } else {
564 color = 'root.scopeStyle ? root.scopeStyle.foreground : "grey"';
565 }
567 var summaryTopMargin = (hasMascot || hasSubtitle || hasAttributes ? 'anchors.margins' : '0');
569 code += kSummaryLabelCode.arg(summaryTopAnchor).arg(summaryTopMargin).arg(color);
570 }
572 if (hasSummary) {
573 code += 'implicitHeight: summary.y + summary.height + (summary.text ? units.gu(1) : 0);\n';
574 } else if (hasHeaderRow) {
575 code += 'implicitHeight: row.y + row.height + units.gu(1);\n';
576 } else if (hasMascot) {
577 code += 'implicitHeight: mascotImage.y + mascotImage.height;\n';
578 } else if (hasAttributes) {
579 code += 'implicitHeight: attributesRow.y + attributesRow.height + units.gu(1);\n';
580 } else if (hasSubtitle) {
581 code += 'implicitHeight: subtitleLabel.y + subtitleLabel.height + units.gu(1);\n';
582 } else if (hasTitle) {
583 code += 'implicitHeight: titleLabel.y + titleLabel.height + units.gu(1);\n';
584 } else if (hasArt) {
585 code += 'implicitHeight: artShapeHolder.height;\n';
586 }
587 // Close the AbstractButton
588 code += '}\n';
590 return code;
593function createCardComponent(parent, template, components) {
594 var imports = 'import QtQuick 2.2; \n\
595 import Ubuntu.Components 0.1; \n\
596 import Ubuntu.Thumbnailer 0.1;\n\
597 import Dash 0.1;\n';
598 var card = cardString(template, components);
599 var code = imports + 'Component {\n' + card + '}\n';
601 return Qt.createQmlObject(code, parent, "createCardComponent");