on e3cbeff help sign in
unity8/plugins/Dash/CardCreator.js
596 lines 30 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 Component.onCompleted: { updateWidthHeightBindings(); if (artShapeBorderSource !== undefined) borderSource = artShapeBorderSource; } \n\
75 Connections { target: root; onFixedArtShapeSizeChanged: updateWidthHeightBindings(); } \n\
76 function updateWidthHeightBindings() { \n\
77 if (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) { \n\
78 width = root.fixedArtShapeSize.width; \n\
79 height = root.fixedArtShapeSize.height; \n\
80 } else { \n\
81 width = Qt.binding(function() { return !visible ? 0 : image.width }); \n\
82 height = Qt.binding(function() { return !visible ? 0 : image.height }); \n\
83 } \n\
84 } \n\
85 image: Image { \n\
86 objectName: "artImage"; \n\
87 source: cardData && cardData["art"] || ""; \n\
88 cache: true; \n\
89 asynchronous: root.asynchronous; \n\
90 fillMode: Image.PreserveAspectCrop; \n\
91 width: %2; \n\
92 height: %3; \n\
93 } \n\
94 } \n\
95 } \n\
96 }\n';
98var kOverlayLoaderCode = 'Loader { \n\
99 id: overlayLoader; \n\
100 anchors { \n\
101 left: artShapeHolder.left; \n\
102 right: artShapeHolder.right; \n\
103 bottom: artShapeHolder.bottom; \n\
104 } \n\
105 active: artShapeLoader.active && artShapeLoader.item && artShapeLoader.item.image.status === Image.Ready || false; \n\
106 asynchronous: root.asynchronous; \n\
107 visible: showHeader && status == Loader.Ready; \n\
108 sourceComponent: ShaderEffect { \n\
109 id: overlay; \n\
110 height: (fixedHeaderHeight > 0 ? fixedHeaderHeight : headerHeight) + units.gu(2); \n\
111 opacity: 0.6; \n\
112 property var source: ShaderEffectSource { \n\
113 id: shaderSource; \n\
114 sourceItem: artShapeLoader.item; \n\
115 onVisibleChanged: if (visible) scheduleUpdate(); \n\
116 live: false; \n\
117 sourceRect: Qt.rect(0, artShapeLoader.height - overlay.height, artShapeLoader.width, overlay.height); \n\
118 } \n\
119 vertexShader: " \n\
120 uniform highp mat4 qt_Matrix; \n\
121 attribute highp vec4 qt_Vertex; \n\
122 attribute highp vec2 qt_MultiTexCoord0; \n\
123 varying highp vec2 coord; \n\
124 void main() { \n\
125 coord = qt_MultiTexCoord0; \n\
126 gl_Position = qt_Matrix * qt_Vertex; \n\
127 }"; \n\
128 fragmentShader: " \n\
129 varying highp vec2 coord; \n\
130 uniform sampler2D source; \n\
131 uniform lowp float qt_Opacity; \n\
132 void main() { \n\
133 lowp vec4 tex = texture2D(source, coord); \n\
134 gl_FragColor = vec4(0, 0, 0, tex.a) * qt_Opacity; \n\
135 }"; \n\
136 } \n\
137 }\n';
139// %1 is used as anchors of row
140// %2 is used as first child of the row
141// %3 is used as second child of the row
142var kHeaderRow2Code = 'Row { \n\
143 id: row; \n\
144 objectName: "outerRow"; \n\
145 property real margins: units.gu(1); \n\
146 spacing: margins; \n\
147 height: root.fixedHeaderHeight != -1 ? root.fixedHeaderHeight : implicitHeight; \n\
148 anchors { %1 } \n\
149 anchors.right: parent.right; \n\
150 anchors.margins: margins;\n\
151 data: [ %2\n\
152 ,\n\
153 %3 \n\
154 ] \n\
155 }\n';
157// %1 is used as anchors of row
158// %2 is used as first child of the row
159// %3 is used as second child of the row
160// %4 is used as third child of the row
161var kHeaderRow3Code = 'Row { \n\
162 id: row; \n\
163 objectName: "outerRow"; \n\
164 property real margins: units.gu(1); \n\
165 spacing: margins; \n\
166 height: root.fixedHeaderHeight != -1 ? root.fixedHeaderHeight : implicitHeight; \n\
167 anchors { %1 } \n\
168 anchors.right: parent.right; \n\
169 anchors.margins: margins;\n\
170 data: [ %2\n\
171 ,\n\
172 %3 \n\
173 ,\n\
174 %4 \n\
175 ] \n\
176 }\n';
178// %1 is used as first child of the column
179// %2 is used as second child of the column
180var kHeaderColumnCode = 'Column { \n\
181 anchors.verticalCenter: parent.verticalCenter; \n\
182 spacing: units.dp(2); \n\
183 width: parent.width - x;\n\
184 data: [ %1\n\
185 ,\n\
186 %2 \n\
187 ] \n\
188 }\n';
190// multiple column version of kHeaderColumnCode.
191function kHeaderColumnCodeGenerator() {
192 var headerColumnCodeTemplate = 'Column { \n\
193 anchors.verticalCenter: parent.verticalCenter; \n\
194 spacing: units.dp(2); \n\
195 width: parent.width - x;\n\
196 data: [ \n\
197 %1 \n\
198 ]\n\
199 }\n';
200 var args = Array.prototype.slice.call(arguments);
201 var code = headerColumnCodeTemplate.arg(args.join(',\n'));
202 return code;
205// %1 is used as anchors of mascotShapeLoader
206var kMascotShapeLoaderCode = 'Loader { \n\
207 id: mascotShapeLoader; \n\
208 objectName: "mascotShapeLoader"; \n\
209 asynchronous: root.asynchronous; \n\
210 active: mascotImage.status === Image.Ready; \n\
211 visible: showHeader && active && status == Loader.Ready; \n\
212 width: units.gu(6); \n\
213 height: units.gu(5.625); \n\
214 sourceComponent: UbuntuShape { image: mascotImage } \n\
215 anchors { %1 } \n\
216 }\n';
218// %1 is used as anchors of mascotImage
219// %2 is used as visible of mascotImage
220var kMascotImageCode = 'Image { \n\
221 id: mascotImage; \n\
222 objectName: "mascotImage"; \n\
223 anchors { %1 } \n\
224 readonly property int maxSize: Math.max(width, height) * 4; \n\
225 source: cardData && cardData["mascot"]; \n\
226 width: units.gu(6); \n\
227 height: units.gu(5.625); \n\
228 sourceSize { width: maxSize; height: maxSize } \n\
229 fillMode: Image.PreserveAspectCrop; \n\
230 horizontalAlignment: Image.AlignHCenter; \n\
231 verticalAlignment: Image.AlignVCenter; \n\
232 visible: %2; \n\
233 }\n';
235// %1 is used as anchors of titleLabel
236// %2 is used as color of titleLabel
237// %3 is used as extra condition for visible of titleLabel
238var kTitleLabelCode = 'Label { \n\
239 id: titleLabel; \n\
240 objectName: "titleLabel"; \n\
241 anchors { %1 } \n\
242 elide: Text.ElideRight; \n\
243 fontSize: "small"; \n\
244 wrapMode: Text.Wrap; \n\
245 maximumLineCount: 2; \n\
246 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale); \n\
247 color: %2; \n\
248 visible: showHeader %3; \n\
249 text: root.title; \n\
250 font.weight: components && components["subtitle"] ? Font.DemiBold : Font.Normal; \n\
251 horizontalAlignment: root.headerAlignment; \n\
252 }\n';
254// %1 is used as anchors of subtitleLabel
255// %2 is used as color of subtitleLabel
256var kSubtitleLabelCode = 'Label { \n\
257 id: subtitleLabel; \n\
258 objectName: "subtitleLabel"; \n\
259 anchors { %1 } \n\
260 elide: Text.ElideRight; \n\
261 fontSize: "small"; \n\
262 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale); \n\
263 color: %2; \n\
264 visible: titleLabel.visible && titleLabel.text; \n\
265 text: cardData && cardData["subtitle"] || ""; \n\
266 font.weight: Font.Light; \n\
267 horizontalAlignment: root.headerAlignment; \n\
268 }\n';
270// %1 is used as anchors of attributesRow
271var kAttributesRowCode = 'CardAttributes { \n\
272 id: attributesRow; \n\
273 objectName: "attributesRow"; \n\
274 anchors { %1 } \n\
275 color: %2; \n\
276 model: cardData && cardData["attributes"] || undefined; \n\
277 }\n';
279// %1 is used as top anchor of summary
280// %2 is used as topMargin anchor of summary
281// %3 is used as color of summary
282var kSummaryLabelCode = 'Label { \n\
283 id: summary; \n\
284 objectName: "summaryLabel"; \n\
285 anchors { \n\
286 top: %1; \n\
287 left: parent.left; \n\
288 right: parent.right; \n\
289 margins: units.gu(1); \n\
290 topMargin: %2; \n\
291 } \n\
292 wrapMode: Text.Wrap; \n\
293 maximumLineCount: 5; \n\
294 elide: Text.ElideRight; \n\
295 text: cardData && cardData["summary"] || ""; \n\
296 height: text ? implicitHeight : 0; \n\
297 fontSize: "small"; \n\
298 color: %3; \n\
299 }\n';
301function cardString(template, components) {
302 var code;
303 code = 'AbstractButton { \n\
304 id: root; \n\
305 property var template; \n\
306 property var components; \n\
307 property var cardData; \n\
308 property var artShapeBorderSource: undefined; \n\
309 property real fontScale: 1.0; \n\
310 property var scopeStyle: null; \n\
311 property int headerAlignment: Text.AlignLeft; \n\
312 property int fixedHeaderHeight: -1; \n\
313 property size fixedArtShapeSize: Qt.size(-1, -1); \n\
314 readonly property string title: cardData && cardData["title"] || ""; \n\
315 property bool asynchronous: true; \n\
316 property bool showHeader: true; \n\
317 implicitWidth: childrenRect.width; \n';
319 var hasArt = components["art"] && components["art"]["field"] || false;
320 var hasSummary = components["summary"] || false;
321 var artAndSummary = hasArt && hasSummary;
322 var isHorizontal = template["card-layout"] === "horizontal";
323 var hasBackground = !isHorizontal && (template["card-background"] || components["background"] || artAndSummary);
324 var hasTitle = components["title"] || false;
325 var hasMascot = components["mascot"] || false;
326 var headerAsOverlay = hasArt && template && template["overlay"] === true && (hasTitle || hasMascot);
327 var hasSubtitle = hasTitle && components["subtitle"] || false;
328 var hasHeaderRow = hasMascot && hasTitle;
329 var hasAttributes = hasTitle && components["attributes"] || false;
331 if (hasBackground) {
332 code += kBackgroundLoaderCode;
333 }
335 if (hasArt) {
336 code += 'onArtShapeBorderSourceChanged: { if (artShapeBorderSource !== undefined && artShapeLoader.item) artShapeLoader.item.borderSource = artShapeBorderSource; } \n';
337 code += 'readonly property size artShapeSize: artShapeLoader.item ? Qt.size(artShapeLoader.item.width, artShapeLoader.item.height) : Qt.size(-1, -1);\n';
339 var widthCode, heightCode;
340 var anchors;
341 if (isHorizontal) {
342 anchors = 'left: parent.left';
343 if (hasMascot || hasTitle) {
344 widthCode = 'height * artShape.aspect'
345 heightCode = 'headerHeight + 2 * units.gu(1)';
346 } else {
347 // This side of the else is a bit silly, who wants an horizontal layout without mascot and title?
348 // So we define a "random" height of the image height + 2 gu for the margins
349 widthCode = 'height * artShape.aspect'
350 heightCode = 'units.gu(7.625)';
351 }
352 } else {
353 anchors = 'horizontalCenter: parent.horizontalCenter;';
354 widthCode = 'root.width'
355 heightCode = 'width / artShape.aspect';
356 }
358 code += kArtShapeHolderCode.arg(anchors).arg(widthCode).arg(heightCode);
359 } else {
360 code += 'readonly property size artShapeSize: Qt.size(-1, -1);\n'
361 }
363 if (headerAsOverlay) {
364 code += kOverlayLoaderCode;
365 }
367 var headerVerticalAnchors;
368 if (headerAsOverlay) {
369 headerVerticalAnchors = 'bottom: artShapeHolder.bottom; \n\
370 bottomMargin: units.gu(1);\n';
371 } else {
372 if (hasArt) {
373 if (isHorizontal) {
374 headerVerticalAnchors = 'top: artShapeHolder.top; \n\
375 topMargin: units.gu(1);\n';
376 } else {
377 headerVerticalAnchors = 'top: artShapeHolder.bottom; \n\
378 topMargin: units.gu(1);\n';
379 }
380 } else {
381 headerVerticalAnchors = 'top: parent.top; \n\
382 topMargin: units.gu(1);\n';
383 }
384 }
385 var headerLeftAnchor;
386 var headerLeftAnchorHasMargin = false;
387 if (isHorizontal && hasArt) {
388 headerLeftAnchor = 'left: artShapeHolder.right; \n\
389 leftMargin: units.gu(1);\n';
390 headerLeftAnchorHasMargin = true;
391 } else {
392 headerLeftAnchor = 'left: parent.left;\n';
393 }
395 if (hasHeaderRow) {
396 code += 'readonly property int headerHeight: row.height;\n'
397 } else if (hasMascot) {
398 code += 'readonly property int headerHeight: mascotImage.height;\n'
399 } else if (hasAttributes) {
400 if (hasTitle && hasSubtitle) {
401 code += 'readonly property int headerHeight: titleLabel.height + subtitleLabel.height + subtitleLabel.anchors.topMargin + attributesRow.height + attributesRow.anchors.topMargin;\n'
402 } else if (hasTitle) {
403 code += 'readonly property int headerHeight: titleLabel.height + attributesRow.height + attributesRow.anchors.topMargin;\n'
404 } else {
405 code += 'readonly property int headerHeight: attributesRow.height;\n'
406 }
407 } else if (hasSubtitle) {
408 code += 'readonly property int headerHeight: titleLabel.height + subtitleLabel.height + subtitleLabel.anchors.topMargin;\n'
409 } else if (hasTitle) {
410 code += 'readonly property int headerHeight: titleLabel.height;\n'
411 } else {
412 code += 'readonly property int headerHeight: 0;\n'
413 }
415 var mascotShapeCode = "";
416 var mascotCode = "";
417 if (hasMascot) {
418 var useMascotShape = !hasBackground && !headerAsOverlay;
419 var anchors = "";
420 if (!hasHeaderRow) {
421 anchors += headerLeftAnchor;
422 anchors += headerVerticalAnchors;
423 if (!headerLeftAnchorHasMargin) {
424 anchors += 'leftMargin: units.gu(1);\n'
425 }
426 } else {
427 anchors = "verticalCenter: parent.verticalCenter;"
428 }
430 if (useMascotShape) {
431 mascotShapeCode = kMascotShapeLoaderCode.arg(anchors);
432 }
434 var mascotImageVisible = useMascotShape ? 'false' : 'showHeader';
435 mascotCode = kMascotImageCode.arg(anchors).arg(mascotImageVisible);
436 }
438 var summaryColorWithBackground = 'backgroundLoader.active && backgroundLoader.item && backgroundLoader.item.luminance < 0.7 ? "white" : (root.scopeStyle ? root.scopeStyle.foreground : "grey")';
440 var titleSubtitleCode = "";
441 if (hasTitle) {
442 var color;
443 if (headerAsOverlay) {
444 color = '"white"';
445 } else if (hasSummary) {
446 color = 'summary.color';
447 } else if (hasBackground) {
448 color = summaryColorWithBackground;
449 } else {
450 color = 'root.scopeStyle ? root.scopeStyle.foreground : "grey"';
451 }
453 var titleAnchors;
454 var subtitleAnchors;
455 var attributesAnchors;
456 if (hasMascot && (hasSubtitle || hasAttributes)) {
457 // Using row + column
458 titleAnchors = 'left: parent.left; right: parent.right';
459 subtitleAnchors = titleAnchors;
460 attributesAnchors = subtitleAnchors;
461 } else if (hasMascot) {
462 // Using row + label
463 titleAnchors = 'verticalCenter: parent.verticalCenter;\n'
464 } else {
465 if (headerAsOverlay) {
466 // Using anchors to the overlay
467 titleAnchors = 'left: parent.left; \n\
468 leftMargin: units.gu(1); \n\
469 right: parent.right; \n\
470 rightMargin: units.gu(1); \n\
471 top: overlayLoader.top; \n\
472 topMargin: units.gu(1);\n';
473 } else {
474 // Using anchors to the mascot/parent
475 titleAnchors = "right: parent.right;\n";
476 titleAnchors += "rightMargin: units.gu(1);\n";
477 titleAnchors += headerLeftAnchor;
478 titleAnchors += headerVerticalAnchors;
479 if (!headerLeftAnchorHasMargin) {
480 titleAnchors += 'leftMargin: units.gu(1);\n'
481 }
482 }
483 subtitleAnchors = 'left: titleLabel.left; \n\
484 leftMargin: titleLabel.leftMargin; \n\
485 right: titleLabel.right; \n\
486 rightMargin: titleLabel.rightMargin; \n\
487 top: titleLabel.bottom; \n\
488 topMargin: units.dp(2);\n';
489 if (hasSubtitle) {
490 attributesAnchors = 'left: subtitleLabel.left; \n\
491 leftMargin: subtitleLabel.leftMargin; \n\
492 right: subtitleLabel.right; \n\
493 rightMargin: subtitleLabel.rightMargin; \n\
494 top: subtitleLabel.bottom; \n\
495 topMargin: units.dp(2);\n';
496 } else {
497 attributesAnchors = subtitleAnchors;
498 }
499 }
501 var titleLabelVisibleExtra = (headerAsOverlay ? '&& overlayLoader.active': '');
502 var titleCode = kTitleLabelCode.arg(titleAnchors).arg(color).arg(titleLabelVisibleExtra);
503 var subtitleCode = "";
504 if (hasSubtitle) {
505 subtitleCode += kSubtitleLabelCode.arg(subtitleAnchors).arg(color);
506 }
508 if (hasMascot && (hasSubtitle || hasAttributes)) {
509 // If using row + column wrap the code in the column
510 titleSubtitleCode = kHeaderColumnCode.arg(titleCode).arg(subtitleCode);
511 if (hasSubtitle && hasAttributes) {
512 var attributesCode = kAttributesRowCode.arg(attributesAnchors).arg(color);
513 titleSubtitleCode = kHeaderColumnCodeGenerator(titleCode, subtitleCode, attributesCode);
514 } else if (hasSubtitle) {
515 titleSubtitleCode = kHeaderColumnCode.arg(titleCode).arg(subtitleCode);
516 } else if (hasAttributes) {
517 var attributesCode = kAttributesRowCode.arg(attributesAnchors).arg(color);
518 titleSubtitleCode = kHeaderColumnCode.arg(titleCode).arg(attributesCode);
519 }
520 } else {
521 titleSubtitleCode = titleCode;
522 if (hasSubtitle) {
523 titleSubtitleCode = titleSubtitleCode + subtitleCode;
524 }
525 if (hasAttributes) {
526 var attributesCode = kAttributesRowCode.arg(attributesAnchors).arg(color);
527 titleSubtitleCode = titleSubtitleCode + attributesCode;
528 }
529 }
530 }
532 if (hasHeaderRow) {
533 if (mascotShapeCode != "") {
534 code += kHeaderRow3Code.arg(headerVerticalAnchors + headerLeftAnchor).arg(mascotShapeCode).arg(mascotCode).arg(titleSubtitleCode);
535 } else {
536 code += kHeaderRow2Code.arg(headerVerticalAnchors + headerLeftAnchor).arg(mascotCode).arg(titleSubtitleCode);
537 }
538 } else {
539 code += mascotShapeCode + mascotCode + titleSubtitleCode;
540 }
542 if (hasSummary) {
543 var summaryTopAnchor;
544 if (isHorizontal && hasArt) summaryTopAnchor = "artShapeHolder.bottom";
545 else if (headerAsOverlay && hasArt) summaryTopAnchor = "artShapeHolder.bottom";
546 else if (hasHeaderRow) summaryTopAnchor = "row.bottom";
547 else if (hasMascot) summaryTopAnchor = "mascotImage.bottom";
548 else if (hasAttributes) summaryTopAnchor = "attributesRow.bottom";
549 else if (hasSubtitle) summaryTopAnchor = "subtitleLabel.bottom";
550 else if (hasTitle) summaryTopAnchor = "titleLabel.bottom";
551 else if (hasArt) summaryTopAnchor = "artShapeHolder.bottom";
552 else summaryTopAnchor = "parent.top";
554 var color;
555 if (hasBackground) {
556 color = summaryColorWithBackground;
557 } else {
558 color = 'root.scopeStyle ? root.scopeStyle.foreground : "grey"';
559 }
561 var summaryTopMargin = (hasMascot || hasSubtitle || hasAttributes ? 'anchors.margins' : '0');
563 code += kSummaryLabelCode.arg(summaryTopAnchor).arg(summaryTopMargin).arg(color);
564 }
566 if (hasSummary) {
567 code += 'implicitHeight: summary.y + summary.height + (summary.text ? units.gu(1) : 0);\n';
568 } else if (hasHeaderRow) {
569 code += 'implicitHeight: row.y + row.height + units.gu(1);\n';
570 } else if (hasMascot) {
571 code += 'implicitHeight: mascotImage.y + mascotImage.height;\n';
572 } else if (hasAttributes) {
573 code += 'implicitHeight: attributesRow.y + attributesRow.height + units.gu(1);\n';
574 } else if (hasSubtitle) {
575 code += 'implicitHeight: subtitleLabel.y + subtitleLabel.height + units.gu(1);\n';
576 } else if (hasTitle) {
577 code += 'implicitHeight: titleLabel.y + titleLabel.height + units.gu(1);\n';
578 } else if (hasArt) {
579 code += 'implicitHeight: artShapeHolder.height;\n';
580 }
581 // Close the AbstractButton
582 code += '}\n';
584 return code;
587function createCardComponent(parent, template, components) {
588 var imports = 'import QtQuick 2.2; \n\
589 import Ubuntu.Components 0.1; \n\
590 import Ubuntu.Thumbnailer 0.1;\n\
591 import Dash 0.1;\n';
592 var card = cardString(template, components);
593 var code = imports + 'Component {\n' + card + '}\n';
595 return Qt.createQmlObject(code, parent, "createCardComponent");